本文整理汇总了PHP中Phalcon\DiInterface::get方法的典型用法代码示例。如果您正苦于以下问题:PHP DiInterface::get方法的具体用法?PHP DiInterface::get怎么用?PHP DiInterface::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\DiInterface
的用法示例。
在下文中一共展示了DiInterface::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerServices
public function registerServices(\Phalcon\DiInterface $di)
{
//registrando annotations
$this->registerAnnotationsFiles(['Column', 'Entity', 'GeneratedValue', 'HasLifecycleCallbacks', 'Id', 'PrePersist', 'PreUpdate', 'Table', 'ManyToOne', 'ManyToMany', 'JoinTable', 'JoinColumn']);
//configurando entity manager
$di->setShared('entityManager', function () use($di) {
$infraConfig = $di->get('Infrastructure\\Config');
// $doctrine_config = Setup::createAnnotationMetadataConfiguration($infraConfig['ormMapper'], $di->get('App\Config')['devmode']);
$config = Setup::createConfiguration($di->get('App\\Config')['devmode']);
$driver = new AnnotationDriver(new AnnotationReader(), $infraConfig['ormMapper']);
// registering noop annotation autoloader - allow all annotations by default
AnnotationRegistry::registerLoader('class_exists');
$config->setMetadataDriverImpl($driver);
$entityManager = EntityManager::create($infraConfig['databases'][0], $config);
$platform = $entityManager->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
return $entityManager;
});
$di->setShared('api', function () use($di) {
$infraConfig = $di->get('Infrastructure\\Config');
return new Service\RESTClient($infraConfig['baseUrl']['api'], $infraConfig['credentials']);
});
$di->setShared('geocodeApi', function () use($di) {
return new Service\RESTClient('https://maps.googleapis.com/maps/api/geocode/json?&key=AIzaSyBwFWzpssaahZ7SfLZt6mv7PeZBFXImpmo&address=');
});
}
示例2: 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);
}
示例3: registerServices
/**
* Register specific services for the module
*/
public function registerServices(DiInterface $di)
{
$config = $di->get('config');
//Registering a dispatcher
$di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace("Promoziti\\Modules\\Business\\Controllers");
return $dispatcher;
});
$di->set('view', function () {
$view = new View();
$view->setViewsDir(__DIR__ . '/views/');
$view->registerEngines(array('.volt' => function ($view, $di) {
$volt = new VoltEngine($view, $di);
$config = $di->get('config');
$volt->setOptions(array('compileAlways' => true, 'compiledPath' => $config->application->cache_dir . "volt/", 'compiledSeparator' => '_'));
return $volt;
}));
return $view;
});
$di->set('aws_s3', function () use($config) {
//version 2.7 style
$s3 = \Aws\S3\S3Client::factory(array('key' => $config->application->security->aws->key, 'secret' => $config->application->security->aws->secret, 'region' => 'us-west-2', 'version' => '2006-03-01'));
return $s3;
});
}
示例4: 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");
}
示例5: 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;
}
示例6: register
/**
* {@inheritdoc}
*/
public function register(DiInterface $di)
{
$di->set(self::SERVICE_NAME, function () use($di) {
$adapter = new \Vegas\Security\Authentication\Adapter\Standard($di->get('userPasswordManager'));
$adapter->setSessionStorage($di->get('sessionManager')->createScope('auth'));
$auth = new \Vegas\Security\Authentication($adapter);
return $auth;
}, true);
}
示例7: registerAutoloaders
public function registerAutoloaders(\Phalcon\DiInterface $manager = NULL)
{
$loader = new Loader();
$loader->registerNamespaces(array(ucfirst($this->moduleName) . '\\Controllers' => __DIR__ . '/controllers/', 'Multiple\\Components' => APPLICATION_PATH . $manager->get('config')->application->componentsDir, 'Multiple\\Models' => APPLICATION_PATH . $manager->get('config')->application->modelsDir, 'Multiple\\Plugins' => APPLICATION_PATH . $manager->get('config')->application->pluginsDir));
$loader->register();
$manager->set('logger', function () use($manager) {
$monthNow = date("Y-m-d", time());
$pathLog = APPLICATION_PATH . $manager->get('config')->application->logsDir . '/' . $this->moduleName . '/' . $monthNow . '.log';
$logger = new LogFile($pathLog);
return $logger;
});
}
示例8: registerServices
public function registerServices(DiInterface $di = null)
{
$dispatcher = $di->get('dispatcher');
$dispatcher->setDefaultNamespace('Admin\\Controller');
/**
* @var $view \Phalcon\Mvc\View
*/
$view = $di->get('view');
$view->setLayout('index');
$view->setViewsDir(APPLICATION_PATH . '/modules/admin/views/');
$view->setLayoutsDir('../../common/layouts/');
$view->setPartialsDir('../../common/partials/');
$di->set('view', $view);
}
示例9: verifyNon
/**
* 判断是否在不需要判断权限列表中
* @param \Phalcon\DiInterface $di
* @param string $controllerName
* @param string $actionName
* @return bool
*/
private static function verifyNon($controllerName, $actionName, $di)
{
$controllerName = is_string($controllerName) ? strtolower($controllerName) : $controllerName;
$actionName = is_string($actionName) ? strtolower($actionName) : $actionName;
$nonVerifyRight = $di->get('appConfig') && $di->get('appConfig')->offsetExists('operator') && $di->get('appConfig')->operator->offsetExists('nonVerifyRight') ? $di->get('appConfig')->operator->nonVerifyRight->toArray() : null;
if ($nonVerifyRight == null) {
$nonVerifyRight = $di->get('moduleConfig') && $di->get('moduleConfig')->offsetExists('operator') && $di->get('moduleConfig')->operator->offsetExists('nonVerifyRight') ? $di->get('moduleConfig')->operator->nonVerifyRight->toArray() : null;
}
$nonVerifyRight = $nonVerifyRight == null ? [] : $nonVerifyRight;
foreach ($nonVerifyRight as $k => $v) {
if (strtolower($k) == $controllerName) {
if ($actionName == null) {
return true;
}
if (is_string($v)) {
if ($v == '*' || strtolower($v) == $actionName) {
return true;
}
} else {
if (in_array($actionName, $v)) {
return true;
}
}
}
}
return false;
}
示例10: registerServices
/**
* Registers services related to the module
*
* @param DiInterface $di
*/
public function registerServices(DiInterface $di)
{
/**
* Read configuration
*/
$module_config = (include APP_PATH . "/apps/cliente/config/config.php");
$di->get('config')->merge($module_config);
$config = $di->get('config');
/**
* Database connection is created based in the parameters defined in the configuration file
*/
$di['db'] = function () use($config) {
return new DbAdapter($config->database->toArray());
};
}
示例11: __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);
}
示例12: register
/**
* {@inheritdoc}
*/
public function register(DiInterface $di)
{
$di->set(self::SERVICE_NAME, function () use($di) {
$session = new Vegas\Session($di->get('session'));
return $session;
}, true);
}
示例13: register
/**
* {@inheritdoc}
*/
public function register(DiInterface $di)
{
$di->set(self::SERVICE_NAME, function () use($di) {
$config = $di->get('config');
return new Phalcon\Db\Adapter\Pdo\Mysql(["host" => $config->database->host, "dbname" => $config->database->dbname, "port" => $config->database->port, "username" => $config->database->username, "password" => $config->database->password, "options" => [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']]);
}, true);
}
示例14: register
/**
* {@inheritdoc}
* @see http://docs.phalconphp.com/en/latest/api/Phalcon_Db_Adapter_Pdo_Sqlite.html
*/
public function register(DiInterface $di)
{
$di->set(self::SERVICE_NAME, function () use($di) {
$config = $di->get('config');
return new Phalcon\Db\Adapter\Pdo\Sqlite(array("dbname" => $config->db->dbname));
}, true);
}
示例15: registerServices
/**
* Registers the module-only services
*
* @param \Phalcon\DiInterface $di
*/
public function registerServices($di)
{
/**
* Read application wide and module only configurations
*/
$appConfig = $di->get('config');
$moduleConfig = (include __DIR__ . '/config/config.php');
$di->set('moduleConfig', $moduleConfig);
/**
* The URL component is used to generate all kind of urls in the application
*/
$di->set('url', function () use($appConfig) {
$url = new UrlResolver();
$url->setBaseUri($appConfig->application->baseUri);
return $url;
});
/**
* Module specific dispatcher
*/
$di->set('dispatcher', function () use($di) {
$dispatcher = new Dispatcher();
$dispatcher->setEventsManager($di->getShared('eventsManager'));
$dispatcher->setDefaultNamespace('App\\Modules\\Oauth\\');
return $dispatcher;
});
/**
* Module specific database connection
*/
$di->set('db', function () use($appConfig) {
return new DbAdapter(['host' => $moduleConfig->database->host, 'username' => $moduleConfig->database->username, 'password' => $moduleConfig->database->password, 'dbname' => $moduleConfig->database->name]);
});
}