/** * Registers services related to the module * * @param DiInterface $di Dependency Injection Container */ public function registerServices(DiInterface $di) { /** * Read configuration */ $config = (require __DIR__ . "/config/config.php"); /** * Setting up the view component */ $di->setShared('view', function () { $view = new View(); $view->setViewsDir(__DIR__ . '/views/'); $view->setTemplateBefore('main'); $view->registerEngines([".volt" => function ($view, $di) { $volt = new Volt($view, $di); $volt->setOptions(['compiledPath' => function ($templatePath) { return realpath(__DIR__ . "/../../var/volt") . '/' . md5($templatePath) . '.php'; }, 'compiledExtension' => '.php', 'compiledSeparator' => '%']); return $volt; }]); return $view; }); /** * Database connection is created based in the parameters defined in the configuration file */ $di->setShared('db', function () use($config) { return new Connection(['host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname]); }); }
public function registerServices(DiInterface $di) { global $config; $di->setShared('url', function () use($config) { $url = new UrlResolver(); $url->setBaseUri($config->backend->baseUri); return $url; }); $di->setShared('dispatcher', function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace("Multiple\\Backend\\Controllers"); return $dispatcher; }); $di->setShared('view', function () use($config) { $view = new View(); $view->setViewsDir($config->backend->viewsDir); $view->setLayoutsDir('layouts/'); $view->setPartialsDir('partials/'); $view->registerEngines(array('.phtml' => function ($view, $di) use($config) { $volt = new VoltEngine($view, $di); $volt->setOptions(array('compiledPath' => $config->backend->cacheDir, 'compiledSeparator' => '_')); return $volt; }, '.volt' => 'Phalcon\\Mvc\\View\\Engine\\Php')); return $view; }); }
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) { /** * 获取全局配置 */ $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); }
/** * {@inheritdoc} * * @param \Phalcon\DI $di */ public function registerServices(DiInterface $di = null) { $di->getDispatcher()->setDefaultNamespace('Webird\\Web\\Controllers'); $di->setShared('view', $this->getViewFunc($di)); if (DEV_ENV === ENV) { $debugPanel = new DebugPanel($di); } // //Listen for events produced in the dispatcher using the Security plugin // $evManager = $di->getShared('eventsManager'); // // $evManager->attach("dispatch:beforeException", function($event, $dispatcher, $exception) use ($di) { // // switch ($exception->getCode()) { // // case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND: // case Dispatcher::EXCEPTION_ACTION_NOT_FOUND: // // $dispatcher->forward([ // 'controller' => 'errors', // 'action' => 'show404', // ]); // // return FALSE; // break; // } // }); }
public function setDI(DiInterface $di) { $di->setShared('config', static::$config); $this->initEventsManager($di); parent::setDI($di); Di::setDefault($di); }
/** * Initialize the Application Config. */ protected function initConfig() { $this->di->setShared('config', function () { $path = BASE_DIR . 'app/config/'; if (!is_readable($path . 'config.php')) { throw new RuntimeException('Unable to read config from ' . $path . 'config.php'); } $config = (include $path . 'config.php'); if (is_array($config)) { $config = new Config($config); } if (!$config instanceof Config) { $type = gettype($config); if ($type == 'boolean') { $type .= $type ? ' (true)' : ' (false)'; } elseif (is_object($type)) { $type = get_class($type); } throw new RuntimeException(sprintf('Unable to read config file. Config must be either an array or Phalcon\\Config instance. Got %s', $type)); } if (is_readable($path . APPLICATION_ENV . '.php')) { $override = (include_once $path . APPLICATION_ENV . '.php'); if (is_array($override)) { $override = new Config($override); } if ($override instanceof Config) { $config->merge($override); } } return $config; }); }
/** * @param \Phalcon\DiInterface $di * * @return \Phalcon\DiInterface */ public function registerServices($di) { $this->registerAutoloaders(); $di->set('view', function () use($di) { $view = new View(); $view->setViewsDir(AUTOADMINMODULEROOT . '/views/'); return $view; }); $di->setShared('entityManager', function () use($di) { return new EntityManager(); }); $di->setShared('assets', function () { return new AssetsManager(['sourceBasePath' => AUTOADMINMODULEROOT . '/assets/', 'targetBasePath' => PUBLICROOT . '/assets/']); }); return $di; }
/** * Register the services here to make them general * or register in the ModuleDefinition to make them module-specific */ public function registerServices(DiInterface $di) { //Read configuration $config = (include __DIR__ . "/config/config.php"); // The URL component is used to generate all kind of urls in the application $di->set('url', function () use($config) { $url = new Url(); $url->setBaseUri($config->application->baseUri); return $url; }); //Registering a dispatcher $di->set('dispatcher', function () { //Create/Get an EventManager $eventsManager = new EventsManager(); //Attach a listener $eventsManager->attach('dispatch', function ($event, $dispatcher, $exception) { //controller or action doesn't exist if ($event->getType() == 'beforeException') { switch ($exception->getCode()) { case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND: case Dispatcher::EXCEPTION_ACTION_NOT_FOUND: $dispatcher->forward(['module' => 'backend', 'controller' => 'errors', 'action' => 'notFound']); return false; } } }); $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace("Phanbook\\Backend\\Controllers"); $dispatcher->setEventsManager($eventsManager); return $dispatcher; }); /** * Setting up the view component */ $di->set('view', function () use($config) { $view = new View(); $view->setViewsDir($config->application->viewsDir); $view->disableLevel([View::LEVEL_MAIN_LAYOUT => true, View::LEVEL_LAYOUT => true]); $view->registerEngines(['.volt' => 'volt']); // Create an event manager $eventsManager = new EventsManager(); // Attach a listener for type 'view' $eventsManager->attach('view', function ($event, $view) { if ($event->getType() == 'notFoundView') { throw new \Exception('View not found!!! (' . $view->getActiveRenderPath() . ')'); } }); // Bind the eventsManager to the view component $view->setEventsManager($eventsManager); return $view; }); $configMenu = (include __DIR__ . "/config/config.menu.php"); $di->setShared('menuStruct', function () use($configMenu) { // if structure received from db table instead getting from $config // we need to store it to cache for reducing db connections $struct = $configMenu->get('menuStruct')->toArray(); return $struct; }); }
/** * @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)); }; }
/** * {@inheritdoc} * * @param \Phalcon\DI $di */ public function registerServices(DiInterface $di = null) { $di->getDispatcher()->setDefaultNamespace('Webird\\Admin\\Controllers'); $di->setShared('view', $this->getViewFunc($di)); if (DEV_ENV === ENV) { $debugPanel = new DebugPanel($di); } }
/** * 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); }
public static function init(Di $di, $defaultTube = 'default') { $config = $di->get('config'); if (!isset($config->queue)) { return; } $params = (array) $config->queue; $di->setShared(self::SERVICE_NAME, function () use($params, $defaultTube) { $beanstalk = new Beanstalk($params); $beanstalk->choose($defaultTube); return $beanstalk; }); }
/** * 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; } } $di->setShared('config', $config); /** * 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(); }); // 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'; }); }
/** * Register the services here to make them general or register in the ModuleDefinition to make them module-specific */ public function registerServices(DiInterface $di) { // Setup the Dispatcher service $di->get('dispatcher')->setDefaultNamespace("App\\Backend\\Controllers\\"); // Registering a Smarty shared-service $di->setShared('smarty', function () use($di) { $smarty = new \Smarty(); $options = ['left_delimiter' => '<{', 'right_delimiter' => '}>', 'template_dir' => ROOT_DIR . '/app/Backend/Views', 'compile_dir' => ROOT_DIR . '/runtime/Smarty/compile', 'cache_dir' => ROOT_DIR . '/runtime/Smarty/cache', 'error_reporting' => error_reporting() ^ E_NOTICE, 'escape_html' => true, 'force_compile' => false, 'compile_check' => true, 'caching' => false, 'debugging' => true]; foreach ($options as $k => $v) { $smarty->{$k} = $v; } $BaseUri = './'; $smarty->assign('BaseUri', $BaseUri); return $smarty; }); // Registering a Html shared-service $di->setShared('html', function () use($di) { $smarty = $di->get('smarty'); $router = $di->get('router'); $controller = $router->getControllerName(); $action = $router->getActionName(); return $smarty->display(implode('/', [$controller, $action]) . '.html'); }); }
/** * 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'; }); }
public static function init(Di $di, $isDevelopment = false) { $config = $di->get('config'); $sentryDsn = ''; if (isset($config->sentry->dsn)) { $sentryDsn = $config->sentry->dsn; } $client = new \Raven_Client($sentryDsn); if ($isDevelopment) { error_reporting(E_ALL); ini_set('display_errors', 1); } else { $error_handler = new \Raven_ErrorHandler($client); $error_handler->registerExceptionHandler(); $error_handler->registerErrorHandler(); $error_handler->registerShutdownFunction(); } $di->setShared(self::SERVICE_NAME, function () use($client) { return $client; }); }
public static function init(Di $di) { $di->setShared(self::SERVICE_NAME, function () { return new GeoIp(); }); }
public function run(Api $api, DiInterface $di, Config $config) { /** * @description Config - \Phalcon\Config */ $di->setShared(Services::CONFIG, $config); /** * @description Phalcon - \Phalcon\Db\Adapter\Pdo\Mysql */ $di->set(Services::DB, function () use($config, $di) { $config = $config->get('database')->toArray(); $adapter = $config['adapter']; unset($config['adapter']); $class = 'Phalcon\\Db\\Adapter\\Pdo\\' . $adapter; $connection = new $class($config); // Assign the eventsManager to the db adapter instance $connection->setEventsManager($di->get(Services::EVENTS_MANAGER)); return $connection; }); /** * @description Phalcon - \Phalcon\Mvc\Url */ $di->set(Services::URL, function () use($config) { $url = new UrlResolver(); $url->setBaseUri($config->get('application')->baseUri); return $url; }); /** * @description Phalcon - \Phalcon\Mvc\View\Simple */ $di->set(Services::VIEW, function () use($config) { $view = new View(); $view->setViewsDir($config->get('application')->viewsDir); return $view; }); /** * @description Phalcon - EventsManager */ $di->setShared(Services::EVENTS_MANAGER, function () use($di, $config) { return new EventsManager(); }); /** * @description Phalcon - TokenParsers */ $di->setShared(Services::TOKEN_PARSER, function () use($di, $config) { return new JWTTokenParser($config->get('authentication')->secret, JWTTokenParser::ALGORITHM_HS256); }); /** * @description Phalcon - AuthManager */ $di->setShared(Services::AUTH_MANAGER, function () use($di, $config) { $authManager = new AuthManager($config->get('authentication')->expirationTime); $authManager->registerAccountType(UsernameAccountType::NAME, new UsernameAccountType()); return $authManager; }); /** * @description Phalcon - \Phalcon\Mvc\Model\Manager */ $di->setShared(Services::MODELS_MANAGER, function () use($di) { $modelsManager = new ModelsManager(); return $modelsManager->setEventsManager($di->get(Services::EVENTS_MANAGER)); }); /** * @description PhalconRest - \League\Fractal\Manager */ $di->setShared(Services::FRACTAL_MANAGER, function () { $fractal = new FractalManager(); $fractal->setSerializer(new CustomSerializer()); return $fractal; }); /** * @description PhalconRest - \PhalconRest\User\Service */ $di->setShared(Services::USER_SERVICE, new UserService()); }
/** * 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->setShared('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; }); }
public static function init(Di $di) { $di->setShared(self::SERVICE_NAME, function () { return new ApplicationCookie(); }); }
/** * Initialize time zones. * * @param DiInterface $di Dependency Injector * @param Config $config App config * @param EventsManager $em Events Manager * * @return void */ protected function initTimezones(DiInterface $di, Config $config, EventsManager $em) { $di->setShared('timezones', function () use($config) { return require_once BASE_DIR . 'app/config/timezones.php'; }); }
public static function init(Di $di, $userModelName = null) { $di->setShared(self::SERVICE_NAME, function () use($userModelName) { return new Auth($userModelName); }); }
/** * {@inheritdoc} * * @param \Phalcon\DI $di */ public function registerServices(DiInterface $di = null) { $di->getDispatcher()->setDefaultNamespace('Webird\\Api\\Controllers'); $di->setShared('view', $this->getViewFunc($di)); }
/** * Регистрация сервисов модуля */ public function registerServices(\Phalcon\DiInterface $di) { $config = new \Phalcon\Config\Adapter\Ini(__DIR__ . '/config/config.ini'); // Set site config $di->set('config', $config); // Setting up mongo $di->set('mongo', function () use($config) { $mongo = new \MongoClient($config->database->host, array('connectTimeoutMS' => intval($config->database->timeout))); return $mongo->selectDb($config->database->name); }, true); // Mongo with users $di->set('mongoUsers', function () use($config) { $mongo = new \MongoClient($config->database->usersHost, array('connectTimeoutMS' => intval($config->database->timeout))); return $mongo->selectDb($config->database->usersName); }, true); // Mongo with users $di->set('mongoLog', function () use($config) { $mongo = new \MongoClient($config->database->logHost, array('connectTimeoutMS' => intval($config->database->timeout))); return $mongo->selectDb($config->database->logName); }, true); // Service for running users $di->set('userService', '\\Kladr\\Core\\Services\\UserService'); // Registering the collectionManager service $di->set('collectionManager', function () { $modelsManager = new \Phalcon\Mvc\Collection\Manager(); return $modelsManager; }, true); // Setting up dispatcher $di->set('dispatcher', function () use($di) { $dispatcher = new \Phalcon\Mvc\Dispatcher(); $dispatcher->setDefaultNamespace('Kladr\\Core\\Controllers'); return $dispatcher; }); // Setting memcache $di->set('memcache', function () use($config) { $frontCache = new \Phalcon\Cache\Frontend\Data(array("lifetime" => 86400)); $cache = new \Phalcon\Cache\Backend\Memcache($frontCache, array("host" => $config->memcache->host, "port" => $config->memcache->port)); return $cache; }); // Settings mongocache $di->set('mongocache', function () use($config) { $frontCache = new \Phalcon\Cache\Frontend\Data(array("lifetime" => 86400)); $cache = new \Phalcon\Cache\Backend\Mongo($frontCache, array('server' => 'mongodb://' . $config->mongocache->host, 'db' => $config->mongocache->db, 'collection' => $config->mongocache->collection, 'connectTimeoutMS' => intval($config->mongocache->timeout))); return $cache; }); // Setting cache $di->set('cache', array('className' => '\\Kladr\\Core\\Plugins\\Tools\\Cache', 'properties' => array(array('name' => 'cache', 'value' => array('type' => 'service', 'name' => 'mongocache')), array('name' => 'config', 'value' => array('type' => 'service', 'name' => 'config'))))); //setting sphinxapi $di->set('sphinxapi', function () use($config) { include dirname(__FILE__) . '/plugins/tools/sphinxapi.php'; $sphinxapi = new \SphinxClient(); $sphinxapi->SetServer($config->sphinxapi->server, $config->sphinxapi->port); return $sphinxapi; }); // Register validate plugin $di->set('validate', function () { return new \Kladr\Core\Plugins\General\ValidatePlugin(); }); // Register oneString plugin $di->set('oneString', array('className' => '\\Kladr\\Core\\Plugins\\General\\OneStringPlugin', 'properties' => array(array('name' => 'cache', 'value' => array('type' => 'service', 'name' => 'cache')), array('name' => 'sphinxClient', 'value' => array('type' => 'service', 'name' => 'sphinxapi'))))); // Register find plugin $di->set('find', array('className' => '\\Kladr\\Core\\Plugins\\General\\FindPlugin', 'properties' => array(array('name' => 'cache', 'value' => array('type' => 'service', 'name' => 'cache'))))); // Register special cases plugin $di->set('specialCases', array('className' => '\\Kladr\\Core\\Plugins\\General\\SpecialCasesPlugin', 'properties' => array(array('name' => 'cache', 'value' => array('type' => 'service', 'name' => 'cache'))))); // Register duplicate plugin $di->set('duplicate', array('className' => '\\Kladr\\Core\\Plugins\\General\\DuplicatePlugin', 'properties' => array(array('name' => 'cache', 'value' => array('type' => 'service', 'name' => 'cache'))))); // Register find parents plugin $di->set('findParents', array('className' => '\\Kladr\\Core\\Plugins\\General\\FindParentsPlugin', 'properties' => array(array('name' => 'cache', 'value' => array('type' => 'service', 'name' => 'cache'))))); // Register find parents plugin $di->set('parentsSpecialCases', array('className' => '\\Kladr\\Core\\Plugins\\General\\ParentsSpecialCasesPlugin', 'properties' => array(array('name' => 'cache', 'value' => array('type' => 'service', 'name' => 'cache'))))); // Register find parents plugin $di->set('logPaidUsersPlugin', array('className' => '\\Kladr\\Core\\Plugins\\General\\LogPaidUsersPlugin', 'properties' => array(array('name' => 'userService', 'value' => array('type' => 'service', 'name' => 'userService'))))); $di->set('allDataPlugin', array('className' => '\\Kladr\\Core\\Plugins\\General\\AllDataPlugin', 'properties' => array(array('name' => 'userService', 'value' => array('type' => 'service', 'name' => 'userService')), array('name' => 'cacheDir', 'value' => array('type' => 'parameter', 'value' => $config->application->cacheDir)), array('name' => 'disablePaid', 'value' => array('type' => 'parameter', 'value' => $config->application->disablePaid))))); $di->set('enabledTokensPlugin', '\\Kladr\\Core\\Plugins\\General\\EnabledTokensPlugin'); // Register GA $di->set('apiTracker', function () use($config) { if ($config->ga->code == '') { return false; } return new \Racecore\GATracking\GATracking($config->ga->code); }); // Setting api $di->setShared('api', function () use($di, $config) { $api = new Services\ApiService($di->get('apiTracker')); if ($config->application->enableTokens) { $api->addPlugin($di->get('enabledTokensPlugin')); } if ($config->application->enableUserLog) { $api->addPlugin($di->get('logPaidUsersPlugin')); } $api->addPlugin($di->get('allDataPlugin')); $api->addPlugin($di->get('validate')); if ($config->sphinxapi->enabled) { $api->addPlugin($di->get('oneString')); } $api->addPlugin($di->get('find')); //$api->addPlugin($di->get('specialCases')); //$api->addPlugin($di->get('duplicate')); $api->addPlugin($di->get('findParents')); $api->addPlugin($di->get('parentsSpecialCases')); return $api; }); // Setting up the view component $di->set('view', function () use($config) { $view = new \Phalcon\Mvc\View(); $view->setViewsDir($config->application->viewsDir); return $view; }); }