function setup() { $this->application = new ApplicationWithTerminalWidth('TestApplication', '0.0.0'); $this->commandFactory = new AnnotatedCommandFactory(); // $factory->addListener(...); $alterOptionsEventManager = new AlterOptionsCommandEvent($this->application); $eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $eventDispatcher->addSubscriber($this->commandFactory->commandProcessor()->hookManager()); $eventDispatcher->addSubscriber($alterOptionsEventManager); $this->application->setDispatcher($eventDispatcher); $this->application->setAutoExit(false); $discovery = new CommandFileDiscovery(); $discovery->setSearchPattern('*CommandFile.php')->setIncludeFilesAtBase(false)->setSearchLocations(['alpha']); chdir(__DIR__); $commandFiles = $discovery->discover('.', '\\Consolidation\\TestUtils'); $formatter = new FormatterManager(); $formatter->addDefaultFormatters(); $formatter->addDefaultSimplifiers(); $terminalWidthOption = new PrepareTerminalWidthOption(); $terminalWidthOption->setApplication($this->application); $this->commandFactory->commandProcessor()->setFormatterManager($formatter); $this->commandFactory->commandProcessor()->addPrepareFormatter($terminalWidthOption); $this->commandFactory->setIncludeAllPublicMethods(false); $this->addDiscoveredCommands($this->commandFactory, $commandFiles); $helpCommandfile = new HelpCommand($this->application); $commandList = $this->commandFactory->createCommandsFromClass($helpCommandfile); foreach ($commandList as $command) { $this->application->add($command); } }
function setup() { $this->application = new ApplicationWithTerminalWidth('TestApplication', '0.0.0'); $this->commandFactory = new AnnotatedCommandFactory(); $alterOptionsEventManager = new AlterOptionsCommandEvent($this->application); $eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $eventDispatcher->addSubscriber($this->commandFactory->commandProcessor()->hookManager()); $eventDispatcher->addSubscriber($alterOptionsEventManager); $this->application->setDispatcher($eventDispatcher); $this->application->setAutoExit(false); }
public function registerServices($container) { // Me $container->set('kernel', $this); // Routes $container->set('routes', function ($c) { return new \Symfony\Component\Routing\RouteCollection(); }); // Request/Routes $container->set('request_stack', function ($c) { return new \Cerad\Component\HttpMessage\RequestStack(); }); /* ============================================= * $this->context->getHost() * $this->context->getMethod() * $this->context->getScheme() */ $container->set('request_context', function ($c) { $request = $c->get('request_stack')->getMasterRequest(); $context = []; $context['method'] = $request->getMethod(); return $context; }); $container->set('route_matcher', function ($c) { $routes = []; $tags = $c->getTags('routes'); foreach ($tags as $tag) { $serviceId = $tag['service_id']; $service = $c->get($serviceId); $routes[$serviceId] = $service; } return new \Cerad\Component\HttpRouting\UrlMatcher($routes, $c->get('request_context')); }); $container->set('route_generator', function ($c) { return new \Symfony\Component\Routing\Generator\UrlGenerator($c->get('routes'), $c->get('request_context')); }); $container->set('database_connection', function ($c) { $config = new \Doctrine\DBAL\Configuration(); $connectionParams = ['url' => $c->get('db_url'), 'driverOptions' => [\PDO::ATTR_EMULATE_PREPARES => false]]; $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); return $conn; }); $container->set('event_dispatcher', function ($c) { $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $tags = $c->getTags('event_listener'); foreach ($tags as $tag) { $listener = $c->get($tag['service_id']); $dispatcher->addSubscriber($listener); } return $dispatcher; }); $container->set('kernel_cors_listener', function () { return new \Cerad\Module\KernelModule\EventListener\CorsListener(); }, 'event_listener'); }
<?php include_once __DIR__ . '/../vendor/autoload.php'; ini_set('display_errors', 1); $adapter = new Itkg\Core\Cache\Adapter\Bridge\Doctrine(new \Doctrine\Common\Cache\FilesystemCache('/tmp')); $registry = new \Itkg\Core\Cache\Adapter\Registry(); $eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $eventDispatcher->addSubscriber(new \Itkg\Consumer\Listener\CacheListener($eventDispatcher)); $eventDispatcher->addSubscriber(new \Itkg\Consumer\Listener\LoggerListener()); $eventDispatcher->addSubscriber(new \Itkg\Consumer\Listener\DeserializerListener(JMS\Serializer\SerializerBuilder::create()->build())); $eventDispatcher->addSubscriber(new \Itkg\Consumer\Listener\CacheControlListener(new \Itkg\Consumer\Cache\ServiceCacheQueueWriter($adapter))); $service = new \Itkg\Consumer\Service\Service($eventDispatcher, new Itkg\Consumer\Client\RestClient(array('timeout' => 10)), array('identifier' => 'my test', 'cache_adapter' => $adapter, 'cache_ttl' => 3600, 'cache_warmup' => true, 'cache_fresh_ttl' => 10)); $service->sendRequest(\Symfony\Component\HttpFoundation\Request::create('XXXX'))->getResponse(); $service = new \Itkg\Consumer\Service\Service($eventDispatcher, new Itkg\Consumer\Client\RestClient(array('timeout' => 10)), array('cache_ttl' => 20, 'cache_adapter' => $registry, 'identifier' => 'my test')); $service->sendRequest(\Symfony\Component\HttpFoundation\Request::create('XXXX'))->getResponse(); $service = new \Itkg\Consumer\Service\Service($eventDispatcher, new Itkg\Consumer\Client\RestClient(array('timeout' => 10)), array('identifier' => 'my test', 'logger' => new \Monolog\Logger('my_logger', array(new \Monolog\Handler\StreamHandler('/tmp/test'))))); $response = $service->sendRequest(\Symfony\Component\HttpFoundation\Request::create('XXXX'))->getResponse();
/** * @param string $entity * @param string $action * @param array $params * @param bool $throws whether we should pass any exceptions for authorization failures * * @throws API_Exception * @throws Exception * @return bool TRUE or FALSE depending on the outcome of the authorization check */ function runPermissionCheck($entity, $action, $params, $throws = FALSE) { $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addSubscriber(new \Civi\API\Subscriber\PermissionCheck()); $kernel = new \Civi\API\Kernel($dispatcher); $apiRequest = \Civi\API\Request::create($entity, $action, $params, NULL); try { $kernel->authorize(NULL, $apiRequest); return TRUE; } catch (\API_Exception $e) { $extra = $e->getExtraParams(); if (!$throws && $extra['error_code'] == API_Exception::UNAUTHORIZED) { return FALSE; } else { throw $e; } } }
#!/usr/bin/php <?php $config = ['require_services' => ['sf_event_dispatcher', 'sf_http_foundation', 'sf_debug', 'psr_log', 'sf_routing'], 'git_urls' => ['https://github.com/symfony/HttpKernel.git' => 'sf_http_kernel/'], 'autoload_config' => ['sf_http_kernel/' => 'Symfony\\Component\\HttpKernel'], 'example' => function () { $old_level = error_reporting(); error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_USER_DEPRECATED & ~E_STRICT); $routes = new \Symfony\Component\Routing\RouteCollection(); $routes->add('hello', new \Symfony\Component\Routing\Route('/', ['_controller' => function (\Symfony\Component\HttpFoundation\Request $request) { return new \Symfony\Component\HttpFoundation\Response(sprintf("Hello %s", $request->get('name'))); }])); $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals(); $context = new \Symfony\Component\Routing\RequestContext(); $context->fromRequest($request); $matcher = new \Symfony\Component\Routing\Matcher\UrlMatcher($routes, $context); $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addSubscriber(new \Symfony\Component\HttpKernel\EventListener\RouterListener($matcher)); $resolver = new \Symfony\Component\HttpKernel\Controller\ControllerResolver(); $kernel = new \Symfony\Component\HttpKernel\HttpKernel($dispatcher, $resolver); $kernel->handle($request)->send(); echo PHP_EOL; error_reporting($old_level); }]; if ($return_config) { return $config; } require_once __DIR__ . '/_yf_autoloader.php'; new yf_autoloader($config);
function assertRunCommandViaApplicationEquals($command, $input, $expectedOutput, $expectedStatusCode = 0) { $output = new BufferedOutput(); if ($this->commandFileInstance && method_exists($this->commandFileInstance, 'setOutput')) { $this->commandFileInstance->setOutput($output); } $application = new Application('TestApplication', '0.0.0'); $alterOptionsEventManager = new AlterOptionsCommandEvent($application); $eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $eventDispatcher->addSubscriber($this->commandFactory->commandProcessor()->hookManager()); $eventDispatcher->addSubscriber($alterOptionsEventManager); $application->setDispatcher($eventDispatcher); $application->setAutoExit(false); $application->add($command); $statusCode = $application->run($input, $output); $commandOutput = trim($output->fetch()); $this->assertEquals($expectedOutput, $commandOutput); $this->assertEquals($expectedStatusCode, $statusCode); }
/** * @see EventDispatcherInterface::addSubscriber() * * @api */ public static function addSubscriber(Symfony\Component\EventDispatcher\EventSubscriberInterface $subscriber) { return static::$instance->addSubscriber($subscriber); }
$fs->copy(Application::ROOT_DIR . '/app/resources/envmgr.db', $envMgrPath . '/envmgr.db'); // Try to connect to the database. $database = new Database($envMgrPath . '/envmgr.db'); } catch (DatabaseNotFoundException $e) { print sprintf('Error: %s' . "\n", $e->getMessage()); exit; } catch (Exception $e) { print 'An unknown exception occured while trying to load the database.' . "\n"; exit; } return $database; }); $c->addService('docker', function () { return new \commpress\Cli\Service\Docker\DockerManager(); }); $c->addService('filesystem', function () { return new \commpress\Cli\Service\Filesystem\Filesystem(); }); $c->addService('platform_config_parser', function () { return new \commpress\Cli\Service\Platform\PlatformConfigParser(); }); $c->addService('drupal.helper', function () { return new \commpress\Cli\Service\Drupal\DrupalHelper(); }); $c->addService('event_dispatcher', function () { $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addSubscriber(new \commpress\Cli\Event\Subscriber\EnvironmentSubscriber()); $dispatcher->addSubscriber(new \commpress\Cli\Event\Subscriber\VirtualHostSubscriber()); return $dispatcher; }); return $c;
public function register(Application $app) { $config = $this->config; $app['devture_nagios.bundle_path'] = dirname(__FILE__); $app['devture_nagios.colors'] = array('#014de7', '#3a87ad', '#06cf99', '#8fcf06', '#dda808', '#e76d01', '#7801e7', '#353535', '#888888'); $app['devture_nagios.db'] = $app->share(function ($app) use($config) { return $app[$config['database_service_id']]; }); $app['devture_nagios.event_dispatcher'] = $app->share(function ($app) { $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); foreach ($app['devture_nagios.event_subscribers'] as $subscriber) { $dispatcher->addSubscriber($subscriber); } return $dispatcher; }); $app['devture_nagios.event_subscribers'] = function ($app) { return array($app['devture_nagios.time_period.event_subscriber'], $app['devture_nagios.command.event_subscriber'], $app['devture_nagios.host.event_subscriber'], $app['devture_nagios.contact.event_subscriber']); }; $app['devture_nagios.time_period.event_subscriber'] = $app->share(function ($app) { return new Event\Subscriber\TimePeriodEventsSubscriber($app); }); $app['devture_nagios.time_period.repository'] = $app->share(function ($app) { return new Repository\TimePeriodRepository($app['devture_nagios.event_dispatcher'], $app['devture_nagios.db']); }); $app['devture_nagios.time_period.validator'] = function ($app) { return new Validator\TimePeriodValidator($app['devture_nagios.time_period.repository']); }; $app['devture_nagios.time_period.form_binder'] = function ($app) { $binder = new Form\TimePeriodFormBinder($app['devture_nagios.time_period.validator']); $binder->setCsrfProtection($app['devture_framework.csrf_token_manager'], 'time_period'); return $binder; }; $app['devture_nagios.command.event_subscriber'] = $app->share(function ($app) { return new Event\Subscriber\CommandEventsSubscriber($app); }); $app['devture_nagios.command.repository'] = $app->share(function ($app) { return new Repository\CommandRepository($app['devture_nagios.event_dispatcher'], $app['devture_nagios.db']); }); $app['devture_nagios.command.validator'] = function ($app) { return new Validator\CommandValidator($app['devture_nagios.command.repository']); }; $app['devture_nagios.command.form_binder'] = function ($app) { $binder = new Form\CommandFormBinder($app['devture_nagios.command.validator']); $binder->setCsrfProtection($app['devture_framework.csrf_token_manager'], 'command'); return $binder; }; $app['devture_nagios.contact.event_subscriber'] = $app->share(function ($app) { return new Event\Subscriber\ContactEventsSubscriber($app); }); $app['devture_nagios.contact.repository'] = $app->share(function ($app) { return new Repository\ContactRepository($app['devture_nagios.event_dispatcher'], $app['devture_nagios.time_period.repository'], $app['devture_nagios.command.repository'], $app['devture_user.repository'], $app['devture_nagios.db']); }); $app['devture_nagios.contact.validator'] = function ($app) { return new Validator\ContactValidator($app['devture_nagios.contact.repository']); }; $app['devture_nagios.contact.form_binder'] = function ($app) { $binder = new Form\ContactFormBinder($app['devture_nagios.time_period.repository'], $app['devture_nagios.command.repository'], $app['devture_user.repository'], $app['devture_nagios.helper.access_checker'], $app['devture_user.access_control'], $app['devture_nagios.contact.validator']); $binder->setCsrfProtection($app['devture_framework.csrf_token_manager'], 'contact'); return $binder; }; $app['devture_nagios.host.event_subscriber'] = $app->share(function ($app) { return new Event\Subscriber\HostEventsSubscriber($app); }); $app['devture_nagios.host.repository'] = $app->share(function ($app) { return new Repository\HostRepository($app['devture_nagios.event_dispatcher'], $app['devture_nagios.db']); }); $app['devture_nagios.host.validator'] = function ($app) { return new Validator\HostValidator($app['devture_nagios.host.repository']); }; $app['devture_nagios.host.form_binder'] = function ($app) { $binder = new Form\HostFormBinder($app['devture_nagios.host.validator']); $binder->setCsrfProtection($app['devture_framework.csrf_token_manager'], 'host'); return $binder; }; $app['devture_nagios.service.defaults'] = new \ArrayObject($config['defaults']['service']); $app['devture_nagios.service.repository'] = $app->share(function ($app) { return new Repository\ServiceRepository($app['devture_nagios.host.repository'], $app['devture_nagios.command.repository'], $app['devture_nagios.contact.repository'], $app['devture_nagios.db']); }); $app['devture_nagios.service.validator'] = function ($app) { return new Validator\ServiceValidator($app['devture_nagios.service.repository']); }; $app['devture_nagios.service.form_binder'] = function ($app) { $binder = new Form\ServiceFormBinder($app['devture_nagios.contact.repository'], $app['devture_nagios.service.validator']); $binder->setCsrfProtection($app['devture_framework.csrf_token_manager'], 'service'); return $binder; }; $app['devture_nagios.resource.repository'] = $app->share(function ($app) { return new Repository\ResourceRepository($app['devture_nagios.db']); }); $app['devture_nagios.resource.validator'] = function ($app) { return new Validator\ResourceValidator(); }; $app['devture_nagios.resource.form_binder'] = function ($app) { $binder = new Form\ResourceFormBinder($app['devture_nagios.resource.validator']); $binder->setCsrfProtection($app['devture_framework.csrf_token_manager'], 'resource'); return $binder; }; $app['devture_nagios.helper.colorizer'] = $app->share(function ($app) { return new Helper\Colorizer($app['devture_nagios.colors']); }); $app['devture_nagios.helper.access_checker'] = $app->share(function ($app) { return new Helper\AccessChecker(); }); $app['devture_nagios.twig.extension'] = function ($app) { return new Twig\NagiosExtension($app); }; $this->overrideUserServices($app); $this->registerDeploymentServices($app); $this->registerEmailServices($app); $this->registerSmsServices($app); $this->registerInstallerServices($app); $this->registerInteractionServices($app); $this->registerApiModelBridgeServices($app); $this->registerConsoleServices($app); $this->registerControllers($app); }