/** * 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; }
public static function getInstance() { if (!self::$instance) { self::$instance = new Application(); } return self::$instance; }
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); }
public static function GetInstance() { if (self::$instance == null) { self::$instance = new Application(); } return self::$instance; }
/** * Application singleton * @return Application */ public static function init() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
static function getInstance() { if (is_null(self::$instance)) { self::$instance = new self(); } return self::$instance; }
private static function getInstance() { if (!is_object(self::$instance)) { self::$instance = new self(); } return self::$instance; }
static function getInstance() { if (self::$instance == null) { self::$instance = new Application(); self::$instance->initialize(); } return self::$instance; }
/** * 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; }
/** * <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()); } }
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')); } }
/** * 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; }
/** * @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); } }
/** * 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); }
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; }
/** Find one model satisfying attributes * @param array $attributes * @return Model|null found model or null */ public function findByAttributes($attributes = []) { $db = Application::instance()->db; $tableName = $this->tableName(); $sql = "SELECT * FROM {$tableName}"; if (!empty($attributes)) { $sql .= " WHERE "; $condition = []; foreach ($attributes as $name => $value) { $condition[] = "{$name} = :{$name}"; } $sql .= implode(' AND ', $condition); } $sql .= " LIMIT 1"; $query = $db->prepare($sql); foreach ($attributes as $name => $value) { $query->bindValue(":{$name}", $value); } $result = null; if ($query->execute()) { if ($row = $query->fetch(\PDO::FETCH_ASSOC)) { $className = get_class($this); $model = new $className('update'); foreach ($row as $column => $value) { $model->{$column} = $value; } $result = $model; } } return $result; }
public function before() { parent::before(); // detecting language, setting it // $this->detect_language(); // $this->set('_language', $this->language); $this->set('device', $this->detect_device()); //var_dump($_COOKIE); // creating and attaching page metadata $this->metadata = new Model_Metadata(); $this->metadata->title(__(Application::instance()->get('title')), false); $this->set('_metadata', $this->metadata); $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 . Url::query()); View::bind_global('_breadcumbs', $this->breadcumbs); // detecting if user is logged in if (method_exists(Auth::instance(), 'auto_login')) { Auth::instance()->auto_login(); } // if (Auth::instance()->logged_in()) { $id = Auth::instance()->get_user()->id; $user = ORM::factory('user', $id); $input = $user->has('roles', ORM::factory('role', array('name' => 'admin'))); $this->set("admin_mode", $input); } else { $this->set("admin_mode", false); } // $this->user = Auth::instance()->get_user(); $this->set('_user', $this->user); if (Auth::instance()->logged_in() && $this->user->profile->is_visited != 1 && strtolower($this->request->controller()) == 'profile') { $this->redirect('profile/information', 301); } $sliders = ORM::factory('Slider')->where('is_active', '=', 1)->and_where('type', '=', 'slider')->order_by('order', 'asc')->find_all(); $this->set('sliders', $sliders); $banner = ORM::factory('Slider')->where('is_active', '=', 1)->and_where('type', '=', 'banner')->find_all(); $this->set('menu_banner', $banner); $menu = ORM::factory('Page')->where('key', '=', 'menu')->find(); //Для SEO (сортировка) if ($this->request->controller() == 'Auth' or $this->request->controller() == 'Search' or $this->request->controller() == 'Profile') { $this->set('sort', 1); } //end SEO $page_roots = ORM::factory('Page', $menu->id)->children(); $page_main = array(); $children_pages = array(); $children_pages_last = array(); $children_pages_last_last = array(); foreach ($page_roots as $p) { $page_main[$p->key] = array('id' => $p->id, 'name' => $p->name, 'description' => $p->description); $children_pages[$p->key] = $p->children(); //ORM::factory('Page')->where('parent_id','=',$p->id)->find_all();//только первый уровень детей //второй уровень детей. foreach ($children_pages[$p->key] as $ch_p) { if ($ch_p->id == 232 or $ch_p->id == 159) { continue; } $children_pages_last[$ch_p->id] = $ch_p->children(); //третий уровень детей foreach ($children_pages_last[$ch_p->id] as $ch_p_l) { $children_pages_last_last[$ch_p_l->id] = $ch_p_l->children(); } } } $page_halyk_kaharmany = ORM::factory('Page', 319); $this->set('page_halyk_kaharmany', $page_halyk_kaharmany); $this->set('_pages', $page_main)->set('_children_pages', $children_pages)->set('_children_pages_last', $children_pages_last)->set('_children_pages_last_last', $children_pages_last_last)->set('_return_url', URL::media(Request::initial()->uri())); //для вывода сообщения о регистрации восстановления пароля и прочих действий //само сообщение выводится в модальном окне, находится в шаблоне footer if (Message::get()) { $this->set('basic_message', Message::display('/message/basic')); } $nofollowlink = url::media(Request::initial()->uri()); $controller = strtolower(Request::initial()->controller()); $action = strtolower(Request::initial()->action()); if ($controller == 'books' and $action == 'index') { $params = explode('books/', $_SERVER['REQUEST_URI']); if (isset($params[1]) and isset($params[0])) { $params = explode('?', $params[1]); $razdel = $params[0]; } else { $razdel = ''; } if (isset($params[1])) { $params = explode('=', $params[1]); $idbook = $params[1]; } else { $idbook = ''; } $wherestring = 'books_' . $razdel . '_' . $idbook; $page = ORM::factory('Page')->where('key', '=', $wherestring)->find(); $linkid = $page->id; $nofollowlink = URL::site('contents/list/' . $linkid); } if ($controller == 'biography' and $action == 'index') { $params = explode('biography/', $_SERVER['REQUEST_URI']); if (isset($params[1])) { $idbiography = $params[1]; } else { $idbiography = ''; } $wherestring = 'biography' . '_' . $idbiography; $page = ORM::factory('Page')->where('key', 'LIKE', $wherestring . '%')->find(); $linkid = $page->id; $nofollowlink = URL::site('contents/list/' . $linkid); } if ($controller == 'organization' and $action == 'show') { $params = explode('organization/show/', $_SERVER['REQUEST_URI']); if (isset($params[1])) { $idorganization = $params[1]; } else { $idorganization = ''; } $wherestring = 'organization' . '_' . $idorganization; $page = ORM::factory('Page')->where('key', 'LIKE', $wherestring . '%')->find(); $linkid = $page->id; $nofollowlink = URL::site('contents/list/' . $linkid); } if ($controller == 'expert' and $action == 'index') { $nofollowlink = URL::site('contents/list/301'); } //в базе дублируется запись 4 и 301 if ($controller == 'publications' and $action == 'index') { $nofollowlink = URL::site('contents/list/231'); } if ($controller == 'debate' and $action == 'index') { $nofollowlink = URL::site('contents/list/335'); } if ($controller == 'debate' and $action == 'index') { $nofollowlink = URL::site('contents/list/335'); } $this->set('nofollowlink', $nofollowlink); //потому-что SEO. }
<?php namespace bloc; date_default_timezone_set('America/Chicago'); #1. Frow where index.php is located, load the application file. This is the only mandatory part I think. require '../bloc/application.php'; #2. Create an instance of the application $app = Application::instance(['mode' => 'dev']); # main page deal $app->prepare('http-request', function ($app, $params) { $request = new Request($params); $response = new Response($request); $app->setExchanges($request, $response); // Provide a namespace (also a directory) to load objects that can respond to controller->action $router = new Router('controllers', $request); // default controller and action as arguments, in case nothin doin in the request $response->setBody($router->delegate('graph', 'index')); echo $response; }); #4. Run the app. Nothing happens w/o this. Can call different stuff from the queue. $app->execute('http-request', $_REQUEST);
<?php namespace bloc; define('DOMAIN', "http://{$_SERVER['SERVER_NAME']}"); date_default_timezone_set('America/Chicago'); #1. Frow where index.php is located, load the application file. This is the only mandatory part I think. require '../bloc/application.php'; #2. Create an instance of the application $app = Application::instance(['mode' => getenv('MODE') ?: 'production']); #3. Get a Session ready $app->prepare('session-start', function ($app) { $app->session('COLUM'); }); $app->prepare('clean-up', function ($app) { session_write_close(); }); # main page deal $app->prepare('http-request', function ($app, $params) { $request = new Request($params); $response = new Response($request); $app->setExchanges($request, $response); // Provide a namespace (also a directory) to load objects that can respond to controller->action $router = new Router('controllers', $request); try { $output = $router->delegate('lecture', 'index'); } catch (\Exception $e) { \bloc\application::instance()->log($e->getTrace()); $view = new View(\controllers\records::layout); $view->content = 'views/layouts/error.html'; $output = $view->render(['message' => $e->getMessage()]);
function app($callback = null) { return Application::instance($callback); }
function log_error($msg) { $logger = Application::instance()->logger(); $logger->error($msg); }
/** * We will return proxy objects from container * * @return Container */ protected static function getContainer() { return Application::instance(); }
<?php /** * This file is part of the Cygnite package. * * (c) Sanjoy Dey <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Cygnite\Foundation; if (!defined('CF_SYSTEM')) { exit('External script access not allowed'); } return array(Application::instance()->registerDirectories(array('apps.controllers', 'apps.models', 'apps.configs.definitions')));
* Cygnite framework * Auto loader Configuration Settings * * An open source application development framework for PHP 5.3x or newer * * License * * This source file is subject to the MIT license that is bundled * with this package in the file LICENSE.txt. * http://www.cygniteframework.com/license.txt * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to sanjoy@hotmail.com so I can send you a copy immediately. * *@package : Apps *@subpackages : Configurations *@filename : autoload *@description : This file is used to specify which files should be register * on cygnite engine by default. *@author : Sanjoy Dey *@copyright : Copyright (c) 2013 - 2014, *@link : http://www.cygniteframework.com *@since : Version 1.0 *@filesource *@warning : If you don't protect this directory from direct web access, * anybody will be able to see your configuaration and settings. * * */ return array(Application::instance()->registerDirectories(array('apps.controllers', 'apps.modules', 'apps.configs.definitions', 'apps.models', 'apps.components.authx', 'apps.components.thumbnail', 'apps.components.form', 'apps.components.wallscript', 'apps.extensions', 'apps.modules.admin')));
<?php require_once 'helpers/Application.php'; /** * Structure: * Example: index/run/123 * 1. index is controller * 2. run is method of index controller * 3. 123 is parameter in run method of index controller */ $App = Application::instance(); $App->run();
<?php require_once dirname(dirname(__FILE__)) . '/test.application.inc'; Application::instance()->main();
/** * @return Application */ public static function Instance() { if (is_null(self::$instance)) { self::$instance = new Application(); } return self::$instance; }
/** * @return SessionInstance */ public static function instance() { return Application::instance()->getSession(); }