logo       

cvs: pear /Config/Config Container.php: msg#00375

Subject: cvs: pear /Config/Config Container.php
mansion         Tue Nov 26 14:16:35 2002 EDT

  Modified files:              
    /pear/Config/Config Container.php 
  Log:
  Added a new countChildren method useful when a section has multiple 
directives with the same name.
  
  
Index: pear/Config/Config/Container.php
diff -u pear/Config/Config/Container.php:1.6 
pear/Config/Config/Container.php:1.7
--- pear/Config/Config/Container.php:1.6        Tue Nov 26 08:38:38 2002
+++ pear/Config/Config/Container.php    Tue Nov 26 14:16:34 2002
@@ -15,7 +15,7 @@
 // | Author: Bertrand Mansion <bmansion@xxxxxxxxxxx>                     |
 // +---------------------------------------------------------------------+
 //
-// $Id: Container.php,v 1.6 2002/11/26 13:38:38 mansion Exp $
+// $Id: Container.php,v 1.7 2002/11/26 19:16:34 mansion Exp $
 
 require_once('Config.php');
 
@@ -215,12 +215,7 @@
         if ($this->type != 'section') {
             return PEAR::raiseError('Config_Container::getItem must be called 
on a section type object.', null, PEAR_ERROR_RETURN);
         }
-        $testFields = array();
-        if ($type == '') {
-            return PEAR::raiseError('You must specify an existing type in 
Config_Container::getItem.', null, PEAR_ERROR_RETURN);
-        } else {
-            $testFields[] = 'type';
-        }
+        $testFields[] = 'type';
         if (!is_null($name)) {
             $testFields[] = 'name';
         }
@@ -255,7 +250,51 @@
             }
         }
     } // end func &getItem
-    
+
+    /**
+    * Returns how many children this container has
+    *
+    * @param  string    type    (optional)type of children counted
+    * @param  string    type    (optional)name of children counted
+    * @return int  number of children found
+    */
+    function countChildren($type = null, $name = null)
+    {
+        if ($this->type != 'section') {
+            return PEAR::raiseError('Config_Container::getChildrenNum must be 
called on a section type object.', null, PEAR_ERROR_RETURN);
+        }
+        if (is_null($type) && is_null($name)) {
+            return count($this->children);
+        }
+        $count = 0;
+        if (isset($name) && isset($type)) {
+            for ($i = 0; $i < count($this->children); $i++) {
+                if ($this->children[$i]->name == $name && 
+                    $this->children[$i]->type == $type) {
+                    $count++;
+                }
+            }
+            return $count;
+        }
+        if (isset($type)) {
+            for ($i = 0; $i < count($this->children); $i++) {
+                if ($this->children[$i]->type == $type) {
+                    $count++;
+                }
+            }
+            return $count;
+        }
+        if (isset($name)) {
+            // Some directives can have the same name
+            for ($i = 0; $i < count($this->children); $i++) {
+                if ($this->children[$i]->name == $name) {
+                    $count++;
+                }
+            }
+            return $count;
+        }
+    } // end func &countChildren
+
     /**
     * Inserts an item to a specified position.
     * The position is relative to a target object if it is defined.



-- 
PEAR CVS Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
science.linguis...    culture.sf.lite...    video.mplayer.c...    yellowdog.gener...    ietf.rfc822/199...    emacs.help/2002...    redhat.release....    kernel.speakup/...    java.openejb.de...    debian.devel.gt...    xfree86.newbie/...    bug-tracking.ma...    pam/2003-05/msg...    games.devel.ope...    user-groups.lin...    music.pancham/2...    network.mq.deve...    web.html.genera...    arklinux.bugs/2...    linux.ecasound/...    qnx.openqnx.dev...    org.user-groups...    file-systems.sf...    trustix.contrib...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe