Beispiel #1
0
 /**
  * Helper for `Payload::push()`.
  *
  * @param  object  $entity       The Chaos entity to push in the payload.
  * @param  boolean $relationship Indicates whether the entity is some related data or not.
  * @return array                 The pushed data
  */
 public function _push($entity, $related = false)
 {
     if (!$entity instanceof Model) {
         $this->errors([['status' => 500, 'code' => 500, 'title' => "The JSON-API serializer only supports Chaos entities."]]);
         return;
     }
     $definition = $entity::definition();
     $data = $this->_data($entity);
     if (($link = $this->_link) && $entity->exists()) {
         $data['links']['self'] = $link(Inflector::camelize($data['type']), ['id' => $entity->id()], ['absolute' => true]);
     }
     if ($related) {
         $this->_store($data);
         unset($data['attributes']);
         unset($data['links']);
     } elseif ($relations = $definition->relations()) {
         $this->_populateRelationships($entity, $relations, $data);
     }
     return $data;
 }
Beispiel #2
0
         expect(Inflector::underscore('dashed-version'))->toBe('dashed_version');
     });
 });
 describe("::dasherize()", function () {
     it("dasherizes a string", function () {
         expect(Inflector::dasherize('class_name'))->toBe('class-name');
         expect(Inflector::dasherize('test_field'))->toBe('test-field');
     });
 });
 describe("::camelize()", function () {
     it("camelizes a string", function () {
         expect(Inflector::camelize('test-field'))->toBe('TestField');
         expect(Inflector::camelize('test_field'))->toBe('TestField');
         expect(Inflector::camelize('TEST_FIELD'))->toBe('TestField');
         expect(Inflector::camelize('TestField'))->toBe('TestField');
         expect(Inflector::camelize('my_name\\space'))->toBe('MyName\\Space');
     });
 });
 describe("::camelback()", function () {
     it("camelbacks a string", function () {
         expect(Inflector::camelback('test-field'))->toBe('testField');
         expect(Inflector::camelback('test field'))->toBe('testField');
         expect(Inflector::camelback('TEST_FIELD'))->toBe('testField');
         expect(Inflector::camelback('TestField'))->toBe('testField');
         expect(Inflector::camelback('my_name\\space'))->toBe('myName\\Space');
     });
 });
 describe("::titleize()", function () {
     it("titleizes a string", function () {
         expect(Inflector::titleize('posts'))->toBe('Posts');
         expect(Inflector::titleize('posts_tags'))->toBe('Posts Tags');