public function one(array $data, array $options = [])
    {
        list($data, $options) = $this->_prepareDataAndOptions($data, $options);

        $primaryKey = (array)$this->_endpoint->getPrimaryKey();
        $resourceClass = $this->_endpoint->getResourceClass();
        /* @var \Muffin\Webservice\Model\Resource $entity */
        $entity = new $resourceClass();
        $entity->setSource($this->_endpoint->getRegistryAlias());

        if (isset($options['accessibleFields'])) {
            foreach ((array)$options['accessibleFields'] as $key => $value) {
                $entity->setAccess($key, $value);
            }
        }

        $errors = $this->_validate($data, $options, true);
        $properties = [];
        foreach ($data as $key => $value) {
            if (!empty($errors[$key])) {
                $entity->setInvalidField($key, $value);
                continue;
            }
            if ($value === '' && in_array($key, $primaryKey, true)) {
                // Skip marshalling '' for pk fields.
                continue;
            }
            $properties[$key] = $value;
        }

        if (!isset($options['fieldList'])) {
            $entity->set($properties);
            $entity->setErrors($errors);

            return $entity;
        }

        foreach ((array)$options['fieldList'] as $field) {
            if (array_key_exists($field, $properties)) {
                $entity->set($field, $properties[$field]);
            }
        }

        $entity->setErrors($errors);

        return $entity;
    }
public function one(array $data, array $options = [])
    {
        list($data, $options) = $this->_prepareDataAndOptions($data, $options);

        $primaryKey = (array)$this->_endpoint->getPrimaryKey();
        $resourceClass = $this->_endpoint->getResourceClass();
        /* @var \Muffin\Webservice\Model\Resource $entity */
        $entity = new $resourceClass();
        $entity->setSource($this->_endpoint->getRegistryAlias());

        if (isset($options['accessibleFields'])) {
            foreach ((array)$options['accessibleFields'] as $key => $value) {
                $entity->setAccess($key, $value);
            }
        }

        $errors = $this->_validate($data, $options, true);
        $properties = [];
        foreach ($data as $key => $value) {
            if (!empty($errors[$key])) {
                $entity->setInvalidField($key, $value);
                continue;
            }
            if ($value === '' && in_array($key, $primaryKey, true)) {
                // Skip marshalling '' for pk fields.
                continue;
            }
            $properties[$key] = $value;
        }

        if (!isset($options['fieldList'])) {
            $entity->set($properties);
            $entity->setErrors($errors);

            return $entity;
        }

        foreach ((array)$options['fieldList'] as $field) {
            if (array_key_exists($field, $properties)) {
                $entity->set($field, $properties[$field]);
            }
        }

        $entity->setErrors($errors);

        return $entity;
    }
public function one ( array $ data , array $ options = [ ] ) { list ( $ data , $ options ) = $ this -> _prepareDataAndOptions ( $ data , $ options ) ; $ primaryKey = ( array ) $ this -> _endpoint -> getPrimaryKey ( ) ; $ resourceClass = $ this -> _endpoint -> getResourceClass ( ) ; /* @var \Muffin\Webservice\Model\Resource $entity */ $ entity = new $ resourceClass ( ) ; $ entity -> setSource ( $ this -> _endpoint -> getRegistryAlias ( ) ) ; if ( isset ( $ options [ 'accessibleFields' ] ) ) { foreach ( ( array ) $ options [ 'accessibleFields' ] as $ key => $ value ) { $ entity -> setAccess ( $ key , $ value ) ; } } $ errors = $ this -> _validate ( $ data , $ options , true ) ; $ properties = [ ] ; foreach ( $ data as $ key => $ value ) { if ( ! empty ( $ errors [ $ key ] ) ) { $ entity -> setInvalidField ( $ key , $ value ) ; continue ; } if ( $ value === '' && in_array ( $ key , $ primaryKey , true ) ) { // Skip marshalling '' for pk fields. continue ; } $ properties [ $ key ] = $ value ; } if ( ! isset ( $ options [ 'fieldList' ] ) ) { $ entity -> set ( $ properties ) ; $ entity -> setErrors ( $ errors ) ; return $ entity ; } foreach ( ( array ) $ options [ 'fieldList' ] as $ field ) { if ( array_key_exists ( $ field , $ properties ) ) { $ entity -> set ( $ field , $ properties [ $ field ] ) ; } } $ entity -> setErrors ( $ errors ) ; return $ entity ; }
Hydrate one entity.

### Options:

* fieldList: A whitelist of fields to be assigned to the entity. If not present,
the accessible fields list in the entity will be used.
* accessibleFields: A list of fields to allow or deny in entity accessible fields.

@param array $data The data to hydrate.
@param array $options List of options
@return \Muffin\Webservice\Model\Resource
@see \Muffin\Webservice\Model\Endpoint::newEntity()
Hydrate one entity .