Пример #1
0
 /**
  * Check the body using specified "data" key and return that data.
  * If key doesn't exists, ParserException exception will be thrown
  * @param  array $body
  * @return array
  */
 protected function setDataFromBody($body)
 {
     $return = false;
     //body only has a single key? prolly entities are grouped under one key
     //ie:- { tweets : [ {}, {}, {}] }
     if (H::arrayIsAssoc($body) and $keys = array_keys($body) and count($keys) < 2) {
         //get stuff under that key
         $key = array_shift($keys);
         $return = H::arrayGet($body, $key);
         //if user has set a custom data key, check for that
     } elseif ($key = $this->getKey('data')) {
         //check with the key assoc to find which key has data
         if (!array_key_exists($this->getKey('data'), $body)) {
             throw new ParserException("Couldn't find data under '{$key}', key doesn't exists in response.");
         }
         $return = H::arrayGet($body, $this->getKey('data'));
         //nothing to do, just take it as it is
     } else {
         $return = $body;
     }
     if (empty($return)) {
         $this->data = array();
     } elseif (H::arrayIsAssoc($return)) {
         $this->data = array($return);
     } else {
         $this->data = $return;
     }
 }
Пример #2
0
 public function testArrayIsAssoc()
 {
     $this->assertTrue(H::arrayIsAssoc(array('first' => 'john', 'email' => '*****@*****.**')));
     $this->assertFalse(H::arrayIsAssoc(array('john', '*****@*****.**')));
 }
Пример #3
0
 /**
  * Build relationship models using in model data
  * @param  string $key attribute name
  * @return array
  */
 protected function getInModelData($key)
 {
     $model = $this->getCallingModel();
     if ($model->attributeExists($key)) {
         $data = $model->getRawAttribute($key);
         if (H::arrayIsAssoc($data)) {
             $data = array($data);
         }
         return $this->query->buildModels($data);
     }
     return false;
 }