Наследование: extends ArrayObject
Пример #1
0
 /**
  * @return Collection
  */
 public function execute()
 {
     /**
      * @var ObjectInterface $from_class
      */
     $from_class = $this->from_class;
     $url = new URL($this->app, $from_class::getResourceURI(), $from_class::getAPIStem());
     $request = new Request($this->app, $url, Request::METHOD_GET);
     // Concatenate where statements
     $where = $this->getWhere();
     if (!empty($where)) {
         $request->setParameter('where', $where);
     }
     if ($this->order !== null) {
         $request->setParameter('order', $this->order);
     }
     if ($this->modifiedAfter !== null) {
         $request->setHeader('If-Modified-Since', $this->modifiedAfter);
     }
     if ($this->fromDate !== null) {
         $request->setParameter('fromDate', $this->fromDate);
     }
     if ($this->toDate !== null) {
         $request->setParameter('toDate', $this->toDate);
     }
     if ($this->date !== null) {
         $request->setParameter('date', $this->date);
     }
     if ($this->page !== null) {
         $request->setParameter('page', $this->page);
     }
     if ($this->offset !== null) {
         $request->setParameter('offset', $this->offset);
     }
     $request->send();
     $elements = new Collection();
     foreach ($request->getResponse()->getElements() as $element) {
         /**
          * @var Object $built_element
          */
         $built_element = new $from_class($this->app);
         $built_element->fromStringArray($element);
         $elements->append($built_element);
     }
     return $elements;
 }
Пример #2
0
 /**
  * Load an assoc array into the instance of the object $property => $value
  * $replace_data - replace existing data
  *
  * @param $input_array
  * @param $replace_data
  */
 public function fromStringArray($input_array, $replace_data = false)
 {
     foreach (static::getProperties() as $property => $meta) {
         $type = $meta[self::KEY_TYPE];
         $php_type = $meta[self::KEY_PHP_TYPE];
         //If set and NOT replace data, continue
         if (!$replace_data && isset($this->_data[$property])) {
             continue;
         }
         if (!isset($input_array[$property])) {
             $this->_data[$property] = null;
             continue;
         }
         //Fix for an earlier assumption that the API didn't return more than
         //two levels of nested objects.
         //Handles Invoice > Contact > Address etc. in one build.
         if (is_array($input_array[$property]) && Helpers::isAssoc($input_array[$property]) === false) {
             $collection = new Collection();
             $collection->addAssociatedObject($property, $this);
             foreach ($input_array[$property] as $assoc_element) {
                 $cast = self::castFromString($type, $assoc_element, $php_type);
                 //Do this here so that you know it's not a static method call to ::castFromString
                 if ($cast instanceof Object) {
                     $cast->addAssociatedObject($property, $this);
                 }
                 $collection->append($cast);
             }
             $this->_data[$property] = $collection;
         } else {
             $cast = self::castFromString($type, $input_array[$property], $php_type);
             //Do this here so that you know it's not a static method call to ::castFromString
             if ($cast instanceof Object) {
                 $cast->addAssociatedObject($property, $this);
             }
             $this->_data[$property] = $cast;
         }
     }
 }