Ejemplo n.º 1
1
 public static function init()
 {
     $app = new \Slim\Slim();
     $app->setName(Application::InstanceName());
     if (strpos($app->request()->getPath(), Application::BasePath()) === 0) {
         Doc::createInstance($app);
         Posts::createInstance($app);
         $app->run();
         exit;
     }
 }
Ejemplo n.º 2
0
 public function testAdminNavigation()
 {
     \Slim\Environment::mock(array('SCRIPT_NAME' => '', 'PATH_INFO' => '/admin'));
     $app = new \Slim\Slim();
     $app->view(new \Slim\View());
     $app->get('/admin', function () {
         echo 'Success';
     });
     $auththenticationService = $this->getMock('Zend\\Authentication\\AuthenticationService');
     $auththenticationService->expects($this->once())->method('hasIdentity')->will($this->returnValue(true));
     $mw = new Navigation($auththenticationService);
     $mw->setApplication($app);
     $mw->setNextMiddleware($app);
     $mw->call();
     $response = $app->response();
     $navigation = $app->view()->getData('navigation');
     $this->assertNotNull($navigation);
     $this->assertInternalType('array', $navigation);
     $this->assertEquals(4, count($navigation));
     $this->assertEquals('Home', $navigation[0]['caption']);
     $this->assertEquals('/', $navigation[0]['href']);
     $this->assertEquals('', $navigation[0]['class']);
     $this->assertEquals('Admin', $navigation[1]['caption']);
     $this->assertEquals('/admin', $navigation[1]['href']);
     $this->assertEquals('active', $navigation[1]['class']);
     $this->assertEquals('Settings', $navigation[2]['caption']);
     $this->assertEquals('/admin/settings', $navigation[2]['href']);
     $this->assertEquals('', $navigation[2]['class']);
     $this->assertEquals('Logout', $navigation[3]['caption']);
     $this->assertEquals('/logout', $navigation[3]['href']);
     $this->assertEquals('', $navigation[3]['class']);
 }
Ejemplo n.º 3
0
 public function testMergeImports()
 {
     $app = new \Slim\Slim();
     $data = array('item-a' => 'Item A', 'item-1' => 'Item 1', 'item-2' => 'Item 2', 'item-3' => 'Item 3');
     Yaml::_()->addFile(dirname(__FILE__) . '/fixtures/merge1.yml');
     $this->assertEquals($data, $app->config('items'));
 }
Ejemplo n.º 4
0
 public function testEscapedParameters()
 {
     $app = new \Slim\Slim();
     $data = array('%Item 1%', 'Item 2', 'Item 3');
     Yaml::_()->addParameters(array('item2' => 'Item 2'))->addFile(dirname(__FILE__) . '/fixtures/escape.yml');
     $this->assertEquals($data, $app->config('items'));
 }
Ejemplo n.º 5
0
function autenticar1()
{
    $app = new \Slim\Slim();
    $request = $app->request();
    echo json_decode($request->getBody());
    //var_dump($user);
}
Ejemplo n.º 6
0
 /**
  * Executa
  * @return null
  */
 static function run()
 {
     // Autoload baseado nos módulos carregados
     /*spl_autoload_register(function($className) {
     			$className = ltrim($className, '\\');
     			$fileName  = '';
     			$namespace = '';
     			if ($lastNsPos = strrpos($className, '\\')) {
     				$namespace = substr($className, 0, $lastNsPos);
     				$className = substr($className, $lastNsPos + 1);
     				$fileName  = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
     			}
     			$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
     			require $fileName;
     		});*/
     // Instanciando Slim
     //require __ROOT__ . '/vendor/slim/slim/Slim/Slim.php';
     //\Slim\Slim::registerAutoloader();
     $app = new \Slim\Slim();
     // Incluindo arquivos que devem vir antes dos routes
     foreach (self::$modules as $mod) {
         @(include "{$mod}/config.php");
         @(include "{$mod}/helpers.php");
         @(include "{$mod}/filter.php");
     }
     // Incluindo os routes
     foreach (self::$modules as $mod) {
         @(include "{$mod}/routes.php");
     }
     // Renderizando tudo
     $app->run();
 }
Ejemplo n.º 7
0
 /**
  * 
  * @return array ['status', 'headers', 'body']
  */
 protected function _getResponse($envArgs)
 {
     \Slim\Environment::mock($envArgs);
     $app = new \Slim\Slim();
     new \Voce\Thermal\v1\API($app);
     $app->call();
     return $app->response()->finalize();
 }
Ejemplo n.º 8
0
function addUser()
{
    $app = new \Slim\Slim();
    $request = $app->request();
    $data = json_decode($request->getBody(), true);
    $user = User::create($data);
    $user->save();
}
Ejemplo n.º 9
0
 public function dispatch_api()
 {
     require_once 'lib/jsonp/jsonp.php';
     \Slim\Slim::registerAutoloader();
     $app = new \Slim\Slim();
     new \Voce\Thermal\v1\API($app);
     $app->run();
     exit;
 }
Ejemplo n.º 10
0
 function getSubmit(Slim\Slim $_app, $key)
 {
     $ret = null;
     $data = get_object_vars(json_decode($_app->request()->getBody()));
     if (isset($data[$key])) {
         $ret = get_object_vars($data[$key]);
     }
     return $ret;
 }
Ejemplo n.º 11
0
 /**
  * Check if the provided $user_id matches the logged-in user.
  *
  * @param mixed $user_id The user id.
  *
  * @return bool true if it's the logged in user, false otherwise.
  */
 public function checkUserId($user_id)
 {
     if (!isset($_SESSION) || $user_id != $_SESSION['user_id']) {
         $this->app->response()->status(403);
         $this->app->response()->write("Wrong user_id");
         return false;
     }
     return true;
 }
Ejemplo n.º 12
0
function authorize()
{
    return function () {
        $app = new \Slim\Slim();
        if (empty($_SESSION['user'])) {
            $app->halt(401, 'You shall not pass!');
        }
    };
}
Ejemplo n.º 13
0
function editUser()
{
    $app = new \Slim\Slim();
    $request = $app->request();
    $data = json_decode($request->getBody());
    $user = User::find($data->id);
    $user->username = $data->username;
    $user->fullname = $data->fullname;
    $user->save();
}
Ejemplo n.º 14
0
 /**
  * @dataProvider authenticationDataProvider
  */
 public function testRouteAuthentication($requestMethod, $path, $location, $hasIdentity, $identity, $httpStatus)
 {
     \Slim\Environment::mock(array('REQUEST_METHOD' => $requestMethod, 'PATH_INFO' => $path));
     $this->auth->expects($this->once())->method('hasIdentity')->will($this->returnValue($hasIdentity));
     $this->auth->expects($this->once())->method('getIdentity')->will($this->returnValue($identity));
     $app = new \Slim\Slim(array('debug' => false));
     $app->error(function (\Exception $e) use($app) {
         // Example of handling Auth Exceptions
         if ($e instanceof AuthException) {
             $app->response->setStatus($e->getCode());
             $app->response->setBody($e->getMessage());
         }
     });
     $app->get('/', function () {
     });
     $app->get('/member', function () {
     });
     $app->delete('/member/photo/:id', function ($id) {
     });
     $app->get('/admin', function () {
     });
     $app->map('/login', function () {
     })->via('GET', 'POST')->name('login');
     $app->add($this->middleware);
     ob_start();
     $app->run();
     ob_end_clean();
     $this->assertEquals($httpStatus, $app->response->status());
     $this->assertEquals($location, $app->response->header('location'));
 }
 public function testBestFormatWithPriorities()
 {
     \Slim\Environment::mock(array('ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'negotiation.priorities' => array('xml')));
     $s = new \Slim\Slim();
     $s->add(new ContentNegotiation());
     $s->run();
     $env = \Slim\Environment::getInstance();
     $bestFormat = $env['request.best_format'];
     $this->assertNotNull($bestFormat);
     $this->assertEquals('xml', $bestFormat);
 }
Ejemplo n.º 16
0
 public function getCookie(Slim\Slim &$app)
 {
     if (empty($app->getCookie('username'))) {
         //setting cokkie if the user doesn't have it
         $generateToken = new Token();
         $cookieKey = md5($generateToken->generatePassword(8));
         $app->setCookie('username', $cookieKey, time() + 86400 * 4);
     }
     $cookie = $app->getCookie('username');
     return $cookie;
 }
Ejemplo n.º 17
0
 public static function start()
 {
     self::bootstrapErrorReporting();
     $app = new \Slim\Slim();
     self::bootstrapLogs();
     self::bootstrapSession();
     self::bootstrapDatabase();
     self::bootstrapViews();
     self::bootstrapRouting();
     return $app->run();
 }
Ejemplo n.º 18
0
 function init()
 {
     if (strstr($_SERVER['REQUEST_URI'], 'api/')) {
         define('SHORTINIT', true);
         $app = new \Slim\Slim();
         $app->setName('wp-elastic-api');
         new DocRoutes($app);
         new v1\Routes($app);
         $app->run();
         exit;
     }
 }
Ejemplo n.º 19
0
 /**
  * Test Language middleware with Accept-Language header
  */
 public function testLanguageHeader()
 {
     \Slim\Environment::mock(array('HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.8,es;q=0.6'));
     $app = new \Slim\Slim(array());
     $app->get('/', function () {
     });
     $mw = new \Mnlg\Middleware\Language();
     $mw->setApplication($app);
     $mw->setNextMiddleware($app);
     $mw->call();
     $this->assertEquals($app->acceptLanguages, array('en-US' => 1.0, 'en' => 0.8, 'es' => 0.6));
 }
Ejemplo n.º 20
0
function initialize()
{
    $app = new \Slim\Slim(array('mode' => 'production'));
    // Only invoked if mode is "production"
    $app->configureMode('production', function () use($app) {
        $app->config(array('log.enable' => false, 'debug' => false, 'config.path' => '../config/prod/'));
    });
    // Only invoked if mode is "development"
    $app->configureMode('development', function () use($app) {
        $app->config(array('log.enable' => false, 'debug' => true, 'config.path' => '../config/dev/'));
    });
}
Ejemplo n.º 21
0
 public function getSlimInstance()
 {
     $capsule = new Illuminate\Database\Capsule\Manager();
     $capsule->addConnection(['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '']);
     $capsule->setEventDispatcher(new Illuminate\Events\Dispatcher());
     $capsule->setAsGlobal();
     $capsule->bootEloquent();
     require __DIR__ . '/../app/schema.php';
     $app = new \Slim\Slim(['debug' => false, 'mode' => 'testing', 'templates.path' => __DIR__ . '/../views']);
     $app->setName('default');
     require __DIR__ . '/../app/app.php';
     return $app;
 }
Ejemplo n.º 22
0
 /**
  * @param array $config
  * @return \Slim\Slim
  */
 public function dispatch($config)
 {
     \Slim\Environment::mock(array('REQUEST_METHOD' => 'HEAD', 'PATH_INFO' => '/'));
     $config['debug'] = false;
     // ignore pretty exceptions
     $slim = new \Slim\Slim($config);
     $manager = new \Slim\Middleware\SessionManager($slim);
     $manager->setDbConnection($this->capsule->getConnection());
     $session = new \Slim\Middleware\Session($manager);
     $slim->add($session);
     $slim->run();
     return $slim;
 }
Ejemplo n.º 23
0
 public function request($method, $path, $options = array())
 {
     // Capture STDOUT
     ob_start();
     // Prepare a mock environment
     Environment::mock(array_merge(array('REQUEST_METHOD' => $method, 'PATH_INFO' => $path, 'SERVER_NAME' => 'slim-test.dev'), $options));
     $app = new \Slim\Slim();
     $this->app = $app;
     $this->request = $app->request();
     $this->response = $app->response();
     // Return STDOUT
     return ob_get_clean();
 }
Ejemplo n.º 24
0
 public function testVisitAdminPageLoggedInSucceeds()
 {
     \Slim\Environment::mock(array('SCRIPT_NAME' => '/index.php', 'PATH_INFO' => '/admin'));
     $app = new \Slim\Slim();
     $app->get('/admin', function () {
         echo 'Success';
     });
     $this->auththenticationService->expects($this->once())->method('hasIdentity')->will($this->returnValue(true));
     $this->middleware->setApplication($app);
     $this->middleware->setNextMiddleware($app);
     $this->middleware->call();
     $response = $app->response();
     $this->assertTrue($response->isOk());
 }
 public function testSetEditor()
 {
     \Slim\Environment::mock(array('SCRIPT_NAME' => '/index.php', 'PATH_INFO' => '/foo'));
     $app = new \Slim\Slim();
     $app->config('whoops.editor', 'sublime');
     $app->get('/foo', function () {
         echo "It is work";
     });
     $middleware = new WhoopsMiddleware();
     $middleware->setApplication($app);
     $middleware->setNextMiddleware($app);
     $middleware->call();
     $this->assertEquals('subl://open?url=file://test_path&line=168', $app->whoopsPrettyPageHandler->getEditorHref('test_path', 168));
 }
Ejemplo n.º 26
0
 /**
  * Verify basic behavior of __invoke()
  *
  * @test
  * @covers ::__invoke
  *
  * @return void
  */
 public function invoke()
 {
     $storage = new \OAuth2\Storage\Memory(['client_credentials' => ['testClientId' => ['client_id' => 'testClientId', 'client_secret' => 'testClientSecret']]]);
     $server = new \OAuth2\Server($storage, ['access_lifetime' => 3600], [new \OAuth2\GrantType\ClientCredentials($storage)]);
     $json = json_encode(['client_id' => 'testClientId', 'client_secret' => 'testClientSecret', 'grant_type' => 'client_credentials']);
     \Slim\Environment::mock(['REQUEST_METHOD' => 'POST', 'CONTENT_TYPE' => 'application/json', 'PATH_INFO' => '/token', 'CONTENT_LENGTH' => strlen($json), 'slim.input' => $json]);
     $slim = new \Slim\Slim();
     $slim->post('/token', new Token($slim, $server));
     ob_start();
     $slim->run();
     ob_get_clean();
     $this->assertSame(200, $slim->response->status());
     $actual = json_decode($slim->response->getBody(), true);
     $this->assertSame(['access_token' => $actual['access_token'], 'expires_in' => 3600, 'token_type' => 'Bearer', 'scope' => null], $actual);
 }
Ejemplo n.º 27
0
 /**
  * Test maintenance middleware when 'maintenance' mode is enabled with a custom callable
  */
 public function testMaintenanceEnabledCustomCallable()
 {
     \Slim\Environment::mock(array('SCRIPT_NAME' => '/index.php', 'PATH_INFO' => '/'));
     $app = new \Slim\Slim(array('mode' => 'maintenance'));
     $app->get('/', function () {
         echo "Success";
     });
     $mw = new \Mnlg\Middleware\Maintenance(function () use($app) {
         $app->response()->body('Maintenance');
     });
     $mw->setApplication($app);
     $mw->setNextMiddleware($app);
     $mw->call();
     $this->assertEquals(200, $app->response()->status());
     $this->assertEquals('Maintenance', $app->response()->body());
 }
Ejemplo n.º 28
0
 public function getLinkAttribute()
 {
     $name = 'shw' . substr($this->attributes['contenible_type'], 0, 7);
     $attr = ['id' . substr($this->attributes['contenible_type'], 0, 3) => $this->attributes['contenible_id']];
     $app = Slim\Slim::getInstance();
     return $app->request->getUrl() . $app->urlFor($name, $attr);
 }
Ejemplo n.º 29
0
 /**
  * @param SlimWebServiceRegistryCategory $category
  */
 public function AddCategory(SlimWebServiceRegistryCategory $category)
 {
     foreach ($category->Gets() as $registration) {
         $this->slim->get($registration->Route(), $registration->Callback())->name($registration->RouteName());
         $this->SecureRegistration($registration);
     }
     foreach ($category->Posts() as $registration) {
         $this->slim->post($registration->Route(), $registration->Callback())->name($registration->RouteName());
         $this->SecureRegistration($registration);
     }
     foreach ($category->Deletes() as $registration) {
         $this->slim->delete($registration->Route(), $registration->Callback())->name($registration->RouteName());
         $this->SecureRegistration($registration);
     }
     $this->categories[] = $category;
 }
Ejemplo n.º 30
-1
 public function testAddFile()
 {
     $app = new \Slim\Slim();
     $data = array('item1', 'item2');
     Yaml::_()->addFile(dirname(__FILE__) . '/fixtures/index.yml');
     $this->assertEquals($data, $app->config('items'));
 }