public function dataFormatTemplateFiles() { $context = \Nette\Environment::getContext(); return array( array('Nella\Foo\Bar::render', array( $context->params['appDir'] . "/Foo/Bar.latte", $context->params['appDir'] . "/templates/Foo/Bar.latte", __DIR__ . "/Foo/Bar.latte", __DIR__ . "/templates/Foo/Bar.latte", NELLA_FRAMEWORK_DIR . "/Foo/Bar.latte", NELLA_FRAMEWORK_DIR . "/templates/Foo/Bar.latte", )), array('Nella\Foo\Bar::renderBaz', array( $context->params['appDir'] . "/Foo/Bar.baz.latte", $context->params['appDir'] . "/templates/Foo/Bar.baz.latte", __DIR__ . "/Foo/Bar.baz.latte", __DIR__ . "/templates/Foo/Bar.baz.latte", NELLA_FRAMEWORK_DIR . "/Foo/Bar.baz.latte", NELLA_FRAMEWORK_DIR . "/templates/Foo/Bar.baz.latte", )), array('Nella\Foo::renderBarBaz', array( $context->params['appDir'] . "/Foo.barBaz.latte", $context->params['appDir'] . "/templates/Foo.barBaz.latte", __DIR__ . "/Foo.barBaz.latte", __DIR__ . "/templates/Foo.barBaz.latte", NELLA_FRAMEWORK_DIR . "/Foo.barBaz.latte", NELLA_FRAMEWORK_DIR . "/templates/Foo.barBaz.latte", )), ); }
/** * Renders blue screen. * @param \Exception * @return void */ public static function renderBlueScreen(\Exception $exception) { if (class_exists('Nette\\Environment', FALSE)) { $application = Environment::getContext()->hasService('Nette\\Application\\Application', TRUE) ? Environment::getContext()->getService('Nette\\Application\\Application') : NULL; } require __DIR__ . '/templates/bluescreen.phtml'; }
/** * @internal * @return string */ protected function getStorageDir() { if ($this instanceof FileEntity) { return \Nette\Environment::getContext()->expand(FileService::STORAGE_DIR); } else { return \Nette\Environment::getContext()->expand(ImageService::STORAGE_DIR); } }
/** * @return \Nette\DI\Container */ protected function getContext() { static $context; if (!$context) { $context = \Nette\Environment::getContext(); } return $context; }
protected function createTemplate($class = NULL) { $template = parent::createTemplate($class); $template->registerHelperLoader('Helpers::loader'); $this->translator = \Nette\Environment::getContext()->translator; $template->setTranslator($this->translator); $template->registerHelper('convert', callback(\Nette\Environment::getContext()->currencyHelper, 'convert')); $template->currentLang = $this->translator->getLangTo(); return $template; }
/** * Get context * @return \Nette\Context */ public function getContext() { return Environment::getContext(); }
/** * @return Nette\Application\Application */ public static function createApplication() { if (Environment::getVariable('baseUri', NULL) === NULL) { Environment::setVariable('baseUri', Environment::getHttpRequest()->getUri()->getBasePath()); } $context = clone Environment::getContext(); $context->addService('Nette\\Application\\IRouter', 'Nette\\Application\\MultiRouter'); if (!$context->hasService('Nette\\Application\\IPresenterLoader')) { $context->addService('Nette\\Application\\IPresenterLoader', function () { return new Nette\Application\PresenterLoader(Environment::getVariable('appDir')); }); } $application = new Nette\Application\Application(); $application->setContext($context); $application->catchExceptions = Environment::isProduction(); return $application; }
<?php define('LIBS_DIR', __DIR__ . '/../libs'); require_once LIBS_DIR . '/Nette/loader.php'; require_once LIBS_DIR . '/dump.php'; use Nette\Diagnostics\Debugger as Debug; use Nette\Environment; use Nette\Loaders\RobotLoader; Debug::enable(false); Debug::$strictMode = true; Environment::setVariable('tempDir', __DIR__ . '/tmp'); $r = new RobotLoader(); $r->setCacheStorage(Environment::getContext()->cacheStorage); $r->addDirectory(LIBS_DIR); $r->addDirectory(__DIR__ . '/cases'); $r->register(); require_once __DIR__ . '/TestCase.php';
public function dataFormatTemplatesFiles() { $context = \Nette\Environment::getContext(); return array( array('Foo', 'bar', array( $context->params['appDir'] . "/templates/Foo/bar.latte", $context->params['appDir'] . "/templates/Foo.bar.latte", $context->params['appDir'] . "/templates/Foo/@global.latte", $context->params['appDir'] . "/templates/@global.latte", __DIR__ . "/templates/Foo/bar.latte", __DIR__ . "/templates/Foo.bar.latte", __DIR__ . "/templates/Foo/@global.latte", __DIR__ . "/templates/@global.latte", NELLA_FRAMEWORK_DIR . "/templates/Foo/bar.latte", NELLA_FRAMEWORK_DIR . "/templates/Foo.bar.latte", NELLA_FRAMEWORK_DIR . "/templates/Foo/@global.latte", NELLA_FRAMEWORK_DIR . "/templates/@global.latte", )), array('Foo:Bar', 'baz', array( $context->params['appDir'] . "/Foo/templates/Bar/baz.latte", $context->params['appDir'] . "/Foo/templates/Bar.baz.latte", $context->params['appDir'] . "/Foo/templates/Bar/@global.latte", $context->params['appDir'] . "/Foo/templates/@global.latte", $context->params['appDir'] . "/templates/Foo/Bar/baz.latte", $context->params['appDir'] . "/templates/Foo/Bar.baz.latte", $context->params['appDir'] . "/templates/Foo/Bar/@global.latte", $context->params['appDir'] . "/templates/Foo/@global.latte", $context->params['appDir'] . "/templates/@global.latte", __DIR__ . "/Foo/templates/Bar/baz.latte", __DIR__ . "/Foo/templates/Bar.baz.latte", __DIR__ . "/Foo/templates/Bar/@global.latte", __DIR__ . "/Foo/templates/@global.latte", __DIR__ . "/templates/Foo/Bar/baz.latte", __DIR__ . "/templates/Foo/Bar.baz.latte", __DIR__ . "/templates/Foo/Bar/@global.latte", __DIR__ . "/templates/Foo/@global.latte", __DIR__ . "/templates/@global.latte", NELLA_FRAMEWORK_DIR . "/Foo/templates/Bar/baz.latte", NELLA_FRAMEWORK_DIR . "/Foo/templates/Bar.baz.latte", NELLA_FRAMEWORK_DIR . "/Foo/templates/Bar/@global.latte", NELLA_FRAMEWORK_DIR . "/Foo/templates/@global.latte", NELLA_FRAMEWORK_DIR . "/templates/Foo/Bar/baz.latte", NELLA_FRAMEWORK_DIR . "/templates/Foo/Bar.baz.latte", NELLA_FRAMEWORK_DIR . "/templates/Foo/Bar/@global.latte", NELLA_FRAMEWORK_DIR . "/templates/Foo/@global.latte", NELLA_FRAMEWORK_DIR . "/templates/@global.latte", )), ); }
use Nette\Web\Html; // Load libraries require LIBS_DIR . '/Nette/loader.php'; require APP_DIR . '/routers/StaticRouter.php'; require APP_DIR . '/classes/TemplateLocator.php'; require APP_DIR . '/classes/PresenterLoader.php'; // Enable and setup Nette\Debug Debug::enable(); Debug::$strictMode = !Debug::$productionMode; // Configure environment date_default_timezone_set('Europe/Prague'); Html::$xhtml = FALSE; Env::getContext()->addService('TemplateLocator', 'StaticWeb\TemplateLocator'); Env::getContext()->addService('Nette\\Application\\IPresenterLoader', function () { return new PresenterLoader(Env::getVariable('appDir')); }); // Configure application $application = Env::getApplication(); $application->errorPresenter = 'Error'; $application->catchExceptions = Debug::$productionMode; $application->setRouter(new StaticRouter('StaticPage', 'homepage', 'default')); // Run the application! $application->run();
protected function setup() { $this->context = clone \Nette\Environment::getContext(); }
/** * @return Nette\Application\Application */ public static function createApplication(array $options = NULL) { if (Environment::getVariable('baseUri', NULL) === NULL) { Environment::setVariable('baseUri', Environment::getHttpRequest()->getUri()->getBaseUri()); } $context = clone Environment::getContext(); $context->addService('Nette\\Application\\IRouter', 'Nette\Application\MultiRouter'); if (!$context->hasService('Nette\\Application\\IPresenterFactory')) { $context->addService('Nette\\Application\\IPresenterFactory', function() use ($context) { return new Nette\Application\PresenterFactory(Environment::getVariable('appDir'), $context); }); } $class = isset($options['class']) ? $options['class'] : 'Nette\Application\Application'; $application = new $class; $application->setContext($context); $application->catchExceptions = Environment::isProduction(); return $application; }
/** * Renders JavaScript body of function. */ public function renderInitJavaScript(MultipleFileUpload $upload) { $tpl = $this->createTemplate(dirname(__FILE__) . "/initJS.js"); $tpl->token = $upload->getToken(); $tpl->sizeLimit = $upload->maxFileSize; $tpl->maxFiles = $upload->maxFiles; // TODO: make creation of link nicer! $baseUrl = Environment::getContext()->httpRequest->url->baseUrl; $tpl->uploadLink = $baseUrl . "?token=" . $tpl->token . "&uploader=plupload"; $tpl->id = $this->getHtmlIdFlashCompatible($upload); return $tpl->__toString(TRUE); }
/** * @return Nette\Caching\ICacheStorage */ public static function createCacheStorage() { $context = new Context(); $context->addService('Nette\\Caching\\ICacheJournal', Environment::getContext()); $dir = Environment::getVariable('tempDir') . '/cache'; umask(00); @mkdir($dir, 0777); // @ - directory may exists return new Nette\Caching\FileStorage($dir, $context); }
/** * Stores this order in DB */ public function send() { if ($this->orderSent()) { throw new Nette\InvalidStateException('Order has been already stored in DB'); } $this->_orderSent = true; $this->load(); $db = $this->context->connection; $persistentRepo = Nette\Environment::getContext()->repository; $user = $this->context->user; $this->onPreSave[] = function ($e) use($db, $persistentRepo, $user) { $table = $e->getMetadata()->getTableName(); $db->query("LOCK TABLES [" . $table . "] WRITE"); $db->begin(); $date = new \DateTime(); $monthPrefix = $date->format('Ym'); $e->data->timestamp = $date->format('Y-m-d H:i:s'); // Pred ulozenim odstranim schovane nulove polozky (nulove slevy atd.) // Zaroven to vyvola load => musim nacist polozky, // protoze jakmile se zmeni ID, nemam je podle ceho svazat foreach ($e->items as $curr) { if (!$curr->isVisible() && $curr->getPrice() == 0) { $e->items->remove($curr); } } $id = $db->select('MAX(id)')->from($table)->where('SUBSTRING(id, 1, 6) = %s', $monthPrefix)->fetchSingle(); $e->data->id = $monthPrefix . ($id == null ? 1 : substr($id, 6) + 1); $e->user = $user->isLoggedIn() ? $user->getIdentity() : null; }; $this->onPostSave[] = function ($e) use($db) { $db->query("UNLOCK TABLES"); }; $persistentRepo->save($this); // Odstranim polozky ze session objednavky $orderedProducts = $this->context->sessionRepository->findAll('vStore\\Shop\\OrderItem', true); foreach ($orderedProducts as $curr) { $curr->delete(); } // Vyresetuju objednavku (Ulozi to destruktor) list($sessionOrder) = $this->context->sessionRepository->findAll('vStore\\Shop\\Order', true)->fetchAll(); $sessionOrder->isPaid = false; $sessionOrder->save(); // Zavolam vsechny listenery (pouziju pro jistotu j*z ulozenou objednavku) $this->context->shop->onOrderCreated($this->context->shop->getOrder($this->id)); }