Using Route objects, these two operations can be handled in a reciprocally consistent way. For example, if you wanted the /login URL to be routed to myapp\controllers\SessionsController::add(), you could set up a route like the following in config/routes.php: {{{ use lithium\net\http\Router; Router::connect('/login', array('controller' => 'Sessions', 'action' => 'add')); -- or -- Router::connect('/login', 'Sessions::add'); }}} Not only would that correctly route all requests for /login to SessionsController::add(), but any time the framework generated a route with matching parameters, Router would return the correct short URL. While most framework components that work with URLs (and utilize routing) handle calling the Router directly (i.e. controllers doing redirects, or helpers generating links), if you have a scenario where you need to call the Router directly, you can use the match() method. This allows you to keep your application's URL structure nicely decoupled from the underlying software design. For more information on parsing and generating URLs, see the parse() and match() methods.
Inheritance: extends lithium\core\StaticObject
示例#1
0
 public function tearDown()
 {
     Router::reset();
     foreach ($this->_routes as $route) {
         Router::connect($route);
     }
 }
示例#2
0
 /**
  * Create navigation link compatible with `Twitter Bootstrap` markup.
  * Instead of plain `<a/>` output this method wrap anchor in `<li/>`. If current url is url of
  * wrapped `<a/>` add `active` class to `<li/>` wrapper.
  * For example:
  * {{{
  *   $this->backend->nav('Test', '/');
  *   // outputs:
  *   // <li><a href="/">Test</a></li>
  *   // if current url is url of anchor:
  *   // <li class="active"><a href="/">Test</a></li>
  * }}}
  *
  * @param $title
  * @param mixed $url
  * @param array $options Add following options to link:
  *     - `'wrapper-options'` _array_: Options that will be passed to `'nav-link'`
  *     - `'return'` _string_: Define would you like `'html'` output or `'array'` that contains two
  *     keys `'active'` _boolean_ and `'html'` used by `dropdown` method for example to know when
  *     to add `'active'` class to parent.
  *
  * @return array|string
  *
  * @see lithium\template\helper\Html::link()
  */
 public function nav($title, $url = null, array $options = array())
 {
     $defaults = array('wrapper-options' => array(), 'return' => 'html');
     list($scope, $options) = $this->_options($defaults, $options);
     $request = $this->_context->request();
     $currentUrl = $request->env('base') . $request->url;
     $matchedUrl = Router::match($url, $request);
     $active = false;
     if ($currentUrl === $matchedUrl || $currentUrl === $matchedUrl . '/index') {
         $active = true;
         if (isset($scope['wrapper-options']['class'])) {
             $scope['wrapper-options']['class'] .= ' active';
         } else {
             $scope['wrapper-options']['class'] = 'active';
         }
     }
     $link = $this->link($title, $url, $options);
     $html = $this->_render(__METHOD__, 'nav-link', array('options' => $scope['wrapper-options'], 'link' => $link));
     if ($scope['return'] === 'html') {
         return $html;
     }
     if ($scope['return'] === 'array') {
         return compact('active', 'html');
     }
 }
示例#3
0
 /**
  * Compare $url with $mask. Returns true if there is a match !
  *
  * @param  mixed $url   String, array or Request : url to test
  * @param  array  $mask Mask, in a Request::$params form
  * @return bool         Yep/nope ?
  */
 public static function match($url, array $mask)
 {
     // Multiple $url types
     if ($url instanceof Request) {
         $test = Router::parse($url);
     } elseif (is_string($url)) {
         $request = new Request();
         $request->url = $url;
         $test = Router::parse($request);
     } else {
         $test = $url;
     }
     foreach ($mask as $key => $value) {
         if (!isset($test[$key])) {
             return false;
         }
         if (is_array($value) && !static::match($mask[$key], $test[$key])) {
             return false;
         }
         if (is_string($value) && strtolower($value) !== strtolower($test[$key])) {
             return false;
         }
     }
     return true;
 }
示例#4
0
 function teardown()
 {
     Router::reset();
     foreach ($this->_routes as $route) {
         Router::connect($route);
     }
     unset($this->analytics);
 }
示例#5
0
 /**
  * Clean up after the test.
  *
  * @return void
  */
 public function tearDown()
 {
     Router::connect(null);
     $this->_routes->each(function ($route) {
         Router::connect($route);
     });
     unset($this->html);
 }
示例#6
0
 public function setUp()
 {
     $this->html = new Html();
     $this->mock = new MockHtml();
     Router::connect('/test/{:args}', array('controller' => '\\lithium\\test\\Controller'));
     Router::connect('/test', array('controller' => '\\lithium\\test\\Controller'));
     $this->request = new Request(array('base' => null, 'env' => array('PHP_SELF' => '/', 'DOCUMENT_ROOT' => '/')));
 }
 public function testRun()
 {
     Router::connect('/', array('controller' => 'test', 'action' => 'test'));
     $request = new Request();
     $request->url = '/';
     MockDispatcher::run($request);
     $result = end(MockDispatcher::$dispatched);
     $expected = array('controller' => 'test', 'action' => 'test');
     $this->assertEqual($expected, $result->params);
 }
 public function setUp()
 {
     $this->_routes = Router::get();
     Router::reset();
     Router::connect('/{:controller}/{:action}/page/{:page:[0-9]+}');
     $request = new Request();
     $request->params = array('controller' => 'posts', 'action' => 'index');
     $request->persist = array('controller');
     $this->context = new MockRenderer(compact('request'));
     $this->pagination = new Pagination(array('context' => $this->context));
 }
示例#9
0
 /**
  * Clean up after the test.
  */
 public function tearDown()
 {
     Router::reset();
     foreach ($this->_routes as $scope => $routes) {
         Router::scope($scope, function () use($routes) {
             foreach ($routes as $route) {
                 Router::connect($route);
             }
         });
     }
     unset($this->html);
 }
示例#10
0
 public function testConfigManipulation()
 {
     $config = MockDispatcher::config();
     $expected = array('rules' => array());
     $this->assertEqual($expected, $config);
     MockDispatcher::config(array('rules' => array('admin' => array('action' => 'admin_{:action}'))));
     Router::connect('/', array('controller' => 'test', 'action' => 'test', 'admin' => true));
     MockDispatcher::run(new Request(array('url' => '/')));
     $result = end(MockDispatcher::$dispatched);
     $expected = array('action' => 'admin_test', 'controller' => 'Test', 'admin' => true);
     $this->assertEqual($expected, $result->params);
 }
示例#11
0
 /**
  * Tests that URLs are properly escaped by the URL handler.
  */
 public function testUrlAutoEscaping()
 {
     Router::connect('/{:controller}/{:action}/{:id}');
     $this->assertEqual('/<foo>/<bar>', $this->subject->url('/<foo>/<bar>'));
     $result = $this->subject->url(array('Controller::action', 'id' => '<script />'));
     $this->assertEqual('/controller/action/<script />', $result);
     $this->subject = new Simple(array('response' => new Response(), 'view' => new View(), 'request' => new Request(array('base' => '', 'env' => array('HTTP_HOST' => 'foo.local')))));
     $this->assertEqual('/&lt;foo&gt;/&lt;bar&gt;', $this->subject->url('/<foo>/<bar>'));
     $result = $this->subject->url(array('Controller::action', 'id' => '<script />'));
     $this->assertEqual('/controller/action/&lt;script /&gt;', $result);
     $result = $this->subject->url(array('Posts::index', '?' => array('foo' => 'bar', 'baz' => 'dib')));
     $this->assertEqual('/posts?foo=bar&baz=dib', $result);
 }
示例#12
0
 protected function _restoreCtrlContext()
 {
     Router::reset();
     foreach ($this->_context['routes'] as $scope => $routes) {
         Router::scope($scope, function () use($routes) {
             foreach ($routes as $route) {
                 Router::connect($route);
             }
         });
     }
     foreach ($this->_context['scopes'] as $scope => $attachment) {
         Router::attach($scope, $attachment);
     }
     Router::scope($this->_context['scope']);
 }
示例#13
0
 /**
  * Fetch data for current path
  * On first access return HTML
  * Next time you fetch via AJAX return just JSON that we render client side
  * 
  * html:method GET
  */
 public function index()
 {
     $path = $this->request->args ? join('/', $this->request->args) : null;
     $data = Location::ls($path);
     if ($data === false) {
         return $this->redirect($this->_link);
     }
     $breadcrumb = array(array('Index', 'url' => Router::match($this->_link, $this->request, array('absolute' => true))));
     $args = array();
     foreach ($this->request->args as $arg) {
         $args[] = $arg;
         $this->_link += array('args' => $args);
         $breadcrumb[] = array($arg, 'url' => Router::match($this->_link, $this->request, array('absolute' => true)));
     }
     $breadcrumb[count($breadcrumb) - 1]['url'] = null;
     if ($this->request->is('ajax')) {
         return $this->render(array('json' => compact('data', 'breadcrumb')));
     }
     return compact('data', 'breadcrumb');
 }
示例#14
0
 public function upload()
 {
     if (!$this->request->is('ajax')) {
         return array();
     }
     $model = $this->model;
     $this->_render['type'] = 'json';
     $allowed = '*';
     $file = $this->_upload(compact('allowed'));
     if ($file['error'] !== UPLOAD_ERR_OK) {
         return $file;
     }
     $result = $model::init($file);
     if (!empty($result['asset'])) {
         $result['message'] = !empty($result['success']) ? 'upload successful' : 'file already present';
         $result['url'] = Router::match(array('library' => 'radium', 'controller' => 'assets', 'action' => 'view', 'id' => $result['asset']->id()), $this->request, array('absolute' => true));
         // unset($result['asset']);
     }
     // if ($result['success']) {
     // 	unset($result['asset']);
     // }
     return $result;
 }
示例#15
0
 public function testConfigManipulation()
 {
     $config = MockDispatcher::config();
     $expected = array('rules' => array());
     $this->assertEqual($expected, $config);
     MockDispatcher::config(array('rules' => array('admin' => array('action' => 'admin_{:action}'))));
     Router::connect('/', array('controller' => 'test', 'action' => 'test', 'admin' => true));
     MockDispatcher::run(new Request(array('url' => '/')));
     $result = end(MockDispatcher::$dispatched);
     $expected = array('action' => 'admin_test', 'controller' => 'Test', 'admin' => true);
     $this->assertEqual($expected, $result->params);
     MockDispatcher::config(array('rules' => array('action' => array('action' => function ($params) {
         return Inflector::camelize(strtolower($params['action']), false);
     }))));
     MockDispatcher::$dispatched = array();
     Router::reset();
     Router::connect('/', array('controller' => 'test', 'action' => 'TeST-camelize'));
     MockDispatcher::run(new Request(array('url' => '/')));
     $result = end(MockDispatcher::$dispatched);
     $expected = array('action' => 'testCamelize', 'controller' => 'Test');
     $this->assertEqual($expected, $result->params);
     MockDispatcher::config(array('rules' => function ($params) {
         if (isset($params['admin'])) {
             return array('special' => array('action' => 'special_{:action}'));
         }
         return array();
     }));
     MockDispatcher::$dispatched = array();
     Router::reset();
     Router::connect('/', array('controller' => 'test', 'action' => 'test', 'admin' => true));
     Router::connect('/special', array('controller' => 'test', 'action' => 'test', 'admin' => true, 'special' => true));
     MockDispatcher::run(new Request(array('url' => '/')));
     $result = end(MockDispatcher::$dispatched);
     $expected = array('action' => 'test', 'controller' => 'Test', 'admin' => true);
     $this->assertEqual($expected, $result->params);
     MockDispatcher::run(new Request(array('url' => '/special')));
     $result = end(MockDispatcher::$dispatched);
     $expected = array('action' => 'special_test', 'controller' => 'Test', 'admin' => true, 'special' => true);
     $this->assertEqual($expected, $result->params);
 }
示例#16
0
 * the primary key of the database object, and can be accessed in the controller as
 * `$this->request->id`.
 *
 * If you're using a relational database, such as MySQL, SQLite or Postgres, where the primary key
 * is an integer, uncomment the routes below to enable URLs like `/posts/edit/1138`,
 * `/posts/view/1138.json`, etc.
 */
// Router::connect('/{:controller}/{:action}/{:id:\d+}.{:type}', array('id' => null));
// Router::connect('/{:controller}/{:action}/{:id:\d+}');
/**
 * If you're using a document-oriented database, such as CouchDB or MongoDB, or another type of
 * database which uses 24-character hexidecimal values as primary keys, uncomment the routes below.
 */
// Router::connect('/{:controller}/{:action}/{:id:[0-9a-f]{24}}.{:type}', array('id' => null));
// Router::connect('/{:controller}/{:action}/{:id:[0-9a-f]{24}}');
/**
 * ### Default controller/action routes
 *
 * Finally, connect the default route. This route acts as a catch-all, intercepting requests in the
 * following forms:
 *
 * - `/foo/bar`: Routes to `FooController::bar()` with no parameters passed.
 * - `/foo/bar/param1/param2`: Routes to `FooController::bar('param1, 'param2')`.
 * - `/foo`: Routes to `FooController::index()`, since `'index'` is assumed to be the action if none
 *   is otherwise specified.
 *
 * In almost all cases, custom routes should be added above this one, since route-matching works in
 * a top-down fashion.
 */
Router::connect('/{:controller}/{:action}/{:args}');
示例#17
0
 public function testLibraryBasedRoute()
 {
     $route = Router::connect('/{:library}/{:controller}/{:action}', array('library' => 'app'), array('persist' => array('library')));
     $expected = '/app/hello/world';
     $result = Router::match(array('controller' => 'hello', 'action' => 'world'));
     $this->assertEqual($expected, $result);
     $expected = '/myapp/hello/world';
     $result = Router::match(array('library' => 'myapp', 'controller' => 'hello', 'action' => 'world'));
     $this->assertEqual($expected, $result);
 }
示例#18
0
 /**
  * Logic to request password reset for user
  *
  * @param array $conditions
  * @return int
  */
 public static function requestPasswordReset(array $conditions = array())
 {
     $self = static::_object();
     if ($user = $self::first(compact('conditions'))) {
         $time = new \DateTime();
         $reset = PasswordResets::first(array('conditions' => array('user_id' => $user->id)));
         if ($reset) {
             $expires = new \DateTime($reset->expires);
             if ($expires <= $time) {
                 $reset->delete();
             } else {
                 return PasswordResets::RESET_TOKEN_EXISTS;
             }
         }
         if (!$reset || !$reset->exists()) {
             $expires = clone $time;
             $expires->modify(LI3_UM_PasswordResetExpires);
             $token = Token::generate($user->email);
             $reset = PasswordResets::create(array('user_id' => $user->id, 'expires' => $expires->format('Y-m-d H:i:s'), 'token' => $token));
             if ($reset->save()) {
                 $link = Router::match(array('li3_usermanager.Users::resetPassword', 'id' => $user->id, 'token' => $token), $self::$request, array('absolute' => true));
                 Mailer::$_data['subject'] = 'Your password reset link!';
                 Mailer::$_data['from'] = LI3_UM_PasswordResetEmailFrom;
                 Mailer::$_data['to'] = $user->email;
                 Mailer::$_data['body'] = 'This is your password reset link:' . "\n" . $link;
                 return PasswordResets::GENERATED_NEW_RESET_TOKEN;
             }
         }
     }
 }
示例#19
0
 /**
  * Test if the routes.php file is loaded correctly and the
  * routes are connected to the router.
  */
 public function testRouteLoading()
 {
     $this->assertEmpty(Router::get(null, true));
     $command = new Route(array('routes' => $this->_config['routes']));
     $this->assertCount(4, Router::get(null, true));
     Router::reset();
     $request = new Request();
     $request->params['env'] = 'production';
     $command = new Route(compact('request') + array('routes' => $this->_config['routes']));
     $this->assertCount(2, Router::get(null, true));
 }
示例#20
0
<?php

use lithium\net\http\Router;
$url = Router::match(array('library' => 'radium', 'controller' => 'assets', 'action' => 'show', 'id' => $this->scaffold->object->id()), $this->request(), array('absolute' => true));
?>
<div class="plaintext"><pre><?php 
echo $url;
?>
</pre></div>
<audio controls><source src="<?php 
echo $url;
?>
" type="<?php 
echo $this->scaffold->object['mime'];
?>
"></audio>
<hr />
<?php 
unset($this->scaffold->object['file']);
echo $this->scaffold->render('data', array('data' => \lithium\util\Set::flatten($this->scaffold->object->data())));
示例#21
0
<?php

use lithium\net\http\Router;
Router::connect('/bot', array('library' => 'li3_bot', 'controller' => 'pages', 'action' => 'home'));
Router::connect('/bot/logs', array('library' => 'li3_bot', 'controller' => 'logs', 'action' => 'channels'));
Router::connect('/bot/logs/{:channel}/{:date:[0-9]{4}-[0-9]{2}-[0-9]{2}}', array('library' => 'li3_bot', 'controller' => 'logs', 'action' => 'view'));
Router::connect('/bot/logs/{:channel}/{:year}', array('library' => 'li3_bot', 'controller' => 'logs', 'action' => 'index'));
Router::connect('/bot/logs/{:channel}', array('library' => 'li3_bot', 'controller' => 'logs', 'action' => 'index'));
Router::connect('/bot/tells', array('library' => 'li3_bot', 'controller' => 'tells', 'action' => 'index'));
示例#22
0
<?php

use li3b_users\models\Asset;
use lithium\net\http\Router;
use lithium\core\Environment;
use lithium\action\Dispatcher;
use lithium\action\Response;
Router::connect("/login", array('library' => 'li3b_users', 'controller' => 'users', 'action' => 'login', 'admin' => null));
Router::connect("/logout", array('library' => 'li3b_users', 'controller' => 'users', 'action' => 'logout', 'admin' => null));
Router::connect("/register", array('library' => 'li3b_users', 'controller' => 'users', 'action' => 'register', 'admin' => null));
Router::connect("/settings", array('library' => 'li3b_users', 'controller' => 'users', 'action' => 'update', 'admin' => null));
Router::connect("/profile/{:args}", array('library' => 'li3b_users', 'controller' => 'users', 'action' => 'read', 'args' => array(), 'admin' => null));
// Route for images stored in GridFS.
Router::connect('/profilepic/{:args}.(jpe?g|png|gif)', array(), function ($request) {
    $possibleErrors = array('TOO_LARGE', 'INVALID_FILE_TYPE');
    if (!in_array($request->params['args'][0], $possibleErrors)) {
        $image = Asset::find('first', array('conditions' => array('_id' => $request->params['args'][0])));
        if (!$image || !$image->file) {
            header("Status: 404 Not Found");
            header("HTTP/1.0 404 Not Found");
            die;
        }
        return new Response(array('headers' => array('Content-type' => $image->contentType), 'body' => $image->file->getBytes()));
    }
    return new Response(array('location' => '/li3b_users/img/default-profile-picture.png'));
});
示例#23
0
 /**
  * Test if the routes.php file is loaded correctly and the
  * routes are connected to the router.
  */
 public function testRouteLoading()
 {
     $this->assertFalse(Router::get());
     $command = new Route(array('routes' => $this->_config['routes']));
     $this->assertEqual(4, count(Router::get()));
     Router::reset();
     $request = new Request();
     $request->params['env'] = 'production';
     $command = new Route(compact('request') + array('routes' => $this->_config['routes']));
     $this->assertEqual(2, count(Router::get()));
 }
示例#24
0
 public function tearDown()
 {
     Router::reset();
 }
示例#25
0
<?php

use lithium\core\Libraries;
use lithium\action\Response;
use lithium\net\http\Router;
use lithium\net\http\Media;
$config = Libraries::get('li3_docs');
$base = $config['url'] == '/' ? '' : $config['url'];
/**
 * Handles broken URL parsers by matching method URLs with no closing ) and redirecting.
 */
Router::connect("{$base}/{:args}\\(", array(), function ($request) {
    return new Response(array('location' => "{$request->url})"));
});
Router::connect($base ?: '/', array('controller' => 'li3_docs.ApiBrowser', 'action' => 'index'));
Router::connect("{$base}/{:path:js|css}/{:file}.{:type}", array(), function ($request) {
    $req = $request->params;
    $file = dirname(__DIR__) . "/webroot/{$req['path']}/{$req['file']}.{$req['type']}";
    if (!file_exists($file)) {
        return;
    }
    return new Response(array('body' => file_get_contents($file), 'headers' => array('Content-type' => str_replace(array('css', 'js'), array('text/css', 'text/javascript'), $req['type']))));
});
Router::connect("{$base}/{:lib}/{:args}", array('controller' => 'li3_docs.ApiBrowser', 'action' => 'view'));
示例#26
0
 public function testMatchWithScopeAndWithoutController()
 {
     Router::scope('app', function () {
         Router::connect('/{:id}', 'Posts::index');
     });
     $request = new Request(array('url' => '/1', 'base' => ''));
     MockDispatcher::run($request);
     $result = Router::match(array('id' => 2), $request);
     $this->assertEqual('/2', $result);
 }
 /**
  * Tests default route formatters, and setting/getting new formatters.
  */
 public function testRouteFormatters()
 {
     $formatters = Router::formatters();
     $this->assertEqual(array('args', 'controller'), array_keys($formatters));
     $this->assertEqual('foo/bar', $formatters['args'](array('foo', 'bar')));
     $this->assertEqual('list_items', $formatters['controller']('ListItems'));
     Router::formatters(array('action' => function ($value) {
         return strtolower($value);
     }));
     $formatters = Router::formatters();
     $this->assertEqual(array('action', 'args', 'controller'), array_keys($formatters));
     Router::formatters(array('action' => null));
     $formatters = Router::formatters();
     $this->assertEqual(array('args', 'controller'), array_keys($formatters));
 }
示例#28
0
Router::connect('/{:library}/profile/trace/{:file}', array('file' => 'latest'), function ($request) {
    // If for some reason a profile session is active, do NOT run the code in this route.
    // It would cause some pretty big issues =)
    if (isset($_GET['XDEBUG_PROFILE']) || isset($_COOKIE['XDEBUG_PROFILE'])) {
        echo 'You can\'t attempt to get the latest profile information while the profiler is active.';
        return false;
    }
    // webgrind bootstrap/config process
    require LITHIUM_APP_PATH . '/libraries/li3_perf/extensions/webgrind/library/bootstrap.php';
    $trace_files = FileHandler::getInstance()->getTraceList(1);
    if (is_array($trace_files)) {
        $dataFile = $trace_files[0]['filename'];
        // I've seen this work before and then sometimes not...Sometimes it needs the slash. Weird.
        if (!file_exists(Webgrind::$config->xdebugOutputDir . $dataFile)) {
            $dataFile = '/' . $dataFile;
        }
        $costFormat = Webgrind::$config->defaultCostformat;
        $reader = FileHandler::getInstance()->getTraceReader($dataFile, $costFormat);
        $result = array();
        $functions = array();
        $shownTotal = 0;
        $breakdown = array('internal' => 0, 'procedural' => 0, 'class' => 0, 'include' => 0);
        $functionCount = $reader->getFunctionCount();
        $result['moodpik'] = array('function_calls' => 0, 'total_cost' => 0);
        for ($i = 0; $i < $functionCount; $i++) {
            $functionInfo = $reader->getFunctionInfo($i);
            //var_dump($functionInfo['functionName']);
            if (strstr($functionInfo['functionName'], 'moodpik\\')) {
                $result['moodpik']['function_calls']++;
                $result['moodpik']['total_cost'] += $functionInfo['summedSelfCost'];
            }
            $isInternal = strpos($functionInfo['functionName'], 'php::') !== false;
            if ($isInternal) {
                if (get('hideInternals', false)) {
                    continue;
                }
                $breakdown['internal'] += $functionInfo['summedSelfCost'];
                $humanKind = 'internal';
            } elseif (false !== strpos($functionInfo['functionName'], 'require_once::') || false !== strpos($functionInfo['functionName'], 'require::') || false !== strpos($functionInfo['functionName'], 'include_once::') || false !== strpos($functionInfo['functionName'], 'include::')) {
                $breakdown['include'] += $functionInfo['summedSelfCost'];
                $humanKind = 'include';
            } elseif (false !== strpos($functionInfo['functionName'], '->') || false !== strpos($functionInfo['functionName'], '::')) {
                $breakdown['class'] += $functionInfo['summedSelfCost'];
                $humanKind = 'class';
            } else {
                $breakdown['procedural'] += $functionInfo['summedSelfCost'];
                $humanKind = 'procedural';
            }
            $shownTotal += $functionInfo['summedSelfCost'];
            $functions[$i] = $functionInfo;
            $functions[$i]['nr'] = $i;
            $functions[$i]['humanKind'] = $humanKind;
        }
        usort($functions, 'costCmp');
        $remainingCost = $shownTotal * get('showFraction');
        $result['functions'] = array();
        foreach ($functions as $function) {
            $remainingCost -= $function['summedSelfCost'];
            $function['file'] = urlencode($function['file']);
            $result['functions'][] = $function;
            if ($remainingCost < 0) {
                break;
            }
        }
        $result['summedInvocationCount'] = $reader->getFunctionCount();
        $result['summedRunTime'] = $reader->formatCost($reader->getHeader('summary'), 'msec');
        $result['dataFile'] = $dataFile;
        $result['invokeUrl'] = $reader->getHeader('cmd');
        $result['runs'] = $reader->getHeader('runs');
        $result['breakdown'] = $breakdown;
        $result['mtime'] = date(Webgrind::$config->dateFormat, filemtime(Webgrind::$config->xdebugOutputDir . '/' . $dataFile));
        $creator = preg_replace('/[^0-9\\.]/', '', $reader->getHeader('creator'));
        $result['linkToFunctionLine'] = version_compare($creator, '2.1') > 0;
        var_dump($result);
        exit;
    }
});
示例#29
0
 /**
  * Returns the corresponding params for a given URL and an optional request
  * method.
  *
  * Examples:
  * ```
  * 1: li3 route show /foo
  * 2: li3 route show post /foo/bar/1
  * 3: li3 route show /test
  * 4: li3 route show /test --env=production
  * ```
  *
  * Will return outputs similar to:
  *
  * ```
  * 1: {"controller":"foo","action":"index"	}
  * 2: {"controller":"foo","action":"bar","args":["1"]}
  * 3: {"controller":"lithium\\test\\Controller","action":"index"}
  * 4: {"controller":"test","action":"index"}
  * ```
  *
  * @return void
  */
 public function show()
 {
     $url = join(" ", $this->request->params['args']);
     $method = 'GET';
     if (!$url) {
         $this->error('Please provide a valid URL');
     }
     if (preg_match('/^(GET|POST|PUT|DELETE|HEAD|OPTIONS) (.+)/i', $url, $matches)) {
         $method = strtoupper($matches[1]);
         $url = $matches[2];
     }
     $request = new Request(compact('url') + array('env' => array('REQUEST_METHOD' => $method)));
     $result = Router::process($request);
     $this->out($result->params ? json_encode($result->params) : "No route found.");
 }
示例#30
0
// TODO: See why this isn't catching in the Minerva library routes...
// This should already be set...
Router::connect('/minerva_gallery/admin/{:controller}/{:action}/{:args}', array('admin' => 'admin', 'library' => 'minerva_gallery', 'controller' => 'items', 'action' => 'index'));
// JSON Routes
Router::connect('/minerva_gallery/{:controller}/{:action}.json', array('library' => 'minerva_gallery', 'controller' => 'items', 'type' => 'json'));
Router::connect('/minerva_gallery/{:controller}/{:action}/{:args}.json', array('library' => 'minerva_gallery', 'controller' => 'items', 'type' => 'json'));
// Route for reading a gallery (note the "document_type" parameter)
Router::connect('/gallery/read/{:url}', array('library' => 'minerva', 'plugin' => 'minerva_gallery', 'controller' => 'pages', 'action' => 'read'));
// Route for listing all galleries
Router::connect('/gallery/index', array('library' => 'minerva', 'plugin' => 'minerva_gallery', 'controller' => 'pages', 'action' => 'index'));
// Pagination for galleries (default limit is 10)
Router::connect('/gallery/index/page:{:page:[0-9]+}', array('library' => 'minerva', 'plugin' => 'minerva_gallery', 'controller' => 'pages', 'action' => 'index'));
Router::connect('/gallery/index/page:{:page:[0-9]+}/limit:{:limit:[0-9]+}', array('library' => 'minerva', 'plugin' => 'minerva_gallery', 'controller' => 'pages', 'action' => 'index'));
// Yes, you can render "static" pages from the library as well by using the "view" action,
// Templates from: /libraries/minerva_gallery/views/pages/static/template-name.html.php
Router::connect('/gallery', array('library' => 'minerva', 'plugin' => 'minerva_gallery', 'controller' => 'pages', 'action' => 'view', 'home'));
Router::connect('/gallery/view/{:args}', array('library' => 'minerva', 'plugin' => 'minerva_gallery', 'controller' => 'pages', 'action' => 'view', 'home'));
// NOTE: /gallery route could also be reached via the default Minerva route: /minerva/plugin/minerva_gallery
// Also: /minerva/plugin/minerva_gallery/pages/read/document == /gallery/read/{:url}
// TODO? Do galleries also need comments? Should there be a unified comments library now?
// Router::connect('/gallery/comments/{:action}.json', array('library' => 'minerva_gallery', 'controller' => 'comments', 'type' => 'json'));
// Router::connect('/gallery/comments/{:action}/{:args}.json', array('library' => 'minerva_gallery', 'controller' => 'comments', 'type' => 'json'));
// SWEEPSTAKES LIBRARY SPECIFIC ROUTES (Routed to look like it belongs to Minerva. Library added as with 'minerva_plugin' => true, so it will follow the render paths.)
/*
Router::connect("/minerva/gallery/admin/{:controller}/{:action}/{:url}", array('admin' => 'admin', 'library' => 'sweeps', 'controller' => 'sweepstakes', 'action' => 'index'));

Router::connect("/minerva/gallery/{:controller}/{:action}", array('library' => 'sweeps', 'controller' => 'sweepstakes', 'action' => 'index'));
Router::connect("/minerva/gallery/{:controller}/{:action}/{:args}", array('library' => 'sweeps', 'controller' => 'sweepstakes', 'action' => 'index'));

Router::connect("/minerva/gallery/{:controller}/{:action}/{:url}", array('library' => 'sweeps', 'controller' => 'sweepstakes', 'action' => 'index'));
 * */