Exemplo n.º 1
0
 public function getSlimInstance()
 {
     $app = new \Slim\Slim(array('version' => '0.0.0', 'debug' => false, 'mode' => 'testing', 'view' => new \Slim\Views\Twig(), 'templates.path' => ROOT_PATH . '/resources/views'));
     // Set options
     $view = $app->view();
     $view->parserOptions = array('debug' => false, 'cache' => ROOT_PATH . '/storage/views');
     // force to overwrite the App singleton, so that \Slim\Slim::getInstance()
     // returns the correct instance.
     $app->setName('default');
     return $app;
 }
<?php

require_once 'vendor/autoload.php';
use Slim\Slim;
use Slim\Extras\Middleware\CsrfGuard;
$directory = get_template_directory() . "/app";
$assets = get_template_directory_uri();
$loader = new Twig_Loader_Filesystem($directory);
$twig = new Twig_Environment($loader);
$twig->addExtension(new Twig_Extensions_Extension_I18n());
// here I can use MongoDB if i want to. very flexible.
$mongo = new MongoClient("mongodb://localhost/?journal=true&w=1&wTimeoutMS=20000");
$mongodb = $mongo->react_blog;
$MongoUser = $mongodb->users;
$app = new \Slim\Slim();
$app->add(new \Slim\Middleware\SessionCookie(array('expires' => '20 minutes', 'path' => '/', 'domain' => null, 'secure' => false, 'httponly' => false, 'name' => 'slimblog_dev_session', 'secret' => 'YOU_ARE_SUCH_A_COOL_KID', 'cipher' => MCRYPT_RIJNDAEL_256, 'cipher_mode' => MCRYPT_MODE_CBC, 'date.timezone' => 'UTC')));
$app->add(new CsrfGuard());
$app->get('/', function () use($app, $twig, $assets) {
    $data = array('user' => 'testuser', 'test' => 'hahahahha', 'static_url' => $assets);
    if (isset($_SESSION['app_id'])) {
        echo $twig->render('views/index.php', $data);
    } else {
        echo "You gonna login first";
    }
});
$app->get('/app', function () use($app, $twig, $assets) {
    $data = array('user' => 'testuser', 'test' => 'hahahahha', 'static_url' => $assets);
    if (isset($_SESSION['app_id'])) {
        echo $twig->render('views/index.php', $data);
    } else {
        echo "You gonna login first bro";
Exemplo n.º 3
0
<?php

require_once 'vendor/autoload.php';
require 'Orm/NotORM.php';
use Slim\Slim;
// Register autoloader and instantiate Slim
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
// Database Configuration
$dbhost = 'localhost';
$dbuser = '******';
$dbpass = '******';
// $dbname = 'naiemoji';
$dbname = 'testorm';
$dbmethod = 'mysql:dbname=';
$dsn = $dbmethod . $dbname;
$pdo = new PDO($dsn, $dbuser, $dbpass);
$db = new NotORM($pdo);
// Home Route
$app->get('/', function () use($app) {
    $app->response->setStatus(200);
    $app->render('../templates/homepage.html');
});
// Register a user
$app->post('/register', function () use($app, $db) {
    $app->response()->header('Content-Type', 'application/json');
    $name = $app->request()->post('name');
    $email = $app->request()->post('email');
    $password = $app->request()->post('password');
    $passwordEncryption = md5($password);
    if ($email === $db->users()->where('email', $email)->fetch('email')) {
$collection->attachRoute(new Route('/openMaps', array('_controller' => 'MapsController::openMapsView', 'methods' => 'GET')));
$collection->attachRoute(new Route('/listTotalRevenue', array('_controller' => 'PaymentController::listTotalRevenueView', 'methods' => 'GET')));
$collection->attachRoute(new Route('/calendar', array('_controller' => 'PaymentController::listPaymentsOnCalendarView', 'methods' => 'GET')));
$collection->attachRoute(new Route('/calendar/:dni/:year', array('_controller' => 'PaymentController::listPaymentsOnCalendarView', 'methods' => 'GET')));
$collection->attachRoute(new Route('/calendarAction', array('_controller' => 'PaymentController::listPaymentsOnCalendarAction', 'methods' => 'POST')));
$router = new Router($collection);
$router->setBasePath('/');
$route = $router->matchCurrentRequest();
// Vamos a usar el PHPRouter para todas las rutas relacionadas a la pagina de la escuela,
// y Slim para todas las rutas de la api REST.
// Asique si al llegar una ruta vemos que no pertenece al mapeo de PHPRouter, usamos slim.
if ($route) {
    AuthController::checkPermission($route->getAction());
    $route->dispatch();
} else {
    $slimApp = new \Slim\Slim();
    // Retorna un arreglo asociativo con las claves "por_pagar" y "pagas".
    // Cada arreglo dentro de esas 2 cosas contiene los datos de un alumno
    // http://localhost/cuotasImpagasYPorPagarDe/21/year/2016   << este tiene datos cargados para ver
    $slimApp->get('/cuotasImpagasYPorPagarDe/:studentID/year/:year', function ($studentID, $year) {
        FeeService::listPaidAndToBePaidFeesOfStudentInYear($studentID, $year);
    });
    // Devuelve un arreglo de 12 posiciones, cada posicion representa un mes, y contiene la cantidad de ingresos
    // en ese mes.
    $slimApp->get('/ingresosTotalesEn/:year', function ($year) {
        RevenueService::totalRevenueByMonthInYear($year);
    });
    $slimApp->get('/getUsersPosition', function () {
        //$positions = [[-57.9749, -34.9205], [-57.9799, -34.9305]];
        //echo json_encode($positions);
        StudentService::getStudentsPositions();
Exemplo n.º 5
0
<?php

require "vendor/autoload.php";
use Slim\Slim;
use Slim\Extras\Views\Twig;
$log = new Monolog\Logger('log');
$log->pushHandler(new Monolog\Handler\StreamHandler('log/wol.log', Monolog\Logger::INFO));
$app = new \Slim\Slim(['view' => new Twig(), 'templates.path' => 'template']);
//
// request
//
$app->get("/", function () use($app, $log) {
    require_once 'app/models/WakeUpLanManager.php';
    $wol = new WakeUpLanManager($log);
    echo $app->render('index.html', ['wol_list' => $wol->getWolJson()]);
});
$app->get("/wakeup/:id", function ($id) use($app, $log) {
    $log->info('START');
    require_once 'app/models/WakeUpLanManager.php';
    $wol = new WakeUpLanManager($log);
    // WOL実行
    $result = $wol->postWol($id, $wol->getWolJson());
    $app->response->headers->set('Content-Type', 'application/json');
    $app->response->setBody(json_encode(['result' => 'ok']));
});
$app->get("/ping/:id", function ($id = null) use($app, $log) {
    $log->info('START');
    require_once 'app/models/WakeUpLanManager.php';
    $wol = new WakeUpLanManager($log);
    /// ping チェック
    if (empty($id)) {
Exemplo n.º 6
0
</head>
<body>
<h1>SlimAuth - AccessControlManager class test page</h1>

<?php 
require __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
use Slim\Slim;
use BenGee\Slim\Db\SlimORM;
use BenGee\Slim\Auth\AccessControlManager;
use BenGee\Slim\Auth\RouteControlRule;
try {
    // ===========================
    // ====== INITIALISATION =====
    // ===========================
    $config = array(SlimORM::CONNECTIONS => array(SlimORM::DEFAULT_CNX => array(SlimORM::DSN => 'mysql:host=localhost;port=3306;dbname=slim', SlimORM::USR => 'root', SlimORM::PWD => 'rootsdev', SlimORM::OPT => null)), 'debug' => false);
    $app = new \Slim\Slim($config);
    $app->error(function (\Exception $e) use($app) {
        throw $e;
    });
    SlimORM::register($app);
    AccessControlManager::register($app);
    $app->auth->enableRouteControl(true);
    // ==========================
    // ===== PAGE D'ACCUEIL =====
    // ==========================
    $app->map('/', function () use($app) {
        if ($app->auth->isRouteControlEnabled()) {
            ?>
			<fieldset>
				<legend>Test links to check route access control</legend>
				<p><a href="access_all">All</a> : This page should be accessible to anybody !</p>
Exemplo n.º 7
0
<?php

define('BASE_DIR', __DIR__ . "/..");
use Slim\Slim;
// Load php configuration file
require BASE_DIR . '/config/settings.php';
// Initialize the autoloader
require BASE_DIR . '/vendor/autoload.php';
// Setup custom Twig view
$twigView = new \Slim\Views\Twig();
// Initialize the app
$app = new \Slim\Slim(array('debug' => true, 'view' => $twigView, 'templates.path' => BASE_DIR . '/app/views'));
// Automatically *ALL* load router files
$routers = glob(BASE_DIR . '/app/routers/*.router.php');
foreach ($routers as $router) {
    require $router;
}
// Run the app
$app->run();
Exemplo n.º 8
0
<?php

require_once dirname(dirname(__FILE__)) . '/vendor/autoload.php';
use Slim\Slim;
use Slim\LogWriter;
use Config\Database\DbHandler;
use Config\SecureSessionHandler;
\Slim\Slim::registerAutoloader();
$_ENV['SLIM_MODE'] = APP_ENV;
$app = new \Slim\Slim();
$app->setName('BBC_API');
// Only invoked if mode is "production"
$app->configureMode('production', function () use($app) {
    $app->config(array('log.enable' => true, 'debug' => false));
    $handle = fopen('debug.log', 'w');
    $app->log->setWriter(new \Slim\LogWriter($handle));
});
// Only invoked if mode is "development"
$app->configureMode('development', function () use($app) {
    $app->config(array('log.enable' => false, 'debug' => true));
});
/**
 * Perform an API get status
 * This is not much than a ping on the API server
 */
$app->get('/status', function () {
    $response['status'] = 'ok';
    echoRespnse(200, $response);
    exit;
});
/**
Exemplo n.º 9
0
<?php

require_once dirname(__FILE__) . '/vendor/autoload.php';
use Slim\Slim;
use Slim\LogWriter;
use Config\Database\DbHandler;
use Config\SecureSessionHandler;
\Slim\Slim::registerAutoloader();
$_ENV['SLIM_MODE'] = APP_ENV;
$app = new \Slim\Slim();
$app->setName('LQ_API');
// Only invoked if mode is "production"
$app->configureMode('production', function () use($app) {
    $app->config(array('log.enable' => true, 'debug' => false));
    $handle = fopen('debug.log', 'w');
    $app->log->setWriter(new \Slim\LogWriter($handle));
});
// Only invoked if mode is "development"
$app->configureMode('development', function () use($app) {
    $app->config(array('log.enable' => false, 'debug' => true));
});
/**
 * Perform an API get status
 * This is not much than a ping on the API server
 */
$app->get('/status', function () {
    $response['status'] = 'ok';
    echoRespnse(200, $response);
    exit;
});
/**
Exemplo n.º 10
0
use Flynsarmy\SlimMonolog\Log\MonologWriter;
// Init application mode
if (empty($_ENV['SLIM_MODE'])) {
    $_ENV['SLIM_MODE'] = getenv('SLIM_MODE') ? getenv('SLIM_MODE') : 'production';
}
// Init and load configuration
$config = array();
$configFile = dirname(__FILE__) . '/share/config/' . $_ENV['SLIM_MODE'] . '.php';
if (is_readable($configFile)) {
    require_once $configFile;
} else {
    require_once dirname(__FILE__) . '/share/config/default.php';
}
// Create Application
$logger = new \Flynsarmy\SlimMonolog\Log\MonologWriter(array('handlers' => array(new \Monolog\Handler\StreamHandler('../logs/' . date('Y-m-d') . '.log'))));
$app = new \Slim\Slim(array('log.writer' => $logger, 'mode' => 'production'));
// Only invoked if mode is "production"
$app->configureMode('production', function () use($app) {
    $app->config(array('log.enable' => true, 'log.level' => \Slim\Log::WARN, 'debug' => false));
});
// Only invoked if mode is "development"
$app->configureMode('development', function () use($app) {
    $app->config(array('log.enable' => true, 'log.level' => \Slim\Log::DEBUG, 'debug' => true));
});
// Get log writer
$log = $app->getLog();
#echo "<pre>";
#print_r($config);
try {
    if (!empty($config['db'])) {
        \ORM::configure($config['db']['dsn']);
Exemplo n.º 11
-3
<?php

require 'vendor/autoload.php';
use Slim\Slim;
/**
 * Setup the timezone
 */
ini_set('date.timezone', 'America/Edmonton');
$logWriter = new \Flynsarmy\SlimMonolog\Log\MonologWriter(array('handlers' => array(new \Monolog\Handler\StreamHandler('src/log/' . date('Y-m-d') . '.log'))));
//$logWriter = new \Slim\LogWriter(fopen('src/log/errors_slim.log', 'a'));
//$logWriter = new \Slim\LogWriter(fopen('src/log/bullhorn.log', 'a'));
$app = new \Slim\Slim(array('debug' => true, 'log.enabled' => true, 'log.level' => \Slim\Log::DEBUG, 'mode' => 'development', 'log.writer' => $logWriter, 'templates.path' => 'Stratum/templates'));
$app->setName('stratum');
$log = $app->getLog();
$app->post('/endpoint/:id', function ($endpoint) use($log) {
    $entityBody = file_get_contents('php://input');
    $log->debug($entityBody);
    $formController = new Stratum\Controller\FormController();
    $log->debug("parsing input data");
    $formResult = $formController->parse($entityBody);
    $formResult->setLogger($log);
    //form has updated mappings for each question
    $candidate = new Stratum\Model\Candidate();
    $candidate->setLogger($log);
    $log->debug("parsed input data");
    $candidateController = new Stratum\Controller\CandidateController();
    $candidateController->setLogger($log);
    $candidate = $candidateController->populate($candidate, $formResult);
    $log->debug("Candidate submitted with name " . $candidate->getName());
    $controller = new Stratum\Controller\BullhornController();
    $controller->setLogger($log);