Example #1
0
 public function getComposite()
 {
     $composerName = $this->resource->getComposer();
     $composer = $this->composerManager->getComposer($composerName);
     $data = is_object($this->resource->getData()) ? array($this->resource->getData()) : $this->resource->getData();
     // Get embeded composed models
     $embededModels = $composer->getEmbededModels($this, $data);
     // Compose resource
     $embededModels = $embededModels ? $embededModels : array();
     return $composer->compose($data, $embededModels);
 }
Example #2
0
 public function testGetData()
 {
     $resource = new Resource();
     $resource->addSuccessMessage('foo');
     $resource->addInfoMessage('bar');
     $resource->addWarningMessage('baz');
     $resource->addErrorMessage('boom');
     $resource->setData(['key' => 'value']);
     $this->assertSame(['key' => 'value', '_messages' => [['type' => 'success', 'message' => 'foo'], ['type' => 'info', 'message' => 'bar'], ['type' => 'warn', 'message' => 'baz'], ['type' => 'error', 'message' => 'boom']]], $resource->getData());
 }
 /**
  * Filter attributes. Applies the visible/hidden field filter, hides owner of resource.
  * If visible attributes are defined, hidden attributes filter will not be applied.
  *
  * @param \marius321967\BaseResource\Resource $resource
  * @return array
  */
 public static function getFilteredAttributes(Resource $resource)
 {
     $descriptor = $resource->getDescriptor();
     $attributes = $resource->getData(true);
     // In whatever case, client does not need to know about the owner of resource.
     unset($attributes['owner_id']);
     // If only fields that are visible are defined, don't use the other filter.
     if (count($descriptor->getVisibleAttributes())) {
         $attributes = array_intersect_key($attributes, array_flip($descriptor->getVisibleAttributes()));
     } elseif (count($descriptor->getHiddenAttributes())) {
         $attributes = array_diff_key($attributes, array_flip($descriptor->getHiddenAttributes()));
     }
     return $attributes;
 }