本文整理汇总了PHP中DI\object函数的典型用法代码示例。如果您正苦于以下问题:PHP object函数的具体用法?PHP object怎么用?PHP object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了object函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createContainer
private function createContainer(array $definitions = [])
{
$builder = new ContainerBuilder();
$builder->addDefinitions(__DIR__ . '/../../res/config/config.php');
$builder->addDefinitions([ContainerInterface::class => get(Container::class), Twig_LoaderInterface::class => object(Twig_Loader_Array::class)->constructor([]), ResourceRepository::class => object(NullRepository::class)]);
$builder->addDefinitions($definitions);
return $builder->build();
}
示例2: initialSetupContainerBuilder
/**
* 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;
}
示例3: buildContainer
/**
* 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;
}
示例4: __construct
/**
* Application initialization.
*
* @param mixed $router Routing system.
* @param ContainerInterface $container Dependency Injection container.
*/
public function __construct($router = null, ContainerInterface $container = null)
{
$this->container = $container ?: $this->buildContainer(Loader::load());
$container =& $this->container;
$this->response = new Response();
$this->request = ServerRequestFactory::fromGlobals();
if ($router == null && $container->has('router') == false) {
throw new Exception('Define router config');
}
if ($container->has('router') == false) {
$container->set('router', $router);
}
$container->set('event_manager', DI\object('Zend\\EventManager\\EventManager'));
$container->set('dispatcher', DI\object('GianArb\\Penny\\Dispatcher')->constructor($container->get('router')));
$container->set('di', $container);
}
示例5: compose
/**
* @param array $list
* @param string|array|DefinitionSource $definitions Can be an array of definitions, the
* name of a file containing definitions
* or a DefinitionSource object.
* @param bool $test_mode
* @throws InvalidListException
* @throws \Exception
*/
function compose(array $list, $definitions = [], $test_mode = false)
{
validate($list);
$to_cleanup = [];
/** @var \DI\Container $container */
$container = (new ContainerBuilder())->addDefinitions($definitions)->build();
try {
foreach ($list as $name => $block) {
$container->set(Values::class, object()->constructor($list));
echo $name . PHP_EOL;
$list[$name]['value'] = $container->call($list[$name]['action']);
if (isset($list[$name]['cleanup'])) {
$to_cleanup[] = $list[$name]['cleanup'];
} else {
$to_cleanup[] = function () {
};
}
}
/**
* Force cleanup on all actions
*/
if ($test_mode) {
throw new TestModeException();
}
} catch (\Exception $e) {
/**
* Call all previous action cleanups
*/
array_map(function ($cleanup) use($list, $container) {
$container->set(Values::class, object()->constructor($list));
$container->call($cleanup);
}, array_reverse($to_cleanup));
/**
* We want the exception if not a TestModeException,
* but want to exit if test mode
*/
if ($e instanceof TestModeException) {
echo "--- Test Mode Ended Successfully ---\n";
return;
}
throw $e;
}
}
示例6: factory
<?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));
}
}))]];
示例7: foreach
foreach ($routes as $routeName => $route) {
$router->add($routeName, $route['pattern'])->addValues(['controller' => $route['controller']]);
}
return $router;
}), LoggerInterface::class => factory(function (ContainerInterface $c) {
$logger = new Logger('main');
$file = $c->get('directory.logs') . '/app.log';
$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';
示例8: factory
<?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()]];
示例9: object
<?php
use DI\Container;
use Interop\Container\ContainerInterface;
use Puli\Discovery\Api\Discovery;
use Puli\UrlGenerator\Api\UrlGenerator;
use Stratify\Framework\Middleware\ContainerBasedInvoker;
use Zend\Diactoros\Response\EmitterInterface;
use Zend\Diactoros\Response\SapiEmitter;
use function DI\get;
use function DI\object;
return [\Stratify\Http\Application::class => object()->constructor(get('http'), get('middleware_invoker'), get(EmitterInterface::class)), \Silly\Application::class => object()->method('useContainer', get(Container::class), true, true), 'http' => function () {
throw new Exception('No HTTP stack was defined');
}, ContainerInterface::class => get(Container::class), EmitterInterface::class => get(SapiEmitter::class), 'middleware_invoker' => get(ContainerBasedInvoker::class), UrlGenerator::class => function (ContainerInterface $c) {
$puli = $c->get('puli.factory');
return $puli->createUrlGenerator($c->get(Discovery::class));
}];
示例10: function
$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();
示例11: object
}))]];
$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]];
示例12: object
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 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'));
示例13: object
<?php
use Slim\HttpCache\Cache;
use function DI\env;
use function DI\get;
use function DI\object;
return [Cache::class => object(Cache::class)->constructorParameter('type', env('HTTP_CACHE_TYPE', 'public'))->constructorParameter('maxAge', env('HTTP_CACHE_MAX_AGE', 315360000))];
示例14: factory
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');
}))]];
示例15: object
<?php
use livetyping\hermitage\app\signer\Signer;
use function DI\env;
use function DI\get;
use function DI\object;
return ['signer' => object(Signer::class)->constructor(env('SIGNER_ALGORITHM', 'sha256')), Signer::class => get('signer')];