Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Define only Yii framework path in configuration files instead of yi…

…i.php, yiit.php and yiilite.php.

- Better CSS styles for showDebug().
  • Loading branch information...
commit abd1dd90c90f025bc39c560a96459672d8314e63 1 parent 72b89c9
@janisto authored
View
35 Environment.php
@@ -1,9 +1,8 @@
<?php
-
/**
* @name Environment
* @author Jani Mikkonen
- * @version 1.0
+ * @version 1.1
* @license public domain (http://unlicense.org)
* @package extensions.environment
* @link https://github.com/janisto/yii-environment
@@ -28,7 +27,9 @@ class Environment
private $_mode;
// Environment Yii properties
+ public $yiiFramework; // path to Yii framework
public $yiiPath; // path to yii.php
+ public $yiicPath; // path to yiic.php
public $yiitPath; // path to yiit.php
public $yiilitePath; // path to yiilite.php
public $yiiLite; // boolean
@@ -108,13 +109,15 @@ private function getMode($mode = null)
private function setEnvironment()
{
// Load main config
- $fileMainConfig = dirname(__FILE__).DIRECTORY_SEPARATOR.constant(get_class($this).'::CONFIG_DIR').DIRECTORY_SEPARATOR.'main.php';
+ $fileMainConfig = dirname(__FILE__).DIRECTORY_SEPARATOR.constant(get_class($this).'::CONFIG_DIR')
+ .DIRECTORY_SEPARATOR.'main.php';
if (!file_exists($fileMainConfig))
throw new Exception('Cannot find main config file "'.$fileMainConfig.'".');
$configMain = require($fileMainConfig);
// Load specific config
- $fileSpecificConfig = dirname(__FILE__).DIRECTORY_SEPARATOR.constant(get_class($this).'::CONFIG_DIR').DIRECTORY_SEPARATOR.'mode_'.strtolower($this->_mode).'.php';
+ $fileSpecificConfig = dirname(__FILE__).DIRECTORY_SEPARATOR.constant(get_class($this).'::CONFIG_DIR')
+ .DIRECTORY_SEPARATOR.'mode_'.strtolower($this->_mode).'.php';
if (!file_exists($fileSpecificConfig))
throw new Exception('Cannot find mode specific config file "'.$fileSpecificConfig.'".');
$configSpecific = require($fileSpecificConfig);
@@ -123,17 +126,27 @@ private function setEnvironment()
$config = self::mergeArray($configMain, $configSpecific);
// If one exists, load local config
- $fileLocalConfig = dirname(__FILE__).DIRECTORY_SEPARATOR.constant(get_class($this).'::CONFIG_DIR').DIRECTORY_SEPARATOR.'local.php';
+ $fileLocalConfig = dirname(__FILE__).DIRECTORY_SEPARATOR.constant(get_class($this).'::CONFIG_DIR')
+ .DIRECTORY_SEPARATOR.'local.php';
if (file_exists($fileLocalConfig)) {
// Merge local config into previously merged config
$configLocal = require($fileLocalConfig);
$config = self::mergeArray($config, $configLocal);
}
+ // Normalize the framework path
+ $framework = str_replace('\\', DIRECTORY_SEPARATOR, realpath($config['yiiFramework']));
+
+ if(!is_dir($framework)) {
+ throw new Exception('Invalid Yii framework path "'.$config['yiiFramework'].'".');
+ }
+
// Set attributes
- $this->yiiPath = $config['yiiPath'];
- $this->yiitPath = $config['yiitPath'];
- $this->yiilitePath = $config['yiilitePath'];
+ $this->yiiFramework = $framework;
+ $this->yiiPath = $framework.DIRECTORY_SEPARATOR.'yii.php';
+ $this->yiicPath = $framework.DIRECTORY_SEPARATOR.'yiic.php';
+ $this->yiitPath = $framework.DIRECTORY_SEPARATOR.'yiit.php';
+ $this->yiilitePath = $framework.DIRECTORY_SEPARATOR.'yiilite.php';
$this->yiiLite = $config['yiiLite'];
$this->yiiDebug = $config['yiiDebug'];
$this->yiiTraceLevel = $config['yiiTraceLevel'];
@@ -165,8 +178,10 @@ public function runYiiStatics()
*/
public function showDebug()
{
- echo '<div style="position: absolute; bottom: 0; z-index: 99; height: 250px; overflow: auto; background-color: #ddd; color: #000; border: 1px solid #000; margin: 5px; padding: 5px;">
- <pre>'.htmlspecialchars(print_r($this, true)).'</pre></div>';
+ print '<div style="position: absolute; left: 0; width: 100%; height: 250px; overflow: auto;'
+ .'bottom: 0; z-index: 9999; color: #000; margin: 0; border-top: 1px solid #000;">'
+ .'<pre style="margin: 0; background-color: #ddd; padding: 5px;">'
+ .htmlspecialchars(print_r($this, true)).'</pre></div>';
}
/**
View
2  ExampleEnvironment.php
@@ -3,7 +3,7 @@
require('Environment.php');
/**
- * This is an example Environment, for when you want to use a custom SERVER_VAR
+ * This is an example Environment when you want to use a custom SERVER_VAR
* or CONFIG_DIR, or want to use other than the predefined modes.
*
* If you use the extended class, don't forget to require and create it from your
View
11 README.md
@@ -3,6 +3,17 @@ yii-environment
Predefine configurations for use in different environments, like development, testing, staging and production.
+Changelog
+---------
+
+### v1.1
+
+- Define only Yii framework path in configuration files instead of yii.php, yiit.php and yiilite.php.
+- Better CSS styles for showDebug().
+
+### v1.0
+
+- Initial version.
License
-------
View
6 example-config/local.php
@@ -8,10 +8,8 @@
return array(
- // Set yiiPath (relative to Environment.php)
- 'yiiPath'=>dirname(__FILE__) . '/../../../yii/framework/yii.php',
- 'yiitPath'=>dirname(__FILE__) . '/../../../yii/framework/yiit.php',
- 'yiilitePath'=>dirname(__FILE__) . '/../../../yii/framework/yiilite.php',
+ // Set Yii framework path relative to Environment.php
+ 'yiiFramework'=>dirname(__FILE__) . '/../../../../yii/framework',
// Include yiilite if this is set to true. Performance boost if APC cache is in use.
'yiiLite'=>false,
View
6 example-config/main.php
@@ -7,10 +7,8 @@
return array(
- // Set yiiPath (relative to Environment.php)
- 'yiiPath'=>dirname(__FILE__) . '/../../../yii/framework/yii.php',
- 'yiitPath'=>dirname(__FILE__) . '/../../../yii/framework/yiit.php',
- 'yiilitePath'=>dirname(__FILE__) . '/../../../yii/framework/yiilite.php',
+ // Set Yii framework path relative to Environment.php
+ 'yiiFramework'=>dirname(__FILE__) . '/../../../yii/framework',
// Include yiilite if this is set to true. Performance boost if APC cache is in use.
'yiiLite'=>false,
View
6 example-config/mode_development.php
@@ -11,10 +11,8 @@
return array(
- // Set yiiPath (relative to Environment.php)
- 'yiiPath'=>dirname(__FILE__) . '/../../../yii/framework/yii.php',
- 'yiitPath'=>dirname(__FILE__) . '/../../../yii/framework/yiit.php',
- 'yiilitePath'=>dirname(__FILE__) . '/../../../yii/framework/yiilite.php',
+ // Set Yii framework path relative to Environment.php
+ 'yiiFramework'=>dirname(__FILE__) . '/../../../../yii/framework',
// Include yiilite if this is set to true. Performance boost if APC cache is in use.
'yiiLite'=>false,
View
6 example-config/mode_production.php
@@ -10,10 +10,8 @@
return array(
- // Set yiiPath (relative to Environment.php)
- //'yiiPath'=>dirname(__FILE__) . '/../../../yii/framework/yii.php',
- //'yiitPath'=>dirname(__FILE__) . '/../../../yii/framework/yiit.php',
- //'yiilitePath'=>dirname(__FILE__) . '/../../../yii/framework/yiilite.php',
+ // Set Yii framework path relative to Environment.php
+ //'yiiFramework'=>dirname(__FILE__) . '/../../../yii/framework',
// Include yiilite if this is set to true. Performance boost if APC cache is in use.
'yiiLite'=>true,
View
6 example-config/mode_staging.php
@@ -10,10 +10,8 @@
return array(
- // Set yiiPath (relative to Environment.php)
- //'yiiPath'=>dirname(__FILE__) . '/../../../yii/framework/yii.php',
- //'yiitPath'=>dirname(__FILE__) . '/../../../yii/framework/yiit.php',
- //'yiilitePath'=>dirname(__FILE__) . '/../../../yii/framework/yiilite.php',
+ // Set Yii framework path relative to Environment.php
+ //'yiiFramework'=>dirname(__FILE__) . '/../../../yii/framework',
// Include yiilite if this is set to true. Performance boost if APC cache is in use.
'yiiLite'=>true,
View
6 example-config/mode_test.php
@@ -10,10 +10,8 @@
return array(
- // Set yiiPath (relative to Environment.php)
- 'yiiPath'=>dirname(__FILE__) . '/../../../yii/framework/yii.php',
- 'yiitPath'=>dirname(__FILE__) . '/../../../yii/framework/yiit.php',
- 'yiilitePath'=>dirname(__FILE__) . '/../../../yii/framework/yiilite.php',
+ // Set Yii framework path relative to Environment.php
+ 'yiiFramework'=>dirname(__FILE__) . '/../../../../yii/framework',
// Include yiilite if this is set to true. Performance boost if APC cache is in use.
'yiiLite'=>false,
View
8 example-index/.example-htaccess
@@ -1,2 +1,6 @@
-# Set Yii environment
-SetEnv YII_ENVIRONMENT DEVELOPMENT
+# Set Yii environment:
+
+#SetEnv YII_ENVIRONMENT DEVELOPMENT
+#SetEnv YII_ENVIRONMENT STAGING
+#SetEnv YII_ENVIRONMENT TEST
+SetEnv YII_ENVIRONMENT PRODUCTION
View
3  example-index/cron.php
@@ -1,4 +1,7 @@
<?php
+/**
+ * This is the bootstrap file for console application.
+ */
// Set environment
require_once(dirname(__FILE__) . '/protected/extensions/environment/Environment.php');
View
3  example-index/index.php
@@ -1,4 +1,7 @@
<?php
+/**
+ * This is the bootstrap file for web application.
+ */
// Set environment
require_once(dirname(__FILE__) . '/protected/extensions/environment/Environment.php');
Please sign in to comment.
Something went wrong with that request. Please try again.