本文整理匯總了PHP中lithium\core\Libraries::locate方法的典型用法代碼示例。如果您正苦於以下問題:PHP Libraries::locate方法的具體用法?PHP Libraries::locate怎麽用?PHP Libraries::locate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類lithium\core\Libraries
的用法示例。
在下文中一共展示了Libraries::locate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: get
/**
* Read the configuration or access the connections you have set up.
*
* Usage:
* {{{
* // Gets the names of all available configurations
* $configurations = Connections::get();
*
* // Gets the configuration array for the connection named 'db'
* $config = Connections::get('db', array('config' => true));
*
* // Gets the instance of the connection object, configured with the settings defined for
* // this object in Connections::add()
* $dbConnection = Connections::get('db');
*
* // Gets the connection object, but only if it has already been built.
* // Otherwise returns null.
* $dbConnection = Connections::get('db', array('autoCreate' => false));
* }}}
*
* @param string $name The name of the connection to get, as defined in the first parameter of
* `add()`, when the connection was initially created.
* @param array $options Options to use when returning the connection:
* - `'autoCreate'`: If `false`, the connection object is only returned if it has
* already been instantiated by a previous call.
* - `'config'`: If `true`, returns an array representing the connection's internal
* configuration, instead of the connection itself.
* @return mixed A configured instance of the connection, or an array of the configuration used.
*/
public static function get($name = null, array $options = array())
{
static $mockAdapter;
$defaults = array('config' => false, 'autoCreate' => true);
$options += $defaults;
if ($name === false) {
if (!$mockAdapter) {
$class = Libraries::locate('data.source', 'Mock');
$mockAdapter = new $class();
}
return $mockAdapter;
}
if (!$name) {
return array_keys(static::$_configurations);
}
if (!isset(static::$_configurations[$name])) {
return null;
}
if ($options['config']) {
return static::_config($name);
}
$settings = static::$_configurations[$name];
if (!isset($settings[0]['object'])) {
if (!$options['autoCreate']) {
return null;
}
}
return static::adapter($name);
}
示例2: all
/**
* Get all test cases. By default, does not include function or integration tests.
*
* @param string $options
* @return array
*/
public static function all(array $options = array())
{
$defaults = array('library' => true, 'filter' => '/cases/', 'exclude' => '/mock/', 'recursive' => true);
$options += $defaults;
$classes = Libraries::locate('tests', null, $options);
return $classes;
}
示例3: __invoke
/**
* Magic method to make Controller callable.
*
* @see lithium\action\Dispatcher::_callable()
* @param object $request A \lithium\action\Request object.
* @param array $dispatchParams Array of params after being parsed by router.
* @param array $options Some basic options for this controller.
* @return string
*/
public function __invoke($request, $dispatchParams, array $options = array())
{
$dispatchParamsDefaults = array('args' => array());
$dispatchParams += $dispatchParamsDefaults;
$defaults = array('reporter' => 'html', 'format' => 'html');
$options += (array) $request->query + $defaults;
$params = compact('request', 'dispatchParams', 'options');
set_time_limit(0);
return $this->_filter(__METHOD__, $params, function ($self, $params) {
$request = $params['request'];
$options = $params['options'];
$params = $params['dispatchParams'];
$group = join('\\', (array) $params['args']);
if ($group === "all") {
$group = Group::all();
$options['title'] = 'All Tests';
}
$report = Dispatcher::run($group, $options);
$filters = Libraries::locate('test.filter');
$menu = Libraries::locate('tests', null, array('filter' => '/cases|integration|functional/', 'exclude' => '/mocks/'));
sort($menu);
$result = compact('request', 'report', 'filters', 'menu');
return $report->render('layout', $result);
});
}
示例4: _init
protected function _init()
{
parent::_init();
$class = Libraries::locate('socket.util', $this->_classes['socket']);
if (is_string($class)) {
$this->_connection = new $class($this->_config);
}
}
示例5: _render
/**
* Grab a the `layout.html.php` template and return output
*
* @param string $template name of the template (eg: layout)
* @param string $data array from `_data()` method
* @return string
*/
protected function _render($template, $data)
{
$template = Libraries::locate('test.reporter.template', $template, array('filter' => false, 'type' => 'file', 'suffix' => '.html.php'));
extract($data);
ob_start();
include $template;
return ob_get_clean();
}
示例6: get
/**
* Finds the test case for the corresponding class name.
*
* @param string $class A fully-namespaced class reference for which to find a test case.
* @return string Returns the class name of a test case for `$class`, or `null` if none exists.
*/
public static function get($class)
{
$parts = explode('\\', $class);
$library = array_shift($parts);
$name = array_pop($parts);
$type = 'tests.cases.' . implode('.', $parts);
return Libraries::locate($type, $name, compact('library'));
}
示例7: _init
/**
* Exercise initialization.
*
* @return void
*/
public function _init()
{
parent::_init();
Libraries::paths(array('exercises' => '{:library}\\extensions\\exercises\\{:name}'));
$exercises = Libraries::locate('exercises');
foreach ($exercises as $exercise) {
$this->_exercises[$this->exerciseName($exercise)] = $exercise;
}
}
示例8: apply
public static function apply($model, array $behaviors) {
foreach ($behaviors as $name => $config) {
if (is_string($config)) {
$name = $config;
$config = array();
}
if ($class = Libraries::locate('behavior', $name)) {
$class::bind($model, $config);
}
}
}
示例9: all
/**
* Get all tests
*
* @param string $options
* @return array
*/
public static function all($options = array())
{
$defaults = array('transform' => false, 'library' => true);
$options += $defaults;
$m = '/\\\\tests\\\\cases\\\\(.+)Test$/';
$transform = function ($class) use($m) {
return preg_replace($m, '\\\\\\1', $class);
};
$classes = Libraries::locate('tests', null, $options + array('filter' => '/cases|integration|functional/', 'recursive' => true));
return $options['transform'] ? array_map($transform, $classes) : $classes;
}
示例10: schema
public function schema()
{
$data = Libraries::locate('models');
$models = new Collection(compact('data'));
if ($this->request->is('json')) {
$models->each(function ($model) {
$schema = is_callable(array($model, 'schema')) ? $model::schema() : array();
return array($model => $schema ? $schema->fields() : array());
});
}
return compact('models');
}
示例11: run
public function run()
{
$models = Libraries::locate('models', $this->model);
if (empty($models)) {
throw new Exception('Could not locate model: ' . $this->model);
}
if (!is_array($models)) {
$models = array($models);
}
$counters = array('models' => 0, 'indexes' => 0);
foreach ($models as $model) {
$model = str_replace("\\\\", "\\", $model);
if (property_exists($model, '_indexes')) {
$indexes = $model::$_indexes;
if (empty($indexes)) {
continue;
}
$db = $model::connection();
if (!is_a($db, 'lithium\\data\\source\\MongoDb')) {
throw new Exception('This command works only with MongoDB');
}
$db->connect();
$collection = $db->connection->{$model::meta('source')};
$counters['models']++;
$this->out('{:heading}Ensuring indexes for model: ' . $model . '{:end}');
foreach ($indexes as $name => $index) {
if (empty($index['keys'])) {
$this->error(' * No keys defined for index: ' . $name);
continue;
}
$keys = $index['keys'];
unset($index['keys']);
if (!isset($index['name'])) {
$index['name'] = $name;
}
$options = $index + $this->defaults;
try {
$collection->ensureIndex($keys, $options);
} catch (Exception $e) {
$this->error(' * Failed: {:command}' . $name . '{:end} with: ' . $e->getMessage());
continue;
}
$counters['indexes']++;
$this->out(' * Ensured: {:command}' . $name . '{:end}');
}
}
}
$this->out('');
$this->header('{:heading}Done! Ensured a total of ' . $counters['indexes'] . ' indexes on ' . $counters['models'] . ' models{:end}');
}
示例12: run
/**
* Auto run the help command
*
* @param string $name COMMAND to get help
* @return void
*/
public function run($name = null)
{
if (!$name) {
$this->out('COMMANDS', 'heading1', 2);
$commands = Libraries::locate('command', null, array('recursive' => false));
foreach ($commands as $command) {
$info = Inspector::info($command);
$name = strtolower(Inflector::slug($info['shortName']));
$this->out($this->_pad($name), 'heading2');
$this->out($this->_pad($info['description']), 2);
}
$message = 'See `{:command}li3 help COMMAND{:end}`';
$message .= ' for more information on a specific command.';
$this->out($message, 2);
return true;
}
$name = Inflector::classify($name);
if (!($class = Libraries::locate('command', $name))) {
$this->error("{$name} not found");
return false;
}
if (strpos($name, '\\') !== false) {
$name = join('', array_slice(explode("\\", $name), -1));
}
$name = strtolower(Inflector::slug($name));
$methods = $this->_methods($class);
$properties = $this->_properties($class);
$this->out('USAGE', 'heading1');
$this->out($this->_pad(sprintf("{:command}li3 %s{:end}{:option}%s{:end} [ARGS]", $name ?: 'COMMAND', array_reduce($properties, function ($a, $b) {
return "{$a} {$b['usage']}";
}))));
$info = Inspector::info($class);
if (!empty($info['description'])) {
$this->nl();
$this->out('DESCRIPTION');
$this->out($this->_pad(strtok($info['description'], "\n"), 1));
$this->nl();
}
if ($properties || $methods) {
$this->out('OPTIONS', 'heading2');
}
if ($properties) {
$this->_render($properties);
}
if ($methods) {
$this->_render($methods);
}
return true;
}
示例13: _init
public function _init()
{
parent::_init();
$this->socket = $this->_instance('socket', array('host' => $this->_config['host'], 'port' => $this->_config['port']));
foreach (Libraries::locate('command.bot.plugins') as $class) {
if (method_exists($class, 'poll')) {
Logger::debug("Registering `poll` method from plugin `{$class}`.");
$this->_plugins['poll'][] = new $class($this->_config);
}
if (method_exists($class, 'process')) {
Logger::debug("Registering `process` method from plugin `{$class}`.");
$this->_plugins['process'][] = new $class($this->_config);
}
}
}
示例14: apply
public static function apply($report, $tests, array $options = array())
{
$rules = new Rules();
$file = Libraries::get('li3_quality', 'path') . '/config/syntax.json';
$config = json_decode(file_get_contents($file), true) + array('name' => null, 'rules' => array(), 'options' => array());
foreach ($config['rules'] as $ruleName) {
$class = Libraries::locate('rules.syntax', $ruleName);
$rules->add(new $class());
}
if ($config['options']) {
$rules->options($config['options']);
}
foreach ($tests->invoke('subject') as $class) {
$report->collect(__CLASS__, array($class => $rules->apply(new Testable(array('path' => Libraries::path($class))))));
}
return $tests;
}
示例15: _init
protected function _init()
{
parent::_init();
$config = $this->_config;
$singularName = $config['name'];
if ($config['type'] == 'hasMany') {
$singularName = Inflector::singularize($config['name']);
}
if (!$config['to']) {
$assoc = preg_replace("/\\w+\$/", "", $config['from']) . $singularName;
$config['to'] = class_exists($assoc) ? $assoc : Libraries::locate('models', $assoc);
}
if (!$config['fieldName']) {
$config['fieldName'] = lcfirst($config['name']);
}
$config['keys'] = $this->_keys($config['keys'], $config);
$this->_config = $config;
}