Пример #1
0
 public static function fromControllers(\bolt\browser\route\collection $collection)
 {
     $routes = [];
     // get all loaded classes
     if (($classes = b::getClassImplements('\\bolt\\browser\\route\\face')) != false) {
         foreach ($classes as $class) {
             if ($class->name === 'bolt\\browser\\controller' or !$class->hasProperty('routes') and !$class->hasMethod('getRoutes')) {
                 continue;
             }
             // skip our controller class and make sure we have at least $routes || getRoutes()
             $_ = ['ref' => $class, 'collection' => $class->hasProperty('routeCollection') ? $class->getStaticPropertyValue('routeCollection') : ['prefix' => ''], 'routes' => []];
             if ($class->hasProperty('routes')) {
                 $_['routes'] = array_merge($_['routes'], $class->getStaticPropertyValue('routes'));
             }
             if ($class->hasMethod('getRoutes')) {
                 $name = $class->name;
                 $_['routes'] = array_merge($_['routes'], $name::getRoutes());
             }
             $routes[] = $_;
         }
     }
     foreach ($routes as $class) {
         $c = new collection();
         // loop through routes
         foreach ($class['routes'] as $key => $route) {
             $name = b::param('name', false, $route);
             if (!$name and !is_string($key)) {
                 $name = "route" . rand(9, 999);
             } else {
                 if (!$name) {
                     $name = $key;
                 }
             }
             // no name
             unset($route['name']);
             // add our two default things
             $route['controller'] = $class['ref']->name;
             $route['action'] = b::param('action', false, $route);
             // loop through each part and set it
             $c->add($name, b::browser_route('create', $route));
         }
         // get our prefix vars
         extract(array_merge(['prefix' => '', 'requirements' => [], 'options' => [], 'host' => false, 'schemes' => []], $class['collection']), EXTR_OVERWRITE);
         // set prefix
         $c->addPrefix($prefix, $requirements, $options, $host, $schemes);
         // add this collection
         $collection->addCollection($c);
     }
     return null;
 }
Пример #2
0
 public function build($params = [])
 {
     // what method
     $method = $this->request->getMethod();
     // is there an action
     $action = b::param('_action', false, $params);
     // lets figure out what function we're going to call
     $try = ['dispatch', "{$method}{$action}", $action, $method];
     foreach ($try as $func) {
         if (method_exists($this, $func)) {
             break;
         }
     }
     // reflect the controller and method
     // and figure out what params we need
     $ref = b::getReflectionClass(get_called_class());
     // get
     $args = $this->getArgsFromMethodRef($ref->getMethod($func), $params);
     // wonderfull, lets call the function and figure out what
     // they respond with
     return call_user_func_array([$this, $func], $args);
 }
Пример #3
0
 public function __construct($config = [])
 {
     $this->_file = b::param('file', false, $config);
     $this->_vars = b::param('vars', [], $config);
     $this->_context = b::param('context', false, $config);
 }
Пример #4
0
 public function processFile($path, $config = [])
 {
     $rel = b::param('rel', false, $config);
     $url = b::param('url', false, $config);
     $useGlobalFilters = b::param('useGlobalFilters', true, $config);
     // get the file
     $file = $this->getFile($path);
     $root = pathinfo($path)['dirname'];
     $ext = pathinfo($path)['extension'];
     // get it's tree
     $content = $file->getContent();
     if (empty($content)) {
         return $content;
     }
     $inc = [];
     // parse the string
     $found = $this->parseString($content, $root);
     if (b::param('filterOnly', false, $config) === 'true') {
         $found = ['filter' => $found['filter']];
     }
     $tree = $this->getCombinedTree($found, $ext);
     $reduce = function ($items, $reduce) {
         $resp = [];
         foreach ($items as $key => $files) {
             $resp[] = $key;
             $resp += $reduce($files, $reduce);
         }
         return $resp;
     };
     // loop through each file and append
     foreach (array_unique($reduce($tree, $reduce)) as $f) {
         if ($f === $path) {
             continue;
         }
         $inc[] = $this->processFile($f);
     }
     $source = false;
     $sourcePath = false;
     $targetPath = false;
     if ($url) {
         $parts = parse_url($url);
         $source = "{$parts['scheme']}://{$parts['host']}";
         $targetPath = trim($parts['path'], '/');
         $sourcePath = $targetPath . '/' . trim($rel, '/');
     }
     $inc[] = $content;
     $a = new StringAsset(implode("\n", $inc), [], $source, $sourcePath);
     if ($targetPath) {
         $a->setTargetPath($targetPath);
     }
     // use filters
     if ($useGlobalFilters !== false) {
         if (array_key_exists($ext, $this->_filters)) {
             foreach ($this->_filters[$ext] as $filter) {
                 if ($filter[1] === false and b::env() === 'dev') {
                     continue;
                 }
                 $a->ensureFilter(new $filter[0]());
             }
         }
         foreach ($this->_filters['*'] as $filter) {
             if ($filter[1] === false and b::env() === 'dev') {
                 continue;
             }
             $a->ensureFilter(new $filter[0]());
         }
     }
     $a->ensureFilter(new CssRewriteFilter());
     return trim($a->dump());
 }
Пример #5
0
 public function test_param()
 {
     $this->assertEquals('poop', b::param('poop', false, ['poop' => 'poop']));
     $this->assertEquals('poop', b::param('none', 'poop', []));
 }
Пример #6
0
 public function route($route = [])
 {
     $name = b::param('name', 'route' . rand(9, 999), $route);
     $r = b::browser_route('create', $route);
     $this->_routes->add($name, $r);
     return $r;
 }