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); }
/** * getUserMapper * * @return \Profile\Mapper\UserMapper */ public function getUserMapper() { if (null === $this->userMapper) { $this->userMapper = $this->serviceManager->get('userMapper'); } return $this->userMapper; }
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')); }
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 \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); }
public function SCSTFC() { $sm = new ServiceManager(); $service_scst = $sm->getService("scst"); $this->service_scst_status = $service_scst->getStatus(); if ($this->service_scst_status === STATE_RUNNING) { $this->isRunning = TRUE; $this->reset(); } }
public function configureServiceManager(ServiceManager $serviceManager) { $allowOverride = $this->getAllowOverride(); isset($allowOverride) ? $serviceManager->setAllowOverride($allowOverride) : null; foreach ($this->getFactories() as $name => $factory) { $serviceManager->setFactory($name, $factory); } foreach ($this->getAbstractFactories() as $factory) { $serviceManager->addAbstractFactory($factory); } foreach ($this->getInvokables() as $name => $invokable) { $serviceManager->setInvokableClass($name, $invokable); } foreach ($this->getServices() as $name => $service) { $serviceManager->setService($name, $service); } foreach ($this->getAliases() as $alias => $nameOrAlias) { $serviceManager->setAlias($alias, $nameOrAlias); } foreach ($this->getInitializers() as $initializer) { $serviceManager->addInitializer($initializer); } foreach ($this->getShared() as $name => $isShared) { $serviceManager->setShared($name, $isShared); } }
/** * 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); }
protected function executeSave() { $redirect = $this->getRequestParameter('redirect'); $id = $this->getRequestParameter(); $m = $this->getRequestParameter('m', 'array', array()); try { $ex = ServiceManager::getInstance()->getByPk($id, true); $ex->addField('oldImage', 'string', $ex->image); $ex->updateFromRequest($m); if (!$ex->isValid()) { throw new EUserMessageError("Ошибка при сохранении", $ex); } if (!$ex->save()) { throw new EUserMessageError("Ошибка при сохранении", $ex); } $this->setFlash('Данные успешно сохранены', self::$FLASH_SUCCESS); $this->setHeader('redirect', fvSite::$fvConfig->get('dir_web_root') . $this->getRequest()->getRequestParameter('module') . ($redirect ? "" : "/edit/?id=" . $ex->getPk())); } catch (EUserMessageError $e) { $this->setFlash($e->getMessage(), self::$FLASH_ERROR); $this->setHeader('X-JSON', json_encode($e->getValidationResult())); } catch (EDatabaseError $db) { $this->setFlash($db->getMessage(), self::$FLASH_ERROR); } return $this->getRequest()->isXmlHttpRequest() ? self::$FV_AJAX_CALL : self::$FV_OK; }
/** * getInstance * * Get an instance of a service manager * * @param unknown_type $serviceModule - name of service module * @param unknown_type $serviceName - service name * @param unknown_type $serviceRootDir - optional service root directory; the default the APPLICATION's /lib/services dir * @return unknown */ public static function getInstance($serviceModule = false, $serviceName = false, $serviceRootDir = false, $databaseDir = false, $datasource = false, $enablePersistancy = false) { $enablePersistancy = false; if (!isset($_instance)) { self::$_instance = new self(); } self::$_instance->{FrameworkConstants::SERVICE_MODULE} = $serviceModule; self::$_instance->{FrameworkConstants::SERVICE_NAME} = $serviceName; if ($serviceRootDir) { self::$_instance->{FrameworkConstants::SERVICE_DIR} = $serviceRootDir; } else { self::$_instance->{FrameworkConstants::SERVICE_DIR} = APPLICATION_LIB_DIR . 'services/'; } if ($databaseDir) { self::$_instance->{FrameworkConstants::DAO_DIR} = $databaseDir; } else { self::$_instance->{FrameworkConstants::DAO_DIR} = APPLICATION_LIB_DIR . 'database/'; } if ($datasource) { self::$_instance->{FrameworkConstants::DATABASE_CONFIG_SECTION} = $datasource; } if ($enablePersistancy) { self::$_instance->{FrameworkConstants::DATABASE_PERSIST} = true; } self::$_instance->{FrameworkConstants::PLURALIZE} = 'true'; return self::$_instance; }
/** * @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; }
public function configureServiceManager(ServiceManager $serviceManager) { foreach ($this->getFactories() as $name => $factory) { $serviceManager->setFactory($name, $factory); } foreach ($this->getAbstractFactories() as $factory) { $serviceManager->addAbstractFactory($factory); } foreach ($this->getInvokables() as $name => $invokable) { $serviceManager->setInvokableClass($name, $invokable); } foreach ($this->getServices() as $name => $service) { $serviceManager->setService($name, $service); } foreach ($this->getAliases() as $alias => $nameOrAlias) { $serviceManager->setAlias($alias, $nameOrAlias); } foreach ($this->getShared() as $name => $isShared) { $serviceManager->setShared($name, $isShared); } }
function showEdit() { $id = $this->getRequestParameter(); $ex = ServiceManager::getInstance()->getByPk($id, true); $this->__assign("tmpDir", fvSite::$fvConfig->get("path.upload.web_temp_image")); $this->__assign("ex", $ex); $this->__assign("wt", range(-20, 20)); return $this->__display('edit.tpl'); }
public function actionIndex() { $model = new SysImportData(); if (isset($_POST["SysImportData"])) { $_POST['SysImportData']['model'] = $_GET['m']; ServiceManager::start('ImportData', $_POST["SysImportData"]); return; } $this->renderForm("SysImportData", $model); }
public function actionStart($name, $l = 1) { $params = ['svc' => null]; $options = []; if ($l == 0) { $options['layout'] = '//layouts/blank'; } $params['id'] = ServiceManager::run($name, $_GET); $this->renderForm("SysServiceForm", null, $params, $options); }
private function createProject(SimpleXMLElement $xml, Tuleap\Project\SystemEventRunner $event_runner) { $event_runner->checkPermissions(); $this->logger->info("Create project {$xml['unix-name']}"); $data = ProjectCreationData::buildFromXML($xml, 100, $this->xml_validator, ServiceManager::instance(), $this->project_manager); $project = $this->project_creator->build($data); $this->logger->info("Execute system events to finish creation of project {$project->getID()}, this can take a while..."); $event_runner->runSystemEvents(); $this->logger->info("System events success"); return $project; }
public function getSvc($name, $id = null) { $svc = []; if (!is_null($id)) { $svc = ServiceManager::getInstance($id); } else { if (!is_null($name)) { $svc = ServiceManager::getInstanceByName($name); } } return $svc; }
function showIndex() { $infra = ServiceManager::getInstance()->getAll("is_show=1 and service_type=" . ServiceManager::ST_INFRA, "weight asc"); $compl = ServiceManager::getInstance()->getAll("is_show=1 and service_type=" . ServiceManager::ST_COMPL, "weight asc"); $deliv = ServiceManager::getInstance()->getAll("is_show=1 and service_type=" . ServiceManager::ST_DELIV, "weight asc"); $serv = ServiceManager::getInstance()->getAll("is_show=1 and service_type=" . ServiceManager::ST_SERV, "weight asc"); $this->__assign("infra", $infra); $this->__assign("compl", $compl); $this->__assign("serv", $serv); $this->__assign("deliv", $deliv); $this->__assign("manager", ServiceManager::getInstance()); return $this->__display("index.tpl"); }
public function actionExecute($id) { ServiceManager::initLogAppend($id, "[OK]"); $running = true; while ($running) { if (ServiceManager::hasMsg($id)) { $svc = ServiceManager::readMsg($id); if (is_array($svc)) { $running = false; $commandPath = Yii::getPathOfAlias($svc['commandPath']); $commandName = lcfirst(substr($svc['command'], 0, strlen($svc['command']) - 7)); $actionName = lcfirst(substr($svc['action'], 6)); $GLOBALS['svc'] = $svc; $GLOBALS['svc_id'] = $id; ServiceManager::initLog($id, str_pad("Starting {$svc['name']} [PID:{$svc['pid']}]", 45, ".")); $runner = new CConsoleCommandRunner(); $runner->addCommands($commandPath); $runner->run(['yiic', $commandName, $actionName]); } } } }
/** * 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); } } }
protected function mockApplication($firewallEnabled = false) { $serviceManager = new ServiceManager(); //mock event manager $mockEventManager = $this->getMock('Zend\\EventManager\\EventManagerInterface'); //ensure the event manager "trigger" is executed $mockEventManager->expects($this->once())->method('trigger'); $serviceManager->setService('EventManager', $mockEventManager); //mock requests $mockRequest = $this->getMock('Zend\\Http\\Request'); $serviceManager->setService('Request', $mockRequest); $mockResponse = $this->getMock('Zend\\Http\\PhpEnvironment\\Response'); $serviceManager->setService('Response', $mockResponse); //mock application $mockApplication = $this->getMock('Zend\\Mvc\\Application', [], [[], $serviceManager]); $mockApplication->method('getEventManager')->willReturn($mockEventManager); $serviceManager->setService('Application', $mockApplication); }
function Project($param) { $this->Group($param); //for right now, just point our prefs array at Group's data array //this will change later when we split the project_data table off from groups table $this->project_data_array = $this->data_array; // Get defined classname of services // TODO: Move this in a helper for performances pov (load of many projects) $this->serviceClassnames = array('file' => 'ServiceFile', 'svn' => 'ServiceSVN'); EventManager::instance()->processEvent(Event::SERVICE_CLASSNAMES, array('classnames' => &$this->serviceClassnames)); // Get Service data $allowed_services = ServiceManager::instance()->getListOfAllowedServicesForProject($this); if (count($allowed_services) < 1) { $this->service_data_array = array(); } $j = 1; foreach ($allowed_services as $service) { $res_row = $service->data; $short_name = $service->getShortName(); if (!$short_name) { $short_name = $j++; } // needed for localisation $matches = array(); if ($res_row['description'] == "service_" . $short_name . "_desc_key") { $res_row['description'] = $GLOBALS['Language']->getText('project_admin_editservice', $res_row['description']); } elseif (preg_match('/(.*):(.*)/', $res_row['description'], $matches)) { if ($GLOBALS['Language']->hasText($matches[1], $matches[2])) { $res_row['description'] = $GLOBALS['Language']->getText($matches[1], $matches[2]); } } if ($res_row['label'] == "service_" . $short_name . "_lbl_key") { $res_row['label'] = $GLOBALS['Language']->getText('project_admin_editservice', $res_row['label']); } elseif (preg_match('/(.*):(.*)/', $res_row['label'], $matches)) { if ($GLOBALS['Language']->hasText($matches[1], $matches[2])) { $res_row['label'] = $GLOBALS['Language']->getText($matches[1], $matches[2]); } } $this->service_data_array[$short_name] = $res_row; if ($short_name) { $this->use_service[$short_name] = $service->isUsed(); } $this->services[$short_name] = $service; if ($service->isActive()) { $this->cache_active_services[] = $service; } } }
/** * 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); }
public function actionUpdate($id = null) { $model = DevServiceForm::load($id); if (!$model) { throw new CHttpException(404); } Asset::registerJS('application.static.js.lib.ace'); $instances = ServiceManager::getRunningInstance($id); $this->renderForm('DevServiceForm', $model, ['isRunning' => count($instances) > 0, 'instances' => $instances, 'log' => ServiceManager::readLog($id)]); }
/** @return ServiceManager */ private function getServiceManager() { return ServiceManager::instance(); }
/** * Create service via callback * * @param callable $callable * @param string $cName * @param string $rName * @throws Exception\ServiceNotCreatedException * @throws Exception\ServiceNotFoundException * @throws Exception\CircularDependencyFoundException * @return object */ protected function createServiceViaCallback($callable, $cName, $rName) { if (is_object($callable)) { $factory = $callable; } elseif (is_array($callable)) { // reset both rewinds and returns the value of the first array element $factory = reset($callable); } if (isset($factory) && $factory instanceof MutableCreationOptionsInterface && is_array($this->creationOptions) && !empty($this->creationOptions)) { $factory->setCreationOptions($this->creationOptions); } return parent::createServiceViaCallback($callable, $cName, $rName); }
/** * Register a service with the locator. * * Validates that the service object via validatePlugin() prior to * attempting to register it. * * @param string $name * @param mixed $service * @param bool $shared * @return AbstractPluginManager * @throws Exception\InvalidServiceNameException */ public function setService($name, $service, $shared = true) { if ($service) { $this->validatePlugin($service); } parent::setService($name, $service, $shared); return $this; }
/** * Configure service manager * * @param ServiceManager $serviceManager * @return void */ public function configureServiceManager(ServiceManager $serviceManager) { if (($allowOverride = $this->getAllowOverride()) !== null) { $serviceManager->setAllowOverride($allowOverride); } foreach ($this->getFactories() as $name => $factory) { $serviceManager->setFactory($name, $factory); } foreach ($this->getAbstractFactories() as $factory) { $serviceManager->addAbstractFactory($factory); } foreach ($this->getInvokables() as $name => $invokable) { $serviceManager->setInvokableClass($name, $invokable); } foreach ($this->getServices() as $name => $service) { $serviceManager->setService($name, $service); } foreach ($this->getAliases() as $alias => $nameOrAlias) { $serviceManager->setAlias($alias, $nameOrAlias); } foreach ($this->getInitializers() as $initializer) { $serviceManager->addInitializer($initializer); } foreach ($this->getShared() as $name => $isShared) { $serviceManager->setShared($name, $isShared); } foreach ($this->getDelegators() as $originalServiceName => $delegators) { foreach ($delegators as $delegator) { $serviceManager->addDelegator($originalServiceName, $delegator); } } }