Пример #1
0
 public function generate(CodeWriter $writer)
 {
     $actions = $names = $methods = $staticPaths = $regexPaths = $prefixPaths = [];
     $ajax = [true => [], false => []];
     foreach ($this->scanner->scan() as $i => $mapping) {
         $route = $mapping->route;
         $action = $mapping->action;
         if ($this->compiler->checkSymbol($route->value)) {
             $pattern = $this->compiler->compile($route->value);
             $regexPaths[$i] = $pattern;
             $prefix = strtok($route->value, "*{(");
             $prefixPaths[$prefix][$i] = 1;
         } else {
             $staticPaths[$route->value][$i] = 1;
         }
         $actions[$i] = $action;
         foreach ((array) $route->method as $method) {
             $methods[$method][$i] = 1;
         }
         if ($route->ajax === null) {
             $ajax[true][$i] = $ajax[false][$i] = 1;
         } else {
             $ajax[$route->ajax][$i] = 1;
         }
         if ($route->name) {
             $name = ["params" => array_values($this->compiler->parse($route->value)), "uri" => preg_replace('/\\{\\$(.*?)\\}/', '$1', $route->value)];
             $names[$route->name] = $name;
         }
     }
     $writer->write("function __construct() {");
     $writer->indent();
     $writer->write("parent::__construct(");
     $writer->indent();
     $writer->writeln(var_export($names, true), ", ");
     $writer->writeln(var_export($actions, true), ", ");
     $writer->writeln("new MethodIndex(", var_export($methods, true), "), ");
     $writer->writeln("new AjaxIndex(", var_export($ajax, true), "), ");
     $writer->writeln("new StaticPathIndex(", var_export($staticPaths, true), "), ");
     $writer->writeln("new PrefixPathIndex(", var_export($prefixPaths, true), "), ");
     $writer->write("new RegexPathIndex(", var_export($regexPaths, true), ")");
     $writer->outdent();
     $writer->write(");");
     $writer->outdent();
     $writer->writeln("}");
 }
Пример #2
0
 public function generate(Type $type, CodeWriter $writer)
 {
     $writer->writeln('public $i, $k, $d;');
     $writer->write('function __construct(Spot\\Inject\\Injector $i, Spot\\Inject\\Key $k) {');
     $writer->indent();
     $writer->write('$this->i = $i;');
     $writer->write('$this->k = $k;');
     $writer->outdent();
     $writer->writeln('}');
     $writer->write("function __() {");
     $writer->indent();
     $writer->write('return $this->d ?: $this->d = $this->i->get($this->k);');
     $writer->outdent();
     $writer->write("}");
     foreach ($type->getMethods(Method::IS_PUBLIC) as $method) {
         if (!$method->isConstructor()) {
             $this->generateMethod($method, $writer);
         }
     }
 }
Пример #3
0
 public function get(Modules $modules)
 {
     $adapter = "ModulesAdapter__" . $modules->hash();
     if ($this->storage->load($adapter)) {
         return $adapter;
     }
     $this->builder->build();
     $writer = new CodeWriter();
     $writer->write("class ", $adapter, " {");
     $writer->indent();
     $writer->write("const SINGLETONS_SIZE = ", $this->singletons->getSize(), ";");
     $writer->outdent();
     $writer->write("}");
     $this->storage->store($adapter, $writer);
     return $adapter;
 }
Пример #4
0
 public function generate(Type $type, CodeWriter $writer)
 {
     $writer->write('function __construct($s, $m, $i, $r, $d) {');
     $writer->indent();
     $writer->writeln('$this->s = $s;');
     $writer->writeln('$this->m = $m;');
     $writer->writeln('$this->i = $i;');
     $writer->writeln('$this->r = $r;');
     $writer->write('$this->d = $d;');
     $writer->outdent();
     $writer->writeln("}");
     foreach ($type->getMethods(Method::IS_PUBLIC) as $method) {
         if ($method->isConstructor()) {
             continue;
         }
         if ($this->pointCuts->matches($method)) {
             $this->generateMethod($method, $this->pointCuts->getAdvices($method), $writer);
         } else {
             $this->generateDelegateMethod($method, $writer);
         }
     }
 }