/**
  *
  * @param <type> $table
  * @param ArrayIterator $params
  * @return ArrayObject
  */
 public function search($table, ArrayIterator $params)
 {
     $this->searchParams = $params;
     $this->join();
     if ($table == "analysis") {
         $this->statements->remove("type_event");
     }
     $statement = "SELECT this_.* " . $this->selectAttributes() . " FROM {$table} this_ ";
     $statement .= $this->join();
     $i = 0;
     $this->searchParams->rewind();
     if ($this->searchParams->count() > 0 && !$this->searchParams->offsetExists('true')) {
         $statement .= " WHERE ";
     }
     while ($this->searchParams->valid()) {
         if ($this->statements->containsKey($this->searchParams->key())) {
             if ($i++ > 0) {
                 $statement .= " AND ";
             }
             $clause = $this->statements->get($this->searchParams->key());
             $statement .= str_replace(":" . $this->searchParams->key(), "'" . $this->searchParams->current() . "'", $clause['where']);
         }
         $this->searchParams->next();
     }
     return $this->getObject($statement . " ORDER BY this_.date DESC, this_.id DESC");
 }
 public function getParam($name, $default = null)
 {
     $value = $default;
     if ($this->params->offsetExists($name)) {
         $value = $this->params->offsetGet($name);
     }
     return $value;
 }
 /**
  * @param $locId
  * @return LocationHelper
  * @throws \Exception
  */
 public function getLocation($locId)
 {
     if ($this->locations->offsetExists($locId)) {
         return $this->locations->offsetGet($locId);
     } else {
         return $this->locHelper->factory($locId);
     }
 }
Beispiel #4
0
 public function verifyAccess($name, $resource, $page)
 {
     if (!$this->resources->offsetExists($resource)) {
         return false;
     }
     if (!$this->pages->offsetExists($page)) {
         return false;
     }
     return true;
 }
 /**
  * \WP_Widget::update_callback(): $old_instance = isset($all_instances[$number]) ? $all_instances[$number] : array();
  * \WP_Widget::display_callback(): if ( array_key_exists( $this->number, $instance ) ) {
  * \WP_Widget::get_settings(): if ( !empty($settings) && !array_key_exists('_multiwidget', $settings) ) {
  *
  * @param int|string $key Array key.
  * @return bool
  */
 public function offsetExists($key)
 {
     if ('_multiwidget' === $key) {
         return true;
     }
     return parent::offsetExists($key);
 }
Beispiel #6
0
 public function offsetGet($offset)
 {
     $name = $this->_normalizeHeaderName($offset);
     if (!parent::offsetExists($name)) {
         throw new Bringit_Exception("Header '{$name}' not in ");
     }
     return parent::offsetGet($name);
 }
 /**
  * Reflect the handle class
  *
  * @param string $class
  * @return Collection\Method
  * @throws Exception\InvalidArgument
  */
 public function reflect($class)
 {
     if (class_exists($class) === false) {
         throw new Exception\InvalidArgument(sprintf($this->exceptions[1], $class), 1);
     }
     // Check if we've already reflected this class
     if (static::$reflections->offsetExists($class)) {
         return static::$reflections->offsetGet($class);
     }
     // Create reflection
     $reflectionClass = new \ReflectionClass($class);
     $reflectionMethods = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC);
     // Method container
     $methods = new Collection\Method();
     // Loop through the class methods (Only public);
     foreach ($reflectionMethods as $reflectionMethod) {
         // Create method information entity
         $method = new Entity\Method();
         $method->setName($reflectionMethod->getName());
         // Get method parameters
         $reflectionParams = $reflectionMethod->getParameters();
         // Evaluate the method params
         foreach ($reflectionParams as $reflectionParam) {
             // Create parameter information entity
             $parameter = new Entity\Parameter();
             $parameter->setIndex($reflectionParam->getPosition());
             $parameter->setName($reflectionParam->getName());
             $parameter->setRequired($reflectionParam->isDefaultValueAvailable() === false);
             // Only set default value when param is optional
             if ($parameter->getRequired() === false) {
                 $parameter->setDefault($reflectionParam->getDefaultValue());
             }
             // Add the parameter to the container
             $method->addParameter($parameter);
         }
         // Add the method to the method container
         $methods->offsetSet(strtolower($method->getName()), $method);
     }
     // Cache reflection in the runtime
     self::$reflections->offsetSet($class, $methods);
     // Return the methods
     return $methods;
 }
Beispiel #8
0
 private function getPostedFile($key)
 {
     if (!$this->specsIterator->offsetExists($key)) {
         return null;
     }
     $spec = $this->specsIterator[$key];
     if (is_array($spec)) {
         $this->specsIterator[$key] = new \Barberry\PostedFile($this->readTempFile($spec['tmp_name']), $spec['name']);
     }
     return $this->specsIterator[$key];
 }
Beispiel #9
0
 /**
  * Check input against the Rules configured for this Validator.
  *
  * @param array|object|Persistent $input The input data to check.
  * @param bool $all If true, all rules will be checked even if the field
  * does not exist in the input data.
  *
  * @return bool True if all Rules pass, false otherwise.
  */
 public function check($input, $all = false)
 {
     $data = new \ArrayIterator($input);
     foreach ($this->ruleSet as $field => $rules) {
         if ($all || $data->offsetExists($field)) {
             $fieldValue = $data->offsetExists($field) ? $data->offsetGet($field) : null;
             foreach (explode('|', $rules) as $ruleDef) {
                 $ruleExploded = explode(':', $ruleDef, 2);
                 $rule = $ruleExploded[0];
                 $ruleArgs = isset($ruleExploded[1]) ? explode(',', $ruleExploded[1]) : [];
                 try {
                     Rules::$rule($field, $fieldValue, $ruleArgs);
                 } catch (ValidationFailedException $failure) {
                     $this->addFailure($field, $failure->getMessage(), $failure->getCode());
                     $this->failed = true;
                 }
             }
         }
     }
     $this->checked = true;
     return $this->failed === false;
 }
 /**
  * Determines the actual array offset given the input offset.
  *
  * @param string $offset  Input offset.
  *
  * @return string  Real offset or null.
  */
 protected function _getRealOffset($offset)
 {
     /* Optimize: check for base $offset in array first. */
     if (parent::offsetExists($offset)) {
         return $offset;
     }
     foreach (array_keys($this->getArrayCopy()) as $key) {
         if (strcasecmp($key, $offset) === 0) {
             return $key;
         }
     }
     return null;
 }
Beispiel #11
0
 /**
  * Get the handler based on the namespace
  *
  * @param string $namespace
  * @return object
  * @throws Exception\ArgumentException
  */
 protected function getHandler($namespace)
 {
     // Chack if namespace has been registered
     if ($this->handlers->offsetExists($namespace) === false) {
         throw new Exception\InvalidArgument(sprintf($this->exceptions[1], $namespace), 1);
     }
     // Create instance when needed
     if ($this->handlerInstances->offsetExists($namespace) === false) {
         $handler = $this->handlers->offsetGet($namespace);
         $this->handlerInstances->offsetSet($namespace, new $handler());
     }
     // Return instance
     return $this->handlerInstances->offsetGet($namespace);
 }
Beispiel #12
0
 /**
  * Verifica o mime type do arquivo
  * @return boolean
  */
 public function checkMimeTypes()
 {
     $fileExtension = $this->getFileExtension();
     $fileMimeType = $this->getMimeTypeFile();
     $oIMines = $this->getMimeTypes()->getIterator();
     $oIExtension = $this->getExtension()->getIterator();
     $valid = new \ArrayIterator();
     while ($oIExtension->valid()) {
         $current = $oIExtension->current();
         if ($oIMines->offsetExists($current)) {
             $valid->offsetSet($current, $oIMines->offsetGet($current));
         }
         $oIExtension->next();
     }
     if ($valid->offsetExists($fileExtension)) {
         $item = $valid->offsetGet($fileExtension);
         if (is_array($item)) {
             if (in_array($fileMimeType, $item)) {
                 return true;
             } else {
                 $this->setMessageError("error_mime_type");
                 return false;
             }
         } else {
             if ($fileMimeType == $item) {
                 return true;
             } else {
                 $this->setMessageError("error_mime_type");
                 return false;
             }
         }
     } else {
         $this->setMessageError("error_mime_type");
         return false;
     }
 }
 /**
  * Check if the index exist into container
  * 
  * @param int $index
  * @return boolean
  */
 public function existIndex($index)
 {
     return parent::offsetExists($index);
 }
 public function offsetUnset($name)
 {
     if (!is_array($name)) {
         return parent::offsetUnset($name);
     } else {
         $key = array_shift($name);
         if (sizeof($name) == 0) {
             return parent::offsetUnset($key);
         } else {
             if (parent::offsetExists($key)) {
                 $object = parent::offsetGet($key);
                 if (is_a($object, 'MutliDimArray')) {
                     $object->offsetUnset($name);
                     if ($object->sizeof() == 0) {
                         parent::offsetUnset($key);
                     }
                 } else {
                     parent::offsetUnset($key);
                 }
             }
         }
     }
 }
 /**
  * Check whether an offset exists.
  * 
  * @param mixed $offset
  * @return boolean
  */
 public function offsetExists($offset)
 {
     return $this->iterator->offsetExists($offset);
 }
Beispiel #16
0
 /**
  * (PHP 5 &gt;= 5.0.0)<br/>
  * Whether a offset exists
  * @link http://php.net/manual/en/arrayaccess.offsetexists.php
  * @param mixed $offset <p>
  * An offset to check for.
  * </p>
  * @return boolean true on success or false on failure.
  * </p>
  * <p>
  * The return value will be casted to boolean if non-boolean was returned.
  */
 public function offsetExists($offset)
 {
     return $this->data->offsetExists($offset);
 }

?>

<?php
$iterator = new ArrayIterator(array('recipe'=>'pancakes', 'egg', 'milk', 'flour'));
$itCnt = $iterator->count();
echo $itCnt . PHP_EOL;
 
$iterator->append("water");
$iterator->ksort();

while($iterator->valid()){
    echo "Key : ". $iterator->key() . ", Value: " .$iterator->current() . PHP_EOL; 
    $iterator->next();
}
if($iterator->offsetExists(9)){
    $iterator->seek(3);
}
else{
    $iterator->seek($itCnt);
    echo $iterator->offsetGet('recipe') . PHP_EOL;
}

echo "[$itCnt]" . PHP_EOL;

echo PHP_EOL . "Key : ". $iterator->key() . ", Value: " .$iterator->current() . PHP_EOL; 

var_dump(iterator_count($iterator));
?>
Beispiel #18
0
 /**
  * Contains one collectable with $name
  * @param  int $index
  * @return boolean
  */
 public function containsIndex($index)
 {
     return parent::offsetExists($index);
 }
Beispiel #19
0
 /**
  * Unset value at offset
  * 
  * @param string $index
  */
 public function offsetUnset($index)
 {
     parent::offsetExists($index) && parent::offsetUnset($index);
 }
Beispiel #20
0
echo '--------------------------------- ArrayIterator START --------------------------------', "\n";
/**
 * ArrayIterator类 、ArrayObject类、RecursiveArrayIterator类、RecursiveIteratorIterator类
 *
 * ArrayObject类 将数组变成对象object,但是不支持遍历
 * ArrayIterator类 可以对数组进行遍历, 支持offset放方法
 *
 * 但是ArrayObject和ArrayIterator只支持遍历一维数组。
 * 如果要支持多维数组,便用RecursiveArrayIterator生成一个Iterator。然后再说对这个Iterator使用RecursiveIteratorIterator
 *
 */
$array = array('value1', 'value3', 'value2', 'value4', 'value5');
try {
    $object = new ArrayIterator($array);
    // 判断第二个节点是否存在
    if ($object->offsetExists(2)) {
        // 给第二个节点赋新值
        $object->offsetSet(2, 'value2_1');
    }
    // 在数组最后插入新值
    $object->append('value_6');
    // 自然排序排序 natsort(): 数组进行自然排序; natcasesort():对数组进行自然排序,并不区分大小写
    // uasort(): uksort(): 通过在参数中传递已定义的排序方式进行排序;
    $object->natsort();
    // 检查key为3所对应的值
    $object->offsetGet(3);
    // 销毁key为3的值
    $object->offsetUnset(3);
    // 指针跳转到第5个节点
    $object->seek(4);
    // foreach 循环
Beispiel #21
0
 /**
  */
 public function offsetExists($offset)
 {
     return is_null($offset = $this->_getRealOffset($offset)) ? false : parent::offsetExists($offset);
 }