public function init() { $controller = \PMVC\plug('controller'); if (empty($controller)) { return !trigger_error('Need initial controller first', E_USER_WARNING); } $request = $controller->getRequest(); $method = $this->getMethod(); $request->setMethod($method); if ('GET' === $method) { $inputs =& $_GET; } else { $isJsonInput = 'application/json' === getenv('CONTENT_TYPE'); if ($isJsonInput || 'PUT' === $method) { $input = file_get_contents("php://input"); if ($isJsonInput) { $inputs = (array) \PMVC\fromJson($input); } else { parse_str($input, $inputs); } } else { $inputs =& $_POST; } } \PMVC\set($request, $inputs); }
/** * Test set object. */ public function testSetObject() { $arr = (object) [1, 2, 3]; $arr1 = []; \PMVC\set($arr1, $arr); $expected = [1, 2, 3]; $this->assertEquals($expected, $arr1); }
public function mergeDefault($inputs = array()) { if (empty($this->getDefault())) { return; } if (!\PMVC\isArray($inputs)) { $inputs = array(); } $arr = \PMVC\arrayReplace($this->getDefault(), $inputs); \PMVC\set($this, $arr); }
public function testProcessError() { $b = new PMVC\MappingBuilder(); $b->addAction('index', [_FUNCTION => ['FakeClass', 'index'], _FORM => 'FakeFailForm']); $b->addForward('error', [_PATH => 'hello', _TYPE => 'view']); $options = [\PMVC\ERRORS => [\PMVC\USER_ERRORS => 'erros', \PMVC\USER_LAST_ERROR => 'last'], _RUN_ACTION => 'index']; $mvc = \PMVC\plug('controller'); \PMVC\set($mvc, $options); $view = \PMVC\plug('view', [_CLASS => '\\PMVC\\FakeView']); $error = $mvc->process($b); $this->assertEquals($options[\PMVC\ERRORS][\PMVC\USER_ERRORS], $error[0]['v']['errors']); $this->assertEquals($options[\PMVC\ERRORS][\PMVC\USER_LAST_ERROR], $error[0]['v']['lastError']); }
public function testDefaultForm() { $test_str = 'Hello World!'; $b = new PMVC\MappingBuilder(); $b->addAction('index', [_FUNCTION => function () use($test_str) { return $test_str; }, _FORM => 'myForm']); $option = [_DEFAULT_FORM => 'FakeDefaultForm']; $mvc = \PMVC\plug('controller'); \PMVC\set($mvc, $option); $result = $mvc->process($b); $this->assertEquals($test_str, $result[0]); $this->assertEquals('aaa', \PMVC\getOption('fakeDefaultForm')); }
public function onMapRequest() { $request = $this->getRequest(); $uri = \PMVC\plug('url')->getPath(); $dispatch = $this->_route->getDispatch($this['method'], $uri); if (is_int($dispatch)) { http_response_code($dispatch); \PMVC\callPlugIn('dispatcher', 'stop', [true]); return !trigger_error('no match router found'); } \PMVC\set($request, $dispatch->var); if (is_string($dispatch->action)) { $this->setAppAction($dispatch->action); } else { $b = new \PMVC\MappingBuilder(); $b->addAction('index', $dispatch->action); $this->addMapping($b); } }
public function validate($params = array()) { \PMVC\set($this, $params); return $this->verifyCode($this['secret'], $this['one']); }
public function query($query) { $query = $this->queryToArray($query); return \PMVC\set($this[QUERY], $query); }