function run() { $routes = new RouteCollection(); foreach ($this->serviceManager->get('ConfigManager')->getConfig('routes') as $rota => $values) { $routes->add($rota, new Route($values['route'], array('controller' => $values['controller'], 'action' => $values['action']))); } $context = $this->serviceManager->get('RequestManager')->getContext(); $matcher = new UrlMatcher($routes, $context); $errorController = $this->getServiceManager()->get('ErrorController'); try { $parameters = $matcher->match($context->getPathInfo()); $controller = $this->getServiceManager()->get($parameters['controller']); $action = $this->getNomeAction($parameters['action']); if (false == method_exists($controller, $action)) { throw new Exception(sprintf('O Controller %s não possui o método %s', get_class($controller), $action)); } $actionParameters = $this->getActionParameters($parameters); if (true == method_exists($controller, 'beforeDispatch')) { call_user_func(array($controller, 'beforeDispatch')); } return call_user_func_array(array($controller, $action), $actionParameters); } catch (ResourceNotFoundException $ex) { return $errorController->actionError404(); } catch (MethodNotAllowedException $ex) { return $errorController->actionError500($ex); } catch (Exception $ex) { return $errorController->actionError500($ex); } }
public function __invoke(ServiceManager $serviceManager) { $db = $serviceManager->get('PDO'); $cpr = $serviceManager->get('RequestManager'); $debug = $serviceManager->get('ConfigManager')->getConfig('debug'); return new DataHelper($db, $cpr, $debug); }
public function __invoke(ServiceManager $serviceManager) { /* @var $configManager ConfigManager */ $configManager = $serviceManager->get('ConfigManager'); $renderer = $serviceManager->get('CupRenderer'); return new MailerManager($configManager->getConfig('mailer'), $renderer, $configManager->getConfig('dumpEmailOnScreen')); }
/** * getUserMapper * * @return \Profile\Mapper\UserMapper */ public function getUserMapper() { if (null === $this->userMapper) { $this->userMapper = $this->serviceManager->get('userMapper'); } return $this->userMapper; }
/** * @param ServiceManager $serviceManager * @return \UserHelper */ public function __invoke(ServiceManager $serviceManager) { /* @var $em EntityManager */ $em = $serviceManager->get('EntityManager'); /* @var $config ConfigManager */ $config = $serviceManager->get('ConfigManager'); return new UserHelper($em, $config->getConfig('userEntityName')); }
public function __invoke(ServiceManager $serviceManager) { /* @var $configManager ConfigManager */ $configManager = $serviceManager->get('ConfigManager'); $urlGenerator = $serviceManager->get('UrlGenerator'); $rendererConfig = $configManager->getConfig('renderer'); $siteConfig = $configManager->getConfig('site'); return new CupRenderer($rendererConfig['pastaTemplates'], $rendererConfig['pastaViews'], $siteConfig['titulo'], $urlGenerator); }
/** * Static method for quick and easy initialization of the Console Application. * * If you use this init() method, you cannot specify a service with the * name of 'ApplicationConfig' in your service manager config. This name is * reserved to hold the array from application.config.php. * * The following services can only be overridden from application.config.php: * * - ModuleManager * - SharedEventManager * - EventManager & Zend\EventManager\EventManagerInterface * * All other services are configured after module loading, thus can be * overridden by modules. * * @param array $configuration * @return Application */ public static function init($configuration = []) { $smConfig = isset($configuration['service_manager']) ? $configuration['service_manager'] : array(); $serviceManager = new ServiceManager(new Service\ServiceManagerConfig($smConfig)); $serviceManager->setService('ApplicationConfig', $configuration); $serviceManager->get('ModuleManager')->loadModules(); $listenersFromAppConfig = isset($configuration['listeners']) ? $configuration['listeners'] : array(); $config = $serviceManager->get('Config'); $listenersFromConfigService = isset($config['listeners']) ? $config['listeners'] : array(); $listeners = array_unique(array_merge($listenersFromConfigService, $listenersFromAppConfig)); return $serviceManager->get('Application')->bootstrap($listeners); }
public function __invoke(ServiceManager $serviceManager) { /* @var $configManager ConfigManager */ $configManager = $serviceManager->get('ConfigManager'); $databaseConfig = $configManager->getConfig('database'); return new PDO("mysql:host=" . $databaseConfig['host'] . ";dbname=" . $databaseConfig['dbname'], $databaseConfig['user'], $databaseConfig['password']); }
/** * @param ServiceManager $serviceManager * @return EntityManager */ public function __invoke(ServiceManager $serviceManager) { /* @var $configManager ConfigManager */ $configManager = $serviceManager->get('ConfigManager'); $databaseConfig = $configManager->getConfig('database'); $doctrineConfig = $configManager->getConfig('doctrine'); $connectionParams = array('dbname' => $databaseConfig['dbname'], 'user' => $databaseConfig['user'], 'password' => $databaseConfig['password'], 'host' => $databaseConfig['host'], 'driver' => 'pdo_mysql', 'charset' => 'utf8', 'driverOptions' => array(1002 => 'SET NAMES utf8')); $entitiesPaths = $doctrineConfig['entitiesPaths']; $proxyDir = $doctrineConfig['proxyDir']; $isDevMode = $configManager->getConfig('debug'); $setupConfig = Setup::createAnnotationMetadataConfiguration($entitiesPaths, $isDevMode, $proxyDir); $setupConfig->addCustomStringFunction('rand', 'Mapado\\MysqlDoctrineFunctions\\DQL\\MysqlRand'); $entityManager = EntityManager::create($connectionParams, $setupConfig); $platform = $entityManager->getConnection()->getDatabasePlatform(); $platform->registerDoctrineTypeMapping('enum', 'string'); return $entityManager; }
/** * Register additional view strategies * * If there is a "strategies" key of the view manager configuration, loop * through it. Pull each as a service from the service manager, and, if it * is a ListenerAggregate, attach it to the view, at priority 100. This * latter allows each to trigger before the default strategy, and for them * to trigger in the order they are registered. * * @return void */ private function registerViewStrategies() { if (!isset($this->config['strategies'])) { return; } $strategies = $this->config['strategies']; if (is_string($strategies)) { $strategies = [$strategies]; } if (!is_array($strategies) && !$strategies instanceof Traversable) { return; } $view = $this->getView(); $events = $view->getEventManager(); foreach ($strategies as $strategy) { if (!is_string($strategy)) { continue; } $listener = $this->services->get($strategy); if ($listener instanceof ListenerAggregateInterface) { $listener->attach($events, 100); } } }
/** * Constructor. * * @param ServiceManager $container Servicemanager. */ public function __construct(ContainerInterface $container) { $this->container = $container; $this->dispatcher = $this->container->get('event_dispatcher'); $this->event = new GenericEvent($this); }
/** * Retrieve a service from the manager by name * * Allows passing an array of options to use when creating the instance. * createFromInvokable() will use these and pass them to the instance * constructor if not null and a non-empty array. * * @param string $name * @param array $options * @param bool $usePeeringServiceManagers * @return object */ public function get($name, $options = array(), $usePeeringServiceManagers = true) { // Allow specifying a class name directly; registers as an invokable class if (!$this->has($name) && $this->autoAddInvokableClass && class_exists($name)) { $this->setInvokableClass($name, $name); } $this->creationOptions = $options; $instance = parent::get($name, $usePeeringServiceManagers); $this->creationOptions = null; $this->validatePlugin($instance); return $instance; }
function __invoke(ServiceManager $serviceManager) { return new UrlGenerator($serviceManager->get('RequestManager')); }
/** * Get a site entity by slug. * * @param ServiceManager $serviceLocator * @param string $slug * @return Site|null */ protected function getSite($serviceLocator, $slug) { return $serviceLocator->get('Omeka\\EntityManager')->createQuery('SELECT s FROM Omeka\\Entity\\Site s WHERE s.slug = :slug')->setParameter('slug', $slug)->getOneOrNullResult(); }