function it_delegates_to_container(\ArrayAccess $container) { $serviceName = 'dummy'; $retval = 'foo'; $container->offsetGet($serviceName)->willReturn($retval)->shouldBeCalled(); $this->get($serviceName)->shouldBe($retval); }
/** * Checks whether if an item exists on the queried path or not * @param string $query * @return bool */ public function exists($query) { if (empty($query)) { throw new \InvalidArgumentException('Argument 1 should not be empty.'); } $keyExists = 'exists' . $this->type; $key = ''; $result = null; while (strlen($key .= $this->shiftKey($query)) > 0 and $result === null) { $realKey = $this->parseKey($key); if ($this->{$keyExists}($realKey)) { switch ($this->type) { case static::TYPE_ARRAY: $result =& $this->object[$realKey]; break; case static::TYPE_ACCESS: if ($key[0] !== '@' and $key[0] !== '!' and $this->object->offsetExists($realKey)) { $result =& $this->object->offsetGet($realKey); break; } case static::TYPE_OBJECT: if ($key[0] === '@') { $call = $this->object[$realKey]; if (!$call instanceof Provider) { throw new \RuntimeException('"' . $key . '" is not a Provider. Using "@" (service-getter) prefix only allowed on Provider item.'); } $result = $call($this->object); } else { if ($key[0] == '!') { $call = $this->object[$realKey]; if (!$call instanceof Provider) { throw new \RuntimeException('"' . $key . '" is not a Provider. Using "!" (mutation-getter) prefix only allowed on Provider item.'); } if (!$call->isMutated()) { throw new \RuntimeException('Provider "' . $key . '" is not mutated.'); } $result =& $call->getMutatedItem(); } else { $result =& $this->object->{$realKey}; } } break; } if ($query !== '' and (is_array($result) or is_object($result))) { $q = new static($result); if ($q->exists($query)) { $result =& QueryParser::Create($result)->find($query); } else { return false; } } } else { if ($query === '') { return false; } } } return true; }
/** * Cancel a pending timer. * * @param TimerInterface $timer The timer to cancel. */ public function cancelTimer(TimerInterface $timer) { if ($this->timers->offsetExists($timer)) { $id = $this->timers->offsetGet($timer); $this->timers->offsetUnset($timer); $this->reactor->cancel($id); } }
/** * @param \ArrayAccess $keyvalue * * @return boolean */ public function check(\ArrayAccess $keyvalue) { foreach ($this as $key => $value) { if (!($keyvalue->offsetExists($key) && $keyvalue->offsetGet($key) === $value)) { return false; } } return true; }
/** * Implode node array to string using values separator * * @param array $keys * @param string $implodeChar [optional] * * @return $this */ public function implodeValues(array $keys, $implodeChar = ',') { foreach ($keys as $key) { if ($this->array->offsetExists($key) && is_array($this->array->offsetGet($key))) { $this->array->offsetSet($key, implode($implodeChar, $this->array->offsetGet($key))); } } return $this; }
/** * Simple test comment. * * FANOUT := 4 * CALLS := 7 * * @param ArrayAccess $items The input items. * @param integer $index The requested index. * * @return MyObjectItem * @throws OutOfRangeException For invalid index values. * @throws InvalidArgumentException For invalid index values. */ function getItemAt(ArrayAccess $items, $index) { if (is_int($index) === false) { throw new InvalidArgumentException('Error'); } if (!$items->offsetExists($index)) { throw new OutOfRangeException('Error...'); } $data = $items->offsetGet($index); if (is_array($data)) { return new MyObjectItem(array_keys($data), array_values($data)); } return MyObjectItem::getDefault(); }
/** * Returns the content to render * * @param Request $request * @param Response $response * @param null|callable $next * @return null|Response */ public function dispatch(Request $request, Response $response, callable $next = null) : Response { // On GET requests that are not comming from PRG, just return the template if ($request->getMethod() === 'GET' && !$this->session->offsetExists(self::PRG_DATA)) { return $this->createTemplateResponse($request); } // On POST requests, get request data, store it in the session, and redirect to sel if ($request->getMethod() === 'POST') { $params = $request->getParsedBody(); $this->session->offsetSet(self::PRG_DATA, $params); return new RedirectResponse($request->getUri()); } // On a GET request that contains data, process the data and clear it from session $params = $this->session->offsetGet(self::PRG_DATA); $this->session->offsetUnset(self::PRG_DATA); $filter = $this->contactFilter; $filter->setData($params); if (!$filter->isValid()) { return $this->createTemplateResponse($request, ['errors' => $filter->getMessages(), 'currentData' => $params]); } // If the form is valid, send the email $result = $this->contactService->send($filter->getValues()); return $this->createTemplateResponse($request, $result ? ['success' => true] : ['errors' => []]); }
private function mergeTableData() { $keyValue = $this->getKeyValue(); // Nothing to do if setTableData() has not been called if ($this->arr === NULL) { return; } // Mark record as modified if we are a new record if (!$this->arr->offsetExists($keyValue)) { $this->state = self::DIRTY; return; } // DB fields are transfered into the object storage. Record state // is unchanged and existing values are retained. foreach ($this->arr->offsetGet($keyValue) as $key => $value) { if (!$this->data->offsetExists($key)) { $this->data->offsetSet($key, $value); } } }
/** * @see \ArrayAccess::offsetGet() */ public function offsetGet($offset) { return $this->metadata->offsetGet($offset); }
/** * Retrieve a single key from an array. If the key does not exist in the * array, the default value will be returned instead. * * // Get the value "username" from $_POST, if it exists * $username = Arr::get($_POST, 'username'); * * // Get the value "sorting" from $_GET, if it exists * $sorting = Arr::get($_GET, 'sorting'); * * @param array|\ArrayAccess $array array to extract from * @param string $key key name * @param mixed $default default value * @return mixed */ public static function get($array, $key, $default = NULL) { if ($array instanceof \ArrayObject) { // This is a workaround for inconsistent implementation of isset between PHP and HHVM // See https://github.com/facebook/hhvm/issues/3437 return $array->offsetExists($key) ? $array->offsetGet($key) : $default; } else { return isset($array[$key]) ? $array[$key] : $default; } }
/** * @param \Prophecy\Argument\Token\ExactValueToken $key * @param \Prophecy\Argument\Token\TokenInterface $value * @param \ArrayAccess $object */ function it_does_not_score_array_accessible_object_if_key_and_value_tokens_do_not_score_same_entry($key, $value, $object) { $object->offsetExists('key')->willReturn(true); $object->offsetGet('key')->willReturn('value'); $key->getValue()->willReturn('key'); $value->scoreArgument('value')->willReturn(false); $key->scoreArgument('key')->willReturn(true); $this->scoreArgument($object)->shouldBe(false); }
public function get($name) { return $this->container->offsetGet($name); }
/** * Checks if a section was already factored. * * @param string $name * @return bool */ public function get($name) { return $this->sections->offsetGet($name); }
/** * @return \Illuminate\Config\Repository */ protected function config() { return $this->app->offsetGet('config'); }
/** * @inheritdoc * * This implementation retrieves the specified offset in this context or any ancestor contexts. */ public function offsetGet($offset) { return parent::offsetExists($offset) ? parent::offsetGet($offset) : (!is_null($this->parent) ? $this->parent->offsetGet($offset) : null); }
/** * Simple test comment. * * FANOUT := 4 * CALLS := 7 * * @param ArrayAccess $items The input items. * @param integer $index The requested index. * * @return MyObjectItem * @throws DomainException For invalid index values. * @throws InvalidArgumentException For invalid index values. */ public function getItemAt(ArrayAccess $items, $index) { if (is_int($index) === false) { throw new DomainException('Error'); } if (!$items->offsetExists($index)) { throw new OutOfBoundsException('Error...'); } $data = $items->offsetGet($index); if (is_array($data)) { return new MyObjectItem(array_keys($data), array_values($data)); } return MyObjectItemCollection::getDefault(); }
/** * @param \ArrayAccess $flaggedObject * @param array $layout * * @return array */ protected function getLayoutOptions(\ArrayAccess $flaggedObject, array $layout) { $result = array(); foreach ($layout as $flag => $options) { if ($flaggedObject->offsetExists($flag)) { $value = $flaggedObject->offsetGet($flag); $value = (string) $value; if (isset($options[$value])) { $result += $options[$value]; } } } /* @var $callback callable */ foreach ($this->layoutCallback as $callback) { $result = $callback($flaggedObject, $result); } return $result; }
/** * @param ArrayAccess $item * @param string $property_or_method * @param mixed $property_value * @param string $comparison_operator * @param array $method_arguments * @return bool */ protected function item_matches_condition(ArrayAccess $item, $property_or_method, $property_value, $comparison_operator, array $method_arguments = null) { if ($item->offsetExists($property_or_method)) { if ($this->compare($item->offsetGet($property_or_method), $property_value, $comparison_operator)) { return true; } } else { if (method_exists($item, $property_or_method)) { $method_result = $method_arguments ? call_user_func_array(array($item, $property_or_method), $method_arguments) : $item->{$property_or_method}(); if ($this->compare($method_result, $property_value, $comparison_operator)) { return true; } } } return false; }
/** * (PHP 5 >= 5.1.0)<br/> * Return the current element * @link http://php.net/manual/en/iterator.current.php * @return mixed Can return any type. */ public function current() { return $this->object->offsetGet($this->position); }