Cake\Controller\Component::__get PHP 메소드

__get() 공개 메소드

Magic method for lazy loading $components.
public __get ( string $name ) : mixed
$name string Name of component to get.
리턴 mixed A Component object or null.
    public function __get($name)
    {
        if (isset($this->_componentMap[$name]) && !isset($this->{$name})) {
            $config = (array) $this->_componentMap[$name]['config'] + ['enabled' => false];
            $this->{$name} = $this->_registry->load($this->_componentMap[$name]['class'], $config);
        }
        if (!isset($this->{$name})) {
            return null;
        }
        return $this->{$name};
    }

Usage Example

 /**
  * Magic accessor for backward compatibility for property `$sessionKey`.
  *
  * @param string $name Property name
  * @return mixed
  */
 public function __get($name)
 {
     if ($name === 'sessionKey') {
         return $this->storage()->config('key');
     }
     return parent::__get($name);
 }