Beispiel #1
0
 /**
  * Factory and/or returns template objects.
  *
  * @param  string                            $path      Full path to template file
  * @param  \Foil\Engine                      $engine
  * @param  string                            $className A custom template class name
  * @return \Foil\Contracts\TemplateInterface
  */
 public function factory($path, Engine $engine, $className = null)
 {
     if (!is_string($path)) {
         throw new InvalidArgumentException('Template path must be in a string.');
     }
     if (!$this->templates->offsetExists($path)) {
         $class = $this->getClass($className);
         $template = new $class($path, $this->sections, $engine, $this->command);
         $template instanceof Aliasable && $this->alias and $template->alias($this->alias);
         $this->templates[$path] = $template;
     }
     return $this->templates[$path];
 }
Beispiel #2
0
 /**
  * Factory a section instance (if it was not already factored) and return it.
  *
  * @param  string                           $name       Section name
  * @param  int|bool                         $mode       Section mode, one of the mode const
  * @param  string                           $className Full qualified section class name
  * @return \Foil\Contracts\SectionInterface
  * @throws InvalidArgumentException
  */
 public function factory($name, $mode = false, $className = null)
 {
     if (!is_string($name)) {
         throw new InvalidArgumentException('Section name must be in a string.');
     }
     if (!$this->sections->offsetExists($name)) {
         $class = $this->getClass($className);
         $this->sections[$name] = new $class($mode, $this->defaultMode);
     } else {
         $merge = $mode === SectionInterface::MODE_REPLACE ? false : true;
         $this->sections[$name]->setMode($mode, $merge);
     }
     return $this->sections[$name];
 }
Beispiel #3
0
 protected function existsAccess($key)
 {
     if ($this->object->offsetExists($key)) {
         return true;
     }
     return $this->existsObject($key);
 }
Beispiel #4
0
 /**
  * Determine if the given key exists in the provided array.
  *
  * @param \ArrayAccess|array $array
  * @param string|int         $key
  *
  * @return bool
  */
 public function arrExists($array, $key)
 {
     if ($array instanceof ArrayAccess) {
         return $array->offsetExists($key);
     }
     return array_key_exists($key, $array);
 }
Beispiel #5
0
 /**
  * Conditionally replace node value with new one
  *
  * @param string                       $key
  * @param string|integer|float|boolean $oldValue
  * @param mixed                        $newValue
  *
  * @return $this
  */
 public function replaceValue($key, $oldValue, $newValue)
 {
     if ($this->array->offsetExists($key) && $oldValue === $this->array->offsetExists($key)) {
         $this->array->offsetSet($key, $newValue);
     }
     return $this;
 }
Beispiel #6
0
 /**
  * Converts instance of \ArrayAccess to key => value array entry
  *
  * @param \ArrayAccess $object
  *
  * @return array|null
  * @throws \Prophecy\Exception\InvalidArgumentException
  */
 private function convertArrayAccessToEntry(\ArrayAccess $object)
 {
     if (!$this->key instanceof ExactValueToken) {
         throw new InvalidArgumentException(sprintf('You can only use exact value tokens to match key of ArrayAccess object' . PHP_EOL . 'But you used `%s`.', $this->key));
     }
     $key = $this->key->getValue();
     return $object->offsetExists($key) ? array($key => $object[$key]) : array();
 }
Beispiel #7
0
 /**
  * @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;
 }
Beispiel #8
0
 /**
  * @inheritdoc
  */
 public function supply($section, $default = '')
 {
     if ($this->sections->offsetExists($section)) {
         return $this->sections[$section]->content();
     }
     while (is_callable($default)) {
         $default = $default($section, $this);
     }
     return is_string($default) ? $default : '';
 }
/**
 * 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();
}
Beispiel #10
0
 /**
  * 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' => []]);
 }
Beispiel #11
0
 /**
  * @param  \ArrayAccess $flagedObject
  * @param  array        $layout
  * @return array
  */
 protected function getLayoutOptions(\ArrayAccess $flagedObject, array $layout)
 {
     $result = array();
     foreach ($layout as $flag => $options) {
         if ($flagedObject->offsetExists($flag)) {
             $value = $flagedObject->offsetGet($flag);
             $value = (string) $value;
             if (isset($options[$value])) {
                 $result += $options[$value];
             }
         }
     }
     foreach ($this->layoutCallback as $callback) {
         $result = $callback($flagedObject, $result);
     }
     return $result;
 }
 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);
         }
     }
 }
Beispiel #13
0
 /**
  * @see \ArrayAccess::offsetExists()
  */
 public function offsetExists($offset)
 {
     return $this->metadata->offsetExists($offset);
 }
Beispiel #14
0
 /**
  * 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);
 }
Beispiel #16
0
 /**
  * Checks if a section was already factored.
  *
  * @param  string $name
  * @return bool
  */
 public function has($name)
 {
     return $this->sections->offsetExists($name);
 }
 /**
  * @inheritdoc
  *
  * This implementation detects the specified offset in this context or any ancestor contexts.
  */
 public function offsetExists($offset)
 {
     return parent::offsetExists($offset) || !is_null($this->parent) && $this->parent->offsetExists($offset);
 }
 /**
  * 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();
 }
Beispiel #19
0
 /**
  * Check if a given timer is active.
  *
  * @param TimerInterface $timer The timer to check.
  *
  * @return boolean True if the timer is still enqueued for execution.
  */
 public function isTimerActive(TimerInterface $timer)
 {
     return $this->timers->offsetExists($timer);
 }
 /**
  * @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;
 }