示例#1
0
 /**
  * Creates a single resource or collection of resources
  *
  * @param object|array $entity The entity - single resource or collection - to be created
  *
  * @return Resource|ResourceCollection
  */
 public static function create($entity)
 {
     // can't make anything out of a string or integer
     if (is_scalar($entity)) {
         throw new \InvalidArgumentException("Entity should be an object or array of objects");
     }
     // arrays with numeric-only keys will be collections, everything else translates to a resource
     if (is_array($entity) && ArrayHelper::isCollection($entity)) {
         return new ResourceCollection($entity);
     } else {
         return new Resource($entity);
     }
 }
示例#2
0
 public function testIsPropertiedWithMixedArray()
 {
     $entity = ['bar', 'foo' => 'bar'];
     $actual = ArrayHelper::isPropertied($entity);
     $this->assertFalse($actual);
     $entity = ['foo' => 'bar', 'bar'];
     $actual = ArrayHelper::isPropertied($entity);
     $this->assertFalse($actual);
 }