作者:rutrade
项目:nette-blo
public function __construct(Context $context, Container $container, EntityManager $entityManager)
{
$this->context = $context;
$this->container = $container;
$this->em = $entityManager;
$this->cache = $this->container->getService('cacheStorage');
}
作者:VasekPurchar
项目:khanovaskola-v
public function __construct($containerFactory = NULL, Container $container = NULL)
{
parent::__construct($containerFactory);
/** @var IStorage $storage */
$storage = $container->getService('cacheStorage');
$this->cache = new Cache($storage);
}
作者:VasekPurchar
项目:khanovaskola-v
public function __construct(Container $container)
{
$p = $container->getParameters();
foreach (['app' => 'appDir', 'backup' => 'backupDir', 'bin' => 'binDir', 'libs' => 'libsDir', 'log' => 'logDir', 'migrations' => 'migrationsDir', 'temp' => 'tempDir', 'tests' => 'testsDir', 'www' => 'wwwDir'] as $prop => $key) {
$this->{$prop} = $p[$key];
}
}
作者:VasekPurchar
项目:khanovaskola-v
public function __construct(Container $context)
{
parent::__construct();
$secured = NULL;
if ($context->getParameters()['tls']) {
Route::$defaultFlags |= Route::SECURED;
$secured = Route::SECURED;
}
$this[] = new StaticRouter(['Homepage:default' => 'index.php'], StaticRouter::ONE_WAY | $secured);
$this[] = new StaticRouter(['Homepage:default' => '', 'Homepage:marathon' => 'maraton', 'Homepage:preklad' => 'preklad', 'Profile:default' => 'profil', 'Auth:in' => 'prihlaseni', 'Auth:out' => 'odhlaseni', 'Auth:registration' => 'registrace', 'Auth:resetPassword' => 'heslo', 'Text:about' => 'o-skole', 'Text:team' => 'o-skole/tym', 'Subjects:default' => 'predmety', 'File:opensearch' => 'opensearch.xml', 'File:robots' => 'robots.txt', 'Sitemap:default' => 'sitemap.xml', 'Text:tos' => 'podminky', 'Text:privacy' => 'soukromi'], $secured);
$this[] = new Route('vyhledavani/?hledat=<query>', 'Search:results');
$this[] = new Route('vyhledavani/cviceni', 'Search:blueprints');
$this[] = new Route('schema/[<action \\D+>/]<schemaId \\d+>[-<slug>]', 'Schema:default');
$this[] = new Route('blok/[<action \\D+>/][<schemaId \\d+>/]<blockId \\d+>[-<slug>]', 'Block:default');
$this[] = new Route('video/[<action \\D+>/][[<schemaId \\d+>/]<blockId \\d+>/]<videoId \\d+>[-<slug>]?zacatek=<startAtTime \\d+>', 'Video:default');
$this[] = new Route('cviceni/[<action \\D+>/][[<schemaId \\d+>/]<blockId \\d+>/]<blueprintId \\d+>[-<slug>]', 'Blueprint:default');
$this[] = new Route('tabule/[<action \\D+>/][[<schemaId \\d+>/]<blockId \\d+>/]<blackboardId \\d+>[-<slug>]?zacatek=<startAtTime \\d+>', 'Blackboard:default');
// old links
$this[] = new Route('video/<youtubeId>', 'Video:youtube');
$this[] = new Redirect('dobrovolnici', 'https://wiki.khanovaskola.cz/doku.php?id=dobrovolnici');
$this[] = new Redirect('dobrovolnici/preklad', 'https://wiki.khanovaskola.cz/doku.php?id=jaknato');
$this[] = new Redirect('dobrovolnici/pravidla-prekladu', 'https://wiki.khanovaskola.cz/doku.php?id=pravidla');
$this[] = new Redirect('o-skole/projekty', 'https://wiki.khanovaskola.cz/doku.php?id=start');
$this[] = new Redirect('kontakt', 'https://wiki.khanovaskola.cz/doku.php?id=tym');
$this[] = $context->createInstance(Routers\OldVideo::class);
$this[] = $context->createInstance(Routers\OldCategory::class);
$this[] = $context->createInstance(Routers\OldBlog::class);
$this[] = new Route('<presenter>/<action \\D+>[/<id>]', 'Homepage:default');
}
作者:baz
项目:Tatam
public static function create(DI\Container $container)
{
$robotLoader = $container->getService('robotLoader');
//$cacheStorage = $container->getService('cacheStorage');
$shortcutsManager = new \ShortcutsManager($robotLoader);
return $shortcutsManager;
}
作者:CSH
项目:websit
public function signIn(Nette\DI\Container $container)
{
$container->removeService('nette.userStorage');
$userStorage = m::mock('Nette\\Security\\IUserStorage');
$userStorage->shouldReceive('isAuthenticated')->once()->andReturn(true);
$userStorage->shouldReceive('getIdentity')->once()->andReturn(new Nette\Security\Identity(1));
$container->addService('nette.userStorage', $userStorage);
}
作者:markett
项目:gopa
/**
* Registers 'addPaymentButtons' & 'addPaymentButton' methods to form using DI container
*
* @param Container $container
*/
public static function registerAddPaymentButtonsUsingDependencyContainer(Container $container)
{
$binder = $container->getByType(Binder::class);
$services = $container->findByType(AbstractPaymentService::class);
foreach ($services as $service) {
self::registerAddPaymentButtons($binder, $container->getService($service));
}
}
作者:darkknighti
项目:nette-injects-extensio
/**
* @param string $type
* @param Container $container
* @return object[]
*/
public static function findServicesOfType($type, Container $container)
{
$services = array();
foreach ($container->findByType($type) as $name) {
$services[] = $container->getService($name);
}
return $services;
}
作者:instant
项目:php-test-suit
public static function createFromContainer(Container $context)
{
/** @var EntityManager $em */
$em = $context->getByType(EntityManager::class);
/** @var Configuration $conf */
$conf = $context->getByType(Configuration::class);
return new self($em, $conf, $context->getParameters()['tempDir']);
}
作者:blitzi
项目:vycetk
public function __construct(\Nette\DI\Container $container)
{
$this->container = $container;
$this->connection = $container->getService('leanMapper.connection');
$this->entityFactory = $container->getService('entityFactory');
$this->mapper = $container->getService('standardMapper');
$this->transaction = $container->getService('transaction');
}
作者:venn
项目:file
/**
* @return \Nette\Security\User
*/
private function getUser()
{
if (!$this->user) {
$this->user = $this->container->getByType(User::class);
}
return $this->user;
}
作者:clevi
项目:migratio
/**
* Vytvoří DB a naplní testovacími daty.
*/
public function runMigrations()
{
if (!$this->context->parameters['migrations']['enabled']) {
return;
}
$connection = $this->context->getService('dibiConnection');
$dbNamePrefix = $this->context->parameters['testDbPrefix'] . date('Ymd_His') . '_' . rand(1, 1000) . '_';
$i = 1;
do {
$dbName = $dbNamePrefix . $i;
$i++;
} while ($connection->query('SHOW DATABASES WHERE %n', 'Database', ' = %s', $dbName)->count());
$connection->query('CREATE DATABASE %n COLLATE=utf8_czech_ci', $dbName);
$connection->query('USE %n', $dbName);
$migrationsPath = $this->context->parameters['wwwDir'] . '/' . $this->context->parameters['migrations']['path'];
$finder = new Migration\Finders\MultipleDirectories();
$finder->addDirectory($migrationsPath . '/struct');
$finder->addDirectory($migrationsPath . '/data');
$migrations = $this->createRunner($connection);
ob_start();
$migrations->run($finder, FALSE, TRUE);
$result = ob_get_clean();
if (substr(strip_tags($result), -2) !== 'OK') {
throw new \Exception('Migrace neproběhly v pořádku: ' . $result);
}
$this->context->parameters['testDbName'] = $dbName;
}
作者:svobodn
项目:we
/**
* @return Nette\Application\IResponse
*/
public function run(Application\Request $request)
{
$this->request = $request;
$httpRequest = $this->context->getByType('Nette\\Http\\IRequest');
if (!$httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) {
$refUrl = clone $httpRequest->getUrl();
$url = $this->context->getService('router')->constructUrl($request, $refUrl->setPath($refUrl->getScriptPath()));
if ($url !== NULL && !$httpRequest->getUrl()->isEqual($url)) {
return new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY);
}
}
$params = $request->getParameters();
if (!isset($params['callback'])) {
throw new Application\BadRequestException("Parameter callback is missing.");
}
$params['presenter'] = $this;
$callback = new Nette\Callback($params['callback']);
$response = $callback->invokeArgs(Application\UI\PresenterComponentReflection::combineArgs($callback->toReflection(), $params));
if (is_string($response)) {
$response = array($response, array());
}
if (is_array($response)) {
if ($response[0] instanceof \SplFileInfo) {
$response = $this->createTemplate('Nette\\Templating\\FileTemplate')->setParameters($response[1])->setFile($response[0]);
} else {
$response = $this->createTemplate('Nette\\Templating\\Template')->setParameters($response[1])->setSource($response[0]);
}
}
if ($response instanceof Nette\Templating\ITemplate) {
return new Responses\TextResponse($response);
} else {
return $response;
}
}
作者:b4na
项目:doctrin
/**
* getter for specified model
*
* @param string $name name of model
* @return BaseModel
* @throws \InvalidArgumentException
*/
public function getModel($name)
{
if ($this->container->hasService($name)) {
return $this->container->getService($name);
}
throw new \InvalidArgumentException("Model '{$name}' not found.");
}
作者:Northy
项目:Codeceptio
/**
* @param Request $request
* @return Response
*/
public function doRequest($request)
{
$_COOKIE = $request->getCookies();
$_SERVER = $request->getServer();
$_FILES = $request->getFiles();
$_SERVER['REQUEST_METHOD'] = $method = strtoupper($request->getMethod());
$_SERVER['REQUEST_URI'] = $uri = str_replace('http://localhost', '', $request->getUri());
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
if ($method === 'HEAD' || $method === 'GET') {
$_GET = $request->getParameters();
$_POST = [];
} else {
$_POST = $request->getParameters();
$_GET = [];
}
$httpRequest = $this->container->getByType(IRequest::class);
$httpResponse = $this->container->getByType(IResponse::class);
if (!$httpRequest instanceof HttpRequest || !$httpResponse instanceof HttpResponse) {
throw new Exception('Arachne\\Codeception\\DI\\CodeceptionExtension is not used or conflicts with another extension.');
}
$httpRequest->reset();
$httpResponse->reset();
try {
ob_start();
$this->container->getByType(Application::class)->run();
$content = ob_get_clean();
} catch (Exception $e) {
ob_end_clean();
throw $e;
}
$code = $httpResponse->getCode();
$headers = $httpResponse->getHeaders();
return new Response($content, $code, $headers);
}
作者:svobodn
项目:we
public function createNew($arguments = array())
{
/** @var BaseFileEntity $entity */
$entity = parent::createNew($arguments);
$entity->setUser($this->container->getByType('Nette\\Security\\User'));
return $entity;
}
作者:broslan
项目:blockchai
/**
* @param string $name
* @return Wallet
*/
public function getWallet($name)
{
if (!isset($this->serviceMap[$name])) {
throw new \Nette\InvalidArgumentException("Unknown wallet {$name}.");
}
return $this->serviceLocator->getService($this->serviceMap[$name]);
}
作者:venn
项目:venn
/**
* @param string $name
* @return \Venne\Security\ILoginProvider
*/
public function getLoginProviderByName($name)
{
if (!isset($this->loginProviders[$name])) {
throw new InvalidArgumentException(sprintf('Social login name \'%s\' has not been registered.', $name));
}
return $this->context->getService($this->loginProviders[$name]);
}
作者:petrneme
项目:RabbitM
/**
* @param string $name
* @return RpcServer
*/
public function getRpcServer($name)
{
if (!isset($this->rpcServers[$name])) {
throw new InvalidArgumentException("Unknown RPC server {$name}");
}
return $this->serviceLocator->getService($this->rpcServers[$name]);
}
作者:broslan
项目:blocktrai
/**
* @param string $name
* @return \Blocktrail\SDK\Wallet
* @throws \Nette\InvalidArgumentException
*/
public function getWallet($name = self::DEFAULT_NAME)
{
if (!isset($this->walletsServiceMap[$name])) {
throw new \Nette\InvalidArgumentException("Unknown wallet '{$name}'.");
}
return $this->serviceLocator->getService($this->walletsServiceMap[$name]);
}