/**
  * 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);
 }
예제 #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());
 }
예제 #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'));
 }
예제 #4
0
 /**
  * @param null  $content
  * @param array $headers
  * @param bool  $prettyPrint
  */
 public function __construct($content = null, $headers = [], $prettyPrint = false)
 {
     if (null === $content) {
         $content = new \ArrayObject();
     }
     if (is_array($content) || is_object($content)) {
         $content = $this->jsonEncode($content, $prettyPrint);
     }
     parent::__construct($content, ResponseHeader::HTTP_OK, $headers);
     $this->setContentType(ResponseHeader::CONTENT_TYPE_JSON);
 }
예제 #5
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());
 }
예제 #6
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;
 }
 /**
  * Destroy the session and Logout the user.
  *
  * @return \Cygnite\Http\Responses\JsonResponse
  */
 public function logoutAction()
 {
     $this->auth->logout(false);
     return Response::json(['status' => true, 'user' => []]);
 }
 /**
  *  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);
 }
예제 #9
0
| 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) {
예제 #10
0
 /**
  * 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);
 }