本文整理汇总了PHP中AppKernel::getEnvironment方法的典型用法代码示例。如果您正苦于以下问题:PHP AppKernel::getEnvironment方法的具体用法?PHP AppKernel::getEnvironment怎么用?PHP AppKernel::getEnvironment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppKernel
的用法示例。
在下文中一共展示了AppKernel::getEnvironment方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setServiceKernel
/**
* 每个testXXX执行之前,都会执行此函数,净化数据库。
*
* NOTE: 如果数据库已创建,那么执行清表操作,不重建。
*/
private function setServiceKernel()
{
$kernel = new \AppKernel('test', false);
$kernel->loadClassCache();
$kernel->boot();
Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$serviceKernel = ServiceKernel::create($kernel->getEnvironment(), $kernel->isDebug());
$serviceKernel->setParameterBag($kernel->getContainer()->getParameterBag());
$serviceKernel->setConnection($kernel->getContainer()->get('database_connection'));
$currentUser = new CurrentUser();
$currentUser->fromArray(array('id' => 1, 'nickname' => 'admin', 'email' => 'admin@admin.com', 'password' => 'admin', 'currentIp' => '127.0.0.1', 'roles' => array('ROLE_USER', 'ROLE_ADMIN', 'ROLE_SUPER_ADMIN', 'ROLE_TEACHER')));
$serviceKernel->setCurrentUser($currentUser);
$this->serviceKernel = $serviceKernel;
}
示例2: __construct
/**
*
* @param array $connection
* @param array $paths Array of Paths where Search Entities are found
* @param \AppKernel $kernel
*/
public function __construct(array $connection, array $paths = array(), \AppKernel $kernel)
{
$cacheProvider = 'Doctrine\\Common\\Cache\\ArrayCache';
//Annotation metadata driver
$config = new Configuration();
$md = $config->newDefaultAnnotationDriver($paths);
$config->setMetadataDriverImpl($md);
$config->setMetadataCacheImpl(new $cacheProvider());
$config->setEntitySerializer(new CallbackSerializer('toESDocument', 'fromESDocument'));
$bundles = $kernel->getBundles();
$entityNamespaces = array();
foreach ($bundles as $bundle) {
$nameSpace = $bundle->getNamespace();
$name = $bundle->getName();
$entityNamespaces[$name] = $nameSpace;
}
$config->setEntityNamespaces($entityNamespaces);
$client = new \Elastica\Client(array('connections' => array($connection)));
$this->searchManager = new SearchManager($config, new \Revinate\SearchBundle\Lib\Search\ElasticSearch\Client($client), new EventManager());
$this->mappingManager = new MappingManager($this->searchManager, $kernel->getEnvironment());
}
示例3: onKernelException
/**
* Event handler that renders not found page
* in case of a NotFoundHttpException
*
* @param GetResponseForExceptionEvent $event
*
* @access public
* @return void
* @author Riad Hellal <hellal.riad@gmail.com>
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
$this->request = $event->getRequest($event);
// provide the better way to display a enhanced error page only in prod environment, if you want
if (in_array($this->kernel->getEnvironment(), array('test', 'prod'))) {
// exception object
$exception = $event->getException();
// new Response object
$response = new Response();
//$requestDuplicate = $this->request->duplicate(null, null, ['_controller' => 'MyAppSiteBundle:Default:exception']);
//$response = $this->kernel->handle($requestDuplicate, HttpKernelInterface::SUB_REQUEST);
if ($this->container->hasParameter('sfynx.auth.theme.layout.error.html') && $this->container->getParameter('sfynx.auth.theme.layout.error.html') != "") {
$path_error_file = realpath($this->kernel->locateResource($this->container->getParameter('sfynx.auth.theme.layout.error.html')));
$response->setContent(file_get_contents($path_error_file));
} else {
if ($this->container->hasParameter('sfynx.auth.theme.layout.error.route_name') && $this->container->getParameter('sfynx.auth.theme.layout.error.route_name') != "") {
$route_name = $this->container->getParameter('sfynx.auth.theme.layout.error.route_name');
} else {
$route_name = 'error_404';
}
$url = $this->container->get('sfynx.tool.route.factory')->getRoute($route_name, array('locale' => $this->locale));
$content = PiFileManager::getCurl('/' . $url, null, null, $this->request->getUriForPath(''));
$response->setContent($content);
}
// HttpExceptionInterface is a special type of exception
// that holds status code and header details
if (method_exists($exception, "getStatusCode")) {
$response->setStatusCode($exception->getStatusCode());
} else {
$response->setStatusCode('404');
}
if (method_exists($response, "getHeaders")) {
$response->headers->replace($exception->getHeaders());
}
// set the new $response object to the $event
$event->setResponse($response);
}
}
示例4: AppKernel
}
use Symfony\Component\Debug\Debug;
use Topxia\Service\User\CurrentUser;
use Topxia\Service\Common\ServiceKernel;
use Symfony\Component\HttpFoundation\Request;
fix_gpc_magic();
$loader = (require_once __DIR__ . '/../app/bootstrap.php.cache');
Debug::enable();
require_once __DIR__ . '/../app/AppKernel.php';
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$kernel->boot();
// START: init service kernel
$serviceKernel = ServiceKernel::create($kernel->getEnvironment(), $kernel->isDebug());
$serviceKernel->setEnvVariable(array('host' => $request->getHttpHost(), 'schemeAndHost' => $request->getSchemeAndHttpHost(), 'basePath' => $request->getBasePath(), 'baseUrl' => $request->getSchemeAndHttpHost() . $request->getBasePath()));
$serviceKernel->setParameterBag($kernel->getContainer()->getParameterBag());
$serviceKernel->registerModuleDirectory(dirname(__DIR__) . '/plugins');
$serviceKernel->setConnection($kernel->getContainer()->get('database_connection'));
$serviceKernel->getConnection()->exec('SET NAMES UTF8');
$currentUser = new CurrentUser();
$currentUser->fromArray(array('id' => 0, 'nickname' => '游客', 'currentIp' => $request->getClientIp(), 'roles' => array()));
$serviceKernel->setCurrentUser($currentUser);
// END: init service kernel
// NOTICE: 防止请求捕捉失败而做异常处理
// 包括:数据库连接失败等
try {
$response = $kernel->handle($request);
} catch (\RuntimeException $e) {
echo "Error! " . $e->getMessage();