本文整理汇总了PHP中Slim\Slim::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::__construct方法的具体用法?PHP Slim::__construct怎么用?PHP Slim::__construct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Slim
的用法示例。
在下文中一共展示了Slim::__construct方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(array $userSettings = array(), $configDirectory = 'config')
{
// Slim initialization
parent::__construct($userSettings);
$this->config('debug', false);
$this->notFound(function () {
$this->handleNotFound();
});
$this->error(function ($e) {
$this->handleException($e);
});
// Config
$this->configDirectory = __DIR__ . '/../../' . $configDirectory;
$this->config = $this->initConfig();
// /features
$this->get('/features', function () {
$features = new Features($this->config['features']);
$this->response->headers->set('Content-Type', 'application/json');
$this->response->setBody(json_encode($features->getFeatures()));
});
$this->get('/features/:id', function ($id) {
$features = new Features($this->config['features']);
$feature = $features->getFeature($id);
if ($feature === null) {
return $this->notFound();
}
$this->response->headers->set('Content-Type', 'application/json');
$this->response->setBody(json_encode($feature));
});
}
示例2:
function __construct($config)
{
parent::__construct();
$this->config = $config;
$dsn = "{$config['db_host']}:{$config['db_port']}";
$this->conn = new Crate\PDO\PDO($dsn, null, null, null);
}
示例3: __construct
public function __construct(array $userSettings = array())
{
$this->schemaPath = $userSettings['propelToSlim']['schemaPath'];
$this->schemaMap = new SchemaMap($this->schemaPath);
$this->propelToSlimSettings = $userSettings['propelToSlim'];
return parent::__construct($userSettings);
}
示例4: __construct
public function __construct()
{
parent::__construct(array('mode' => getMode()));
self::$_INSTANCE = $this;
# add the exception middleware
$this->add(new Exception_Middleware());
}
示例5: __construct
public function __construct($config)
{
parent::__construct();
$this->config = $config;
$this->routingManager = new RoutingManager(array("cache" => dirname(__FILE__) . "/../../cache", "controllers" => dirname(__FILE__) . "/Controllers", "controller_namespace" => "App\\Controllers"));
$this->add($this->routingManager);
}
示例6: __construct
public function __construct()
{
$settings = (require "../settings.php");
if (isset($settings['model'])) {
$this->data = $settings['model'];
}
parent::__construct($settings);
}
示例7: array
function __construct($namespace)
{
parent::__construct();
$this->config('debug', true);
$error_handler = array($this, 'error_handler');
$this->error($error_handler);
$this->get('(/)', array($this, 'displayServiceDoc'));
$this->get('/\\$metadata', array($this, 'displayMetadata'));
$this->serviceDoc = new ODataServiceDoc();
$this->metadataDoc = new CSDLSchema($namespace);
}
示例8: __construct
public function __construct(array $userSettings = array())
{
$settings = array_unique(array_merge($this->defaultSettings, $userSettings));
parent::__construct($settings);
$this->view()->parserExtensions = array(new TwigExtension());
$this->registerErrorHandler();
$this->registerHooks();
$this->registerServices();
$this->registerControllers();
$this->registerRoutes();
}
示例9: __construct
/**
* @param $basePath
*/
public function __construct($basePath)
{
$this->basePath = rtrim($basePath, '/');
$dotenv = new Dotenv($this->basePath);
$dotenv->load();
$config = $this->loadConfigFile('config') ?: [];
parent::__construct($config);
$this->loadRoutes();
$this->setupServices();
//$this->setupErrorHandler();
//$this->setupNotFound();
}
示例10: __construct
public function __construct(array $userSettings = array())
{
parent::__construct($userSettings);
$this->get('Product/Image/:id', function ($id) {
echo "hello {$name}";
})->name('id');
echo '===__construct 0<br>';
flush();
$this->curlHandler = curl_init();
echo '===__construct 1<br>';
flush();
}
示例11: __construct
public function __construct($mode = null)
{
if ($mode === null) {
$mode = $this->inferMode();
}
parent::__construct(array('mode' => $mode));
call_user_func(function ($app) {
include self::$privateDir . '/config.php';
}, $this);
$this->setupServices($this);
$this->setupRoutes($this);
}
示例12: __construct
/**
* Register all the application services, routes and middleware
*
* @param array $options Associative array of application settings
*/
public function __construct(array $options = array())
{
parent::__construct($options);
$container = new SlimContainer(new EwalletWebContainer($options, $this));
$this->container = $container->merge($this->container);
$resolver = new Resolver();
$services = new Services($resolver, $options);
$services->configure($this);
$controllers = new Controllers($resolver);
$controllers->register($this);
$middleware = new Middleware();
$middleware->configure($this);
}
示例13: __construct
/**
* Construct a new instance of Tacit.
*
* @param string|array|null $configuration An array or file that returns an
* array when included.
*/
public function __construct($configuration = null)
{
$configuration = $this->loadConfiguration($configuration);
parent::__construct($configuration);
$connection = $this->config('connection');
$this->configureMode('production', function () {
$this->config(['log.enable' => true, 'debug' => false]);
});
$this->configureMode('development', function () {
$this->config(['log.enable' => false, 'debug' => true]);
});
if ($connection !== null) {
$this->container->singleton('repository', function () use($connection) {
$dbClass = $connection['class'];
return new $dbClass($connection);
});
}
$this->add(new ContentTypes());
$this->error(function (\Exception $e) {
$resource = ['status' => 500, 'code' => $e->getCode(), 'message' => $e->getMessage()];
if ($e instanceof RestfulException) {
if ($e instanceof NotFoundException) {
$this->notFound();
}
$resource['status'] = $e->getStatus();
$resource['description'] = $e->getDescription();
$resource['property'] = $e->getProperty();
}
/* @var \Slim\Http\Response $response */
$response = $this->response;
$response->headers->set('Content-Type', 'application/json');
$response->setStatus($resource['status']);
if ($this->config('debug') === true) {
$resource['request_duration'] = microtime(true) - $this->config('startTime');
}
$response->setBody(json_encode($resource));
$this->stop();
});
$this->notFound(function () {
$resource = ['status' => 404, 'message' => 'Resource not found'];
/* @var \Slim\Http\Response $response */
$response = $this->response;
$response->headers->set('Content-Type', 'application/json');
$response->setStatus(404);
if ($this->config('debug') === true) {
$resource['request_duration'] = microtime(true) - $this->config('startTime');
}
$response->setBody(json_encode($resource));
$this->stop();
});
}
示例14: __construct
/**
* Constructor
*
* @param array $settings null
*/
public function __construct(array $settings = null)
{
if (version_compare(phpversion(), '5.4.0', '<')) {
throw new \RuntimeException('Slimore require PHP version >= 5.4.0');
}
require __DIR__ . "/../Helper/Functions.php";
$settings = array_merge($this->defaults, $settings);
if ($settings['x-framework-header']) {
header('X-Framework-By: Slimore/' . $this->version);
}
parent::__construct($settings);
date_default_timezone_set($this->config('timezone'));
$this->init();
}
示例15: __construct
public function __construct($userSettings = array())
{
parent::__construct($userSettings);
ZiFacade::setFacadeApplication($this);
ZiFacade::registerAliases();
$this->view(new \Slim\Views\Twig());
$this->view->parserOptions = array('charset' => 'utf-8', 'cache' => realpath('zi/templates/cache'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true);
$this->view->parserExtensions = array(new \Slim\Views\TwigExtension(), new ZiTwigExtension());
$this->container->singleton('db', function ($c) {
return require ZICONFIG . '/database.php';
});
$this->setORM();
$this->setAuth();
}