require_once "app/controllers/login.controller.php"; require_once "app/controllers/ideas.controller.php"; define('APPLICATION', 'Share My Ideas'); define('VERSION', '1.0.0'); define('EXT', '.twig'); use Slim\Slim; use Slim\Extras\Views\Twig as TwigView; use Strong\Strong; use Slim\Extras\Middleware\StrongAuth; $app = new Slim(array('view' => new TwigView())); $dsn = sprintf('mysql:host=%s;dbname=%s', $db[$activeGroup]['hostname'], $db[$activeGroup]['database']); // Authentication $config = array('provider' => 'PDO', 'pdo' => new PDO($dsn, $db[$activeGroup]['username'], $db[$activeGroup]['password']), 'auth.type' => 'form', 'login.url' => '/login', 'security.urls' => array(array('path' => '/comment/'), array('path' => '/api/.+'), array('path' => '/account/'))); $app->add(new StrongAuth($config, new Strong($config))); // Asset Management TwigView::$twigExtensions = array('Twig_Extensions_Slim'); $c = new Application($app); $loginController = new LoginController(); $ideasController = new IdeasController(); // routes $c->app->get('/', array($ideasController, 'index'))->name('home'); $c->app->map('/login/', array($loginController, 'index'))->via('GET', 'POST')->name('login'); $c->app->map('/register/', array($loginController, 'signup'))->via('GET', 'POST')->name('signup'); $c->app->map('/account/', array($loginController, 'profile'))->via('GET', 'POST')->name('profile'); $c->app->map('/account/settings/', array($loginController, 'settings'))->via('GET', 'POST')->name('settings'); $c->app->map('/forgot/', array($loginController, 'forgot'))->via('GET', 'POST')->name('forgot_password'); $c->app->get('/logout/', array($loginController, 'logout'))->name('logout'); $c->app->get('/idea(/:id)', array($ideasController, 'idea'))->name('idea'); $c->app->post('/idea/save', array($ideasController, 'save'))->name('idea_save'); $c->app->get('/ideas/latest', array($ideasController, 'latest'))->name('latest_ideas'); $c->app->get('/ideas/mostrated', array($ideasController, 'mostrated'))->name('mostrated_ideas');
/** * Make Slim app. * @return Slim */ private static function app() { self::requireConstants(['DIRECTUS_ENV', 'APPLICATION_PATH'], __FUNCTION__); $loggerSettings = ['path' => APPLICATION_PATH . '/api/logs']; $app = new Slim(['templates.path' => APPLICATION_PATH . '/api/views/', 'mode' => DIRECTUS_ENV, 'debug' => false, 'log.enable' => true, 'log.writer' => new DateTimeFileWriter($loggerSettings), 'view' => new Twig()]); Twig::$twigExtensions = [new DirectusTwigExtension()]; $app->container->singleton('emitter', function () { return Bootstrap::get('hookEmitter'); }); return $app; }
use Untitled\Middleware\HttpAuthentication; use Untitled\Session; use Slim\Extras\Views\Twig; use Zend\Authentication\AuthenticationService; defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'development'); $config = (require __DIR__ . '/../config.php'); Session::start($config['session']); // Prepare app. $app = new Slim\Slim($config['slim']); $app->configureMode('development', function () { error_reporting(-1); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); }); // Prepare view Twig::$twigOptions = $config['twig']; $app->view(new Twig()); // If you are building a REST API, you may not // care to use cookies. $auth = new AuthenticationService(); $storage = new EncryptedCookie($app); $auth->setStorage($storage); // Set up the Doctrine Entity Manager. $em = \Doctrine\ORM\EntityManager::create(array('driver' => $config['db'][APPLICATION_ENV]['driver'], 'host' => $config['db'][APPLICATION_ENV]['host'], 'port' => $config['db'][APPLICATION_ENV]['port'], 'user' => $config['db'][APPLICATION_ENV]['user'], 'password' => $config['db'][APPLICATION_ENV]['password'], 'dbname' => $config['db'][APPLICATION_ENV]['dbname']), \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration(array(__DIR__ . '/library'), APPLICATION_ENV == 'development', __DIR__ . '/../library/Proxies', new \Doctrine\Common\Cache\ArrayCache())); // Include our required UDFs. require '../src/functions.php'; // Add any middleware. $app->add(new Authentication($auth, $config)); // This function allows us to conditionally call this middleware // only for API requests. function APIRequest()