public function testHello() { $test_str = 'Hello World!'; $b = new PMVC\MappingBuilder(); $b->addAction('index', function () use($test_str) { return $test_str; }); $mvc = \PMVC\plug('controller'); $result = $mvc->process($b); $this->assertEquals($test_str, $result[0]); }
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); } }
<?php $b = new PMVC\MappingBuilder(); ${_INIT_CONFIG}[_CLASS] = 'SwaggerUiAction'; ${_INIT_CONFIG}[_INIT_BUILDER] = $b; $b->addAction('index', [${_INIT_CONFIG}[_CLASS], 'index']); $b->addAction('css', [${_INIT_CONFIG}[_CLASS], 'asset']); $b->addAction('lib', [${_INIT_CONFIG}[_CLASS], 'asset']); $b->addAction('swagger-ui.min.js', [${_INIT_CONFIG}[_CLASS], 'asset']); $b->addAction('fonts', [${_INIT_CONFIG}[_CLASS], 'asset']); $b->addAction('images', [${_INIT_CONFIG}[_CLASS], 'asset']); $b->addForward('home', array(_PATH => 'index', _TYPE => 'view')); \PMVC\getC()->store([_TEMPLATE_DIR => __DIR__ . '/themes/', _VIEW_ENGINE => "html"]); class SwaggerUiAction extends PMVC\Action { static function index($m, $f) { $go = $m['home']; return $go; } static function asset($m, $f) { $url = \PMVC\plug('url'); $c = \PMVC\getC(); $app = $c->getApp(); $pathInfo = $url->getPathInfo(); $path = str_replace('/' . $app . '/', '', $pathInfo); $asset = __DIR__ . '/' . 'themes/asset/' . $path; $fs = \PMVC\plug('file_list'); $fs->dump($asset); }
<?php $b = new PMVC\MappingBuilder(); ${_INIT_CONFIG}[_CLASS] = 'NewActionName'; ${_INIT_CONFIG}[_INIT_BUILDER] = $b; $b->addAction('index', array(_FUNCTION => array(${_INIT_CONFIG}[_CLASS], 'index'), _FORM => 'HelloVerify')); $b->addAction('lazy-index', array(_FUNCTION => array(${_INIT_CONFIG}[_CLASS], 'index_laziness'))); $b->addForward('home', array(_PATH => 'hello', _TYPE => 'view', _ACTION => 'lazy-index')); $b->addForward('laze', array(_PATH => 'laze', _TYPE => 'view')); class NewActionName extends PMVC\Action { static function index($m, $f) { $go = $m['home']; $go->set('text', ' world---' . microtime()); return $go; } static function index_laziness($m, $f) { $go = $m['laze']; $go->set('laze_text', 'This is laziness'); return $go; } } class HelloVerify extends PMVC\ActionForm { function validate() { //PMVC\plug("adkjfa;lsdkjf"); return true; }
<?php ini_set("memory_limit", "256M"); $b = new \PMVC\MappingBuilder(); ${_INIT_CONFIG}[_CLASS] = 'FileSign'; ${_INIT_CONFIG}[_INIT_BUILDER] = $b; $b->addAction('index', [_FORM => 'FileSignVerify']); \PMVC\plug('view_cli', ['flush' => true]); class FileSign extends \PMVC\Action { function index($m, $f) { $path = $f['path']; $pattern = $f['pattern']; $exclude = $f['exclude']; $log = $f['log']; \PMVC\plug('view_cli', ['plainText' => $log]); $go = $m['dump']; $go->set('Run', $path); $go->set('Pattern', $pattern); $go->set('Log', $log ? 'enable' : 'disable'); $files = PMVC\plug('file_list', ['hash' => true, 'maskKey' => $path, 'exclude' => $exclude])->ls($path, $pattern); ksort($files); foreach ($files as $k => $v) { $hash = \PMVC\value($v, ['hash']) ?: ''; if ($hash) { $hash = ',' . $hash; } $go->set($k . $hash); } return $go;