本文整理汇总了PHP中Phalcon\DiInterface::has方法的典型用法代码示例。如果您正苦于以下问题:PHP DiInterface::has方法的具体用法?PHP DiInterface::has怎么用?PHP DiInterface::has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\DiInterface
的用法示例。
在下文中一共展示了DiInterface::has方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* @param string $name
* @return mixed
* @throws \Exception
*/
public function get($name)
{
if ($this->di->has($name)) {
return $this->di->get($name);
}
throw new \Exception("Service \"{$name}\" is not defined");
}
示例2: registerConfig
protected function registerConfig()
{
$config = (require __DIR__ . '/config/config.php');
if ($this->di->has('console.config')) {
$config->merge($this->di->get('console.config'));
}
$this->di['console.config'] = $config;
}
示例3: __construct
/**
* Constructor. Allows you to specify the initial settings for the widget.
* Parameters can be passed as an associative array.
* Also, the parameters can be set using the appropriate methods
*
* @param array $params
* @throws \Phalcon\DI\Exception
* @throws \Phalcon\Session\Exception
*/
public function __construct(array $params = [])
{
if (DI::getDefault() === null) {
throw new \Phalcon\DI\Exception('DI is not configured!');
}
if ($this->hasSession() === false) {
throw new Exception('Session does not configured in DI');
}
if ($this->session->has(self::KEY) === true) {
$this->user = $this->session->get(self::KEY);
} else {
$this->user = false;
}
parent::__construct($params);
}
示例4: collect
/**
* Called by the DebugBar when data needs to be collected
* @return array Collected data
*/
function collect()
{
$request = $this->request;
$response = $this->response;
$status = $response->getHeaders()->get('Status') ?: '200 ok';
$responseHeaders = $response->getHeaders()->toArray() ?: headers_list();
$cookies = $_COOKIE;
unset($cookies[session_name()]);
$cookies_service = $response->getCookies();
if ($cookies_service) {
$useEncrypt = true;
if ($cookies_service->isUsingEncryption() && $this->di->has('crypt') && !$this->di['crypt']->getKey()) {
$useEncrypt = false;
}
if (!$cookies_service->isUsingEncryption()) {
$useEncrypt = false;
}
foreach ($cookies as $key => $vlaue) {
$cookies[$key] = $cookies_service->get($key)->useEncryption($useEncrypt)->getValue();
}
}
$data = array('status' => $status, 'request_query' => $request->getQuery(), 'request_post' => $request->getPost(), 'request_body' => $request->getRawBody(), 'request_cookies' => $cookies, 'request_server' => $_SERVER, 'response_headers' => $responseHeaders, 'response_body' => $request->isAjax() ? $response->getContent() : '');
if (Version::getId() < 2000000 && $request->isAjax()) {
$data['request_headers'] = '';
// 1.3.x has a ajax bug , so we use empty string insdead.
} else {
$data['request_headers'] = $request->getHeaders();
}
$data = array_filter($data);
if (isset($data['request_query']['_url'])) {
unset($data['request_query']['_url']);
}
if (empty($data['request_query'])) {
unset($data['request_query']);
}
if (isset($data['request_headers']['php-auth-pw'])) {
$data['request_headers']['php-auth-pw'] = '******';
}
if (isset($data['request_server']['PHP_AUTH_PW'])) {
$data['request_server']['PHP_AUTH_PW'] = '******';
}
foreach ($data as $key => $var) {
if (!is_string($data[$key])) {
$data[$key] = $this->formatVar($var);
}
}
return $data;
}
示例5: getApplication
/**
* @param \Phalcon\DiInterface $di
*
* @return \Phalcon\Mvc\Application
*/
protected function getApplication(\Phalcon\DiInterface $di)
{
if (!$di->has("application")) {
return $this->getDefaultApplication($di);
}
return $di->get("application");
}
示例6: getConsole
/**
* @param \Phalcon\DiInterface $di
*
* @return \Phalcon\Cli\Console
*/
protected function getConsole(\Phalcon\DiInterface $di)
{
if (!$di->has("console")) {
return $this->getDefaultConsole($di);
}
return $di->get("console");
}
示例7: registerServices
/**
* Registers services related to the module
*
* @param DiInterface $di
*/
public function registerServices(DiInterface $di)
{
/**
* 获取全局配置
*/
$config = $di->has('config') ? $di->getShared('config') : null;
/**
* 各模块可自定义config文件并替换全局的config配置
*/
if (file_exists($this->modulePath . '/config/config.php')) {
$override = new Config(include $this->modulePath . '/config/config.php');
if ($config instanceof Config) {
$config->merge($override);
} else {
$config = $override;
}
}
//重置全局配置
$di->setShared('config', $config);
/**
* 设置各个模块的视图目录
*/
$view = new View();
//$view->setViewsDir($this->modulePath . '/views/default/');
$view->setViewsDir(FRONTEND_PUBLIC_PATH . 'views/default/');
$view->registerEngines(['.volt' => 'volt', '.php' => 'volt', '.html' => 'volt']);
$di->set('view', $view);
}
示例8: registerServices
/**
* Registers services related to the module
*
* @param DiInterface $di
*/
public function registerServices(DiInterface $di)
{
/**
* Read common configuration
*/
$config = $di->has('config') ? $di->getShared('config') : null;
/**
* Try to load local configuration
*/
if (file_exists(__DIR__ . '/config/config.php')) {
$override = new Config(include __DIR__ . '/config/config.php');
if ($config instanceof Config) {
$config->merge($override);
} else {
$config = $override;
}
}
/**
* Setting up the view component
*/
$view = $di->get('view');
$view->setViewsDir($config->get('application')->viewsDir);
$di->set('view', $view);
// add default namespace
$dispatcher = $di->get('dispatcher');
$dispatcher->setDefaultNamespace("Application\\Frontend\\Controllers");
$di->set('dispatcher', $dispatcher);
}
示例9: setupExtraServices
/**
* Setups extra services (if not exist) required by mongo service
*
* @param DiInterface $di
*/
public function setupExtraServices(DiInterface $di)
{
if (!$di->has('collectionManager')) {
$di->set('collectionManager', function () {
return new Manager();
});
}
}
示例10: hasService
/**
* Checks if a service is registered in the DI
*
* @param string $serviceName
* @return boolean
* @throws Exception
*/
public function hasService($serviceName)
{
if (is_string($serviceName) === false) {
throw new Exception('Invalid parameter type.');
}
if (is_object($this->_dependencyInjector) === false) {
$this->_dependencyInjector = new FactoryDefault();
}
return $this->_dependencyInjector->has($serviceName);
}
示例11: setDI
/**
* Sets the DependencyInjector container
*/
public function setDI(DiInterface $dependencyInjector)
{
/**
* We automatically set ourselves as application service
*/
if (!$dependencyInjector->has("application")) {
$dependencyInjector->set("application", $this);
}
$this->_dependencyInjector = $dependencyInjector;
}
示例12: send
/**
* Sends the cookie to the HTTP client
* Stores the cookie definition in session
*
* @return \Phalcon\Http\Cookie
* @throws Exception
*/
public function send()
{
//@note no interface validation
if (is_object($this->_dependencyInjector) === true) {
if ($this->_dependencyInjector->has('session') === true) {
$definition = array();
if ($this->_expire !== 0) {
$definition['expire'] = $this->_expire;
}
if (empty($this->_path) === false) {
$definition['path'] = $this->_path;
}
if (empty($this->_domain) === false) {
$definition['domain'] = $this->_domain;
}
if (empty($this->_secure) === false) {
$definition['secure'] = $this->_secure;
}
if (empty($this->_httpOnly) === false) {
$definition['httpOnly'] = $this->_httpOnly;
}
//The definition is stored in session
if (count($definition) !== 0) {
$session = $this->_dependencyInjector->getShared('session');
if (is_null($session) === false) {
if ($session instanceof SessionInterface === false) {
throw new Exception('Wrong session service.');
}
$session->set('_PHCOOKIE_' . $this->_name, $definition);
}
}
}
}
/* Encryption */
if ($this->_useEncryption === true && empty($this->_value) === false) {
if (is_object($this->_dependencyInjector) === false) {
//@note wrong exception message
throw new Exception("A dependency injection object is required to access the 'filter' service");
}
$crypt = $this->_dependencyInjector->getShared('crypt');
if ($crypt instanceof CryptInterface === false) {
throw new Exception('Wrong crypt service.');
}
//Encrypt the value also coding it with base64
$value = $crypt->encryptBase64($this->_value);
}
//Sets the cookie using the standard 'setcookie' function
//@note use 'bool' as type for the last two parameter
setcookie((string) $this->_name, (string) $value, (int) $this->_expire, (string) $this->_path, (string) $this->_domain, (bool) $this->_secure, (bool) $this->_httpOnly);
return $this;
}
示例13: registerServices
/**
* Registers services related to the module
*
* @param DiInterface $di
*/
public function registerServices(DiInterface $di)
{
/**
* Read common configuration
*/
$config = $di->has('config') ? $di->getShared('config') : null;
/**
* Try to load local configuration
*/
if (file_exists(__DIR__ . '/config/config.php')) {
$override = new Config(include __DIR__ . '/config/config.php');
if ($config instanceof Config) {
$config->merge($override);
} else {
$config = $override;
}
}
/**
* Setting up the view component
*/
$view = $di->get('view');
$view->setViewsDir($config->get('application')->viewsDir);
$di->set('view', $view);
// register helper
$di->setShared('adminHelper', function () {
return new \Application\Admin\Librarys\voltHelper();
});
/**
* Database connection is created based in the parameters defined in the configuration file
*/
$di['db'] = function () use($config) {
$config = $config->database->toArray();
$dbAdapter = '\\Phalcon\\Db\\Adapter\\Pdo\\' . $config['adapter'];
unset($config['adapter']);
return new $dbAdapter($config);
};
// add default namespace
$dispatcher = $di->get('dispatcher');
$dispatcher->setDefaultNamespace("Application\\Admin\\Controllers");
$di->set('dispatcher', $dispatcher);
// register menu
$di->set('AdminMenus', function () {
return require __DIR__ . '/config/menus.php';
});
}
示例14: getModelIdentity
/**
* Get identity.
*
* @param \Phalcon\Mvc\Model $model
* @return mixed
*/
protected function getModelIdentity(PhalconModel $model)
{
if (property_exists($model, 'id')) {
return $model->id;
}
if (!$this->di->has('modelsMetadata')) {
return null;
}
$primaryKeys = $this->di->get('modelsMetadata')->getPrimaryKeyAttributes($model);
switch (count($primaryKeys)) {
case 0:
return null;
case 1:
return $model->{$primaryKeys[0]};
default:
return array_intersect_key(get_object_vars($model), array_flip($primaryKeys));
}
}
示例15: initialize
/**
* @param \Phalcon\DiInterface $di
* @return mixed
*/
public function initialize(\Phalcon\DiInterface $di)
{
/** @var \Phalcon\Config $config */
$config = $di->get('config');
$viewConfig = isset($config->application->view) ? $config->application->view->toArray() : [];
if ($di->has('view')) {
/** @var \Phalcon\Mvc\View $view */
$view = $di->get('view');
$viewEngines = $view->getRegisteredEngines();
if (!$viewEngines) {
$viewEngines = [];
}
$viewEngines['.twig'] = function ($this, $di) use($viewConfig) {
return new \Phalcon\Mvc\View\Engine\Twig($this, $di, $viewConfig);
};
$view->registerEngines($viewEngines);
}
}