/** * @param Request $request * @param Response $response * @param InterceptorManager $interceptorManager */ public function __construct(Request $request, Response $response, InterceptorManager $interceptorManager) { $this->request = $request; $this->response = $response; $this->_event = new ControllerEvent($this, $interceptorManager); parent::__construct(); }
/** * @param $data */ public function __construct($data) { if (empty($data)) { return; } $this->_multi = is_array(current($data)) && is_int(key($data)); $this->_originalData = $data; if ($this->_multi) { $this->_data = $data; } else { $this->_data[] = $data; } $this->_length = count($this->_data); parent::__construct(); $this->_data = array_map(array($this, 'prepare'), $this->_data); }
/** * @param Request $request */ public function __construct(Request $request) { parent::__construct($request); $reflect = new \ReflectionClass($this); $props = $reflect->getProperties(\ReflectionProperty::IS_PUBLIC); // get public field foreach ($props as $prop) { $name = $prop->getName(); $setterName = 'set' . ucfirst($name); $this->_props[] = $name; // get value by default define $default = $prop->getValue($this); if (is_array($default)) { $value = $request->getArray($name); if (empty($value)) { $value = $default; } } else { $value = $request->get($name, $default); if (is_array($value)) { $value = $default; } } // set value to current var $this->_current = $value; if ($reflect->hasMethod($setterName)) { $method = $reflect->getMethod($setterName); if ($method->isPublic()) { $params = $method->getParameters(); if (1 == count($params)) { try { $this->{$setterName}($value); continue; } catch (ValidateException $e) { $this->_messages[$name] = $e->getMessage(); $prop->setValue($this, $value); $this->_isValid = false; } } } } } }