Skip to content

Instantly share code, notes, and snippets.

@unok
Created January 18, 2016 06:57
Show Gist options
  • Save unok/cce87be3b2d7f41ac8e5 to your computer and use it in GitHub Desktop.
Save unok/cce87be3b2d7f41ac8e5 to your computer and use it in GitHub Desktop.
<?php
class TasteCake {
function TasteCake() {
$this->__initConstants();
$this->__bootstrap();
App::uses('ClassRegistry', 'Utility');
App::uses('Dispatcher', 'Routing');
App::uses('Router', 'Routing');
Configure::write('App.baseUrl', 'http://localhost');
}
function __initConstants() {
if (function_exists('ini_set')) {
ini_set('html_errors', false);
ini_set('implicit_flush', true);
ini_set('max_execution_time', 0);
}
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', realpath(dirname('taste.php')));
define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');
define('CAKEPHP_SHELL', true);
if (!defined('CORE_PATH')) {
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
}
}
}
function __bootstrap() {
$defaults = array('app' => 'app', 'root' => ROOT, 'working' => null, 'webroot' => 'webroot');
define('APP_DIR', $defaults['app']);
define('APP_PATH', $defaults['working'] . DS);
define('WWW_ROOT', APP_PATH . $defaults['webroot'] . DS);
if (!is_dir(ROOT . DS . APP_DIR . DS . 'tmp')) {
define('TMP', CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'Console' . DS . 'Templates' . DS . 'skel' . DS . 'tmp' . DS);
}
$boot = file_exists(ROOT . DS . APP_DIR . DS . 'Config' . DS . 'bootstrap.php');
$vendorPath = ROOT . DS . APP_DIR . DS . 'Vendor' . DS . 'cakephp' . DS . 'cakephp' . DS . 'lib';
$dispatcher = 'Cake' . DS . 'Console' . DS . 'ShellDispatcher.php';
if (!defined('CAKE_CORE_INCLUDE_PATH') && file_exists($vendorPath . DS . $dispatcher)) {
define('CAKE_CORE_INCLUDE_PATH', $vendorPath);
}
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
if (function_exists('ini_set')) {
ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'));
}
if (!include 'Cake' . DS . 'bootstrap.php') {
$failed = true;
}
} else {
if (!include CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php') {
$failed = true;
}
}
if (!empty($failed)) {
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);
}
return true;
}
}
$taste = new TasteCake();
$file_list = glob(ROOT . DS . 'app/Model/*.php');
foreach ($file_list as $f) {
$m = array();
if (preg_match('/([a-zA-Z0-9]+).php$/', $f, $m)) {
App::uses($m[1], 'Model');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment