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/')); }); }
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')); }
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')); }
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)); }
/** * create slim app */ function create_app($name) { $app = new \Slim\Slim(array('templates.path' => ROOT . 'templates/', 'cookies.lifetime' => '2 days', 'cookies.secret_key' => 'livehubsecretkey')); $app->configureMode('development', function () use($app) { $app->config(array('debug' => true, 'log.enable' => true, 'log.level' => \Slim\Log::DEBUG, 'cookies.lifetime' => '2 days', 'cookies.secret_key' => 'livehubsecretkey')); }); $app->configureMode('production', function () use($app) { $app - config(array('log.level' => \Slim\Log::ERROR, 'cookies.lifetime' => '2 days', 'cookies.encrypt' => true, 'cookies.secret_key' => 'livehubsecretkey')); }); $app->container->singleton('log', function () use($name) { $log = new \Monolog\Logger($name); $log->pushHandler(new \Monolog\Handler\StreamHandler(ROOT . "logs/{$name}.log", \Monolog\Logger::DEBUG)); return $log; }); $app->view(new \Slim\Views\Twig()); $app->view->parserOptions = array('charset' => 'utf-8', 'cache' => realpath('templates/cache'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true); $app->view->parserExtensions = array(new \Slim\Views\TwigExtension()); $app->setName($name); return $app; }
<?php error_reporting(E_ALL); require '../vendor/autoload.php'; $app = new \Slim\Slim(); require 'config.php'; require 'rest_dao.php'; require 'ta_mailer.php'; require 'help_classes.php'; $app->config('debug', false); $app->response->headers->set('Content-Type', 'application/json'); $app->error(function ($e) use($app) { echo '{"error":{ "text":"' . $e->getMessage() . '", "file":"' . $e->getFile() . '", "line":"' . $e->getLine() . "\"\n }}\n"; // file_put_contents(__DIR__.'/deb.txt', $deb); }); $app->notFound(function () use($app) { echo '{"error": 404 }'; }); $dao = new RestDAO(); $help = new Helper(); $mailer = new TA_Mailer(); $mailer->setTemplateDirectory('emails'); $auth = function () { $app = \Slim\Slim::getInstance(); $auth = new Auth(); $tokenAuth = $app->request->headers->get('Auth'); if (empty($tokenAuth) or !$auth->tokenOk($tokenAuth)) { $app->response->setStatus(401);
$root_dir = dirname(__DIR__); /** * Use Dotenv to set required environment variables and load .env file in root */ $dotenv = new Dotenv\Dotenv($root_dir); if (file_exists($root_dir . '/.env')) { $dotenv->load(); $dotenv->required(['SITE_URL']); } // Fetch the configuration settings $config = (require_once 'config.php'); // Initialise the Slim framework $app = new \Slim\Slim(array('mode' => getenv("ENVIRONMENT"))); // Only invoked if mode is "production" $app->configureMode('production', function () use($app, &$config) { $app->config(array('log.enable' => true, 'debug' => false)); $config['debug_mode'] = false; }); // Only invoked if mode is "development" $app->configureMode('development', function () use($app, &$config, $root_dir) { $app->config(array('log.enable' => false, 'debug' => true)); $config['debug_mode'] = true; $config['debug_file'] = $root_dir . '/debug.log'; }); // Return an instance of HybridAuth $app->container->singleton('hybridInstance', function () use($config) { $instance = new Hybrid_Auth($config); return $instance; }); // Return an instance of NameParser $app->container->singleton('parserInstance', function () {
if ($response !== false) { $decodedResponse = json_decode($response, true); if (array_key_exists('Response', $decodedResponse)) { // in case of error.. $response = array("Search" => array()); $response = json_encode($response); } $app->response->setBody($response); $app->response->setStatus(200); } }); $app->get('/movie/:imdb', function ($q) use($app) { $q = htmlentities($q); $response = file_get_contents("http://www.omdbapi.com/?type=movie&plot=full&i=" . $q); $omdbResponse = json_decode($response); $conn = new PDO("mysql:host=" . $app->config('db.host') . ";dbname=" . $app->config('db.name') . ";charset=utf8", $app->config('db.username'), $app->config('db.password')); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $conn->prepare('SELECT count(*) as c from posters where imbdid = :id'); $stmt->bindParam(':id', $q); $filename = null; if ($stmt->execute()) { $row = $stmt->fetch(PDO::FETCH_ASSOC); $count = $row['c']; if ($count == 1) { $stmt = $conn->prepare('SELECT `fileid` from posters where imbdid = :id'); $stmt->bindParam(":id", $q); if ($stmt->execute()) { $row = $stmt->fetch(PDO::FETCH_ASSOC); $filename = $row['fileid']; } }
// DEFAULT: "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"; $output = "[%datetime%] [%level_name%] [%extra%] : %message% %context%\n"; $formatter = new Monolog\Formatter\LineFormatter($output); $streamToFile->setFormatter($formatter); $streamToFile->pushProcessor(function ($record) use($config) { if ($config['enviroment'] == 'development') { $record['extra']['connection'] = 'testing'; } else { $record['extra']['connection'] = 'default'; } return $record; }); $handlers[] = $streamToFile; $logger_writer = new \Flynsarmy\SlimMonolog\Log\MonologWriter(array('handlers' => $handlers, 'processors' => array(new Monolog\Processor\UidProcessor(), new Monolog\Processor\WebProcessor($_SERVER)))); $app = new \Slim\Slim(array('mode' => $config['enviroment'], 'log.level' => \Slim\Log::DEBUG, 'log.enabled' => true, 'log.writer' => $logger_writer, 'templates.path' => '../templates')); $app->config('databases', $config['databases']); $app->add(new \BitPrepared\Slim\Middleware\EloquentMiddleware()); $corsOptions = array("origin" => "*"); $app->add(new \CorsSlim\CorsSlim($corsOptions)); $app->hook('slim.before.router', function () use($app) { $req = $app->request; $allGetVars = $req->get(); $allPostVars = $req->post(); $allPutVars = $req->put(); $vars = array_merge($allGetVars, $allPostVars); $vars = array_merge($vars, $allPutVars); $srcParam = json_encode($vars); $srcUri = $req->getRootUri(); $srcUrl = $req->getResourceUri(); //$app->log->info(@Kint::dump( $srcUrl )); $app->log->debug('REQUEST : ' . var_export($_REQUEST, true));
$app->render('404.html.twig', $twig_vars); }); $authenticate = function ($app) { return function () use($app) { if (!isset($_SESSION['user'])) { $app->flash('error', 'Login required'); $app->redirect('/admin'); } }; }; /*********************************************************************************************************************** * ADMIN BLOCK **********************************************************************************************************************/ // Admin $app->get('/admin/', function () use($app) { $twig_vars = $app->config('twigVars'); $app->view->setTemplatesDirectory("admin/"); $app->render('admin.html.twig', $twig_vars); }); // Admin Login $app->post('/admin/login', function () use($app) { $twig_vars = $app->config('twigVars'); $config = $twig_vars['config']; $user = $app->request()->post('user'); $pass = sha1($app->request()->post('password')); if ($config['user'] == $user && $config['password'] == $pass) { $_SESSION['user'] = $user; $_SESSION['pass'] = $pass; $app->redirect($config['url'] . '/admin/pages'); } else { $app->redirect($config['url'] . '/admin');
<?php require 'vendor/autoload.php'; $app = new \Slim\Slim(); $app->config(array('debug' => true, 'templates.path' => 'client/views/')); $app->get('/', function () use($app) { $app->render('index.html'); }); $app->get('/date', function () use($app) { echo date('Y-m-d H:i:s'); }); $app->notFound(function () use($app) { $app->render('index.html'); }); $app->run();
$_SERVER['SCRIPT_NAME'] = preg_replace('/public\\/index\\.php$/', 'index.php', $_SERVER['SCRIPT_NAME'], 1); // Load Config require 'app/config.php'; // Autoload require 'vendor/autoload.php'; // RedBeanPHP alias fix class R extends RedBeanPHP\Facade { } // RedBeanPHP setup R::setup('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USERNAME, DB_PASSWORD); R::freeze(DB_FREEZE); // Slim app instance $app = new \Slim\Slim(['view' => new EnhancedView()]); // Slim Config $app->config(['templates.path' => 'app/views', 'debug' => APP_DEBUG]); // Add support for JSON posts $app->add(new \Slim\Middleware\ContentTypes()); // JSON view function function APIrequest() { $app = \Slim\Slim::getInstance(); $app->view(new \JsonView()); $app->view->clear(); } // Set webroot for portable $app->hook('slim.before', function () use($app) { $app->wroot = $app->request->getUrl() . $app->request->getRootUri(); $app->view()->appendData(['wroot' => $app->wroot]); }); // Load routes
<?php require 'vendor/autoload.php'; require_once 'lib/Slim/Controller/API/Person.php'; require_once 'lib/Slim/Controller/API/Job.php'; require_once 'lib/Slim/Controller/API/Alexa.php'; if (!file_exists('config.json')) { die("Missing configuration file config.json"); } $application_settings = json_decode(file_get_contents('config.json'), TRUE); if (is_null($application_settings)) { die("config file exist but was not able to be decoded. Bad JSON?"); } $app = new \Slim\Slim($application_settings); $app->config('job_dir', __DIR__ . '/jobs/'); $app->get('/api/person/', '\\Slim\\Controller\\API\\Person:getAllPeople'); $app->get('/api/person/:username', '\\Slim\\Controller\\API\\Person:getPerson'); // This should be a patch put this is not implemented in the version of lighttpd I am current running :( $app->put('/api/person/:username', '\\Slim\\Controller\\API\\Person:patchPerson'); $app->post('/api/person/:username/action/:action/location/:location', '\\Slim\\Controller\\API\\Person:changeLocationForPerson'); // Run a job directly @TODO might need to do something so that jobs do not get executed automatically here $app->post('/api/job/:job/', '\\Slim\\Controller\\API\\Job:executeJob')->name('execute_job'); $app->get('/api/job/:job/', '\\Slim\\Controller\\API\\Job:executeJob')->name('execute_job'); $app->post('/api/alexa/:skill/', '\\Slim\\Controller\\API\\Alexa:handleRequest'); $app->run();
<?php require "../vendor/autoload.php"; require "../vendor/phpmailer/phpmailer/PHPMailerAutoload.php"; require "../vendor/phpmailer/phpmailer/function.php"; $app = new \Slim\Slim(); $app->config(array('debug' => true, 'templates.path' => '../views')); $db = new PDO("mysql:host=localhost;dbname=projeto", "root", "root"); $app->get('/', function () use($app) { $app->render("index.php"); }); $app->get('/novo/nome', function () use($app, $db) { $app->render('novo.php'); }); $app->post('/', function () use($app, $db) { $request = $app->request; $name = $request->post('name'); $email = $request->post('email'); $site = $request->post('site'); $inquiry = $request->post('inquiry'); if ($name == '' || $email == '' || $site == '' || $inquiry == '') { $app->redirect("index.php"); } else { $dbquery = $db->prepare("INSERT INTO inquiry(name,email,website,inquiry) VALUES(:name,:email,:site,:inquiry)"); $dbquery->execute(array(":name" => $name, ":email" => $email, ":site" => $site, ":inquiry" => $inquiry)); } $app->redirect("index.php"); }); $app->get('/send_email', function () use($app) { send_email(); });
<?php require 'vendor/autoload.php'; $app = new \Slim\Slim(); $app->config(['templates.path' => 'templates']); // Set singleton value $app->container->singleton('db', function () { require __DIR__ . '/../../bin/private/variables.php'; try { $db = new PDO("mysql:host={$host};dbname={$dbName};charset=utf8", $userName, $pwd, [\PDO::ATTR_PERSISTENT => false]); } catch (PDOException $e) { die('Error!: ' . $e->getMessage()); } return $db; }); $app->container->singleton('hybridInstance', function () { $instance = new Hybrid_Auth('config.php'); return $instance; }); $model = new \Model\App_Model($app->db); $authenticate = function ($app) { return function () use($app) { $app->hybridInstance; $session_identifier = Hybrid_Auth::storage()->get('user'); if (is_null($session_identifier) && $app->request()->getPathInfo() != '/login/') { $app->redirect('/login/'); } }; }; $app->get('/', function () use($app, $model) { $app->hybridInstance;
/* Description: Core de API RestFUL para consulta de saldo de tarjeta Bip! Version: 1 Author: Francisco Capone Author Mail: francisco.capone@gmail.com Author URI: http://www.franciscocapone.com */ @session_start(); require_once 'class/Utils.class.php'; require_once 'class/AbstractCURL.class.php'; require_once 'class/Bip.class.php'; require_once 'class/vendor/Slim/Slim.php'; \Slim\Slim::registerAutoloader(); $restBipApp = new \Slim\Slim(); $restBipApp->config(array('templates.path' => 'vistas')); $restBipApp->get('/', function () use($restBipApp) { $restBipApp->response->setStatus(200); echo "RestFUL BIP!"; }); $restBipApp->contentType('text/html; charset=utf-8'); $restBipApp->get('/getSaldo/:id', function ($id) { $restBipApp = \Slim\Slim::getInstance(); try { $resultadosSaldo = new Bip($id); if ($resultadosSaldo) { $restBipApp->response->setStatus(200); $restBipApp->response()->headers->set('Access-Control-Allow-Origin', '*'); $restBipApp->response()->headers->set('Content-Type', 'application/json'); print_r($resultadosSaldo->getData()); }
/** * Test batch set settings */ public function testBatchSetSettings() { $s = new \Slim\Slim(); $this->assertEquals('./templates', $s->config('templates.path')); $this->assertTrue($s->config('debug')); $s->config(array('templates.path' => './tmpl', 'debug' => false)); $this->assertEquals('./tmpl', $s->config('templates.path')); $this->assertFalse($s->config('debug')); }
/** * Test set settings recursively */ public function testSetSettingsRecursively() { $config = array('my_module' => array('paths' => array('./my_module/path/1'))); $s = new \Slim\Slim($config); $override = array('my_module' => array('paths' => array('./my_module/path/2', './my_module/path/3'))); // Test recursive batch behaviour $s->config($override, true); $expected = array('paths' => array('./my_module/path/1', './my_module/path/2', './my_module/path/3')); $this->assertEquals($expected, $s->config('my_module')); // Test default batch behaviour $s = new \Slim\Slim($config); $s->config($override); $this->assertNotEquals($expected, $s->config('my_module')); }
} else { die("<pre>Rename 'config/database.config.php.install' to 'config/database.config.php' and configure your connection</pre>"); } /** * Extract settings from db */ $settings = Settings::where('id', '=', 1)->first(); /* $settings->language = "en-US"; $settings->template = "default"; */ $settings->base_url = $app->request->getUrl() . $app->request->getScriptName(); /** * Set template directory */ $app->config(array("templates.path" => TEMPLATEDIR . $settings->template . DS)); /** * Add some twig extensions for multilanguage support */ $app->view->parserExtensions = array(new \Slim\Views\TwigExtension(), new Twig_Extension_StringLoader()); /** * Get language */ $app->lang = (require_once LANGUAGEDIR . $settings->language . ".php"); /** * Markdown support */ $app->container->singleton('markdown', function () { return Parsedown::instance(); }); /**
if (file_exists($file)) { return include $file; } return array(); } } /** * Prepare app */ $app = new \Slim\Slim(_loadConfig('app/general')); // $app->setName('Slim Framework Quickstart'); /** * Only invoked if mode is "production" */ $app->configureMode('production', function () use($app) { $app->config(_loadConfig('app/production')); }); /** * Only invoked if mode is "development" */ $app->configureMode('development', function () use($app) { $app->config(_loadConfig('app/development')); }); /** * Create monolog logger and store logger in container as singleton * (Singleton resources retrieve the same log resource definition each time) * @todo set custom error handler */ $app->container->singleton('log', function () use($app) { $logpath = APPPATH . 'logs/' . date('Y/m'); $logfile = $logpath . '/' . date('d') . '.log';
$contact_groups = true; } if ($contacts === true || $contact_groups === true) { return true; } $apiResponse = new APIViewData(1, $deployment, "Unable to detect either contacts or contact_group parameter"); $app->halt(404, $apiResponse->returnJson()); } function httpCache($app, $sec = 30) { $app->response()->header('cache-control', 'private, max-age=' . $sec); $app->response()->header('expires', date('r', time() + $sec)); $app->response()->header('pragma', 'cache'); } // Setup our application's environment $app->config(array('debug' => true)); // Setup Lazy Loader for Routes $app->hook('slim.before.router', function () use($app) { $uri = $app->request()->getResourceUri(); if (($k = strpos($uri, "/", 1)) === false) { $controller = $uri; } else { $controller = '/' . strtok($uri, '/'); $controller .= '/' . strtok('/'); } switch ($controller) { case "/sapi/configs": require_once BASE_PATH . "/routes/configs.route.php"; break; case "/sapi/consumer": require_once BASE_PATH . "/routes/consumer.route.php";
<?php require 'vendor/autoload.php'; require 'helpers_bp.php'; $app = new \Slim\Slim(); $app->config(array('debug' => true, 'mode' => 'development')); $app->post('/add_voter', function () use($app) { //$userid = $app->request->post('userid'); $token = $app->request->post('token'); //Facebook access token $userid = id_by_token($token); if (!is_null($userid)) { //Stores the new validation number and associates with user ID //Returns NULL if user id already there $random_number = genValidationNumberAndStore($userid); if (!is_null($random_number)) { $ret = array('success' => true, 'message' => "{$random_number}"); echo json_encode($ret); return json_encode($ret); } } //Else the token was bad, couldn't retrieve user ID //OR the user has already requested a validation number in past //Perhaps return the same validation number? $ret = array('success' => false, 'message' => 'Bad token or user already requested validation number.'); echo json_encode($ret); }); $app->post('/vote', function () use($app) { $validation_num = $app->request->post('validnum'); // Validation number given to user $userid = $app->request->post('userspecifiedid');
<?php require 'vendor/autoload.php'; $app = new \Slim\Slim(array('mode' => 'development')); // 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/')); }); // Define mysql connector $app->container->singleton('mysql', function () { $app = \Slim\Slim::getInstance(); $config = parse_ini_file(getAppConfigFile('mysql.ini')); $pdo = new PDO("mysql:host=" . $config['db.hostname'] . ";dbname=" . $config['db.schema'], $config['db.user'], $config['db.password']); // set the character set to utf8 to ensure proper json encoding $pdo->exec("SET NAMES 'utf8'"); return $pdo; }); $app->container->singleton('log', function () { $app = \Slim\Slim::getInstance(); Logger::configure(getAppConfigFile('log4php-config.xml')); return Logger::getLogger('default'); }); // FIXME: Implement separation of view and data // TODO: move index.html into the /views directory and // point the templates to /views $view = $app->view(); $view->setTemplatesDirectory('./');
<?php function __autoload($class_name) { echo $class_name; if (file_exists(BASE_PATH . '_app/libraries/' . $class_name . '.php')) { include_once BASE_PATH . '_app/libraries/' . $class_name . '.php'; } } require_once BASE_PATH . '_app/function.php'; require_once BASE_PATH . '_app/model.php'; require_once BASE_PATH . '_app/libraries/Yacms.php'; require_once BASE_PATH . '_app/libraries/Tiny.php'; $app = new \Slim\Slim(); $app->config = Yacms::loadConfigs(); foreach ($app->config as $key => $value) { $app->config($key, $value); } $template_engine = $app->config['template_engine']; if (file_exists(BASE_PATH . '/_app/libraries/template_engine/' . $template_engine . '.php')) { require_once BASE_PATH . '/_app/libraries/template_engine/' . $template_engine . '.php'; } $app->view(new $template_engine()); $app->add(new \Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware()); $app->add(new \Slim\Middleware\SessionCookie(array('expires' => $app->config['cookies.lifetime'], 'path' => '/', 'domain' => null, 'secure' => false, 'httponly' => false, 'name' => 'session', 'secret' => $app->config['session_secret'], 'cipher' => MCRYPT_RIJNDAEL_256, 'cipher_mode' => MCRYPT_MODE_CBC))); $app->model = new DB(); require_once __DIR__ . '/admin_routes.php'; require_once __DIR__ . '/routes.php'; return $app;
/** * Test $_SESSION is populated from an unencrypted HTTP cookie * * The unencrypted cookie contains the serialized array ['foo' => 'bar']. * The global cookies.encrypt setting is set to false */ public function testSessionIsPopulatedFromMalformedCookieData() { \Slim\Environment::mock(array('SCRIPT_NAME' => '/index.php', 'PATH_INFO' => '/foo', 'HTTP_COOKIE' => 'slim_session={"foo":"bar"sdkhguy5y}')); $app = new \Slim\Slim(); // The cookie value in the test is unencrypted, so cookies.encrypt must // be set to false $app->config('cookies.encrypt', false); $app->get('/foo', function () { echo "Success"; }); $mw = new \Slim\Middleware\SessionCookie(array('expires' => '10 years')); $mw->setApplication($app); $mw->setNextMiddleware($app); $mw->call(); $this->assertEquals(array(), $_SESSION); }
require_once 'phplib/Auth.php'; require_once 'vendor/autoload.php'; @(include 'phplib/deploy_version.php'); if (!defined('MORGUE_VERSION')) { define('MORGUE_VERSION', ''); } $config = Configuration::get_configuration(); if (!$config) { $message = "Could not parse configuration file."; $content = "error"; error_log("ERROR: " . $message); include '../views/page.php'; die; } $app = new \Slim\Slim(); $app->config('debug', true); $app->log->setEnabled(true); if ($config['environment'] == "development") { $app->log->setLevel(4); } else { $app->log->setLevel(1); } // must be require_once'd after the Slim autoloader is registered require_once 'phplib/AssetVersionMiddleware.php'; // helper method for returning the selected timezone. // If set, get the user timezone else get it from the global config // otherwise default to 'America/New_York' // returns: string function getUserTimezone() { $config = Configuration::get_configuration();
<?php /******************************* LOADING & INITIALIZING BASE APPLICATION ****************************************/ // Configuration for error reporting, useful to show every little problem during development error_reporting(E_ALL); ini_set("display_errors", 1); // Load Composer's PSR-4 autoloader (necessary to load Slim, Mini etc.) require './vendor/autoload.php'; // Initialize Slim (the router/micro framework used) $app = new \Slim\Slim(); // and define the engine used for the view @see http://twig.sensiolabs.org $app->view = new \Slim\Views\Twig(); $app->view->setTemplatesDirectory("inc/view"); /******************************************* THE CONFIGS *******************************************************/ require_once 'inc/config.php'; require_once 'inc/helper.php'; /******************************************** THE MODEL ********************************************************/ require_once 'inc/entities.php'; // Initialize the model, pass the database configs. $model can now perform all methods from Mini\model\model.php $model = new DataModel($app->config('database')); /************************************ THE ROUTES / CONTROLLERS *************************************************/ require_once 'inc/routes.php'; /******************************************* RUN THE APP *******************************************************/ $app->run(); //include 'test.php';
// ========== COMPOSER ========== require ROOT_PATH . '/vendor/autoload.php'; // ========== CONFIGURATION ========== $config = (require APP_PATH . '/src/config.php'); // ========== PHP (from configuration) ========== // time zone date_default_timezone_set($config['PHP']['default_timezone']); // errors ini_set('display_errors', $config['PHP']['display_errors']); ini_set('display_startup_errors', $config['PHP']['display_startup_errors']); ini_set('log_errors', $config['PHP']['log_errors']); // session if (true === $config['PHP']['need_session']) { session_cache_limiter(false); session_set_cookie_params(0, '/', '', $config['PHP']['session_cookie_secure'], true); session_start(); } unset($config['PHP']); // ========== SLIM ========== $app = new \Slim\Slim($config['Slim']); $app->config('app', $config['App']); $app->view()->setData('config', $app->config('app')); require APP_PATH . '/src/dependencies.php'; require APP_PATH . '/src/middlewares.php'; require APP_PATH . '/src/routes.php'; // Error handler $app->error(function (\Exception $e) use($app) { $app->getLog()->error($e); $app->render('errors/error.twig'); }); $app->run();
} elseif (isset($_SESSION["language"]) && in_array($_SESSION["language"], $allowedLanguages)) { $selectedLanguage = $_SESSION["language"]; } else { $_SESSION["language"] = $selectedLanguage; } $language = (require __DIR__ . "/../data/lang/{$selectedLanguage}.php"); // Save post parameters starting with "c_" to session $params = $app->request()->params(); foreach ($params as $key => $value) { if (strpos($key, "c_") !== false) { $_SESSION["parameters"][$key] = $value; } } // Initiate database object $databaseParameters = array("user" => isset($_SESSION["parameters"]["c_database_user"]) ? $_SESSION["parameters"]["c_database_user"] : "", "password" => isset($_SESSION["parameters"]["c_database_password"]) ? $_SESSION["parameters"]["c_database_password"] : "", "host" => isset($_SESSION["parameters"]["c_database_host"]) ? $_SESSION["parameters"]["c_database_host"] : "", "port" => isset($_SESSION["parameters"]["c_database_port"]) ? $_SESSION["parameters"]["c_database_port"] : "", "socket" => isset($_SESSION["parameters"]["c_database_socket"]) ? $_SESSION["parameters"]["c_database_socket"] : "", "database" => isset($_SESSION["parameters"]["c_database_schema"]) ? $_SESSION["parameters"]["c_database_schema"] : ""); $app->config("install.database.parameters", $databaseParameters); $app->container->singleton('install.database', function () use($app) { return new Shopware\Recovery\Install\Database($app->config("install.database.parameters"), SW_PATH); }); $app->container->singleton('install.license', function () use($app) { /** @var \Shopware\Recovery\Install\Database $database */ $database = $app->container->get('install.database'); if (!$database->setDatabase()) { throw new \Exception($database->getError()); } $pdo = $database->getDatabase(); $license = new \Shopware\Recovery\Install\License($pdo); return $license; }); $app->config('install.configuration', new \Shopware\Recovery\Install\Configuration()); $app->config('install.requirements', new \Shopware\Recovery\Install\Requirements(__DIR__ . '/../data/System.xml'));
public function testAddFile() { $app = new \Slim\Slim(); $data = array('item1', 'item2'); Yaml::_()->addFile(dirname(__FILE__) . '/fixtures/index.yml'); $this->assertEquals($data, $app->config('items')); }