当前位置: 首页>>代码示例>>PHP>>正文


PHP Libraries::instance方法代码示例

本文整理汇总了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;
     }
 }
开发者ID:atelierdisko,项目名称:li3_mailer,代码行数:35,代码来源:Mail.php

示例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;
     }
 }
开发者ID:ncud,项目名称:sagalaya,代码行数:13,代码来源:Service.php

示例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;
 }
开发者ID:bruensicke,项目名称:radium,代码行数:12,代码来源:Form.php

示例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'];
     });
 }
开发者ID:nilamdoc,项目名称:KYCGlobal,代码行数:20,代码来源:Service.php

示例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);
 }
开发者ID:newmight2015,项目名称:Blockchain-2,代码行数:17,代码来源:Model.php

示例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);
		}
	}
开发者ID:niel,项目名称:lithium,代码行数:28,代码来源:View.php

示例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);
 }
开发者ID:WarToaster,项目名称:HangOn,代码行数:16,代码来源:StaticObject.php

示例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);
         }
     });
 }
开发者ID:fedeisas,项目名称:lithium,代码行数:25,代码来源:Dispatcher.php

示例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;
 }
开发者ID:WarToaster,项目名称:HangOn,代码行数:16,代码来源:Service.php

示例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);
     });
 }
开发者ID:nateabele,项目名称:li3_resources,代码行数:13,代码来源:Resources.php

示例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.");
     }
 }
开发者ID:nashadalam,项目名称:lithium,代码行数:23,代码来源:Renderer.php

示例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();
 }
开发者ID:rmarscher,项目名称:lithium,代码行数:20,代码来源:LibrariesTest.php

示例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.");
     }
 }
开发者ID:nateabele,项目名称:li3_mailer,代码行数:21,代码来源:File.php

示例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');
 }
开发者ID:EHER,项目名称:monopolis,代码行数:7,代码来源:LibrariesTest.php


注:本文中的lithium\core\Libraries::instance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。