Cake\View\JsonView::_dataToSerialize PHP Метод

_dataToSerialize() защищенный Метод

Returns data to be serialized.
protected _dataToSerialize ( array | string | boolean $serialize = true ) : mixed
$serialize array | string | boolean The name(s) of the view variable(s) that need(s) to be serialized. If true all available view variables will be used.
Результат mixed The data to serialize.
    protected function _dataToSerialize($serialize = true)
    {
        if ($serialize === true) {
            $data = array_diff_key($this->viewVars, array_flip($this->_specialVars));
            if (empty($data)) {
                return null;
            }
            return $data;
        }
        if (is_array($serialize)) {
            $data = [];
            foreach ($serialize as $alias => $key) {
                if (is_numeric($alias)) {
                    $alias = $key;
                }
                if (array_key_exists($key, $this->viewVars)) {
                    $data[$alias] = $this->viewVars[$key];
                }
            }
            return !empty($data) ? $data : null;
        }
        return isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null;
    }

Usage Example

 /**
  * Returns data to be serialized.
  *
  * @param array|string|bool $serialize The name(s) of the view variable(s) that
  *   need(s) to be serialized. If true all available view variables will be used.
  * @return mixed The data to serialize.
  */
 protected function _dataToSerialize($serialize = true)
 {
     $data = parent::_dataToSerialize($serialize);
     $serializer = $this->getSerializer();
     $includes = $this->get('_includes');
     $manager = new Manager();
     $manager->setSerializer($serializer);
     if ($includes) {
         $manager->parseIncludes($includes);
     }
     if (is_array($data)) {
         foreach ($data as $varName => &$var) {
             $var = $this->transform($manager, $var, $varName);
         }
         unset($var);
     } else {
         $data = $this->transform($manager, $data);
     }
     return $data;
 }