gonzalo123 / app-service-provider
Silex ServiceProvider to build mobile backends
dev-master / 1.0.x-dev
2015-04-09 18:12 UTC
Requires
- gonzalo123/angularpostrequestserviceprovider: 1.0.*@dev
- silex/silex: 1.3.*@dev
This package is not auto-updated.
Last update: 2024-12-21 18:55:36 UTC
README
SilexService Provider
<?php include __DIR__ . "/../vendor/autoload.php"; use Silex\Application; use G\AppServiceProvider; use G\AngularPostRequestServiceProvider; use G\SecurityIface; class Security implements SecurityIface { public function validateCredentials($user, $pass) { if ($user == 'gonzalo') { $out = [ 'status' => true, 'token' => md5("gonzalo") ]; } else { $out = [ 'status' => false, 'message' => "Not valid credentials" ]; } return $out; } public function getUserFromToken($token) { if (md5("gonzalo") == $token) { return 'gonzalo'; } else { return false; } } } $app = new Application([ 'debug' => true, 'version' => 1, AppServiceProvider::AUTH_MOUNT => '/auth', AppServiceProvider::VALIDATE_CREDENTIALS_ROUTE => '/validateCredentials', ]); $app->register(new AngularPostRequestServiceProvider()); $app->register(new AppServiceProvider(new Security())); $app->get('/hello', function (Application $app) { return $app->json(['Hello']); }); $app->run();