本文整理汇总了PHP中lithium\core\Libraries::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Libraries::instance方法的具体用法?PHP Libraries::instance怎么用?PHP Libraries::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lithium\core\Libraries
的用法示例。
在下文中一共展示了Libraries::instance方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _init
/**
* Perform initialization.
*
* @return void
*/
protected function _init()
{
Object::_init();
$type = isset($this->_config['type']) ? $this->_config['type'] : null;
if ($type === 'text') {
$h = function ($data) {
return $data;
};
} else {
$encoding = 'UTF-8';
if ($this->_message) {
$encoding =& $this->_message->charset;
}
$h = function ($data) use(&$encoding) {
return htmlspecialchars((string) $data, ENT_QUOTES, $encoding);
};
}
$this->outputFilters += compact('h') + $this->_config['outputFilters'];
foreach (array('loader', 'renderer') as $key) {
if (is_object($this->_config[$key])) {
$this->{'_' . $key} = $this->_config[$key];
continue;
}
$class = $this->_config[$key];
$config = array('view' => $this) + $this->_config;
$path = 'adapter.template.mail';
$instance = Libraries::instance($path, $class, $config);
$this->{'_' . $key} = $instance;
}
}
示例2: _init
/**
* Initialize connection
*
*/
protected function _init()
{
$config = array('classes' => $this->_classes) + $this->_config;
try {
$this->connection = Libraries::instance('socket', $config['socket'], $config);
} catch (ClassNotFoundException $e) {
$this->connection = null;
}
}
示例3: create
public function create($bindings = null, array $options = array())
{
$result = parent::create($bindings, $options);
if ($this->_binding) {
$model = $this->_binding->model();
$this->model = $model;
$this->instance = Libraries::instance('model', $model);
$this->schema = $model::schema();
$this->rules = $this->instance->validates;
}
return $result;
}
示例4: _init
/**
* Initialize connection
*
*/
protected function _init()
{
$config = array('classes' => $this->_classes) + $this->_config;
try {
$this->connection = Libraries::instance('socket', $config['socket'], $config);
} catch (ClassNotFoundException $e) {
$this->connection = null;
}
$this->_responseTypes += array('headers' => function ($response) {
return $response->headers;
}, 'body' => function ($response) {
return $response->body();
}, 'code' => function ($response) {
return $response->status['code'];
});
}
示例5: _instance
/**
* Returns an instance of a class with given `config`. The `name` could be a key from the
* `classes` array, a fully-namespaced class name, or an object. Typically this method is used
* in `_init` to create the dependencies used in the current class.
*
* @param string|object $name A `classes` alias or fully-namespaced class name.
* @param array $options The configuration passed to the constructor.
* @return object
*/
protected static function _instance($name, array $options = array())
{
$self = static::_object();
if (is_string($name) && isset($self->_classes[$name])) {
$name = $self->_classes[$name];
}
return Libraries::instance(null, $name, $options);
}
示例6: _init
/**
* Perform initialization of the View.
*
* @return void
*/
protected function _init() {
parent::_init();
$encoding = 'UTF-8';
if ($this->_response) {
$encoding =& $this->_response->encoding;
}
$h = function($data) use (&$encoding) {
return htmlspecialchars((string) $data, ENT_QUOTES, $encoding);
};
$this->outputFilters += compact('h') + $this->_config['outputFilters'];
foreach (array('loader', 'renderer') as $key) {
if (is_object($this->_config[$key])) {
$this->{'_' . $key} = $this->_config[$key];
continue;
}
$class = $this->_config[$key];
$config = array('view' => $this) + $this->_config;
$this->{'_' . $key} = Libraries::instance('adapter.template.view', $class, $config);
}
}
示例7: _instance
/**
* Returns an instance of a class with given `config`. The `name` could be a key from the
* `classes` array, a fully namespaced class name, or an object. Typically this method is used
* in `_init` to create the dependencies used in the current class.
*
* @param string|object $name A `classes` key or fully-namespaced class name.
* @param array $options The configuration passed to the constructor.
* @return object
*/
protected static function _instance($name, array $options = array())
{
if (is_string($name) && isset(static::$_classes[$name])) {
$name = static::$_classes[$name];
}
return Libraries::instance(null, $name, $options);
}
示例8: _callable
/**
* Accepts parameters generated by the `Router` class in `Dispatcher::run()`, and produces a
* callable controller object. By default, this method uses the `'controller'` path lookup
* configuration in `Libraries::locate()` to return a callable object.
*
* @param object $request The instance of the `Request` class either passed into or generated by
* `Dispatcher::run()`.
* @param array $params The parameter array generated by routing the request.
* @param array $options Not currently implemented.
* @return object Returns a callable object which the request will be routed to.
* @filter
*/
protected static function _callable($request, $params, $options)
{
$params = compact('request', 'params', 'options');
return static::_filter(__FUNCTION__, $params, function ($self, $params) {
$options = array('request' => $params['request']) + $params['options'];
$controller = $params['params']['controller'];
try {
return Libraries::instance('controllers', $controller, $options);
} catch (ClassNotFoundException $e) {
throw new DispatchException("Controller `{$controller}` not found.", null, $e);
}
});
}
示例9: array
/**
* Retrieve instance of configured socket
*
* @param array $config options to be passed on to the socket
* @return object
*/
public function &connection($config = array())
{
$config += $this->_config;
try {
$this->connection = Libraries::instance('socket', $config['socket'], $config);
} catch (ClassNotFoundException $e) {
$this->connection = null;
}
return $this->connection;
}
示例10: bind
public static function bind($class)
{
$class::applyFilter('_callable', function ($self, $params, $chain) {
$options = $params['options'];
$name = $params['params']['controller'];
if ($class = Libraries::locate('resources', $name, $options)) {
if (strpos($class, 'Controller') === false) {
return Libraries::instance(null, $class, $options);
}
}
return $chain->next($self, $params, $chain);
});
}
示例11: helper
/**
* Brokers access to helpers attached to this rendering context, and loads helpers on-demand if
* they are not available.
*
* @param string $name Helper name
* @param array $config
* @return object
*/
public function helper($name, array $config = array())
{
if (isset($this->_helpers[$name])) {
return $this->_helpers[$name];
}
try {
$config += array('context' => $this);
return $this->_helpers[$name] = Libraries::instance('helper', ucfirst($name), $config);
} catch (ClassNotFoundException $e) {
if (ob_get_length()) {
ob_end_clean();
}
throw new RuntimeException("Helper `{$name}` not found.");
}
}
示例12: testClassInstanceWithSubnamespace
public function testClassInstanceWithSubnamespace()
{
$testApp = Libraries::get(true, 'resources') . '/tmp/tests/test_app';
mkdir($testApp);
$paths = array("/controllers", "/controllers/admin");
foreach ($paths as $path) {
$namespace = str_replace('/', '\\', $path);
$dotsyntax = str_replace('/', '.', trim($path, '/'));
$class = 'Posts';
Libraries::add('test_app', array('path' => $testApp));
mkdir($testApp . $path, 0777, true);
file_put_contents($testApp . $path . "/{$class}Controller.php", "<?php namespace test_app{$namespace};\n\n\t\t\t\tclass {$class}Controller extends \\lithium\\action\\Controller {\n\t\t\t\tpublic function index() {\n\t\t\t\t\treturn true;\n\t\t\t\t}}");
Libraries::cache(false);
$expected = "test_app{$namespace}\\{$class}Controller";
$instance = Libraries::instance($dotsyntax, "Posts", array('library' => 'test_app'));
$result = get_class($instance);
$this->assertEqual($expected, $result, "{$path} did not work");
}
$this->_cleanUp();
}
示例13: helper
/**
* Brokers access to helpers attached to this rendering context, and loads helpers on-demand if
* they are not available.
*
* @param string $name Helper name
* @param array $config
* @return object
*/
public function helper($name, array $config = array())
{
if (isset($this->_helpers[$name])) {
return $this->_helpers[$name];
}
try {
$config += array('context' => $this);
$helper = Libraries::instance('helper.mail', ucfirst($name), $config);
return $this->_helpers[$name] = $helper;
} catch (ClassNotFoundException $e) {
throw new RuntimeException("Mail helper `{$name}` not found.");
}
}
示例14: testServiceLocateInstantiation
public function testServiceLocateInstantiation()
{
$result = Libraries::instance('adapter.template.view', 'Simple');
$this->assertTrue(is_a($result, 'lithium\\template\\view\\adapter\\Simple'));
$this->expectException("Class 'Foo' of type 'adapter.template.view' not found.");
$result = Libraries::instance('adapter.template.view', 'Foo');
}