/**
  * Build an array that represents a paypal payer
  *
  * @param array|\ArrayAccess|PayPalRestApiClient\Model\PayerInterface $payer an array of values 
  * or an istance of a class implmenting PayPalRestApiClient\Model\PayerInterface or \ArrayAccess interface
  * 
  * @return array
  * 
  * @throws PayPalRestApiClient\Exception\BuilderException if the given input parameter is not an array or
  * it is not an object implementing PayPalRestApiClient\Model\PayerInterface or \ArrayAccess interface
  * 
  * @see https://developer.paypal.com/docs/api/#payer-object
  */
 public function buildArray($payer)
 {
     $payerData = array();
     if ($payer instanceof PayerInterface) {
         $payerData['payment_method'] = $payer->getPaymentMethod();
         if ($fundingInstruments = $payer->getFundingInstruments()) {
             $payerData['funding_instruments'] = $fundingInstruments;
         }
         if ($info = $payer->getInfo()) {
             $payerData['payer_info'] = $info;
         }
         return $payerData;
     }
     if (($payer instanceof \ArrayAccess || is_array($payer)) && isset($payer['payment_method'])) {
         $payerData['payment_method'] = $payer['payment_method'];
         if (isset($payer['funding_instruments'])) {
             $payerData['funding_instruments'] = $payer['funding_instruments'];
         }
         if (isset($payer['payer_info'])) {
             $payerData['payer_info'] = $payer['payer_info'];
         }
         return $payerData;
     }
     throw new BuilderException('Payer is not valid');
 }
 function it_delegates_to_container(\ArrayAccess $container)
 {
     $serviceName = 'dummy';
     $retval = 'foo';
     $container->offsetGet($serviceName)->willReturn($retval)->shouldBeCalled();
     $this->get($serviceName)->shouldBe($retval);
 }
Esempio n. 3
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);
 }
Esempio n. 4
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();
 }
Esempio n. 5
0
 /**
  * @param  array|\ArrayAccess|RedisSource $resource
  * @return $this
  * @throws \Yafrk\Cache\Exception\InvalidArgumentException
  */
 public function setResource($resource)
 {
     if ($resource instanceof RedisSource) {
         try {
             $resource->ping();
         } catch (\RedisException $ex) {
             throw new Exception\InvalidArgumentException('Invalid redis resource', $ex->getCode(), $ex);
         }
         if ($resource->getOption(RedisSource::OPT_SERIALIZER) == RedisSource::SERIALIZER_NONE) {
             $resource->setOption(RedisSource::OPT_SERIALIZER, RedisSource::SERIALIZER_PHP);
         }
         $this->resource = $resource;
         return $this;
     }
     if (is_string($resource)) {
         $resource = array($resource);
     }
     if (!is_array($resource) && !$resource instanceof \ArrayAccess) {
         throw new Exception\InvalidArgumentException(sprintf('%s: expects an string, array, or Traversable argument; received "%s"', __METHOD__, is_object($resource) ? get_class($resource) : gettype($resource)));
     }
     $host = $port = $auth = $database = null;
     // array(<host>[, <port>[, <auth>, [<database>]]])
     if (isset($resource[0])) {
         if (strpos(':', (string) $resource[0])) {
             list($host, $port) = explode(':', (string) $resource[0]);
         } else {
             $host = (string) $resource[0];
         }
         if (isset($resource[1])) {
             $port = (int) $resource[1];
         }
         if (isset($resource[2])) {
             $auth = (string) $resource[2];
         }
         if (isset($resource[3])) {
             $database = (int) $resource[3];
         }
     } elseif (isset($resource['host'])) {
         if (strpos(':', (string) $resource['host'])) {
             list($host, $port) = explode(':', (string) $resource['host']);
         } else {
             $host = (string) $resource['host'];
         }
         if (isset($resource['port'])) {
             $port = (int) $resource['port'];
         }
         if (isset($resource['auth'])) {
             $auth = (string) $resource['auth'];
         }
         if (isset($resource['database'])) {
             $database = (int) $resource['database'];
         }
     }
     if (!$host) {
         throw new Exception\InvalidArgumentException('Invalid redis resource, option "host" must be given');
     }
     $this->resource = array('host' => $host, 'port' => $port ?: 6379, 'auth' => $auth, 'database' => $database);
 }
Esempio n. 6
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;
 }
Esempio n. 7
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];
 }
/**
 * 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();
}
Esempio n. 9
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];
 }
Esempio n. 10
0
 protected function existsAccess($key)
 {
     if ($this->object->offsetExists($key)) {
         return true;
     }
     return $this->existsObject($key);
 }
Esempio n. 11
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;
 }
 /**
  * @see \MetaborStd\ArrayConvertableInterface::toArray()
  */
 public function toArray()
 {
     if ($this->object instanceof MetadataInterface) {
         return $this->object->getMetadata();
     } elseif ($this->object instanceof ArrayConvertableInterface) {
         return $this->object->toArray();
     } elseif ($this->object instanceof \ArrayIterator) {
         return $this->object->getArrayCopy();
     } elseif ($this->object instanceof \ArrayObject) {
         return $this->object->getArrayCopy();
     } elseif ($this->object instanceof \Traversable) {
         return iterator_to_array($this->object);
     } else {
         throw new \RuntimeException('Unable to get MetaData!');
     }
 }
Esempio n. 13
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;
 }
Esempio n. 14
0
 /**
  * @param array|\ArrayAccess|MemcachedSource $resource
  * @throws \Cache\Exception\InvalidArgumentException
  * @return Memcached
  */
 public function setResource($resource)
 {
     if ($resource instanceof MemcachedSource) {
         if (!$resource->getVersion()) {
             throw new Exception\InvalidArgumentException('Invalid memcached resource');
         }
         $this->resource = $resource;
         return $this;
     }
     if (is_string($resource)) {
         $resource = array($resource);
     }
     if (!is_array($resource) && !$resource instanceof \ArrayAccess) {
         throw new Exception\InvalidArgumentException(sprintf('%s: expects an string, array, or Traversable argument; received "%s"', __METHOD__, is_object($resource) ? get_class($resource) : gettype($resource)));
     }
     $host = $port = $weight = $persistent_id = null;
     // array(<host>[, <port>[, <weight> [,<persistent_id>]]])
     if (isset($resource[0])) {
         $host = (string) $resource[0];
         if (isset($resource[1])) {
             $port = (int) $resource[1];
         }
         if (isset($resource[2])) {
             $weight = (string) $resource[2];
         }
         if (isset($resource[3])) {
             $persistent_id = (string) $resource[3];
         }
     } elseif (isset($resource['host'])) {
         $host = (string) $resource['host'];
         if (isset($resource['port'])) {
             $port = (int) $resource['port'];
         }
         if (isset($resource['weight'])) {
             $weight = (int) $resource['weight'];
         }
         if (isset($resource['persistent_id'])) {
             $persistent_id = (string) $resource['persistent_id'];
         }
     }
     if (!$host) {
         throw new Exception\InvalidArgumentException('Invalid memcached resource, option "host" must be given');
     }
     $this->resource = array('host' => $host, 'port' => $port, 'weight' => $weight, 'persistent_id' => $persistent_id);
 }
Esempio n. 15
0
 /**
  * Autoload
  * @param ArrayAccess $aditionalDirectories
  * @return void
  */
 public function load(ArrayAccess $aditionalDirectories = null)
 {
     if (isset(self::$str_autoload)) {
         return;
     }
     $this->scandir(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
     //        $this->scandir(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR);
     $arrobj_autoload = $this->directoryTree;
     foreach ($arrobj_autoload as $path) {
         self::$str_autoload .= $path . PATH_SEPARATOR;
     }
     if ($aditionalDirectories instanceof ArrayAccess && $aditionalDirectories->count() > 0) {
         foreach ($aditionalDirectories as $directory) {
             self::$str_autoload .= $directory . PATH_SEPARATOR;
         }
     }
     set_include_path(self::$str_autoload . get_include_path());
 }
Esempio n. 16
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 : '';
 }
Esempio n. 17
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' => []]);
 }
Esempio n. 18
0
 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);
         }
     }
 }
Esempio n. 19
0
 /**
  * @see \ArrayAccess::offsetUnset()
  */
 public function offsetUnset($offset)
 {
     $this->metadata->offsetUnset($offset);
 }
Esempio n. 20
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);
 }
Esempio n. 22
0
 public function get($name)
 {
     return $this->container->offsetGet($name);
 }
Esempio n. 23
0
 /**
  * Checks if a section was already factored.
  *
  * @param  string $name
  * @return bool
  */
 public function get($name)
 {
     return $this->sections->offsetGet($name);
 }
Esempio n. 24
0
 /**
  * @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 &gt;= 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);
 }
Esempio n. 26
0
 /**
  * @return \Illuminate\Config\Repository
  */
 protected function config()
 {
     return $this->app->offsetGet('config');
 }
Esempio n. 27
0
 /**
  * Constructor...
  */
 public function __construct()
 {
     $this->sources = new ArrayObject();
     $this->sources->append(new TwitterGateway());
     $this->messages = new ArrayObject();
 }
Esempio n. 28
0
 /**
  * @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();
 }
 /**
  * {@inheritdoc}
  */
 public function listObserved() : array
 {
     return $this->observedList->getArrayCopy();
 }