summaryrefslogtreecommitdiff
path: root/ext/spl
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2003-12-07 15:03:11 +0000
committerMarcus Boerger <helly@php.net>2003-12-07 15:03:11 +0000
commit1765271499b3ab279b2d93ee2a8d62725a9ba6f8 (patch)
tree31b5b9ec971d23e425b50a4259b2528d7d772790 /ext/spl
parent8eb22d7b8d88e4897c7c469d6fb82ef58197cc21 (diff)
downloadphp-git-1765271499b3ab279b2d93ee2a8d62725a9ba6f8.tar.gz
Use a single bit field for the flags here
Diffstat (limited to 'ext/spl')
-rw-r--r--ext/spl/examples/cachingiterator.inc13
-rw-r--r--ext/spl/examples/cachingrecursiveiterator.inc11
-rw-r--r--ext/spl/examples/directorygraphiterator.inc2
-rw-r--r--ext/spl/examples/directorytreeiterator.inc2
4 files changed, 15 insertions, 13 deletions
diff --git a/ext/spl/examples/cachingiterator.inc b/ext/spl/examples/cachingiterator.inc
index a9cc075b70..f83932dbdd 100644
--- a/ext/spl/examples/cachingiterator.inc
+++ b/ext/spl/examples/cachingiterator.inc
@@ -1,5 +1,8 @@
<?php
+define('CIT_GET_STR_VALUE', 1);
+define('CIT_CATCH_GET_CHILD', 2);
+
class CachingIterator
{
protected $it;
@@ -9,10 +12,10 @@ class CachingIterator
protected $strValue;
protected $getStrVal;
- function __construct(Iterator $it, $getStrVal = true)
+ function __construct(Iterator $it, $flags = CIT_GET_STR_VALUE)
{
$this->it = $it;
- $this->getStrVal = (boolean)$getStrVal;
+ $this->flags = $flags & (CIT_GET_STR_VALUE|CIT_CATCH_GET_CHILD);
}
function rewind()
@@ -26,7 +29,7 @@ class CachingIterator
if ($this->more = $this->it->hasMore()) {
$this->current = $this->it->current();
$this->key = $this->it->key();
- if ($this->getStrVal) {
+ if ($this->flags & CIT_GET_STR_VALUE) {
if (is_object($this->current)) {
$this->strValue = $this->current->__toString();
} else {
@@ -36,7 +39,7 @@ class CachingIterator
} else {
$this->current = NULL;
$this->key = NULL;
- $this->strValue = '';
+ $this->strValue = NULL;
}
$this->it->next();
}
@@ -68,7 +71,7 @@ class CachingIterator
function __toString()
{
- if (!$this->getStrVal) {
+ if (!$this->flags & CIT_GET_STR_VALUE) {
throw new exception('CachingIterator does not fetch string value (see CachingIterator::__construct)');
}
return $this->strValue;
diff --git a/ext/spl/examples/cachingrecursiveiterator.inc b/ext/spl/examples/cachingrecursiveiterator.inc
index 898d40b0bc..cc1f101d99 100644
--- a/ext/spl/examples/cachingrecursiveiterator.inc
+++ b/ext/spl/examples/cachingrecursiveiterator.inc
@@ -6,23 +6,22 @@ class CachingRecursiveIterator extends CachingIterator implements RecursiveItera
protected $getChildren;
protected $catch_get_child;
- function __construct(RecursiveIterator $it, $getStrVal = true, $catch_get_child = false)
+ function __construct(RecursiveIterator $it, $flags = CIT_GET_STR_VALUE)
{
- $this->catch_get_child = $catch_get_child;
- parent::__construct($it, $getStrVal);
+ parent::__construct($it, $flags);
}
function next()
{
if ($this->hasChildren = $this->it->hasChildren()) {
try {
- //$this->getChildren = new CachingRecursiveIterator($this->it->getChildren(), $this->getStrVal, $this->catch_get_child);
+ //$this->getChildren = new CachingRecursiveIterator($this->it->getChildren(), $this->flags);
// workaround memleaks...
$child = $this->it->getChildren();
- $this->getChildren = new CachingRecursiveIterator($child, $this->getStrVal, $this->catch_get_child);
+ $this->getChildren = new CachingRecursiveIterator($child, $this->flags);
}
catch(Exception $e) {
- if (!$this->catch_get_child) {
+ if (!$this->flags & CIT_CATCH_GET_CHILD) {
throw $e;
}
$this->hasChildren = false;
diff --git a/ext/spl/examples/directorygraphiterator.inc b/ext/spl/examples/directorygraphiterator.inc
index b1b8743b4c..50b27bf48b 100644
--- a/ext/spl/examples/directorygraphiterator.inc
+++ b/ext/spl/examples/directorygraphiterator.inc
@@ -4,7 +4,7 @@ class DirectoryGraphIterator extends DirectoryTreeIterator
{
function __construct($path)
{
- RecursiveIteratorIterator::__construct(new CachingRecursiveIterator(new ParentIterator(new RecursiveDirectoryIterator($path)), true, true), 1);
+ RecursiveIteratorIterator::__construct(new CachingRecursiveIterator(new ParentIterator(new RecursiveDirectoryIterator($path)), CIT_GET_STR_VALUE|CIT_CATCH_GET_CHILD), 1);
}
}
diff --git a/ext/spl/examples/directorytreeiterator.inc b/ext/spl/examples/directorytreeiterator.inc
index 3accacae43..0c2717ccf2 100644
--- a/ext/spl/examples/directorytreeiterator.inc
+++ b/ext/spl/examples/directorytreeiterator.inc
@@ -4,7 +4,7 @@ class DirectoryTreeIterator extends RecursiveIteratorIterator
{
function __construct($path)
{
- parent::__construct(new CachingRecursiveIterator(new RecursiveDirectoryIterator($path), true, true), 1);
+ parent::__construct(new CachingRecursiveIterator(new RecursiveDirectoryIterator($path), CIT_GET_STR_VALUE|CIT_CATCH_GET_CHILD), 1);
}
function current()