/**
  * Restrict user to access the application if user
  * not belong to particular IP address.
  *
  * @param Request $request
  * @param callable $next
  * @return static
  */
 public function handle(Request $request, Closure $next)
 {
     if ($request->server->get('REMOTE_ADDR') !== '192.168.23.1') {
         return Response::make('Forbidden', ResponseHeader::HTTP_UNAUTHORIZED);
     }
     return $next($request);
 }
Exemple #2
0
 public function testViewCreateMethod()
 {
     $data = ['foo' => 'Cygnite!'];
     $content = View::create("fixtures.hello", $data);
     $this->assertEquals('Hello Cygnite!', Response::make($content)->getContent());
     $data = ['foo' => 'Foo Bar!'];
     $composeContent = View::compose("fixtures.hello", $data);
     $this->assertEquals('Hello Foo Bar!', Response::make($composeContent)->getContent());
 }
Exemple #3
0
 public function testSetAndReturnsHeadersCorrectly()
 {
     $r = Response::make('hello http')->setHeader('Content-Type', 'application/json');
     $this->assertSame(true, $r->getHeaders()->has('Content-Type'));
     $r = Response::make('hello http');
     $r->setHeader('Content-Type', 'text/xml');
     $this->assertSame(true, $r->getHeaders()->has('Content-Type'));
     $this->assertEquals('text/xml', $r->getHeaders()->get('Content-Type'));
 }
Exemple #4
0
 public function testViewCreateMethod()
 {
     $app = new \Cygnite\Foundation\Application();
     ViewFactory::setApplication($app);
     $data = ['foo' => 'Cygnite!'];
     $content = View::create('fixtures.hello', $data);
     $this->assertEquals('Hello Cygnite!', Response::make($content)->getContent());
     $data = ['foo' => 'Foo Bar!'];
     $composeContent = View::compose('fixtures.hello', $data);
     $this->assertEquals('Hello Foo Bar!', Response::make($composeContent)->getContent());
 }
Exemple #5
0
 /**
  * Handle the request and dispatch to routes.
  *
  * @param $request
  *
  * @throws Exception|\Exception
  *
  * @return array|ResponseInterface|mixed|static
  *
  *
  * @note this function is incomplete, need to enhance
  * for better exception handling
  */
 public function handle($request)
 {
     $this->setRouter($this->app->compose('Cygnite\\Base\\Router\\Router', $request), $request);
     try {
         $response = $this->sendRequestThroughRouter($request);
         /*
          * Check whether return value is a instance of Response,
          * otherwise we will try to fetch the response form container,
          * create a response and return to the browser.
          *
          */
         if (!$response instanceof ResponseInterface && !is_array($response)) {
             $r = $this->app->has('response') ? $this->app->get('response') : '';
             $response = Response::make($r);
         }
     } catch (\Exception $e) {
         $this->handleException($e);
     } catch (Throwable $e) {
         $this->handleException($e);
     }
     return $response;
 }
 /**
  *  Display product details
  * @param type $id
  */
 public function showAction($id)
 {
     $product = Product::find($id);
     $content = View::create('Apps.Views.product.show', ['record' => $product, 'title' => 'Show the Product']);
     return Response::make($content);
 }
| Set Locale For The Application
| $app->setLocale();
*/
/*
| Language Translation
|
|  show(trans('message:custom.welcome'));
|  show(trans('message:accepted', ['{attribute}' => 'accepted']));
|  show(trans('Hello Translator {user}', ['{user}' => 'Cygnite']));
*/
$app->router->get('/module/{:id}', function ($router, $id) {
    /*
    | Call module directly from routing
    */
    $content = $router->callController(["Acme::User@index", [$id]]);
    return Response::make($content);
});
/*
| Separate all static and group routing from this file
| also allow you to extend the CRUD static routes
|
| For every CRUD Controller you need to define routes
| in RouteCollection, see
| 
| RouteCollection::executeStaticRoutes(); function
|
| Uncomment below snippet to use RouteCollection
*/
$routeCollection = $app->make('\\Apps\\Routing\\RouteCollection');
$routeCollection->setRouter($app->router)->run();
$app->router->get('/user/{:name}/{:id}', function ($router, $name, $groupId) {
 /**
  * Default method for your controller. Render welcome page to user.
  * @access public
  *
  */
 public function indexAction()
 {
     $content = View::create('Apps.Views.home.welcome', ['title' => 'Welcome to Cygnite Framework']);
     return Response::make($content);
 }