<?php

/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2010, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */
use lithium\console\Dispatcher;
Dispatcher::applyFilter('_call', function ($self, $params, $chain) {
    $params['callable']->response->styles(array('heading' => '\\033[1;30;46m'));
    return $chain->next($self, $params, $chain);
});
示例#2
0
文件: g11n.php 项目: EHER/chegamos
});
/**
 * Integration with `Validator`. You can load locale dependent rules into the `Validator`
 * by specifying them manually or retrieving them with the `Catalog` class.
 */
foreach (array('phone', 'postalCode', 'ssn') as $name) {
    Validator::add($name, Catalog::read(true, "validation.{$name}", 'en_US'));
}
/**
 * Intercepts dispatching processes in order to set the effective locale by using
 * the locale of the request or if that is not available retrieving a locale preferred
 * by the client.
 */
ActionDispatcher::applyFilter('_callable', function ($self, $params, $chain) {
    $request = $params['request'];
    $controller = $chain->next($self, $params, $chain);
    if (!$request->locale) {
        $request->params['locale'] = Locale::preferred($request);
    }
    Environment::set(Environment::get(), array('locale' => $request->locale));
    return $controller;
});
ConsoleDispatcher::applyFilter('_callable', function ($self, $params, $chain) {
    $request = $params['request'];
    $command = $chain->next($self, $params, $chain);
    if (!$request->locale) {
        $request->params['locale'] = Locale::preferred($request);
    }
    Environment::set(Environment::get(), array('locale' => $request->locale));
    return $command;
});
示例#3
0
<?php

/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2011, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */
use lithium\console\Dispatcher;
use lithium\core\Environment;
/**
 * This filter sets the environment based on the current request. By default, `$request->env`, for
 * example in the command `li3 help --env=production`, is used to determine the environment.
 *
 */
Dispatcher::applyFilter('run', function ($self, $params, $chain) {
    Environment::set($params['request']);
    return $chain->next($self, $params, $chain);
});
/**
 * This filter will convert {:heading} to the specified color codes. This is useful for colorizing
 * output and creating different sections.
 *
 */
// Dispatcher::applyFilter('_call', function($self, $params, $chain) {
// 	$params['callable']->response->styles(array(
// 		'heading' => '\033[1;30;46m'
// 	));
// 	return $chain->next($self, $params, $chain);
// });
示例#4
0
 * Intercepts dispatching processes in order to set the effective locale by using
 * the locale of the request or if that is not available retrieving a locale preferred
 * by the client.
 *
 * @see lithium\g11n\Message
 * @see lithium\core\Environment
 */
$setLocale = function ($self, $params, $chain) {
    if (!$params['request']->locale()) {
        $params['request']->locale(Locale::preferred($params['request']));
    }
    Environment::set(true, array('locale' => $params['request']->locale()));
    return $chain->next($self, $params, $chain);
};
ActionDispatcher::applyFilter('_callable', $setLocale);
ConsoleDispatcher::applyFilter('_callable', $setLocale);
/**
 * Resources
 *
 * Globalization (g11n) catalog configuration.  The catalog allows for obtaining and
 * writing globalized data. Each configuration can be adjusted through the following settings:
 *
 *   - `'adapter'` _string_: The name of a supported adapter. The builtin adapters are `Memory` (a
 *     simple adapter good for runtime data and testing), `Php`, `Gettext`, `Cldr` (for
 *     interfacing with Unicode's common locale data repository) and `Code` (used mainly for
 *     extracting message templates from source code).
 *
 *   - `'path'` All adapters with the exception of the `Memory` adapter require a directory
 *     which holds the data.
 *
 *   - `'scope'` If you plan on using scoping i.e. for accessing plugin data separately you
示例#5
0
use lithium\core\Environment;
use lithium\core\Libraries;
/**
 * This filter sets the environment based on the current request. By default, `$request->env`, for
 * example in the command `li3 help --env=production`, is used to determine the environment.
 *
 * Routes are also loaded, to facilitate URL generation from within the console environment.
 *
 */
Dispatcher::applyFilter('run', function ($self, $params, $chain) {
    Environment::set($params['request']);
    foreach (array_reverse(Libraries::get()) as $name => $config) {
        if ($name === 'lithium') {
            continue;
        }
        $file = "{$config['path']}/config/routes.php";
        file_exists($file) ? call_user_func(function () use($file) {
            include $file;
        }) : null;
    }
    return $chain->next($self, $params, $chain);
});
/**
 * This filter will convert {:heading} to the specified color codes. This is useful for colorizing
 * output and creating different sections.
 *
 */
// Dispatcher::applyFilter('_call', function($self, $params, $chain) {
// 	$params['callable']->response->styles(array(
// 		'heading' => '\033[1;30;46m'
// 	));
示例#6
0
<?php

/**
 * Initialize code index.
 */
use lithium\core\Libraries;
use lithium\action\Dispatcher;
use lithium\console\Dispatcher as ConsoleDispatcher;
use li3_docs\extensions\docs\Code;
$filter = function ($self, $params, $chain) {
    $indexPath = Libraries::get(true, 'path') . '/resources/docs.index.json';
    if (file_exists($indexPath) && is_readable($indexPath)) {
        Code::index((array) json_decode(file_get_contents($indexPath), true));
    }
    $result = $chain->next($self, $params, $chain);
    if (($index = Code::index()) && is_array($index) && is_writable(dirname($indexPath))) {
        file_put_contents($indexPath, json_encode($index));
    }
    return $result;
};
Dispatcher::applyFilter('run', $filter);
ConsoleDispatcher::applyFilter('run', $filter);
/**
 * Setup default options:
 *
 * - `'index'` _array|void_: Allows to restrict indexing to provided set of libraries.
 *   By default all libraries registered in the application are indexed.
 * - `'categories'` _array|void_: Allows manually provide a set of category names. By
 *    default categories are extracted from all indexed libraries.
 */
Libraries::add('li3_docs', array('bootstrap' => false) + Libraries::get('li3_docs') + array('url' => '/docs', 'index' => null, 'categories' => null));
示例#7
0
<?php

use lithium\action\Dispatcher;
use lithium\console\Dispatcher as ConsoleDispatcher;
use li3_redis\storage\Redis;
/**
 * Apply filter to Dispatcher, to initialize Redis configuration
 */
Dispatcher::applyFilter('_call', function ($self, $params, $chain) {
    Redis::config();
    return $chain->next($self, $params, $chain);
});
ConsoleDispatcher::applyFilter('_call', function ($self, $params, $chain) {
    Redis::config();
    return $chain->next($self, $params, $chain);
});