예제 #1
0
 private function doCompile(string $clsName = '', string $indent = '    ') : UserClass
 {
     if ($clsName == '') {
         $clsName = 'Fruit\\RouteKit\\GeneratedMux';
     }
     $gen = new UserClass($clsName);
     $gen->implementInterface('Fruit\\RouteKit\\Router');
     $in1 = $indent;
     $in2 = $in1 . $in1;
     $stateMap = array();
     $varMap = array();
     $funcMap = array();
     $funcCnt = 0;
     foreach ($this->roots as $m => $root) {
         $root->fillID(0);
         $stateMap[$m] = $root->stateTable(array());
         $varMap[$m] = $root->varTable(array());
         $funcMap[$m] = $root->funcTable(array(), 0, $this->interceptor);
         // make handlers
         foreach ($funcMap[$m] as $id => $body) {
             $fn = sprintf('f%d', $funcCnt++);
             $gen->addMethod('private static', $fn, array('$method', '$url', '$params', '$int'), $body);
             $funcMap[$m][$id] = $fn;
         }
     }
     $gen->addStaticVar('stateMap', $stateMap, 'private');
     $gen->addStaticVar('varMap', $varMap, 'private');
     $gen->addStaticVar('funcMap', $funcMap, 'private');
     $gen->addPrivateProperty('interceptor', null);
     // make dispatcher
     $func = array();
     $func[] = 'list($f, $params) = \\Fruit\\RouteKit\\Mux::findRoute(';
     $func[] = '    $method, $uri,';
     $func[] = '    self::$stateMap,';
     $func[] = '    self::$varMap,';
     $func[] = '    self::$funcMap';
     $func[] = ');';
     $func[] = '';
     $func[] = 'if ($f === null) {';
     $func[] = '    throw new \\Exception(\'No route for \' . $uri);';
     $func[] = '}';
     $func[] = '';
     $func[] = 'return self::$f($method, $uri, $params, $this->interceptor);';
     $gen->addMethod('public', 'dispatch', array('string $method', 'string $uri'), $func);
     if ($this->interceptor !== null) {
         $func = array('$this->interceptor = ' . var_export($this->interceptor, true) . ';');
         $gen->addMethod('public', '__construct', array(), $func);
     }
     $gen->addMethod('public', 'getInterceptor', array(), array('return $this->interceptor;'));
     return $gen;
 }
예제 #2
0
 public function __construct($title)
 {
     $class = Inflector::classify(preg_replace('/\\W+/', ' ', $title));
     parent::__construct($class);
     $this->extendClass('PHPUnit_Framework_TestCase', true);
 }
예제 #3
0
 /**
  * @param Block $block
  * @param ClassFile $class
  * @param $config
  * @return bool
  */
 private static function openInMenuBlock(Block $block, UserClass $class, $config)
 {
     fwrite(STDOUT, 'processing: ' . $config->module . ':' . $config->controller . ':' . $config->action . "\n");
     $elements = Reverse::getElements($config);
     if ($elements === false) {
         return false;
     }
     $tryStmt = new TryCatchStatement();
     $block->appendRenderable($tryStmt);
     $tryBlock = $tryStmt->tryBlock;
     $tryBlock->appendRenderable(new Statement(new AssignExpr('$session', new MethodCall('$this', 'getLoggedSession'))));
     $tryBlock->appendRenderable(new Statement(new MethodCall('$this', 'openInMenu', [new ObjectProperty('$this', 'mapModule'), '$session'])));
     $tryBlock->appendRenderable(new Statement(new MethodCall('$this', 'checkWait', ['$session'])));
     $tryBlock->appendRenderable(new Statement(new AssignExpr('$page', new MethodCall('$session', 'getPage'))));
     /** @var FormElement $input */
     foreach ($elements->getInputs() as $input) {
         $tryBlock->appendLine('');
         $tryBlock->appendRenderable(new Comment('input type: ' . $input->getType() . ' label: ' . $input->getLabel()));
         $tryBlock->appendRenderable(new AssignStatement(new Raw($input->getPhpName() . 'Input'), new MethodCall('$page', $input->getFindMethod(), $input->getFindArgs())));
     }
     /** @var Button $button */
     foreach ($elements->getButtons() as $button) {
         $tryBlock->appendLine('');
         //$tryBlock->appendRenderable(
         //    new CommentBlock(explode("\n", var_export($button, true)))
         //);
         $tryBlock->appendRenderable(new Comment('button label: ' . $button->getLabel()));
         $tryBlock->appendRenderable(new AssignStatement(new Raw($button->getPhpName() . 'Button'), new MethodCall('$page', $button->getFindMethod(), $button->getFindArgs())));
     }
     $tryBlock->appendLine('');
     $tryBlock->appendLine('');
     $tryBlock->appendRenderable(new Comment('Implement test here.'));
     $tryBlock->appendLine('');
     $tryBlock->appendLine('');
     $tryBlock->appendRenderable(new Statement(new MethodCall('$this', 'checkErrors', ['$session'])));
     $tryBlock->appendLine('');
     $tryBlock->appendLine('');
     $tryBlock->appendRenderable(new Comment('Remove the following lines when you implement this test.'));
     /*        $tryBlock->appendRenderable(
               new Statement(new StaticMethodCall('static', 'markTestIncomplete', ['This test has not been implemented yet . '])));*/
     $tryBlock->appendLine('');
     $tryBlock->appendLine('');
     $throwBlock = $tryStmt->catchBlock;
     $throwBlock->appendRenderable(new Statement(new MethodCall(new StaticMethodCall('Mink', 'getInstance'), 'ss')));
     $throwBlock->appendRenderable(new Comment('Remove the following lines when you implement this test.'));
     /*        $throwBlock->appendRenderable(
               new Statement(new StaticMethodCall('static', 'markTestIncomplete', ['This test has not been implemented yet . '])));*/
     if ($elements->getDataTables()) {
         foreach ($elements->getDataTables() as $key => $dataTable) {
             $doc = new CommentBlock();
             $doc->appendLine('Datatable tests');
             $dtTest = new ClassMethod('testDataTable' . ($key + 1));
             $dtTest->setScope('public');
             //$dtTest->setCommentBlock($doc);
             $block = $dtTest->getBlock();
             self::createDataTableTest($dataTable, $block);
             $class->addMethodObject($dtTest);
         }
     }
     return true;
 }