本文整理汇总了PHP中static::env方法的典型用法代码示例。如果您正苦于以下问题:PHP static::env方法的具体用法?PHP static::env怎么用?PHP static::env使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类static
的用法示例。
在下文中一共展示了static::env方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor
*
* @param string|RFormatter $format Output format ID, or formatter instance defaults to 'html'
*/
public function __construct($format = 'html')
{
static $didIni = false;
if (!$didIni) {
$didIni = true;
foreach (array_keys(static::$config) as $key) {
$iniVal = get_cfg_var('ref.' . $key);
print_r($iniVal);
if ($iniVal !== false) {
static::$config[$key] = $iniVal;
}
}
}
if ($format instanceof RFormatter) {
$this->fmt = $format;
} else {
$format = __NAMESPACE__ . '\\' . (isset(static::$config['formatters'][$format]) ? static::$config['formatters'][$format] : 'R' . ucfirst($format) . 'Formatter');
if (!class_exists($format, true)) {
throw new \Exception(sprintf('%s class not found', $format));
}
$this->fmt = new $format();
}
if (static::$env) {
return;
}
static::$env = array('is54' => version_compare(PHP_VERSION, '5.4') >= 0, 'is546' => version_compare(PHP_VERSION, '5.4.6') >= 0, 'is56' => version_compare(PHP_VERSION, '5.6') >= 0, 'curlActive' => function_exists('curl_version'), 'mbStr' => function_exists('mb_detect_encoding'), 'supportsDate' => strncasecmp(PHP_OS, 'WIN', 3) !== 0 || version_compare(PHP_VERSION, '5.3.10') >= 0);
}
示例2: __construct
/**
* Instantiates this class
*
* @param int $id ID of the attachment
*/
public function __construct($id)
{
// Check if post exists
if (!is_string(get_post_status($id))) {
throw new \Exception("Post does not exist");
}
// Check if post is an attachment
if (get_post_type($id) != 'attachment') {
throw new \Exception("Target post is not an attachment");
}
// Check if attachment have a file path to use
$this->partial_path = get_post_meta($id, '_wp_attached_file', true);
if (!$this->partial_path) {
throw new \Exception("Target post does not have a file path to be used");
}
// Collect environment information if not already available
if (is_null(static::$env)) {
static::$env = static::__getEnvInfo();
}
// Get WordPress meta data
$default_wordpress_meta = ['sizes' => []];
$this->wordpress_meta = get_post_meta($id, '_wp_attachment_metadata', true) ?: $default_wordpress_meta;
// Get plugin meta data
$default_plugin_meta = ['sizes' => []];
$plugin_meta_json = get_post_meta($id, Config::ATTACHMENT_META_KEY, true);
$this->plugin_meta = $plugin_meta_json ? json_decode($plugin_meta_json, true) : $default_plugin_meta;
// Store post id
$this->id = $id;
}
示例3: loadEnv
public static function loadEnv($filepath, array $options = [])
{
$loader = (new Loader($filepath))->raiseExceptions(true)->parse();
if (!empty($options)) {
extract($options);
}
if (isset($expect) && is_array($expect)) {
$loader = $loader->expect($expect);
}
static::$env = $loader->toArray();
}
示例4: detectEnvironment
/**
* Detect environment
*
* By default check
*
* @return string env
*/
public static function detectEnvironment($request = null)
{
if (!empty(static::$env)) {
return static::$env;
}
$rules = self::get('env');
$request = $request ? $request : Request::createFromGlobals();
$host = $request->getHost();
foreach ($rules as $env => $rule) {
if (is_callable($rule)) {
static::$env = $env;
} elseif (preg_match($rule, $host)) {
static::$env = $env;
break;
}
}
static::loadEnvironment(static::$env);
return static::$env;
}
示例5: dataFixtures
/**
* Generate data for ApiTestCaseV2
*
* @param string $fixtures patch to fixtures directory
* @return array
* @throws \Scalr\System\Config\Exception\YamlException
*/
public static function dataFixtures($fixtures)
{
// set config
static::$testUserId = \Scalr::config('scalr.phpunit.userid');
static::$user = User::findPk(static::$testUserId);
static::$testEnvId = \Scalr::config('scalr.phpunit.envid');
static::$env = Environment::findPk(static::$testEnvId);
$data = [];
foreach (new DirectoryIterator($fixtures) as $fileInfo) {
if ($fileInfo->isFile()) {
$class = __NAMESPACE__ . '\\' . ucfirst($fileInfo->getBasename('.yaml'));
if (class_exists($class)) {
/* @var $object TestDataFixtures */
$object = new $class(Yaml::load($fileInfo->getPathname())->toArray());
$object->prepareTestData();
$data = array_merge($data, $object->preparePathInfo());
}
}
}
return $data;
}
示例6: init
/**
* Initializes the framework. This can only be called once.
*
* @access public
* @return void
*/
public static function init($config)
{
if (static::$initialized) {
throw new \Exception("You can't initialize Fuel more than once.");
}
register_shutdown_function('fuel_shutdown_handler');
set_exception_handler('fuel_exception_handler');
set_error_handler('fuel_error_handler');
// Start up output buffering
ob_start();
static::$profiling = isset($config['profiling']) ? $config['profiling'] : false;
if (static::$profiling) {
\Profiler::init();
\Profiler::mark(__METHOD__ . ' Start');
}
static::$cache_dir = isset($config['cache_dir']) ? $config['cache_dir'] : APPPATH . 'cache/';
static::$caching = isset($config['caching']) ? $config['caching'] : false;
static::$cache_lifetime = isset($config['cache_lifetime']) ? $config['cache_lifetime'] : 3600;
if (static::$caching) {
static::$path_cache = static::cache('Fuel::path_cache');
}
\Config::load($config);
static::$_paths = array_merge(\Config::get('module_paths', array()), array(APPPATH, COREPATH));
static::$is_cli = (bool) (php_sapi_name() == 'cli');
if (!static::$is_cli) {
if (\Config::get('base_url') === null) {
\Config::set('base_url', static::generate_base_url());
}
\Uri::detect();
}
// Run Input Filtering
\Security::clean_input();
static::$env = \Config::get('environment');
static::$locale = \Config::get('locale');
//Load in the packages
foreach (\Config::get('always_load.packages', array()) as $package) {
static::add_package($package);
}
// Set some server options
setlocale(LC_ALL, static::$locale);
// Always load classes, config & language set in always_load.php config
static::always_load();
static::$initialized = true;
if (static::$profiling) {
\Profiler::mark(__METHOD__ . ' End');
}
}
示例7: detectEnvironment
/**
*
*/
private function detectEnvironment()
{
static::$env = ['developing' => env('APP_ENV', 'PRODUCTION') !== 'PRODUCTION', 'app_key' => env('APP_KEY', '[set me]'), 'debugging' => env('DEBUG', FALSE), 'testing' => env('TESTING', FALSE)];
}
示例8: setUpBeforeClass
/**
* Add test environment, test Acl, setups test user, environment and API key
*/
public static function setUpBeforeClass()
{
if (!Scalr::getContainer()->config->defined('scalr.phpunit.apiv2')) {
static::markTestIncomplete('phpunit apiv2 configurations is invalid');
}
if (Scalr::getContainer()->config->defined('scalr.phpunit.apiv2.params.max_results')) {
static::$maxResults = Scalr::config('scalr.phpunit.apiv2.params.max_results');
}
static::$testUserId = Scalr::config('scalr.phpunit.apiv2.userid');
static::$user = User::findPk(static::$testUserId);
static::$testUserType = static::$user->type;
static::$testEnvId = Scalr::config('scalr.phpunit.apiv2.envid');
static::$env = Environment::findPk(static::$testEnvId);
if (empty(static::$user) || empty(static::$env)) {
static::markTestIncomplete('Either test environment or user is invalid.');
}
$apiKeyName = static::getTestName();
$apiKeyEntity = ApiKeyEntity::findOne([['name' => $apiKeyName], ['userId' => static::$testUserId]]);
if (empty($apiKeyEntity)) {
$apiKeyEntity = new ApiKeyEntity(static::$testUserId);
$apiKeyEntity->name = $apiKeyName;
$apiKeyEntity->save();
}
static::$apiKeyEntity = $apiKeyEntity;
static::$defaultAcl = Scalr::getContainer()->acl;
static::$data = [static::$testEnvId => []];
if (empty(static::$fullAccessAcl)) {
static::$fullAccessAcl = new ApiTestAcl();
static::$fullAccessAcl->setDb(Scalr::getContainer()->adodb);
static::$fullAccessAcl->createTestAccountRole(static::$user->getAccountId(), static::getTestName(ApiFixture::ACL_FULL_ACCESS), ApiTestAcl::ROLE_ID_FULL_ACCESS);
static::$fullAccessAcl->aclType = ApiFixture::ACL_FULL_ACCESS;
}
if (empty(static::$readOnlyAccessAcl)) {
static::$readOnlyAccessAcl = new ApiTestAcl();
static::$readOnlyAccessAcl->setDb(Scalr::getContainer()->adodb);
static::$readOnlyAccessAcl->createTestAccountRole(static::$user->getAccountId(), static::getTestName(ApiFixture::ACL_READ_ONLY_ACCESS), ApiTestAcl::ROLE_ID_READ_ONLY_ACCESS);
static::$readOnlyAccessAcl->aclType = ApiFixture::ACL_READ_ONLY_ACCESS;
}
}
示例9: init
/**
* Initializes the framework. This can only be called once.
*
* @access public
* @return void
*/
public static function init($config)
{
\Config::load($config);
if (static::$initialized) {
throw new \Fuel_Exception("You can't initialize Fuel more than once.");
}
register_shutdown_function('fuel_shutdown_handler');
set_exception_handler('fuel_exception_handler');
set_error_handler('fuel_error_handler');
// Start up output buffering
ob_start(\Config::get('ob_callback', null));
static::$profiling = \Config::get('profiling', false);
if (static::$profiling) {
\Profiler::init();
\Profiler::mark(__METHOD__ . ' Start');
}
static::$cache_dir = \Config::get('cache_dir', APPPATH . 'cache/');
static::$caching = \Config::get('caching', false);
static::$cache_lifetime = \Config::get('cache_lifetime', 3600);
if (static::$caching) {
static::$path_cache = static::cache('Fuel::path_cache');
}
// set a default timezone if one is defined
static::$timezone = \Config::get('default_timezone') ?: date_default_timezone_get();
date_default_timezone_set(static::$timezone);
// set the encoding and locale to use
static::$encoding = \Config::get('encoding', static::$encoding);
static::$locale = \Config::get('locale', static::$locale);
static::$_paths = array(APPPATH, COREPATH);
if (!static::$is_cli) {
if (\Config::get('base_url') === null) {
\Config::set('base_url', static::generate_base_url());
}
\Uri::detect();
}
// Run Input Filtering
\Security::clean_input();
static::$env = \Config::get('environment');
\Event::register('shutdown', 'Fuel::finish');
//Load in the packages
foreach (\Config::get('always_load.packages', array()) as $package => $path) {
is_string($package) and $path = array($package => $path);
static::add_package($path);
}
// Load in the routes
\Config::load('routes', true);
\Router::add(\Config::get('routes'));
// Set locale
static::$locale and setlocale(LC_ALL, static::$locale);
// Always load classes, config & language set in always_load.php config
static::always_load();
static::$initialized = true;
if (static::$profiling) {
\Profiler::mark(__METHOD__ . ' End');
}
}
示例10: isTracking
/**
* Helper method to determine if track calls should be respected
*
* It is possible to filter tracking calls based on environment
* and this method will make sure that is respected
* @return bool
**/
protected static function isTracking()
{
if (($env = static::$_config['env']) && $env === '*') {
return true;
}
if (!static::$env) {
static::$env = Environment::get();
}
return is_array($env) ? in_array(static::$env, $env) : static::$env === $env;
}
示例11: __construct
/**
* Constructor
*
* @param string|RFormatter $format Output format ID, or formatter instance defaults to 'html'
*/
public function __construct($format = 'html')
{
if ($format instanceof RFormatter) {
$this->fmt = $format;
} else {
$format = isset(static::$config['formatters'][$format]) ? static::$config['formatters'][$format] : 'R' . ucfirst($format) . 'Formatter';
if (!class_exists($format, false)) {
throw new \Exception(sprintf('%s class not found', $format));
}
$this->fmt = new $format();
}
if (static::$env) {
return;
}
static::$env = array('is54' => version_compare(PHP_VERSION, '5.4') >= 0, 'is546' => version_compare(PHP_VERSION, '5.4.6') >= 0, 'curlActive' => function_exists('curl_version'), 'mbStr' => function_exists('mb_detect_encoding'), 'supportsDate' => strncasecmp(PHP_OS, 'WIN', 3) !== 0 || version_compare(PHP_VERSION, '5.3.10') >= 0);
}
示例12: detect_environment
/**
* **Detect and configure the environment.**
*
* @throws ConfigurationException
*/
private function detect_environment()
{
static::$env = ['developing' => env('APP_ENV', 'PRODUCTION') !== 'PRODUCTION', 'app_key' => env('APP_KEY', '[set me]'), 'debugging' => env('DEBUG', FALSE), 'testing' => env('TESTING', FALSE)];
// register this factory
Forge::set([static::class, 'AppFactory'], $this);
}
示例13: loadData
/**
* Generate data for ApiTest
*
* @param string $fixtures patch to fixtures directory
* @param string $type api specifications type
* @return array
* @throws \Scalr\System\Config\Exception\YamlException
*/
public static function loadData($fixtures, $type)
{
// set config
static::$testUserId = \Scalr::config('scalr.phpunit.apiv2.userid');
static::$user = User::findPk(static::$testUserId);
static::$testEnvId = \Scalr::config('scalr.phpunit.apiv2.envid');
static::$env = Environment::findPk(static::$testEnvId);
$data = [];
foreach (new ApiFixtureIterator(new DirectoryIterator($fixtures), $type) as $fileInfo) {
$class = __NAMESPACE__ . '\\' . ucfirst($fileInfo->getBasename('.yaml'));
try {
/* @var $object ApiFixture */
$object = new $class(Yaml::load($fileInfo->getPathname())->toArray(), $type);
$object->prepareTestData();
$pathInfo = $object->preparePathInfo();
} catch (Exception $e) {
$pathInfo = [array_merge([$class, $e, null, null, null], static::$defaultOperation)];
}
$data = array_merge($data, $pathInfo);
}
return $data;
}
示例14: env
/**
* Get or set the system environment
*
* @param string $environment The system environment to be set
* @return string
*/
public static function env($environment = null)
{
if ($environment) {
static::$env = $environment;
}
return static::$env;
}
示例15: setUpBeforeClass
/**
* Setups test user, environment and API key
*
* @beforeClass
*
* @throws \Scalr\Exception\ModelException
*/
public static function setUpBeforeClass()
{
static::$testUserId = \Scalr::config('scalr.phpunit.userid');
static::$user = User::findPk(static::$testUserId);
static::$testEnvId = \Scalr::config('scalr.phpunit.envid');
static::$env = Environment::findPk(static::$testEnvId);
$apiKeyName = static::getTestName();
$apiKeyEntity = ApiKeyEntity::findOne([['name' => $apiKeyName], ['userId' => static::$testUserId]]);
if (empty($apiKeyEntity)) {
$apiKeyEntity = new ApiKeyEntity(static::$testUserId);
$apiKeyEntity->name = $apiKeyName;
$apiKeyEntity->save();
}
static::$apiKeyEntity = $apiKeyEntity;
}