]> granicus.if.org Git - php/commitdiff
- Update examples
authorMarcus Boerger <helly@php.net>
Wed, 28 Jul 2004 22:52:11 +0000 (22:52 +0000)
committerMarcus Boerger <helly@php.net>
Wed, 28 Jul 2004 22:52:11 +0000 (22:52 +0000)
ext/spl/examples/autoload.inc
ext/spl/examples/dbareader.inc

index af4b931ff40a16c2a12c14bea33b4ea1aa3c515c..7fecfa5758d1c9441af7bb3af5456c4d8a252e6a 100755 (executable)
@@ -33,7 +33,10 @@ function __load_class($classname, $dir)
  */
 function __autoload($classname) {
        $classname = strtolower($classname);
-       foreach(split(':', ini_get('include_path')) as $dir)
+       $inc = split(':', ini_get('include_path'));
+       $inc[] = '.';
+       $inc[] = dirname($_SERVER['PATH_TRANSLATED']);
+       foreach($inc as $dir)
        {
                if (__load_class($classname, $dir))
                {
@@ -41,10 +44,7 @@ function __autoload($classname) {
                        return;
                }
        }
-       if (!__load_class($classname, '.'))
-       if (!__load_class($classname, dirname($_SERVER['PATH_TRANSLATED'])))
        fprintf(STDERR, 'Class not found ('.$classname.")\n");
-       return;
 }
 
 ?>
\ No newline at end of file
index 02b084031732005ab5528f1e2fc626e0ca1247be..cd27ad7baa8c397c62da9509402e6eb696a41da1 100755 (executable)
@@ -28,32 +28,24 @@ class DbaReader implements Iterator
         * @param handler Handler to use for database access.
         */
        function __construct($file, $handler) {
-               $this->db = dba_open($file, 'r', $handler);
+               if (!$this->db = dba_open($file, 'r', $handler)) {
+                   throw new exception('Could not open file ' . $file);
+               }
        }
        
        /**
         * Close database.
         */
        function __destruct() {
-               if ($this->db) {
-                       dba_close($this->db);
-               }
+               dba_close($this->db);
        }
 
        /**
         * Rewind to first element.
         */
        function rewind() {
-               if ($this->db) {
-                       $this->key = dba_firstkey($this->db);
-               }
-       }
-
-       /**
-        * @return Current data.
-        */
-       function current() {
-               return $this->val;
+               $this->key = dba_firstkey($this->db);
+               fetch_data();
        }
 
        /**
@@ -62,14 +54,26 @@ class DbaReader implements Iterator
         * @return void
         */
        function next() {
-               if ($this->db) {
-                       $this->key = dba_nextkey($this->db);
-                       if ($this->key !== false) {
-                               $this->val = dba_fetch($this->key, $this->db);
-                       }
+               $this->key = dba_nextkey($this->db);
+               fetch_data();
+       }
+
+    /**
+     * Fetches the current data if $key is valid
+     */        
+       private function fetch_data() {
+               if ($this->key !== false) {
+                       $this->val = dba_fetch($this->key, $this->db);
                }
        }
 
+       /**
+        * @return Current data.
+        */
+       function current() {
+               return $this->val;
+       }
+
        /**
         * @return Whether more elements are available.
         */