public function setUp() { $containerBuilder = new \DI\ContainerBuilder(); $containerBuilder->addDefinitions([iConfig::class => \DI\object(Config::class)->constructor(require __DIR__ . '/../config/main.php')]); $this->_container = $containerBuilder->build(); $this->init(); }
public function register() { $this->set($this->routeClass, \DI\object($this->routeClass)); $this->set('Symfony\\Component\\HttpFoundation\\Request', \DI\Factory(function () { return \Symfony\Component\HttpFoundation\Request::createFromGlobals(); })); $this->registerRoutes(); }
public function __construct() { $builder = new \DI\ContainerBuilder(); $container = $builder->build(); //Register Notification Implementation $container->set('Services_NotifyInterface', \DI\object('Services_TwitterNotify')); $this->_container = $container; return $container; }
private function parseDefinitions(array $definitions) { return array_map(function ($service) { if (preg_match('/^@/', $service)) { return \DI\link(preg_replace('/^@(.+)/', '$1', $service)); } else { return \DI\object($service); } }, $definitions); }
#!/usr/bin/env php <?php /** * Load correct autoloader depending on install location. */ if (file_exists(__DIR__ . '/../vendor/autoload.php')) { require __DIR__ . '/../vendor/autoload.php'; } else { require __DIR__ . '/../../../autoload.php'; } use Ptondereau\PackMe\Commands\CreateCommand; use Silly\Edition\PhpDi\Application; /* * Application bootstrap. */ $version = '2.0.8'; $app = new Application('Laravel PackMe', $version); /* * Inject dependencies. */ $container = $app->getContainer(); $container->set(\Symfony\Component\Console\Helper\HelperSet::class, DI\object()->constructor(['question' => new \Symfony\Component\Console\Helper\QuestionHelper()])); $container->set(\Ptondereau\PackMe\Crafters\CrafterInterface::class, DI\object(\Ptondereau\PackMe\Crafters\PHPCrafter::class)); /* * Create the package with user's answers. */ $app->command('create [dir]', CreateCommand::class)->descriptions('Create your package with a given directory', ['dir' => 'Your directory name']); /* * Run the application. */ $app->run();
<?php use DI\Scope; return ['A' => \DI\object()->scope(Scope::PROTOTYPE()), 'B' => \DI\object()->scope(Scope::PROTOTYPE()), 'C' => \DI\object()->scope(Scope::PROTOTYPE()), 'D' => \DI\object()->scope(Scope::PROTOTYPE()), 'E' => \DI\object()->scope(Scope::PROTOTYPE()), 'F' => \DI\object()->scope(Scope::PROTOTYPE()), 'G' => \DI\object()->scope(Scope::PROTOTYPE()), 'H' => \DI\object()->scope(Scope::PROTOTYPE()), 'I' => \DI\object()->scope(Scope::PROTOTYPE()), 'J' => \DI\object()->scope(Scope::PROTOTYPE())];
<?php use DI\Container; use Psr\Log\LoggerInterface; use Symfony\Component\Config\FileLocator; use Symfony\Component\EventDispatcher\EventDispatcher; return [EventDispatcher::class => DI\object(), FileLocator::class => DI\object()->constructor(APP_HOME), 'logger.level' => Monolog\Logger::DEBUG, 'logger.file' => APP_HOME . '/var/log/homeservice.log', LoggerInterface::class => DI\factory(function (Container $c) { return new Monolog\Logger('logger', [new Monolog\Handler\ChromePHPHandler($c->get('logger.level')), new Monolog\Handler\StreamHandler($c->get('logger.file'), $c->get('logger.level')), new Monolog\Handler\RavenHandler($c->get(Raven_Client::class))]); }), Raven_Client::class => DI\object()->constructor('https://*****:*****@app.getsentry.com/43338')];
<?php return array('Piwik\\Plugins\\CoreUpdater\\Updater' => DI\object()->constructorParameter('tmpPath', DI\get('path.tmp')), 'diagnostics.optional' => DI\add(array(DI\get('Piwik\\Plugins\\CoreUpdater\\Diagnostic\\HttpsUpdateCheck'))));
$level = strtoupper($c->get('ini.log.log_level')); if (!empty($level) && defined('Piwik\\Log::' . strtoupper($level))) { return Log::getMonologLevel(constant('Piwik\\Log::' . strtoupper($level))); } } return Logger::WARNING; }), 'log.file.filename' => DI\factory(function (ContainerInterface $c) { $logPath = $c->get('ini.log.logger_file_path'); // Absolute path if (strpos($logPath, '/') === 0) { return $logPath; } // Remove 'tmp/' at the beginning if (strpos($logPath, 'tmp/') === 0) { $logPath = substr($logPath, strlen('tmp')); } if (empty($logPath)) { // Default log file $logPath = '/logs/piwik.log'; } $logPath = $c->get('path.tmp') . $logPath; if (is_dir($logPath)) { $logPath .= '/piwik.log'; } return $logPath; }), 'Piwik\\Plugins\\Monolog\\Formatter\\LineMessageFormatter' => DI\object()->constructor(DI\get('log.format')), 'log.format' => DI\factory(function (ContainerInterface $c) { if ($c->has('ini.log.string_message_format')) { return $c->get('ini.log.string_message_format'); } return '%level% %tag%[%datetime%] %message%'; }));
<?php return ['event_manager' => \DI\decorate(function ($eventManager, $container) { $eventManager->attach('ERROR_DISPATCH', [$container->get(\ClassicApp\EventListener\DispatcherExceptionListener::class), 'onError']); $eventManager->attach('*', [$container->get(\ClassicApp\EventListener\ExceptionListener::class), 'onError']); return $eventManager; }), \ClassicApp\EventListener\ExceptionListener::class => \DI\object(\ClassicApp\EventListener\ExceptionListener::class)->constructor(\DI\get('template')), \ClassicApp\EventListener\DispatcherExceptionListener::class => \DI\object(\ClassicApp\EventListener\DispatcherExceptionListener::class)->constructor(\DI\get('template')), 'dispatcher' => \DI\factory(function (\DI\Container $c) { $dispatcher = new \ClassicApp\Dispatcher\SymfonyDispatcher($c->get('router')); return $dispatcher; }), 'session' => \DI\factory(function (\DI\Container $c) { $session = new \Symfony\Component\HttpFoundation\Session\Session(); $session->start(); return $session; }), 'translator' => \DI\factory(function () { $translator = new \Symfony\Component\Translation\Translator('en_US', new \Symfony\Component\Translation\MessageSelector()); $translator->addLoader('php', new \Symfony\Component\Translation\Loader\PhpFileLoader()); $translator->addResource('php', './app/Resources/translator/en_US.php', 'en_US'); $translator->addResource('php', './app/Resources/translator/it_IT.php', 'it_IT'); return $translator; }), 'template' => \DI\factory(function (\DI\Container $c) { $twigBridgeViews = __DIR__ . '/../vendor/symfony/twig-bridge/Resources/views/Form'; $loader = new Twig_Loader_Filesystem([$twigBridgeViews, './app/Resources/view']); $twig = new Twig_Environment($loader, $c->get('parameters')['twig']['loader_options']); $twig->addGlobal('show_exception_backtrace', $c->get('parameters')['twig']['show_exception_backtrace']); $twig->addGlobal('session', $c->get('session')); $formEngine = new \Symfony\Bridge\Twig\Form\TwigRendererEngine(['bootstrap_3_layout.html.twig']); $formEngine->setEnvironment($twig); $formExt = new \Symfony\Bridge\Twig\Extension\FormExtension(new \Symfony\Bridge\Twig\Form\TwigRenderer($formEngine)); $twig->addExtension($formExt); $transExt = new \Symfony\Bridge\Twig\Extension\TranslationExtension($c->get('translator')); $twig->addExtension($transExt);
<?php return ['dependencies' => ['Zend\\Expressive\\Whoops' => DI\object(Whoops\Run::class), 'Zend\\Expressive\\WhoopsPageHandler' => DI\object(Whoops\Handler\PrettyPageHandler::class), 'Zend\\Expressive\\FinalHandler' => DI\factory(Zend\Expressive\Container\WhoopsErrorHandlerFactory::class)], 'whoops' => ['json_exceptions' => ['display' => true, 'show_trace' => true, 'ajax_only' => true]]];
public function provideContainerConfig() { return array('Piwik\\Plugin\\Manager' => \DI\object('Piwik\\Tests\\Unit\\AssetManager\\PluginManagerMock')); }
$builder = new \DI\ContainerBuilder(); $builder->useAnnotations(true); if (\Fraym\Core::ENV_STAGING === ENV || \Fraym\Core::ENV_PRODUCTION === ENV) { error_reporting(-1); ini_set("display_errors", 0); $builder->writeProxiesToFile(true, CACHE_DI_PATH); define('GLOBAL_CACHING_ENABLED', true); $apcEnabled = (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled'); } else { error_reporting(-1); ini_set("display_errors", 1); define('GLOBAL_CACHING_ENABLED', false); $apcEnabled = false; } define('APC_ENABLED', $apcEnabled); if (defined('IMAGE_PROCESSOR') && IMAGE_PROCESSOR === 'Imagick') { $builder->addDefinitions(['Imagine' => DI\object('Imagine\\Imagick\\Imagine')]); } elseif (defined('IMAGE_PROCESSOR') && IMAGE_PROCESSOR === 'Gmagick') { $builder->addDefinitions(['Imagine' => DI\object('Imagine\\Gmagick\\Imagine')]); } else { $builder->addDefinitions(['Imagine' => DI\object('Imagine\\Gd\\Imagine')]); } $builder->addDefinitions(['db.options' => array('driver' => DB_DRIVER, 'user' => DB_USER, 'password' => DB_PASS, 'host' => DB_HOST, 'dbname' => DB_NAME, 'charset' => DB_CHARSET)]); if (APC_ENABLED) { $cache = new Doctrine\Common\Cache\ApcuCache(); } else { $cache = new Doctrine\Common\Cache\ArrayCache(); } $cache->setNamespace('Fraym_instance_' . FRAYM_INSTANCE); $builder->setDefinitionCache($cache); $diContainer = $builder->build();
<?php use Interop\Container\ContainerInterface; use Psr\Log\LogLevel; use Symfony\Component\Console\Output\OutputInterface; return ['steps.init' => [], 'steps.before' => [], 'steps.preprocessing' => [], 'steps.postprocessing' => [], 'steps.after' => [], 'steps' => function (ContainerInterface $c) { return array_merge($c->get('steps.init'), $c->get('steps.before'), $c->get('steps.preprocessing'), $c->get('steps.postprocessing'), $c->get('steps.after')); }, 'Couscous\\Generator' => DI\object()->constructorParameter('steps', DI\get('steps')), 'application' => DI\object('Symfony\\Component\\Console\\Application')->method('add', DI\get('Couscous\\Application\\Cli\\GenerateCommand'))->method('add', DI\get('Couscous\\Application\\Cli\\PreviewCommand'))->method('add', DI\get('Couscous\\Application\\Cli\\DeployCommand'))->method('add', DI\get('Couscous\\Application\\Cli\\ClearCommand'))->method('add', DI\get('Couscous\\Application\\Cli\\TravisAutoDeployCommand'))->method('add', DI\get('Couscous\\Application\\Cli\\InitTemplateCommand')), 'Symfony\\Component\\Console\\Logger\\ConsoleLogger' => DI\object()->constructorParameter('verbosityLevelMap', [LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL, LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL, LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL, LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL, LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL, LogLevel::NOTICE => OutputInterface::VERBOSITY_NORMAL, LogLevel::INFO => OutputInterface::VERBOSITY_VERBOSE, LogLevel::DEBUG => OutputInterface::VERBOSITY_VERY_VERBOSE])];
<?php $repository = $config['repository']; return ['dependencies' => ['repository' => $config['repository'], 'EntityManager' => DI\factory([FNBr\Infrastructure\Persistence\Doctrine\EntityManagerFactory::class, 'build']), '*Repository' => DI\factory("FNBr\\Infrastructure\\Persistence\\RepositoryFactory"), 'ColorQueryService' => DI\object(FNBr\Application\Service\Color\QueryService::class)->constructor(DI\get('ColorRepository')), 'ColorSaveService' => DI\object(FNBr\Application\Service\Color\SaveService::class)->constructor(DI\get('ColorRepository'))]];
<?php return array('Piwik\\Cache\\Backend' => DI\object('Piwik\\Cache\\Backend\\ArrayCache'), 'Piwik\\Translation\\Loader\\LoaderInterface' => DI\object('Piwik\\Translation\\Loader\\LoaderCache')->constructor(DI\get('Piwik\\Translation\\Loader\\DevelopmentLoader')), 'Piwik\\Translation\\Loader\\DevelopmentLoader' => DI\object()->constructor(DI\get('Piwik\\Translation\\Loader\\JsonFileLoader')));
<?php return ["parameters" => ["database" => ["host" => "127.0.0.1", "user" => "root", "password" => "root", "dbName" => "app"]], "redis" => \DI\object("Predis\\Client"), "rate-limiter" => \DI\object('App\\Service\\RateLimiter')->constructor(\DI\get("redis")), "router" => function () { return \FastRoute\simpleDispatcher(function (\FastRoute\RouteCollector $r) { $r->addRoute('GET', '/', ['App\\Controller\\IndexController', 'index'], ["name" => "index"]); $r->addRoute('GET', '/reset', ['App\\Controller\\MessageController', 'resetToken'], ["name" => "reset"]); $r->addRoute('GET', '/message', ['App\\Controller\\MessageController', 'getList'], ["name" => "message.list"]); $r->addRoute('POST', '/message', ['App\\Controller\\MessageController', 'create'], ["name" => "message.create"]); }); }];
<?php return [ZohoBooksAL\Configuration\Reader\ConfigFileReader::class => DI\object()->constructorParameter('configurationFileName', __DIR__ . '/../config.inc.php'), ZohoBooksAL\Persister\PersistedEntityTracker::class => DI\object()->scope(\DI\Scope::PROTOTYPE), ZohoBooksAL\Configuration\Configuration::class => DI\object()->constructorParameter('configurationReader', DI\get(ZohoBooksAL\Configuration\Reader\ConfigFileReader::class)), ZohoBooksAL\Transport\GenericTransport::class => DI\object()->constructorParameter('httpClient', DI\get(GuzzleHttp\Client::class)), ZohoBooksAL\Mapper\GenericMapper::class => DI\object()->constructorParameter('transport', DI\get(ZohoBooksAL\Transport\GenericTransport::class)), ZohoBooksAL\EntityManager::class => DI\object()->constructorParameter('configuration', DI\get(ZohoBooksAL\Configuration\Configuration::class)), ZohoBooksAL\Transport\Uri\Uri::class => DI\object()->constructorParameter('configuration', DI\get(ZohoBooksAL\Configuration\Configuration::class)), ZohoBooksAL\UnitOfWork::class => DI\object()->constructorParameter('mapper', DI\get(ZohoBooksAL\Mapper\GenericMapper::class)), Zend\Code\Annotation\AnnotationManager::class => DI\object()->method('attach', DI\get(ZohoBooksAL\Code\Annotation\Parser\AnnotationParser::class)), ZohoBooksAL\Metadata\Collector\EntityCollector::class => DI\object()->constructorParameter('manager', DI\get(Zend\Code\Annotation\AnnotationManager::class))->constructorParameter('scanner', DI\get(Zend\Code\Scanner\DirectoryScanner::class)), ZohoBooksAL\Metadata\MetadataCollection::class => DI\object()->constructorParameter('collector', DI\get(ZohoBooksAL\Metadata\Collector\EntityCollector::class))];
public function provideContainerConfig() { return array('Piwik\\CliMulti' => \DI\object('Piwik\\Tests\\Framework\\Mock\\FakeCliMulti')); }
} else { $instanceId = ''; } return $root . '/tmp' . $instanceId; }, 'path.cache' => DI\string('{path.tmp}/cache/tracker/'), 'Piwik\\Cache\\Eager' => function (ContainerInterface $c) { $backend = $c->get('Piwik\\Cache\\Backend'); $cacheId = $c->get('cache.eager.cache_id'); if (SettingsServer::isTrackerApiRequest()) { $eventToPersist = 'Tracker.end'; $cacheId .= 'tracker'; } else { $eventToPersist = 'Request.dispatch.end'; $cacheId .= 'ui'; } $cache = new Eager($backend, $cacheId); \Piwik\Piwik::addAction($eventToPersist, function () use($cache) { $cache->persistCacheIfNeeded(43200); }); return $cache; }, 'Piwik\\Cache\\Backend' => function (ContainerInterface $c) { try { $backend = $c->get('ini.Cache.backend'); } catch (NotFoundException $ex) { $backend = 'chained'; // happens if global.ini.php is not available } return \Piwik\Cache::buildBackend($backend); }, 'cache.eager.cache_id' => function () { return 'eagercache-' . str_replace(array('.', '-'), '', \Piwik\Version::VERSION) . '-'; }, 'Psr\\Log\\LoggerInterface' => DI\object('Psr\\Log\\NullLogger'), 'Piwik\\Translation\\Loader\\LoaderInterface' => DI\object('Piwik\\Translation\\Loader\\LoaderCache')->constructor(DI\get('Piwik\\Translation\\Loader\\JsonFileLoader')), 'observers.global' => array(), 'Piwik\\EventDispatcher' => DI\object()->constructorParameter('observers', DI\get('observers.global')));
public function provideContainerConfig() { $self = $this; $cacheProxy = $this->getMock('Piwik\\Cache\\Lazy', array('fetch', 'contains', 'save', 'delete', 'flushAll'), array(), '', $callOriginalConstructor = false); $cacheProxy->expects($this->any())->method('fetch')->willReturnCallback(function ($id) { $realCache = StaticContainer::get('Piwik\\Cache\\Lazy'); return $realCache->fetch($id); }); $cacheProxy->expects($this->any())->method('contains')->willReturnCallback(function ($id) use($self) { $realCache = StaticContainer::get('Piwik\\Cache\\Lazy'); $result = $realCache->contains($id); if ($result) { ++$self->tableLogActionCacheHits; } return $result; }); $cacheProxy->expects($this->any())->method('save')->willReturnCallback(function ($id, $data, $lifetime = 0) { $realCache = StaticContainer::get('Piwik\\Cache\\Lazy'); return $realCache->save($id, $data, $lifetime); }); $cacheProxy->expects($this->any())->method('delete')->willReturnCallback(function ($id) { $realCache = StaticContainer::get('Piwik\\Cache\\Lazy'); return $realCache->delete($id); }); $cacheProxy->expects($this->any())->method('flushAll')->willReturnCallback(function () { $realCache = StaticContainer::get('Piwik\\Cache\\Lazy'); return $realCache->flushAll(); }); return array('Piwik\\Access' => new FakeAccess(), 'Piwik\\Tracker\\TableLogAction\\Cache' => \DI\object()->constructorParameter('cache', $cacheProxy)); }
<?php return ['event_manager' => \DI\decorate(function ($eventManager, $container) { $eventManager->attach("ERROR_DISPATCH", [$container->get(\ClassicApp\EventListener\DispatcherExceptionListener::class), "onError"]); $eventManager->attach("*_error", [$container->get(\ClassicApp\EventListener\ExceptionListener::class), "onError"]); return $eventManager; }), \ClassicApp\EventListener\ExceptionListener::class => \DI\object(\ClassicApp\EventListener\ExceptionListener::class)->constructor(\DI\get("template")), \ClassicApp\EventListener\DispatcherExceptionListener::class => \DI\object(\ClassicApp\EventListener\DispatcherExceptionListener::class)->constructor(\DI\get("template")), 'template' => \DI\object(\League\Plates\Engine::class)->constructor('./app/view/'), 'router' => function () { return \FastRoute\simpleDispatcher(function (\FastRoute\RouteCollector $r) { $r->addRoute('GET', '/', ['ClassicApp\\Controller\\IndexController', 'index']); }); }];
<?php use DI\ContainerBuilder; return call_user_func(function () { $builder = new ContainerBuilder(); $builder->useAnnotations(false); $builder->useAutowiring(false); $builder->addDefinitions(['cache_path' => '/tmp/cache', CacheProvider::class => \DI\object(FileCache::class)->constructorParameter('path', \DI\get('cache_path')), UserRepository::class => \DI\object()->constructorParameter('cache', \DI\get(CacheProvider::class))]); return $builder->build(); });
<?php use Air\View\ViewFactoryInterface; use Air\View\Mustache\ViewFactory; return [ViewFactoryInterface::class => DI\object(ViewFactory::class)->constructorParameter('partialsDir', __DIR__ . '/../View/')->methodParameter('addPath', 'viewPath', __DIR__ . '/../View/')];
<?php use Ratchet\Http\HttpServerInterface; use React\Socket\ServerInterface; use stigsb\pixelpong\bitmap\BitmapLoader; use stigsb\pixelpong\bitmap\FontLoader; use stigsb\pixelpong\frame\FrameBuffer; use stigsb\pixelpong\frame\OffscreenFrameBuffer; $__topdir = dirname(__DIR__); $__w = 47; $__h = 27; return ['framebuffer.width' => $__w, 'framebuffer.height' => $__h, 'server.port' => DI\env('PONG_PORT', '4432'), 'server.bind_addr' => DI\env('PONG_BIND_ADDR', '0.0.0.0'), 'server.fps' => DI\env('PONG_FPS', '10.0'), FrameBuffer::class => DI\object(OffscreenFrameBuffer::class)->constructor(DI\get('framebuffer.width'), DI\get('framebuffer.height')), ServerInterface::class => DI\object(React\Socket\Server::class), HttpServerInterface::class => DI\object(Ratchet\WebSocket\WsServer::class), FontLoader::class => DI\object(FontLoader::class)->constructor("{$__topdir}/res/fonts"), BitmapLoader::class => DI\object(BitmapLoader::class)->constructor("{$__topdir}/res/bitmaps/{$__w}x{$__h}:{$__topdir}/res/sprites")];
<?php return array('Piwik\\Auth' => DI\object('Piwik\\Plugins\\GoogleAuthenticator\\Auth'));
<?php return array('Piwik\\Plugins\\CoreHome\\Tracker\\VisitRequestProcessor' => DI\object()->constructorParameter('visitStandardLength', DI\get('ini.Tracker.visit_standard_length')));
<?php return [\Dafiti\Kong\KongClient::class => DI\object(\Dafiti\Kong\Client\GuzzleClient::class), \GuzzleHttp\ClientInterface::class => DI\object(\GuzzleHttp\Client::class)];
<?php return array('Piwik\\Auth' => DI\object('Piwik\\Plugins\\Login\\Auth'));
<?php declare (strict_types=1); use function DI\get; use Interop\Container\ContainerInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; use Stratify\ErrorHandlerModule\ErrorHandlerMiddleware; use Stratify\ErrorHandlerModule\ErrorResponder\ErrorResponder; use Stratify\ErrorHandlerModule\ErrorResponder\SimpleProductionResponder; use Stratify\ErrorHandlerModule\ErrorResponder\WhoopsResponder; use Whoops\Handler\PrettyPageHandler; use Whoops\Run; return [ErrorHandlerMiddleware::class => function (ContainerInterface $c) { $logger = $c->has(LoggerInterface::class) ? $c->get(LoggerInterface::class) : new NullLogger(); return new ErrorHandlerMiddleware($c->get(ErrorResponder::class), $logger); }, ErrorResponder::class => get(SimpleProductionResponder::class), WhoopsResponder::class => DI\object()->constructor(get('error_handler.whoops')), 'error_handler.whoops' => function () { $whoops = new Run(); $whoops->writeToOutput(false); $whoops->allowQuit(false); $handler = new PrettyPageHandler(); $handler->handleUnconditionally(true); $whoops->pushHandler($handler); return $whoops; }];