public function __construct($filePath, $parser = null) { $this->remember = Remember::ns('notoj'); $files = array(); foreach ((array) $filePath as $file) { if (!is_file($file) || !is_readable($file)) { throw new \RuntimeException("{$filePath} is not a file or cannot be read"); } $files[] = Path::normalize($file); } $this->files = $files; $this->annotations = new Annotations(); foreach ((array) $files as $file) { $this->doParse($file, $parser); } }
public function __construct($files) { $this->annotations = new Annotation\Annotations(); $loader = Remember::wrap('notoj', function ($args, $files) { $parser = new ClassInfo(); $files = array_filter($files, 'is_file'); $pFiles = array(); foreach ($files as $file) { $pFiles[] = new File($file, $parser); } return $pFiles; }); $files = is_array($files) ? $files : array($files); $files[] = 'filesystem'; foreach ($loader($files) as $f) { $this->add($f); } }
public function prepare() { $loader = Remember::wrap('cli', function ($args, $files) { $dirAnn = new Dir($args); return array($dirAnn->getCallable('cli'), $dirAnn->get('CliPlugin', 'Callable')); }); $Arg = new ReflectionClass('Symfony\\Component\\Console\\Input\\InputArgument'); $Option = new ReflectionClass('Symfony\\Component\\Console\\Input\\InputOption'); $console = new Application(); list($functions, $plugins) = $loader($this->dirs); foreach ($plugins as $plugin) { $name = current($plugin->getArgs()); $this->plugins[$name][] = $plugin->getObject(); } foreach ($functions as $function) { $opts = array(); $this->processCommandArgs($opts, 'Argument', $Arg, $function); $this->processCommandArgs($opts, 'Option', $Option, $function); $this->processWorker($opts, $function); $this->processPrompt($opts, $function); $this->registerCommand($console, $function, $opts); } return $console; }
public function readDirectory($path) { $filter = $this->filter; $parser = $this->Parser; $wrap = Remember::wrap('notoj', function ($dir, $files) use($parser) { $files = array_filter($files, $dir[0]); $classes = array(); foreach ($files as $file) { $classes[$file] = new File($file, $parser); } return $classes; }); foreach ($wrap(array('is_file', $path)) as $file => $obj) { if ($filter && !$filter(new SplFileInfo($file))) { continue; } $this->addFile($obj); } return $this->annotations; }
public function getFunctions($ann, &$isCached = null) { $ann = strtolower(str_replace("@", "", $ann)); $dirs = array_merge(array($ann), $this->dirs); $isCached = true; $loader = Remember::wrap('function-discovery', function ($args) use(&$isCached) { $functions = array(); $isCached = false; $query = array_shift($args); $fs = new Filesystem($args); foreach ($fs->get($query, 'Callable') as $annotation) { $function = $annotation->getObject(); $static = false; if ($function->isMethod()) { $callback = [$function->getClass()->getName(), $function->getName()]; $static = $function->isStatic(); } else { $callback = $function->getName(); } try { $name = strtolower($annotation->getArg()); } catch (Exception $e) { $name = null; } $annotations = []; foreach ($annotation->getParent() as $annotation) { $annotations[] = [strtolower($annotation->getName()), $annotation->getArgs()]; } $wrapper = new TFunction($function->getFile(), $callback, $static); $wrapper->setAnnotations($annotations); if ($name) { $functions[$name] = $wrapper; } else { $functions[] = $wrapper; } } return $functions; }); return $loader($dirs); }
<?php namespace Notoj\Test; use Notoj\ReflectionClass; use Notoj\ReflectionMethod; use Remember\Remember; require __DIR__ . "/../vendor/autoload.php"; if (!is_callable('_')) { function _($x) { return $x; } } function getReflection($class) { $class = explode("::", $class); return new ReflectionMethod($class[0], $class[1]); } @unlink(__DIR__ . "/tmp.cache"); Remember::setDirectory('/tmp/cache');