本文整理汇总了PHP中Application::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::instance方法的具体用法?PHP Application::instance怎么用?PHP Application::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Application
的用法示例。
在下文中一共展示了Application::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createFreshMockInstance
/**
* Create a fresh mock instance for the given class.
*
* @param string $name
* @return \Mockery\Expectation
*/
protected static function createFreshMockInstance($name)
{
static::$resolvedInstance[$name] = $mock = static::createMockByName($name);
$mock->shouldAllowMockingProtectedMethods();
if (isset(static::$app)) {
static::$app->instance($name, $mock);
}
return $mock;
}
示例2: getInstance
public static function getInstance()
{
if (!self::$instance) {
self::$instance = new Application();
}
return self::$instance;
}
示例3: before
public function before()
{
parent::before();
// detecting language, setting it
$this->detect_language();
$this->set('_language', $this->language);
// creating and attaching page metadata
$this->metadata = new Model_Metadata();
$this->metadata->title(__(Application::instance()->get('title')), false);
$this->set('_metadata', $this->metadata);
//TODO: token auth
/*
if ($this->request->method() == Request::POST && Arr::get($_POST, 'token', '') !== Security::token())
{
throw new HTTP_Exception_403('Wrong token data');
}
*/
$this->set('_token', Security::token());
// Handles return urls, cropping language out of it (will be appended by url.site at redirect time)
$rr = Request::initial()->uri();
$rr = trim($rr, '/');
$rr = explode('/', $rr);
if (in_array($rr[0], Application::instance()->get('language.list'))) {
array_shift($rr);
}
$rr = implode('/', $rr);
$this->set('_return', $rr);
// detecting if user is logged in
if (method_exists(Auth::instance(), 'auto_login')) {
Auth::instance()->auto_login();
}
$this->user = Auth::instance()->get_user();
$this->set('_user', $this->user);
}
示例4: GetInstance
public static function GetInstance()
{
if (self::$instance == null) {
self::$instance = new Application();
}
return self::$instance;
}
示例5: init
/**
* Application singleton
* @return Application
*/
public static function init()
{
if (!self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
示例6: getInstance
static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
示例7: getInstance
private static function getInstance()
{
if (!is_object(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
示例8: getInstance
static function getInstance()
{
if (self::$instance == null) {
self::$instance = new Application();
self::$instance->initialize();
}
return self::$instance;
}
示例9: getInstance
/**
* return the once Application instance
* @param: NULL
* @return: ref
* @access: public
* @static
*/
public static function getInstance()
{
/*{{{*/
if (!isset(self::$instance)) {
$c = __CLASS__;
self::$instance = new $c();
}
return self::$instance;
}
示例10: run
/**
* <p>This is the only methods which runs the application. In fact it creates a new
* instance of this class because the constructor contains all necessary instructions to set up
* application variables and parse required data from XML source. It is as easy as possible 8-D</p>
*/
public static function run()
{
self::$instance = new Application();
try {
self::$instance->getParser()->parse();
Viewer::vizualize(self::$instance->getParams()->getRequestedView());
} catch (Exception $e) {
self::$instance->caughtException = $e;
Viewer::vizualize(self::$instance->getParams()->getErrorView());
}
}
示例11: before
public function before()
{
//$this->redirect('http://ehistory.kz/manage');
parent::before();
$this->response->headers('cache-control', 'private');
// creating and attaching page metadata
$this->metadata = new Model_Metadata();
$this->metadata->title(__(Application::instance()->get('title')), false);
$this->set('_metadata', $this->metadata);
Auth::instance()->auto_login();
if (!Auth::instance()->logged_in()) {
$this->redirect('manage/auth/login');
} else {
$id = Auth::instance()->get_user()->id;
$user = ORM::factory('user', $id);
$input = $user->has('roles', ORM::factory('role', array('name' => 'admin'))) || $user->has('roles', ORM::factory('Role', array('name' => 'moderator')));
$input_redactor = $user->has('roles', ORM::factory('Role', array('name' => 'redactor')));
if (!$input && !$input_redactor) {
$this->redirect('/manage/auth/logout');
}
if (!$input && (strtolower($this->request->controller()) != 'ehistory' && strtolower($this->request->controller()) != 'language')) {
$this->redirect('manage/ehistory');
}
}
$this->user = Auth::instance()->get_user();
if (Request::$initial === Request::$current) {
$messages = Notify::instance()->get_all_once();
$this->set('_notifications', $messages);
}
$language = Session::instance()->get('_language', 'ru');
$this->language = in_array($language, array('ru', 'en', 'kz')) ? $language : 'ru';
I18n::lang($this->language);
$rr = Request::initial()->uri() . urlencode(URL::query(null, true));
$rr = trim($rr, '/');
//$this->metadata->title('Sharua.kz', false);
$countcomm = ORM::factory('Comment')->where('status', '=', '0')->count_all();
//смотрим сколько новых коментов
$this->set('_user', $this->user)->set('_language', $this->language)->set('_return_url', $rr)->set('_countcomm', $countcomm);
//вносим в переменную количество новых коментов
$knigi = ORM::factory('Book')->where('category_id', '=', '0')->find_all();
//смотрим сколько книг без категории
if ($knigi) {
if (count($knigi) > 0) {
$this->set('_uncatcount', count($knigi));
//вносим в переменную количество книг без категории
}
}
$this->referrer = Request::initial()->referrer();
if (Message::get()) {
$this->set('basic_message', Message::display('/message/basic'));
}
}
示例12: is
/**
* Check if the current environment matches one of the names passed.
*
* @param string|string[] $names A name or array of names
*
* @return bool
*/
public static function is($names)
{
if (is_string($names)) {
$names = [$names];
}
$app = Application::instance();
foreach ($names as $name) {
if (in_array($name, $app->environments)) {
return true;
}
}
return false;
}
示例13: setMethodArguments
/**
* @return void
*/
protected function setMethodArguments()
{
$method = new \ReflectionMethod($this->controller, $this->method);
$parameters = $method->getParameters();
foreach ($parameters as $param) {
if (array_key_exists($param->getName(), $this->params)) {
$this->arguments[] = $this->params[$param->getName()];
continue;
} elseif ($param->isDefaultValueAvailable()) {
$this->arguments[] = $param->getDefaultValue();
continue;
}
$class = $param->getClass()->name;
$this->arguments[] = Application::instance()->get($class);
}
}
示例14: slab_core_init
/**
* Initialize Slab Core
*
* @return void
**/
function slab_core_init()
{
$autoloader = new Autoloader();
$autoloader->registerNamespace('Slab\\Core', SLAB_CORE_DIR . 'src');
$slab = Application::instance();
$slab->singleton('Slab\\Core\\Application', $slab);
$slab->alias('Slab\\Core\\ContainerInterface', 'Slab\\Core\\Application');
$slab->singleton('Slab\\Core\\Autoloader', $autoloader);
$slab->alias('autoloader', 'Slab\\Core\\Autoloader');
$slab->singleton('Slab\\Core\\Http\\RequestInterface', function () {
return Request::createFromGlobals();
});
$slab->alias('request', 'Slab\\Core\\Http\\RequestInterface');
do_action('slab_init', $slab);
do_action('slab_boot', $slab);
do_action('slab_loaded', $slab);
}
示例15: handleException
public static function handleException(Exception $exception)
{
// Log exception
$logger = Application::instance()->logger();
if ($logger !== null) {
$msg = sprintf("%s: %s", get_class($exception), $exception->getMessage());
try {
$logger->error($msg);
} catch (Exception $e) {
// Ignore exception, it will be handled next time
}
}
// Mail exception
$errorsMailer = new ErrorsMailer();
try {
$errorsMailer->deliverErrorMail($exception);
} catch (Exception $e) {
// Ignore exception, it will be handled next time
}
// Render exception for development and show 500 page in production
try {
if (is_development()) {
$format = is_cli() ? 'txt' : 'html';
$view_template = sprintf('errors/exception.%s.php', $format);
$request = new Request();
$view = new View(APP_VIEWS_DIR, $view_template, array('exception' => $exception, 'request' => $request));
$response = new Response();
$response->statusCode = 500;
$response->body = $view->render();
$response->send();
} else {
if (!is_cli()) {
$view = new View(PUBLIC_DIR, '500.html');
$response = new Response();
$response->statusCode = 500;
$response->body = $view->render();
$response->send();
}
}
} catch (Exception $e) {
echo $e->getMessage();
}
exit;
}