/** * Open a database connection * * @param \Slim\Slim $app * @return \PDO */ public static function openDatabase($app) { $dsn = $app->config('database.dsn'); $user = $app->config('database.user'); $pass = $app->config('database.pass'); return new \PDO($dsn, $user, $pass); }
/** * Load config into slim configuration * @param Slim $app */ public function refresh(Slim $app = null) { if ($app != null) { $this->app = $app; } $this->app->config($this->config); }
/** * Setup the form service. * * @param \Slim\Slim $app The application instance. */ public static function setup(Slim $app) { $app->container->singleton('form', function () use($app) { $prefix = $app->config('form.prefix'); return new Form($prefix ?: null); }); }
/** * @param array $settings * @return $this */ public function addSettings(array $settings) { foreach ($settings as $key => $value) { $this->app->config($key, $value); } return $this; }
/** * @return $this */ public function run() { require_once __DIR__ . '/../config/propel/config.php'; //$this->config = Yaml::parse(file_get_contents(__DIR__ . '/../config/config.yml')); $this->routes = Yaml::parse(file_get_contents(__DIR__ . '/../config/routes.yml'))['routes']; $this->app = new \Slim\Slim(); $this->app->config(['templates.path' => __DIR__ . '/Views/']); $this->oauth = $this->configureOAuth(); $this->instantiateRoutes()->app->run(); return $this; }
public function __construct() { $slim = new Slim(['view' => new Twig()]); $slim->config(['templates.path' => __DIR__ . '/../../view']); $slim->view()->parserOptions = array('debug' => true, 'cache' => __DIR__ . '/../../compilation_cache'); $slim->config(['content' => ['main_menu' => $this->getMainMenu()]]); global $config; ORM::configure("mysql:host={$config['host']};port={$config['port']};dbname={$config['db_name']}"); ORM::configure('username', $config['db_user']); ORM::configure('password', $config['db_password']); ORM::configure('driver_options', [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']); ORM::configure('error_mode', PDO::ERRMODE_EXCEPTION); $this->initSlimRoute(); }
/** * Setup the template service. * * @param \Slim\Slim $app The application instance. */ public static function setup(Slim $app) { $debug = $app->config('debug'); $view = $app->view(new Twig()); $view->parserOptions = ['debug' => $debug, 'cache' => $app->config('view.cache_path')]; $view->setTemplatesDirectory($app->config('view.path')); $view->parserExtensions = [new TwigExtension()]; if ($debug) { $view->parserExtensions[] = new Twig_Extension_Debug(); } $extensions = (array) $app->config('view.extensions'); foreach ($extensions as $ext) { $view->parserExtensions[] = new $ext(); } }
public function enable(Slim $app) { $this->app = $app; $this->config = $this->app->config('api'); $this->factory = new Factory($this->config['resources']); // Middleware $this->app->add(new Database()); $this->app->add(new ApiMiddleware($this->config)); // Routes $this->app->get($this->config['prefix'] . '/:resource/:id', [$this, 'getAction'])->conditions(['id' => '\\d+'])->name('resource_get'); $this->app->get($this->config['prefix'] . '/:resource', [$this, 'listAction'])->name('resource_get_list'); $this->app->put($this->config['prefix'] . '/:resource/:id', [$this, 'putAction'])->conditions(['id' => '\\d+'])->name('resource_put'); $this->app->post($this->config['prefix'] . '/:resource', [$this, 'postAction'])->name('resource_post'); $this->app->delete($this->config['prefix'] . '/:resource/:id', [$this, 'deleteAction'])->conditions(['id' => '\\d+'])->name('resource_delete'); }
/** * Override \Slim\Slim::render method on controller * * @param string $tpl * @param array $data [] * @param string $suffix * @return void */ protected function render($tpl, array $data = []) { $suffix = $this->app->config('template.suffix'); $suffix = empty($suffix) ? $this->viewSuffix : $suffix; $tpl .= $suffix; $this->app->render($tpl, $data); }
/** * Apply settings to the Slim application. * * @param \Slim\Slim $slim Application */ protected function configureSlim(\Slim\Slim $slim) { $slim->config(array('parsoid.url' => Config::getStr('PARSOID_URL', 'http://parsoid-lb.eqiad.wikimedia.org/enwiki/'), 'parsoid.cache' => Config::getStr('CACHE_DIR', "{$this->deployDir}/data/cache"), 'es.url' => Config::getStr('ES_URL', 'http://127.0.0.1:9200/'), 'es.user' => Config::getStr('ES_USER', ''), 'es.password' => Config::getStr('ES_PASSWORD', ''), 'can.edit' => Config::getBool('CAN_EDIT', false), 'can.vote' => Config::getBool('CAN_VOTE', false), 'oauth.enable' => Config::getBool('USE_OAUTH', false), 'oauth.consumer_token' => Config::getStr('OAUTH_CONSUMER_TOKEN', ''), 'oauth.secret_token' => Config::getStr('OAUTH_SECRET_TOKEN', ''), 'oauth.endpoint' => Config::getStr('OAUTH_ENDPOINT', ''), 'oauth.redir' => Config::getStr('OAUTH_REDIR', ''), 'oauth.callback' => Config::getStr('OAUTH_CALLBACK', ''))); $slim->configureMode('production', function () use($slim) { $slim->config(array('debug' => false, 'log.level' => Config::getStr('LOG_LEVEL', 'INFO'))); // Install a custom error handler $slim->error(function (\Exception $e) use($slim) { $errorId = substr(session_id(), 0, 8) . '-' . substr(uniqid(), -8); $slim->log->critical($e->getMessage(), array('exception' => $e, 'errorId' => $errorId)); $slim->view->set('errorId', $errorId); $slim->render('error.html'); }); }); $slim->configureMode('development', function () use($slim) { $slim->config(array('debug' => true, 'log.level' => Config::getStr('LOG_LEVEL', 'DEBUG'), 'view.cache' => false)); }); }
/** * Apply settings to the Slim application. * * @param \Slim\Slim $slim Application */ protected function configureSlim(\Slim\Slim $slim) { $slim->config(['parsoid.url' => Config::getStr('PARSOID_URL', 'http://parsoid-lb.eqiad.wikimedia.org/enwiki/'), 'parsoid.cache' => Config::getStr('CACHE_DIR', "{$this->deployDir}/data/cache"), 'es.url' => Config::getStr('ES_URL', 'http://127.0.0.1:9200/')]); $slim->configureMode('production', function () use($slim) { $slim->config(['debug' => false, 'log.level' => Config::getStr('LOG_LEVEL', 'INFO')]); // Install a custom error handler $slim->error(function (\Exception $e) use($slim) { $errorId = substr(session_id(), 0, 8) . '-' . substr(uniqid(), -8); $slim->log->critical($e->getMessage(), ['exception' => $e, 'errorId' => $errorId]); $slim->view->set('errorId', $errorId); $slim->render('error.html'); }); }); $slim->configureMode('development', function () use($slim) { $slim->config(['debug' => true, 'log.level' => Config::getStr('LOG_LEVEL', 'DEBUG'), 'view.cache' => false]); }); }
/** * Constructor for TodoQueue\Controller\Login * * @param \Slim\Slim $app Ref to slim app */ public function __construct(\Slim\Slim &$app) { $this->app = $app; if ($renderTemplateSuffix = $app->config('controller.template_suffix')) { $this->renderTemplateSuffix = $renderTemplateSuffix; } if (!is_null($paramPrefix = $app->config('controller.param_prefix'))) { $this->paramPrefix = $paramPrefix; $prefixLength = strlen($this->paramPrefix); if ($prefixLength > 0 && substr($this->paramPrefix, -$prefixLength) !== '.') { $this->paramPrefix .= '.'; } } if ($app->config('controller.cleanup_params')) { $this->paramCleanup = true; } }
public static function configureModes(Slim $app, array $modeConfigs) { foreach ($modeConfigs as $mode => $config) { $app->configureMode($mode, function () use($app, $config) { $app->config($config); }); } }
protected function getFramework($config) { $app = new Slim(['view' => new Twig()]); $app->config(['templates.path' => $config['templates.path']]); $view = $app->view(); $view->parserOptions = $config['parserOptions']; $view->parserExtensions = array(new TwigExtension()); return $app; }
public function __construct(StorageInterface $storage, Slim $app) { $this->storage = $storage; $this->app = $app; $this->ignored = $app->config('api.classes.auth.ignored'); if (!is_array($this->ignored)) { $this->ignored = array(); } }
/** * Setup the pagination service. * * @param \Slim\Slim $app The application instance. */ public static function setup(Slim $app) { $key = $app->config('pagination.key'); if (empty($key)) { $key = 'page'; } Paginator::currentPageResolver(function () use($app, $key) { return $app->request->get($key); }); }
public function __construct(StorageInterface $storage, Slim $app) { $this->storage = $storage; $this->app = $app; $realm = $app->config('api.class.auth.adapter.realm'); if (empty($realm)) { $realm = 'Deal'; } $this->realm = $realm; }
/** * Setup the database service. * * @param \Slim\Slim $app The application instance. */ public static function setup(Slim $app) { $manager = new Manager(); $manager->addConnection(['driver' => $app->config('db.driver'), 'host' => $app->config('db.host'), 'database' => $app->config('db.database'), 'username' => $app->config('db.username'), 'password' => $app->config('db.password'), 'charset' => $app->config('db.charset'), 'collation' => $app->config('db.collation'), 'prefix' => $app->config('db.prefix')]); $manager->setEventDispatcher(new Dispatcher(new Container())); $manager->setAsGlobal(); $manager->bootEloquent(); // Setting database connection to use the same time zone as // application. $manager->getConnection()->statement('SET time_zone = ?', [Carbon::now()->offsetHours . ':00']); $app->database = $manager; }
static function factory($filePath) { $storage = new YamlStorage($filePath); $slimApp = new Slim(); $slimApp->add(new ContentTypes()); $slimApp->config('debug', false); $instance = new static($slimApp, $storage); $slimApp->error(array($instance, 'error')); return $instance; }
/** * Route * @param array $routes * @return \Nogo\Framework\Bootstrap */ public function route(array $routes = array()) { $config = $this->app->config('routes'); if (empty($config)) { $routes = array(); } $routes = array_merge($config, $routes); foreach ($routes as $class) { $ref = new \ReflectionClass($class); if ($ref->implementsInterface('Nogo\\Framework\\Controller\\SlimController')) { /** * @var SlimController $controller */ $controller = new $class(); $controller->enable($this->app); $this->app->log->debug('Register and enable controller [' . $class . '].'); } } return $this; }
protected function prepareDebugBar() { if ($this->debugbar instanceof SlimDebugBar) { $this->debugbar->initCollectors($this->app); } $storage = $this->app->config('debugbar.storage'); if ($storage instanceof StorageInterface) { $this->debugbar->setStorage($storage); } // add debugbar to Slim IoC container $this->app->container->set('debugbar', $this->debugbar); }
public function register(Slim $app) { $app->container->singleton('cache', function () { return new FilesystemCache('tmp/cache/db'); }); $app->container->singleton('connection', function () { $dbOptions = (require 'config/connection.config.php'); $config = new Configuration(); return DriverManager::getConnection($dbOptions, $config); }); $app->container->singleton('log', function () { $logger = new Logger('echale-gas'); $logger->pushHandler(new StreamHandler('tmp/logs/app.log', LogLevel::DEBUG)); return $logger; }); $app->container->singleton('paginator', function () use($app) { return new PagerfantaPaginator($app->config('defaultPageSize')); }); $app->container->singleton('paginatorFactory', function () use($app) { return new PaginatorFactory($app->paginator); }); $app->container->singleton('proxiesConfiguration', function () use($app) { $config = new ProxyConfiguration(); $config->setProxiesTargetDir('tmp/cache/proxies'); spl_autoload_register($config->getProxyAutoloader()); return $config; }); $app->urlHelper = new TwigExtension(); $app->container->singleton('twig', function () use($app) { $twig = new Twig(); $twig->parserOptions = ['charset' => 'utf-8', 'cache' => realpath('tmp/cache/twig'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true]; $twig->parserExtensions = [$app->urlHelper, new HalRendererExtension()]; return $twig; }); $app->container->singleton('controllerEvents', function () use($app) { $eventManager = new EventManager(); // Ensure rendering is performed at the end by assigning a very low priority $eventManager->attach('postDispatch', new RenderResourceListener($app->twig), -100); $eventManager->attach('renderErrors', new RenderErrorsListener($app->twig), -100); return $eventManager; }); $app->container->singleton('controller', function () use($app) { $controller = new RestController($app->request(), $app->response()); $factory = new RestControllerProxyFactory($app->proxiesConfiguration, $app->controllerEvents); $controller = $factory->createProxy($controller); $factory->addEventManagement($controller); return $controller; }); $app->view($app->twig); }
public function getMiddleware(Slim $app) { if (!$this->auth) { $auth = $app->config('api.classes.auth.adapter'); if (!$auth || !class_exists($auth)) { throw new \InvalidArgumentException('Config value api.classes.auth.adapter="' . $auth . '" which does not exist'); } $storage = $app->config('api.classes.auth.storage'); if (!$storage || !class_exists($storage)) { throw new \InvalidArgumentException('Config value api.classes.auth.storage="' . $storage . '" which does not exist'); } $storage = new $storage($app->settings()); if (!$storage instanceof StorageInterface) { throw new \InvalidArgumentException('Class ' . get_class($storage) . ' must implement StorageInterface'); } $auth = $this->auth = new $auth($storage, $app); if (!$auth instanceof AuthInterface) { throw new \InvalidArgumentException('Class ' . get_class($auth) . ' must implement AuthInterface'); } } return array($this->auth, 'authenticate'); // this notation is lighter in the engine than a closure }
public function __construct(Slim $app) { $this->app = $app; $this->singleton('slim', function () use($app) { return $app; }); $this->singleton('config', function ($app) { return new Config($app['slim']); }); $this['path'] = $app->config('path'); $service_manager = $this; $app->hook('slim.before', function () use($service_manager) { $service_manager->boot(); }, 1); }
public static function newInstance(\Slim\Slim $app) { try { $config = $app->config('connection'); $instance = new \PDO("mysql:host={$config['mysql']['host']};dbname={$config['mysql']['database']}", $config['mysql']['user'], $config['mysql']['password'], $config['mysql']['options']); if (!empty($config['mysql']['execute'])) { foreach ($config['mysql']['execute'] as $sql) { $stmt = $instance->prepare($sql); $stmt->execute(); } } } catch (\PDOException $p) { //$this->slim->log->error('BAD THINGS'); return $app->halt(500, $app->view()->fetch('error/500.php')); } return $instance; }
public function checkRequirements() { $paths = Utils::getPaths(SW_PATH . "/engine/Shopware/Components/Check/Data/Path.xml"); clearstatcache(); $systemCheckPathResults = Utils::checkPaths($paths, SW_PATH); foreach ($systemCheckPathResults as $value) { if (!$value['result']) { $fileName = SW_PATH . '/' . $value['name']; @mkdir($fileName, 0777, true); @chmod($fileName, 0777); } } clearstatcache(); $systemCheckPathResults = Utils::checkPaths($paths, SW_PATH); $hasErrors = false; foreach ($systemCheckPathResults as $value) { if (!$value['result']) { $hasErrors = true; } } $directoriesToDelete = ['engine/Library/Mpdf/tmp' => false, 'engine/Library/Mpdf/ttfontdata' => false]; CommonUtils::clearOpcodeCache(); $results = []; foreach ($directoriesToDelete as $directory => $deleteDirecory) { $result = true; $filePath = SW_PATH . '/' . $directory; Utils::deleteDir($filePath, $deleteDirecory); if ($deleteDirecory && is_dir($filePath)) { $result = false; $hasErrors = true; } if ($deleteDirecory) { $results[$directory] = $result; } } if (!$hasErrors && $this->app->request()->get("force") !== "1") { // No errors, skip page except if force parameter is set $this->app->redirect($this->app->urlFor("dbmigration")); } $isSkippableCheck = $this->app->config('skippable.check'); if ($isSkippableCheck && $this->app->request()->get("force") !== "1") { // No errors, skip page except if force parameter is set $this->app->redirect($this->app->urlFor("dbmigration")); } $this->app->render('checks.php', ['systemCheckResultsWritePermissions' => $systemCheckPathResults, 'filesToDelete' => $results, 'error' => $hasErrors]); }
protected function configureApp(Slim $app, Container $c) { // Add Middleware $app->add($c['profileMiddleware']); $app->add($c['navigationMiddleware']); $app->add($c['authenticationMiddleware']); $app->add($c['sessionCookieMiddleware']); // Prepare view $app->view($c['twig']); $app->view->parserOptions = $this['config']['twig']; $app->view->parserExtensions = array($c['slimTwigExtension'], $c['twigExtensionDebug']); $config = $this['config']; // Dev mode settings $app->configureMode('development', function () use($app, $config) { $app->config(array('log.enabled' => true, 'log.level' => Log::DEBUG)); $config['twig']['debug'] = true; }); }
public function __construct(Slim $app) { $filename = $app->config('api.class.auth.storage.filename'); if (!file_exists($filename)) { $filename = __DIR__ . '/File.txt'; touch($filename); } $data = array(); $items = file($filename); foreach ($items as $line) { $line = explode(':', $line); if (isset($line[0]) && isset($line[1])) { $data[trim($line[0])] = trim($line[1]); } } $this->data = $data; $this->filename = $filename; }
public function __construct(Slim $app) { $this->registerAliases(); $this->app = $app; $this->singleton('slim', function () use($app) { return $app; }); $this->singleton('config', function ($app) { return new Config($app['slim']); }); $this['path'] = $app->config('path'); //Antes de iniciar slim, iniciamos los servicios. $service_manager = $this; $app->hook('slim.before', function () use($service_manager) { $service_manager->boot(); }, 1); Facade::setFacadeApplication($this); $this->registerBaseServiceProviders(); }
/** * @SWG\Property(name="station_id",type="integer",description="Unique identifier of the gas station") * @SWG\Property(name="name",type="string",description="Name of the gas station") * @SWG\Property(name="social_reason",type="string",description="Official name of the gas station") * @SWG\Property(name="address_line_1",type="string",description="Street name and number of the gas station") * @SWG\Property(name="address_line_2",type="string",description="Neighborhood name of the gas station") * @SWG\Property(name="location",type="string",description="State and city name where the gas station is located") * @SWG\Property(name="latitude",type="double",description="Latitude coordinate") * @SWG\Property(name="longitude",type="double",description="Longitude coordinate") * @SWG\Property(name="created_at",type="string",format="date-format",description="Registration date of the gas station") * @SWG\Property(name="last_updated_at",type="string",format="date-format",description="Most recent date in which the gas station was edited") */ public function register(Slim $app) { $app->container->singleton('station', function () use($app) { return new Model($app->stationTable, $app->stationValidator, $app->paginatorFactory); }); $app->container->singleton('stationFormatter', function () use($app) { return new ResourceFormatter($app->urlHelper, 'station', 'station_id'); }); $app->container->singleton('stationsFormatter', function () use($app) { return new CollectionFormatter($app->urlHelper, 'stations', $app->stationFormatter); }); $app->container->singleton('stationEvents', function () use($app) { $eventManager = new EventManager(); $specification = new ChainedSpecification(); $specification->addSpecification(new PaginationSpecification($app->config('defaultPageSize'))); $specification->addSpecification(new GeolocationSpecification()); $eventManager->attach('postFindAll', new QuerySpecificationListener($specification)); $eventManager->attachAggregate(new HasTimestampListener()); $eventManager->attachAggregate(new CacheListener($app->cache, $app->request()->getPathInfo())); return $eventManager; }); $app->container->singleton('stationTable', function () use($app) { $stationTable = new StationTable('stations', $app->connection); $factory = new TableProxyFactory($app->proxiesConfiguration, $app->stationEvents); $stationTable = $factory->createProxy($stationTable); $factory->addEventManagement($stationTable); return $stationTable; }); $app->container->singleton('stationValidator', function () use($app) { return new ValitronValidator(require 'config/validations/stations.config.php'); }); $app->container->singleton('stationController', function () use($app) { $app->controller->setModel($app->station); $app->controllerEvents->attach('postDispatch', new FormatResourceListener($app->stationFormatter)); return $app->controller; }); $app->container->singleton('stationsController', function () use($app) { $app->controller->setModel($app->station); $app->controllerEvents->attach('postDispatch', new FormatResourceListener($app->stationsFormatter)); return $app->controller; }); }