Пример #1
0
 /**
  * Initial setup of DI\ContainerBuilder.
  *
  * @param bool $annotation annotation usage.
  *
  * @return DI\ContainerBuilder
  */
 protected static function initialSetupContainerBuilder($annotation)
 {
     $builder = new DI\ContainerBuilder();
     $builder->useAnnotations($annotation);
     $builder->addDefinitions(['request' => ServerRequestFactory::fromGlobals(), 'response' => DI\object(Response::class), 'http_flow_event' => DI\object(ZendHttpFlowEvent::class)->constructor('bootstrap', DI\get('request'), DI\get('response')), 'event_manager' => DI\object(ZendEvmProxy::class), 'dispatcher' => DI\factory(function ($container) {
         return new Dispatcher($container->get('router'), $container);
     })]);
     return $builder;
 }
Пример #2
0
 /**
  * Container compilation.
  *
  * @param mixed $config Configuration file/array.
  *
  * @link http://php-di.org/doc/php-definitions.html
  *
  * @return ContainerInterface
  */
 public static function buildContainer($config = [])
 {
     $builder = new DI\ContainerBuilder();
     $builder->useAnnotations(true);
     $builder->addDefinitions(['request' => \Zend\Diactoros\ServerRequestFactory::fromGlobals(), 'response' => DI\object('Zend\\Diactoros\\Response'), 'http_flow_event' => DI\object('Penny\\Event\\HttpFlowEvent')->constructor('bootstrap', DI\get('request'), DI\get('response')), 'event_manager' => DI\object('Zend\\EventManager\\EventManager'), 'dispatcher' => DI\factory(function ($container) {
         return new \Penny\Dispatcher($container->get('router'), $container);
     })]);
     $builder->addDefinitions($config);
     $container = $builder->build();
     $container->set('di', $container);
     return $container;
 }
Пример #3
0
use CASS\Domain\Bundles\Attachment\Service\AttachmentPreviewService;
use function DI\object;
use function DI\factory;
use function DI\get;
use DI\Container;
use CASS\Application\Bundles\Doctrine2\Factory\DoctrineRepositoryFactory;
use CASS\Domain\Bundles\Attachment\Entity\Attachment;
use CASS\Domain\Bundles\Attachment\Repository\AttachmentRepository;
use CASS\Domain\Bundles\Attachment\Service\AttachmentService;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use League\Flysystem\Memory\MemoryAdapter;
return ['php-di' => ['config.paths.attachment.dir' => factory(function (Container $container) {
    return sprintf('%s/entity/attachment', $container->get('config.storage.dir'));
}), 'config.paths.attachment.www' => factory(function (Container $container) {
    return sprintf('%s/entity/attachment', $container->get('config.storage.www'));
}), AttachmentRepository::class => factory(new DoctrineRepositoryFactory(Attachment::class)), AttachmentService::class => object()->constructorParameter('wwwDir', factory(function (Container $container) {
    return $container->get('config.paths.attachment.www');
}))->constructorParameter('generatePreviews', factory(function (Container $container) {
    return $container->get('config.env') !== 'test';
}))->constructorParameter('fileSystem', factory(function (Container $container) {
    $env = $container->get('config.env');
    if ($env === 'test') {
        return new Filesystem(new MemoryAdapter());
    } else {
        return new Filesystem(new Local($container->get('config.paths.attachment.dir')));
    }
})), AttachmentPreviewService::class => object()->constructorParameter('attachmentsRealPath', factory(function (Container $container) {
    return $container->get('config.paths.attachment.dir');
}))]];
Пример #4
0
<?php

namespace CASS\Domain\Bundles\ProfileCommunities;

use function DI\object;
use function DI\factory;
use function DI\get;
use CASS\Application\Bundles\Doctrine2\Factory\DoctrineRepositoryFactory;
use CASS\Domain\Bundles\ProfileCommunities\Entity\ProfileCommunityEQ;
use CASS\Domain\Bundles\ProfileCommunities\Repository\ProfileCommunitiesRepository;
return ['php-di' => [ProfileCommunitiesRepository::class => factory(new DoctrineRepositoryFactory(ProfileCommunityEQ::class))]];
Пример #5
0
    $hbs->addHelper('count', function (HbsTemplate $template, HbsContext $context, $args, $source) {
        return count($context->get($args));
    });
    $hbs->addHelper('join', function (HbsTemplate $template, HbsContext $context, $args, $source) {
        $matches = [];
        if (preg_match("#'([^']+)' (.+)#", $args, $matches)) {
            list(, $separator, $input) = $matches;
            $out = [];
            foreach ((array) $context->get($input) as $value) {
                $context->push($value);
                $out[] = $template->render($context);
                $context->pop();
            }
            return implode($separator, $out);
        }
        return '';
    });
    return $hbs;
}), 'Bigwhoop\\Trumpet\\Commands\\CommandExecutionContext' => DI\object(), 'Bigwhoop\\Trumpet\\Commands\\CommandHandler' => DI\factory(function (DIC $c) {
    $handler = new CommandHandler();
    $handler->registerCommand($c->get('Bigwhoop\\Trumpet\\Commands\\CodeCommand'));
    $handler->registerCommand($c->get('Bigwhoop\\Trumpet\\Commands\\ExecCommand'));
    $handler->registerCommand($c->get('Bigwhoop\\Trumpet\\Commands\\IncludeCommand'));
    $handler->registerCommand($c->get('Bigwhoop\\Trumpet\\Commands\\ImageCommand'));
    $handler->registerCommand($c->get('Bigwhoop\\Trumpet\\Commands\\WikiCommand'));
    return $handler;
}), 'PhpParser\\PrettyPrinterAbstract' => DI\object('\\PhpParser\\PrettyPrinter\\Standard'), 'PhpParser\\Lexer' => DI\object('PhpParser\\Lexer\\Emulative'), 'PhpParser\\ParserAbstract' => DI\object('PhpParser\\Parser')->constructor(DI\link('PhpParser\\Lexer')), 'PhpParser\\NodeTraverserInterface' => DI\object('PhpParser\\NodeTraverser')->method('addVisitor', DI\link('PhpParser\\NodeVisitor\\NameResolver'))];
$builder = new DI\ContainerBuilder();
$builder->addDefinitions(new DI\Definition\Source\ArrayDefinitionSource($definitions));
//$builder->useAnnotations(false);
return $builder->build();
Пример #6
0
<?php

namespace CASS\Application\Console;

use function DI\object;
use function DI\factory;
use function DI\get;
use CASS\Application\Bundles\Console\Factory\ConsoleApplicationFactory;
use Symfony\Component\Console\Application;
return ['php-di' => [Application::class => factory(new ConsoleApplicationFactory())]];
Пример #7
0
<?php

use GuzzleHttp\Psr7\ServerRequest;
use Interop\Container\ContainerInterface;
use League\Plates;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;
use TimTegeler\Routerunner\Routerunner;
use function DI\factory;
use function DI\object;
return [Routerunner::class => function (ContainerInterface $container) {
    return new Routerunner('Creios\\Creiwork\\Controller', $container);
}, Plates\Engine::class => object()->constructor(__DIR__ . '/../template'), LoggerInterface::class => function (\Monolog\Handler\StreamHandler $streamHandler) {
    $logger = new \Monolog\Logger('Creiwork');
    $logger->pushHandler($streamHandler);
    return $logger;
}, \Monolog\Handler\StreamHandler::class => object()->constructor(__DIR__ . '/../log/test.log', \Monolog\Logger::INFO), ServerRequestInterface::class => factory([ServerRequest::class, 'fromGlobals'])];
Пример #8
0
    $logger->pushHandler(new StreamHandler($file, Logger::WARNING));
    return $logger;
}), Poser::class => object()->constructor(link(SvgFlatRender::class)), Twig_Environment::class => factory(function (ContainerInterface $c) {
    $loader = new Twig_Loader_Filesystem(__DIR__ . '/../../src/Maintained/Application/View');
    $twig = new Twig_Environment($loader);
    $twig->addExtension($c->get(TwigExtension::class));
    $twig->addExtension($c->get(PiwikTwigExtension::class));
    return $twig;
}), PiwikTwigExtension::class => object()->constructor(link('piwik.host'), link('piwik.site_id'), link('piwik.enabled')), Cache::class => factory(function (ContainerInterface $c) {
    $cache = new FilesystemCache($c->get('directory.cache') . '/app');
    $cache->setNamespace('Maintained');
    return $cache;
}), 'storage.repositories' => factory(function (ContainerInterface $c) {
    $backend = new StorageWithTransformers(new FileStorage($c->get('directory.data') . '/repositories.json'));
    $backend->addTransformer(new JsonEncoder(true));
    $storage = new MapWithTransformers(new MapAdapter($backend));
    $storage->addTransformer(new ObjectArrayMapper(Repository::class));
    return $storage;
}), 'storage.statistics' => factory(function (ContainerInterface $c) {
    $storage = new MapWithTransformers(new MultipleFileStorage($c->get('directory.data') . '/statistics'));
    $storage->addTransformer(new PhpSerializeEncoder());
    return $storage;
}), Client::class => factory(function (ContainerInterface $c) {
    $cacheDirectory = $c->get('directory.cache') . '/github';
    $client = new Client(new CachedHttpClient(['cache_dir' => $cacheDirectory]));
    $authToken = $c->get('github.auth_token');
    if ($authToken) {
        $client->authenticate($authToken, null, Client::AUTH_HTTP_TOKEN);
    }
    return $client;
})];
Пример #9
0
<?php

use DI\Bridge\Slim\CallableResolver;
use DI\Bridge\Slim\ControllerInvoker;
use DI\Container;
use DI\Scope;
use Interop\Container\ContainerInterface;
use Invoker\Invoker;
use Invoker\ParameterResolver\AssociativeArrayResolver;
use Invoker\ParameterResolver\Container\TypeHintContainerResolver;
use Invoker\ParameterResolver\ResolverChain;
use Slim\Http\Headers;
use Slim\Http\Request;
use Slim\Http\Response;
use function DI\factory;
use function DI\get;
use function DI\object;
return ['settings.httpVersion' => '1.1', 'settings.responseChunkSize' => 4096, 'settings.outputBuffering' => 'append', 'settings.determineRouteBeforeAppMiddleware' => false, 'settings.displayErrorDetails' => false, 'settings' => ['httpVersion' => get('settings.httpVersion'), 'responseChunkSize' => get('settings.responseChunkSize'), 'outputBuffering' => get('settings.outputBuffering'), 'determineRouteBeforeAppMiddleware' => get('settings.determineRouteBeforeAppMiddleware'), 'displayErrorDetails' => get('settings.displayErrorDetails')], 'router' => object(Slim\Router::class), 'errorHandler' => object(Slim\Handlers\Error::class)->constructor(get('settings.displayErrorDetails')), 'notFoundHandler' => object(Slim\Handlers\NotFound::class), 'notAllowedHandler' => object(Slim\Handlers\NotAllowed::class), 'environment' => function () {
    return new Slim\Http\Environment($_SERVER);
}, 'request' => factory(function (ContainerInterface $c) {
    return Request::createFromEnvironment($c->get('environment'));
})->scope(Scope::SINGLETON), 'response' => factory(function (ContainerInterface $c) {
    $headers = new Headers(['Content-Type' => 'text/html; charset=UTF-8']);
    $response = new Response(200, $headers);
    return $response->withProtocolVersion($c->get('settings')['httpVersion']);
})->scope(Scope::SINGLETON), 'foundHandler' => object(ControllerInvoker::class)->constructor(get('foundHandler.invoker')), 'foundHandler.invoker' => function (ContainerInterface $c) {
    $resolvers = [new AssociativeArrayResolver(), new TypeHintContainerResolver($c)];
    return new Invoker(new ResolverChain($resolvers), $c);
}, 'callableResolver' => object(CallableResolver::class), ContainerInterface::class => get(Container::class)];
Пример #10
0
use function DI\factory;
use function DI\link;
use function DI\object;
return [ContainerInterface::class => link(Container::class), 'baseUrl' => 'http://isitmaintained.com', 'routes' => require __DIR__ . '/routes.php', Router::class => factory(function (ContainerInterface $c) {
    $router = (new RouterFactory())->newInstance();
    // Add the routes from the array config (Aura router doesn't seem to accept routes as array)
    $routes = $c->get('routes');
    foreach ($routes as $routeName => $route) {
        $router->add($routeName, $route['pattern'])->addValues(['controller' => $route['controller']]);
    }
    return $router;
}), Poser::class => factory(function () {
    return new Poser([new SvgRender()]);
}), Twig_Environment::class => factory(function (ContainerInterface $c) {
    $loader = new Twig_Loader_Filesystem(__DIR__ . '/../../src/Maintained/Application/View');
    $twig = new Twig_Environment($loader);
    $twig->addExtension($c->get(TwigExtension::class));
    return $twig;
}), 'cache.directory' => __DIR__ . '/../../app/cache', Cache::class => factory(function (ContainerInterface $c) {
    $cache = new FilesystemCache($c->get('cache.directory') . '/app');
    $cache->setNamespace('Maintained');
    return $cache;
}), 'github.auth_token' => null, Client::class => factory(function (ContainerInterface $c) {
    $cacheDirectory = $c->get('cache.directory') . '/github';
    $client = new Client(new CachedHttpClient(['cache_dir' => $cacheDirectory]));
    $authToken = $c->get('github.auth_token');
    if ($authToken) {
        $client->authenticate($authToken, null, Client::AUTH_HTTP_TOKEN);
    }
    return $client;
}), StatisticsProvider::class => object(CachedStatisticsProvider::class)->constructorParameter('wrapped', link(StatisticsComputer::class)), ClearCacheCommand::class => object()->lazy()->constructorParameter('cacheDirectory', link('cache.directory'))];
Пример #11
0
use PhpSchool\LearnYouPhp\Exercise\ArrayWeGo;
use PhpSchool\LearnYouPhp\Exercise\BabySteps;
use PhpSchool\LearnYouPhp\Exercise\ConcernedAboutSeparation;
use PhpSchool\LearnYouPhp\Exercise\DatabaseRead;
use PhpSchool\LearnYouPhp\Exercise\ExceptionalCoding;
use PhpSchool\LearnYouPhp\Exercise\FilteredLs;
use PhpSchool\LearnYouPhp\Exercise\HelloWorld;
use PhpSchool\LearnYouPhp\Exercise\HttpJsonApi;
use PhpSchool\LearnYouPhp\Exercise\MyFirstIo;
use PhpSchool\LearnYouPhp\Exercise\TimeServer;
use PhpSchool\LearnYouPhp\Exercise\DependencyHeaven;
use PhpSchool\LearnYouPhp\TcpSocketFactory;
use Symfony\Component\Filesystem\Filesystem;
use Faker\Factory as FakerFactory;
return [BabySteps::class => object(BabySteps::class), HelloWorld::class => object(HelloWorld::class), HttpJsonApi::class => object(HttpJsonApi::class), MyFirstIo::class => factory(function (ContainerInterface $c) {
    return new MyFirstIo($c->get(Filesystem::class), FakerFactory::create());
}), FilteredLs::class => factory(function (ContainerInterface $c) {
    return new FilteredLs($c->get(Filesystem::class));
}), ConcernedAboutSeparation::class => factory(function (ContainerInterface $c) {
    return new ConcernedAboutSeparation($c->get(Filesystem::class), FakerFactory::create(), $c->get(Parser::class));
}), ArrayWeGo::class => factory(function (ContainerInterface $c) {
    return new ArrayWeGo($c->get(Filesystem::class), FakerFactory::create());
}), ExceptionalCoding::class => factory(function (ContainerInterface $c) {
    return new ExceptionalCoding($c->get(Filesystem::class), FakerFactory::create());
}), DatabaseRead::class => factory(function (ContainerInterface $c) {
    return new DatabaseRead(FakerFactory::create());
}), TimeServer::class => factory(function (ContainerInterface $c) {
    return new TimeServer(new TcpSocketFactory());
}), DependencyHeaven::class => factory(function (ContainerInterface $c) {
    return new DependencyHeaven(FakerFactory::create('fr_FR'));
})];
Пример #12
0
<?php

namespace CASS\Domain\Bundles\Subscribe;

use function DI\factory;
use CASS\Application\Bundles\Doctrine2\Factory\DoctrineRepositoryFactory;
use CASS\Domain\Bundles\Subscribe\Entity\Subscribe;
use CASS\Domain\Bundles\Subscribe\Repository\SubscribeRepository;
return ['php-di' => [SubscribeRepository::class => factory(new DoctrineRepositoryFactory(Subscribe::class))]];
Пример #13
0
<?php

use livetyping\hermitage\app\factories\CommandBus;
use livetyping\hermitage\foundation\bus\commands;
use livetyping\hermitage\foundation\bus\handlers;
use SimpleBus\Message\Bus\MessageBus;
use function DI\factory;
use function DI\get;
use function DI\object;
return ['command-bus.middleware' => [], 'command-bus' => factory([CommandBus::class, 'create']), MessageBus::class => get('command-bus'), 'command-bus.command-handler-map' => [commands\StoreImageCommand::class => handlers\StoreImageCommandHandler::class, commands\MakeImageVersionCommand::class => handlers\MakeImageVersionCommandHandler::class, commands\DeleteImageCommand::class => handlers\DeleteImageCommandHandler::class], handlers\StoreImageCommandHandler::class => object(handlers\StoreImageCommandHandler::class), handlers\MakeImageVersionCommandHandler::class => object(handlers\MakeImageVersionCommandHandler::class), handlers\DeleteImageCommandHandler::class => object(handlers\DeleteImageCommandHandler::class)];
Пример #14
0
<?php

namespace CASS\Chat;

use CASS\Chat\Entity\Message;
use CASS\Chat\Repository\MessageRepository;
use function DI\factory;
use CASS\Application\Bundles\Doctrine2\Factory\DoctrineRepositoryFactory;
return ['php-di' => [MessageRepository::class => factory(new DoctrineRepositoryFactory(Message::class))]];
Пример #15
0
}), PrepareSolutionListener::class => object(), CodePatchListener::class => factory(function (ContainerInterface $c) {
    return new CodePatchListener($c->get(CodePatcher::class));
}), SelfCheckListener::class => factory(function (ContainerInterface $c) {
    return new SelfCheckListener($c->get(ResultAggregator::class));
}), FileExistsCheck::class => object(FileExistsCheck::class), PhpLintCheck::class => object(PhpLintCheck::class), CodeParseCheck::class => factory(function (ContainerInterface $c) {
    return new CodeParseCheck($c->get(Parser::class));
}), StdOutCheck::class => object(StdOutCheck::class), FunctionRequirementsCheck::class => factory(function (ContainerInterface $c) {
    return new FunctionRequirementsCheck($c->get(Parser::class));
}), CgiOutputCheck::class => object(CgiOutputCheck::class), DatabaseCheck::class => object(DatabaseCheck::class), ComposerCheck::class => object(ComposerCheck::class), Filesystem::class => object(Filesystem::class), Parser::class => factory(function (ContainerInterface $c) {
    $parserFactory = new ParserFactory();
    return $parserFactory->create(ParserFactory::PREFER_PHP7);
}), CodePatcher::class => factory(function (ContainerInterface $c) {
    $patch = (new Patch())->withInsertion(new Insertion(Insertion::TYPE_BEFORE, 'ini_set("display_errors", 1);'))->withInsertion(new Insertion(Insertion::TYPE_BEFORE, 'error_reporting(E_ALL);'))->withInsertion(new Insertion(Insertion::TYPE_BEFORE, 'date_default_timezone_set("Europe/London");'));
    return new CodePatcher($c->get(Parser::class), new Standard(), $patch);
}), TerminalInterface::class => factory([TerminalFactory::class, 'fromSystem']), 'menu' => factory([new MenuFactory(), '__invoke']), ExerciseRenderer::class => factory(function (ContainerInterface $c) {
    return new ExerciseRenderer($c->get('appName'), $c->get(ExerciseRepository::class), $c->get(UserState::class), $c->get(UserStateSerializer::class), $c->get(MarkdownRenderer::class), $c->get(Color::class), $c->get(OutputInterface::class));
}), MarkdownRenderer::class => factory(function (ContainerInterface $c) {
    $docParser = new DocParser(Environment::createCommonMarkEnvironment());
    $cliRenderer = (new MarkdownCliRendererFactory())->__invoke($c);
    return new MarkdownRenderer($docParser, $cliRenderer);
}), UserStateSerializer::class => factory(function () {
    return new UserStateSerializer(sprintf('%s/.phpschool.json', getenv('HOME')));
}), UserState::class => factory(function (ContainerInterface $c) {
    return $c->get(UserStateSerializer::class)->deSerialize();
}), SyntaxHighlighter::class => factory(function (ContainerInterface $c) {
    return (new \PhpSchool\PSX\Factory())->__invoke();
}), ResetProgress::class => factory(function (ContainerInterface $c) {
    return new ResetProgress($c->get(UserStateSerializer::class), $c->get(OutputInterface::class));
}), ResultRendererFactory::class => object(), ResultsRenderer::class => factory(function (ContainerInterface $c) {
    return new ResultsRenderer($c->get('appName'), $c->get(Color::class), $c->get(TerminalInterface::class), $c->get(ExerciseRepository::class), $c->get(SyntaxHighlighter::class), $c->get(ResultRendererFactory::class));
}), 'coreContributors' => ['@AydinHassan' => 'Aydin Hassan', '@mikeymike' => 'Michael Woodward', '@shakeyShane' => 'Shane Osbourne', '@chris3ailey' => 'Chris Bailey'], 'appContributors' => []];
Пример #16
0
}, CodePatcher::class => function (ContainerInterface $c) {
    $patch = (new Patch())->withInsertion(new Insertion(Insertion::TYPE_BEFORE, 'ini_set("display_errors", 1);'))->withInsertion(new Insertion(Insertion::TYPE_BEFORE, 'error_reporting(E_ALL);'))->withInsertion(new Insertion(Insertion::TYPE_BEFORE, 'date_default_timezone_set("Europe/London");'));
    return new CodePatcher($c->get(Parser::class), new Standard(), $patch);
}, FakerGenerator::class => function () {
    return FakerFactory::create();
}, RequestRenderer::class => object(), TerminalInterface::class => factory([TerminalFactory::class, 'fromSystem']), 'menu' => factory(MenuFactory::class), MenuFactory::class => object(), ExerciseRenderer::class => function (ContainerInterface $c) {
    return new ExerciseRenderer($c->get('appName'), $c->get(ExerciseRepository::class), $c->get(UserState::class), $c->get(UserStateSerializer::class), $c->get(MarkdownRenderer::class), $c->get(Color::class), $c->get(OutputInterface::class));
}, MarkdownRenderer::class => function (ContainerInterface $c) {
    $docParser = new DocParser(Environment::createCommonMarkEnvironment());
    $cliRenderer = (new MarkdownCliRendererFactory())->__invoke($c);
    return new MarkdownRenderer($docParser, $cliRenderer);
}, UserStateSerializer::class => function (ContainerInterface $c) {
    return new UserStateSerializer(getenv('HOME'), $c->get('workshopTitle'), $c->get(ExerciseRepository::class));
}, UserState::class => function (ContainerInterface $c) {
    return $c->get(UserStateSerializer::class)->deSerialize();
}, SyntaxHighlighter::class => factory(PsxFactory::class), PsxFactory::class => object(), ResetProgress::class => function (ContainerInterface $c) {
    return new ResetProgress($c->get(UserStateSerializer::class));
}, ResultRendererFactory::class => function (ContainerInterface $c) {
    $factory = new ResultRendererFactory();
    $factory->registerRenderer(FunctionRequirementsFailure::class, FunctionRequirementsFailureRenderer::class);
    $factory->registerRenderer(Failure::class, FailureRenderer::class);
    $factory->registerRenderer(CgiResult::class, CgiResultRenderer::class, function (CgiResult $result) use($c) {
        return new CgiResultRenderer($result, $c->get(RequestRenderer::class));
    });
    $factory->registerRenderer(CgiGenericFailure::class, FailureRenderer::class);
    $factory->registerRenderer(CgiRequestFailure::class, CgiRequestFailureRenderer::class);
    $factory->registerRenderer(CliResult::class, CliResultRenderer::class);
    $factory->registerRenderer(CliGenericFailure::class, FailureRenderer::class);
    $factory->registerRenderer(CliRequestFailure::class, CliRequestFailureRenderer::class);
    $factory->registerRenderer(ComparisonFailure::class, ComparisonFailureRenderer::class);
    return $factory;
Пример #17
0
    return sprintf('%s/entity/community/by-sid/avatar/', $container->get('config.storage.www'));
}), 'config.paths.community.avatar.dir' => factory(function (Container $container) {
    return sprintf('%s/entity/community/by-sid/avatar/', $container->get('config.storage.dir'));
}), 'config.paths.community.backdrop.dir' => factory(function (Container $container) {
    return sprintf('%s/entity/community/by-sid/backdrop', $container->get('config.storage.dir'));
}), 'config.paths.community.backdrop.www' => factory(function (Container $container) {
    return sprintf('%s/entity/community/by-sid/backdrop', $container->get('config.storage.www'));
}), CommunityRepository::class => factory(new DoctrineRepositoryFactory(Community::class)), CommunityService::class => object()->constructorParameter('imageFileSystem', factory(function (Container $container) {
    $env = $container->get('config.env');
    if ($env === 'test') {
        return new Filesystem(new MemoryAdapter($container->get('config.paths.community.avatar.dir')));
    } else {
        return new Filesystem(new Local($container->get('config.paths.community.avatar.dir')));
    }
}))->constructorParameter('wwwImageDir', factory(function (Container $container) {
    return $container->get('config.paths.community.avatar.www');
})), CommunityBackdropPresetFactory::class => object()->constructorParameter('json', factory(function (Container $container) {
    return $container->get('config.paths.community.backdrop.presets.json');
})), CommunityBackdropUploadStrategyFactory::class => object()->constructorParameter('wwwPath', factory(function (Container $container) {
    return $container->get('config.paths.community.backdrop.www');
}))->constructorParameter('storagePath', factory(function (Container $container) {
    return $container->get('config.paths.community.backdrop.dir');
}))->constructorParameter('fileSystem', factory(function (Container $container) {
    $env = $container->get('config.env');
    $dir = $container->get('config.paths.community.backdrop.dir');
    if ($env === 'test') {
        return new Filesystem(new MemoryAdapter($dir));
    } else {
        return new Filesystem(new Local($dir));
    }
}))]];
Пример #18
0
<?php

namespace CASS\Domain\Bundles\Post;

use function DI\object;
use function DI\factory;
use function DI\get;
use CASS\Application\Bundles\Doctrine2\Factory\DoctrineRepositoryFactory;
use CASS\Domain\Bundles\Post\Entity\Post;
use CASS\Domain\Bundles\Post\Entity\PostThemeEQ;
use CASS\Domain\Bundles\Post\Repository\PostRepository;
use CASS\Domain\Bundles\Post\Repository\PostThemeEQRepository;
return ['php-di' => [PostRepository::class => factory(new DoctrineRepositoryFactory(Post::class)), PostThemeEQRepository::class => factory(new DoctrineRepositoryFactory(PostThemeEQ::class))]];
Пример #19
0
<?php

namespace CASS\Application;

use function DI\object;
use function DI\factory;
use function DI\get;
use DI\Container;
use Evenement\EventEmitter;
use Intervention\Image\ImageManager;
return ['php-di' => ['composer.json' => factory(function (Container $container) {
    return json_decode(file_get_contents(sprintf('%s/composer.json', $container->get('paths')['backend'])), true);
}), 'paths' => ['backend' => sprintf('%s/../../../', __DIR__), 'frontend' => sprintf('%s/../../../../frontend', __DIR__), 'www' => sprintf('%s/../../../../www/app', __DIR__)], 'config.version.current' => factory(function (Container $container) {
    return $container->get('composer.json')['version'];
}), 'config.storage.dir' => '/data/storage', 'config.storage.www' => '/storage', 'config.routes_group' => ['auth', 'with-profile', 'common', 'final'], ImageManager::class => factory(function (Container $container) {
    return new ImageManager(['driver' => 'gd']);
}), EventEmitter::class => object()]];
Пример #20
0
<?php

namespace CASS\Application\Doctrine2;

use function DI\object;
use function DI\factory;
use function DI\get;
use CASS\Application\Bundles\Doctrine2\Factory\DoctrineEntityManagerFactory;
use Doctrine\ORM\EntityManager;
return ['php-di' => [EntityManager::class => factory(DoctrineEntityManagerFactory::class)]];
Пример #21
0
<?php

namespace CASS\Domain\Bundles\Theme;

use DI\Container;
use function DI\object;
use function DI\factory;
use function DI\get;
use CASS\Application\Bundles\Doctrine2\Factory\DoctrineRepositoryFactory;
use CASS\Domain\Bundles\Theme\Entity\Theme;
use CASS\Domain\Bundles\Theme\Frontline\ThemeScript;
use CASS\Domain\Bundles\Theme\Repository\ThemeRepository;
use CASS\Domain\Bundles\Theme\Service\ThemeService;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use League\Flysystem\Memory\MemoryAdapter;
return ['php-di' => ['config.paths.theme.preview.www' => factory(function (Container $container) {
    return sprintf('%s/entity/themes/preview', $container->get('config.storage.www'));
}), 'config.paths.theme.preview.dir' => factory(function (Container $container) {
    return sprintf('%s/entity/themes/preview/', $container->get('config.storage.dir'));
}), ThemeScript::class => object()->constructorParameter('wwwStorage', factory(function (Container $container) {
    return $container->get('config.paths.theme.preview.www');
})), ThemeRepository::class => factory(new DoctrineRepositoryFactory(Theme::class)), ThemeService::class => object()->constructorParameter('fileSystem', factory(function (Container $container) {
    $env = $container->get('config.env');
    $path = $container->get('config.paths.theme.preview.dir');
    if ($env === 'test') {
        return new Filesystem(new MemoryAdapter($path));
    } else {
        return new Filesystem(new Local($path));
    }
}))]];
Пример #22
0
<?php

namespace CASS\Domain\Bundles\Feedback;

use function DI\object;
use function DI\factory;
use function DI\get;
use CASS\Application\Bundles\Doctrine2\Factory\DoctrineRepositoryFactory;
use CASS\Domain\Bundles\Feedback\Entity\Feedback;
use CASS\Domain\Bundles\Feedback\Entity\FeedbackResponse;
use CASS\Domain\Bundles\Feedback\Repository\FeedbackRepository;
use CASS\Domain\Bundles\Feedback\Repository\FeedbackResponseRepository;
return ['php-di' => [FeedbackRepository::class => factory(new DoctrineRepositoryFactory(Feedback::class)), FeedbackResponseRepository::class => factory(new DoctrineRepositoryFactory(FeedbackResponse::class))]];
Пример #23
0
use PhpSchool\LearnYouPhp\Exercise\FilteredLs;
use PhpSchool\LearnYouPhp\Exercise\HelloWorld;
use PhpSchool\LearnYouPhp\Exercise\HttpJsonApi;
use PhpSchool\LearnYouPhp\Exercise\MyFirstIo;
use PhpSchool\LearnYouPhp\Exercise\TimeServer;
use PhpSchool\LearnYouPhp\Exercise\DependencyHeaven;
use PhpSchool\LearnYouPhp\TcpSocketFactory;
use PhpSchool\PhpWorkshop\Event\Event;
use Symfony\Component\Filesystem\Filesystem;
use Faker\Factory as FakerFactory;
return [BabySteps::class => object(BabySteps::class), HelloWorld::class => object(HelloWorld::class), HttpJsonApi::class => object(HttpJsonApi::class), MyFirstIo::class => factory(function (ContainerInterface $c) {
    return new MyFirstIo($c->get(Filesystem::class), FakerFactory::create());
}), FilteredLs::class => factory(function (ContainerInterface $c) {
    return new FilteredLs($c->get(Filesystem::class));
}), ConcernedAboutSeparation::class => factory(function (ContainerInterface $c) {
    return new ConcernedAboutSeparation($c->get(Filesystem::class), FakerFactory::create(), $c->get(Parser::class));
}), ArrayWeGo::class => factory(function (ContainerInterface $c) {
    return new ArrayWeGo($c->get(Filesystem::class), FakerFactory::create());
}), ExceptionalCoding::class => factory(function (ContainerInterface $c) {
    return new ExceptionalCoding($c->get(Filesystem::class), FakerFactory::create());
}), DatabaseRead::class => factory(function (ContainerInterface $c) {
    return new DatabaseRead(FakerFactory::create());
}), TimeServer::class => factory(function (ContainerInterface $c) {
    return new TimeServer(new TcpSocketFactory());
}), DependencyHeaven::class => factory(function (ContainerInterface $c) {
    return new DependencyHeaven(FakerFactory::create('fr_FR'));
}), 'eventListeners' => ['exercise.selected.hello-world' => [function () {
    if (!file_exists('hello-world.php')) {
        touch('hello-world.php');
    }
}]]];
Пример #24
0
<?php

namespace CASS\Domain\Bundles\Colors;

use function DI\object;
use function DI\factory;
use function DI\get;
use DI\Container;
use CASS\Application\Service\BundleService;
use CASS\Domain\Bundles\Avatar\Service\AvatarService;
use CASS\Domain\Bundles\Avatar\Service\Strategy\FileAvatarStrategy;
use CASS\Domain\Bundles\Avatar\Service\Strategy\MockAvatarStrategy;
use CASS\Domain\DomainBundle;
$configDefault = ['php-di' => [AvatarService::class => object()->constructorParameter('strategy', get(FileAvatarStrategy::class))]];
$configMock = ['php-di' => [AvatarService::class => object()->constructorParameter('strategy', get(MockAvatarStrategy::class))]];
return ['php-di' => [FileAvatarStrategy::class => object()->constructorParameter('fontPath', factory(function (Container $container) {
    $domainBundle = $container->get(BundleService::class)->getBundleByName(DomainBundle::class);
    /** @var DomainBundle $domainBundle */
    return sprintf('%s/fonts/Roboto/Roboto-Medium.ttf', $domainBundle->getResourcesDir());
}))], 'env' => ['development' => $configDefault, 'production' => $configDefault, 'stage' => $configDefault, 'test' => $configMock]];
Пример #25
0
}))]];
$configTest = ['php-di' => [ProfileService::class => object()->constructorParameter('wwwImagesDir', factory(function (Container $container) {
    return $container->get('config.paths.profile.avatar.www');
}))->constructorParameter('imagesFlySystem', factory(function (Container $container) {
    return new Filesystem(new MemoryAdapter($container->get('config.paths.profile.avatar.dir')));
}))]];
return ['php-di' => ['config.paths.profile.backdrop.presets.json' => factory(function (Container $container) {
    return json_decode(file_get_contents(sprintf('%s/presets/profile/presets.json', $container->get('config.storage.dir'))), true);
}), 'config.paths.profile.avatar.dir' => factory(function (Container $container) {
    return sprintf('%s/entity/profile/by-sid/avatar/', $container->get('config.storage.dir'));
}), 'config.paths.profile.avatar.www' => factory(function (Container $container) {
    return sprintf('%s/entity/profile/by-sid/avatar/', $container->get('config.storage.www'));
}), 'config.paths.profile.backdrop.dir' => factory(function (Container $container) {
    return sprintf('%s/entity/profile/by-sid/backdrop', $container->get('config.storage.dir'));
}), 'config.paths.profile.backdrop.www' => factory(function (Container $container) {
    return sprintf('%s/entity/profile/by-sid/backdrop', $container->get('config.storage.www'));
}), ProfileRepository::class => factory(new DoctrineRepositoryFactory(Profile::class)), ProfileExpertInEQRepository::class => factory(new DoctrineRepositoryFactory(ProfileExpertInEQ::class)), ProfileInterestingInEQRepository::class => factory(new DoctrineRepositoryFactory(ProfileInterestingInEQ::class)), ProfileBackdropPresetFactory::class => object()->constructorParameter('json', factory(function (Container $container) {
    return $container->get('config.paths.profile.backdrop.presets.json');
})), ProfileBackdropUploadStrategyFactory::class => object()->constructorParameter('wwwPath', factory(function (Container $container) {
    return $container->get('config.paths.profile.backdrop.www');
}))->constructorParameter('storagePath', factory(function (Container $container) {
    return $container->get('config.paths.profile.backdrop.dir');
}))->constructorParameter('fileSystem', factory(function (Container $container) {
    $env = $container->get('config.env');
    $dir = $container->get('config.paths.profile.backdrop.dir');
    if ($env === 'test') {
        return new Filesystem(new MemoryAdapter($dir));
    } else {
        return new Filesystem(new Local($dir));
    }
}))], 'env' => ['development' => $configDefault, 'production' => $configDefault, 'stage' => $configDefault, 'test' => $configTest]];
Пример #26
0
<?php

namespace CASS\Domain\Bundles\Account;

use function DI\object;
use function DI\factory;
use function DI\get;
use CASS\Domain\Bundles\Account\Entity\Account;
use CASS\Domain\Bundles\Account\Entity\AccountAppAccess;
use CASS\Domain\Bundles\Account\Entity\OAuthAccount;
use CASS\Domain\Bundles\Account\Repository\AccountAppAccessRepository;
use CASS\Domain\Bundles\Account\Repository\AccountRepository;
use CASS\Domain\Bundles\Account\Repository\OAuthAccountRepository;
use CASS\Application\Bundles\Doctrine2\Factory\DoctrineRepositoryFactory;
return ['php-di' => [AccountRepository::class => factory(new DoctrineRepositoryFactory(Account::class)), OAuthAccountRepository::class => factory(new DoctrineRepositoryFactory(OAuthAccount::class)), AccountAppAccessRepository::class => factory(new DoctrineRepositoryFactory(AccountAppAccess::class))]];
Пример #27
0
<?php

namespace ZEA2\Platform\Bundles\Swagger;

use function DI\object;
use function DI\factory;
use function DI\get;
use DI\Container;
use ZEA2\Platform\Bundles\Swagger\Service\APIDocsService;
return ['php-di' => [APIDocsService::class => object()->constructorParameter('excludedBundles', factory(function (Container $container) : array {
    if ($container->has('config.api-docs.excluded-bundles')) {
        return $container->get('config.api-docs.excluded-bundles');
    } else {
        return [];
    }
}))]];
Пример #28
0
<?php

namespace CASS\Application\Bundles\MongoDB;

use function DI\object;
use function DI\factory;
use function DI\get;
use DI\Container;
use MongoDB\Database;
use MongoDB\Client;
return ['php-di' => [Database::class => factory(function (Container $container) {
    $env = $container->get('config.env');
    $config = $container->get('config.mongodb');
    $mongoClient = new Client($config['server'] ?? 'mongodb://127.0.0.1:27017', $config['options'] ?? ['connect' => true], $config['driver_options'] ?? []);
    return $mongoClient->selectDatabase(sprintf('%s_%s', $config['db_prefix'] ?? 'cass', $env));
})]];