public function testComposeMethod() { $app = Application::instance(); $bazBar = $app->compose('BazBar', ['greet' => 'Hello!']); $this->assertArrayHasKey('greet', $app); $this->assertEquals("Hello!", $bazBar->greet()); }
public function setUp() { $_SERVER['HTTP_HOST'] = 'localhost'; $_SERVER['REQUEST_URI'] = '/'; $app = Application::instance(); $app['router'] = new Router(); Url::setBase("/cygnite/index.php/user"); }
/** * @return mixed */ public static function make() { if (is_null(static::$view)) { $app = App::instance(); static::$view = $app->resolve('cygnite.mvc.view.view'); } return static::$view; }
public function setUp() { $this->app = Application::instance(); $this->app['url'] = new \Cygnite\Common\UrlManager\Url(); $this->app['request'] = \Cygnite\Http\Requests\Request::createFromGlobals(); $this->app['router'] = new \Cygnite\Base\Router\Router($this->app['request']); $this->app['router']->setApplication($this->app); $this->app['url']->setApplication($this->app); $this->url = $this->app['url']; }
private function setUpAssetConfig() { $app = Application::instance(); $app['router'] = new \Cygnite\Base\Router\Router(); $_SERVER['REQUEST_URI'] = '/hello/user/'; $_SERVER['HTTP_HOST'] = 'localhost'; $configuration = ['global.config' => ['encoding' => 'utf-8']]; Config::$config = $configuration; Url::setBase('/cygnite/'); //$app['router']->getBaseUrl() }
public function setUp() { $this->app = Application::instance(); $this->app['request'] = \Cygnite\Http\Requests\Request::createFromGlobals(); $this->app['router'] = new \Cygnite\Base\Router\Router($this->app['request']); $this->app['router']->setApplication($this->app); $this->app['request']->server->add('SCRIPT_NAME', '/index.php'); $this->app['request']->server->add('REQUEST_METHOD', 'GET'); $this->app['request']->server->add('SERVER_PROTOCOL', 'HTTP/1.1'); $this->router = $this->app['router']; }
public function testMakeClass() { $this->app = Application::instance(); $this->app['url'] = new \Cygnite\Common\UrlManager\Url(); $this->app['request'] = \Cygnite\Http\Requests\Request::createFromGlobals(); $this->app['router'] = new \Cygnite\Base\Router\Router($this->app['request']); $this->app['router']->setApplication($this->app); $this->app['url']->setApplication($this->app); $madeUrl = $this->container->make('\\Cygnite\\Common\\UrlManager\\Url'); $madeUrl->setApplication($this->app); $this->assertEquals($this->app['url'], $madeUrl); }
/** * We will run Cygnite Console Application */ public function run() { $app = CygniteApplication::instance(); $console = new ConsoleApplication($app, $this->version); /* | We will also register Application Console commands | User can register multiple commands apart from core | commands and run on the fly */ $appConsoleBootStrap = $app->make('\\Apps\\Console\\BootStrapConsoleApplication'); $appConsoleCommands = $appConsoleBootStrap->register(); $console->setCommand($appConsoleCommands)->registerCommands()->run(); }
private function setUpAssetConfig() { $app = Application::instance(); $app['url'] = new \Cygnite\Common\UrlManager\Url(); $app['request'] = \Cygnite\Http\Requests\Request::createFromGlobals(); $app['router'] = new \Cygnite\Base\Router\Router($app['request']); $app['url']->setApplication($app); $app['request']->server->add('REQUEST_URI', '/hello/user'); $app['request']->server->add('HTTP_HOST', 'localhost'); $configuration = ['global.config' => ['encoding' => 'utf-8']]; Config::$config = $configuration; Url::setBase('cygnite/'); //$app['router']->getBaseUrl() }
public function setUp() { $this->app = Application::instance(); $this->app['url'] = new \Cygnite\Common\UrlManager\Url(); $this->app['request'] = \Cygnite\Http\Requests\Request::createFromGlobals(); $this->app['router'] = new \Cygnite\Base\Router\Router($this->app['request']); $this->app['router']->setApplication($this->app); $this->app['url']->setApplication($this->app); $this->app['request']->server->add('HTTP_HOST', 'localhost'); $this->app['request']->server->add('REQUEST_URI', '/'); /* $app = Application::instance(); $app['router'] = new Router;*/ Url::setBase('/cygnite/index.php/user'); }
/** * Get Application instance * * @return App */ private function getApplication() { return App::instance(); }
/** * @param $arguments * @return object * @throws \Exception */ private function callController($arguments) { $params = array(); if (isset($arguments[1])) { $params = $arguments[1]; } $this->setUpControllerAndMethodName($arguments); $file = CYGNITE_BASE . strtolower(str_replace('\\', DS, $this->namespace)) . $this->controller . EXT; if (!is_readable($file)) { throw new \Exception("Route " . array_pop($arguments) . " not found. "); } //include $file; $router = $this; // Get the instance of controller from Cygnite Container // and inject all dependencies into controller dynamically // It's cool. You can write powerful rest api using restful // routing return Application::instance(function ($app) use($router) { // make and return instance of controller $instance = $app->make($router->controllerWithNS); // inject all properties of controller defined in definition $app->propertyInjection($instance, $router->controllerWithNS); return $instance->{$router->method}(); }); }
function app($callback = null) { return App::instance($callback); }
/** * We will return proxy objects from container * * @return Container */ protected static function getContainer() { return Application::instance(); }
/** * Add wildcards to the given URI. * * @param string $uri * @return string */ public function addUriWildcards($uri, $reflection, $method) { $refAction = $reflection->getReflectionClass()->getMethod($method); $app = Application::instance(); $parameter = ''; $patterns = $app->router->getPattern(); $arguments = new \CachingIterator(new \ArrayIterator($refAction->getParameters())); foreach ($arguments as $key => $param) { if (!$param->isOptional()) { if (array_key_exists('{:' . $param->getName() . '}', $patterns)) { $slash = $arguments->hasNext() ? '/' : ''; $parameter .= '{:' . $param->getName() . '}' . $slash; } } } return $uri . '/' . $parameter; }
/** Return Url Instance * * @return static */ public static function make() { $app = App::instance(); return new static($app['router']); }
public function setUp() { $app = Application::instance(); $app['router'] = new Router(); $this->url = new Url($app['router']); }
/** * Run user quest and call controller * * @return mixed */ public function run() { $dispatcher = null; $dispatcher = $this; // If no argument passed or single slash call default controller if ($this->router->getCurrentUri() == '/' || $this->router->getCurrentUri() == '/' . self::$indexPage) { if ($this->default['controller'] != '') { //Static route: / (Default Home Page) $response = $this->router->get('/', function () use($dispatcher) { return Application::instance(function ($app) use($dispatcher) { $controller = $app->getController($dispatcher->default['controller']); $action = $app->getActionName($dispatcher->default['action']); $instance = $app->make($controller); $app->propertyInjection($instance, $controller); return call_user_func_array(array($instance, $action), array()); }); }); } } else { $routeConfig = Config::get('config.router'); $newUrl = str_replace('/index.php', '', rtrim($this->router->getCurrentUri())); $exp = array_filter(explode('/', $newUrl)); $matchedUrl = $this->matches($routeConfig); //Check with router configuration if matched then call defined controller if (!is_null($matchedUrl)) { $requestUri = preg_split('/[\\.\\ ]/', $matchedUrl['controllerPath']); // We are matching with static routing if match then dispatch it $response = Application::instance(function ($app) use($requestUri, $matchedUrl, $dispatcher) { $controller = $app->getController($requestUri[0]); $action = $app->getActionName($requestUri[1]); if (!class_exists($controller)) { throw new Exception('Unhandled Exception (404 Page)'); } $params = (array) $matchedUrl['params']; $instance = $app->make($controller); $app->propertyInjection($instance, $controller); return call_user_func_array(array($instance, $action), $params); }); } else { // Process user request provided in url $response = Application::instance(function ($app) use($exp, $dispatcher) { $controller = $method = $param = $instance = null; $controller = $exp[1]; if (isset($exp[2])) { $method = $exp[2]; } $params = array_slice($exp, 2); $controllerDir = ''; if (is_dir(CYGNITE_BASE . str_replace('\\', DS, strtolower($app->namespace . $exp[1])))) { $controllerDir = ucfirst($exp[1]); $controller = $exp[2]; $method = $exp[3]; $params = array_slice($exp, 3); } $controller = $app->getController($controller, $controllerDir); $action = isset($method) ? $method : 'index'; $action = $app->getActionName($action); if (!class_exists($controller)) { throw new Exception('Unhandled Exception (404 Page)'); } $instance = $app->make($controller); $app->propertyInjection($instance, $controller); return call_user_func_array(array($instance, $action), $params); }); } } $this->router->run(); return $response; }
| ------------------------------------------------------------------- */ $filename = preg_replace('#(\\?.*)$#', '', $_SERVER['REQUEST_URI']); if (php_sapi_name() === 'cli-server' && is_file($filename)) { return false; } /* |-------------------------------------------------------------------------- | Create The Application |-------------------------------------------------------------------------- | | To boot framework first thing we will create a new application instance | which serves glue for all the components, and binding components | with the IoC container */ $app = \Cygnite\Foundation\Application::instance(); //$app->importHelpers(); /* |-------------------------------------------------------------------------- | Attach Exception handler to Event Listener |-------------------------------------------------------------------------- | | We will attach exception handler to event listener, so that if anything | goes wrong it will catch exceptions. */ $app['app.event'] = function () use($app) { $event = $app->singleton('event', '\\Cygnite\\Base\\EventHandler\\Event'); $event->attach("exception", '\\Cygnite\\Exception\\Handler@handleException'); return $event; }; $config = \Cygnite\Helpers\Config::load();
/** * Get the application instance * @return Application */ public static function getContainer() { return Application::instance(); }
function show($resultArray = array(), $hasExit = "") { echo '<pre>'; print_r($resultArray); echo '</pre>'; if ($hasExit === 'exit') { exit; } } global $event; //create Event handler to attach all events $event = new Event(); $event->attach("exception", '\\Cygnite\\Exception\\Handler@handleException'); $config = array(); //Get the configuration variables. $config = array('app' => Config::load(), 'event' => $event); //unset($config); //Load application and Get application instance to boot up $application = Application::instance(function ($app) use($config) { /** *--------------------------------------------------- * Set Configurations and Events for boot-up process * -------------------------------------------------- */ return $app->setConfiguration($config)->boot(); }); //Response to browser $application->run(); if (Config::get('global.config', 'enable_profiling') == true) { Profiler::end(); }
<?php use Cygnite\Foundation\Application; if (!defined('CF_SYSTEM')) { exit('No External script access allowed'); } $app = Application::instance(); // Before Router Middle Ware $app->router->before('GET', '/{:all}', function () { //echo "This site is under maintenance.";exit; }); /* // Dynamic route: /hello/cygnite/3222 $app->router->get('/hello/{:name}/{:digit}', function ($router, $name, $id) { //Router::call('Home.welcome', array($name, $id)); }); */ /* GET - resource/ user.getIndex GET - resource/new user.getNew POST - resource/ user.postCreate GET - resource/{id} user.getShow GET - resource/{id}/edit user.getEdit PUT|PATCH - resource/{id} user.putUpdate DELETE - resource/{id} user.delete */ //$app->router->resource('resource', 'user'); // respond to resource routing /** * After routing callback * Will call after executing all user defined routing.
/** * Sets up the tests */ public function setUp() { $this->app = Application::instance(); $this->pipeline = new Pipeline($this->app); }
/** * Get Application instance * * @return App */ public function getApplication() { return App::instance(); }
/** * @param $func * @param $pattern * @throws \Exception * @return mixed */ protected function mapStaticRoutes($pattern, $func) { $app = null; $app = App::instance(); return $app['router']->get($pattern, $func); }
/** * @return mixed */ public function view() { ViewFactory::setApplication(Application::instance()); return ViewFactory::make(); }
public function getContainer() { return App::instance(); }
/** * We will return proxy objects from container. * * @return Container */ public static function app() { return Application::instance(); }
protected function getContainer() { return App::instance(); }
/** * @param $arguments * @return object * @throws \Exception */ private function callController($arguments) { $params = array(); $this->setUpControllerAndMethodName($arguments); // Check if whether user trying to access module if (string_has($arguments[0], '::')) { $exp = string_split($arguments[0], '::'); $this->setModuleConfiguration($exp); } if (isset($arguments[1])) { $params = $arguments[1]; } $file = CYGNITE_BASE . str_replace('\\', DS, $this->controllerWithNS) . EXT; if (!is_readable($file)) { throw new \Exception("Route " . $this->controllerWithNS . " not found. "); } $me = $this; // Get the instance of controller from Cygnite Container // and inject all dependencies into controller dynamically // It's cool. You can write powerful rest api using restful // routing return App::instance(function ($app) use($me, $params) { // make and return instance of controller $instance = $app->make($me->controllerWithNS); // inject all properties of controller defined in definition $app->propertyInjection($instance, $me->controllerWithNS); $args = array(); $args = !is_array($params) ? array($params) : $params; return call_user_func_array(array($instance, $me->method), $args); }); }