From 91f6c6cb00948f5ac3a97f550a05727e12f6efa9 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov Date: Thu, 23 May 2013 20:03:59 +0400 Subject: [PATCH 001/122] jQuery UI DatePicker widget --- framework/yii/jui/DatePicker.php | 101 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 framework/yii/jui/DatePicker.php diff --git a/framework/yii/jui/DatePicker.php b/framework/yii/jui/DatePicker.php new file mode 100644 index 0000000..4f68d56 --- /dev/null +++ b/framework/yii/jui/DatePicker.php @@ -0,0 +1,101 @@ + 'yii/jui/datepicker/i18n/ru', + * 'model' => $model, + * 'attribute' => 'country', + * 'clientOptions' => array( + * 'dateFormat' => 'yy-mm-dd', + * ), + * )); + * ``` + * + * The following example will use the name property instead: + * + * ```php + * echo DatePicker::widget(array( + * 'language' => 'yii/jui/datepicker/i18n/ru', + * 'name' => 'country', + * 'clientOptions' => array( + * 'dateFormat' => 'yy-mm-dd', + * ), + * )); + *``` + * + * @see http://api.jqueryui.com/datepicker/ + * @author Alexander Kochetov + * @since 2.0 + */ +class DatePicker extends Widget +{ + /** + * @var string the jQuery UI datepicker widget language bundle. + */ + public $language = false; + /** + * @var \yii\base\Model the data model that this widget is associated with. + */ + public $model; + /** + * @var string the model attribute that this widget is associated with. + */ + public $attribute; + /** + * @var string the input name. This must be set if [[model]] and [[attribute]] are not set. + */ + public $name; + /** + * @var string the input value. + */ + public $value; + + + /** + * Renders the widget. + */ + public function run() + { + echo $this->renderField(); + $this->registerWidget('datepicker'); + if ($this->language !== false) { + $this->getView()->registerAssetBundle($this->language); + } + } + + /** + * Renders the DatePicker field. If [[model]] has been specified then it will render an active field. + * If [[model]] is null or not from an [[Model]] instance, then the field will be rendered according to + * the [[name]] attribute. + * @return string the rendering result. + * @throws InvalidConfigException when none of the required attributes are set to render the textInput. + * That is, if [[model]] and [[attribute]] are not set, then [[name]] is required. + */ + public function renderField() + { + if ($this->model instanceof Model && $this->attribute !== null) { + return Html::activeTextInput($this->model, $this->attribute, $this->options); + } elseif ($this->name !== null) { + return Html::textInput($this->name, $this->value, $this->options); + } else { + throw new InvalidConfigException("Either 'name' or 'model' and 'attribute' properties must be specified."); + } + } +} From 89bbdae6c11ad1666c646257dac1ede9d8bae508 Mon Sep 17 00:00:00 2001 From: resurtm Date: Thu, 23 May 2013 22:34:37 +0600 Subject: [PATCH 002/122] Initial version of the new error/exception page. --- apps/bootstrap/controllers/SiteController.php | 1 + apps/bootstrap/www/index.php | 5 +- framework/yii/base/ErrorHandler.php | 215 +++--------------- framework/yii/views/errorHandler.php | 303 ++++++++++++++++++++++++++ 4 files changed, 333 insertions(+), 191 deletions(-) create mode 100644 framework/yii/views/errorHandler.php diff --git a/apps/bootstrap/controllers/SiteController.php b/apps/bootstrap/controllers/SiteController.php index ff3b8b4..4c00cea 100644 --- a/apps/bootstrap/controllers/SiteController.php +++ b/apps/bootstrap/controllers/SiteController.php @@ -20,6 +20,7 @@ class SiteController extends Controller public function actionIndex() { + throw new \yii\base\HttpException(500, 'Test exception'); echo $this->render('index'); } diff --git a/apps/bootstrap/www/index.php b/apps/bootstrap/www/index.php index 3b7b2fc..cb363a0 100644 --- a/apps/bootstrap/www/index.php +++ b/apps/bootstrap/www/index.php @@ -3,8 +3,9 @@ // comment out the following line to disable debug mode defined('YII_DEBUG') or define('YII_DEBUG', true); -require(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php'); -require(__DIR__ . '/../vendor/autoload.php'); +//require(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php'); +//require(__DIR__ . '/../vendor/autoload.php'); +require(__DIR__ . '/../../../framework/yii/Yii.php'); $config = require(__DIR__ . '/../config/main.php'); diff --git a/framework/yii/base/ErrorHandler.php b/framework/yii/base/ErrorHandler.php index 8340723..09e4a59 100644 --- a/framework/yii/base/ErrorHandler.php +++ b/framework/yii/base/ErrorHandler.php @@ -7,6 +7,8 @@ namespace yii\base; +use Yii; + /** * ErrorHandler handles uncaught PHP errors and exceptions. * @@ -31,28 +33,25 @@ class ErrorHandler extends Component */ public $discardExistingOutput = true; /** - * @var string the route (eg 'site/error') to the controller action that will be used to display external errors. - * Inside the action, it can retrieve the error information by \Yii::$app->errorHandler->error. - * This property defaults to null, meaning ErrorHandler will handle the error display. + * @var string the route (e.g. 'site/error') to the controller action that will be used + * to display external errors. Inside the action, it can retrieve the error information + * by Yii::$app->errorHandler->error. This property defaults to null, meaning ErrorHandler + * will handle the error display. */ public $errorAction; /** - * @var string the path of the view file for rendering exceptions - */ - public $exceptionView = '@yii/views/exception.php'; - /** - * @var string the path of the view file for rendering errors + * @var string the path of the view file for rendering exceptions and errors. */ - public $errorView = '@yii/views/error.php'; + public $view = '@yii/views/errorHandler.php'; /** - * @var \Exception the exception that is being handled currently + * @var \Exception the exception that is being handled currently. */ public $exception; /** - * Handles exception - * @param \Exception $exception + * Handles exception. + * @param \Exception $exception to be handled. */ public function handle($exception) { @@ -66,14 +65,16 @@ class ErrorHandler extends Component } /** - * Renders exception - * @param \Exception $exception + * Renders exception. + * @param \Exception $exception to be handled. */ protected function renderException($exception) { if ($this->errorAction !== null) { - \Yii::$app->runAction($this->errorAction); - } elseif (\Yii::$app instanceof \yii\web\Application) { + Yii::$app->runAction($this->errorAction); + } elseif (!(Yii::$app instanceof \yii\web\Application)) { + Yii::$app->renderException($exception); + } else { if (!headers_sent()) { if ($exception instanceof HttpException) { header('HTTP/1.0 ' . $exception->statusCode . ' ' . $exception->getName()); @@ -82,7 +83,7 @@ class ErrorHandler extends Component } } if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest') { - \Yii::$app->renderException($exception); + Yii::$app->renderException($exception); } else { // if there is an error during error rendering it's useful to // display PHP error in debug mode instead of a blank screen @@ -90,177 +91,25 @@ class ErrorHandler extends Component ini_set('display_errors', 1); } - $view = new View; - if (!YII_DEBUG || $exception instanceof UserException) { - $viewName = $this->errorView; - } else { - $viewName = $this->exceptionView; - } - echo $view->renderFile($viewName, array( - 'exception' => $exception, - ), $this); - } - } else { - \Yii::$app->renderException($exception); - } - } - - /** - * Returns server and Yii version information. - * @return string server version information. - */ - public function getVersionInfo() - { - $version = 'Yii Framework/' . \Yii::getVersion(); - if (isset($_SERVER['SERVER_SOFTWARE'])) { - $version = $_SERVER['SERVER_SOFTWARE'] . ' ' . $version; - } - return $version; - } - - /** - * Converts arguments array to its string representation - * - * @param array $args arguments array to be converted - * @return string string representation of the arguments array - */ - public function argumentsToString($args) - { - $isAssoc = $args !== array_values($args); - $count = 0; - foreach ($args as $key => $value) { - $count++; - if ($count >= 5) { - if ($count > 5) { - unset($args[$key]); - } else { - $args[$key] = '...'; - } - continue; - } - - if (is_object($value)) { - $args[$key] = get_class($value); - } elseif (is_bool($value)) { - $args[$key] = $value ? 'true' : 'false'; - } elseif (is_string($value)) { - if (strlen($value) > 64) { - $args[$key] = '"' . substr($value, 0, 64) . '..."'; - } else { - $args[$key] = '"' . $value . '"'; - } - } elseif (is_array($value)) { - $args[$key] = 'array(' . $this->argumentsToString($value) . ')'; - } elseif ($value === null) { - $args[$key] = 'null'; - } elseif (is_resource($value)) { - $args[$key] = 'resource'; - } - - if (is_string($key)) { - $args[$key] = '"' . $key . '" => ' . $args[$key]; - } elseif ($isAssoc) { - $args[$key] = $key . ' => ' . $args[$key]; + $view = new View(); + echo $view->renderFile($this->view, array('e' => $exception), $this); } } - return implode(', ', $args); } /** - * Returns a value indicating whether the call stack is from application code. - * @param array $trace the trace data - * @return boolean whether the call stack is from application code. + * Converts special characters to HTML entities. + * @param string $text to encode. + * @return string encoded text. */ - public function isCoreCode($trace) - { - if (isset($trace['file'])) { - return $trace['file'] === 'unknown' || strpos(realpath($trace['file']), YII_PATH . DIRECTORY_SEPARATOR) === 0; - } - return false; - } - - /** - * Renders the source code around the error line. - * @param string $file source file path - * @param integer $errorLine the error line number - * @param integer $maxLines maximum number of lines to display - */ - public function renderSourceCode($file, $errorLine, $maxLines) + public function htmlEncode($text) { - $errorLine--; // adjust line number to 0-based from 1-based - if ($errorLine < 0 || ($lines = @file($file)) === false || ($lineCount = count($lines)) <= $errorLine) { - return; - } - - $halfLines = (int)($maxLines / 2); - $beginLine = $errorLine - $halfLines > 0 ? $errorLine - $halfLines : 0; - $endLine = $errorLine + $halfLines < $lineCount ? $errorLine + $halfLines : $lineCount - 1; - $lineNumberWidth = strlen($endLine + 1); - - $output = ''; - for ($i = $beginLine; $i <= $endLine; ++$i) { - $isErrorLine = $i === $errorLine; - $code = sprintf("%0{$lineNumberWidth}d %s", $i + 1, $this->htmlEncode(str_replace("\t", ' ', $lines[$i]))); - if (!$isErrorLine) { - $output .= $code; - } else { - $output .= '' . $code . ''; - } - } - echo '
' . $output . '
'; + return htmlspecialchars($text, ENT_QUOTES, Yii::$app->charset); } /** - * Renders calls stack trace - * @param array $trace + * Removes all output echoed before calling this method. */ - public function renderTrace($trace) - { - $count = 0; - echo "\n"; - foreach ($trace as $n => $t) { - if ($this->isCoreCode($t)) { - $cssClass = 'core collapsed'; - } elseif (++$count > 3) { - $cssClass = 'app collapsed'; - } else { - $cssClass = 'app expanded'; - } - - $hasCode = isset($t['file']) && $t['file'] !== 'unknown' && is_file($t['file']); - echo "\n"; - } - echo '
#$n"; - echo '
'; - if ($hasCode) { - echo '
+
-
'; - } - echo ' '; - if (isset($t['file'])) { - echo $this->htmlEncode($t['file']) . '(' . $t['line'] . '): '; - } - if (!empty($t['class'])) { - echo '' . $t['class'] . '' . $t['type']; - } - echo '' . $t['function'] . ''; - echo '(' . (empty($t['args']) ? '' : $this->htmlEncode($this->argumentsToString($t['args']))) . ')'; - echo '
'; - if ($hasCode) { - $this->renderSourceCode($t['file'], $t['line'], $this->maxTraceSourceLines); - } - echo "
'; - } - - /** - * Converts special characters to HTML entities - * @param string $text text to encode - * @return string - */ - public function htmlEncode($text) - { - return htmlspecialchars($text, ENT_QUOTES, \Yii::$app->charset); - } - public function clearOutput() { // the following manual level counting is to deal with zlib.output_compression set to On @@ -268,16 +117,4 @@ class ErrorHandler extends Component @ob_end_clean(); } } - - /** - * @param \Exception $exception - */ - public function renderAsHtml($exception) - { - $view = new View; - $name = !YII_DEBUG || $exception instanceof HttpException ? $this->errorView : $this->exceptionView; - echo $view->renderFile($name, array( - 'exception' => $exception, - ), $this); - } } diff --git a/framework/yii/views/errorHandler.php b/framework/yii/views/errorHandler.php new file mode 100644 index 0000000..92aa812 --- /dev/null +++ b/framework/yii/views/errorHandler.php @@ -0,0 +1,303 @@ +context; +$title = $c->htmlEncode($e instanceof \yii\base\Exception ? $e->getName() : get_class($e)); +?> + + + + + + + <?php echo $title; ?> + + + + + + + +
+ Attention +

Exceptionyii\base\HttpException – 404

+

Requested user cannot be found!

+
+ +
+
+
$_GET = [
+	'show-post' => 100,
+	'refresh-page' => 'yes',
+	'ascending-sort' => 1,
+];
+
+$_POST = [
+	'blog-post-form' => [
+		'title' => 'hello',
+		'author_id' => '12',
+	],
+];
+
+$_SERVER = [
+	'DOCUMENT_ROOT' => '/home/resurtm/work/data',
+	'REMOTE_ADDR' => '::1',
+	'REMOTE_PORT' => '52694',
+	'SERVER_SOFTWARE' => 'PHP 5.4.3 Development Server',
+	'SERVER_PROTOCOL' => 'HTTP/1.1',
+	'SERVER_NAME' => 'localhost',
+	'SERVER_PORT' => '8000',
+	'REQUEST_URI' => '/index.php?post-form[title]=hello&post-form[author_id]=12',
+	'REQUEST_METHOD' => 'GET',
+	'SCRIPT_NAME' => '/index.php',
+	'SCRIPT_FILENAME' => '/home/resurtm/work/data/index.php',
+	'PHP_SELF' => '/index.php',
+	'QUERY_STRING' => 'post-form[title]=hello&post-form[author_id]=12',
+	'HTTP_HOST' => 'localhost:8000',
+	'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0',
+	'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
+	'HTTP_ACCEPT_LANGUAGE' => 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
+	'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
+	'HTTP_CONNECTION' => 'keep-alive',
+	'REQUEST_TIME_FLOAT' => 1369146454.0856,
+	'REQUEST_TIME' => 1369146454,
+];
+
+ + + + + + + + + + + From 0963cf8b7b034740776c050545a01d0a94dbfdaf Mon Sep 17 00:00:00 2001 From: resurtm Date: Thu, 23 May 2013 22:53:17 +0600 Subject: [PATCH 003/122] Minor enhancements. --- framework/yii/views/errorHandler.php | 41 ++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/framework/yii/views/errorHandler.php b/framework/yii/views/errorHandler.php index 92aa812..a7fe09a 100644 --- a/framework/yii/views/errorHandler.php +++ b/framework/yii/views/errorHandler.php @@ -147,12 +147,21 @@ $title = $c->htmlEncode($e instanceof \yii\base\Exception ? $e->getName() : get_ } /* code */ + #code-wrap{ + overflow: hidden; + position: relative; + } #code-highlighter{ background-color: #ffffff; position: fixed; width: 100%; z-index: 100; } + #code-inner-wrap{ + min-width: 860px; /* padding compensation: 960px - 50px * 2 */ + max-width: 1100px; /* padding compensation: 1200px - 50px * 2 */ + margin: 0 auto; + } pre{ display: inline; color: #505050; @@ -223,8 +232,10 @@ $title = $c->htmlEncode($e instanceof \yii\base\Exception ? $e->getName() : get_
-
-
$_GET = [
+		
+
+
+
$_GET = [
 	'show-post' => 100,
 	'refresh-page' => 'yes',
 	'ascending-sort' => 1,
@@ -260,6 +271,8 @@ $_SERVER = [
 	'REQUEST_TIME_FLOAT' => 1369146454.0856,
 	'REQUEST_TIME' => 1369146454,
 ];
+
+
- - + + - - + +
+
+
+
+ + 10
11
12
13
14
15
16
17
18
19
20
21
22
+ 23
24
25
26
27
28
29
30
31
32
33
34 +
+
	{
+		return array(
+			'captcha' => array(
+				'class' => 'yii\web\CaptchaAction',
+			),
+		);
+	}
+
+	public function actionIndex()
+	{
+//		throw new \yii\base\HttpException(500);
+		$x = null;
+		$x->y = 1;
+
+		echo $this->render('index');
+	}
+
+	public function actionLogin()
+	{
+		$model = new LoginForm();
+		if ($this->populate($_POST, $model) && $model->login()) {
+			Yii::$app->response->redirect(array('site/index'));
+		} else {
+			echo $this->render('login', array(
+				'model' => $model,
+
+
+ +
- Attention -

Exceptionyii\base\HttpException – 404

+ Attention +

Exceptionyii\base\HttpException – 404

Requested user cannot be found!

+
+
    +
  • +
    +
    + 1. + in C:\_work\jetbrains\yii2\apps\bootstrap\protected\controllers\SiteController.php + at line + 22 +
    +
    + +
  • +
  • +
    +
    + 2. + at C:\_work\jetbrains\yii2\yii\base\InlineAction.php – + call_user_func_array() + at line + 47 +
    +
    + +
  • +
  • +
    +
    + 3. + at C:\_work\jetbrains\yii2\yii\base\Controller.php – + yii\base\InlineActionrunWithParams() + at line + 117 +
    +
    + +
  • +
  • +
    +
    + 4. + at C:\_work\jetbrains\yii2\yii\web\Application.php – + yii\base\ModulerunAction() + at line + 35 +
    +
    + +
  • +
  • +
    +
    + 5. + at C:\_work\jetbrains\yii2\yii\web\Application.php – + yii\base\ModulerunAction() + at line + 35 +
    +
    + +
  • +
  • +
    +
    + 6. + at C:\_work\jetbrains\yii2\yii\base\Application.php – + yii\web\ApplicationprocessRequest() + at line + 146 +
    +
    + +
  • +
  • +
    +
    + 7. + at C:\_work\jetbrains\yii2\apps\bootstrap\index.php – + yii\base\Applicationrun() + at line + 14 +
    +
    + +
  • +
+
+ +
@@ -264,7 +188,6 @@ $_SERVER = [ 'QUERY_STRING' => 'post-form[title]=hello&post-form[author_id]=12', 'HTTP_HOST' => 'localhost:8000', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0', - 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_LANGUAGE' => 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3', 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate', 'HTTP_CONNECTION' => 'keep-alive', @@ -273,46 +196,14 @@ $_SERVER = [ ]; - + */ ?> - - - - From 0fb30f8d25eaef1072bd0583a97d2b218b40fa63 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 24 May 2013 21:47:27 +0400 Subject: [PATCH 018/122] Advanced application template --- apps/advanced/LICENSE.md | 32 ++++++++ apps/advanced/README.md | 89 ++++++++++++++++++++ apps/advanced/backstage/assets/.gitkeep | 1 + apps/advanced/backstage/config/.gitignore | 2 + apps/advanced/backstage/config/assets.php | 18 ++++ apps/advanced/backstage/config/main.php | 46 +++++++++++ apps/advanced/backstage/config/params.php | 5 ++ .../backstage/controllers/SiteController.php | 61 ++++++++++++++ apps/advanced/backstage/models/.gitkeep | 1 + apps/advanced/backstage/runtime/.gitignore | 2 + apps/advanced/backstage/views/layouts/main.php | 66 +++++++++++++++ apps/advanced/backstage/views/site/about.php | 16 ++++ apps/advanced/backstage/views/site/contact.php | 46 +++++++++++ apps/advanced/backstage/views/site/index.php | 47 +++++++++++ apps/advanced/backstage/views/site/login.php | 24 ++++++ apps/advanced/backstage/www/assets/.gitignore | 2 + apps/advanced/backstage/www/css/site.css | 78 ++++++++++++++++++ apps/advanced/common/config/.gitignore | 1 + apps/advanced/common/config/params.php | 9 ++ apps/advanced/common/models/ContactForm.php | 63 ++++++++++++++ apps/advanced/common/models/LoginForm.php | 58 +++++++++++++ apps/advanced/common/models/User.php | 61 ++++++++++++++ apps/advanced/composer.json | 44 ++++++++++ apps/advanced/console/config/.gitignore | 2 + apps/advanced/console/config/main.php | 34 ++++++++ apps/advanced/console/config/params.php | 5 ++ .../console/controllers/HelloController.php | 29 +++++++ .../console/controllers/InstallController.php | 13 +++ apps/advanced/console/migrations/.gitkeep | 1 + apps/advanced/console/runtime/.gitignore | 2 + apps/advanced/frontend/assets/.gitkeep | 2 + apps/advanced/frontend/config/.gitignore | 2 + apps/advanced/frontend/config/assets.php | 18 ++++ apps/advanced/frontend/config/main.php | 46 +++++++++++ apps/advanced/frontend/config/params.php | 5 ++ .../frontend/controllers/SiteController.php | 61 ++++++++++++++ apps/advanced/frontend/models/ContactForm.php | 63 ++++++++++++++ apps/advanced/frontend/models/LoginForm.php | 58 +++++++++++++ apps/advanced/frontend/models/User.php | 61 ++++++++++++++ apps/advanced/frontend/runtime/.gitignore | 2 + apps/advanced/frontend/views/layouts/main.php | 66 +++++++++++++++ apps/advanced/frontend/views/site/about.php | 16 ++++ apps/advanced/frontend/views/site/contact.php | 46 +++++++++++ apps/advanced/frontend/views/site/index.php | 47 +++++++++++ apps/advanced/frontend/views/site/login.php | 24 ++++++ apps/advanced/frontend/www/assets/.gitignore | 2 + apps/advanced/frontend/www/css/site.css | 78 ++++++++++++++++++ .../install/dev/backstage/config/main-local.php | 3 + .../install/dev/backstage/config/params-local.php | 3 + apps/advanced/install/dev/backstage/www/index.php | 14 ++++ .../install/dev/common/config/params-local.php | 3 + .../install/dev/console/config/main-local.php | 3 + .../install/dev/console/config/params-local.php | 3 + .../install/dev/frontend/config/main-local.php | 3 + .../install/dev/frontend/config/params-local.php | 3 + apps/advanced/install/dev/frontend/www/index.php | 15 ++++ apps/advanced/requirements.php | 96 ++++++++++++++++++++++ apps/advanced/vendor/.gitignore | 2 + apps/advanced/yii | 26 ++++++ apps/advanced/yii.bat | 20 +++++ 60 files changed, 1649 insertions(+) create mode 100644 apps/advanced/LICENSE.md create mode 100644 apps/advanced/README.md create mode 100644 apps/advanced/backstage/assets/.gitkeep create mode 100644 apps/advanced/backstage/config/.gitignore create mode 100644 apps/advanced/backstage/config/assets.php create mode 100644 apps/advanced/backstage/config/main.php create mode 100644 apps/advanced/backstage/config/params.php create mode 100644 apps/advanced/backstage/controllers/SiteController.php create mode 100644 apps/advanced/backstage/models/.gitkeep create mode 100644 apps/advanced/backstage/runtime/.gitignore create mode 100644 apps/advanced/backstage/views/layouts/main.php create mode 100644 apps/advanced/backstage/views/site/about.php create mode 100644 apps/advanced/backstage/views/site/contact.php create mode 100644 apps/advanced/backstage/views/site/index.php create mode 100644 apps/advanced/backstage/views/site/login.php create mode 100644 apps/advanced/backstage/www/assets/.gitignore create mode 100644 apps/advanced/backstage/www/css/site.css create mode 100644 apps/advanced/common/config/.gitignore create mode 100644 apps/advanced/common/config/params.php create mode 100644 apps/advanced/common/models/ContactForm.php create mode 100644 apps/advanced/common/models/LoginForm.php create mode 100644 apps/advanced/common/models/User.php create mode 100644 apps/advanced/composer.json create mode 100644 apps/advanced/console/config/.gitignore create mode 100644 apps/advanced/console/config/main.php create mode 100644 apps/advanced/console/config/params.php create mode 100644 apps/advanced/console/controllers/HelloController.php create mode 100644 apps/advanced/console/controllers/InstallController.php create mode 100644 apps/advanced/console/migrations/.gitkeep create mode 100644 apps/advanced/console/runtime/.gitignore create mode 100644 apps/advanced/frontend/assets/.gitkeep create mode 100644 apps/advanced/frontend/config/.gitignore create mode 100644 apps/advanced/frontend/config/assets.php create mode 100644 apps/advanced/frontend/config/main.php create mode 100644 apps/advanced/frontend/config/params.php create mode 100644 apps/advanced/frontend/controllers/SiteController.php create mode 100644 apps/advanced/frontend/models/ContactForm.php create mode 100644 apps/advanced/frontend/models/LoginForm.php create mode 100644 apps/advanced/frontend/models/User.php create mode 100644 apps/advanced/frontend/runtime/.gitignore create mode 100644 apps/advanced/frontend/views/layouts/main.php create mode 100644 apps/advanced/frontend/views/site/about.php create mode 100644 apps/advanced/frontend/views/site/contact.php create mode 100644 apps/advanced/frontend/views/site/index.php create mode 100644 apps/advanced/frontend/views/site/login.php create mode 100644 apps/advanced/frontend/www/assets/.gitignore create mode 100644 apps/advanced/frontend/www/css/site.css create mode 100644 apps/advanced/install/dev/backstage/config/main-local.php create mode 100644 apps/advanced/install/dev/backstage/config/params-local.php create mode 100644 apps/advanced/install/dev/backstage/www/index.php create mode 100644 apps/advanced/install/dev/common/config/params-local.php create mode 100644 apps/advanced/install/dev/console/config/main-local.php create mode 100644 apps/advanced/install/dev/console/config/params-local.php create mode 100644 apps/advanced/install/dev/frontend/config/main-local.php create mode 100644 apps/advanced/install/dev/frontend/config/params-local.php create mode 100644 apps/advanced/install/dev/frontend/www/index.php create mode 100644 apps/advanced/requirements.php create mode 100644 apps/advanced/vendor/.gitignore create mode 100644 apps/advanced/yii create mode 100644 apps/advanced/yii.bat diff --git a/apps/advanced/LICENSE.md b/apps/advanced/LICENSE.md new file mode 100644 index 0000000..6edcc4f --- /dev/null +++ b/apps/advanced/LICENSE.md @@ -0,0 +1,32 @@ +The Yii framework is free software. It is released under the terms of +the following BSD License. + +Copyright © 2008-2013 by Yii Software LLC (http://www.yiisoft.com) +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of Yii Software LLC nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/apps/advanced/README.md b/apps/advanced/README.md new file mode 100644 index 0000000..08f0b0d --- /dev/null +++ b/apps/advanced/README.md @@ -0,0 +1,89 @@ +Yii 2 Advanced Application Template +=================================== + +**NOTE** Yii 2 and the relevant applications and extensions are still under heavy +development. We may make significant changes without prior notices. Please do not +use them for production. Please consider using [Yii v1.1](https://github.com/yiisoft/yii) +if you have a project to be deployed for production soon. + + +Thank you for using Yii 2 Advanced Application Template - an application template +that works out-of-box and can be easily customized to fit for your needs. + +Yii 2 Advanced Application Template is best suitable for large projects requiring frontend and backstage separation, +deployment in different environments, configuration nesting etc. + + +DIRECTORY STRUCTURE +------------------- + +``` +common + config/ contains shared configurations + env/ contains environment-based overrides + models/ contains model classes used in both backstage and frontend +console + config/ contains console configurations + controllers/ contains console controllers (commands) + env/ contains environment-based overrides + migrations/ contains database migrations + models/ contains console-specific model classes + runtime/ contains files generated during runtime +backstage + assets/ contains application assets such as JavaScript and CSS + config/ contains backstage configurations + controllers/ contains Web controller classes + env/ contains environment-based overrides + models/ contains backstage-specific model classes + runtime/ contains files generated during runtime + views/ contains view files for the Web application + www/ contains the entry script and Web resources +frontend + assets/ contains application assets such as JavaScript and CSS + config/ contains frontend configurations + controllers/ contains Web controller classes + env/ contains environment-based overrides + models/ contains frontend-specific model classes + runtime/ contains files generated during runtime + views/ contains view files for the Web application + www/ contains the entry script and Web resources +vendor/ contains dependent 3rd-party packages +``` + + + +REQUIREMENTS +------------ + +The minimum requirement by Yii is that your Web server supports PHP 5.3.?. + + +INSTALLATION +------------ + +### Install via Composer + +If you do not have [Composer](http://getcomposer.org/), you may download it from +[http://getcomposer.org/](http://getcomposer.org/) or run the following command on Linux/Unix/MacOS: + +~~~ +curl -s http://getcomposer.org/installer | php +~~~ + +You can then install the Bootstrap Application using the following command: + +~~~ +php composer.phar create-project --stability=dev yiisoft/yii2-app-advanced yii-advanced +~~~ + +Now you should be able to access: + +- the frontend using the URL `http://localhost/yii-advanced/frontend/www/` +- the backstage using the URL `http://localhost/yii-advanced/backstage/www/` + +assuming `yii-advanced` is directly under the document root of your Web server. + + +### Install from an Archive File + +This is not currently available. We will provide it when Yii 2 is formally released. diff --git a/apps/advanced/backstage/assets/.gitkeep b/apps/advanced/backstage/assets/.gitkeep new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/apps/advanced/backstage/assets/.gitkeep @@ -0,0 +1 @@ +* diff --git a/apps/advanced/backstage/config/.gitignore b/apps/advanced/backstage/config/.gitignore new file mode 100644 index 0000000..20da318 --- /dev/null +++ b/apps/advanced/backstage/config/.gitignore @@ -0,0 +1,2 @@ +main-local.php +params-local.php \ No newline at end of file diff --git a/apps/advanced/backstage/config/assets.php b/apps/advanced/backstage/config/assets.php new file mode 100644 index 0000000..ee0d610 --- /dev/null +++ b/apps/advanced/backstage/config/assets.php @@ -0,0 +1,18 @@ + array( + 'basePath' => '@wwwroot', + 'baseUrl' => '@www', + 'css' => array( + 'css/site.css', + ), + 'js' => array( + + ), + 'depends' => array( + 'yii', + 'yii/bootstrap/responsive', + ), + ), +); diff --git a/apps/advanced/backstage/config/main.php b/apps/advanced/backstage/config/main.php new file mode 100644 index 0000000..3fb95da --- /dev/null +++ b/apps/advanced/backstage/config/main.php @@ -0,0 +1,46 @@ + 'change-me', + 'basePath' => dirname(__DIR__), + 'preload' => array('log'), + 'controllerNamespace' => 'app\controllers', + 'modules' => array( +// 'debug' => array( +// 'class' => 'yii\debug\Module', +// ) + ), + 'components' => array( + 'cache' => array( + 'class' => 'yii\caching\FileCache', + ), + 'user' => array( + 'class' => 'yii\web\User', + 'identityClass' => 'app\models\User', + ), + 'assetManager' => array( + 'bundles' => require(__DIR__ . '/assets.php'), + ), + 'log' => array( + 'class' => 'yii\logging\Router', + 'targets' => array( + array( + 'class' => 'yii\logging\FileTarget', + 'levels' => array('error', 'warning'), + ), +// array( +// 'class' => 'yii\logging\DebugTarget', +// ) + ), + ), + ), + 'params' => $params, +); diff --git a/apps/advanced/backstage/config/params.php b/apps/advanced/backstage/config/params.php new file mode 100644 index 0000000..1e197d0 --- /dev/null +++ b/apps/advanced/backstage/config/params.php @@ -0,0 +1,5 @@ + 'admin@example.com', +); \ No newline at end of file diff --git a/apps/advanced/backstage/controllers/SiteController.php b/apps/advanced/backstage/controllers/SiteController.php new file mode 100644 index 0000000..ff3b8b4 --- /dev/null +++ b/apps/advanced/backstage/controllers/SiteController.php @@ -0,0 +1,61 @@ + array( + 'class' => 'yii\web\CaptchaAction', + ), + ); + } + + public function actionIndex() + { + echo $this->render('index'); + } + + public function actionLogin() + { + $model = new LoginForm(); + if ($this->populate($_POST, $model) && $model->login()) { + Yii::$app->response->redirect(array('site/index')); + } else { + echo $this->render('login', array( + 'model' => $model, + )); + } + } + + public function actionLogout() + { + Yii::$app->getUser()->logout(); + Yii::$app->getResponse()->redirect(array('site/index')); + } + + public function actionContact() + { + $model = new ContactForm; + if ($this->populate($_POST, $model) && $model->contact(Yii::$app->params['adminEmail'])) { + Yii::$app->session->setFlash('contactFormSubmitted'); + Yii::$app->response->refresh(); + } else { + echo $this->render('contact', array( + 'model' => $model, + )); + } + } + + public function actionAbout() + { + echo $this->render('about'); + } +} diff --git a/apps/advanced/backstage/models/.gitkeep b/apps/advanced/backstage/models/.gitkeep new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/apps/advanced/backstage/models/.gitkeep @@ -0,0 +1 @@ +* diff --git a/apps/advanced/backstage/runtime/.gitignore b/apps/advanced/backstage/runtime/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/apps/advanced/backstage/runtime/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/apps/advanced/backstage/views/layouts/main.php b/apps/advanced/backstage/views/layouts/main.php new file mode 100644 index 0000000..635e118 --- /dev/null +++ b/apps/advanced/backstage/views/layouts/main.php @@ -0,0 +1,66 @@ +registerAssetBundle('app'); +?> +beginPage(); ?> + + + + + <?php echo Html::encode($this->title); ?> + head(); ?> + + +
+ beginBody(); ?> +
+

My Company

+ + + +
+ + isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : array(), + )); ?> + + +
+ + + endBody(); ?> +
+ + + +endPage(); ?> diff --git a/apps/advanced/backstage/views/site/about.php b/apps/advanced/backstage/views/site/about.php new file mode 100644 index 0000000..86e19e1 --- /dev/null +++ b/apps/advanced/backstage/views/site/about.php @@ -0,0 +1,16 @@ +title = 'About'; +$this->params['breadcrumbs'][] = $this->title; +?> +

title); ?>

+ +

+ This is the About page. You may modify the following file to customize its content: +

+ + + diff --git a/apps/advanced/backstage/views/site/contact.php b/apps/advanced/backstage/views/site/contact.php new file mode 100644 index 0000000..e740d0f --- /dev/null +++ b/apps/advanced/backstage/views/site/contact.php @@ -0,0 +1,46 @@ +title = 'Contact'; +$this->params['breadcrumbs'][] = $this->title; +?> +

title); ?>

+ +session->hasFlash('contactFormSubmitted')): ?> +
+ Thank you for contacting us. We will respond to you as soon as possible. +
+ + +

+ If you have business inquiries or other questions, please fill out the following form to contact us. Thank you. +

+ + array('class' => 'form-horizontal'), + 'fieldConfig' => array('inputOptions' => array('class' => 'input-xlarge')), +)); ?> + field($model, 'name')->textInput(); ?> + field($model, 'email')->textInput(); ?> + field($model, 'subject')->textInput(); ?> + field($model, 'body')->textArea(array('rows' => 6)); ?> + field($model, 'verifyCode'); + echo $field->begin() + . $field->label() + . Captcha::widget() + . Html::activeTextInput($model, 'verifyCode', array('class' => 'input-medium')) + . $field->error() + . $field->end(); + ?> +
+ 'btn btn-primary')); ?> +
+ diff --git a/apps/advanced/backstage/views/site/index.php b/apps/advanced/backstage/views/site/index.php new file mode 100644 index 0000000..158b61c --- /dev/null +++ b/apps/advanced/backstage/views/site/index.php @@ -0,0 +1,47 @@ +title = 'Welcome'; +?> +
+

Welcome!

+ +

Cras justo odio, dapibus ac facilisis in, egestas eget quam. Fusce dapibus, tellus ac cursus + commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.

+ Get started with Yii +
+ +
+ + +
+
+

Heading

+ +

Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris + condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. + Donec sed odio dui.

+ +

View details »

+
+
+

Heading

+ +

Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris + condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. + Donec sed odio dui.

+ +

View details »

+
+
+

Heading

+ +

Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta + felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum + massa.

+ +

View details »

+
+
+ diff --git a/apps/advanced/backstage/views/site/login.php b/apps/advanced/backstage/views/site/login.php new file mode 100644 index 0000000..f676b98 --- /dev/null +++ b/apps/advanced/backstage/views/site/login.php @@ -0,0 +1,24 @@ +title = 'Login'; +$this->params['breadcrumbs'][] = $this->title; +?> +

title); ?>

+ +

Please fill out the following fields to login:

+ + array('class' => 'form-horizontal'))); ?> + field($model, 'username')->textInput(); ?> + field($model, 'password')->passwordInput(); ?> + field($model, 'rememberMe')->checkbox(); ?> +
+ 'btn btn-primary')); ?> +
+ diff --git a/apps/advanced/backstage/www/assets/.gitignore b/apps/advanced/backstage/www/assets/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/apps/advanced/backstage/www/assets/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/apps/advanced/backstage/www/css/site.css b/apps/advanced/backstage/www/css/site.css new file mode 100644 index 0000000..890a953 --- /dev/null +++ b/apps/advanced/backstage/www/css/site.css @@ -0,0 +1,78 @@ +body { + padding-top: 20px; + padding-bottom: 60px; +} + +/* Custom container */ +.container { + margin: 0 auto; + max-width: 1000px; +} + +.container > hr { + margin: 60px 0; +} + +/* Main marketing message and sign up button */ +.jumbotron { + margin: 80px 0; + text-align: center; +} + +.jumbotron h1 { + font-size: 100px; + line-height: 1; +} + +.jumbotron .lead { + font-size: 24px; + line-height: 1.25; +} + +.jumbotron .btn { + font-size: 21px; + padding: 14px 24px; +} + +/* Supporting marketing content */ +.marketing { + margin: 60px 0; +} + +.marketing p + h4 { + margin-top: 28px; +} + +/* Customize the navbar links to be fill the entire space of the .navbar */ +.navbar .navbar-inner { + padding: 0; +} + +.navbar .nav { + margin: 0; + display: table; + width: 100%; +} + +.navbar .nav li { + display: table-cell; + width: 1%; + float: none; +} + +.navbar .nav li a { + font-weight: bold; + text-align: center; + border-left: 1px solid rgba(255, 255, 255, .75); + border-right: 1px solid rgba(0, 0, 0, .1); +} + +.navbar .nav li:first-child a { + border-left: 0; + border-radius: 3px 0 0 3px; +} + +.navbar .nav li:last-child a { + border-right: 0; + border-radius: 0 3px 3px 0; +} diff --git a/apps/advanced/common/config/.gitignore b/apps/advanced/common/config/.gitignore new file mode 100644 index 0000000..46f6eb4 --- /dev/null +++ b/apps/advanced/common/config/.gitignore @@ -0,0 +1 @@ +params-local.php \ No newline at end of file diff --git a/apps/advanced/common/config/params.php b/apps/advanced/common/config/params.php new file mode 100644 index 0000000..9eb2b15 --- /dev/null +++ b/apps/advanced/common/config/params.php @@ -0,0 +1,9 @@ + 'admin@example.com', + + 'component.cache' => array( + 'class' => 'yii\caching\FileCache', + ), +); \ No newline at end of file diff --git a/apps/advanced/common/models/ContactForm.php b/apps/advanced/common/models/ContactForm.php new file mode 100644 index 0000000..7b713a1 --- /dev/null +++ b/apps/advanced/common/models/ContactForm.php @@ -0,0 +1,63 @@ + 'Verification Code', + ); + } + + /** + * Sends an email to the specified email address using the information collected by this model. + * @param string $email the target email address + * @return boolean whether the model passes validation + */ + public function contact($email) + { + if ($this->validate()) { + $name = '=?UTF-8?B?' . base64_encode($this->name) . '?='; + $subject = '=?UTF-8?B?' . base64_encode($this->subject) . '?='; + $headers = "From: $name <{$this->email}>\r\n" . + "Reply-To: {$this->email}\r\n" . + "MIME-Version: 1.0\r\n" . + "Content-type: text/plain; charset=UTF-8"; + mail($email, $subject, $this->body, $headers); + return true; + } else { + return false; + } + } +} diff --git a/apps/advanced/common/models/LoginForm.php b/apps/advanced/common/models/LoginForm.php new file mode 100644 index 0000000..5ba1dc6 --- /dev/null +++ b/apps/advanced/common/models/LoginForm.php @@ -0,0 +1,58 @@ +username); + if (!$user || !$user->validatePassword($this->password)) { + $this->addError('password', 'Incorrect username or password.'); + } + } + + /** + * Logs in a user using the provided username and password. + * @return boolean whether the user is logged in successfully + */ + public function login() + { + if ($this->validate()) { + $user = User::findByUsername($this->username); + Yii::$app->user->login($user, $this->rememberMe ? 3600*24*30 : 0); + return true; + } else { + return false; + } + } +} diff --git a/apps/advanced/common/models/User.php b/apps/advanced/common/models/User.php new file mode 100644 index 0000000..afbf9f8 --- /dev/null +++ b/apps/advanced/common/models/User.php @@ -0,0 +1,61 @@ + array( + 'id' => '100', + 'username' => 'admin', + 'password' => 'admin', + 'authKey' => 'test100key', + ), + '101' => array( + 'id' => '101', + 'username' => 'demo', + 'password' => 'demo', + 'authKey' => 'test101key', + ), + ); + + public static function findIdentity($id) + { + return isset(self::$users[$id]) ? new self(self::$users[$id]) : null; + } + + public static function findByUsername($username) + { + foreach (self::$users as $user) { + if (strcasecmp($user['username'], $username) === 0) { + return new self($user); + } + } + return null; + } + + public function getId() + { + return $this->id; + } + + public function getAuthKey() + { + return $this->authKey; + } + + public function validateAuthKey($authKey) + { + return $this->authKey === $authKey; + } + + public function validatePassword($password) + { + return $this->password === $password; + } +} diff --git a/apps/advanced/composer.json b/apps/advanced/composer.json new file mode 100644 index 0000000..a5ff565 --- /dev/null +++ b/apps/advanced/composer.json @@ -0,0 +1,44 @@ +{ + "name": "yiisoft/yii2-app-basic", + "description": "Yii 2 Basic Application Template", + "keywords": ["yii", "framework", "basic", "application template"], + "homepage": "http://www.yiiframework.com/", + "type": "project", + "license": "BSD-3-Clause", + "support": { + "issues": "https://github.com/yiisoft/yii2/issues?state=open", + "forum": "http://www.yiiframework.com/forum/", + "wiki": "http://www.yiiframework.com/wiki/", + "irc": "irc://irc.freenode.net/yii", + "source": "https://github.com/yiisoft/yii2" + }, + "minimum-stability": "dev", + "require": { + "php": ">=5.3.0", + "yiisoft/yii2": "dev-master", + "yiisoft/yii2-composer": "dev-master" + }, + "scripts": { + "post-install-cmd": [ + "yii\\composer\\InstallHandler::setPermissions" + ], + "post-update-cmd": [ + "yii\\composer\\InstallHandler::setPermissions" + ] + }, + "extra": { + "yii-install-writable": [ + "backstage/runtime", + "backstage/www/assets", + + "console/runtime", + "console/migrations", + + "frontend/runtime", + "frontend/www/assets" + ], + "yii-install-executable": [ + "yii" + ] + } +} diff --git a/apps/advanced/console/config/.gitignore b/apps/advanced/console/config/.gitignore new file mode 100644 index 0000000..20da318 --- /dev/null +++ b/apps/advanced/console/config/.gitignore @@ -0,0 +1,2 @@ +main-local.php +params-local.php \ No newline at end of file diff --git a/apps/advanced/console/config/main.php b/apps/advanced/console/config/main.php new file mode 100644 index 0000000..7af7824 --- /dev/null +++ b/apps/advanced/console/config/main.php @@ -0,0 +1,34 @@ + 'bootstrap-console', + 'basePath' => dirname(__DIR__), + 'preload' => array('log'), + 'controllerPath' => dirname(__DIR__) . '/commands', + 'controllerNamespace' => 'app\controllers', + 'modules' => array( + ), + 'components' => array( + 'cache' => array( + 'class' => 'yii\caching\FileCache', + ), + 'log' => array( + 'class' => 'yii\logging\Router', + 'targets' => array( + array( + 'class' => 'yii\logging\FileTarget', + 'levels' => array('error', 'warning'), + ), + ), + ), + ), + 'params' => $params, +); diff --git a/apps/advanced/console/config/params.php b/apps/advanced/console/config/params.php new file mode 100644 index 0000000..1e197d0 --- /dev/null +++ b/apps/advanced/console/config/params.php @@ -0,0 +1,5 @@ + 'admin@example.com', +); \ No newline at end of file diff --git a/apps/advanced/console/controllers/HelloController.php b/apps/advanced/console/controllers/HelloController.php new file mode 100644 index 0000000..603c6e8 --- /dev/null +++ b/apps/advanced/console/controllers/HelloController.php @@ -0,0 +1,29 @@ + + * @since 2.0 + */ +class HelloController extends Controller +{ + /** + * This command echos what you have entered as the message. + * @param string $message the message to be echoed. + */ + public function actionIndex($message = 'hello world') + { + echo $message."\n"; + } +} \ No newline at end of file diff --git a/apps/advanced/console/controllers/InstallController.php b/apps/advanced/console/controllers/InstallController.php new file mode 100644 index 0000000..cbc2227 --- /dev/null +++ b/apps/advanced/console/controllers/InstallController.php @@ -0,0 +1,13 @@ + array( + 'basePath' => '@wwwroot', + 'baseUrl' => '@www', + 'css' => array( + 'css/site.css', + ), + 'js' => array( + + ), + 'depends' => array( + 'yii', + 'yii/bootstrap/responsive', + ), + ), +); diff --git a/apps/advanced/frontend/config/main.php b/apps/advanced/frontend/config/main.php new file mode 100644 index 0000000..9379e06 --- /dev/null +++ b/apps/advanced/frontend/config/main.php @@ -0,0 +1,46 @@ + 'bootstrap', + 'basePath' => dirname(__DIR__), + 'preload' => array('log'), + 'controllerNamespace' => 'app\controllers', + 'modules' => array( +// 'debug' => array( +// 'class' => 'yii\debug\Module', +// ) + ), + 'components' => array( + 'cache' => array( + 'class' => 'yii\caching\FileCache', + ), + 'user' => array( + 'class' => 'yii\web\User', + 'identityClass' => 'app\models\User', + ), + 'assetManager' => array( + 'bundles' => require(__DIR__ . '/assets.php'), + ), + 'log' => array( + 'class' => 'yii\logging\Router', + 'targets' => array( + array( + 'class' => 'yii\logging\FileTarget', + 'levels' => array('error', 'warning'), + ), +// array( +// 'class' => 'yii\logging\DebugTarget', +// ) + ), + ), + ), + 'params' => $params, +); diff --git a/apps/advanced/frontend/config/params.php b/apps/advanced/frontend/config/params.php new file mode 100644 index 0000000..1e197d0 --- /dev/null +++ b/apps/advanced/frontend/config/params.php @@ -0,0 +1,5 @@ + 'admin@example.com', +); \ No newline at end of file diff --git a/apps/advanced/frontend/controllers/SiteController.php b/apps/advanced/frontend/controllers/SiteController.php new file mode 100644 index 0000000..ff3b8b4 --- /dev/null +++ b/apps/advanced/frontend/controllers/SiteController.php @@ -0,0 +1,61 @@ + array( + 'class' => 'yii\web\CaptchaAction', + ), + ); + } + + public function actionIndex() + { + echo $this->render('index'); + } + + public function actionLogin() + { + $model = new LoginForm(); + if ($this->populate($_POST, $model) && $model->login()) { + Yii::$app->response->redirect(array('site/index')); + } else { + echo $this->render('login', array( + 'model' => $model, + )); + } + } + + public function actionLogout() + { + Yii::$app->getUser()->logout(); + Yii::$app->getResponse()->redirect(array('site/index')); + } + + public function actionContact() + { + $model = new ContactForm; + if ($this->populate($_POST, $model) && $model->contact(Yii::$app->params['adminEmail'])) { + Yii::$app->session->setFlash('contactFormSubmitted'); + Yii::$app->response->refresh(); + } else { + echo $this->render('contact', array( + 'model' => $model, + )); + } + } + + public function actionAbout() + { + echo $this->render('about'); + } +} diff --git a/apps/advanced/frontend/models/ContactForm.php b/apps/advanced/frontend/models/ContactForm.php new file mode 100644 index 0000000..7b713a1 --- /dev/null +++ b/apps/advanced/frontend/models/ContactForm.php @@ -0,0 +1,63 @@ + 'Verification Code', + ); + } + + /** + * Sends an email to the specified email address using the information collected by this model. + * @param string $email the target email address + * @return boolean whether the model passes validation + */ + public function contact($email) + { + if ($this->validate()) { + $name = '=?UTF-8?B?' . base64_encode($this->name) . '?='; + $subject = '=?UTF-8?B?' . base64_encode($this->subject) . '?='; + $headers = "From: $name <{$this->email}>\r\n" . + "Reply-To: {$this->email}\r\n" . + "MIME-Version: 1.0\r\n" . + "Content-type: text/plain; charset=UTF-8"; + mail($email, $subject, $this->body, $headers); + return true; + } else { + return false; + } + } +} diff --git a/apps/advanced/frontend/models/LoginForm.php b/apps/advanced/frontend/models/LoginForm.php new file mode 100644 index 0000000..5ba1dc6 --- /dev/null +++ b/apps/advanced/frontend/models/LoginForm.php @@ -0,0 +1,58 @@ +username); + if (!$user || !$user->validatePassword($this->password)) { + $this->addError('password', 'Incorrect username or password.'); + } + } + + /** + * Logs in a user using the provided username and password. + * @return boolean whether the user is logged in successfully + */ + public function login() + { + if ($this->validate()) { + $user = User::findByUsername($this->username); + Yii::$app->user->login($user, $this->rememberMe ? 3600*24*30 : 0); + return true; + } else { + return false; + } + } +} diff --git a/apps/advanced/frontend/models/User.php b/apps/advanced/frontend/models/User.php new file mode 100644 index 0000000..afbf9f8 --- /dev/null +++ b/apps/advanced/frontend/models/User.php @@ -0,0 +1,61 @@ + array( + 'id' => '100', + 'username' => 'admin', + 'password' => 'admin', + 'authKey' => 'test100key', + ), + '101' => array( + 'id' => '101', + 'username' => 'demo', + 'password' => 'demo', + 'authKey' => 'test101key', + ), + ); + + public static function findIdentity($id) + { + return isset(self::$users[$id]) ? new self(self::$users[$id]) : null; + } + + public static function findByUsername($username) + { + foreach (self::$users as $user) { + if (strcasecmp($user['username'], $username) === 0) { + return new self($user); + } + } + return null; + } + + public function getId() + { + return $this->id; + } + + public function getAuthKey() + { + return $this->authKey; + } + + public function validateAuthKey($authKey) + { + return $this->authKey === $authKey; + } + + public function validatePassword($password) + { + return $this->password === $password; + } +} diff --git a/apps/advanced/frontend/runtime/.gitignore b/apps/advanced/frontend/runtime/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/apps/advanced/frontend/runtime/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/apps/advanced/frontend/views/layouts/main.php b/apps/advanced/frontend/views/layouts/main.php new file mode 100644 index 0000000..635e118 --- /dev/null +++ b/apps/advanced/frontend/views/layouts/main.php @@ -0,0 +1,66 @@ +registerAssetBundle('app'); +?> +beginPage(); ?> + + + + + <?php echo Html::encode($this->title); ?> + head(); ?> + + +
+ beginBody(); ?> +
+

My Company

+ + + +
+ + isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : array(), + )); ?> + + +
+ + + endBody(); ?> +
+ + + +endPage(); ?> diff --git a/apps/advanced/frontend/views/site/about.php b/apps/advanced/frontend/views/site/about.php new file mode 100644 index 0000000..86e19e1 --- /dev/null +++ b/apps/advanced/frontend/views/site/about.php @@ -0,0 +1,16 @@ +title = 'About'; +$this->params['breadcrumbs'][] = $this->title; +?> +

title); ?>

+ +

+ This is the About page. You may modify the following file to customize its content: +

+ + + diff --git a/apps/advanced/frontend/views/site/contact.php b/apps/advanced/frontend/views/site/contact.php new file mode 100644 index 0000000..e740d0f --- /dev/null +++ b/apps/advanced/frontend/views/site/contact.php @@ -0,0 +1,46 @@ +title = 'Contact'; +$this->params['breadcrumbs'][] = $this->title; +?> +

title); ?>

+ +session->hasFlash('contactFormSubmitted')): ?> +
+ Thank you for contacting us. We will respond to you as soon as possible. +
+ + +

+ If you have business inquiries or other questions, please fill out the following form to contact us. Thank you. +

+ + array('class' => 'form-horizontal'), + 'fieldConfig' => array('inputOptions' => array('class' => 'input-xlarge')), +)); ?> + field($model, 'name')->textInput(); ?> + field($model, 'email')->textInput(); ?> + field($model, 'subject')->textInput(); ?> + field($model, 'body')->textArea(array('rows' => 6)); ?> + field($model, 'verifyCode'); + echo $field->begin() + . $field->label() + . Captcha::widget() + . Html::activeTextInput($model, 'verifyCode', array('class' => 'input-medium')) + . $field->error() + . $field->end(); + ?> +
+ 'btn btn-primary')); ?> +
+ diff --git a/apps/advanced/frontend/views/site/index.php b/apps/advanced/frontend/views/site/index.php new file mode 100644 index 0000000..158b61c --- /dev/null +++ b/apps/advanced/frontend/views/site/index.php @@ -0,0 +1,47 @@ +title = 'Welcome'; +?> +
+

Welcome!

+ +

Cras justo odio, dapibus ac facilisis in, egestas eget quam. Fusce dapibus, tellus ac cursus + commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.

+ Get started with Yii +
+ +
+ + +
+
+

Heading

+ +

Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris + condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. + Donec sed odio dui.

+ +

View details »

+
+
+

Heading

+ +

Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris + condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. + Donec sed odio dui.

+ +

View details »

+
+
+

Heading

+ +

Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta + felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum + massa.

+ +

View details »

+
+
+ diff --git a/apps/advanced/frontend/views/site/login.php b/apps/advanced/frontend/views/site/login.php new file mode 100644 index 0000000..f676b98 --- /dev/null +++ b/apps/advanced/frontend/views/site/login.php @@ -0,0 +1,24 @@ +title = 'Login'; +$this->params['breadcrumbs'][] = $this->title; +?> +

title); ?>

+ +

Please fill out the following fields to login:

+ + array('class' => 'form-horizontal'))); ?> + field($model, 'username')->textInput(); ?> + field($model, 'password')->passwordInput(); ?> + field($model, 'rememberMe')->checkbox(); ?> +
+ 'btn btn-primary')); ?> +
+ diff --git a/apps/advanced/frontend/www/assets/.gitignore b/apps/advanced/frontend/www/assets/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/apps/advanced/frontend/www/assets/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/apps/advanced/frontend/www/css/site.css b/apps/advanced/frontend/www/css/site.css new file mode 100644 index 0000000..890a953 --- /dev/null +++ b/apps/advanced/frontend/www/css/site.css @@ -0,0 +1,78 @@ +body { + padding-top: 20px; + padding-bottom: 60px; +} + +/* Custom container */ +.container { + margin: 0 auto; + max-width: 1000px; +} + +.container > hr { + margin: 60px 0; +} + +/* Main marketing message and sign up button */ +.jumbotron { + margin: 80px 0; + text-align: center; +} + +.jumbotron h1 { + font-size: 100px; + line-height: 1; +} + +.jumbotron .lead { + font-size: 24px; + line-height: 1.25; +} + +.jumbotron .btn { + font-size: 21px; + padding: 14px 24px; +} + +/* Supporting marketing content */ +.marketing { + margin: 60px 0; +} + +.marketing p + h4 { + margin-top: 28px; +} + +/* Customize the navbar links to be fill the entire space of the .navbar */ +.navbar .navbar-inner { + padding: 0; +} + +.navbar .nav { + margin: 0; + display: table; + width: 100%; +} + +.navbar .nav li { + display: table-cell; + width: 1%; + float: none; +} + +.navbar .nav li a { + font-weight: bold; + text-align: center; + border-left: 1px solid rgba(255, 255, 255, .75); + border-right: 1px solid rgba(0, 0, 0, .1); +} + +.navbar .nav li:first-child a { + border-left: 0; + border-radius: 3px 0 0 3px; +} + +.navbar .nav li:last-child a { + border-right: 0; + border-radius: 0 3px 3px 0; +} diff --git a/apps/advanced/install/dev/backstage/config/main-local.php b/apps/advanced/install/dev/backstage/config/main-local.php new file mode 100644 index 0000000..5b61b0e --- /dev/null +++ b/apps/advanced/install/dev/backstage/config/main-local.php @@ -0,0 +1,3 @@ +run(); diff --git a/apps/advanced/install/dev/common/config/params-local.php b/apps/advanced/install/dev/common/config/params-local.php new file mode 100644 index 0000000..2670143 --- /dev/null +++ b/apps/advanced/install/dev/common/config/params-local.php @@ -0,0 +1,3 @@ +run(); diff --git a/apps/advanced/requirements.php b/apps/advanced/requirements.php new file mode 100644 index 0000000..5a2d910 --- /dev/null +++ b/apps/advanced/requirements.php @@ -0,0 +1,96 @@ + 'PDO extension', + 'mandatory' => true, + 'condition' => extension_loaded('pdo'), + 'by' => 'All DB-related classes', + ), + array( + 'name' => 'PDO SQLite extension', + 'mandatory' => false, + 'condition' => extension_loaded('pdo_sqlite'), + 'by' => 'All DB-related classes', + 'memo' => 'Required for SQLite database.', + ), + array( + 'name' => 'PDO MySQL extension', + 'mandatory' => false, + 'condition' => extension_loaded('pdo_mysql'), + 'by' => 'All DB-related classes', + 'memo' => 'Required for MySQL database.', + ), + // Cache : + array( + 'name' => 'Memcache extension', + 'mandatory' => false, + 'condition' => extension_loaded('memcache') || extension_loaded('memcached'), + 'by' => 'CMemCache', + 'memo' => extension_loaded('memcached') ? 'To use memcached set CMemCache::useMemcached to true.' : '' + ), + array( + 'name' => 'APC extension', + 'mandatory' => false, + 'condition' => extension_loaded('apc') || extension_loaded('apc'), + 'by' => 'CApcCache', + ), + // Additional PHP extensions : + array( + 'name' => 'Mcrypt extension', + 'mandatory' => false, + 'condition' => extension_loaded('mcrypt'), + 'by' => 'CSecurityManager', + 'memo' => 'Required by encrypt and decrypt methods.' + ), + // PHP ini : + 'phpSafeMode' => array( + 'name' => 'PHP safe mode', + 'mandatory' => false, + 'condition' => $requirementsChecker->checkPhpIniOff("safe_mode"), + 'by' => 'File uploading and console command execution', + 'memo' => '"safe_mode" should be disabled at php.ini', + ), + 'phpExposePhp' => array( + 'name' => 'Expose PHP', + 'mandatory' => false, + 'condition' => $requirementsChecker->checkPhpIniOff("expose_php"), + 'by' => 'Security reasons', + 'memo' => '"expose_php" should be disabled at php.ini', + ), + 'phpAllowUrlInclude' => array( + 'name' => 'PHP allow url include', + 'mandatory' => false, + 'condition' => $requirementsChecker->checkPhpIniOff("allow_url_include"), + 'by' => 'Security reasons', + 'memo' => '"allow_url_include" should be disabled at php.ini', + ), + 'phpSmtp' => array( + 'name' => 'PHP mail SMTP', + 'mandatory' => false, + 'condition' => strlen(ini_get('SMTP'))>0, + 'by' => 'Email sending', + 'memo' => 'PHP mail SMTP server required', + ), +); +$requirementsChecker->checkYii()->check($requirements)->render(); diff --git a/apps/advanced/vendor/.gitignore b/apps/advanced/vendor/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/apps/advanced/vendor/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/apps/advanced/yii b/apps/advanced/yii new file mode 100644 index 0000000..afcba03 --- /dev/null +++ b/apps/advanced/yii @@ -0,0 +1,26 @@ +#!/usr/bin/env php +run(); diff --git a/apps/advanced/yii.bat b/apps/advanced/yii.bat new file mode 100644 index 0000000..5e21e2e --- /dev/null +++ b/apps/advanced/yii.bat @@ -0,0 +1,20 @@ +@echo off + +rem ------------------------------------------------------------- +rem Yii command line bootstrap script for Windows. +rem +rem @author Qiang Xue +rem @link http://www.yiiframework.com/ +rem @copyright Copyright © 2012 Yii Software LLC +rem @license http://www.yiiframework.com/license/ +rem ------------------------------------------------------------- + +@setlocal + +set YII_PATH=%~dp0 + +if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe + +"%PHP_COMMAND%" "%YII_PATH%yii" %* + +@endlocal From 54eafd82945253bf5ae86de5daccf63a41f8e397 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 24 May 2013 19:00:58 +0400 Subject: [PATCH 019/122] Moved $params in basic application configs to the variable at the top so it can be reused for common component definitions if needed --- apps/basic/config/console.php | 4 ++-- apps/basic/config/main.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/basic/config/console.php b/apps/basic/config/console.php index df96023..bfb3ed7 100644 --- a/apps/basic/config/console.php +++ b/apps/basic/config/console.php @@ -1,5 +1,5 @@ 'bootstrap-console', 'basePath' => dirname(__DIR__), @@ -22,5 +22,5 @@ return array( ), ), ), - 'params' => require(__DIR__ . '/params.php'), + 'params' => $params, ); diff --git a/apps/basic/config/main.php b/apps/basic/config/main.php index b5980da..9adfba6 100644 --- a/apps/basic/config/main.php +++ b/apps/basic/config/main.php @@ -1,5 +1,5 @@ 'bootstrap', 'basePath' => dirname(__DIR__), @@ -34,5 +34,5 @@ return array( ), ), ), - 'params' => require(__DIR__ . '/params.php'), + 'params' => $params, ); From 4503067c08d775f0860c2715f723e671a0c57ad6 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 24 May 2013 19:12:30 +0400 Subject: [PATCH 020/122] Corrected basic application readme --- apps/basic/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/basic/README.md b/apps/basic/README.md index 47e5ca6..5300448 100644 --- a/apps/basic/README.md +++ b/apps/basic/README.md @@ -52,7 +52,7 @@ You can then install the Bootstrap Application using the following command: php composer.phar create-project --stability=dev yiisoft/yii2-app-basic yii-basic ~~~ -Now you should be able to access the Bootstrap Application using the URL `http://localhost/yii-basic/www/`, +Now you should be able to access the application using the URL `http://localhost/yii-basic/www/`, assuming `yii-basic` is directly under the document root of your Web server. From 93df0731a5e5e3e366f9ef983fe978195ee75dc1 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 24 May 2013 21:52:41 +0400 Subject: [PATCH 021/122] Application assets should not be ignored --- apps/basic/assets/.gitignore | 1 - apps/basic/assets/.gitkeep | 1 + apps/basic/runtime/.gitignore | 1 + apps/basic/vendor/.gitignore | 1 + apps/basic/www/assets/.gitignore | 1 + 5 files changed, 4 insertions(+), 1 deletion(-) delete mode 100644 apps/basic/assets/.gitignore create mode 100644 apps/basic/assets/.gitkeep diff --git a/apps/basic/assets/.gitignore b/apps/basic/assets/.gitignore deleted file mode 100644 index 72e8ffc..0000000 --- a/apps/basic/assets/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/apps/basic/assets/.gitkeep b/apps/basic/assets/.gitkeep new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/apps/basic/assets/.gitkeep @@ -0,0 +1 @@ +* diff --git a/apps/basic/runtime/.gitignore b/apps/basic/runtime/.gitignore index 72e8ffc..c96a04f 100644 --- a/apps/basic/runtime/.gitignore +++ b/apps/basic/runtime/.gitignore @@ -1 +1,2 @@ * +!.gitignore \ No newline at end of file diff --git a/apps/basic/vendor/.gitignore b/apps/basic/vendor/.gitignore index 72e8ffc..c96a04f 100644 --- a/apps/basic/vendor/.gitignore +++ b/apps/basic/vendor/.gitignore @@ -1 +1,2 @@ * +!.gitignore \ No newline at end of file diff --git a/apps/basic/www/assets/.gitignore b/apps/basic/www/assets/.gitignore index 72e8ffc..c96a04f 100644 --- a/apps/basic/www/assets/.gitignore +++ b/apps/basic/www/assets/.gitignore @@ -1 +1,2 @@ * +!.gitignore \ No newline at end of file From f3554048a90886c4716d7b5e54042ddd751838ae Mon Sep 17 00:00:00 2001 From: Alexander Kochetov Date: Fri, 24 May 2013 22:04:29 +0400 Subject: [PATCH 022/122] ProgressBar enhancement --- framework/yii/jui/ProgressBar.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/framework/yii/jui/ProgressBar.php b/framework/yii/jui/ProgressBar.php index ab07620..6861a22 100644 --- a/framework/yii/jui/ProgressBar.php +++ b/framework/yii/jui/ProgressBar.php @@ -16,13 +16,27 @@ use yii\helpers\Html; * For example: * * ```php - * echo Progressbar::widget(array( + * echo ProgressBar::widget(array( * 'clientOptions' => array( * 'value' => 75, * ), * )); * ``` * + * The following example will show the content enclosed between the [[begin()]] + * and [[end()]] calls within the widget container: + * + * ~~~php + * ProgressBar::widget(array( + * 'clientOptions' => array( + * 'value' => 75, + * ), + * )); + * + * echo '
Loading...
'; + * + * ProgressBar::end(); + * ~~~ * @see http://api.jqueryui.com/progressbar/ * @author Alexander Kochetov * @since 2.0 @@ -30,11 +44,19 @@ use yii\helpers\Html; class ProgressBar extends Widget { /** + * Initializes the widget. + */ + public function init() + { + parent::init(); + echo Html::beginTag('div', $this->options) . "\n"; + } + + /** * Renders the widget. */ public function run() { - echo Html::beginTag('div', $this->options) . "\n"; echo Html::endTag('div') . "\n"; $this->registerWidget('progressbar'); } From a16d3cd37099a10c65095e76e0e8ea2567b0f219 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 24 May 2013 15:19:59 -0300 Subject: [PATCH 023/122] Do explicit check of local config file. --- apps/advanced/yii | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/advanced/yii b/apps/advanced/yii index afcba03..70e730d 100644 --- a/apps/advanced/yii +++ b/apps/advanced/yii @@ -16,10 +16,10 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php'); require(__DIR__ . '/vendor/autoload.php'); -$config = require(__DIR__ . 'console/config/main.php'); -$localConfig = @include(__DIR__ . 'console/config/main-local.php'); -if($localConfig!==false) { - $config = yii\helpers\ArrayHelper::merge($config, $localConfig); +$config = require(__DIR__ . '/console/config/main.php'); +$localConfig = __DIR__ . '/console/config/main-local.php'); +if (is_file($localeConfig)) { + $config = yii\helpers\ArrayHelper::merge($config, require($localConfig)); } $application = new yii\console\Application($config); From 0e7808595b8adc72595a9379716c14457309a80f Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 24 May 2013 15:20:33 -0300 Subject: [PATCH 024/122] typo fix --- apps/advanced/yii | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/advanced/yii b/apps/advanced/yii index 70e730d..77d58cb 100644 --- a/apps/advanced/yii +++ b/apps/advanced/yii @@ -17,7 +17,7 @@ require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php'); require(__DIR__ . '/vendor/autoload.php'); $config = require(__DIR__ . '/console/config/main.php'); -$localConfig = __DIR__ . '/console/config/main-local.php'); +$localConfig = __DIR__ . '/console/config/main-local.php'; if (is_file($localeConfig)) { $config = yii\helpers\ArrayHelper::merge($config, require($localConfig)); } From 0411f09a43902b3e487c032c38c2670425194c62 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 24 May 2013 23:05:41 +0400 Subject: [PATCH 025/122] Added install tool, moved all local configs and entry points to environments --- apps/advanced/.gitignore | 1 + apps/advanced/README.md | 5 +- apps/advanced/console/controllers/.gitkeep | 0 .../console/controllers/HelloController.php | 29 ------ .../console/controllers/InstallController.php | 13 --- apps/advanced/console/models/.gitkeep | 1 + .../dev/backstage/config/main-local.php | 3 + .../dev/backstage/config/params-local.php | 3 + .../environments/dev/backstage/www/index.php | 14 +++ .../dev/common/config/params-local.php | 3 + .../environments/dev/console/config/main-local.php | 3 + .../dev/console/config/params-local.php | 3 + .../dev/frontend/config/main-local.php | 3 + .../dev/frontend/config/params-local.php | 3 + .../environments/dev/frontend/www/index.php | 15 +++ apps/advanced/environments/dev/yii | 25 +++++ apps/advanced/environments/index.php | 38 +++++++ apps/advanced/install | 111 +++++++++++++++++++++ .../install/dev/backstage/config/main-local.php | 3 - .../install/dev/backstage/config/params-local.php | 3 - apps/advanced/install/dev/backstage/www/index.php | 14 --- .../install/dev/common/config/params-local.php | 3 - .../install/dev/console/config/main-local.php | 3 - .../install/dev/console/config/params-local.php | 3 - .../install/dev/frontend/config/main-local.php | 3 - .../install/dev/frontend/config/params-local.php | 3 - apps/advanced/install/dev/frontend/www/index.php | 15 --- apps/advanced/yii | 26 ----- 28 files changed, 227 insertions(+), 122 deletions(-) create mode 100644 apps/advanced/.gitignore create mode 100644 apps/advanced/console/controllers/.gitkeep delete mode 100644 apps/advanced/console/controllers/HelloController.php delete mode 100644 apps/advanced/console/controllers/InstallController.php create mode 100644 apps/advanced/console/models/.gitkeep create mode 100644 apps/advanced/environments/dev/backstage/config/main-local.php create mode 100644 apps/advanced/environments/dev/backstage/config/params-local.php create mode 100644 apps/advanced/environments/dev/backstage/www/index.php create mode 100644 apps/advanced/environments/dev/common/config/params-local.php create mode 100644 apps/advanced/environments/dev/console/config/main-local.php create mode 100644 apps/advanced/environments/dev/console/config/params-local.php create mode 100644 apps/advanced/environments/dev/frontend/config/main-local.php create mode 100644 apps/advanced/environments/dev/frontend/config/params-local.php create mode 100644 apps/advanced/environments/dev/frontend/www/index.php create mode 100644 apps/advanced/environments/dev/yii create mode 100644 apps/advanced/environments/index.php create mode 100644 apps/advanced/install delete mode 100644 apps/advanced/install/dev/backstage/config/main-local.php delete mode 100644 apps/advanced/install/dev/backstage/config/params-local.php delete mode 100644 apps/advanced/install/dev/backstage/www/index.php delete mode 100644 apps/advanced/install/dev/common/config/params-local.php delete mode 100644 apps/advanced/install/dev/console/config/main-local.php delete mode 100644 apps/advanced/install/dev/console/config/params-local.php delete mode 100644 apps/advanced/install/dev/frontend/config/main-local.php delete mode 100644 apps/advanced/install/dev/frontend/config/params-local.php delete mode 100644 apps/advanced/install/dev/frontend/www/index.php delete mode 100644 apps/advanced/yii diff --git a/apps/advanced/.gitignore b/apps/advanced/.gitignore new file mode 100644 index 0000000..b1cf719 --- /dev/null +++ b/apps/advanced/.gitignore @@ -0,0 +1 @@ +/yii \ No newline at end of file diff --git a/apps/advanced/README.md b/apps/advanced/README.md index 08f0b0d..f088fc8 100644 --- a/apps/advanced/README.md +++ b/apps/advanced/README.md @@ -20,12 +20,10 @@ DIRECTORY STRUCTURE ``` common config/ contains shared configurations - env/ contains environment-based overrides models/ contains model classes used in both backstage and frontend console config/ contains console configurations controllers/ contains console controllers (commands) - env/ contains environment-based overrides migrations/ contains database migrations models/ contains console-specific model classes runtime/ contains files generated during runtime @@ -33,7 +31,6 @@ backstage assets/ contains application assets such as JavaScript and CSS config/ contains backstage configurations controllers/ contains Web controller classes - env/ contains environment-based overrides models/ contains backstage-specific model classes runtime/ contains files generated during runtime views/ contains view files for the Web application @@ -42,12 +39,12 @@ frontend assets/ contains application assets such as JavaScript and CSS config/ contains frontend configurations controllers/ contains Web controller classes - env/ contains environment-based overrides models/ contains frontend-specific model classes runtime/ contains files generated during runtime views/ contains view files for the Web application www/ contains the entry script and Web resources vendor/ contains dependent 3rd-party packages +environments/ contains environment-based overrides ``` diff --git a/apps/advanced/console/controllers/.gitkeep b/apps/advanced/console/controllers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/apps/advanced/console/controllers/HelloController.php b/apps/advanced/console/controllers/HelloController.php deleted file mode 100644 index 603c6e8..0000000 --- a/apps/advanced/console/controllers/HelloController.php +++ /dev/null @@ -1,29 +0,0 @@ - - * @since 2.0 - */ -class HelloController extends Controller -{ - /** - * This command echos what you have entered as the message. - * @param string $message the message to be echoed. - */ - public function actionIndex($message = 'hello world') - { - echo $message."\n"; - } -} \ No newline at end of file diff --git a/apps/advanced/console/controllers/InstallController.php b/apps/advanced/console/controllers/InstallController.php deleted file mode 100644 index cbc2227..0000000 --- a/apps/advanced/console/controllers/InstallController.php +++ /dev/null @@ -1,13 +0,0 @@ -run(); diff --git a/apps/advanced/environments/dev/common/config/params-local.php b/apps/advanced/environments/dev/common/config/params-local.php new file mode 100644 index 0000000..2670143 --- /dev/null +++ b/apps/advanced/environments/dev/common/config/params-local.php @@ -0,0 +1,3 @@ +run(); diff --git a/apps/advanced/environments/dev/yii b/apps/advanced/environments/dev/yii new file mode 100644 index 0000000..d763217 --- /dev/null +++ b/apps/advanced/environments/dev/yii @@ -0,0 +1,25 @@ +#!/usr/bin/env php +run(); diff --git a/apps/advanced/environments/index.php b/apps/advanced/environments/index.php new file mode 100644 index 0000000..ff907d2 --- /dev/null +++ b/apps/advanced/environments/index.php @@ -0,0 +1,38 @@ + array( + * 'path' => 'directory storing the local files', + * 'writable' => array( + * // list of directories that should be set writable + * ), + * ), + * ); + * ``` + */ +return array( + 'Development' => array( + 'path' => 'dev', + 'writable' => array( + // handled by composer.json already + ), + 'executable' => array( + 'yiic', + ), + ), + 'Production' => array( + 'path' => 'prod', + 'writable' => array( + // handled by composer.json already + ), + 'executable' => array( + 'yiic', + ), + ), +); diff --git a/apps/advanced/install b/apps/advanced/install new file mode 100644 index 0000000..2204acd --- /dev/null +++ b/apps/advanced/install @@ -0,0 +1,111 @@ + $name) { + echo " [$i] $name\n"; +} +echo "\n Your choice [0-" . (count($envs) - 1) . ', or "q" to quit] '; +$answer = trim(fgets(STDIN)); +if (!ctype_digit($answer) || !isset($envNames[$answer])) { + echo "\n Quit installation.\n"; + return; +} + +$env = $envs[$envNames[$answer]]; +echo "\n Install the application under '{$envNames[$answer]}' environment? [yes|no] "; +$answer = trim(fgets(STDIN)); +if (strncasecmp($answer, 'y', 1)) { + echo "\n Quit installation.\n"; + return; +} + +echo "\n Start installation ...\n\n"; +$files = getFileList("$root/install/{$env['path']}"); +$all = false; +foreach ($files as $file) { + if (!copyFile($root, "install/{$env['path']}/$file", $file, $all)) { + break; + } +} + +if (isset($env['writable'])) { + foreach ($env['writable'] as $writable) { + echo " chmod 0777 $writable\n"; + @chmod("$root/$writable", 0777); + } +} + +if (isset($env['executable'])) { + foreach ($env['executable'] as $executable) { + echo " chmod 0755 $executable\n"; + @chmod("$root/$executable", 0755); + } +} + +echo "\n ... installation completed.\n\n"; + +function getFileList($root, $basePath = '') +{ + $files = array(); + $handle = opendir($root); + while (($path = readdir($handle)) !== false) { + if ($path === '.svn' || $path === '.' || $path === '..') { + continue; + } + $fullPath = "$root/$path"; + $relativePath = $basePath === '' ? $path : "$basePath/$path"; + if (is_dir($fullPath)) { + $files = array_merge($files, getFileList($fullPath, $relativePath)); + } else { + $files[] = $relativePath; + } + } + closedir($handle); + return $files; +} + +function copyFile($root, $source, $target, &$all) +{ + if (!is_file($root . '/' . $source)) { + echo " skip $target ($source not exist)\n"; + return true; + } + if (is_file($root . '/' . $target)) { + if (file_get_contents($root . '/' . $source) === file_get_contents($root . '/' . $target)) { + echo " unchanged $target\n"; + return true; + } + if ($all) { + echo " overwrite $target\n"; + } else { + echo " exist $target\n"; + echo " ...overwrite? [Yes|No|All|Quit] "; + $answer = trim(fgets(STDIN)); + if (!strncasecmp($answer, 'q', 1)) { + return false; + } else { + if (!strncasecmp($answer, 'y', 1)) { + echo " overwrite $target\n"; + } else { + if (!strncasecmp($answer, 'a', 1)) { + echo " overwrite $target\n"; + $all = true; + } else { + echo " skip $target\n"; + return true; + } + } + } + } + file_put_contents($root . '/' . $target, file_get_contents($root . '/' . $source)); + return true; + } + echo " generate $target\n"; + @mkdir(dirname($root . '/' . $target), 0777, true); + file_put_contents($root . '/' . $target, file_get_contents($root . '/' . $source)); + return true; +} diff --git a/apps/advanced/install/dev/backstage/config/main-local.php b/apps/advanced/install/dev/backstage/config/main-local.php deleted file mode 100644 index 5b61b0e..0000000 --- a/apps/advanced/install/dev/backstage/config/main-local.php +++ /dev/null @@ -1,3 +0,0 @@ -run(); diff --git a/apps/advanced/install/dev/common/config/params-local.php b/apps/advanced/install/dev/common/config/params-local.php deleted file mode 100644 index 2670143..0000000 --- a/apps/advanced/install/dev/common/config/params-local.php +++ /dev/null @@ -1,3 +0,0 @@ -run(); diff --git a/apps/advanced/yii b/apps/advanced/yii deleted file mode 100644 index 77d58cb..0000000 --- a/apps/advanced/yii +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env php -run(); From 4c1378cb513f7e40b7d2fcb9a941abe1c1e7b8cf Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 24 May 2013 23:09:55 +0400 Subject: [PATCH 026/122] Adjusted paths, added install.bat --- apps/advanced/install | 6 +++--- apps/advanced/install.bat | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 apps/advanced/install.bat diff --git a/apps/advanced/install b/apps/advanced/install index 2204acd..a2f0160 100644 --- a/apps/advanced/install +++ b/apps/advanced/install @@ -1,6 +1,6 @@ +rem @link http://www.yiiframework.com/ +rem @copyright Copyright © 2012 Yii Software LLC +rem @license http://www.yiiframework.com/license/ +rem ------------------------------------------------------------- + +@setlocal + +set YII_PATH=%~dp0 + +if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe + +"%PHP_COMMAND%" "%YII_PATH%install" %* + +@endlocal From fb1013e6193933ccf6d27dc1e3d8c068bba06573 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 24 May 2013 23:11:40 +0400 Subject: [PATCH 027/122] Ignores for frontend/backstage index.php --- apps/advanced/backstage/www/.gitignore | 1 + apps/advanced/frontend/www/.gitignore | 1 + 2 files changed, 2 insertions(+) create mode 100644 apps/advanced/backstage/www/.gitignore create mode 100644 apps/advanced/frontend/www/.gitignore diff --git a/apps/advanced/backstage/www/.gitignore b/apps/advanced/backstage/www/.gitignore new file mode 100644 index 0000000..148f2b0 --- /dev/null +++ b/apps/advanced/backstage/www/.gitignore @@ -0,0 +1 @@ +/index.php \ No newline at end of file diff --git a/apps/advanced/frontend/www/.gitignore b/apps/advanced/frontend/www/.gitignore new file mode 100644 index 0000000..148f2b0 --- /dev/null +++ b/apps/advanced/frontend/www/.gitignore @@ -0,0 +1 @@ +/index.php \ No newline at end of file From 4a9f0eed0ceb1c2615a54901cb7e679c156c8ca8 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 24 May 2013 23:34:07 +0400 Subject: [PATCH 028/122] Moved commented sections into -local configs, added prod environment --- apps/advanced/backstage/config/main.php | 10 +-------- apps/advanced/console/config/main.php | 7 ++---- .../dev/backstage/config/main-local.php | 14 ++++++++++++ .../dev/frontend/config/main-local.php | 14 ++++++++++++ .../prod/backstage/config/main-local.php | 3 +++ .../prod/backstage/config/params-local.php | 3 +++ .../environments/prod/backstage/www/index.php | 14 ++++++++++++ .../prod/common/config/params-local.php | 3 +++ .../prod/console/config/main-local.php | 3 +++ .../prod/console/config/params-local.php | 3 +++ .../prod/frontend/config/main-local.php | 3 +++ .../prod/frontend/config/params-local.php | 3 +++ .../environments/prod/frontend/www/index.php | 15 +++++++++++++ apps/advanced/environments/prod/yii | 25 ++++++++++++++++++++++ apps/advanced/frontend/config/main.php | 12 ++--------- 15 files changed, 108 insertions(+), 24 deletions(-) create mode 100644 apps/advanced/environments/prod/backstage/config/main-local.php create mode 100644 apps/advanced/environments/prod/backstage/config/params-local.php create mode 100644 apps/advanced/environments/prod/backstage/www/index.php create mode 100644 apps/advanced/environments/prod/common/config/params-local.php create mode 100644 apps/advanced/environments/prod/console/config/main-local.php create mode 100644 apps/advanced/environments/prod/console/config/params-local.php create mode 100644 apps/advanced/environments/prod/frontend/config/main-local.php create mode 100644 apps/advanced/environments/prod/frontend/config/params-local.php create mode 100644 apps/advanced/environments/prod/frontend/www/index.php create mode 100644 apps/advanced/environments/prod/yii diff --git a/apps/advanced/backstage/config/main.php b/apps/advanced/backstage/config/main.php index 3fb95da..561dae1 100644 --- a/apps/advanced/backstage/config/main.php +++ b/apps/advanced/backstage/config/main.php @@ -14,14 +14,9 @@ return array( 'preload' => array('log'), 'controllerNamespace' => 'app\controllers', 'modules' => array( -// 'debug' => array( -// 'class' => 'yii\debug\Module', -// ) ), 'components' => array( - 'cache' => array( - 'class' => 'yii\caching\FileCache', - ), + 'cache' => $params['components.cache'], 'user' => array( 'class' => 'yii\web\User', 'identityClass' => 'app\models\User', @@ -36,9 +31,6 @@ return array( 'class' => 'yii\logging\FileTarget', 'levels' => array('error', 'warning'), ), -// array( -// 'class' => 'yii\logging\DebugTarget', -// ) ), ), ), diff --git a/apps/advanced/console/config/main.php b/apps/advanced/console/config/main.php index 7af7824..f5e488c 100644 --- a/apps/advanced/console/config/main.php +++ b/apps/advanced/console/config/main.php @@ -9,17 +9,14 @@ $params = array_merge( ); return array( - 'id' => 'bootstrap-console', + 'id' => 'change-me', 'basePath' => dirname(__DIR__), 'preload' => array('log'), - 'controllerPath' => dirname(__DIR__) . '/commands', 'controllerNamespace' => 'app\controllers', 'modules' => array( ), 'components' => array( - 'cache' => array( - 'class' => 'yii\caching\FileCache', - ), + 'cache' => $params['components.cache'], 'log' => array( 'class' => 'yii\logging\Router', 'targets' => array( diff --git a/apps/advanced/environments/dev/backstage/config/main-local.php b/apps/advanced/environments/dev/backstage/config/main-local.php index 5b61b0e..f74bfa3 100644 --- a/apps/advanced/environments/dev/backstage/config/main-local.php +++ b/apps/advanced/environments/dev/backstage/config/main-local.php @@ -1,3 +1,17 @@ array( +// 'debug' => array( +// 'class' => 'yii\debug\Module', +// ), + ), + 'components' => array( + 'log' => array( + 'targets' => array( +// array( +// 'class' => 'yii\logging\DebugTarget', +// ) + ), + ), + ), ); diff --git a/apps/advanced/environments/dev/frontend/config/main-local.php b/apps/advanced/environments/dev/frontend/config/main-local.php index 5b61b0e..b77abed 100644 --- a/apps/advanced/environments/dev/frontend/config/main-local.php +++ b/apps/advanced/environments/dev/frontend/config/main-local.php @@ -1,3 +1,17 @@ array( +// 'debug' => array( +// 'class' => 'yii\debug\Module', +// ), + ), + 'components' => array( + 'log' => array( + 'targets' => array( +// array( +// 'class' => 'yii\logging\DebugTarget', +// ) + ), + ), + ), ); diff --git a/apps/advanced/environments/prod/backstage/config/main-local.php b/apps/advanced/environments/prod/backstage/config/main-local.php new file mode 100644 index 0000000..5b61b0e --- /dev/null +++ b/apps/advanced/environments/prod/backstage/config/main-local.php @@ -0,0 +1,3 @@ +run(); diff --git a/apps/advanced/environments/prod/common/config/params-local.php b/apps/advanced/environments/prod/common/config/params-local.php new file mode 100644 index 0000000..2670143 --- /dev/null +++ b/apps/advanced/environments/prod/common/config/params-local.php @@ -0,0 +1,3 @@ +run(); diff --git a/apps/advanced/environments/prod/yii b/apps/advanced/environments/prod/yii new file mode 100644 index 0000000..395aede --- /dev/null +++ b/apps/advanced/environments/prod/yii @@ -0,0 +1,25 @@ +#!/usr/bin/env php +run(); diff --git a/apps/advanced/frontend/config/main.php b/apps/advanced/frontend/config/main.php index 9379e06..561dae1 100644 --- a/apps/advanced/frontend/config/main.php +++ b/apps/advanced/frontend/config/main.php @@ -9,19 +9,14 @@ $params = array_merge( ); return array( - 'id' => 'bootstrap', + 'id' => 'change-me', 'basePath' => dirname(__DIR__), 'preload' => array('log'), 'controllerNamespace' => 'app\controllers', 'modules' => array( -// 'debug' => array( -// 'class' => 'yii\debug\Module', -// ) ), 'components' => array( - 'cache' => array( - 'class' => 'yii\caching\FileCache', - ), + 'cache' => $params['components.cache'], 'user' => array( 'class' => 'yii\web\User', 'identityClass' => 'app\models\User', @@ -36,9 +31,6 @@ return array( 'class' => 'yii\logging\FileTarget', 'levels' => array('error', 'warning'), ), -// array( -// 'class' => 'yii\logging\DebugTarget', -// ) ), ), ), From e8d59fb6cbe4f8ef59afbeecaeec220750eac6da Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 24 May 2013 23:37:22 +0400 Subject: [PATCH 029/122] specified proper namespaces --- apps/advanced/backstage/config/main.php | 2 +- .../backstage/controllers/SiteController.php | 2 +- apps/advanced/common/models/ContactForm.php | 63 ---------------------- apps/advanced/common/models/LoginForm.php | 58 -------------------- apps/advanced/common/models/User.php | 2 +- apps/advanced/console/config/main.php | 2 +- apps/advanced/frontend/config/main.php | 2 +- .../frontend/controllers/SiteController.php | 2 +- apps/advanced/frontend/models/ContactForm.php | 2 +- apps/advanced/frontend/models/LoginForm.php | 2 +- apps/advanced/frontend/models/User.php | 2 +- 11 files changed, 9 insertions(+), 130 deletions(-) delete mode 100644 apps/advanced/common/models/ContactForm.php delete mode 100644 apps/advanced/common/models/LoginForm.php diff --git a/apps/advanced/backstage/config/main.php b/apps/advanced/backstage/config/main.php index 561dae1..6204f50 100644 --- a/apps/advanced/backstage/config/main.php +++ b/apps/advanced/backstage/config/main.php @@ -12,7 +12,7 @@ return array( 'id' => 'change-me', 'basePath' => dirname(__DIR__), 'preload' => array('log'), - 'controllerNamespace' => 'app\controllers', + 'controllerNamespace' => 'backstage\controllers', 'modules' => array( ), 'components' => array( diff --git a/apps/advanced/backstage/controllers/SiteController.php b/apps/advanced/backstage/controllers/SiteController.php index ff3b8b4..192884b 100644 --- a/apps/advanced/backstage/controllers/SiteController.php +++ b/apps/advanced/backstage/controllers/SiteController.php @@ -1,6 +1,6 @@ 'Verification Code', - ); - } - - /** - * Sends an email to the specified email address using the information collected by this model. - * @param string $email the target email address - * @return boolean whether the model passes validation - */ - public function contact($email) - { - if ($this->validate()) { - $name = '=?UTF-8?B?' . base64_encode($this->name) . '?='; - $subject = '=?UTF-8?B?' . base64_encode($this->subject) . '?='; - $headers = "From: $name <{$this->email}>\r\n" . - "Reply-To: {$this->email}\r\n" . - "MIME-Version: 1.0\r\n" . - "Content-type: text/plain; charset=UTF-8"; - mail($email, $subject, $this->body, $headers); - return true; - } else { - return false; - } - } -} diff --git a/apps/advanced/common/models/LoginForm.php b/apps/advanced/common/models/LoginForm.php deleted file mode 100644 index 5ba1dc6..0000000 --- a/apps/advanced/common/models/LoginForm.php +++ /dev/null @@ -1,58 +0,0 @@ -username); - if (!$user || !$user->validatePassword($this->password)) { - $this->addError('password', 'Incorrect username or password.'); - } - } - - /** - * Logs in a user using the provided username and password. - * @return boolean whether the user is logged in successfully - */ - public function login() - { - if ($this->validate()) { - $user = User::findByUsername($this->username); - Yii::$app->user->login($user, $this->rememberMe ? 3600*24*30 : 0); - return true; - } else { - return false; - } - } -} diff --git a/apps/advanced/common/models/User.php b/apps/advanced/common/models/User.php index afbf9f8..035f1fb 100644 --- a/apps/advanced/common/models/User.php +++ b/apps/advanced/common/models/User.php @@ -1,6 +1,6 @@ 'change-me', 'basePath' => dirname(__DIR__), 'preload' => array('log'), - 'controllerNamespace' => 'app\controllers', + 'controllerNamespace' => 'console\controllers', 'modules' => array( ), 'components' => array( diff --git a/apps/advanced/frontend/config/main.php b/apps/advanced/frontend/config/main.php index 561dae1..eac7c4d 100644 --- a/apps/advanced/frontend/config/main.php +++ b/apps/advanced/frontend/config/main.php @@ -12,7 +12,7 @@ return array( 'id' => 'change-me', 'basePath' => dirname(__DIR__), 'preload' => array('log'), - 'controllerNamespace' => 'app\controllers', + 'controllerNamespace' => 'frontend\controllers', 'modules' => array( ), 'components' => array( diff --git a/apps/advanced/frontend/controllers/SiteController.php b/apps/advanced/frontend/controllers/SiteController.php index ff3b8b4..d2ea5a6 100644 --- a/apps/advanced/frontend/controllers/SiteController.php +++ b/apps/advanced/frontend/controllers/SiteController.php @@ -1,6 +1,6 @@ Date: Fri, 24 May 2013 23:44:56 +0400 Subject: [PATCH 030/122] fixed typo --- apps/advanced/common/config/params.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/advanced/common/config/params.php b/apps/advanced/common/config/params.php index 9eb2b15..015be76 100644 --- a/apps/advanced/common/config/params.php +++ b/apps/advanced/common/config/params.php @@ -3,7 +3,7 @@ return array( 'adminEmail' => 'admin@example.com', - 'component.cache' => array( + 'components.cache' => array( 'class' => 'yii\caching\FileCache', ), ); \ No newline at end of file From 987b50cf041f94f7bffe377d54a26481fbab6dde Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 25 May 2013 00:08:24 +0400 Subject: [PATCH 031/122] Added #!/usr/bin/env php --- apps/advanced/install | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/advanced/install b/apps/advanced/install index a2f0160..6864440 100644 --- a/apps/advanced/install +++ b/apps/advanced/install @@ -1,3 +1,4 @@ +#!/usr/bin/env php Date: Sat, 25 May 2013 00:15:17 +0400 Subject: [PATCH 032/122] yii migrate/create should not require db component --- framework/yii/console/controllers/MigrateController.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/framework/yii/console/controllers/MigrateController.php b/framework/yii/console/controllers/MigrateController.php index 0acc672..b437450 100644 --- a/framework/yii/console/controllers/MigrateController.php +++ b/framework/yii/console/controllers/MigrateController.php @@ -115,11 +115,13 @@ class MigrateController extends Controller } $this->migrationPath = $path; - if (is_string($this->db)) { - $this->db = Yii::$app->getComponent($this->db); - } - if (!$this->db instanceof Connection) { - throw new Exception("The 'db' option must refer to the application component ID of a DB connection."); + if($action->id!=='create') { + if (is_string($this->db)) { + $this->db = Yii::$app->getComponent($this->db); + } + if (!$this->db instanceof Connection) { + throw new Exception("The 'db' option must refer to the application component ID of a DB connection."); + } } $version = Yii::getVersion(); From 774a7b52cbf8ddfac70fd7fe4507a2eec8f35242 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 25 May 2013 00:16:30 +0400 Subject: [PATCH 033/122] yiic migrate/create should not require db component --- framework/yii/console/controllers/MigrateController.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/framework/yii/console/controllers/MigrateController.php b/framework/yii/console/controllers/MigrateController.php index 0acc672..b437450 100644 --- a/framework/yii/console/controllers/MigrateController.php +++ b/framework/yii/console/controllers/MigrateController.php @@ -115,11 +115,13 @@ class MigrateController extends Controller } $this->migrationPath = $path; - if (is_string($this->db)) { - $this->db = Yii::$app->getComponent($this->db); - } - if (!$this->db instanceof Connection) { - throw new Exception("The 'db' option must refer to the application component ID of a DB connection."); + if($action->id!=='create') { + if (is_string($this->db)) { + $this->db = Yii::$app->getComponent($this->db); + } + if (!$this->db instanceof Connection) { + throw new Exception("The 'db' option must refer to the application component ID of a DB connection."); + } } $version = Yii::getVersion(); From c4380f65a5753ef41b463718ba7cfd235c1e2f3f Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 25 May 2013 00:23:07 +0400 Subject: [PATCH 034/122] MySQL migration for User model --- apps/advanced/console/migrations/.gitkeep | 1 - .../console/migrations/m130524_201442_init.php | 27 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) delete mode 100644 apps/advanced/console/migrations/.gitkeep create mode 100644 apps/advanced/console/migrations/m130524_201442_init.php diff --git a/apps/advanced/console/migrations/.gitkeep b/apps/advanced/console/migrations/.gitkeep deleted file mode 100644 index 72e8ffc..0000000 --- a/apps/advanced/console/migrations/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/apps/advanced/console/migrations/m130524_201442_init.php b/apps/advanced/console/migrations/m130524_201442_init.php new file mode 100644 index 0000000..24a74c3 --- /dev/null +++ b/apps/advanced/console/migrations/m130524_201442_init.php @@ -0,0 +1,27 @@ +createTable('tbl_user', array( + 'id' => Schema::TYPE_PK, + 'username' => Schema::TYPE_STRING.' NOT NULL', + 'password_hash' => Schema::TYPE_STRING.' NOT NULL', + 'email' => Schema::TYPE_STRING.' NOT NULL', + 'role' => 'tinyint NOT NULL DEFAULT 10', + + 'status' => 'tinyint NOT NULL DEFAULT 10', + 'create_time' => Schema::TYPE_INTEGER.' NOT NULL', + 'update_time' => Schema::TYPE_INTEGER.' NOT NULL', + ), $tableOptions); + } + + public function down() + { + $this->dropTable('tbl_user'); + } +} From ae1576c335a9c96c02e76dc22cfaef3701471e0a Mon Sep 17 00:00:00 2001 From: Alexander Kochetov Date: Sat, 25 May 2013 00:39:14 +0400 Subject: [PATCH 035/122] Remove unnecessary use --- framework/yii/jui/ProgressBar.php | 1 - 1 file changed, 1 deletion(-) diff --git a/framework/yii/jui/ProgressBar.php b/framework/yii/jui/ProgressBar.php index 6861a22..a7697e5 100644 --- a/framework/yii/jui/ProgressBar.php +++ b/framework/yii/jui/ProgressBar.php @@ -7,7 +7,6 @@ namespace yii\jui; -use yii\helpers\base\ArrayHelper; use yii\helpers\Html; /** From b23744ed38dcf813fee8def7fef973fd48548aac Mon Sep 17 00:00:00 2001 From: Alexander Kochetov Date: Sat, 25 May 2013 00:49:28 +0400 Subject: [PATCH 036/122] jQuery UI widget fixes --- framework/yii/jui/Accordion.php | 2 +- framework/yii/jui/Dialog.php | 1 - framework/yii/jui/Tabs.php | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/framework/yii/jui/Accordion.php b/framework/yii/jui/Accordion.php index 6c5dd97..f2e76f6 100644 --- a/framework/yii/jui/Accordion.php +++ b/framework/yii/jui/Accordion.php @@ -8,7 +8,7 @@ namespace yii\jui; use yii\base\InvalidConfigException; -use yii\helpers\base\ArrayHelper; +use yii\helpers\ArrayHelper; use yii\helpers\Html; /** diff --git a/framework/yii/jui/Dialog.php b/framework/yii/jui/Dialog.php index 921758e..f4b3b12 100644 --- a/framework/yii/jui/Dialog.php +++ b/framework/yii/jui/Dialog.php @@ -7,7 +7,6 @@ namespace yii\jui; -use yii\helpers\base\ArrayHelper; use yii\helpers\Html; /** diff --git a/framework/yii/jui/Tabs.php b/framework/yii/jui/Tabs.php index ca0b3da..052ffe7 100644 --- a/framework/yii/jui/Tabs.php +++ b/framework/yii/jui/Tabs.php @@ -8,7 +8,7 @@ namespace yii\jui; use yii\base\InvalidConfigException; -use yii\helpers\base\ArrayHelper; +use yii\helpers\ArrayHelper; use yii\helpers\Html; /** From a46b26b34dc492444cbe7d235b11ddbfc65cbf33 Mon Sep 17 00:00:00 2001 From: Luciano Baraglia Date: Fri, 24 May 2013 18:49:53 -0300 Subject: [PATCH 037/122] requirements: TD html fix - added SPAN in result TD --- framework/yii/requirements/views/web/index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/yii/requirements/views/web/index.php b/framework/yii/requirements/views/web/index.php index 6cd2594..1887f8b 100644 --- a/framework/yii/requirements/views/web/index.php +++ b/framework/yii/requirements/views/web/index.php @@ -56,8 +56,8 @@ - - + + @@ -79,4 +79,4 @@ - \ No newline at end of file + From 75917e2cb112201dd98a5564038bd9578d767a03 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 25 May 2013 03:23:09 +0400 Subject: [PATCH 038/122] User and LoginForm are now common models, User is AR and Identity --- apps/advanced/backstage/config/main.php | 2 +- .../backstage/controllers/SiteController.php | 30 +----- apps/advanced/backstage/views/layouts/main.php | 2 - apps/advanced/backstage/views/site/about.php | 16 --- apps/advanced/backstage/views/site/contact.php | 46 --------- apps/advanced/common/models/LoginForm.php | 58 +++++++++++ apps/advanced/common/models/User.php | 114 +++++++++++++++------ apps/advanced/frontend/config/main.php | 2 +- .../frontend/controllers/SiteController.php | 4 +- apps/advanced/frontend/models/LoginForm.php | 58 ----------- apps/advanced/frontend/models/User.php | 61 ----------- 11 files changed, 147 insertions(+), 246 deletions(-) delete mode 100644 apps/advanced/backstage/views/site/about.php delete mode 100644 apps/advanced/backstage/views/site/contact.php create mode 100644 apps/advanced/common/models/LoginForm.php delete mode 100644 apps/advanced/frontend/models/LoginForm.php delete mode 100644 apps/advanced/frontend/models/User.php diff --git a/apps/advanced/backstage/config/main.php b/apps/advanced/backstage/config/main.php index 6204f50..d47904a 100644 --- a/apps/advanced/backstage/config/main.php +++ b/apps/advanced/backstage/config/main.php @@ -19,7 +19,7 @@ return array( 'cache' => $params['components.cache'], 'user' => array( 'class' => 'yii\web\User', - 'identityClass' => 'app\models\User', + 'identityClass' => 'common\models\User', ), 'assetManager' => array( 'bundles' => require(__DIR__ . '/assets.php'), diff --git a/apps/advanced/backstage/controllers/SiteController.php b/apps/advanced/backstage/controllers/SiteController.php index 192884b..d40738a 100644 --- a/apps/advanced/backstage/controllers/SiteController.php +++ b/apps/advanced/backstage/controllers/SiteController.php @@ -4,20 +4,10 @@ namespace backstage\controllers; use Yii; use yii\web\Controller; -use app\models\LoginForm; -use app\models\ContactForm; +use common\models\LoginForm; class SiteController extends Controller { - public function actions() - { - return array( - 'captcha' => array( - 'class' => 'yii\web\CaptchaAction', - ), - ); - } - public function actionIndex() { echo $this->render('index'); @@ -40,22 +30,4 @@ class SiteController extends Controller Yii::$app->getUser()->logout(); Yii::$app->getResponse()->redirect(array('site/index')); } - - public function actionContact() - { - $model = new ContactForm; - if ($this->populate($_POST, $model) && $model->contact(Yii::$app->params['adminEmail'])) { - Yii::$app->session->setFlash('contactFormSubmitted'); - Yii::$app->response->refresh(); - } else { - echo $this->render('contact', array( - 'model' => $model, - )); - } - } - - public function actionAbout() - { - echo $this->render('about'); - } } diff --git a/apps/advanced/backstage/views/layouts/main.php b/apps/advanced/backstage/views/layouts/main.php index 635e118..44117f4 100644 --- a/apps/advanced/backstage/views/layouts/main.php +++ b/apps/advanced/backstage/views/layouts/main.php @@ -31,8 +31,6 @@ $this->registerAssetBundle('app'); 'options' => array('class' => 'nav'), 'items' => array( array('label' => 'Home', 'url' => array('/site/index')), - array('label' => 'About', 'url' => array('/site/about')), - array('label' => 'Contact', 'url' => array('/site/contact')), Yii::$app->user->isGuest ? array('label' => 'Login', 'url' => array('/site/login')) : array('label' => 'Logout (' . Yii::$app->user->identity->username .')' , 'url' => array('/site/logout')), diff --git a/apps/advanced/backstage/views/site/about.php b/apps/advanced/backstage/views/site/about.php deleted file mode 100644 index 86e19e1..0000000 --- a/apps/advanced/backstage/views/site/about.php +++ /dev/null @@ -1,16 +0,0 @@ -title = 'About'; -$this->params['breadcrumbs'][] = $this->title; -?> -

title); ?>

- -

- This is the About page. You may modify the following file to customize its content: -

- - - diff --git a/apps/advanced/backstage/views/site/contact.php b/apps/advanced/backstage/views/site/contact.php deleted file mode 100644 index e740d0f..0000000 --- a/apps/advanced/backstage/views/site/contact.php +++ /dev/null @@ -1,46 +0,0 @@ -title = 'Contact'; -$this->params['breadcrumbs'][] = $this->title; -?> -

title); ?>

- -session->hasFlash('contactFormSubmitted')): ?> -
- Thank you for contacting us. We will respond to you as soon as possible. -
- - -

- If you have business inquiries or other questions, please fill out the following form to contact us. Thank you. -

- - array('class' => 'form-horizontal'), - 'fieldConfig' => array('inputOptions' => array('class' => 'input-xlarge')), -)); ?> - field($model, 'name')->textInput(); ?> - field($model, 'email')->textInput(); ?> - field($model, 'subject')->textInput(); ?> - field($model, 'body')->textArea(array('rows' => 6)); ?> - field($model, 'verifyCode'); - echo $field->begin() - . $field->label() - . Captcha::widget() - . Html::activeTextInput($model, 'verifyCode', array('class' => 'input-medium')) - . $field->error() - . $field->end(); - ?> -
- 'btn btn-primary')); ?> -
- diff --git a/apps/advanced/common/models/LoginForm.php b/apps/advanced/common/models/LoginForm.php new file mode 100644 index 0000000..4631dbd --- /dev/null +++ b/apps/advanced/common/models/LoginForm.php @@ -0,0 +1,58 @@ +username); + if (!$user || !$user->validatePassword($this->password)) { + $this->addError('password', 'Incorrect username or password.'); + } + } + + /** + * Logs in a user using the provided username and password. + * @return boolean whether the user is logged in successfully + */ + public function login() + { + if ($this->validate()) { + $user = User::findByUsername($this->username); + Yii::$app->user->login($user, $this->rememberMe ? 3600*24*30 : 0); + return true; + } else { + return false; + } + } +} diff --git a/apps/advanced/common/models/User.php b/apps/advanced/common/models/User.php index 035f1fb..110487e 100644 --- a/apps/advanced/common/models/User.php +++ b/apps/advanced/common/models/User.php @@ -1,42 +1,58 @@ array( - 'id' => '100', - 'username' => 'admin', - 'password' => 'admin', - 'authKey' => 'test100key', - ), - '101' => array( - 'id' => '101', - 'username' => 'demo', - 'password' => 'demo', - 'authKey' => 'test101key', - ), - ); + + const STATUS_DELETED = 0; + const STATUS_ACTIVE = 10; + + const ROLE_USER = 10; + + public function behaviors() + { + return array( + 'timestamp' => array( + 'class' => 'yii\behaviors\AutoTimestamp', + 'attributes' => array( + ActiveRecord::EVENT_BEFORE_INSERT => 'create_time', + ActiveRecord::EVENT_BEFORE_INSERT => 'update_time', + ActiveRecord::EVENT_BEFORE_UPDATE => 'update_time', + ), + ), + ); + } public static function findIdentity($id) { - return isset(self::$users[$id]) ? new self(self::$users[$id]) : null; + return static::find($id); } public static function findByUsername($username) { - foreach (self::$users as $user) { - if (strcasecmp($user['username'], $username) === 0) { - return new self($user); - } - } - return null; + return static::find(array('username' => $username, 'status' => static::STATUS_ACTIVE)); } public function getId() @@ -46,16 +62,54 @@ class User extends \yii\base\Object implements \yii\web\Identity public function getAuthKey() { - return $this->authKey; + return $this->auth_key; } public function validateAuthKey($authKey) { - return $this->authKey === $authKey; + return $this->auth_key === $authKey; } public function validatePassword($password) { - return $this->password === $password; + return SecurityHelper::validatePassword($password, $this->password_hash); + } + + public function rules() + { + return array( + array('username', 'filter', 'filter' => 'trim'), + array('username', 'required'), + array('username', 'length', 'min' => 2, 'max' => 255), + + array('email', 'filter', 'filter' => 'trim'), + array('email', 'required'), + array('email', 'email'), + array('email', 'unique', 'message' => 'This email address has already been taken.'), + + array('password', 'required'), + array('password', 'length', 'min' => 6), + ); + } + + public function scenarios() + { + return array( + 'signup' => array('username', 'email', 'password'), + 'login' => array('username', 'password'), + ); + } + + public function beforeSave($insert) + { + if(parent::beforeSave($insert)) { + if($this->isNewRecord) { + if(!empty($this->password)) { + $this->password_hash = SecurityHelper::generatePasswordHash($this->password); + } + } + return true; + } + return false; } } diff --git a/apps/advanced/frontend/config/main.php b/apps/advanced/frontend/config/main.php index eac7c4d..e83ac26 100644 --- a/apps/advanced/frontend/config/main.php +++ b/apps/advanced/frontend/config/main.php @@ -19,7 +19,7 @@ return array( 'cache' => $params['components.cache'], 'user' => array( 'class' => 'yii\web\User', - 'identityClass' => 'app\models\User', + 'identityClass' => 'common\models\User', ), 'assetManager' => array( 'bundles' => require(__DIR__ . '/assets.php'), diff --git a/apps/advanced/frontend/controllers/SiteController.php b/apps/advanced/frontend/controllers/SiteController.php index d2ea5a6..cd3339c 100644 --- a/apps/advanced/frontend/controllers/SiteController.php +++ b/apps/advanced/frontend/controllers/SiteController.php @@ -4,8 +4,8 @@ namespace frontend\controllers; use Yii; use yii\web\Controller; -use app\models\LoginForm; -use app\models\ContactForm; +use common\models\LoginForm; +use frontend\models\ContactForm; class SiteController extends Controller { diff --git a/apps/advanced/frontend/models/LoginForm.php b/apps/advanced/frontend/models/LoginForm.php deleted file mode 100644 index f5e131d..0000000 --- a/apps/advanced/frontend/models/LoginForm.php +++ /dev/null @@ -1,58 +0,0 @@ -username); - if (!$user || !$user->validatePassword($this->password)) { - $this->addError('password', 'Incorrect username or password.'); - } - } - - /** - * Logs in a user using the provided username and password. - * @return boolean whether the user is logged in successfully - */ - public function login() - { - if ($this->validate()) { - $user = User::findByUsername($this->username); - Yii::$app->user->login($user, $this->rememberMe ? 3600*24*30 : 0); - return true; - } else { - return false; - } - } -} diff --git a/apps/advanced/frontend/models/User.php b/apps/advanced/frontend/models/User.php deleted file mode 100644 index 8a60503..0000000 --- a/apps/advanced/frontend/models/User.php +++ /dev/null @@ -1,61 +0,0 @@ - array( - 'id' => '100', - 'username' => 'admin', - 'password' => 'admin', - 'authKey' => 'test100key', - ), - '101' => array( - 'id' => '101', - 'username' => 'demo', - 'password' => 'demo', - 'authKey' => 'test101key', - ), - ); - - public static function findIdentity($id) - { - return isset(self::$users[$id]) ? new self(self::$users[$id]) : null; - } - - public static function findByUsername($username) - { - foreach (self::$users as $user) { - if (strcasecmp($user['username'], $username) === 0) { - return new self($user); - } - } - return null; - } - - public function getId() - { - return $this->id; - } - - public function getAuthKey() - { - return $this->authKey; - } - - public function validateAuthKey($authKey) - { - return $this->authKey === $authKey; - } - - public function validatePassword($password) - { - return $this->password === $password; - } -} From 8325f7a8909cc726e08963e4f533279dc95c478b Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 25 May 2013 03:33:43 +0400 Subject: [PATCH 039/122] Added db component. Added configuration section to readme. --- apps/advanced/README.md | 12 ++++++++++++ apps/advanced/backstage/config/main.php | 1 + apps/advanced/common/config/params.php | 7 +++++++ apps/advanced/console/config/main.php | 1 + apps/advanced/frontend/config/main.php | 1 + 5 files changed, 22 insertions(+) diff --git a/apps/advanced/README.md b/apps/advanced/README.md index f088fc8..a2bcdd4 100644 --- a/apps/advanced/README.md +++ b/apps/advanced/README.md @@ -84,3 +84,15 @@ assuming `yii-advanced` is directly under the document root of your Web server. ### Install from an Archive File This is not currently available. We will provide it when Yii 2 is formally released. + +GETTING STARTED +--------------- + +After template application and its dependencies are downloaded you need to initialize it and set some config values to +match your application requirements. + +1. Execute `install` command selecting `dev` as environment. +2. Set `id` value in `console/config/main.php`, `frontend/config/main.php`, `backstage/config/main.php`. +3. Create new database. It is assumed that MySQL InnoDB is used. If not, adjust `console/migrations/m130524_201442_init.php`. +4. In `common/config/params.php` set your database details in `components.db` values. + diff --git a/apps/advanced/backstage/config/main.php b/apps/advanced/backstage/config/main.php index d47904a..d3288bd 100644 --- a/apps/advanced/backstage/config/main.php +++ b/apps/advanced/backstage/config/main.php @@ -16,6 +16,7 @@ return array( 'modules' => array( ), 'components' => array( + 'db' => $params['components.db'], 'cache' => $params['components.cache'], 'user' => array( 'class' => 'yii\web\User', diff --git a/apps/advanced/common/config/params.php b/apps/advanced/common/config/params.php index 015be76..b9409f9 100644 --- a/apps/advanced/common/config/params.php +++ b/apps/advanced/common/config/params.php @@ -6,4 +6,11 @@ return array( 'components.cache' => array( 'class' => 'yii\caching\FileCache', ), + + 'components.db' => array( + 'class' => 'yii\db\Connection', + 'dsn' => 'mysql:host=localhost;dbname=yii2advanced', + 'username' => 'root', + 'password' => '', + ), ); \ No newline at end of file diff --git a/apps/advanced/console/config/main.php b/apps/advanced/console/config/main.php index a237444..83cb2e3 100644 --- a/apps/advanced/console/config/main.php +++ b/apps/advanced/console/config/main.php @@ -16,6 +16,7 @@ return array( 'modules' => array( ), 'components' => array( + 'db' => $params['components.db'], 'cache' => $params['components.cache'], 'log' => array( 'class' => 'yii\logging\Router', diff --git a/apps/advanced/frontend/config/main.php b/apps/advanced/frontend/config/main.php index e83ac26..607c9a9 100644 --- a/apps/advanced/frontend/config/main.php +++ b/apps/advanced/frontend/config/main.php @@ -16,6 +16,7 @@ return array( 'modules' => array( ), 'components' => array( + 'db' => $params['components.db'], 'cache' => $params['components.cache'], 'user' => array( 'class' => 'yii\web\User', From aadcb59c8ccf07ab96d93e49dac7e3fcfd316d6f Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 24 May 2013 20:55:44 -0400 Subject: [PATCH 040/122] Added ActiveField::widget(). --- framework/yii/widgets/ActiveField.php | 72 ++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 23 deletions(-) diff --git a/framework/yii/widgets/ActiveField.php b/framework/yii/widgets/ActiveField.php index 45faf9d..e3e7f2b 100644 --- a/framework/yii/widgets/ActiveField.php +++ b/framework/yii/widgets/ActiveField.php @@ -6,6 +6,7 @@ */ namespace yii\widgets; +use Yii; use yii\base\Component; use yii\db\ActiveRecord; use yii\helpers\Html; @@ -101,6 +102,11 @@ class ActiveField extends Component */ public $selectors; + + /** + * Renders the opening tag of the field container. + * @return string the rendering result. + */ public function begin() { $options = $this->getClientOptions(); @@ -124,11 +130,19 @@ class ActiveField extends Component return Html::beginTag($this->tag, $options); } + /** + * Renders the closing tag of the field container. + * @return string the rendering result. + */ public function end() { return Html::endTag($this->tag); } + /** + * Returns the JS options for the field. + * @return array the JS options + */ protected function getClientOptions() { $enableClientValidation = $this->enableClientValidation || $this->enableClientValidation === null && $this->form->enableClientValidation; @@ -237,7 +251,7 @@ class ActiveField extends Component } /** - * Generates an input tag for the given model attribute. + * Renders a field containing an input field. * @param string $type the input type (e.g. 'text', 'password') * @param array $options the tag options in terms of name-value pairs. These will be rendered as * the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. @@ -250,12 +264,12 @@ class ActiveField extends Component } /** - * Generates a text input tag for the given model attribute. + * Renders a field containing a text input. * This method will generate the "name" and "value" tag attributes automatically for the model attribute * unless they are explicitly specified in `$options`. * @param array $options the tag options in terms of name-value pairs. These will be rendered as * the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. - * @return string the generated input tag + * @return string the rendering result */ public function textInput($options = array()) { @@ -264,12 +278,12 @@ class ActiveField extends Component } /** - * Generates a hidden input tag for the given model attribute. + * Renders a field containing a hidden input. * This method will generate the "name" and "value" tag attributes automatically for the model attribute * unless they are explicitly specified in `$options`. * @param array $options the tag options in terms of name-value pairs. These will be rendered as * the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. - * @return string the generated input tag + * @return string the rendering result */ public function hiddenInput($options = array()) { @@ -278,12 +292,12 @@ class ActiveField extends Component } /** - * Generates a password input tag for the given model attribute. + * Renders a field containing a password input. * This method will generate the "name" and "value" tag attributes automatically for the model attribute * unless they are explicitly specified in `$options`. * @param array $options the tag options in terms of name-value pairs. These will be rendered as * the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. - * @return string the generated input tag + * @return string the rendering result */ public function passwordInput($options = array()) { @@ -292,12 +306,12 @@ class ActiveField extends Component } /** - * Generates a file input tag for the given model attribute. + * Renders a field containing a file input. * This method will generate the "name" and "value" tag attributes automatically for the model attribute * unless they are explicitly specified in `$options`. * @param array $options the tag options in terms of name-value pairs. These will be rendered as * the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. - * @return string the generated input tag + * @return string the rendering result */ public function fileInput($options = array()) { @@ -306,11 +320,11 @@ class ActiveField extends Component } /** - * Generates a textarea tag for the given model attribute. + * Renders a field containing a text area. * The model attribute value will be used as the content in the textarea. * @param array $options the tag options in terms of name-value pairs. These will be rendered as * the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. - * @return string the generated textarea tag + * @return string the rendering result */ public function textarea($options = array()) { @@ -319,7 +333,7 @@ class ActiveField extends Component } /** - * Generates a radio button tag for the given model attribute. + * Renders a field containing a radio button. * This method will generate the "name" tag attribute automatically unless it is explicitly specified in `$options`. * This method will generate the "checked" tag attribute according to the model attribute value. * @param array $options the tag options in terms of name-value pairs. The following options are specially handled: @@ -334,7 +348,7 @@ class ActiveField extends Component * @param boolean $enclosedByLabel whether to enclose the radio within the label. * If true, the method will still use [[template]] to layout the checkbox and the error message * except that the radio is enclosed by the label tag. - * @return string the generated radio button tag + * @return string the rendering result */ public function radio($options = array(), $enclosedByLabel = true) { @@ -358,7 +372,7 @@ class ActiveField extends Component } /** - * Generates a checkbox tag for the given model attribute. + * Renders a field containing a checkbox. * This method will generate the "name" tag attribute automatically unless it is explicitly specified in `$options`. * This method will generate the "checked" tag attribute according to the model attribute value. * @param array $options the tag options in terms of name-value pairs. The following options are specially handled: @@ -373,7 +387,7 @@ class ActiveField extends Component * @param boolean $enclosedByLabel whether to enclose the checkbox within the label. * If true, the method will still use [[template]] to layout the checkbox and the error message * except that the checkbox is enclosed by the label tag. - * @return string the generated checkbox tag + * @return string the rendering result */ public function checkbox($options = array(), $enclosedByLabel = true) { @@ -397,7 +411,7 @@ class ActiveField extends Component } /** - * Generates a drop-down list for the given model attribute. + * Renders a field containing a drop-down list. * The selection of the drop-down list is taken from the value of the model attribute. * @param array $items the option data items. The array keys are option values, and the array values * are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too). @@ -426,7 +440,7 @@ class ActiveField extends Component * The rest of the options will be rendered as the attributes of the resulting tag. The values will * be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. * - * @return string the generated drop-down list tag + * @return string the rendering result */ public function dropDownList($items, $options = array()) { @@ -435,7 +449,7 @@ class ActiveField extends Component } /** - * Generates a list box. + * Renders a field containing a list box. * The selection of the list box is taken from the value of the model attribute. * @param array $items the option data items. The array keys are option values, and the array values * are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too). @@ -467,7 +481,7 @@ class ActiveField extends Component * The rest of the options will be rendered as the attributes of the resulting tag. The values will * be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. * - * @return string the generated list box tag + * @return string the rendering result */ public function listBox($items, $options = array()) { @@ -476,7 +490,7 @@ class ActiveField extends Component } /** - * Generates a list of checkboxes. + * Renders a field containing a list of checkboxes. * A checkbox list allows multiple selection, like [[listBox()]]. * As a result, the corresponding submitted value is an array. * The selection of the checkbox list is taken from the value of the model attribute. @@ -498,7 +512,7 @@ class ActiveField extends Component * where $index is the zero-based index of the checkbox in the whole list; $label * is the label for the checkbox; and $name, $value and $checked represent the name, * value and the checked status of the checkbox input. - * @return string the generated checkbox list + * @return string the rendering result */ public function checkboxList($items, $options = array()) { @@ -510,7 +524,7 @@ class ActiveField extends Component } /** - * Generates a list of radio buttons. + * Renders a field containing a list of radio buttons. * A radio button list is like a checkbox list, except that it only allows single selection. * The selection of the radio buttons is taken from the value of the model attribute. * @param array $items the data item used to generate the radio buttons. @@ -531,7 +545,7 @@ class ActiveField extends Component * where $index is the zero-based index of the radio button in the whole list; $label * is the label for the radio button; and $name, $value and $checked represent the name, * value and the checked status of the radio button input. - * @return string the generated radio button list + * @return string the rendering result */ public function radioList($items, $options = array()) { @@ -541,4 +555,16 @@ class ActiveField extends Component . '' ); } + + /** + * Renders a field containing a widget. + * @param string $class the widget class name + * @param array $config name-value pairs that will be used to initialize the widget + * @return string the rendering result + */ + public function widget($class, $config = array()) + { + /** @var \yii\base\Widget $class */ + return $this->render($class::widget($config)); + } } From 89ea3fef037d4391c32bd63618de0fdab0bca1d5 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sat, 25 May 2013 04:19:59 +0200 Subject: [PATCH 041/122] Next iteration on console commands issue #33 - implemted getScreenSize for linux systems - tiny adjustments and better naming for console color methods - color switch in base Controller changed to magic property - colorized Help command --- framework/yii/console/Controller.php | 35 +++++- .../yii/console/controllers/HelpController.php | 60 ++++----- framework/yii/helpers/base/Console.php | 138 ++++++++++++++------- tests/unit/framework/helpers/ConsoleTest.php | 79 ++++++++++++ 4 files changed, 232 insertions(+), 80 deletions(-) create mode 100644 tests/unit/framework/helpers/ConsoleTest.php diff --git a/framework/yii/console/Controller.php b/framework/yii/console/Controller.php index fe32daa..22ec39f 100644 --- a/framework/yii/console/Controller.php +++ b/framework/yii/console/Controller.php @@ -36,12 +36,35 @@ class Controller extends \yii\base\Controller public $interactive = true; /** - * @var bool whether to enable ANSI style in output. + * @var boolean whether to enable ANSI style in output. + * Defaults to null meaning auto-detect. + */ + private $_colors; + + /** + * Whether to enable ANSI style in output. + * * Setting this will affect [[ansiFormat()]], [[stdout()]] and [[stderr()]]. * If not set it will be auto detected using [[yii\helpers\Console::streamSupportsAnsiColors()]] with STDOUT * for [[ansiFormat()]] and [[stdout()]] and STDERR for [[stderr()]]. + * @param resource $stream + * @return boolean Whether to enable ANSI style in output. + */ + public function getColors($stream = STDOUT) + { + if ($this->_colors === null) { + return Console::streamSupportsAnsiColors($stream); + } + return $this->_colors; + } + + /** + * Whether to enable ANSI style in output. */ - public $colors; + public function setColors($value) + { + $this->_colors = (bool) $value; + } /** * Runs an action with the specified action ID and parameters. @@ -138,7 +161,7 @@ class Controller extends \yii\base\Controller */ public function ansiFormat($string) { - if ($this->ansi === true || $this->ansi === null && Console::streamSupportsAnsiColors(STDOUT)) { + if ($this->getColors()) { $args = func_get_args(); array_shift($args); $string = Console::ansiFormat($string, $args); @@ -162,7 +185,7 @@ class Controller extends \yii\base\Controller */ public function stdout($string) { - if ($this->ansi === true || $this->ansi === null && Console::streamSupportsAnsiColors(STDOUT)) { + if ($this->getColors()) { $args = func_get_args(); array_shift($args); $string = Console::ansiFormat($string, $args); @@ -186,7 +209,7 @@ class Controller extends \yii\base\Controller */ public function stderr($string) { - if ($this->ansi === true || $this->ansi === null && Console::streamSupportsAnsiColors(STDERR)) { + if ($this->getColors(STDERR)) { $args = func_get_args(); array_shift($args); $string = Console::ansiFormat($string, $args); @@ -259,6 +282,6 @@ class Controller extends \yii\base\Controller */ public function globalOptions() { - return array(); + return array('colors', 'interactive'); } } diff --git a/framework/yii/console/controllers/HelpController.php b/framework/yii/console/controllers/HelpController.php index a729f78..9319163 100644 --- a/framework/yii/console/controllers/HelpController.php +++ b/framework/yii/console/controllers/HelpController.php @@ -13,6 +13,7 @@ use yii\base\InlineAction; use yii\console\Controller; use yii\console\Exception; use yii\console\Request; +use yii\helpers\Console; use yii\helpers\Inflector; /** @@ -56,7 +57,7 @@ class HelpController extends Controller $result = Yii::$app->createController($command); if ($result === false) { throw new Exception(Yii::t('yii', 'No help for unknown command "{command}".', array( - '{command}' => $command, + '{command}' => $this->ansiFormat($command, Console::FG_YELLOW), ))); } @@ -143,14 +144,15 @@ class HelpController extends Controller { $commands = $this->getCommands(); if (!empty($commands)) { - echo "The following commands are available:\n\n"; + $this->stdout("\nThe following commands are available:\n\n", Console::BOLD); foreach ($commands as $command) { - echo "* $command\n"; + echo "- " . $this->ansiFormat($command, Console::FG_YELLOW) . "\n"; } - echo "\nTo see the help of each command, enter:\n"; - echo "\n yii help \n\n"; + $this->stdout("\nTo see the help of each command, enter:\n", Console::BOLD); + echo "\n yii " . $this->ansiFormat('help', Console::FG_YELLOW) . ' ' + . $this->ansiFormat('', Console::FG_CYAN) . "\n\n"; } else { - echo "\nNo commands are found.\n"; + $this->stdout("\nNo commands are found.\n\n", Console::BOLD); } } @@ -167,19 +169,18 @@ class HelpController extends Controller } if ($comment !== '') { - echo "\nDESCRIPTION\n"; - echo "\n" . $comment . "\n\n"; + $this->stdout("\nDESCRIPTION\n", Console::BOLD); + echo "\n" . Console::renderColoredString($comment) . "\n\n"; } $actions = $this->getActions($controller); if (!empty($actions)) { - echo "\nSUB-COMMANDS\n\n"; + $this->stdout("\nSUB-COMMANDS\n\n", Console::BOLD); $prefix = $controller->getUniqueId(); foreach ($actions as $action) { + echo '- ' . $this->ansiFormat($prefix.'/'.$action, Console::FG_YELLOW); if ($action === $controller->defaultAction) { - echo "* $prefix/$action (default)"; - } else { - echo "* $prefix/$action"; + $this->stdout(' (default)', Console::FG_GREEN); } $summary = $this->getActionSummary($controller, $action); if ($summary !== '') { @@ -187,8 +188,9 @@ class HelpController extends Controller } echo "\n"; } - echo "\n\nTo see the detailed information about individual sub-commands, enter:\n"; - echo "\n yii help \n\n"; + echo "\nTo see the detailed information about individual sub-commands, enter:\n"; + echo "\n yii " . $this->ansiFormat('help', Console::FG_YELLOW) . ' ' + . $this->ansiFormat('', Console::FG_CYAN) . "\n\n"; } } @@ -253,25 +255,25 @@ class HelpController extends Controller $options = $this->getOptionHelps($controller); if ($tags['description'] !== '') { - echo "\nDESCRIPTION"; - echo "\n\n" . $tags['description'] . "\n\n"; + $this->stdout("\nDESCRIPTION\n", Console::BOLD); + echo "\n" . Console::renderColoredString($tags['description']) . "\n\n"; } - echo "\nUSAGE\n\n"; + $this->stdout("\nUSAGE\n\n", Console::BOLD); if ($action->id === $controller->defaultAction) { - echo 'yii ' . $controller->getUniqueId(); + echo 'yii ' . $this->ansiFormat($controller->getUniqueId(), Console::FG_YELLOW); } else { - echo "yii " . $action->getUniqueId(); + echo 'yii ' . $this->ansiFormat($action->getUniqueId(), Console::FG_YELLOW); } list ($required, $optional) = $this->getArgHelps($method, isset($tags['param']) ? $tags['param'] : array()); - if (!empty($required)) { - echo ' <' . implode('> <', array_keys($required)) . '>'; + foreach ($required as $arg => $description) { + $this->stdout(' <' . $arg . '>', Console::FG_CYAN); } - if (!empty($optional)) { - echo ' [' . implode('] [', array_keys($optional)) . ']'; + foreach ($optional as $arg => $description) { + $this->stdout(' [' . $arg . ']', Console::FG_CYAN); } if (!empty($options)) { - echo ' [...options...]'; + $this->stdout(' [...options...]', Console::FG_RED); } echo "\n\n"; @@ -281,7 +283,7 @@ class HelpController extends Controller $options = $this->getOptionHelps($controller); if (!empty($options)) { - echo "\nOPTIONS\n\n"; + $this->stdout("\nOPTIONS\n\n", Console::BOLD); echo implode("\n\n", $options) . "\n\n"; } } @@ -310,9 +312,9 @@ class HelpController extends Controller $comment = $tag; } if ($param->isDefaultValueAvailable()) { - $optional[$name] = $this->formatOptionHelp('* ' . $name, false, $type, $param->getDefaultValue(), $comment); + $optional[$name] = $this->formatOptionHelp('- ' . $this->ansiFormat($name, Console::FG_CYAN), false, $type, $param->getDefaultValue(), $comment); } else { - $required[$name] = $this->formatOptionHelp('* ' . $name, true, $type, null, $comment); + $required[$name] = $this->formatOptionHelp('- ' . $this->ansiFormat($name, Console::FG_CYAN), true, $type, null, $comment); } } @@ -352,9 +354,9 @@ class HelpController extends Controller $type = null; $comment = $doc; } - $options[$name] = $this->formatOptionHelp('--' . $name, false, $type, $defaultValue, $comment); + $options[$name] = $this->formatOptionHelp($this->ansiFormat('--' . $name, Console::FG_RED), false, $type, $defaultValue, $comment); } else { - $options[$name] = $this->formatOptionHelp('--' . $name, false, null, $defaultValue, ''); + $options[$name] = $this->formatOptionHelp($this->ansiFormat('--' . $name, Console::FG_RED), false, null, $defaultValue, ''); } } ksort($options); diff --git a/framework/yii/helpers/base/Console.php b/framework/yii/helpers/base/Console.php index b611919..603f0bd 100644 --- a/framework/yii/helpers/base/Console.php +++ b/framework/yii/helpers/base/Console.php @@ -45,6 +45,7 @@ class Console const BG_CYAN = 46; const BG_GREY = 47; + const RESET = 0; const NORMAL = 0; const BOLD = 1; const ITALIC = 3; @@ -240,34 +241,41 @@ class Console } /** - * Sets the ANSI format for any text that is printed afterwards. + * Returns the ANSI format code. * - * You can pass any of the FG_*, BG_* and TEXT_* constants and also [[xterm256ColorFg]] and [[xterm256ColorBg]]. + * @param array $format You can pass any of the FG_*, BG_* and TEXT_* constants and also [[xtermFgColor]] and [[xtermBgColor]]. * TODO: documentation + * @return string */ - public static function ansiFormatBegin() + public static function ansiFormatCode($format) { - echo "\033[" . implode(';', func_get_args()) . 'm'; + return "\033[" . implode(';', $format) . 'm'; } /** - * Resets any ANSI format set by previous method [[ansiFormatBegin()]] - * Any output after this is will have default text style. + * Sets the ANSI format for any text that is printed afterwards. + * + * @param array $format You can pass any of the FG_*, BG_* and TEXT_* constants and also [[xtermFgColor]] and [[xtermBgColor]]. + * TODO: documentation + * @see ansiFormatEnd() */ - public static function ansiFormatReset() + public static function beginAnsiFormat($format) { - echo "\033[0m"; + echo "\033[" . implode(';', $format) . 'm'; } /** - * Returns the ANSI format code. + * Resets any ANSI format set by previous method [[ansiFormatBegin()]] + * Any output after this is will have default text style. + * This is equal to * - * You can pass any of the FG_*, BG_* and TEXT_* constants and also [[xterm256ColorFg]] and [[xterm256ColorBg]]. - * TODO: documentation + * ```php + * echo Console::ansiFormatCode(array(Console::RESET)) + * ``` */ - public static function ansiFormatCode($format) + public static function endAnsiFormat() { - return "\033[" . implode(';', $format) . 'm'; + echo "\033[0m"; } /** @@ -275,7 +283,7 @@ class Console * * @param string $string the string to be formatted * @param array $format array containing formatting values. - * You can pass any of the FG_*, BG_* and TEXT_* constants and also [[xterm256ColorFg]] and [[xterm256ColorBg]]. + * You can pass any of the FG_*, BG_* and TEXT_* constants and also [[xtermFgColor]] and [[xtermBgColor]]. * @return string */ public static function ansiFormat($string, $format=array()) @@ -284,15 +292,32 @@ class Console return "\033[0m" . ($code !== '' ? "\033[" . $code . "m" : '') . $string . "\033[0m"; } - //const COLOR_XTERM256 = 38;// http://en.wikipedia.org/wiki/Talk:ANSI_escape_code#xterm-256colors - public static function xterm256ColorFg($i) // TODO naming! + /** + * Returns the ansi format code for xterm foreground color. + * You can pass the returnvalue of this to one of the formatting methods: + * [[ansiFormat]], [[ansiFormatCode]], [[beginAnsiFormat]] + * + * @param integer $colorCode xterm color code + * @return string + * @see http://en.wikipedia.org/wiki/Talk:ANSI_escape_code#xterm-256colors + */ + public static function xtermFgColor($colorCode) { - return '38;5;' . $i; + return '38;5;' . $colorCode; } - public static function xterm256ColorBg($i) // TODO naming! + /** + * Returns the ansi format code for xterm foreground color. + * You can pass the returnvalue of this to one of the formatting methods: + * [[ansiFormat]], [[ansiFormatCode]], [[beginAnsiFormat]] + * + * @param integer $colorCode xterm color code + * @return string + * @see http://en.wikipedia.org/wiki/Talk:ANSI_escape_code#xterm-256colors + */ + public static function xtermBgColor($colorCode) { - return '48;5;' . $i; + return '48;5;' . $colorCode; } /** @@ -303,7 +328,7 @@ class Console */ public static function stripAnsiFormat($string) { - return preg_replace('/\033\[[\d;]+m/', '', $string); // TODO currently only strips color + return preg_replace('/\033\[[\d;?]*\w/', '', $string); } // TODO refactor and review @@ -418,10 +443,11 @@ class Console } /** - * TODO syntax copied from https://github.com/pear/Console_Color2/blob/master/Console/Color2.php + * Converts a string to ansi formatted by replacing patterns like %y (for yellow) with ansi control codes * - * Converts colorcodes in the format %y (for yellow) into ansi-control - * codes. The conversion table is: ('bold' meaning 'light' on some + * // TODO documentation + * Uses almost the same syntax as https://github.com/pear/Console_Color2/blob/master/Console/Color2.php + * The conversion table is: ('bold' meaning 'light' on some * terminals). It's almost the same conversion table irssi uses. *
 	 *                  text      text            background
@@ -450,7 +476,6 @@ class Console
 	 *
 	 * @param string $string  String to convert
 	 * @param bool   $colored Should the string be colored?
-	 *
 	 * @return string
 	 */
 	public static function renderColoredString($string, $colored = true)
@@ -508,13 +533,14 @@ class Console
 	}
 
 	/**
-	* Escapes % so they don't get interpreted as color codes
-	*
-	* @param string $string String to escape
-	*
-	* @access public
-	* @return string
-	*/
+	 * Escapes % so they don't get interpreted as color codes when
+	 * the string is parsed by [[renderColoredString]]
+	 *
+	 * @param string $string String to escape
+	 *
+	 * @access public
+	 * @return string
+	 */
 	public static function escape($string)
 	{
 		return str_replace('%', '%%', $string);
@@ -548,12 +574,38 @@ class Console
 	/**
 	 * Usage: list($w, $h) = ConsoleHelper::getScreenSize();
 	 *
-	 * @return array
+	 * @return array|boolean An array of ($width, $height) or false when it was not able to determine size.
 	 */
-	public static function getScreenSize()
+	public static function getScreenSize($refresh = false)
 	{
-		// TODO implement
-		return array(150, 50);
+		static $size;
+		if ($size !== null && !$refresh) {
+			return $size;
+		}
+
+		if (static::isRunningOnWindows()) {
+			// TODO implement for windows
+			return $size = false;
+		} else {
+
+			// try stty if available
+			$stty = array();
+			if (exec('stty -a 2>&1', $stty) && preg_match('/rows\s+(\d+);\s*columns\s+(\d+);/mi', implode(' ', $stty), $matches)) {
+				return $size = array($matches[2], $matches[1]);
+			}
+
+			// fallback to tput, which may not be updated on terminal resize
+			if (($width = (int) exec('tput cols 2>&1')) > 0 && ($height = (int) exec('tput lines 2>&1')) > 0) {
+				return $size = array($width, $height);
+			}
+
+			// fallback to ENV variables, which may not be updated on terminal resize
+			if (($width = (int) getenv('COLUMNS')) > 0 && ($height = (int) getenv('LINES')) > 0) {
+				return $size = array($width, $height);
+			}
+		}
+
+		return $size = false;
 	}
 
 	/**
@@ -607,27 +659,23 @@ class Console
 	/**
 	 * Prints text to STDOUT appended with a carriage return (PHP_EOL).
 	 *
-	 * @param string $text
-	 * @param bool $raw
-	 *
+	 * @param string $string
 	 * @return mixed Number of bytes printed or bool false on error
 	 */
-	public static function output($text = null)
+	public static function output($string = null)
 	{
-		return static::stdout($text . PHP_EOL);
+		return static::stdout($string . PHP_EOL);
 	}
 
 	/**
 	 * Prints text to STDERR appended with a carriage return (PHP_EOL).
 	 *
-	 * @param string $text
-	 * @param bool   $raw
-	 *
+	 * @param string $string
 	 * @return mixed Number of bytes printed or false on error
 	 */
-	public static function error($text = null)
+	public static function error($string = null)
 	{
-		return static::stderr($text . PHP_EOL);
+		return static::stderr($string . PHP_EOL);
 	}
 
 	/**
diff --git a/tests/unit/framework/helpers/ConsoleTest.php b/tests/unit/framework/helpers/ConsoleTest.php
new file mode 100644
index 0000000..3bfa56d
--- /dev/null
+++ b/tests/unit/framework/helpers/ConsoleTest.php
@@ -0,0 +1,79 @@
+assertEquals(str_repeat('a', 25), $ouput);
+	}
+
+/*	public function testScreenSize()
+	{
+		for($i = 1; $i < 20; $i++) {
+			echo implode(', ', Console::getScreenSize(true)) . "\n";
+			ob_flush();
+			sleep(1);
+		}
+	}*/
+
+}

From 4fe732e9ae9fd9bd7e0668dcab5c9fcf13cc2a17 Mon Sep 17 00:00:00 2001
From: Carsten Brandt 
Date: Sat, 25 May 2013 04:39:25 +0200
Subject: [PATCH 042/122] there is no app command anymore

issue #131
---
 framework/yii/console/Application.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/framework/yii/console/Application.php b/framework/yii/console/Application.php
index 31580e8..58c2de4 100644
--- a/framework/yii/console/Application.php
+++ b/framework/yii/console/Application.php
@@ -127,7 +127,6 @@ class Application extends \yii\base\Application
 			'message' => 'yii\console\controllers\MessageController',
 			'help' => 'yii\console\controllers\HelpController',
 			'migrate' => 'yii\console\controllers\MigrateController',
-			'app' => 'yii\console\controllers\AppController',
 			'cache' => 'yii\console\controllers\CacheController',
 			'asset' => 'yii\console\controllers\AssetController',
 		);

From 5d254487d7c9bd241e414bf741a7954545f6cedc Mon Sep 17 00:00:00 2001
From: Alexander Kochetov 
Date: Sat, 25 May 2013 12:04:22 +0400
Subject: [PATCH 043/122] jQuery UI widget fixes 2

---
 framework/yii/jui/Menu.php   | 1 -
 framework/yii/jui/Widget.php | 1 -
 2 files changed, 2 deletions(-)

diff --git a/framework/yii/jui/Menu.php b/framework/yii/jui/Menu.php
index 0a84acf..d4e390c 100644
--- a/framework/yii/jui/Menu.php
+++ b/framework/yii/jui/Menu.php
@@ -8,7 +8,6 @@
 namespace yii\jui;
 
 use Yii;
-use yii\base\View;
 use yii\helpers\Json;
 
 
diff --git a/framework/yii/jui/Widget.php b/framework/yii/jui/Widget.php
index f6efd91..eea76d3 100644
--- a/framework/yii/jui/Widget.php
+++ b/framework/yii/jui/Widget.php
@@ -8,7 +8,6 @@
 namespace yii\jui;
 
 use Yii;
-use yii\base\View;
 use yii\helpers\Json;
 
 

From 586752369c1412d40c0d869bf2ae26c7529b6699 Mon Sep 17 00:00:00 2001
From: Qiang Xue 
Date: Sat, 25 May 2013 07:57:37 -0400
Subject: [PATCH 044/122] Fixes issue #403

---
 framework/yii/web/AssetManager.php | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/framework/yii/web/AssetManager.php b/framework/yii/web/AssetManager.php
index 95dcbd2..dfec576 100644
--- a/framework/yii/web/AssetManager.php
+++ b/framework/yii/web/AssetManager.php
@@ -282,6 +282,9 @@ class AssetManager extends Component
 	 */
 	public function getPublishedPath($path)
 	{
+		if (isset($this->_published[$path])) {
+			return $this->_published[$path][0];
+		}
 		if (($path = realpath($path)) !== false) {
 			$base = $this->basePath . DIRECTORY_SEPARATOR;
 			if (is_file($path)) {
@@ -304,7 +307,7 @@ class AssetManager extends Component
 	public function getPublishedUrl($path)
 	{
 		if (isset($this->_published[$path])) {
-			return $this->_published[$path];
+			return $this->_published[$path][1];
 		}
 		if (($path = realpath($path)) !== false) {
 			if (is_file($path)) {

From 113751ea458320253650228cc56f0d242e7b69ae Mon Sep 17 00:00:00 2001
From: Alexander Makarov 
Date: Sat, 25 May 2013 17:40:31 +0400
Subject: [PATCH 045/122] Fixed detection of ANSI color support on Windows

---
 framework/yii/helpers/base/Console.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/framework/yii/helpers/base/Console.php b/framework/yii/helpers/base/Console.php
index 603f0bd..d9068e4 100644
--- a/framework/yii/helpers/base/Console.php
+++ b/framework/yii/helpers/base/Console.php
@@ -547,9 +547,9 @@ class Console
 	}
 
 	/**
-	 * Returns true if the stream supports colorization. ANSI colors is disabled if not supported by the stream.
+	 * Returns true if the stream supports colorization. ANSI colors are disabled if not supported by the stream.
 	 *
-	 * - windows without asicon
+	 * - windows without ansicon
 	 * - not tty consoles
 	 *
 	 * @param mixed $stream
@@ -558,7 +558,7 @@ class Console
 	public static function streamSupportsAnsiColors($stream)
 	{
 		return DIRECTORY_SEPARATOR == '\\'
-			? null !== getenv('ANSICON')
+			? getenv('ANSICON') !== false || getenv('ConEmuANSI') === 'ON'
 			: function_exists('posix_isatty') && @posix_isatty($stream);
 	}
 

From 548643df0e032e2263a71101a6525d8056d4acac Mon Sep 17 00:00:00 2001
From: Alexander Kochetov 
Date: Sat, 25 May 2013 18:29:44 +0400
Subject: [PATCH 046/122] InputWidget base class

---
 framework/yii/jui/InputWidget.php | 59 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 framework/yii/jui/InputWidget.php

diff --git a/framework/yii/jui/InputWidget.php b/framework/yii/jui/InputWidget.php
new file mode 100644
index 0000000..e100d6c
--- /dev/null
+++ b/framework/yii/jui/InputWidget.php
@@ -0,0 +1,59 @@
+
+ * @since 2.0
+ */
+class InputWidget extends Widget
+{
+	/**
+	 * @var Model the data model that this widget is associated with.
+	 */
+	public $model;
+	/**
+	 * @var string the model attribute that this widget is associated with.
+	 */
+	public $attribute;
+	/**
+	 * @var string the input name. This must be set if [[model]] and [[attribute]] are not set.
+	 */
+	public $name;
+	/**
+	 * @var string the input value.
+	 */
+	public $value;
+
+
+	/**
+	 * Initializes the widget.
+	 * If you override this method, make sure you call the parent implementation first.
+	 */
+	public function init()
+	{
+		if (!$this->hasModel() && $this->name === null) {
+			throw new InvalidConfigException("Either 'name' or 'model' and 'attribute' properties must be specified.");
+		}
+		parent::init();
+	}
+
+	/**
+	 * @return boolean whether this widget is associated with a data model.
+	 */
+	protected function hasModel()
+	{
+		return $this->model instanceof Model && $this->attribute !== null;
+	}
+}

From 1b417664608f684892b9986e8df2370c9826bff6 Mon Sep 17 00:00:00 2001
From: Alexander Kochetov 
Date: Sat, 25 May 2013 18:38:52 +0400
Subject: [PATCH 047/122] DatePicker rework

---
 framework/yii/jui/DatePicker.php | 55 +++++++++++++++++++---------------------
 1 file changed, 26 insertions(+), 29 deletions(-)

diff --git a/framework/yii/jui/DatePicker.php b/framework/yii/jui/DatePicker.php
index 4f68d56..6e48418 100644
--- a/framework/yii/jui/DatePicker.php
+++ b/framework/yii/jui/DatePicker.php
@@ -8,8 +8,6 @@
 namespace yii\jui;
 
 use Yii;
-use yii\base\InvalidConfigException;
-use yii\base\Model;
 use yii\helpers\Html;
 
 /**
@@ -44,28 +42,16 @@ use yii\helpers\Html;
  * @author Alexander Kochetov 
  * @since 2.0
  */
-class DatePicker extends Widget
+class DatePicker extends InputWidget
 {
 	/**
 	 * @var string the jQuery UI datepicker widget language bundle.
 	 */
 	public $language = false;
 	/**
-	 * @var \yii\base\Model the data model that this widget is associated with.
+	 * @var boolean If true, shows the widget as an inline calendar and the input as a hidden field.
 	 */
-	public $model;
-	/**
-	 * @var string the model attribute that this widget is associated with.
-	 */
-	public $attribute;
-	/**
-	 * @var string the input name. This must be set if [[model]] and [[attribute]] are not set.
-	 */
-	public $name;
-	/**
-	 * @var string the input value.
-	 */
-	public $value;
+	public $flat = false;
 
 
 	/**
@@ -73,7 +59,7 @@ class DatePicker extends Widget
 	 */
 	public function run()
 	{
-		echo $this->renderField();
+		echo $this->renderWidget() . "\n";
 		$this->registerWidget('datepicker');
 		if ($this->language !== false) {
 			$this->getView()->registerAssetBundle($this->language);
@@ -81,21 +67,32 @@ class DatePicker extends Widget
 	}
 
 	/**
-	 * Renders the DatePicker field. If [[model]] has been specified then it will render an active field.
-	 * If [[model]] is null or not from an [[Model]] instance, then the field will be rendered according to
-	 * the [[name]] attribute.
+	 * Renders the DatePicker widget.
 	 * @return string the rendering result.
-	 * @throws InvalidConfigException when none of the required attributes are set to render the textInput.
-	 * That is, if [[model]] and [[attribute]] are not set, then [[name]] is required.
 	 */
-	public function renderField()
+	protected function renderWidget()
 	{
-		if ($this->model instanceof Model && $this->attribute !== null) {
-			return Html::activeTextInput($this->model, $this->attribute, $this->options);
-		} elseif ($this->name !== null) {
-			return Html::textInput($this->name, $this->value, $this->options);
+		$contents = array();
+
+		if ($this->flat === false) {
+			if ($this->hasModel()) {
+				$contents[] = Html::activeTextInput($this->model, $this->attribute, $this->options);
+			} else {
+				$contents[] = Html::textInput($this->name, $this->value, $this->options);
+			}
 		} else {
-			throw new InvalidConfigException("Either 'name' or 'model' and 'attribute' properties must be specified.");
+			if ($this->hasModel()) {
+				$contents[] = Html::activeHiddenInput($this->model, $this->attribute, $this->options);
+				$this->clientOptions['defaultDate'] = $this->model->{$this->attribute};
+			} else {
+				$contents[] = Html::hiddenInput($this->name, $this->value, $this->options);
+				$this->clientOptions['defaultDate'] = $this->value;
+			}
+			$this->clientOptions['altField'] = '#' . $this->options['id'];
+			$this->options['id'] .= '-container';
+			$contents[] = Html::tag('div', null, $this->options);
 		}
+
+		return implode("\n", $contents);
 	}
 }

From fa0022e7e11089d6490c1d1f3d9be550f45affcf Mon Sep 17 00:00:00 2001
From: resurtm 
Date: Sat, 25 May 2013 20:54:20 +0600
Subject: [PATCH 048/122] New error/exception page WIP.

---
 apps/bootstrap/controllers/SiteController.php      |   1 +
 apps/bootstrap/www/tmp/main.css                    |  99 ++++------
 apps/bootstrap/www/tmp/main.js                     |  81 ++++----
 framework/yii/base/ErrorHandler.php                | 119 +++++++++++-
 framework/yii/views/errorHandler.php               | 209 ---------------------
 framework/yii/views/errorHandler/callStackItem.php |  34 ++++
 framework/yii/views/errorHandler/main.php          | 101 ++++++++++
 7 files changed, 322 insertions(+), 322 deletions(-)
 delete mode 100644 framework/yii/views/errorHandler.php
 create mode 100644 framework/yii/views/errorHandler/callStackItem.php
 create mode 100644 framework/yii/views/errorHandler/main.php

diff --git a/apps/bootstrap/controllers/SiteController.php b/apps/bootstrap/controllers/SiteController.php
index 4c00cea..4652430 100644
--- a/apps/bootstrap/controllers/SiteController.php
+++ b/apps/bootstrap/controllers/SiteController.php
@@ -21,6 +21,7 @@ class SiteController extends Controller
 	public function actionIndex()
 	{
 		throw new \yii\base\HttpException(500, 'Test exception');
+		$x = 1;
 		echo $this->render('index');
 	}
 
diff --git a/apps/bootstrap/www/tmp/main.css b/apps/bootstrap/www/tmp/main.css
index 334bc82..69ca6f7 100644
--- a/apps/bootstrap/www/tmp/main.css
+++ b/apps/bootstrap/www/tmp/main.css
@@ -50,9 +50,6 @@ h1,h2,p,img,ul li{
 	font-family: Arial,sans-serif;
 	color: #505050;
 }
-body,html{
-	/*overflow-x: hidden;*/
-}
 
 /* header */
 .header{
@@ -85,70 +82,70 @@ body,html{
 	text-shadow: 0 1px 0 #cacaca;
 }
 
-/* traceback */
-.traceback{
+/* call stack */
+.call-stack{
 	margin-top: 30px;
 	margin-bottom: 40px;
 }
-.traceback ul li{
+.call-stack ul li{
 	margin: 1px 0;
 }
-.traceback ul li .li-wrap{
+.call-stack ul li .element-wrap{
 	cursor: pointer;
 	padding: 15px 0;
 }
-.traceback ul li.application .li-wrap{
+.call-stack ul li.application .element-wrap{
 	background-color: #fafafa;
 }
-.traceback ul li .li-wrap:hover{
+.call-stack ul li .element-wrap:hover{
 	background-color: #edf9ff;
 }
-.traceback ul li .li{
+.call-stack ul li .element{
 	min-width: 860px; /* 960px - 50px * 2 */
 	max-width: 1100px; /* 1200px - 50px * 2 */
 	margin: 0 auto;
 	padding: 0 50px;
 	position: relative;
 }
-.traceback ul li a{
+.call-stack ul li a{
 	color: #505050;
 }
-.traceback ul li a:hover{
+.call-stack ul li a:hover{
 	color: #000000;
 	text-shadow: 0 1px 0 #cacaca;
 }
-.traceback ul li .number{
+.call-stack ul li .number{
 	width: 45px;
 	display: inline-block;
 }
-.traceback ul li .text{
+.call-stack ul li .text{
 	color: #bbbbbb;
 }
-.traceback ul li.application .text{
+.call-stack ul li.application .text{
 	color: #505050;
 }
-.traceback ul li .at{
+.call-stack ul li .at{
 	position: absolute;
 	right: 110px; /* 50px + 60px */
 	color: #bbbbbb;
 }
-.traceback ul li.application .at{
+.call-stack ul li.application .at{
 	color: #505050;
 }
-.traceback ul li .line{
+.call-stack ul li .line{
 	position: absolute;
 	right: 50px;
 	width: 60px;
 	text-align: right;
 }
-.traceback ul li .code-wrap{
+.call-stack ul li .code-wrap{
 	display: none;
 	position: relative;
 }
-.traceback ul li.application .code-wrap{
+.call-stack ul li.application .code-wrap{
 	display: block;
 }
-.traceback ul li .error-line{
+.call-stack ul li .error-line,.call-stack ul li .hover-line{
 	background-color: #ffebeb;
 	position: absolute;
 	width: 100%;
@@ -156,29 +153,36 @@ body,html{
 	z-index: 100;
 	margin-top: 15px;
 }
-.traceback ul li .code{
+.call-stack ul li .hover-line{
+	background: none;
+}
+.call-stack ul li .hover-line.hover,.call-stack ul li .hover-line:hover{
+	background: #edf9ff !important;
+}
+.call-stack ul li .code{
 	min-width: 860px; /* 960px - 50px * 2 */
 	max-width: 1100px; /* 1200px - 50px * 2 */
 	margin: 0 auto;
 	padding: 15px 50px;
 	position: relative;
 }
-.traceback ul li .code .lines{
+.call-stack ul li .code .lines{
 	position: absolute;
 	z-index: 200;
 	left: 50px;
 	line-height: 18px;
 	font-size: 14px;
-	font-family: Consolas, Courier New, monospaced;
+	font-family: Consolas, Courier New, monospace;
 	color: #bbbbbb;
 }
-.traceback ul li .code pre{
+.call-stack ul li .code pre{
 	position: relative;
 	z-index: 200;
 	left: 50px;
 	line-height: 18px;
 	font-size: 14px;
-	font-family: Consolas, Courier New, monospaced;
+	font-family: Consolas, Courier New, monospace;
+	display: inline;
 }
 
 /* request */
@@ -190,15 +194,15 @@ body,html{
 	margin-bottom: 1px;
 }
 .request pre{
-	font-family: Consolas, Courier New, monospaced;
+	font-family: Consolas, Courier New, monospace;
 }
 
 /* footer */
 .footer{
 	position: relative;
 	height: 222px;
-	min-width: 860px; /* padding compensation: 960px - 50px * 2 */
-	max-width: 1100px; /* padding compensation: 1200px - 50px * 2 */
+	min-width: 860px; /* 960px - 50px * 2 */
+	max-width: 1100px; /* 1200px - 50px * 2 */
 	padding: 0 50px;
 	margin: 1px auto 0 auto;
 }
@@ -223,30 +227,7 @@ body,html{
 	right: -50px;
 }
 
-/* code */
-#code-wrap{
-	overflow: hidden;
-	position: relative;
-}
-#code-highlighter{
-	background-color: #ffffff;
-	position: fixed;
-	width: 100%;
-	z-index: 100;
-}
-#code-inner-wrap{
-	min-width: 860px; /* padding compensation: 960px - 50px * 2 */
-	max-width: 1100px; /* padding compensation: 1200px - 50px * 2 */
-	margin: 0 auto;
-}
-pre{
-	display: inline;
-	color: #505050;
-	font-size: 14px;
-	line-height: 18px;
-	z-index: 200;
-	position: relative;
-}
+/* highlight.js */
 pre .subst,pre .title{
 	font-weight: normal;
 	color: #505050;
@@ -255,16 +236,16 @@ pre .comment,pre .template_comment,pre .javadoc,pre .diff .header{
 	color: #808080;
 	font-style: italic;
 }
-pre .annotation,pre .decorator,pre .preprocessor,pre .doctype,pre .pi,pre .chunk,pre .shebang,
-pre .apache .cbracket,pre .prompt,pre .http .title{
+pre .annotation,pre .decorator,pre .preprocessor,pre .doctype,pre .pi,pre .chunk,pre .shebang,pre .apache .cbracket,
+pre .prompt,pre .http .title{
 	color: #808000;
 }
 pre .tag,pre .pi{
 	background: #efefef;
 }
-pre .tag .title,pre .id,pre .attr_selector,pre .pseudo,pre .literal,pre .keyword,pre .hexcolor,
-pre .css .function,pre .ini .title,pre .css .class,pre .list .title,pre .clojure .title,pre .nginx .title,
-pre .tex .command,pre .request,pre .status{
+pre .tag .title,pre .id,pre .attr_selector,pre .pseudo,pre .literal,pre .keyword,pre .hexcolor,pre .css .function,
+pre .ini .title,pre .css .class,pre .list .title,pre .clojure .title,pre .nginx .title,pre .tex .command,
+pre .request,pre .status{
 	color: #000080;
 }
 pre .attribute,pre .rules .keyword,pre .number,pre .date,pre .regexp,pre .tex .special{
@@ -273,7 +254,7 @@ pre .attribute,pre .rules .keyword,pre .number,pre .date,pre .regexp,pre .tex .s
 pre .number,pre .regexp{
 	font-weight: normal;
 }
-pre .string,pre .value,pre .filter .argument,pre .css .function .params,pre .apache .tag {
+pre .string,pre .value,pre .filter .argument,pre .css .function .params,pre .apache .tag{
 	color: #00aa00;
 }
 pre .symbol,pre .ruby .symbol .string,pre .char,pre .tex .formula{
diff --git a/apps/bootstrap/www/tmp/main.js b/apps/bootstrap/www/tmp/main.js
index 2bd4980..020ce41 100644
--- a/apps/bootstrap/www/tmp/main.js
+++ b/apps/bootstrap/www/tmp/main.js
@@ -1,58 +1,43 @@
-/*;
-
-var lines = null;
-var line = document.getElementById('code-highlighter')
-
-var updateLines = function() {
-	lines = document.getElementById('code').getClientRects();
-};
-updateLines();
-window.onresize = updateLines;
-window.onscroll = updateLines;
-
-document.onmousemove = function(e) {
-	var event = e || window.event;
-	var x = event.clientX, y = event.clientY;
-	for (var i = 0, max = lines.length; i < max; i++) {
-		if (y > lines[i].top && y < lines[i].bottom) {
-			line.style.height = parseInt(lines[i].bottom - lines[i].top + 1) + 'px';
-			line.style.top = parseInt(lines[i].top) + 'px';
-			break;
-		}
-	}
-}
-*/
-
 window.onload = function() {
-	var i, j, max, max2,
+	var i, imax,
 		codeBlocks = Sizzle('pre'),
-		traceBackItems = Sizzle('.trace-back-item');
+		callStackItems = Sizzle('.call-stack-item');
 
-	// highlight code
-	for (i = 0, max = codeBlocks.length; i < max; i++) {
+	// highlight code blocks
+	for (i = 0, imax = codeBlocks.length; i < imax; ++i) {
 		hljs.highlightBlock(codeBlocks[i], '    ');
 	}
 
-	// error lines
-//	var updateErrorLines = function() {
-//		for (i = 0, max = codeBlocks.length; i < max; i++) {
-//			var lines = codeBlocks[i].getClientRects(),
-//				errorLine = codeBlocks[i].getAttribute('data-error-line'),
-//				top = 0;
-//			if (errorLine > lines.length - 1) {
-//				errorLine = lines.length - 1;
-//			}
-//			for (j = 0; j < errorLine; j++) {
-//				top += lines[j].height;
-//			}
-//			Sizzle('.error-line', codeBlocks[i].parentNode.parentNode)[0].style.marginTop = top + 'px';
-//		}
-//	};
-//	updateErrorLines();
+	//
+	document.onmousemove = function(e) {
+		var lines, i, imax, j, jmax, k, kmax,
+			event = e || window.event,
+			y = event.clientY,
+			lineFound = false;
+		for (i = 0, imax = codeBlocks.length; i < imax; ++i) {
+			lines = codeBlocks[i].getClientRects();
+			for (j = 0, jmax = lines.length; j < jmax; ++j) {
+				if (y > lines[j].top && y < lines[j].bottom) {
+					lineFound = true;
+					break;
+				}
+			}
+			if (lineFound) {
+				break;
+			}
+		}
+		var hoverLines = Sizzle('.hover-line');
+		for (k = 0, kmax = hoverLines.length; k < kmax; ++k) {
+			hoverLines[k].className = 'hover-line';
+		}
+		if (lineFound) {
+			Sizzle('.call-stack-item:eq(' + i + ') .hover-line:eq(' + j + ')')[0].className = 'hover-line hover';
+		}
+	}
 
-	// toggle code block visibility of each trace back item
-	for (i = 0, max = traceBackItems.length; i < max; i++) {
-		Sizzle('.li-wrap', traceBackItems[i])[0].addEventListener('click', function() {
+	// toggle code block visibility
+	for (i = 0, imax = callStackItems.length; i < imax; i++) {
+		Sizzle('.element-wrap', callStackItems[i])[0].addEventListener('click', function() {
 			var code = Sizzle('.code-wrap', this.parentNode)[0];
 			code.style.display = window.getComputedStyle(code).display == 'block' ? 'none' : 'block';
 		});
diff --git a/framework/yii/base/ErrorHandler.php b/framework/yii/base/ErrorHandler.php
index 09e4a59..4c6e8eb 100644
--- a/framework/yii/base/ErrorHandler.php
+++ b/framework/yii/base/ErrorHandler.php
@@ -16,6 +16,7 @@ use Yii;
  * nature of the errors and the mode the application runs at.
  *
  * @author Qiang Xue 
+ * @author Timur Ruziev 
  * @since 2.0
  */
 class ErrorHandler extends Component
@@ -42,7 +43,11 @@ class ErrorHandler extends Component
 	/**
 	 * @var string the path of the view file for rendering exceptions and errors.
 	 */
-	public $view = '@yii/views/errorHandler.php';
+	public $mainView = '@yii/views/errorHandler/main.php';
+	/**
+	 * @var string the path of the view file for rendering exceptions and errors call stack element.
+	 */
+	public $callStackItemView = '@yii/views/errorHandler/callStackItem.php';
 	/**
 	 * @var \Exception the exception that is being handled currently.
 	 */
@@ -56,11 +61,9 @@ class ErrorHandler extends Component
 	public function handle($exception)
 	{
 		$this->exception = $exception;
-
 		if ($this->discardExistingOutput) {
 			$this->clearOutput();
 		}
-
 		$this->renderException($exception);
 	}
 
@@ -90,9 +93,8 @@ class ErrorHandler extends Component
 				if (YII_DEBUG) {
 					ini_set('display_errors', 1);
 				}
-
 				$view = new View();
-				echo $view->renderFile($this->view, array('e' => $exception), $this);
+				echo $view->renderFile($this->mainView, array('e' => $exception), $this);
 			}
 		}
 	}
@@ -100,7 +102,7 @@ class ErrorHandler extends Component
 	/**
 	 * Converts special characters to HTML entities.
 	 * @param string $text to encode.
-	 * @return string encoded text.
+	 * @return string encoded original text.
 	 */
 	public function htmlEncode($text)
 	{
@@ -117,4 +119,109 @@ class ErrorHandler extends Component
 			@ob_end_clean();
 		}
 	}
+
+	/**
+	 * Adds informational links to the given PHP type/class.
+	 * @param string $code type/class name to be linkified.
+	 * @return string linkified with HTML type/class name.
+	 */
+	public function addTypeLinks($code)
+	{
+		$html = '';
+		if (strpos($code, '\\') !== false) {
+			// namespaced class
+			foreach (explode('\\', $code) as $part) {
+				$html .= '' . $this->htmlEncode($part) . '\\';
+			}
+			$html = rtrim($html, '\\');
+		}
+		return $html;
+	}
+
+	/**
+	 * Creates HTML containing link to the page with the information on given HTTP status code.
+	 * @param integer $statusCode to be used to generate information link.
+	 * @return string generated HTML with HTTP status code information.
+	 */
+	public function createHttpStatusLink($statusCode)
+	{
+		return '' . (int)$statusCode . '';
+	}
+
+	/**
+	 * Renders a single call stack element.
+	 * @param string $file name where call has happened.
+	 * @param integer $line number on which call has happened.
+	 * @param integer $index number of the call stack element.
+	 * @return string HTML content of the rendered call stack element.
+	 */
+	public function renderCallStackItem($file, $line, $index)
+	{
+		$line--; // adjust line number from one-based to zero-based
+		$lines = @file($file);
+		if ($line < 0 || $lines === false || ($lineCount = count($lines)) < $line + 1) {
+			return '';
+		}
+
+		$half = (int)(($index == 0 ? $this->maxSourceLines : $this->maxTraceSourceLines) / 2);
+		$begin = $line - $half > 0 ? $line - $half : 0;
+		$end = $line + $half < $lineCount ? $line + $half : $lineCount - 1;
+
+		$view = new View();
+		return $view->renderFile($this->callStackItemView, array(
+			'file' => $file,
+			'line' => $line,
+			'index' => $index,
+			'lines' => $lines,
+			'begin' => $begin,
+			'end' => $end,
+		), $this);
+	}
+
+	/**
+	 * Determines whether given name of the file belongs to the framework.
+	 * @param string $file name to be checked.
+	 * @return boolean whether given name of the file belongs to the framework.
+	 */
+	public function isCoreFile($file)
+	{
+		return $file === 'unknown' || strpos(realpath($file), YII_PATH . DIRECTORY_SEPARATOR) === 0;
+	}
+
+	/**
+	 * Creates string containing HTML link which refers to the home page of determined web-server software
+	 * and its full name.
+	 * @return string server software information hyperlink.
+	 */
+	public function createServerInformationLink()
+	{
+		static $serverUrls = array(
+			'http://httpd.apache.org/' => array('apache'),
+			'http://nginx.org/' => array('nginx'),
+			'http://lighttpd.net/' => array('lighttpd'),
+			'http://gwan.com/' => array('g-wan', 'gwan'),
+			'http://iis.net/' => array('iis', 'services'),
+			'http://php.net/manual/en/features.commandline.webserver.php' => array('development'),
+		);
+		if (isset($_SERVER['SERVER_SOFTWARE'])) {
+			foreach ($serverUrls as $url => $keywords) {
+				foreach ($keywords as $keyword) {
+					if (stripos($_SERVER['SERVER_SOFTWARE'], $keyword) !== false ) {
+						return '' . $this->htmlEncode($_SERVER['SERVER_SOFTWARE']) . '';
+					}
+				}
+			}
+		}
+		return '';
+	}
+
+	/**
+	 * Creates string containing HTML link which refers to the page with the current version
+	 * of the framework and version number text.
+	 * @return string framework version information hyperlink.
+	 */
+	public function createFrameworkVersionLink()
+	{
+		return '' . $this->htmlEncode(Yii::getVersion()) . '';
+	}
 }
diff --git a/framework/yii/views/errorHandler.php b/framework/yii/views/errorHandler.php
deleted file mode 100644
index 7589a96..0000000
--- a/framework/yii/views/errorHandler.php
+++ /dev/null
@@ -1,209 +0,0 @@
-context;
-?>
-
-
-
-
-	
-
-	
-
-	
-
-	
-	
-	
-
-
-
-	
-
-
-
- - 10
11
12
13
14
15
16
17
18
19
20
21
22
- 23
24
25
26
27
28
29
30
31
32
33
34 -
-
	{
-		return array(
-			'captcha' => array(
-				'class' => 'yii\web\CaptchaAction',
-			),
-		);
-	}
-
-	public function actionIndex()
-	{
-//		throw new \yii\base\HttpException(500);
-		$x = null;
-		$x->y = 1;
-
-		echo $this->render('index');
-	}
-
-	public function actionLogin()
-	{
-		$model = new LoginForm();
-		if ($this->populate($_POST, $model) && $model->login()) {
-			Yii::$app->response->redirect(array('site/index'));
-		} else {
-			echo $this->render('login', array(
-				'model' => $model,
-
-
- - - -
- Attention -

Exceptionyii\base\HttpException – 404

-

Requested user cannot be found!

-
- -
-
    -
  • -
    -
    - 1. - in C:\_work\jetbrains\yii2\apps\bootstrap\protected\controllers\SiteController.php - at line - 22 -
    -
    - -
  • -
  • -
    -
    - 2. - at C:\_work\jetbrains\yii2\yii\base\InlineAction.php – - call_user_func_array() - at line - 47 -
    -
    - -
  • -
  • -
    -
    - 3. - at C:\_work\jetbrains\yii2\yii\base\Controller.php – - yii\base\InlineActionrunWithParams() - at line - 117 -
    -
    - -
  • -
  • -
    -
    - 4. - at C:\_work\jetbrains\yii2\yii\web\Application.php – - yii\base\ModulerunAction() - at line - 35 -
    -
    - -
  • -
  • -
    -
    - 5. - at C:\_work\jetbrains\yii2\yii\web\Application.php – - yii\base\ModulerunAction() - at line - 35 -
    -
    - -
  • -
  • -
    -
    - 6. - at C:\_work\jetbrains\yii2\yii\base\Application.php – - yii\web\ApplicationprocessRequest() - at line - 146 -
    -
    - -
  • -
  • -
    -
    - 7. - at C:\_work\jetbrains\yii2\apps\bootstrap\index.php – - yii\base\Applicationrun() - at line - 14 -
    -
    - -
  • -
-
- - -
-
-
-
$_GET = [
-	'show-post' => 100,
-	'refresh-page' => 'yes',
-	'ascending-sort' => 1,
-];
-
-$_POST = [
-	'blog-post-form' => [
-		'title' => 'hello',
-		'author_id' => '12',
-	],
-];
-
-$_SERVER = [
-	'DOCUMENT_ROOT' => '/home/resurtm/work/data',
-	'REMOTE_ADDR' => '::1',
-	'REMOTE_PORT' => '52694',
-	'SERVER_SOFTWARE' => 'PHP 5.4.3 Development Server',
-	'SERVER_PROTOCOL' => 'HTTP/1.1',
-	'SERVER_NAME' => 'localhost',
-	'SERVER_PORT' => '8000',
-	'REQUEST_URI' => '/index.php?post-form[title]=hello&post-form[author_id]=12',
-	'REQUEST_METHOD' => 'GET',
-	'SCRIPT_NAME' => '/index.php',
-	'SCRIPT_FILENAME' => '/home/resurtm/work/data/index.php',
-	'PHP_SELF' => '/index.php',
-	'QUERY_STRING' => 'post-form[title]=hello&post-form[author_id]=12',
-	'HTTP_HOST' => 'localhost:8000',
-	'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0',
-	'HTTP_ACCEPT_LANGUAGE' => 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
-	'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
-	'HTTP_CONNECTION' => 'keep-alive',
-	'REQUEST_TIME_FLOAT' => 1369146454.0856,
-	'REQUEST_TIME' => 1369146454,
-];
-
- - */ ?> - - - - - diff --git a/framework/yii/views/errorHandler/callStackItem.php b/framework/yii/views/errorHandler/callStackItem.php new file mode 100644 index 0000000..e4ac1bf --- /dev/null +++ b/framework/yii/views/errorHandler/callStackItem.php @@ -0,0 +1,34 @@ +context; +?> + +
  • +
    +
    + . + in htmlEncode($file); ?> + at line + +
    +
    +
    +
    + +
    + +
    + '; ?> +
    htmlEncode($lines[$i]); ?>
    +
    +
    +
  • diff --git a/framework/yii/views/errorHandler/main.php b/framework/yii/views/errorHandler/main.php new file mode 100644 index 0000000..4ff8c8d --- /dev/null +++ b/framework/yii/views/errorHandler/main.php @@ -0,0 +1,101 @@ +context; +?> + + + + + + + + <?php echo $c->htmlEncode($e->getName() . ' – ' . get_class($e)); ?> + + <?php echo $c->htmlEncode(get_class($e)); ?> + + + + + + + + + + +
    + Attention +

    + ExceptionaddTypeLinks(get_class($e)); ?> + + – createHttpStatusLink($e->statusCode); ?> + +

    +

    htmlEncode($e->getName()); ?>

    +
    + +
    +
      + renderCallStackItem($e->getFile(), $e->getLine(), 1); ?> + getTrace(), $length = count($trace); $i < $length; ++$i): ?> + renderCallStackItem($trace[$i]['file'], $trace[$i]['line'], $i + 1); ?> + +
    +
    + + +
    +
    +
    +
    $_GET = [
    +	'show-post' => 100,
    +	'refresh-page' => 'yes',
    +	'ascending-sort' => 1,
    +];
    +
    +$_POST = [
    +	'blog-post-form' => [
    +		'title' => 'hello',
    +		'author_id' => '12',
    +	],
    +];
    +
    +$_SERVER = [
    +	'DOCUMENT_ROOT' => '/home/resurtm/work/data',
    +	'REMOTE_ADDR' => '::1',
    +	'REMOTE_PORT' => '52694',
    +	'SERVER_SOFTWARE' => 'PHP 5.4.3 Development Server',
    +	'SERVER_PROTOCOL' => 'HTTP/1.1',
    +	'SERVER_NAME' => 'localhost',
    +	'SERVER_PORT' => '8000',
    +	'REQUEST_URI' => '/index.php?post-form[title]=hello&post-form[author_id]=12',
    +	'REQUEST_METHOD' => 'GET',
    +	'SCRIPT_NAME' => '/index.php',
    +	'SCRIPT_FILENAME' => '/home/resurtm/work/data/index.php',
    +	'PHP_SELF' => '/index.php',
    +	'QUERY_STRING' => 'post-form[title]=hello&post-form[author_id]=12',
    +	'HTTP_HOST' => 'localhost:8000',
    +	'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0',
    +	'HTTP_ACCEPT_LANGUAGE' => 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
    +	'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
    +	'HTTP_CONNECTION' => 'keep-alive',
    +	'REQUEST_TIME_FLOAT' => 1369146454.0856,
    +	'REQUEST_TIME' => 1369146454,
    +];
    +
    + + */ ?> + + + + + From 731cbf8980a339cf75b1dfc8a6658cb832df543c Mon Sep 17 00:00:00 2001 From: resurtm Date: Sat, 25 May 2013 21:40:11 +0600 Subject: [PATCH 049/122] New error page WIP. --- apps/bootstrap/controllers/SiteController.php | 4 +- apps/bootstrap/www/tmp/gears.png | Bin 0 -> 4579 bytes apps/bootstrap/www/tmp/main.css | 15 ++++- apps/bootstrap/www/tmp/main.js | 7 +- framework/yii/base/ErrorHandler.php | 16 ++++- framework/yii/views/errorHandler/callStackItem.php | 2 +- framework/yii/views/errorHandler/main.php | 71 +++++++-------------- 7 files changed, 60 insertions(+), 55 deletions(-) create mode 100644 apps/bootstrap/www/tmp/gears.png diff --git a/apps/bootstrap/controllers/SiteController.php b/apps/bootstrap/controllers/SiteController.php index 4652430..a6731f9 100644 --- a/apps/bootstrap/controllers/SiteController.php +++ b/apps/bootstrap/controllers/SiteController.php @@ -20,8 +20,10 @@ class SiteController extends Controller public function actionIndex() { + $x = null; + $x->y = 100; throw new \yii\base\HttpException(500, 'Test exception'); - $x = 1; +// $x = 1; echo $this->render('index'); } diff --git a/apps/bootstrap/www/tmp/gears.png b/apps/bootstrap/www/tmp/gears.png new file mode 100644 index 0000000000000000000000000000000000000000..7eaa41ce13c91790b33d25e0e3aa51425d2e48e9 GIT binary patch literal 4579 zcmaJ_c{r5&-?n8dM3O>HnzD|WA=@0wU@T+HzK3B3gISER#@LsLWM4ueHI@>xFCm01 z$(kjiEQc)Fvi0ixPUrXj@t*g&uIKqK*L~lg?f&bzYoM>m#(IgBhK7a>sf92)S#?id zI5XYJS6P;k>14S`R<|G<6P(CCC=!N71x;|k0FXG8GsXymLi>4iVH9X+=mA(03$lft zF3gdDlR*8#NciH2Cu|xT1!Z3%%Fzu&1~_1xv3Nznwfbg302Zw%XfCY>(Icv1T(DaH zB#g1YzKNs1o1;8hP+19};0rquz+uQJfG^G+?+No&6#PpUcC!C<4Hg9a1tGgB3jQZ4 z3q1pX8i9lXNJ~IKju06LKn5xSmAWY_D=Q9=gg_x+h$I*)34+SPq$FVw2;lEW@FW@u z?F2JIX#5@Pli)>iJQngqq@^KHsJf)e zO*N=GLIbKIB?*z1QiuNLA_$INI1HZrn~VN07y7T z!~Sb7vg-e;_cs^)uer!-{3{oHk_`CQSpV0Ue_x$==hyZh)1Dmuu{{QV;&sxAsrQV^ z-qX;qTOtuECcYmht;Y%HMlbA$+d4Jeo0H3$dt;deZ`IdwaOFvXiv)^keaQ>5zEWhi ztP>%uGn|^LY7xP}QklS39u*F>of~(iIDci7s_L}nDp;>C679^X^=$U+-wa$}PcJG; zy@h(aRH>fGoYoUMmolwGxx|c-_udx$InOdaes@+*!?0#}S;?nwdHeWhFt?EiB~U;~ z>)g2va49`Ku+5%#=Wd7zP{d;{veo0;_k~it>^>J=Om1#<0|nP$X%*F|9A2f3>@RaFlDL+ZtI$ml`2>D#nMpMT7+PFxJX`0&pdx(pK@26vL= zPl@AMHBGxKvm4A}V$|m2&-sQ#tVl|$jfAFSKBrI>pEh&fteu(}OoUuj~lj@faVo0y<#+kr(xM}tQfbUD4UsA_fl)%aQ282&3Il%l6f#fZe!bvgu!Gn z5099c%dL=VC7bGEmx0`Bcr-(9j!eHUrFs6lh?!WQ2U^_8&RVKEc~pmk-CyBy{Zu@k zutaS(=6Y0A#7e{c$b%KjJD#2%5_Hgt$+Kq z8K3UPJ42HXkxj^_SkqpW8c@Qzf&@=eFT6Z3aKwIK5prWx9CSC-9_Uth!|-Cq{+BdL zWXO}S;n(HjZEr+kn*BZ;@8BeuGILVXQpNp38cVa2<@(5&0CBSh$(BaJ&MyOoA3}C_ z_5+mOHfHpOaG%P}2Z2%*609ux`iw$?^P4Ena94=M$f1y-I6D_5#o^`Pc12<2@=5{R z;v)S$AU1QFncD`wm z-P{Gdu}{8DU!TNl%9Y%mNt}qDOa73twzD30UKEulmzfS%W+_YD_jkK3V97AM4{p|i z9i;^wkJEn?vd(jb0J|n1@~6>r8Lkg~3eo}FeHIW%6y`eEecH6AYHN8l5qZXD)FJQP zJmR@PGT#D@do?mY=7F;E$mquli-z{4iAv)6`9Gi<;^5OsN!r%deNL^L^BEa~)6+xq z>%R6aXk>WS4Zk0fB0btc%8i68ve1_J_!u|0H!CGSwx}kDQCG$aZ|uLOUFR|2UD>Ni zECm*fz7SxK3L+Ad>LXPF$?mbSwWp8Pl$n)xkB>A=Uu|qr>ncr*#OG#)^`Ek68HZ`t7Ub8REgFkNBfjwRu!gv3G_j2VKy7bsTt~D+yohHR zo;A|6eME{fosr^a+zl(qYNBMPXNr1zh)}z#D-EL9p%i7h$fY*^fRu&yjvGvC6t5t?RImH{xGJUU8^jJ!X%;^JP(ukg0=Rfu%UvjkE2 zSA3AwTkoYiyWAB;krxun@YPugr1^X;%}9^kEjcgI{0P0E=1kl%S*PdYcm-c}whiq! zGf0wpeiswRW*3j8R;v~2U9SiRudm0pZy&V#oV+WNB6#5fQgQU!i`iQb?LS~$ofr*} zuUq#Iu2vO1m!M$p2CV~x&=%|90ULa^YlWq`xj^J#Oru|0BCy~}{Rc}Pl~IfKd7v3< zmhJ~tO{Vul4C=bb8xd3yl2b?Wqd*$@Kg4Kc7nfSLX)kpfTk|P;i?gMM&cB~#*JrR( z#UkI|JlONV9~1CZG-ry>n?0MZ!$5<>8Ql1I4Zdr0T54S<8XFe@xM@X(M!G>Dgq@wV z9=#9krzBU`!R>9nsi~!UpQXo=+E$h!Fh43su^Z8vfta~^x{Hf5Wdb+oz&4`N;du#C zTqyyRTx%~GZOXCsVIUW?1^1dcmsp`gs+o{px@Z43Gnl_e_SKu9u1>L zzlCyu#aVUh*^XrLf%jw$`;l(n_wCUt_r|O&A)L$@atmRy`nt{df&{<^&WVjPEu(wfifp!ng>@MGxR6Fd|%0Z>vC#ra6RH`HRU?Abfi>sY9zB7{&=K60r z_k~-|89Xg<@Na>r7izo;d3HGY$I~||Ln?^i9(0q?w&8|rwZ(f`nQkmEA??kgN)tWW zCHA)X5wZSFw1!XkRVsh=ZL9irrv7&T0gJMCs)8cZ2C6B}ro$ zbg-T!25&~MNxF!>wWn@wEwJz@{OJf8>#m-jE0RIheCQj=I%4!J#pJpvgih>P=C}I; zu;$0Yjs6&sGh8&xaygHL`>DqAa_wkI%Bt1IadgLZMy66Wws2IiotDqHg0;!3_4QK= zee$6y7I*D^t>KQDjLA|H^H{)POmKKqZ!gRGr?*<7+^THpBv?dQ972;R zngbx5vCR?+Xq9N(74QpCDB1_r?&Gm7y=khi42#vR z`|TxRPJ?Bl^b=9tbm2|a7v4{mP!2=r%aUX&WFEeBOdo6^9Lvk_GsX!3SHH2OhZro7+GLBvQe8x6{*+WtIb+gb|BbS(O-&w1&0r*pyzB4h`@v?< zxb|u@;8fgWI6PwLN%d1PZ}ZY_ka)q`C-8y`F7_1BALjA>hR2Wc;Z;UzTzPg)O*9C+ z5KB_x1#+<*OjOt6m?AwM%H_SnYI7oO0DL-$^)Esy6ZoWaRjM_D(NwiZA4gGWD zJj)9P2ZDo+I_7a=S3x@s*Gz+TtyT|HMeMb9o=c3rhUbMMzZL@z z-(B3^_xeDgaD5JAVFmW?LLg zP5sww`%3I;YC{ABjO29v8t+ZtLvpaaynlHEUOH`8B5lHViNEuHTX}&2bATp8)z%&q zx7ci7TrAo{_w>j>>$GefIx7Dyty0Deb$=zMY2QN0ivZV@~&M=16w;5V`N8EAAG@}pM)(Ss$j*CGFGE@3OlNowszzK>M zo4H)`0r_X3_Lk6N!kZ9!kF;36i!BP5!w2%3Gn1%E5Bt;Vm9JeZrY5tc`%AJ2vh<91 zMKadDxaGEHS(@Bw4D3vdSY$^ijEto>5NVGYe9K(sbSj1Qhv;_Nw!YtR>fWPupok0s%kUA*B~)RrpsunMlqsWEM=GOj zZsYYs7d?$|tbM`H!?2VgiSf2s?}Y}n>XbhChDJJLelVr|_VYvc_(O#tRlS?#CCvVf zMlh(P0~U9b9w%<%?qW6Y1Q(Cx=Z-KPY;U!;{?e{)sJx@c6c*qtv@S>T%aHJ|D`^O< zhr*VXe9LSUYhRgV<~Q3dFBw)$Q~?H`Z64QlMEUWvFE752i;E-UK;A3qX@yrmX}7g? zj35r*ath0g)XGn^(uvjr*01w3ol6_`nfe$^&3o+XCsz;8TNi7dN|tAD*UwgcDw4nq zSJPyp+Pa#+~{IXrenderFile($this->mainView, array('e' => $exception), $this); + $request = array(); + if (count($_GET) > 0) { + $request[] = '$_GET = ' . var_export($_GET, true) . ';'; + } + if (count($_POST) > 0) { + $request[] = '$_POST = ' . var_export($_POST, true) . ';'; + } + $request[] = '$_SERVER = ' . var_export($_SERVER, true) . ';'; + $request = implode("\n\n", $request); + echo $view->renderFile($this->mainView, array( + 'e' => $exception, + 'request' => $request, + 'requestLinesCount' => substr_count($request, "\n"), + ), $this); } } } diff --git a/framework/yii/views/errorHandler/callStackItem.php b/framework/yii/views/errorHandler/callStackItem.php index e4ac1bf..b319d16 100644 --- a/framework/yii/views/errorHandler/callStackItem.php +++ b/framework/yii/views/errorHandler/callStackItem.php @@ -1,13 +1,13 @@ context; ?> diff --git a/framework/yii/views/errorHandler/main.php b/framework/yii/views/errorHandler/main.php index 4ff8c8d..0ea82e1 100644 --- a/framework/yii/views/errorHandler/main.php +++ b/framework/yii/views/errorHandler/main.php @@ -2,6 +2,8 @@ /** * @var \yii\base\View $this * @var \Exception $e + * @var string $request + * @var integer $requestLinesCount * @var \yii\base\ErrorHandler $c */ $c = $this->context; @@ -27,14 +29,23 @@ $c = $this->context;
    - Attention -

    - ExceptionaddTypeLinks(get_class($e)); ?> - - – createHttpStatusLink($e->statusCode); ?> - -

    -

    htmlEncode($e->getName()); ?>

    + + Gears +

    + htmlEncode($e->getName()); ?> + – addTypeLinks(get_class($e)); ?> +

    +

    htmlEncode($e->getMessage()); ?>

    + + Attention +

    + ExceptionaddTypeLinks(get_class($e)); ?> + + – createHttpStatusLink($e->statusCode); ?> + +

    +

    htmlEncode($e->getName()); ?>

    +
    @@ -46,49 +57,11 @@ $c = $this->context;
    - -
    -
    -
    -
    $_GET = [
    -	'show-post' => 100,
    -	'refresh-page' => 'yes',
    -	'ascending-sort' => 1,
    -];
    -
    -$_POST = [
    -	'blog-post-form' => [
    -		'title' => 'hello',
    -		'author_id' => '12',
    -	],
    -];
    -
    -$_SERVER = [
    -	'DOCUMENT_ROOT' => '/home/resurtm/work/data',
    -	'REMOTE_ADDR' => '::1',
    -	'REMOTE_PORT' => '52694',
    -	'SERVER_SOFTWARE' => 'PHP 5.4.3 Development Server',
    -	'SERVER_PROTOCOL' => 'HTTP/1.1',
    -	'SERVER_NAME' => 'localhost',
    -	'SERVER_PORT' => '8000',
    -	'REQUEST_URI' => '/index.php?post-form[title]=hello&post-form[author_id]=12',
    -	'REQUEST_METHOD' => 'GET',
    -	'SCRIPT_NAME' => '/index.php',
    -	'SCRIPT_FILENAME' => '/home/resurtm/work/data/index.php',
    -	'PHP_SELF' => '/index.php',
    -	'QUERY_STRING' => 'post-form[title]=hello&post-form[author_id]=12',
    -	'HTTP_HOST' => 'localhost:8000',
    -	'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0',
    -	'HTTP_ACCEPT_LANGUAGE' => 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
    -	'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
    -	'HTTP_CONNECTION' => 'keep-alive',
    -	'REQUEST_TIME_FLOAT' => 1369146454.0856,
    -	'REQUEST_TIME' => 1369146454,
    -];
    +
    +
    htmlEncode($request); ?>
    -
    - */ ?> +