저자: David Grudl
상속: extends Nette\FreezableObject, implements Nette\DI\IContainer
예제 #1
0
 /**
  * @return \Nette\Security\User
  */
 private function getUser()
 {
     if (!$this->user) {
         $this->user = $this->container->getByType(User::class);
     }
     return $this->user;
 }
예제 #2
0
 /**
  * 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;
 }
예제 #3
0
 /**
  * @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;
     }
 }
예제 #4
0
 /**
  * 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.");
 }
예제 #5
0
 /**
  * @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);
 }
예제 #6
0
 public function createNew($arguments = array())
 {
     /** @var BaseFileEntity $entity */
     $entity = parent::createNew($arguments);
     $entity->setUser($this->container->getByType('Nette\\Security\\User'));
     return $entity;
 }
예제 #7
0
 public function __construct(Context $context, Container $container, EntityManager $entityManager)
 {
     $this->context = $context;
     $this->container = $container;
     $this->em = $entityManager;
     $this->cache = $this->container->getService('cacheStorage');
 }
예제 #8
0
 /**
  * @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]);
 }
 public function __construct($containerFactory = NULL, Container $container = NULL)
 {
     parent::__construct($containerFactory);
     /** @var IStorage $storage */
     $storage = $container->getService('cacheStorage');
     $this->cache = new Cache($storage);
 }
예제 #10
0
 /**
  * @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]);
 }
예제 #11
0
 /**
  * @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]);
 }
예제 #12
0
 /**
  * @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]);
 }
예제 #13
0
 /**
  * @param $name
  * @return ILoginProvider
  * @throws InvalidArgumentException
  */
 public function getLoginProviderByName($name)
 {
     if (!isset($this->loginProviders[$name])) {
         throw new InvalidArgumentException("Social login name '{$name}' has not been registered.");
     }
     return $this->content->getService($this->loginProviders[$name]);
 }
예제 #14
0
 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];
     }
 }
 /**
  * @return VisualPaginator
  */
 public function create()
 {
     $paginator = new VisualPaginator();
     $this->container->callInjects($paginator);
     $this->paginatorStack[] = $paginator;
     return $paginator;
 }
예제 #16
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $login = $input->getArgument('login');
     $password = $input->getArgument('password');
     $this->container->getByType('App\\Model\\UserManager')->add($login, $password);
     $output->writeln("User {$login} was added.");
 }
예제 #17
0
 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');
 }
예제 #18
0
 /** @inheritdoc */
 public function createEntity($entityClass, $arg = null)
 {
     if ($factory = $this->container->getByType($this->resolveEntityFactory($entityClass), false)) {
         return $factory->create($arg);
     }
     return new $entityClass($arg);
 }
예제 #19
0
 /**
  * @return CDNLoader
  */
 public function create()
 {
     $compiler = $this->container->getService('cdnloader.compiler');
     $httpRequest = $this->container->getService('httpRequest');
     $loader = new CDNLoader($compiler, $httpRequest);
     return $loader;
 }
예제 #20
0
 public static function create(DI\Container $container)
 {
     $robotLoader = $container->getService('robotLoader');
     //$cacheStorage = $container->getService('cacheStorage');
     $shortcutsManager = new \ShortcutsManager($robotLoader);
     return $shortcutsManager;
 }
예제 #21
0
파일: Login.php 프로젝트: CSHH/website
 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);
 }
예제 #22
0
파일: Helpers.php 프로젝트: markette/gopay
 /**
  * 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));
     }
 }
 /**
  * @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;
 }
예제 #24
0
 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']);
 }
예제 #25
0
 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');
 }
예제 #26
0
 /**
  * @return MapperMatrix
  */
 public function create()
 {
     $matrix = new MapperMatrix();
     foreach ($this->container->findByTag('echo511.leanmapper.mapper') as $serviceName => $tagAttributes) {
         $matrix->addMapper($this->container->getService($serviceName));
     }
     return $matrix;
 }
 /**
  * BasePresenterTester constructor.
  * @param string $presenterName  - etc. 'Front:GoodsChange:Goods'
  */
 public function __construct($presenterName)
 {
     $this->presenterName = $presenterName;
     $this->container = (require __DIR__ . '/../../../../app/bootstrap.php');
     $this->linkGenerator = $this->container->getByType('Nette\\Application\\LinkGenerator');
     $this->presenterFactory = $this->container->getByType('Nette\\Application\\IPresenterFactory');
     $this->authenticator = new Authenticator();
 }
예제 #28
0
 public function createComponent($name)
 {
     if (isset($this->registry[$name])) {
         $component = $this->container->createService($this->registry[$name]);
         $this->onCreateComponent($component);
         return $component;
     }
 }
예제 #29
0
 /**
  * @param string $eventName
  */
 private function initializeListener($eventName)
 {
     foreach ($this->listenerIds[$eventName] as $serviceName) {
         $subscriber = $this->container->getService($serviceName);
         /** @var Doctrine\Common\EventSubscriber $subscriber */
         $this->addEventSubscriber($subscriber);
     }
     unset($this->listenerIds[$eventName]);
 }
예제 #30
0
 public function create() : Registry
 {
     $tagToService = function (array $tags) {
         return array_map(function (string $serviceName) {
             return $this->container->getService($serviceName);
         }, array_keys($tags));
     };
     return new Registry($tagToService($this->container->findByTag(self::RULE_TAG)));
 }