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); } }
public function offsetGet($offset) { $name = $this->_normalizeHeaderName($offset); if (!parent::offsetExists($name)) { throw new Bringit_Exception("Header '{$name}' not in "); } return parent::offsetGet($name); }
public function offsetGet($k) { $k = $this->normalize($k); if (is_null($k)) { return ''; } return parent::offsetGet($k); }
public function offsetGet($index) { static $i = 0; echo __METHOD__ . "({$index})\n"; if (++$i > 3) { exit(1); } return parent::offsetGet($index); }
/** * 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; }
public function config(ArrayIterator $cotations) { $minValue = $cotations->offsetGet(0)->getClose(); $maxValue = $cotations->offsetGet(0)->getClose(); while ($cotations->valid()) { $cotation = $this->returnCotation($cotations->current()); $date = explode("-", $cotation->getDate()); $date = date("d/m/Y", mktime(0, 0, 0, $date[1], $date[2], $date[0])); if ($maxValue < $cotation->getClose()) { $maxValue = $cotation->getClose(); } if ($minValue > $cotation->getClose()) { $minValue = $cotation->getClose(); } $this->simpleSeries->setValue($cotation->getClose(), $date); $cotations->next(); } $this->configureMinMaxYValues($minValue, $maxValue); }
/** * 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); }
/** * \WP_Widget::update_callback(): $old_instance = isset($all_instances[$number]) ? $all_instances[$number] : array(); * \WP_Widget::display_callback(): $instance = $instance[$this->number]; * \WP_Widget::form_callback(): $instance = $all_instances[ $widget_args['number'] ]; * * @param int|string $key Array key. * @return array|int|null */ public function offsetGet($key) { if ('_multiwidget' === $key) { return 1; } if (!$this->offsetExists($key)) { return null; } $value = parent::offsetGet($key); if (is_int($value)) { // Fetch the widget post_content_filtered and store it in the array. $post = get_post($value); $value = Widget_Posts::get_post_content_filtered($post); $this->offsetSet($key, $value); } return $value; }
public function config(ArrayIterator $cotations) { $i = 1; $date = $cotations->offsetGet(0)->getDate(); $dateInParts = explode('-', $date); $month = $dateInParts[1]; while ($cotations->valid()) { $cot = $this->returnCotation($cotations->current()); $currentMonth = $this->getCurrentMonth($cot->getDate()); if ($this->monthIsDiferent($currentMonth, $month)) { $month = $currentMonth; $this->multiSeries->addCategory($this->translateMonth($month)); $this->multiSeries->addCategoryAttribute($this->translateMonth($month), "x", $i); } $this->multiSeries->setValue("all_values", $cot->getOpen(), $cot->getMax(), $cot->getMin(), $cot->getClose(), $i); $this->addTextToTooltipInASet('all_values', $i, $cot); $i++; $cotations->next(); } }
/** * 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; }
*/ $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 循环 /** * 如下的写法经调试出现了一个bug。 * 当在循环中进行offsetUnset时,此时,当前指针会回跳会第一个节点,即$object->key()的值为0,但是此时循环的key值和value值并没有变,依然是3=>value4。 * 而再次foreach循环之前,$object->key()值为0.循环后,$object->key()为1,所有,此时循环重复值。 */ foreach ($object as $key => $value) { echo '<li>' . $key . '=>' . $value . '</li>' . "\n"; } // while 循环 $object->rewind();
/** * Get value for an offset * * @param string $index * @return string */ public function offsetGet($index) { if (!parent::offsetExists($index)) { return null; } $value = parent::offsetGet($index); return $this->cast($index, $value); }
/** * (PHP 5 >= 5.0.0)<br/> * Get value for an offset * @link http://php.net/manual/en/arrayiterator.offsetget.php * @param string $index <p> * The offset to get the value from. * </p> * @return mixed The value at offset <i>index</i>. */ public function offsetGet($index) { $element = parent::offsetGet($index); return $element[PriorityArrayElementsContainerFactory::VALUE_KEY_NAME]; }
/** * 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; } }
/** * {@inheritdoc} */ public function offsetGet($offset) { return call_user_func($this->callback, parent::offsetGet($offset)); }
public function offsetGet($index) { $value = parent::offsetGet($index); return $this->create($value); }
?> <?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)); ?>
/** * Load currency property. * @param string|Currency\IProperty $index * @return Currency\IProperty * @throws UnknownCurrencyException */ public function offsetGet($index) { if ($index instanceof Currency\IProperty) { return $index; } $index = strtoupper($index); if ($this->offsetExists($index)) { return parent::offsetGet($index); } throw new UnknownCurrencyException('Undefined currency code: ' . $index . ', you must call loadCurrency before.'); }
/** * @inheritdoc */ public function offsetGet($offset) { return $this->iterator->offsetGet($offset); }
/** * Get the item value * * @param {string} Key of value * @return {mixed} Value from iterator */ public function item($key) { return parent::offsetGet($key); }
/** * OffsetGet (supports wildcards). * * @param string $offset the key * @return mixed */ public function offsetGet($offset) { if (isset($this[$offset])) { return parent::offsetGet($offset); } if (false !== strrpos($offset, $this->attributes['wildcard'])) { $parts = array_map('preg_quote', explode($this->attributes['wildcard'], $offset)); $glue = "[^{$this->attributes['separator']}]+"; $pattern = '/' . implode($glue, $parts) . '/'; return new \CallbackFilterIterator($this, function ($current, $key, $iterator) use($pattern) { return (bool) preg_match($pattern, $key); }); } if ($this->attributes['error_mode'] == 'silent') { return null; } if ($this->attributes['error_mode'] == 'error') { trigger_error("Unefined index: {$offset}", E_USER_NOTICE); return null; } if ($this->attributes['error_mode'] == 'exception') { throw new \OutOfBoundsException("Undefined index: {$offset}"); } }
/** * @param mixed|string $value * * @return mixed * @throws CollectionException * @author Yohann Marillet */ public function offsetGet($value) { $k = $this->getKey($value); if (!isset($this[$k])) { throw new CollectionException("This key (or Keyable object) has not been defined in the collection. \n\nContent: \n" . var_export($value, true)); } return parent::offsetGet($k); }
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); } } } } }
/** */ public function offsetGet($offset) { return is_null($offset = $this->_getRealOffset($offset)) ? null : parent::offsetGet($offset); }