public function generateBindedParameter($name, CodeWriter $writer) { if (empty($name)) { $writer->write('iterator_to_array($rq)'); } else { $writer->write('$rq['); $writer->literal($name); $writer->write(']'); } }
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; }
public function generateParameter(Parameter $parameter, CodeWriter $writer) { $class = $parameter->getClass(); if ($class) { $writer->write("\\", $class->name, " "); } else { if ($parameter->isArray()) { $writer->write("array "); } else { if ($parameter->isCallable()) { $writer->write("callable "); } } } $writer->write("\$", $parameter->name); }
public function get(Key $key) { $lazyClass = "Lazy__" . $key->hash(); if ($this->codeStorage->load($lazyClass)) { return $lazyClass; } $type = $this->reflection->get($key->getType()); $writer = new CodeWriter(); $writer->write("class ", $lazyClass); $type->isInterface() ? $writer->write(" implements ") : $writer->write(" extends "); $writer->write($type->name, " {"); $this->lazyGen->generate($type, $writer); $writer->write("}"); $this->codeStorage->store($lazyClass, $writer); return $lazyClass; }
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("}"); }
public function getBinder($domainName) { $binder = "DomainBinder__" . md5($domainName); if ($this->storage->load($binder)) { return $binder; } $writer = new CodeWriter(); $writer->write("class ", $binder, "{"); $writer->indent(); $writer->write('static function newInstance($d, $n, $b) {'); $writer->indent(); $this->gen->generateNewInstance($domainName, $writer); $writer->outdent(); $writer->writeln("}"); $writer->write('static function bind($d, $i, $b) {'); $writer->indent(); $this->gen->generateBind($domainName, $writer); $writer->outdent(); $writer->writeln("}"); $writer->outdent(); $writer->write("}"); $this->storage->store($binder, $writer); return $binder; }
public function get(array $action) { $adapter = "ActionAdapter__" . md5("{$action[0]}::{$action[1]}"); if ($this->storage->load($adapter)) { return $adapter; } $method = $this->reflection->get($action[0])->getMethod($action[1]); $writer = new CodeWriter(); $writer->write("class ", $adapter, " {"); $writer->indent(); $method->isStatic() ? $this->static->generate($method, $writer) : $this->instance->generate($method, $writer); $writer->outdent(); $writer->writeln("}"); $this->storage->store($adapter, $writer); return $adapter; }
public function get() { $router = "InvertedIndex__{$this->hash}"; if ($this->storage->load($router)) { return new $router(); } $writer = new CodeWriter(); $writer->writeln("use Spot\\App\\Web\\Impl\\Router\\InvertedIndexRouter;"); $writer->writeln("use Spot\\App\\Web\\Impl\\Router\\InvertedIndex\\MethodIndex;"); $writer->writeln("use Spot\\App\\Web\\Impl\\Router\\InvertedIndex\\AjaxIndex;"); $writer->writeln("use Spot\\App\\Web\\Impl\\Router\\InvertedIndex\\StaticPathIndex;"); $writer->writeln("use Spot\\App\\Web\\Impl\\Router\\InvertedIndex\\PrefixPathIndex;"); $writer->writeln("use Spot\\App\\Web\\Impl\\Router\\InvertedIndex\\RegexPathIndex;"); $writer->write("class ", $router, " extends InvertedIndexRouter {"); $writer->indent(); $this->gen->generate($writer); $writer->outdent(); $writer->writeln("}"); $this->storage->store($router, $writer); return new $router(); }
public function generateMethodCall(Method $method, CodeWriter $writer) { $writer->write('$i'); if ($this->isTypeBinded($method)) { $writer->write('->fork([new self($rq)])'); } $writer->write('->getInstance('); $writer->literal($method->getType()->name); $writer->write(')->', $method->name); }
public function writeTypedBinding(Type $class, $name, CodeWriter $writer) { $writer->write('is_array($b['); $writer->literal($name); $writer->write(']) ? $d->newInstance('); $writer->literal($class->name); $writer->write(', $b['); $writer->literal($name); $writer->write(']) : $d->find('); $writer->literal($class->name); $writer->write(', $b['); $writer->literal($name); $writer->write('])'); }
public function generateParameter(Parameter $parameter, CodeWriter $writer) { if ($parameter->getClass()) { $writer->write($parameter->getClass()->name, " "); } else { if ($parameter->isArray()) { $writer->write("array "); } } $writer->write('$', $parameter->name); if ($parameter->isDefaultValueAvailable()) { $writer->write(" = "); $writer->literal($parameter->getDefaultValue()); } }
public function generateMethodCall(Method $method, CodeWriter $writer) { $writer->write($method->getType()->name, "::", $method->name); }