コード例 #1
0
 /**
  * registering specific module services
  */
 public function registerServices(DiInterface $di)
 {
     $di->set('view', function () {
         $oView = new View();
         return $oView;
     });
     $oLogger = $di->getFileLogger();
     echo __FUNCTION__ . ' executed <br />' . PHP_EOL;
     //		$oDispatcherEventsManager = new Manager();
     /**
      * @type Dispatcher $oDispatcher
      */
     $oDispatcher = $di->getDispatcher();
     $oDispatcherEventsManager = $oDispatcher->getEventsManager();
     $oDispatcher->setDefaultNamespace('App\\Modules\\Regular\\Controllers');
     //		// Регистрация диспетчера
     //		$di->set('dispatcher', function() use($oDispatcherEventsManager) {
     //			$dispatcher = new Dispatcher();
     //			$dispatcher->setEventsManager($oDispatcherEventsManager);
     //			$dispatcher->setDefaultNamespace('App\Modules\Regular\Controllers');
     //			return $dispatcher;
     //		});
     $oDispatcherEventsManager->attach('dispatch', function ($event, $dispatcher, $exception) use($oLogger) {
         $oLogger->debug('module dispatcher: ' . $event->getType() . ': ' . $exception);
     });
     //
     //
     //
     //
     //		$oConfig = new Config(array(
     //			'application' => array(
     //				'viewsDir' => __DIR__ . '/views',
     //				'cacheDir' => __DIR__ . '/../../../var/cache/regular'
     //			),
     //		));
     //
     //		$di->get('config')->merge($oConfig);
     //
     //
     //		/**
     //		 * Setting up the view component
     //		 */
     //		$di->set('view', function () use ($di) {
     //
     //			$view = new View();
     //			$oConfig = $di->getConfig();
     //
     //			$view->setViewsDir($oConfig->application->viewsDir);
     //
     ////			$view->registerEngines(array(
     ////				'.volt' => function ($view, $di) use ($oConfig) {
     ////
     ////					$volt = new VoltEngine($view, $di);
     ////
     ////					$volt->setOptions(array(
     ////						'compiledPath' => $oConfig->application->cacheDir,
     ////						'compiledSeparator' => '_'
     ////					));
     ////
     ////					return $volt;
     ////				},
     ////				'.phtml' => 'Phalcon\Mvc\View\Engine\Php'
     ////			));
     //
     //			return $view;
     //		}, true);
     //
     ////
     ////		// Регистрация компонента представлений
     ////		$di->set('view', function() {
     ////			$view = new View();
     ////			$view->setViewsDir('../apps/backend/views/');
     ////			return $view;
     ////		});
 }
コード例 #2
0
 /**
  * registering module-specific services
  *
  * @param \DiCustom $di
  */
 public function registerServices(DiInterface $di)
 {
     $oLogger = $di->getFileLogger();
     //		$oRouter = new Router(false);
     $oRouter = new CustomRouter(false);
     //		$oOldRouter = $di->getRouter();
     //		Tester::ec('old router: ' . HC::className($oOldRouter));
     $di->set('router', $oRouter);
     //		Tester::ec('new router set: ' . HC::className($di->getRouter()));
     $oRouter->mount(new ApiRoutes($di));
     $oVersionLoader = new VersionLoader();
     $di->set('versionLoader', $oVersionLoader);
     //		$oApiDispatcherEventsManager = new Manager();
     ////		$oLogger = $di->getFileLogger();
     //		$oRouter = $di->getRouter();
     //
     //		$oLogger->debug('api module ' . __FUNCTION__ . ': setting up dispatcher');
     //
     //		$oApiDispatcherEventsManager->attach('dispatch', function(Event $event, Dispatcher $dispatcher, $data) use($oLogger, $oRouter){
     //			$oLogger->debug('api dispatcher: ' . $event->getType() . ': ' . print_r($oRouter->getMatchedRoute(), true));
     //		});
     //
     //
     //		$oDispatcher = $di->getDispatcher();
     //		$oDispatcher->setDefaultNamespace('App\Modules\Api\Web');
     //		$oDispatcher->setControllerSuffix('Homorrag');
     //		$oDispatcher->setEventsManager($oApiDispatcherEventsManager);
     $oDispatcher = new Dispatcher();
     $oApiDispatcherEventsManager = new Manager();
     $oApiDispatcherEventsManager->attach('dispatch:beforeDispatchLoop', function (Event $oEvent, Dispatcher $oDispatcher, $data) {
         /**
          * @type \DiCustom $di
          */
         $di = Di::getDefault();
         $oLogger = $di->getFileLogger();
         $arParams = $oDispatcher->getParams();
         $oLogger->debug(__CLASS__ . ': ' . $oEvent->getType() . ': trying to dispatch:' . ' module: ' . $oDispatcher->getModuleName() . ' media: ' . $arParams['media'] . ' version: v' . $arParams['major'] . '_' . $arParams['minor'] . ' controller: ' . $oDispatcher->getControllerName() . ' action: ' . $oDispatcher->getActionName());
         $di->getVersionLoader()->load();
     });
     $oApiDispatcherEventsManager->attach('dispatch', function (Event $oEvent, Dispatcher $oDispatcher, $data) {
         /**
          * @type \DiCustom $di
          */
         $di = Di::getDefault();
         $oLogger = $di->getFileLogger();
         //			$oRouter = $di->getRouter();
         //
         //			$arParams = $oRouter->getParams();
         //
         //			$oLogger->debug(__CLASS__ . ': ' . $oEvent->getType() . ': trying to dispatch: from router: '
         //				. ' module: ' . $oRouter->getModuleName()
         //				. ' media: ' . $arParams['media']
         //				. ' version: v' . $arParams['major'] . '_' . $arParams['minor']
         //				. ' controller: ' . $oRouter->getControllerName()
         //				. ' action: ' . $oRouter->getActionName()
         //			);
         $arParams = $oDispatcher->getParams();
         $oLogger->debug(__CLASS__ . ': ' . $oEvent->getType() . ': trying to dispatch: from dispatcher: ' . ' module: ' . $oDispatcher->getModuleName() . ' media: ' . $arParams['media'] . ' version: v' . $arParams['major'] . '_' . $arParams['minor'] . ' controller: ' . $oDispatcher->getControllerName() . ' action: ' . $oDispatcher->getActionName());
         //			$oLogger->debug(__CLASS__ . ': ' . $oEvent->getType());
     });
     $oDispatcher->setEventsManager($oApiDispatcherEventsManager);
     $di->setShared('dispatcher', $oDispatcher);
     //		$di->set('dispatcher', function() use($di){
     //			$dispatcher = new Dispatcher();
     //			$oApiDispatcherEventsManager = new Manager();
     //			$oLogger = $di->getFileLogger();
     //			$oRouter = $di->getRouter();
     //			$oRequest = $di->getRequest();
     //
     //			$oLogger->debug('api module ' . __FUNCTION__ . ': setting up dispatcher');
     //
     //			$oApiDispatcherEventsManager->attach('dispatch', function(Event $event, Dispatcher $dispatcher, $data) use($oLogger, $oRouter, $oRequest){
     //
     //				if($event->getType() == 'beforeDispatchLoop'){
     //
     //					$arRoutes = $oRouter->getRoutes();
     //
     //					foreach ($arRoutes as $oRoute) {
     //						$oRoute->beforeMatch(function($uri, $route) use ($oLogger){
     //							$oLogger->debug('__ api module dispatcher route beforeMatch: ' . $uri . $route);
     //
     //						});
     //						$oLogger->debug('api module dispatcher: ' . $event->getType() . ': route registered: ' . $oRoute->getCompiledPattern());
     //
     //						$regPattern = $oRoute->getCompiledPattern();
     //
     //						$strUri = $oRequest->getURI();
     //
     //						if(preg_match($regPattern, $strUri)){
     //							$oLogger->debug('"' . $strUri . '" matched ' . $regPattern);
     //						}else{
     //							$oLogger->debug('"' . $strUri . '" mismatched ' . $regPattern);
     //						}
     //
     //					}
     //
     //				}
     //
     //				$oLogger->debug('api dispatcher: ' . $event->getType() . ': route matched: ' . print_r($oRouter->getMatchedRoute(), true));
     //				$oLogger->debug('api dispatcher: ' . $event->getType()
     //					. ' module "' . $oRouter->getModuleName()
     //					. '" controller: "' . $oRouter->getControllerName()
     //					. '" action: "' . $oRouter->getActionName() . '"'
     //				);
     //			});
     //
     //			$dispatcher->setEventsManager($oApiDispatcherEventsManager);
     //			$dispatcher->setDefaultNamespace('App\Modules\Api\Web');
     //			return $dispatcher;
     //		});
     //
     //
     //
     //		$oConfig = new Config(array(
     //			'application' => array(
     //				'viewsDir' => __DIR__ . '/views',
     //				'cacheDir' => __DIR__ . '/../../../var/cache/regular'
     //			),
     //		));
     //
     //		$di->get('config')->merge($oConfig);
     /**
      * Setting up the view component
      */
     $di->set('view', function () use($oLogger) {
         $oView = new View();
         $oView->setRenderLevel(View::LEVEL_NO_RENDER);
         $oView->disable();
         $oLogger->debug('view: render level set to disabled');
         //Disable several levels
         //			$view->disableLevel(array(
         //				View::LEVEL_LAYOUT      => true,
         //				View::LEVEL_MAIN_LAYOUT => true
         //			));
         return $oView;
     }, true);
 }