Esempio n. 1
0
 /**
  * Process the application given a request method and URI
  *
  * @param string $requestMethod the request method (e.g. GET, POST, etc.)
  * @param string $requestUri the request URI
  * @param array|object|null $requestData the request data
  * @return \Slim\Http\Response
  */
 public function runApp($requestMethod, $requestUri, $requestData = null)
 {
     // Create a mock environment for testing with
     $environment = Environment::mock(['REQUEST_METHOD' => $requestMethod, 'REQUEST_URI' => $requestUri]);
     // Set up a request object based on the environment
     $request = Request::createFromEnvironment($environment);
     // Add request data, if it exists
     if (isset($requestData)) {
         $request = $request->withParsedBody($requestData);
     }
     // Set up a response object
     $response = new Response();
     // Use the application settings
     $settings = (require __DIR__ . '/../../src/settings.php');
     // Instantiate the application
     $app = new App($settings);
     // Set up dependencies
     require __DIR__ . '/../../src/dependencies.php';
     // Register middleware
     if ($this->withMiddleware) {
         require __DIR__ . '/../../src/middleware.php';
     }
     // Register routes
     require __DIR__ . '/../../src/routes.php';
     // Process the application
     $response = $app->process($request, $response);
     // Return the response
     return $response;
 }
 /**
  * @param SlimApp $slimApp
  * @return SlimRoute
  */
 private function getSlimRouteFromApplication(SlimApp $slimApp)
 {
     $slimRouter = $slimApp->getContainer()->get('router');
     /** @var $slimRouter SlimRouter */
     $slimRoutes = $slimRouter->getRoutes();
     return $slimRoutes['route0'];
 }
Esempio n. 3
0
 public function load(array $settings = [])
 {
     $service = new SlimApp($settings);
     $provider = new ServiceProvider();
     $provider->register($service->getContainer());
     $this->setService($service);
 }
 private function hasRoutesConfigured() : bool
 {
     $slimContainer = $this->slimApp->getContainer();
     $slimRouter = $slimContainer->get('router');
     /** @var $slimRouter SlimRouter */
     return (bool) count($slimRouter->getRoutes());
 }
 public function __construct(App $app)
 {
     $app->group('/periodos', function () {
         $this->get('/actual', RetriveActualAction::class);
         $this->get('/{anio}', RetrivePeriodosDelAnio::class);
     });
 }
Esempio n. 6
0
 public static function register(App $app, $config)
 {
     $app->getContainer()['imagecache'] = function () use($config) {
         return new Manager($config);
     };
     $app->get("/{$config['path_web']}/{$config['path_cache']}/{preset}/{file:.*}", (new ImagecacheRegister())->request())->setName('onigoetz.imagecache');
 }
Esempio n. 7
0
 /**
  * Load the module. This will run for all modules, use for routes mainly
  * @param string $moduleName Module name
  */
 public function initModules(App $app)
 {
     $container = $app->getContainer();
     $this->initDependencies($container);
     $this->initMiddleware($app);
     $this->initRoutes($app);
 }
 public function setUp()
 {
     $app = new App();
     $kernel = new Kernel($app, $app->getContainer());
     $kernel->registerServices();
     $kernel->registerRoutes();
     $this->app = $app;
 }
Esempio n. 9
0
 function __construct(\Slim\App $app, RequestInterface $request, ResponseInterface $response, $args = false)
 {
     $this->app = $app;
     $this->container = $app->getContainer();
     $this->request = $request;
     $this->response = $response;
     $this->args = $args;
 }
 /**
  * @param ResponseInterface $response
  */
 private function renderResponse(ResponseInterface $response)
 {
     if ($this->slim) {
         $this->slim->respond($response);
     } else {
         // do something
     }
 }
Esempio n. 11
0
 public function __construct(\Slim\App $app)
 {
     $this->app = $app;
     $this->view = $app->getContainer()->get('view');
     $this->pdo = $app->getContainer()->get('pdo');
     if (!$this->pdo instanceof PDO) {
         throw new \RuntimeException(sprintf('%s requires a PDO instance, app did not contain "PDO" key', __CLASS__));
     }
 }
Esempio n. 12
0
 public function init(\Slim\App $app)
 {
     $app->group('/categories', function () {
         $this->get('', '\\Controllers\\Categories:index');
         $this->map(['GET', 'POST'], '/created', '\\Controllers\\Categories:created');
         $this->map(['GET', 'POST'], '/edit/{id}', '\\Controllers\\Categories:edit');
         $this->map(['GET', 'POST'], '/delete/{id}', '\\Controllers\\Categories:delete');
     });
 }
Esempio n. 13
0
 public static function Route()
 {
     $app = new App();
     // Reminder: the request is processed from the bottom up,
     // the response is processed from the top down.
     $app->add(SlimMiddleware::class);
     $app->add(Grover::class);
     $app->run();
 }
Esempio n. 14
0
 /**
  * @param String $method
  * @param Uri   $uri
  * @param array $post
  */
 protected function runApp($method, $uri, $post = [])
 {
     $this->buildApp();
     $this->buildRequest($method, $uri, $post);
     $this->app->getContainer()['request'] = $this->request;
     $this->app->getContainer()['response'] = $this->response;
     $this->response = $this->app->run(true);
     $this->response->getBody()->rewind();
     $this->html = $this->response->getBody()->getContents();
 }
Esempio n. 15
0
 public function register(App &$app)
 {
     $app->get('/version', function (Request $request, Response $response) {
         $response->getBody()->write(json_encode("v1.0.0"));
         return $response->withHeader('Access-Control-Allow-Origin', '*');
     });
     $app->options('/version', function (Request $request, Response $response, $args) use(&$self) {
         return $response->withHeader('Access-Control-Allow-Origin', '*')->withHeader('Access-Control-Allow-Headers', 'Content-Type');
     });
 }
Esempio n. 16
0
 public function __construct(App $app)
 {
     $app->group('/empleados/{e_id}/solicitudes_pqr', function () {
         $this->get('', RetriveLastSolicitudPQRAction::class);
         $this->post('', CreateNewSolicitudPQRAction::class);
         $this->delete('/{pqr_id}', DeleteSolicitudPQRAction::class);
         $this->post('/{pqr_id}/respuesta', ResponderSolicitudPQRAction::class);
     });
     $app->get('/solicitudes_pqr', RetriveSolicitudesPQRAction::class);
     $app->get('/solicitudes_pqr/{pqr_id}', RetriveOneSolicitudPQRAction::class);
 }
Esempio n. 17
0
 public function __construct(App $app)
 {
     $app->group('/empleados', function () {
         $this->get('/syncup', SyncUP::class);
         $this->get('[/]', RetriveAction::class);
         $this->get('/{e_id}', RetriveAction::class);
         //$this->get('/certificado_laboral/{crt_id}', GenerateCertificadoAction::class);
         $this->get('/{e_id}/certificado_laboral/{tipo_crt}', GenerateCertificadoAction::class);
         #$this->get('/{e_id}', RetriveAction::class);
     });
 }
Esempio n. 18
0
 /**
  * @param \swoole_http_request $request
  * @param \swoole_http_response $response
  * @throws \Exception
  */
 public function __invoke($request, $response)
 {
     $this->app->getContainer()['environment'] = $this->app->getContainer()->factory(function () {
         return new Environment($_SERVER);
     });
     $this->app->getContainer()['request'] = $this->app->getContainer()->factory(function ($container) {
         return Request::createFromEnvironment($container['environment']);
     });
     $this->app->getContainer()['response'] = $this->app->getContainer()->factory(function ($container) {
         $headers = new Headers(['Content-Type' => 'text/html']);
         $response = new Response(200, $headers);
         return $response->withProtocolVersion($container->get('settings')['httpVersion']);
     });
     /**
      * @var ResponseInterface $appResponse
      */
     $appResponse = $this->app->run(true);
     // set http header
     foreach ($appResponse->getHeaders() as $key => $value) {
         $filter_header = function ($header) {
             $filtered = str_replace('-', ' ', $header);
             $filtered = ucwords($filtered);
             return str_replace(' ', '-', $filtered);
         };
         $name = $filter_header($key);
         foreach ($value as $v) {
             $response->header($name, $v);
         }
     }
     // set http status
     $response->status($appResponse->getStatusCode());
     // send response to browser
     if (!$this->isEmptyResponse($appResponse)) {
         $body = $appResponse->getBody();
         if ($body->isSeekable()) {
             $body->rewind();
         }
         $settings = $this->app->getContainer()->get('settings');
         $chunkSize = $settings['responseChunkSize'];
         $contentLength = $appResponse->getHeaderLine('Content-Length');
         if (!$contentLength) {
             $contentLength = $body->getSize();
         }
         $totalChunks = ceil($contentLength / $chunkSize);
         $lastChunkSize = $contentLength % $chunkSize;
         $currentChunk = 0;
         while (!$body->eof() && $currentChunk < $totalChunks) {
             if (++$currentChunk == $totalChunks && $lastChunkSize > 0) {
                 $chunkSize = $lastChunkSize;
             }
             $response->write($body->read($chunkSize));
             if (connection_status() != CONNECTION_NORMAL) {
                 break;
             }
         }
         $response->end();
     }
 }
Esempio n. 19
0
 public function newApp()
 {
     // config
     $debug = false;
     if (defined("DEBUG")) {
         $debug = true;
     }
     // Make a Slim App
     $app = new App(['settings' => ['debug' => $debug, 'whoops.editor' => 'sublime']]);
     $app->add(new WhoopsMiddleware());
     $this->app = $app;
 }
Esempio n. 20
0
 public function registerRoute(Slim $app)
 {
     $data = $this->getInfo();
     $app->group($data['path'], function () use($data) {
         $this->get('', $data['handle'] . ':index')->setName('list.' . $data['name']);
         $this->get('/add', $data['handle'] . ':add')->setName('add.' . $data['name']);
         $this->get('/edit/{id:\\d+}', $data['handle'] . ':edit')->setName('edit.' . $data['name']);
         $this->map(['PUT', 'POST'], '/add', $data['handle'] . ':doAdd')->setName('store.' . $data['name']);
         $this->map(['PUT', 'POST'], '/edit', $data['handle'] . ':doEdit')->setName('save.' . $data['name']);
         $this->map(['DELETE', 'POST'], '/delete/{id:\\d+}', $data['handle'] . ':doDelete')->setName('delete.' . $data['name']);
     });
 }
Esempio n. 21
0
 public static function init(\Slim\App $app)
 {
     error_reporting(E_ALL);
     ini_set('display_errors', true);
     date_default_timezone_set('Asia/Shanghai');
     $container = $app->getContainer();
     $settings = $container->get('settings');
     $settings['displayErrorDetails'] = true;
     $settings['core.baseNamespace'] = 'Application';
     $settings['view.basePath'] = __DIR__;
     return parent::init($app);
 }
Esempio n. 22
0
 /**
  * Test extend single routes.
  */
 public function testExtendSingle()
 {
     $this->assertCount(0, $this->slim_app->getContainer()->get('router')->getRoutes());
     $this->model_router->mapModel('App\\Model\\User', null, null, function (Extender $extender) {
         $extender->extend('accounts');
     });
     $this->assertCount(3, $this->slim_app->getContainer()->get('router')->getRoutes());
     /** @var Route $user_accounts_route */
     $user_accounts_route = $this->slim_app->getContainer()->get('router')->getRoutes()['route2'];
     $this->assertEquals(['GET'], $user_accounts_route->getMethods());
     $this->assertEquals('user_accounts', $user_accounts_route->getName());
 }
Esempio n. 23
0
 public function bootstrap()
 {
     // Load configuration files into ConfigRepository
     $config = new ConfigRepository(base_path() . '/config');
     // Initialize container for dependency injection
     $container = $this->initContainer($config);
     // Instantiate Slim
     $slim = new Slim($container);
     // Load routes into Slim router
     $this->initRoutes($config, $container, $slim->router);
     // Run app
     $slim->run();
 }
Esempio n. 24
0
 protected function dispatchApplication(array $server, array $pipe = [])
 {
     $app = new App();
     $app->getContainer()['environment'] = function () use($server) {
         return new Environment($server);
     };
     $middlewareFactory = new PhpDebugBarMiddlewareFactory();
     $middleware = $middlewareFactory();
     $app->add($middleware);
     foreach ($pipe as $pattern => $middleware) {
         $app->get($pattern, $middleware);
     }
     return $app->run(true);
 }
Esempio n. 25
0
 private function setSlimRules($rules)
 {
     foreach ($rules as $controllers) {
         if (isset($controllers['groups'])) {
             $this->slim->group($controllers['pattern'], function () use($controllers) {
                 foreach ($controllers['groups'] as $controller) {
                     $this->map($controller['methods'], $controller['pattern'], $controller['action'])->setName($controller['name']);
                 }
             });
         } else {
             $this->slim->map($controllers['methods'], $controllers['pattern'], $controllers['action'])->setName($controllers['name']);
         }
     }
 }
Esempio n. 26
0
 protected function setRouteForPostTypes($postType, $defaultController)
 {
     $controllerPageMapping = $this->app->getContainer()->get(ControllerPageMappingField::class);
     /**
      * @FIXME: In future versions, need to change
      * adding routes to the map of get|post. All WP PAGES and POSTS must
      * coresponds to only GET method. Because it is has content only for reading.
      * All other logic like writing or another logic should be implemented in WIDGETS
      * or in controllers via declarring new routes and handlers for them.
      */
     foreach ($this->wpService->get_posts(['numberposts' => -1, 'post_type' => $postType]) as $post) {
         $controller = $controllerPageMapping->getValue($post->ID);
         $this->app->map(['get', 'post'], parse_url(get_permalink($post), PHP_URL_PATH), $this->app->getContainer()->get(empty($controller) ? $defaultController : $controller))->setArgument('requestedEntity', $post);
     }
 }
Esempio n. 27
0
 /**
  * Register DebugBar service.
  *
  * @param  App $app
  *
  * @return void
  */
 public function register(App $app)
 {
     $container = $app->getContainer();
     $container['debugbar'] = function ($container) {
         return new SlimDebugBar($container, $this->settings);
     };
     if (!$this->settings['enabled']) {
         return;
     }
     $app->group('/_debugbar', function () {
         $this->get('/open', 'Kitchenu\\Debugbar\\Controllers\\OpenHandlerController:handle')->setName('debugbar-openhandler');
         $this->get('/assets/stylesheets', 'Kitchenu\\Debugbar\\Controllers\\AssetController:css')->setName('debugbar-assets-css');
         $this->get('/assets/javascript', 'Kitchenu\\Debugbar\\Controllers\\AssetController:js')->setName('debugbar-assets-js');
     });
     $app->add(new Debugbar($container['debugbar'], $container['errorHandler']));
 }
Esempio n. 28
0
 public function __construct()
 {
     $containerBuilder = new ContainerBuilder();
     $containerBuilder->addDefinitions(__DIR__ . '/config.php');
     $container = $containerBuilder->build();
     parent::__construct($container);
 }
Esempio n. 29
0
 /**
  *
  * @param array $routes
  * @param unknown $options
  */
 public function __construct(array $routes, $options = null)
 {
     parent::__construct($options);
     $this->container = $this->getContainer();
     $this->_routes = $routes;
     $this->resolve();
 }
Esempio n. 30
0
 /**
  * Shiniwork constructor.
  *
  * @param array $settings
  */
 public function __construct(array $settings = [])
 {
     session_start();
     $container = new Settings($settings);
     parent::__construct($container);
     $this->registerView()->registerDatabase()->registerMailer()->registerJWT()->addJWTMiddleware();
 }