Skip to content

Instantly share code, notes, and snippets.

@markstory
Created August 7, 2014 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markstory/87444680576f0ec6c4a6 to your computer and use it in GitHub Desktop.
Save markstory/87444680576f0ec6c4a6 to your computer and use it in GitHub Desktop.
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 0.10.8
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
* Configure paths required to find CakePHP + general filepath
* constants
*/
require __DIR__ . '/paths.php';
// Use composer to load the autoloader.
require ROOT . '/vendor/autoload.php';
/**
* Bootstrap CakePHP.
*
* Does the various bits of setup that CakePHP needs to do.
* This includes:
*
* - Registering the CakePHP autoloader.
* - Setting the default application paths.
*/
require CORE_PATH . 'config' . DS . 'bootstrap.php';
use Cake\Cache\Cache;
use Cake\Configure\Engine\PhpConfig;
use Cake\Console\ConsoleErrorHandler;
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Datasource\ConnectionManager;
use Cake\Error\ErrorHandler;
use Cake\Log\Log;
use Cake\Network\Email\Email;
use Cake\Network\Request;
use Cake\Routing\DispatcherFactory;
use Cake\Utility\Inflector;
/**
* Read configuration file and inject configuration into various
* CakePHP classes.
*
* By default there is only one configuration file. It is often a good
* idea to create multiple configuration files, and separate the configuration
* that changes from configuration that does not. This makes deployment simpler.
*/
try {
Configure::config('default', new PhpConfig());
Configure::load('app.php', 'default', false);
} catch (\Exception $e) {
die('Unable to load config/app.php. Create it by copying config/app.default.php to config/app.php.');
}
// Load an environment local configuration file.
// You can use this file to provide local overrides to your
// shared configuration.
//Configure::load('app_local.php', 'default');
// When debug = false the metadata cache should last
// for a very very long time, as we don't want
// to refresh the cache while users are doing requests.
if (!Configure::read('debug')) {
Configure::write('Cache._cake_model_.duration', '+99 years');
Configure::write('Cache._cake_core_.duration', '+99 years');
}
/**
* Set server timezone to UTC. You can change it to another timezone of your
* choice but using UTC makes time calculations / conversions easier.
*/
date_default_timezone_set('UTC');
/**
* Configure the mbstring extension to use the correct encoding.
*/
mb_internal_encoding(Configure::read('App.encoding'));
/**
* Set the default locale. This controls how dates, number and currency is
* formatted and sets the default language to use for translations.
*/
ini_set('intl.default_locale', 'en_US');
/**
* Register application error and exception handlers.
*/
$isCli = php_sapi_name() === 'cli';
if ($isCli) {
(new ConsoleErrorHandler(Configure::consume('Error')))->register();
} else {
(new ErrorHandler(Configure::consume('Error')))->register();
}
// Include the CLI bootstrap overrides.
if ($isCli) {
require __DIR__ . '/bootstrap_cli.php';
}
/**
* Set the full base URL.
* This URL is used as the base of all absolute links.
*
* If you define fullBaseUrl in your config file you can remove this.
*/
if (!Configure::read('App.fullBaseUrl')) {
$s = null;
if (env('HTTPS')) {
$s = 's';
}
$httpHost = env('HTTP_HOST');
if (isset($httpHost)) {
Configure::write('App.fullBaseUrl', 'http' . $s . '://' . $httpHost);
}
unset($httpHost, $s);
}
Cache::config(Configure::consume('Cache'));
ConnectionManager::config(Configure::consume('Datasources'));
Email::configTransport(Configure::consume('EmailTransport'));
Email::config(Configure::consume('Email'));
Log::config(Configure::consume('Log'));
/**
* Setup detectors for mobile and tablet.
*/
Request::addDetector('mobile', function($request) {
$detector = new \Detection\MobileDetect();
return $detector->isMobile();
});
Request::addDetector('tablet', function($request) {
$detector = new \Detection\MobileDetect();
return $detector->isTablet();
});
/**
* Custom Inflector rules, can be set to correctly pluralize or singularize table, model, controller names or whatever other
* string is passed to the inflection functions
*
* Inflector::rules('singular', ['rules' => [], 'irregular' => [], 'uninflected' => []]);
* Inflector::rules('plural', ['rules' => [], 'irregular' => [], 'uninflected' => []]);
*
*/
/**
* Plugins need to be loaded manually, you can either load them one by one or all of them in a single call
* Uncomment one of the lines below, as you need. make sure you read the documentation on Plugin to use more
* advanced ways of loading plugins
*
* Plugin::loadAll(); // Loads all plugins at once
* Plugin::load('DebugKit'); //Loads a single plugin named DebugKit
*
*/
/**
* Connect middleware/dispatcher filters.
*/
DispatcherFactory::add('Asset');
DispatcherFactory::add('Routing');
DispatcherFactory::add('ControllerFactory');
Plugin::load('ValidatorService', ['bootstrap' => false, 'routes' => true]);
<?php
/**
* Routes configuration
*
* In this file, you set up routes to your controllers and their actions.
* Routes are very important mechanism that allows you to freely connect
* different URLs to chosen controllers and their actions (functions).
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use Cake\Core\Plugin;
use Cake\Routing\Router;
Router::scope('/', function($routes) {
/**
* Here, we are connecting '/' (base path) to a controller called 'Pages',
* its action called 'display', and we pass a param to select the view file
* to use (in this case, src/Template/Pages/home.ctp)...
*/
$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
/**
* ...and connect the rest of 'Pages' controller's URLs.
*/
$routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
/**
* Connect a route for the index action of any controller.
* And a more general catch all route for any action.
*
* The `fallbacks` method is a shortcut for
* `$routes->connect('/:controller', ['action' => 'index'], ['routeClass' => 'InflectedRoute']);`
* `$routes->connect('/:controller/:action/*', [], ['routeClass' => 'InflectedRoute']);`
*
* You can remove these routes once you've connected the
* routes you want in your application.
*/
$routes->fallbacks();
});
/**
* Load all plugin routes. See the Plugin documentation on
* how to customize the loading of plugin routes.
*/
Plugin::routes();
<?php
namespace ValidatorService\Config;
use Cake\Routing\Router;
Router::plugin('ValidatorService', function($routes) {
$routes->fallbacks();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment