示例#1
0
文件: Config.php 项目: tourze/base
 /**
  * 继承原来的load方法,实现级联系统的配置文件自动加载
  *
  * @param array|string $path 缓存文件路径,同时也是缓存的key
  * @param bool         $reload
  * @return static
  */
 public static function load($path, $reload = false)
 {
     if (!is_array($path)) {
         $path = [$path];
     }
     $cacheKey = md5(json_encode($path));
     // 如果有缓存并且可以不重新加载,那么就直接返回
     if (!$reload && isset(self::$_pathCache[$cacheKey])) {
         return self::$_pathCache[$cacheKey];
     }
     $finalPath = [];
     foreach ($path as $_path) {
         foreach (self::$_configPaths as $includePath) {
             // 检测和包含带下面后缀的文件
             $files = [$includePath . $_path . '.php', $includePath . $_path . '-local.php'];
             foreach ($files as $file) {
                 if (strpos($file, '*') === false) {
                     if (is_file($file)) {
                         $finalPath[] = $file;
                     }
                 } else {
                     $finalPath[] = $file;
                 }
             }
         }
     }
     return self::$_pathCache[$cacheKey] = parent::load($finalPath);
 }
示例#2
0
 public function __construct($config = 'mqtt.php', $host = '127.0.0.1', $port = '1883')
 {
     $conf = Config::load(CONFPATH . $config);
     $host = $conf['host'] ? $conf['host'] : $host;
     $port = $conf['port'] ? $conf['port'] : $port;
     $this->mq = new \Mosquitto\client();
     $this->mq->connect($host, $port, 5);
 }
 public function __construct($configFile)
 {
     try {
         $this->config = Config::load($configFile);
     } catch (Exception $e) {
         throw new FeatureTogglerException($e->getMessage());
     }
 }
示例#4
0
 public function __construct()
 {
     $conf = Config::load(CONFPATH . 'redis.php');
     $redis = new Redis($conf['host'], $conf['port']);
     $this->redis = $redis;
     $this->redis->auth('rensheng');
     $this->redis->select($conf['db']);
 }
示例#5
0
 public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
 {
     $this->app_dir = realpath(__DIR__ . '/../');
     try {
         $this->app_conf = Config::load([$this->app_dir . '/config/general.ini', $this->app_dir . '/config/record_types.ini', $this->app_dir . '/config/excluded_record_types.ini']);
     } catch (\Exception $e) {
         print "\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nPlease check your configuration files.  You must create a valid\n'general.ini' (you can use the supplied 'general.ini.template')\nfile with your Netsuite  credentials in order to run this tool.\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
         exit(1);
     }
     parent::__construct($name, $version);
 }
示例#6
0
 public function __construct()
 {
     if (defined('PHPUNIT_BETASYNTAX_TESTSUITE') == true) {
         $basepath = __DIR__ . '/../../tests/config/';
     } else {
         $basepath = (string) app()->getBasePath() . '/config/';
     }
     $this->conf['app'] = Conf::load($basepath . 'app.php');
     $this->conf['db'] = Conf::load($basepath . 'db.php');
     $this->conf['email'] = Conf::load($basepath . 'email.php');
     $this->conf['mounts'] = Conf::load($basepath . 'mounts.php');
 }
示例#7
0
 public function setUp()
 {
     $conf = Config::load(CONFPATH . 'socket.php');
     $this->socket = new Socket($conf['host'], $conf['port'], $conf['type'], $conf['long']);
     if (!$this->socket->connect()) {
         $error = 'socket connect error';
         my_log('/data/log/cronJob/doJob.log', $error);
         exit;
     }
     my_log('/data/log/cronJob/doJob.log', '123');
     $this->redis = new RedisModel();
     $this->redis->selectDB(0);
 }
 public function run()
 {
     if (isset($_SESSION[$this->app->config->get('auth.session')])) {
         $this->app->auth = $this->app->user->where('id', $_SESSION[$this->app->config->get('auth.session')])->first();
     }
     //create language cookie
     if (!isset($_COOKIE[$this->app->config->get('lang.language')])) {
         $this->app->setcookie($this->app->config->get('lang.language'), 'en-us', Carbon::parse('+1 week')->timestamp);
         $language = Config::load(INC_ROOT . "/app/lang/en-us.php");
     } else {
         $lang = $this->app->getCookie($this->app->config->get('lang.language'));
         $language = Config::load(INC_ROOT . "/app/lang/{$lang}.php");
     }
     $this->app->lang = $language->get('lang');
     $this->checkRememberMe();
     $this->app->view()->appendData(['auth' => $this->app->auth, 'baseUrl' => $this->app->config->get('app.url'), 'lang' => $this->app->lang]);
 }
示例#9
0
文件: Manager.php 项目: steadweb/nyx
 /**
  * Create a Manager instance using config
  *
  * @param  $path
  * @return static
  * @throws \Exception
  */
 public static function factory($path)
 {
     $pools = array();
     try {
         if (file_exists($path)) {
             $config = Config::load($path);
             foreach ($config->get('workers', array()) as $worker) {
                 $count = array_key_exists('count', $worker) ? $worker['count'] : null;
                 $options = array_key_exists('options', $worker) ? $worker['options'] : array();
                 $pool = new Pool($count);
                 $pool->add(new Worker(new Process(new Command($worker['path'], $options))));
                 $pools[] = $pool;
             }
         }
     } catch (\Exception $e) {
         throw $e;
     }
     $instance = new static($pools);
     return $instance;
 }
示例#10
0
use Slim\Views\Twig;
use Slim\Views\TwigExtension;
use Noodlehaus\Config;
ini_set('display_errors', 1);
error_reporting(E_ALL);
//Define Main Root
define("INC_ROOT", dirname(__DIR__));
//Define Globals
require_once INC_ROOT . "/app/config/globals.php";
//Database Info
require_once CONFIG_ROOT . "/db.php";
//Composer Autoloader
require_once INC_ROOT . "/vendor/autoload.php";
//Create Slim App
$app = new Slim(["debug" => true, "mode" => file_get_contents(INC_ROOT . "/app/mode.php"), "view" => new Twig(), "templates.path" => VIEWS_ROOT, "routes.case_sensitive" => false, "cookies.encrypt" => true, "cookies.secret_key" => "some_secret", "cookies.cipher" => MCRYPT_RIJNDAEL_256, "cookies.cipher_mode" => MCRYPT_MODE_CBC]);
//Hooks
$app->hook('slim.before', function () use($app) {
    $app->view()->appendData(array('siteUrl' => $app->config->get("template_data.url")));
});
//Set Configuration
$app->configureMode($app->config("mode"), function () use($app) {
    $app->config = Config::load(CONFIG_ROOT . "/{$app->config("mode")}.php");
});
//Include Routes
include ROUTES_ROOT . "/routes.php";
//Twig Configuration
$view = $app->view();
$view->parserOptions = ["debug" => $app->config->get("view.debug")];
$view->parserExtensions = [new TwigExtension()];
//Include Filters
require_once FILTERS_ROOT . "/filters.php";
示例#11
0
<?php

/**
 * app/bootstrap.php
 *
 * @author Zangue <*****@*****.**>
 */
use Slim\Slim;
use Noodlehaus\Config;
//session_cache_limiter(false);
//session_start();
ini_set('display_errors', 'On');
// Require all PHP dependencies using the composer autoloader
require ROOT . DS . 'vendor' . DS . 'autoload.php';
require ROOT . DS . CORE_DIR . DS . 'Router.php';
require ROOT . DS . CORE_DIR . DS . 'Model' . DS . 'Model.php';
require ROOT . DS . CORE_DIR . DS . 'Model' . DS . 'ErrorModel.php';
require ROOT . DS . CORE_DIR . DS . 'Controller' . DS . 'Controller.php';
require ROOT . DS . CORE_DIR . DS . 'Controller' . DS . 'ErrorController.php';
require ROOT . DS . CORE_DIR . DS . 'View' . DS . 'View.php';
require APP_DIR . DS . 'Controller' . DS . 'AppController.php';
require APP_DIR . DS . 'Model' . DS . 'AppModel.php';
// Instantiate a new Slim Application
$app = new Slim(['mode' => 'development', 'templates.path' => VIEW_ROOT]);
// Some more things can be done here. Eg, add a custom middleware
// $app->add(new MyMiddleware());
// Load configuration
$app->configureMode($app->config('mode'), function () use($app) {
    $app->config = Config::load(APP_DIR . DS . "Config" . DS . "{$app->mode}.php");
});
示例#12
0
 public function config()
 {
     if (!$this->config) {
         $this->config = \Noodlehaus\Config::load($this->app_path . DIRECTORY_SEPARATOR . 'modvert.yml');
     }
     return $this->config;
 }
示例#13
0
 /**
  * @return Config
  * @throws \Exception
  */
 public static function getConfig()
 {
     return Config::load(static::$configs);
 }
示例#14
0
文件: start.php 项目: harleybalo/doan
define("ASSETS_PATH", DOC_ROOT . "public/assets/");
define("IMAGE_PATH", ASSETS_PATH . "images/");
define("BANNER_PATH", ASSETS_PATH . "images/banners/");
require DOC_ROOT . 'vendor/autoload.php';
$app = new Slim(['mode' => file_get_contents(DOC_ROOT . 'mode.php'), 'view' => new Twig(), 'templates.path' => DOC_ROOT . 'app/views']);
$app->add(new BeforeMiddleware());
$app->add(new CsrfMiddleware());
$mode = $app->config('mode');
//development
if ($mode == "production") {
    $log = $app->getLog();
    $log->setEnabled(true);
    $log->setWriter(new LogWriter());
}
$app->configureMode($mode, function () use($app) {
    $app->config = Config::load(DOC_ROOT . "app/config/{$app->mode}.php");
});
$config = $app->config;
//$app->config('cookies.domain', $app->config->get('cookie.domain'));
$app->config(array('cookies.domain' => $config->get('cookie.domain'), 'cookies.httponly' => $config->get('cookie.httponly'), 'cookies.secret' => $config->get('cookie.secret')));
require 'database.php';
require 'filters.php';
require 'routes.php';
//echo $dbDriver = $config->get('db.host');
//$user = new  \Core\User\User;
//Make the user available everywhere
$app->container->set('user', function () {
    return new User();
});
$app->container->set('images', function () {
    return new Images();
use Slim\Container;
use Slim\Views\Twig;
use Slim\Views\TwigExtension;
use Slim\HttpCache;
use Slim\Csrf;
use Noodlehaus\Config;
session_cache_limiter('nocache');
session_start();
ini_set('display_errors', 'On');
define('PATH_BASE', dirname(__DIR__));
require PATH_BASE . '/vendor/autoload.php';
$container = new Container();
$container['mode_state'] = file_get_contents(PATH_BASE . '/mode.php');
$container['mode'] = function ($container) {
    $file = $container['mode_state'];
    $mode = Config::load(PATH_BASE . "/app/config/{$file}.php");
    return $mode;
};
$container['view'] = function ($c) {
    $view = new Twig(PATH_BASE . '/app/views');
    /*
    		---Add caching in production for performance enhancing as a second Twig parameter---
    	, [
    			'cache' => PATH_BASE . '/app/views/cache'
    	]);*/
    $view->addExtension(new TwigExtension($c['router'], $c['request']->getUri()));
    $view->parserOptions = ['debug' => $c->get('mode')['twig']['debug']];
    return $view;
};
$container['cache'] = function () {
    return new CacheProvider();
示例#16
0
<?php

define('BASEPATH', dirname(__FILE__));
define('CONFPATH', BASEPATH . '/config/');
require_once BASEPATH . '/vendor/autoload.php';
use Noodlehaus\Config;
$conf = Config::load(CONFPATH . 'redis.php');
date_default_timezone_set('PRC');
Resque::setBackend($conf['host'] . ':' . $conf['port'], $conf['db'], $conf['password']);
示例#17
0
文件: start.php 项目: ajtam/auth-php
use alexander\Helpers\Hash;
use alexander\Validation\Validator;
use alexander\Middleware\BeforeMiddleware;
use alexander\Middleware\CsrfMiddleware;
use alexander\Mail\Mailer;
session_cache_limiter(false);
session_start();
// only for tutorial
ini_set('display_errors', 'On');
define('INC_ROOT', dirname(__DIR__));
require INC_ROOT . '/vendor/autoload.php';
$app = new Slim(['mode' => file_get_contents(INC_ROOT . '/mode.php'), 'view' => new Twig(), 'templates.path' => INC_ROOT . '/app/views']);
$app->add(new BeforeMiddleware());
$app->add(new CsrfMiddleware());
$app->configureMode($app->config('mode'), function () use($app) {
    $app->config = Config::load(INC_ROOT . "/app/config/" . substr($app->mode, 0, strlen($app->mode) - 1) . ".php");
});
require 'database.php';
require 'filters.php';
require 'routes.php';
$app->auth = false;
// $user = new \alexander\user\user;
$app->container->set('user', function () {
    return new User();
});
$app->container->singleton('hash', function () use($app) {
    return new Hash($app->config);
});
$app->container->singleton('validation', function () use($app) {
    return new Validator($app->user, $app->hash, $app->auth);
});
示例#18
0
require '../vendor/autoload.php';
require 'core/Middleware.php';
use Noodlehaus\Config;
use Helge\Framework\Session;
use Helge\Framework\Authentication;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\MessageSelector;
use Symfony\Bridge\Twig\Extension\TranslationExtension;
// Start session
Session::start();
Session::cacheLimiter("nocache");
// Instantiate and setup Slim application instance
$app = new \Slim\Slim(array('view' => new \Slim\Views\Twig(), 'templates.path' => '../app/views', 'cookies.encrypt' => true, 'cookies.secret_key' => "pCAyyIHcGmZ9kT1yzsA8YuhNt64oNPvSOBHHUhQYuamRjYKFrQujaLMjTlhS", 'cookies.cipher' => MCRYPT_RIJNDAEL_256, 'cookies.cipher_mode' => MCRYPT_MODE_CBC, 'log.enabled' => true, 'log.level' => \Slim\Log::WARN, 'log.writer' => new \Slim\Logger\DateTimeFileWriter(array('path' => "../log/"))));
// Load the ini config file
$app->container->set("config", Config::load('../app/config.ini'));
// Set the default timezone from config
date_default_timezone_set($app->config->get("localization.timezone"));
// If debugging is enabled we show all errors
if ($app->config->get("development.debugging")) {
    error_reporting(E_ALL);
    ini_set("display_errors", "on");
} else {
    ini_set("display_errors", "off");
}
// Create a translator instance
$app->container->set("translator", new Translator($app->config->get("localization.language"), new MessageSelector()));
$app->translator->setFallbackLocales(['nb_NO']);
$app->translator->addLoader('php', new \Symfony\Component\Translation\Loader\PhpFileLoader());
// Include require all route files in the routes directory
$languages = glob("../app/lang/*.php");
示例#19
0
 /**
  * @return Config
  */
 protected function getConfiguration()
 {
     if (!$this->configuration instanceof Config) {
         $paths = [$this->rootPath . '/config/config.json'];
         if (is_readable($this->rootPath . '/config/config.local.json')) {
             $paths[] = $this->rootPath . '/config/config.local.json';
         }
         $this->configuration = Config::load($paths);
     }
     return $this->configuration;
 }
示例#20
0
文件: app.php 项目: luptiwahyu/Blog
<?php

use Noodlehaus\Config;
require ROOT_PATH . '/vendor/autoload.php';
session_start();
session_cache_limiter(false);
ini_set('display_errors', 'On');
date_default_timezone_set('Asia/Jakarta');
// Instantiate the app
$app = new \Slim\Slim(array('mode' => 'development', 'debug' => true, 'templates.path' => ROOT_PATH . '/src', 'view' => new \Slim\Views\Twig()));
// Configuration application mode
$app->configureMode($app->config('mode'), function () use($app) {
    $app->config = Config::load(ROOT_PATH . "/app/config/{$app->mode}.php");
});
// Initial authentication
$app->auth = false;
// Set up dependencies
require ROOT_PATH . '/app/services/dependencies.php';
// Register middleware
require ROOT_PATH . '/app/services/middleware.php';
// Set up database
require ROOT_PATH . '/app/services/database.php';
// Filter routes
require ROOT_PATH . '/app/services/filter.php';
// Helpers class and function
require ROOT_PATH . '/src/Helpers/Helper.php';
// Register routes
require ROOT_PATH . '/app/routes.php';
示例#21
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
$app = new \Slim\Slim(array('mode' => 'debug', 'templates.path' => 'www/public_html'));
#region "Configuracion"
$confDir = __DIR__ . '/config.' . $app->getMode() . '.json';
if (file_exists($confDir)) {
    $conf = \Noodlehaus\Config::load($confDir);
    $app->config($conf->get("application"));
}
#endregion
#region "Custom Errors on production mode"
$app->error(function (\Exception $ex) use($app) {
    $app->render('/error/error.html');
});
#endregion
#region Carga de Routers
$app->hook("slim.before.router", function () use($app) {
    require_once __DIR__ . '/src/router/router.php';
});
#endregion
//$app->map('/',function() use($app){
//    $path = $app->request()->getPathInfo();
//    echo "$path <br />";
//    echo "pagina de inicio";
//})->via('GET');
$app->run();
示例#22
0
    private static $length = 0;
    public static function classLoader($class)
    {
        if (static::$length == 0) {
            static::$base_dir = __DIR__ . '/perrich/';
            static::$length = strlen(static::PREFIX);
        }
        if (strncmp(static::PREFIX, $class, static::$length) !== 0) {
            // no, move to the next registered autoloader
            return;
        }
        $relative_class = substr($class, static::$length);
        $relative_class = str_replace('\\', '/', $relative_class);
        $pos = strrpos($relative_class, '/');
        if ($pos !== false) {
            $file = static::$base_dir . strtolower(substr($relative_class, 0, $pos)) . substr($relative_class, $pos) . '.php';
        } else {
            $file = static::$base_dir . $relative_class . '.php';
        }
        if (file_exists($file)) {
            require $file;
        }
    }
}
spl_autoload_register(array('PerrichLoader', 'classLoader'));
// ------------------------------------------------------
// Load configuration
use Noodlehaus\Config;
$conf = Config::load(__DIR__ . '/config.json');
// update logfile to use current directory
$conf->set('logfile', __DIR__ . '/' . $conf->get('logfile'));
示例#23
0
$container['flash'] = function ($c) {
    return new \Slim\Flash\Messages();
};
$container['notFoundHandler'] = function ($c) {
    return function ($request, $response) use($c) {
        return $c['view']->render($response, 'errors/404.twig')->withStatus(404)->withHeader('Content-Type', 'text/html');
    };
};
$c['errorHandler'] = function ($c) {
    return function ($request, $response, $exception) use($c) {
        return $c['view']->render($response, 'errors/500.twig', ['messageM' => $exception->getMessage()])->withStatus(500)->withHeader('Content-Type', 'text/html');
    };
};
//anything application specific can be preserved
$container['application'] = function ($c) use($conf) {
    return $conf->get('application');
};
//set up markdown processor
$container['md_parser'] = function ($c) {
    $parser = new Parsedown();
    return $parser;
};
//toc - all documents and slugs
use Noodlehaus\Config;
$container['toc'] = function ($c) {
    $dir_name = $c['application']['docs_path'];
    $index_file_name = $c['application']['docs_index_file'];
    $indexFile = "{$dir_name}/{$index_file_name}";
    $toc = Config::load($indexFile)->get('toc');
    return $toc;
};
示例#24
0
文件: index.php 项目: BenHicksy/top5
<?php

// All file paths relative to root
chdir(dirname(__DIR__));
require 'vendor/autoload.php';
session_start();
//simulate customer login
$_SESSION['customer_id'] = 1;
use Noodlehaus\Config;
$conf = Config::load('app/boot/settings.yaml');
$settings = $conf->get('settings', []);
// Instantiate Slim
$app = new \Slim\App(['settings' => $settings]);
//require 'app/model/AuthService.php';
require 'app/model/PlacesService.php';
require 'app/boot/dependencies.php';
require 'app/boot/middleware.php';
// Register the routes
require 'app/src/routes.php';
$app->run();
示例#25
0
use Codecourse\User\User;
use Codecourse\Mail\Mailer;
use Codecourse\Helpers\Hash;
use Codecourse\Validation\Validator;
use Codecourse\Middleware\BeforeMiddleware;
use Codecourse\Middleware\CsrfMiddleware;
session_cache_limiter(false);
session_start();
ini_set('display_errors', 'On');
define('INC_ROOT', dirname(__DIR__));
require INC_ROOT . '../vendor/autoload.php';
$app = new Slim(['mode' => file_get_contents(INC_ROOT . '/mode.php'), 'view' => new Twig(), 'templates.path' => INC_ROOT . '/app/views']);
$app->add(new BeforeMiddleware());
$app->add(new CsrfMiddleware());
$app->configureMode($app->config('mode'), function () use($app) {
    $app->config = Config::load(INC_ROOT . "/app/config/development.php");
});
require 'database.php';
require 'filters.php';
require 'routes.php';
$app->auth = false;
// the user is initially unauthenticated
$app->container->set('user', function () {
    return new User();
});
$app->container->singleton('hash', function () use($app) {
    return new Hash($app->config);
});
$app->container->singleton('validation', function () use($app) {
    return new Validator($app->user, $app->hash, $app->auth);
});
示例#26
0
use Slim\Views\Twig;
use Slim\Views\TwigExtension;
use Noodlehaus\Config;
use Myproject\User\User;
use Myproject\Helpers\Hash;
use Myproject\Validation\Validator;
use Myproject\Middleware\BeforeMiddleware;
session_cache_limiter(false);
session_start();
ini_set('display_errors', 'On');
define(INC_ROOT, dirname(__DIR__));
require INC_ROOT . '/vendor/autoload.php';
$app = new Slim(['mode' => file_get_contents(INC_ROOT . '/mode.php'), 'view' => new Twig(), 'templates.path' => INC_ROOT . '/app/views']);
$app->add(new BeforeMiddleware());
$app->configureMode($app->config('mode'), function () use($app) {
    $app->config = Config::load(INC_ROOT . "/app/config/{$app->mode}.php");
});
require 'database.php';
require 'routes.php';
$app->auth = false;
$app->container->set('user', function () {
    return new User();
});
$app->container->singleton('hash', function () use($app) {
    return new Hash($app->config);
});
$app->container->singleton('validation', function () use($app) {
    return new Validator($app->user);
});
$view = $app->view;
$view->parserOptions = ['debug' => $app->config->get('twig.debug')];
示例#27
0
<?php

#session start
session_start();
#dependencies included via composer autoload
require '../vendor/autoload.php';
$conf = \Noodlehaus\Config::load(__DIR__ . DIRECTORY_SEPARATOR . 'settings.php');
#encoding
mb_internal_encoding($conf['app.encoding.mb_internal_encoding']);
mb_http_output($conf['app.encoding.mb_http_output']);
#timezone
date_default_timezone_set($conf['app.timezone']);
#Database Configuration
$serviceContainer = \Propel\Runtime\Propel::getServiceContainer();
$serviceContainer->checkVersion('2.0.0-dev');
$serviceContainer->setAdapterClass($conf['app.namespace'], 'mysql');
$manager = new \Propel\Runtime\Connection\ConnectionManagerSingle();
$manager->setConfiguration(['dsn' => 'mysql:host=' . $conf['app.db.host'] . ';port=' . $conf['app.db.port'] . ';dbname=' . $conf['app.db.name'], 'user' => $conf['app.db.username'], 'password' => $conf['app.db.password'], 'settings' => ['charset' => $conf['app.db.charset'], 'queries' => []], 'classname' => '\\Propel\\Runtime\\Connection\\ConnectionWrapper']);
$manager->setName($conf['app.namespace']);
$serviceContainer->setConnectionManager($conf['app.namespace'], $manager);
$serviceContainer->setDefaultDatasource($conf['app.namespace']);
# End of Propel Database
#SLIM instantiate
$app = new \Slim\App();
$container = $app->getContainer();
$container['view'] = function ($container) use($conf) {
    $view = new \Slim\Views\Twig($conf['app.template.dir'], ['cache' => $conf['app.template.cache'], 'debug' => $conf['app.template.debug'], 'auto_reload' => $conf['app.template.auto_reload']]);
    $view->addExtension(new \Slim\Views\TwigExtension($container['router'], $container['request']->getUri()));
    $view->addExtension(new Twig_Extension_Debug());
    $view->offsetSet('userGlobalData', App::getUser());
    return $view;