本文整理汇总了PHP中Nette\Environment类的典型用法代码示例。如果您正苦于以下问题:PHP Environment类的具体用法?PHP Environment怎么用?PHP Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Environment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dataFormatTemplateFiles
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",
)),
);
}
示例2: getCache
/**
* @return Cache
*/
protected static function getCache()
{
if (self::$cache === NULL) {
self::$cache = \Nette\Environment::getService('webloader.cache');
}
return self::$cache;
}
示例3: match
/**
* @param Nette\Web\IHttpRequest $httpRequest
* @return Nette\Application\PresenterRequest|NULL
*/
public function match(\Nette\Http\IRequest $httpRequest)
{
/** @var $appRequest \Nette\Application\Request */
$appRequest = parent::match($httpRequest);
// doplněno: pokud match vrátí NULL, musíme také vrátit NULL
if (!$appRequest) {
return $appRequest;
}
// musím si přeložit host, kvůli localhostu to není dané
if (strpos($httpRequest->url->host, '.localhost') !== false && !\Nette\Environment::isProduction()) {
// jsme na localhostu
$host = substr($httpRequest->url->host, 0, strripos($httpRequest->url->host, '.localhost'));
// musíme si doménu osamostatnit od .localhost
$host = str_replace('_', '.', $host);
// na lokálu mám místo teček podtržení
} else {
// jsme na produkci
$host = $httpRequest->url->host;
}
// zkusím zda je soubor již v cache
if (is_file(WEB_DIR . '/' . $host . '/cache' . $httpRequest->url->path)) {
return new Nette\Application\Request('Frontend', 'POST', array('action' => 'cache', 'file' => WEB_DIR . '/' . $host . '/cache' . $httpRequest->url->path));
}
/*
if ($params = $this->doFilterParams($this->getRequestParams($appRequest), $appRequest, self::WAY_IN)) {
return $this->setRequestParams($appRequest, $params);
}
*/
// $pages = $this->context->createPages();
$data = array('action' => 'default');
return new Nette\Application\Request('Frontend', 'POST', $data);
}
示例4: renderShow
public function renderShow($id)
{
$service = new TripService($this->entityManager);
$trip = $service->find($id);
$this->template->trip = $trip;
try {
$eventService = new EventService();
$config = Environment::getConfig('api');
$events = $eventService->getEvents($trip->arrival, new DateTime(), new EventfulMapper($config->eventfulUser, $config->eventfulPassword, $config->eventfulKey));
$this->template->events = $events;
} catch (InvalidStateException $e) {
$this->template->events = array();
}
$articleService = new ArticleService($this->entityManager);
$this->template->article = $articleService->buildArticle($trip->arrival, new ArticleWikipediaMapper());
try {
$airportMapper = new AirportTravelMathMapper();
$airportService = new AirportService();
$locationService = new LocationService();
$coordinates = $locationService->getCoordinates($trip->getDeparture());
$from = $airportService->searchNearestAirport($airportMapper, $coordinates['latitude'], $coordinates['longitude']);
$coordinates = $locationService->getCoordinates($trip->getArrival());
$to = $airportService->searchNearestAirport($airportMapper, $coordinates['latitude'], $coordinates['longitude']);
$flightMapper = new FlightKayakMapper();
$flightService = new FlightService($this->entityManager);
$depart_date = new DateTime('now');
$return_date = new DateTime('+1 week');
$this->template->flights = $flightService->buildFlights($flightMapper, $from, $to, $depart_date, $return_date, '1', 'e', 'n');
} catch (FlightException $e) {
$this->template->flightsError = "Connection with search system <a href='http://kayak.com'>Kayak</a> failed.";
} catch (AirportException $e) {
$this->template->flightsError = $e->getMessage();
}
}
示例5: handleUploads
/**
* Handles uploaded files
* forwards it to model
*/
public function handleUploads()
{
// Iterujeme nad přijatými soubory
foreach (\Nette\Environment::getHttpRequest()->getFiles() as $name => $controlValue) {
// MFU vždy posílá soubory v této struktuře:
//
// array(
// "token" => "blablabla",
// "files" => array(
// 0 => HttpUploadedFile(...),
// ...
// )
// )
$isFormMFU = (is_array($controlValue) and isset($controlValue["files"]) and isset($_POST[$name]["token"]));
if ($isFormMFU) {
$token = $_POST[$name]["token"];
foreach ($controlValue["files"] as $file) {
self::processFile($token, $file);
}
}
// soubory, které se netýkají MFU nezpracujeme -> zpracuje si je standardním způsobem formulář
}
return true;
// Skip all next
}
示例6: setLocale
public function setLocale($lang)
{
switch ($lang) {
case 'en':
setlocale(LC_ALL, 'en_EN.UTF8', 'en_EN.UTF-8', 'en_EN ');
break;
case 'cs':
default:
setlocale(LC_ALL, 'cs_CZ.UTF8', 'cs_CZ.UTF-8', 'cs_CZ');
}
$this->lang = $lang;
$cache = Environment::getCache();
$cacheName = 'getText-' . $this->lang;
if (isset($cache[$cacheName])) {
$this->dictionary = unserialize($cache[$cacheName]);
} else {
$dict = new Model\Dictionary('utils/translate');
try {
$this->dictionary = $dict->getPairs($this->lang);
$cache->save($cacheName, serialize((array) $this->dictionary), array('expire' => time() + 60 * 30, 'refresh' => TRUE, 'tags' => array('dictionary')));
} catch (DibiException $e) {
echo $e;
}
}
}
示例7: renderBlueScreen
/**
* 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';
}
示例8: log_write
function log_write($data, FileDownload $file, IDownloader $downloader)
{
$cache = Environment::getCache("FileDownloader/log");
$log = array();
$tid = (string) $file->getTransferId();
if (!isset($cache["registry"])) {
$cache["registry"] = array();
}
$reg = $cache["registry"];
$reg[$tid] = true;
$cache["registry"] = $reg;
if (isset($cache[$tid])) {
$log = $cache[$tid];
}
Debugger::fireLog("Data: " . $data . "; " . $downloader->end);
$data = $data . ": " . Helpers::bytes($file->transferredBytes) . " <->; ";
if ($downloader instanceof AdvancedDownloader and $downloader->isInitialized()) {
$data .= "position: " . Helpers::bytes($downloader->position) . "; ";
//$data .= "length: ".Helpers::bytes($downloader->length)."; ";
$data .= "http-range: " . Helpers::bytes($downloader->start) . "-" . Helpers::bytes($downloader->end) . "; ";
$data .= "progress (con: " . round($file->transferredBytes / $downloader->end * 100) . "% X ";
$data .= "file: " . round($downloader->position / $file->sourceFileSize * 100) . "%)";
}
$log[] = $data;
$cache[$tid] = $log;
}
示例9: createTemplate
/**
* @return Nette\Templates\ITemplate
*/
protected function createTemplate()
{
$template = new Nette\Templates\FileTemplate();
$presenter = $this->getPresenter(FALSE);
$template->onPrepareFilters[] = callback($this, 'templatePrepareFilters');
// default parameters
$template->control = $this;
$template->presenter = $presenter;
$template->user = Nette\Environment::getUser();
$template->baseUri = Nette\Environment::getVariable('baseUri', NULL);
$template->basePath = rtrim($template->baseUri, '/');
// flash message
if ($presenter !== NULL && $presenter->hasFlashSession()) {
$id = $this->getParamId('flash');
$template->flashes = $presenter->getFlashSession()->{$id};
}
if (!isset($template->flashes) || !is_array($template->flashes)) {
$template->flashes = array();
}
// default helpers
$template->registerHelper('escape', 'Nette\\Templates\\TemplateHelpers::escapeHtml');
$template->registerHelper('escapeUrl', 'rawurlencode');
$template->registerHelper('stripTags', 'strip_tags');
$template->registerHelper('nl2br', 'nl2br');
$template->registerHelper('substr', 'iconv_substr');
$template->registerHelper('repeat', 'str_repeat');
$template->registerHelper('replaceRE', 'Nette\\String::replace');
$template->registerHelper('implode', 'implode');
$template->registerHelper('number', 'number_format');
$template->registerHelperLoader('Nette\\Templates\\TemplateHelpers::loader');
return $template;
}
示例10: getConfig
public function getConfig()
{
if (!$this->config) {
$this->config = Environment::getConfig();
}
return $this->config;
}
示例11: handleUpload
public function handleUpload()
{
$files = \Nette\Environment::getHttpRequest()->getFile("user_file");
foreach ($files as $file) {
call_user_func($this->handler, $file);
}
}
示例12: getContext
/**
* @return \Nette\DI\Container
*/
protected function getContext()
{
static $context;
if (!$context) {
$context = \Nette\Environment::getContext();
}
return $context;
}
示例13: getStorageDir
/**
* @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);
}
}
示例14: validateEntity
private function validateEntity($entity)
{
$errors = Environment::getService("validator")->validate($entity);
if (count($errors) > 0) {
foreach ($errors as $violation) {
throw new \Neuron\Model\ValidationException($violation->getMessage(), $violation->getPropertyPath());
}
}
}
示例15: createTemplate
/**
* @return Template
*/
protected function createTemplate($file = null)
{
$template = new Template($file);
$template->baseUrl = \Nette\Environment::getHttpRequest()->url->baseUrl;
$template->basePath = rtrim($template->baseUrl, '/');
$template->interface = $this;
$template->registerHelperLoader('Nette\\Templating\\Helpers::loader');
return $template;
}