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='); }); }
/** * 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); }
/** * 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; }); }
/** * @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"); }
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; }
/** * {@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); }
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; }); }
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); }
/** * 判断是否在不需要判断权限列表中 * @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; }
/** * 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()); }; }
/** * 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); }
/** * {@inheritdoc} */ public function register(DiInterface $di) { $di->set(self::SERVICE_NAME, function () use($di) { $session = new Vegas\Session($di->get('session')); return $session; }, true); }
/** * {@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); }
/** * {@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); }
/** * 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]); }); }
/** * Register specific services for the module * @param \Phalcon\DiInterface $di */ public function registerServices(DiInterface $di) { $config = $this->_config; $configShared = $di->get('config'); $vDI = $di; //Registering a dispatcher $di->set('dispatcher', function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace('Cnab'); return $dispatcher; }); //Registering the view component $di->set('volt', function ($view, $vDI) use($config, $configShared) { $volt = new Volt($view, $vDI); $volt->setOptions(array('compiledPath' => $configShared->volt->path, 'compiledExtension' => $configShared->volt->extension, 'compiledSeparator' => $configShared->volt->separator, 'stat' => (bool) $configShared->volt->stat)); $compiler = $volt->getCompiler(); //Add funcao $compiler->addFunction('is_a', 'is_a'); return $volt; }); /** * Configura o serviço de view */ $di->set('view', function () use($config, $vDI) { $view = new View(); $view->setViewsDir($config->application->viewsDir); $view->registerEngines(array('.volt' => 'volt')); return $view; }); return $di; }
/** * {@inheritdoc} * @see http://docs.phalconphp.com/en/latest/api/Phalcon_Db_Adapter_Pdo_Postgresql.html */ public function register(DiInterface $di) { $di->set(self::SERVICE_NAME, function () use($di) { $config = $di->get('config'); return new Phalcon\Db\Adapter\Pdo\Postgresql(["host" => $config->db->host, "dbname" => $config->db->dbname, "port" => $config->db->port, "username" => $config->db->username, "password" => $config->db->password]); }, true); }
public function access_token() { $session = $this->di->get('session'); $twitterOauth = $session->get('twitterOauth'); $request = $this->di->get('request'); $params = $this->uri_params(); if ($request->get('oauth_token') !== $twitterOauth['oauth_token']) { $this->di->get('logger')->begin(); $this->di->get('logger')->error('The oauth token you started with doesn\'t match the one you\'ve been redirected with. do you have multiple tabs open?'); $this->di->get('logger')->commit(); $session->remove('twitterOauth'); return; } if (!$request->get('oauth_verifier')) { $this->di->get('logger')->begin(); $this->di->get('logger')->error('The oauth verifier is missing so we cannot continue. did you deny the appliction access?'); $this->di->get('logger')->commit(); $session->remove('twitterOauth'); return; } // update with the temporary token and secret $this->reconfigure(array_merge($this->config, array('token' => $twitterOauth['oauth_token'], 'secret' => $twitterOauth['oauth_token_secret']))); $code = $this->user_request(array('method' => 'POST', 'url' => $this->url('oauth/access_token', ''), 'params' => array('oauth_verifier' => trim($request->get('oauth_verifier'))))); if ($code == 200) { $oauth_creds = $this->extract_params($this->response['response']); $this->reconfigure(array_merge($this->config, array('token' => $oauth_creds['oauth_token'], 'secret' => $oauth_creds['oauth_token_secret']))); $session->set('twitterOauth', $oauth_creds); } else { $this->di->get('logger')->begin(); $this->di->get('logger')->error('Access token: ' . json_encode($this->response)); $this->di->get('logger')->commit(); } }
public static function defineRoutes(DiInterface $di) { /* @var $router \Phalcon\Mvc\Router */ $router = $di->get('router'); $default = $router->getDefaults()['module']; $router->add("/customroute/foo/:params", array('module' => self::$modname, 'controller' => 'index', 'action' => 'foo', 'params' => 1))->setName(self::$modname . '_foo'); }
/** * {@inheritdoc} * @see http://docs.phalconphp.com/pl/latest/reference/odm.html */ public function register(DiInterface $di) { $di->set(self::SERVICE_NAME, function () use($di) { $mongoConfig = $di->get('config')->mongo->toArray(); if (isset($mongoConfig['dsn'])) { $hostname = $mongoConfig['dsn']; unset($mongoConfig['dsn']); } else { //obtains hostname if (isset($mongoConfig['host'])) { $hostname = 'mongodb://' . $mongoConfig['host']; } else { $hostname = 'mongodb://localhost'; } if (isset($mongoConfig['port'])) { $hostname .= ':' . $mongoConfig['port']; } //removes options that are not allowed in MongoClient constructor unset($mongoConfig['host']); unset($mongoConfig['port']); } $dbName = $mongoConfig['dbname']; unset($mongoConfig['dbname']); $mongo = new \MongoClient($hostname, $mongoConfig); return $mongo->selectDb($dbName); }, true); }
/** * {@inheritdoc} */ public function register(DiInterface $di) { $di->set(self::SERVICE_NAME, function () use($di) { $arrayConfig = $di->get('config')->db->toArray(); return new \Phalcon\Db\Adapter\Pdo\Mysql($arrayConfig); }, true); }
/** * {@inheritdoc} */ public function register(DiInterface $di) { $config = $di->get('config'); $di->set(self::SERVICE_NAME, function () use($config) { return new \Vegas\Translate\Adapter\Gettext(['locale' => $config->application->language, 'file' => 'messages', 'directory' => APP_ROOT . '/lang']); }); }
/** * {@inheritdoc} */ public function register(DiInterface $di) { $di->set(self::SERVICE_NAME, function () use($di) { $mongo = new \MongoClient(); return $mongo->selectDb($di->get('config')->mongo->db); }, true); }
/** * @param \Phalcon\DiInterface $di */ public function registerServices(\Phalcon\DiInterface $di = null) { // Set up MVC dispatcher. $controller_class = 'Modules\\' . $this->_module_class_name . '\\Controllers'; $di['dispatcher'] = function () use($controller_class) { $eventsManager = new \Phalcon\Events\Manager(); $eventsManager->attach("dispatch:beforeDispatchLoop", function ($event, $dispatcher) { // Set odd/even pairs as the key and value of parameters, respectively. $keyParams = array(); $params = $dispatcher->getParams(); foreach ($params as $position => $value) { if (is_int($position)) { if ($position & 1) { $keyParams[$params[$position - 1]] = urldecode($value); } } else { // The "name" parameter is internal to routes. if ($position != 'name') { $keyParams[$position] = urldecode($value); } } } $dispatcher->setParams($keyParams); // Detect filename in controller and convert to "format" parameter. $controller_name = $dispatcher->getControllerName(); if (strstr($controller_name, '.') !== false) { list($controller_clean, $format) = explode('.', $controller_name, 2); $dispatcher->setControllerName($controller_clean); $dispatcher->setParam('format', $format); } // Detect filename in action and convert to "format" parameter. $action_name = $dispatcher->getActionName(); if (strstr($action_name, '.') !== false) { list($action_clean, $format) = explode('.', $action_name, 2); $dispatcher->setActionName($action_clean); $dispatcher->setParam('format', $format); } }); $dispatcher = new \Phalcon\Mvc\Dispatcher(); $dispatcher->setEventsManager($eventsManager); $dispatcher->setDefaultNamespace($controller_class); return $dispatcher; }; // Set up module-specific configuration. $module_base_name = strtolower($this->_module_class_name); $module_config = $di->get('module_config'); $di->setShared('current_module_config', function () use($module_base_name, $module_config) { if (isset($module_config[$module_base_name])) { return $module_config[$module_base_name]; } else { return null; } }); // Set up the view component and shared templates. $views_dir = 'modules/' . $module_base_name . '/views/scripts/'; $di['view'] = function () use($views_dir) { return \FA\Phalcon\View::getView(array('views_dir' => $views_dir)); }; }
/** * Registers services related to the module * * @param mixed $dependencyInjector */ public function registerServices(DiInterface $dependencyInjector) { /** * @var $dispatcher \Phalcon\Mvc\Dispatcher */ $dispatcher = $dependencyInjector->get('dispatcher'); $dispatcher->setDefaultNamespace('Frontend\\Controller'); /** * @var $view \Phalcon\Mvc\View */ $view = $dependencyInjector->get('view'); $view->setLayout('index'); $view->setViewsDir(VIEW_PATH . '/frontend/'); $view->setLayoutsDir('../common/layouts/'); $view->setPartialsDir('../common/partials/'); $dependencyInjector->set('view', $view); }
/** * {@inheritdoc} */ public function register(DiInterface $di) { $di->set(self::SERVICE_NAME, function () use($di) { $url = new UrlResolver(); $url->setBaseUri($di->get('config')->application->baseUri); return $url; }, true); }
/** * 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'; }); }
/** * @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); } }
/** * {@inheritdoc} */ public function register(DiInterface $di) { $di->set(self::SERVICE_NAME, function () use($di) { $arrayConfig = (array) $di->get('config')->{self::SERVICE_NAME}; $db = new \Phalcon\Db\Adapter\Pdo\Sqlite($arrayConfig); $db->setEventsManager($di->getShared('eventsManager')); return $db; }, true); }
/** * 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\\Frontend\\'); return $dispatcher; }); $di->setShared('request', function () use($appConfig) { return new \Phalcon\Http\Request(); }); /** * Include config per environment */ include __DIR__ . '/config/config_' . $appConfig->application->environment . '.php'; $database = $di->getConfig()->application->site . $di->get('request')->getQuery("country_code"); /** * Simple database connection to localhost */ $di->setShared('mongo', function ($config, $database) { $mongo = new \Mongo(); return $mongo->selectDb($config->{$database}->dbname); }, true); $di->setShared('collectionManager', function () { return new \Phalcon\Mvc\Collection\Manager(); }, true); }