lithium\core\Object::_init PHP Method

_init() protected method

For example, given the following: class Bar extends \lithium\core\Object { protected $_autoConfig = array('foo'); protected $_foo; } $instance = new Bar(array('foo' => 'value')); The $_foo property of $instance would automatically be set to 'value'. If $_foo was an array, $_autoConfig could be set to array('foo' => 'merge'), and the constructor value of 'foo' would be merged with the default value of $_foo and assigned to it.
See also: lithium\core\Object::$_autoConfig
protected _init ( ) : void
return void
    protected function _init()
    {
        foreach ($this->_autoConfig as $key => $flag) {
            if (!isset($this->_config[$key]) && !isset($this->_config[$flag])) {
                continue;
            }
            if ($flag === 'merge') {
                $this->{"_{$key}"} = $this->_config[$key] + $this->{"_{$key}"};
            } else {
                $this->{"_{$flag}"} = $this->_config[$flag];
            }
        }
    }

Usage Example

Beispiel #1
0
	/**
	 * Initializes default rules to use.
	 *
	 * @return void
	 */
	protected function _init() {
		parent::_init();

		$this->_rules += array(
			'allowAll' => function() {
				return true;
			},
			'denyAll' => function() {
				return false;
			},
			'allowAnyUser' => function($user) {
				return $user ? true : false;
			},
			'allowIp' => function($user, $request, $options) {
				$options += array('ip' => false);

				if (is_string($options['ip']) && strpos($options['ip'], '/') === 0) {
					return (boolean) preg_match($options['ip'], $request->env('REMOTE_ADDR'));
				}
				if (is_array($options['ip'])) {
					return in_array($request->env('REMOTE_ADDR'), $options['ip']);
				}
				return $request->env('REMOTE_ADDR') == $options['ip'];
			}
		);
	}
All Usage Examples Of lithium\core\Object::_init