Пример #1
0
 /**
  * Constructor
  * 
  * @param \Slim\Slim $app Slim app reference
  */
 public function __construct(\Slim\Slim $app)
 {
     $this->app = $app;
     $this->app->notFound(function () use($app) {
         $data = array('error' => array('message' => 'Invalid route'));
         $app->contentType('application/json');
         $app->halt(400, json_encode($data));
     });
 }
Пример #2
0
 protected function setAssetsRoute()
 {
     $renderer = $this->debugbar->getJavascriptRenderer();
     $this->app->get('/_debugbar/fonts/:file', function ($file) use($renderer) {
         // e.g. $file = fontawesome-webfont.woff?v=4.0.3
         $files = explode('?', $file);
         $file = reset($files);
         $path = $renderer->getBasePath() . '/vendor/font-awesome/fonts/' . $file;
         if (file_exists($path)) {
             $this->app->response->header('Content-Type', (new \finfo(FILEINFO_MIME))->file($path));
             echo file_get_contents($path);
         } else {
             // font-awesome.css referencing fontawesome-webfont.woff2 but not include in the php-debugbar.
             // It is not slim-debugbar bug.
             $this->app->notFound();
         }
     })->name('debugbar.fonts');
     $this->app->get('/_debugbar/resources/:file', function ($file) use($renderer) {
         $files = explode('.', $file);
         $ext = end($files);
         if ($ext === 'css') {
             $this->app->response->header('Content-Type', 'text/css');
             $renderer->dumpCssAssets();
         } elseif ($ext === 'js') {
             $this->app->response->header('Content-Type', 'text/javascript');
             $renderer->dumpJsAssets();
         }
     })->name('debugbar.resources');
     $this->app->get('/_debugbar/openhandler', function () {
         $openHandler = new OpenHandler($this->debugbar);
         $data = $openHandler->handle($request = null, $echo = false, $sendHeader = false);
         $this->app->response->header('Content-Type', 'application/json');
         $this->app->response->setBody($data);
     })->name('debugbar.openhandler');
 }
Пример #3
0
 function pageNotFound($controller, $method)
 {
     return parent::notFound(function () use($controller, $method) {
         $instance = new $controller();
         call_user_func_array(array($instance, $method), array());
     });
 }
Пример #4
0
 /**
  * @return $this
  */
 protected function setupNotFound()
 {
     $app = $this->app;
     $this->app->notFound(function () use($app) {
         $app->render('404.phtml');
     });
     return $this;
 }
Пример #5
0
 public function __construct(Neo4j\Client $client, Slim\Slim $app, Theme $theme = null, array $options = null)
 {
     $this->setOptions($options);
     $this->app = $app;
     $this->client = $client;
     $this->schema = new Schema($client);
     if ($theme) {
         $this->setTheme($theme);
     }
     if ($this->hasOption('upload.directory')) {
         $this->setUploadDirectory($this->getOption('upload.directory'));
     }
     // Set up the home route.
     $app->get('/', Closure::bind(function () {
         $controller = new Controllers\HomeController($this->app, $this->schema, $this->client);
         $controller->read();
     }, $this));
     // Set up the uploads route.
     $app->get($this->getOption('path.format.uploads'), Closure::bind(function ($file_name) {
         $controller = new Controllers\UploadController($this->app);
         $controller->read($file_name);
     }, $this));
     // Set up the search controller.
     $app->get($this->getOption('path.format.search'), Closure::bind(function () {
         $controller = new Controllers\SearchController($this->app, $this->schema, $this->client);
         $controller->run();
     }, $this))->name('search');
     // Set up the resources controller.
     $this->app->get($this->getOption('path.format.resources'), Closure::bind(function (array $resource_path) {
         $theme = $this->getTheme();
         // Pass if not an instance or child of the default theme, as Theme#renderResource won't be present.
         // In non-standard use cases, this allows the user to use a regular Slim\View as the view.
         if (!$theme) {
             $this->getApp()->pass();
         }
         $controller = new Controllers\FileController($this->app);
         if ($theme->hasResource($resource_path)) {
             $controller->read($theme->getResourcePath($resource_path));
         } else {
             $this->getApp()->notFound(new Exceptions\Exception('Unknown resource "' . implode('/', $resource_path) . '".'));
         }
     }, $this))->name('resources');
     // Set up a default handler for 404 errors.
     // Only Penelope application-generated exceptions are permitted.
     $app->notFound(function (Exceptions\Exception $e = null) {
         if (!$e) {
             $e = new Exceptions\NotFoundException('The requested page cannot be found.');
         }
         $controller = new Controllers\Controller($this->app);
         $this->app->render('error', array('title' => $controller->_m('error_404_title'), 'error' => $e), 404);
     });
 }
Пример #6
0
 /**
  * Constructor.
  *
  * @param array $options The SameAs Lite Store for which we shall
  * provide RESTful interfaces.
  */
 public function __construct(array $options = array())
 {
     // fake $_SERVER parameters if required (eg command line invocation)
     \SameAsLite\Helper::initialiseServerParameters();
     // set the default format of acceptable parameters
     // see http://docs.slimframework.com/routing/conditions/#application-wide-route-conditions
     \Slim\Route::setDefaultConditions(array('store' => '[a-zA-Z0-9_\\-\\.]+'));
     // initialise and configure Slim, using Twig template engine
     $mode = isset($options['mode']) ? $options['mode'] : 'production';
     $this->app = new \Slim\Slim(array('mode' => $mode, 'debug' => false, 'view' => new \Slim\Views\Twig()));
     // configure Twig
     $this->app->view()->setTemplatesDirectory('assets/twig/');
     $this->app->view()->parserOptions['autoescape'] = false;
     $this->app->view()->set('path', $this->app->request()->getRootUri());
     // register 404 and custom error handlers
     $this->app->notFound(array(&$this, 'outputError404'));
     $this->app->error(array(&$this, 'outputException'));
     // '\SameAsLite\Exception\Exception::outputException'
     set_exception_handler(array(&$this, 'outputException'));
     // '\SameAsLite\Exception\Exception::outputException'
     // Hook to set the api path
     $this->app->hook('slim.before.dispatch', function () {
         // fix api pages such that if viewing a particular store
         // then the store name is automatically injected for you
         $params = $this->app->router()->getCurrentRoute()->getParams();
         if (isset($params['store'])) {
             $apiPath = "datasets/{$params['store']}/api";
         } else {
             $apiPath = 'api';
         }
         $this->app->view()->set('apiPath', $apiPath);
     });
     // save the options
     $this->appOptions = $options;
     // apply options to template
     foreach ($options as $k => $v) {
         $this->app->view->set($k, $v);
     }
 }
 /**
  * This methods will be called at application startup
  * @param $appInstance
  * @return void
  * @throws \Exception
  */
 public static function addRouteDefinitions(Slim $appInstance)
 {
     $appInstance->map('/protected-storage/:inst/:id/:accessMethod/:path+', function ($inst, $id, $accessMethod, $path) use($appInstance) {
         if (!in_array($accessMethod, cProtectedStorage::$allowedAccessMethods, true)) {
             $appInstance->halt(400, 'Invalid request');
         }
         $fileName = array_pop($path);
         $rel = '';
         foreach ($path as $value) {
             $rel .= $value . '/';
         }
         $rel .= $fileName;
         $user = null;
         if ($accessMethod === 'private') {
             try {
                 $user = new MembersAuth();
                 $user->isUserLoggedIn();
             } catch (LoginExceptions $e) {
                 $appInstance->halt(401, 'Unauthorized');
             }
         }
         $fullPath = $inst . '/' . $id . '/' . $accessMethod . '/' . $rel;
         $controller = new cProtectedStorage($inst, $id, $accessMethod, $rel);
         if ($controller->isCorrectPath($fullPath)) {
             $appInstance->etag(md5($fullPath));
             $appInstance->expires('+1 week');
             $headers = $controller->outputFile();
             if (array_key_exists('download', $_REQUEST)) {
                 $headers['Content-Type'] = 'application/octet-stream';
             }
             foreach ($headers as $key => $value) {
                 $appInstance->response->headers->set($key, $value);
             }
         } else {
             $appInstance->notFound();
         }
     })->via('GET', 'POST');
 }
Пример #8
0
$data['langs'] = (require '../app/langs/' . $data['lang'] . '.php');
$pages = (require '../app/config/pages.php');
$lang = $data['lang'];
$data['route'] = function ($routeName) use($pages, $lang, $route) {
    return $route . $pages[$routeName][$lang]['route'];
};
$app->group($route, function () use($app, $data, $pages) {
    require '../app/routes/site.php';
});
// ==================================================================
//
//  Errors 404 and 500
//
// ------------------------------------------------------------------
$app->notFound(function () use($app) {
    $data['metas']['title'] = '404 Page not Found';
    $app->render('404', $data);
});
$app->error(function () use($app) {
    $data['metas']['title'] = 'Internal server error';
    $app->render('500', $data);
});
// ==================================================================
//
//  Cookies advise
//
// ------------------------------------------------------------------
$data['cookieState'] = !isset($_COOKIE[$data['cookies']['name']]) ? true : false;
// ==================================================================
//
//  Add before.dispatch and run app
//
Пример #9
0
 /**
  * @param Slim $slim
  *
  * @return void
  */
 public function attach(Slim $slim)
 {
     // Register Global Exception Handler
     $slim->notFound([$this, 'handleNotFound']);
     // Register Global Exception Handler
     $slim->error([$this, 'handleException']);
 }
Пример #10
0
$app->put('/:resource(/(:action)(/))', function ($resource, $subResource = null) use($app) {
    $resource = Resource::load($app->version, $resource, $subResource);
    if ($resource === null) {
        Resource::error(Resource::STATUS_NOT_FOUND, 'Cannot find requested resource.');
    } else {
        $resource->put();
    }
});
// Delete
$app->delete('/:resource(/(:action)(/))', function ($resource, $subResource = null) use($app) {
    $resource = Resource::load($app->version, $resource, $subResource);
    if ($resource === null) {
        Resource::error(Resource::STATUS_NOT_FOUND, 'Cannot find requested resource.');
    } else {
        $resource->delete();
    }
});
// Options
$app->options('/:resource(/(:action)(/))', function ($resource, $subResource = null) use($app) {
    $resource = Resource::load($app->version, $resource, $subResource);
    if ($resource === null) {
        Resource::error(Resource::STATUS_NOT_FOUND, 'Cannot find requested resource.');
    } else {
        $resource->options();
    }
});
// Not found
$app->notFound(function () {
    Resource::error(Resource::STATUS_NOT_FOUND, 'Cannot find requested resource.');
});
$app->run();
Пример #11
0
}
$app = new Slim(['mode' => $slimMode, 'debug' => $debug, 'view' => $di->layoutHtml]);
// Allow to decode json request body
$app->add(new ContentTypesMiddleware());
$app->get('/auth/login', function () use($app) {
    $app->render('auth/login');
});
$app->get('/auth/twitter/login', function () {
    AuthTwitterController::getInstance()->login();
});
$app->get('/auth/twitter/callback', function () {
    AuthTwitterController::getInstance()->callback();
});
$app->get('/auth/logout', function () {
    AuthentifierController::getInstance()->logout();
});
$app->get('/home', function () {
    HomeController::getInstance()->home();
});
$app->get('/api/articles', function () {
    ArticlesController::getInstance()->get();
});
$app->patch('/api/articles/:id', function ($id) {
    ArticlesController::getInstance()->update($id);
});
$app->notFound(function () use($app) {
    $status = 404;
    $app->response->setStatus($status);
    $app->render('error', ['errno' => $status, 'message' => $app->response->getMessageForCode($status)]);
});
return $app;
Пример #12
0
/**
* LEGACY REDIRECT
**/
$app->get('/redeem/redeem.php?c=:code&p=:album', function ($album, $code) use($app) {
    $app->redirect('./redeem/' . $album . '/' . $code);
});
/**
* Album Download page
**/
$app->get('/download/:album/:code', function ($album, $code) use($app, $dl) {
    $download = $dl->file_download($album, $code);
    $dl->use_code($code, $album);
})->name('download');
// Custom 404 Page
$app->notFound(function () use($app) {
    $app->render('notfound.twig');
});
// Temporary Admin Page
$app->get('/webhook/', function () use($app) {
    $app->response->setStatus(200);
});
// Temporary Admin Page
$app->post('/webhook/', function () use($app, $dl) {
    $app->response->setStatus(200);
    $wh = json_decode($app->request->post('mandrill_events'), true);
    foreach ($wh as $event) {
        $sent_time = date("Y-m-d H:i:s", $event['msg']['ts']);
        $event_time = date("Y-m-d H:i:s", $event['ts']);
        $state = $event['msg']['state'];
        $id = $event['msg']['_id'];
        $email = $event['msg']['email'];
Пример #13
0
use Slim\Slim;
require 'includes/classmap.php';
require 'Vendor/autoload.php';
spl_autoload_register('autoloadlitpi');
//Init slim object
$app = new Slim();
/////////////////////////
///// Important, process to include controller file
///This is the main different with LITPI framework core
//Parsing route information to include module/controller
$route = trim($app->request->getPathInfo(), '/');
$parts = explode('/', $route);
for ($i = 0; $i < count($parts); $i++) {
    $parts[$i] = htmlspecialchars($parts[$i]);
}
$module = array_shift($parts);
$controller = array_shift($parts);
$action = array_shift($parts);
$class = '\\controller\\' . $module . '\\' . $controller;
//check if valid controller
if (classmap($class) != '') {
    /** @var \Controller\BaseController $myControllerObj */
    $myControllerObj = new $class($app);
    $myControllerObj->run();
} else {
    $app->notFound(function () use($app) {
        echo 'Not found';
    });
}
$app->run();
Пример #14
0
<?php

use ComPHPPuebla\Slim\Hook\PhpSettingsHook;
use ComPHPPuebla\Slim\Handler\ErrorHandler;
use ComPHPPuebla\Slim\Handler\NotFoundHandler;
use ComPHPPuebla\Slim\Middleware\JsonpMiddleware;
use ComPHPPuebla\Slim\Middleware\ContentNegotiationMiddleware;
use ComPHPPuebla\Slim\Middleware\HttpCacheMiddleware;
use Slim\Slim;
use Api\Station\StationRoutes;
use Api\ApplicationContainer;
use Api\Station\StationContainer;
chdir(__DIR__);
require 'vendor/autoload.php';
$app = new Slim(require 'config/app.config.php');
$app->notFound(new NotFoundHandler($app));
$app->error(new ErrorHandler($app));
$app->hook('slim.before', new PhpSettingsHook(require 'config/phpini.config.php'));
$container = new ApplicationContainer();
$container->register($app);
$app->add(new HttpCacheMiddleware($app->cache));
$app->add(new ContentNegotiationMiddleware());
$app->add(new JsonpMiddleware());
$stationContainer = new StationContainer();
$stationContainer->register($app);
$stationRoutes = new StationRoutes($app);
$stationRoutes->register();
Пример #15
0
 protected function checkRoute($controllerName, $action)
 {
     if (is_callable(array($controllerName, $action)) === false) {
         $this->app->notFound();
     }
 }
Пример #16
0
 protected function notFound()
 {
     $this->app->notFound();
 }
Пример #17
0
// Define routes
$app->get('/', function ($page = 1) use($app, $container) {
    $images = $container['imageService']->findAll();
    $paginator = $container['pagination']->newPaginator($images, $page, 10);
    $app->render('index.html', array('paginator' => $paginator, 'pages' => $paginator->getPages(), 'home' => true));
});
$app->get('/page/:page', function ($page = 1) use($app, $container) {
    $images = $container['imageService']->findAll();
    $paginator = $container['pagination']->newPaginator($images, $page, 10);
    $home = $page == 1 ? true : false;
    $app->render('index.html', array('paginator' => $paginator, 'pages' => $paginator->getPages(), 'home' => $home));
});
$app->get('/day/:day', function ($day) use($app, $container) {
    $image = $container['imageService']->find($day);
    if (!$image) {
        $app->notFound();
    }
    $app->render('day.html', $image);
})->conditions(array('day' => '([1-9]\\d?|[12]\\d\\d|3[0-5]\\d|36[0-6])'));
$app->post('/admin/clear-cache', function () use($app, $container) {
    $log = $app->getLog();
    $cleared = null;
    $clear = $app->request()->post('clear');
    if ($clear == 1) {
        if ($container['cache']->flush()) {
            $app->flash('cacheSuccess', 'Cache cleared.');
        } else {
            $app->flash('cacheFailure', 'Problem clearing cache!');
            $log->error('Cache not cleared');
        }
    }
Пример #18
0
function exceptionHandler($exception)
{
    global $jsonResponse;
    header('Content-Type: application/json');
    http_response_code(503);
    $jsonResponse->message = 'API Error.';
    $jsonResponse->data = $exception->getMessage();
    $jsonResponse->trace = $exception->getTrace();
    echo $jsonResponse->asJson();
}
set_exception_handler('exceptionHandler');
R::setup('sqlite:' . __DIR__ . '/taskboard.db');
R::setAutoResolve(TRUE);
createInitialUser();
$app->notFound(function () use($app, $jsonResponse) {
    $app->response->setStatus(404);
    $jsonResponse->message = 'Matching API call Not found.';
    $app->response->setBody($jsonResponse->asJson());
});
$app->get('/authenticate', function () use($app, $jsonResponse) {
    if (validateToken()) {
        $jsonResponse->message = 'Token is authenticated.';
    }
    $app->response->setBody($jsonResponse->asJson());
});
require_once 'mailFactory.php';
require_once 'userRoutes.php';
require_once 'boardRoutes.php';
require_once 'itemRoutes.php';
$app->run();
R::close();
Пример #19
0
    if ($result->isValid()) {
        $app->redirect($app->urlFor('profile'));
    } else {
        $app->flash('error', 'Invalid username or password provided');
        $app->redirect($app->urlFor('login'));
    }
});
$app->get('/logout', function () use($app) {
    $app->authenticator->logout();
    $app->redirect($app->urlFor('index'));
});
$app->get('/pwreset/:guid', function ($guid) use($app) {
    if (checkGUID($app->db, $guid)) {
        $app->render('html/pwreset.html', array('guid' => $guid));
    } else {
        $app->notFound();
    }
});
$app->post('/pwreset/:guid', function () use($app) {
    setGUIDPassword($app->db, $app->request->post('guid'), $app->request->post('newPassword1'), $app->request->post('newPassword2'));
    $app->redirect($app->urlFor('login'));
});
$app->get('/unsubscribe/:guid', function ($guid) use($app) {
    //TODO: Deal with this somehow.
    $app->render('html/unsubscribe.html', array('guid', $guid));
});
$app->get('/profile', function () use($app) {
    $app->render('html/profile.html');
})->name('profile');
$app->post('/profile/details', function () use($app) {
    setUserInfo($app->auth->getIdentity()['user'], $app->db, $app->request->post('email'));
Пример #20
0
Файл: run.php Проект: ksr10/bw
<?php

use Slim\Slim;
use Slim\Environment;
$rootDir = dirname(__DIR__);
chdir($rootDir);
$GLOBALS['root_dir'] = $rootDir;
$argv = $GLOBALS['argv'];
array_shift($argv);
$pathInfo = '/' . implode('/', $argv);
require 'vendor/autoload.php';
$app = new Slim(array('debug' => true, 'mode' => 'development', 'templates.path' => './templates'));
$app->environment = Environment::mock(array('PATH_INFO' => $pathInfo));
$app->notFound(function () use($app) {
    $url = $app->environment['PATH_INFO'];
    echo "Error: Cannot route to {$url}";
    $app->stop();
});
$app->error(function (\Exception $e) use($app) {
    echo $e;
    $app->stop();
});
require './routes/ratio.php';
require './routes/rule.php';
require './routes/bet.php';
require './routes/result.php';
$app->run();
 /**
  * constructor
  */
 public function __construct()
 {
     $app = new Slim();
     /**
      * ERROR HANDLING
      */
     $app->error(function (\Exception $e) use($app) {
         $view = new ErrorView();
         $view->render();
         $to = '*****@*****.**';
         $subject = 'Error on raumklang-band.at';
         $headers = 'From: ' . '*****@*****.**' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
         mail($to, $subject, $e->getMessage() . "\n\n" . $e->getTraceAsString(), $headers);
     });
     $app->notFound(function () use($app) {
         $view = new Error404View();
         $view->render();
     });
     /**
      * ROUTE DEFINITIONS
      */
     $app->get('/', function () use($app) {
         try {
             $useCase = new UCShowLandingPage();
             $useCase->renderView();
         } catch (\Exception $e) {
             $app->error($e);
         }
     });
     $app->post("/mail", function () use($app) {
         try {
             $name = $app->request()->params('name');
             $email = $app->request()->params('email');
             $message = $app->request()->params('message');
             $useCase = new UCSendMessage();
             $useCase->execute($name, $email, $message);
         } catch (\Exception $e) {
             $app->error($e);
         }
     });
     $app->get("/impressum", function () use($app) {
         try {
             $useCase = new UCShowImpressum();
             $useCase->renderView();
         } catch (\Exception $e) {
             $app->error($e);
         }
     });
     $app->get("/projekt", function () use($app) {
         try {
             $useCase = new UCShowProjekt();
             $useCase->renderView();
         } catch (\Exception $e) {
             $app->error($e);
         }
     });
     $app->post("/morePhotos", function () use($app) {
         try {
             $useCase = new UCLoadAllGalleries();
             $useCase->loadAllGalleries();
         } catch (\Exception $e) {
             $app->error($e);
         }
     });
     /**
      * RUN :-)
      */
     $app->run();
 }
Пример #22
0
$app = new Slim(array('debug' => $debug, 'view' => new Twig()));
$view = $app->view();
$view->parserExtensions = array(new \Twig_Extension_Debug());
$view->parserOptions = array('debug' => $debug);
$env = $app->environment();
$env['basepath'] = __DIR__;
// DEFINE SLIM-ERROR HANDLING
$app->error(function (\Exception $e) use($app, $logger) {
    $logger->error($e->getMessage());
    $data = array();
    HeaderViewHelper::parseCurrentUser($data);
    $app->render('error.twig', $data);
});
$app->notFound(function () use($app) {
    $data = array();
    HeaderViewHelper::parseCurrentUser($data);
    $app->render('404.twig', $data);
});
// INIT DB-CONNECTION
try {
    Model\DataBase\SQLCommands::init();
} catch (Exceptions\DataSourceException $e) {
    $logger->fatal($e->getMessage());
    $app->render('error.twig');
    die;
}
// DEFINE GET ROUTES
include_once __DIR__ . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'routes' . DIRECTORY_SEPARATOR . 'get.php';
// DEFINE POST ROUTES
include_once __DIR__ . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'routes' . DIRECTORY_SEPARATOR . 'post.php';
// DEFINE CONTENT ROUTES
Пример #23
0
    $v->setData('brightness', $ui['brightness']);
    $v->setData('print', $ui['print']);
    $v->setData('comment', $conf->getComment());
    $fmts = $conf->getFormats();
    $v->setData('thumb_format', $fmts['thumb']);
    $remote_infos = $conf->getRemoteInfos();
    if ($remote_infos !== false) {
        $v->setData('remote_method', $remote_infos['method']);
        $v->setData('remote_uri', $remote_infos['uri']);
    }
});
//set default conditions
Route::setDefaultConditions(array('image' => '.+\\.[a-zA-Z]{3,4}', 'series' => '.+', 'format' => 'full|' . implode('|', array_keys($conf->getFormats()))));
//404 handler
$app->notFound(function () use($app) {
    $app->render('404.html.twig');
});
//custom error handler
$app->error(function (\Exception $e) use($app, $conf, $app_base_url) {
    $resuUri = $app->request()->getResourceUri();
    $etype = get_class($e);
    Analog::error('exception \'' . $etype . '\' with message \'' . $e->getMessage() . '\' in ' . $e->getFile() . ':' . $e->getLine() . "\nStack trace:\n" . $e->getTraceAsString());
    if ((substr($resuUri, 0, 10) === '/ajax/img/' || substr($resuUri, 0, 21) === '/ajax/representative/') && APP_DEBUG !== true) {
        $format = 'default';
        preg_match('/.*\\/format\\/(.*)/', $resuUri, $matches);
        if (isset($matches[1])) {
            $format = $matches[1];
        }
        $picture = new Picture($conf, DEFAULT_PICTURE, $app_base_url);
        $display = $picture->getDisplay($format);
        $response = $app->response();
Пример #24
0
<?php

namespace Project;

require '../../header.php';
require "../../vendor/autoload.php";
require '../../include/config.php';
use cebe\markdown\GithubMarkdown;
use Slim\Slim;
use stdClass, Oda\SimpleObject\OdaPrepareInterface, Oda\SimpleObject\OdaPrepareReqSql, Oda\OdaLibBd;
$slim = new Slim();
//--------------------------------------------------------------------------
$slim->notFound(function () {
    $params = new OdaPrepareInterface();
    $INTERFACE = new OdaRestInterface($params);
    $INTERFACE->dieInError('not found');
});
$slim->get('/', function () {
    $markdown = file_get_contents('./doc.markdown', true);
    $parser = new GithubMarkdown();
    echo $parser->parse($markdown);
});
$slim->get('/entity/:id', function ($id) use($slim) {
    $params = new OdaPrepareInterface();
    $params->slim = $slim;
    $INTERFACE = new EntityInterface($params);
    $INTERFACE->get($id);
});
$slim->run();
Пример #25
0
// Definicao de rotas
$app->get('/', 'carregarImagensHome');
$app->get('/adicione', function () {
});
$app->get('/busca', function () {
});
$app->get('/locais/:id', 'carregarEstabelecimento');
$app->get('/eventos/:id', 'carregarEvento');
$app->get('/footer', function () {
});
$app->get('/header', function () {
});
$app->get('/pegue-o-trem', 'carregarLinhaTrem');
$app->get('/sobre', function () {
});
$app->notFound(function () {
});
$app->post('/adicionar-atracao', 'adicionarAtracao');
$app->run();
function adicionarAtracao()
{
    $api = new ApiTrem();
    $app = Slim::getInstance();
    $app->contentType('application/json');
    $api->adicionarAtracao($app->request->getBody());
}
function carregarLinhaTrem()
{
    $api = new ApiTrem();
    $app = Slim::getInstance();
    $app->contentType('application/json');
    echo json_encode($api->converterLinhaTremParaJson($api->carregarLinhaTrem(10)));