mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-17 23:09:10 +08:00
Merge branch 'master' of github.com:yiisoft/yii2 into mssql
This commit is contained in:
@@ -9,6 +9,8 @@ If you are looking for a production-ready PHP framework, please use
|
|||||||
Yii 2.0 is still under heavy development. We may make significant changes
|
Yii 2.0 is still under heavy development. We may make significant changes
|
||||||
without prior notices. **Yii 2.0 is not ready for production use yet.**
|
without prior notices. **Yii 2.0 is not ready for production use yet.**
|
||||||
|
|
||||||
|
[](http://travis-ci.org/yiisoft/yii2)
|
||||||
|
|
||||||
|
|
||||||
DIRECTORY STRUCTURE
|
DIRECTORY STRUCTURE
|
||||||
-------------------
|
-------------------
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ class DictionaryTest extends \yiiunit\TestCase
|
|||||||
* @var \yii\base\Dictionary
|
* @var \yii\base\Dictionary
|
||||||
*/
|
*/
|
||||||
protected $dictionary;
|
protected $dictionary;
|
||||||
protected $item1,$item2,$item3;
|
protected $item1;
|
||||||
|
protected $item2;
|
||||||
|
protected $item3;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
@@ -171,14 +173,15 @@ class DictionaryTest extends \yiiunit\TestCase
|
|||||||
{
|
{
|
||||||
$n = 0;
|
$n = 0;
|
||||||
$found = 0;
|
$found = 0;
|
||||||
foreach($this->dictionary as $index=>$item)
|
foreach ($this->dictionary as $index => $item) {
|
||||||
{
|
|
||||||
$n++;
|
$n++;
|
||||||
if($index==='key1' && $item===$this->item1)
|
if ($index === 'key1' && $item === $this->item1) {
|
||||||
$found++;
|
$found++;
|
||||||
if($index==='key2' && $item===$this->item2)
|
}
|
||||||
|
if ($index === 'key2' && $item === $this->item2) {
|
||||||
$found++;
|
$found++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$this->assertTrue($n == 2 && $found == 2);
|
$this->assertTrue($n == 2 && $found == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ class VectorTest extends \yiiunit\TestCase
|
|||||||
* @var Vector
|
* @var Vector
|
||||||
*/
|
*/
|
||||||
protected $vector;
|
protected $vector;
|
||||||
protected $item1, $item2, $item3;
|
protected $item1;
|
||||||
|
protected $item2;
|
||||||
|
protected $item3;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
@@ -143,12 +145,14 @@ class VectorTest extends \yiiunit\TestCase
|
|||||||
{
|
{
|
||||||
$array = array($this->item3, $this->item1);
|
$array = array($this->item3, $this->item1);
|
||||||
$this->vector->mergeWith($array);
|
$this->vector->mergeWith($array);
|
||||||
$this->assertTrue($this->vector->getCount()==4 && $this->vector[0]===$this->item1 && $this->vector[3]===$this->item1);
|
$this->assertTrue($this->vector->getCount() == 4 && $this->vector[0] === $this->item1 &&
|
||||||
|
$this->vector[3] === $this->item1);
|
||||||
|
|
||||||
$a = array(1);
|
$a = array(1);
|
||||||
$vector = new Vector($a);
|
$vector = new Vector($a);
|
||||||
$this->vector->mergeWith($vector);
|
$this->vector->mergeWith($vector);
|
||||||
$this->assertTrue($this->vector->getCount()==5 && $this->vector[0]===$this->item1 && $this->vector[3]===$this->item1 && $this->vector[4]===1);
|
$this->assertTrue($this->vector->getCount() == 5 && $this->vector[0] === $this->item1 &&
|
||||||
|
$this->vector[3] === $this->item1 && $this->vector[4] === 1);
|
||||||
|
|
||||||
$this->setExpectedException('yii\base\InvalidParamException');
|
$this->setExpectedException('yii\base\InvalidParamException');
|
||||||
$this->vector->mergeWith($this);
|
$this->vector->mergeWith($this);
|
||||||
@@ -172,15 +176,18 @@ class VectorTest extends \yiiunit\TestCase
|
|||||||
{
|
{
|
||||||
$n = 0;
|
$n = 0;
|
||||||
$found = 0;
|
$found = 0;
|
||||||
foreach($this->vector as $index=>$item)
|
foreach ($this->vector as $index => $item) {
|
||||||
{
|
foreach ($this->vector as $a => $b) {
|
||||||
foreach($this->vector as $a=>$b); // test of iterator
|
// test of iterator
|
||||||
|
}
|
||||||
$n++;
|
$n++;
|
||||||
if($index===0 && $item===$this->item1)
|
if ($index === 0 && $item === $this->item1) {
|
||||||
$found++;
|
$found++;
|
||||||
if($index===1 && $item===$this->item2)
|
}
|
||||||
|
if ($index === 1 && $item === $this->item2) {
|
||||||
$found++;
|
$found++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$this->assertTrue($n == 2 && $found == 2);
|
$this->assertTrue($n == 2 && $found == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -318,10 +318,10 @@ class Controller extends Component
|
|||||||
/** @var Model $model */
|
/** @var Model $model */
|
||||||
$scope = $model->formName();
|
$scope = $model->formName();
|
||||||
if ($scope == '') {
|
if ($scope == '') {
|
||||||
$model->attributes = $data;
|
$model->setAttributes($data);
|
||||||
$success = true;
|
$success = true;
|
||||||
} elseif (isset($data[$scope])) {
|
} elseif (isset($data[$scope])) {
|
||||||
$model->attributes = $data[$scope];
|
$model->setAttributes($data[$scope]);
|
||||||
$success = true;
|
$success = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,9 +100,10 @@ class HttpException extends UserException
|
|||||||
509 => 'Bandwidth Limit Exceeded',
|
509 => 'Bandwidth Limit Exceeded',
|
||||||
);
|
);
|
||||||
|
|
||||||
if(isset($httpCodes[$this->statusCode]))
|
if (isset($httpCodes[$this->statusCode])) {
|
||||||
return $httpCodes[$this->statusCode];
|
return $httpCodes[$this->statusCode];
|
||||||
else
|
} else {
|
||||||
return \Yii::t('yii|Error');
|
return \Yii::t('yii|Error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
namespace yii\console\controllers;
|
namespace yii\console\controllers;
|
||||||
|
|
||||||
use yii\console\Controller;
|
use yii\console\Controller;
|
||||||
use yii\helpers\FileHelper;
|
|
||||||
use yii\base\Exception;
|
use yii\base\Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -77,8 +76,7 @@ class AppController extends Controller
|
|||||||
|
|
||||||
if (basename($path) === '.') {
|
if (basename($path) === '.') {
|
||||||
$this->_rootPath = $path = $dir;
|
$this->_rootPath = $path = $dir;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$this->_rootPath = $path = $dir.DIRECTORY_SEPARATOR.basename($path);
|
$this->_rootPath = $path = $dir.DIRECTORY_SEPARATOR.basename($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,11 +119,9 @@ class AppController extends Controller
|
|||||||
|
|
||||||
if ($customSource) {
|
if ($customSource) {
|
||||||
return $customSource;
|
return $customSource;
|
||||||
}
|
} elseif ($defaultSource) {
|
||||||
elseif($defaultSource) {
|
|
||||||
return $defaultSource;
|
return $defaultSource;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw new Exception('Unable to locate the source directory for "'.$this->type.'".');
|
throw new Exception('Unable to locate the source directory for "'.$this->type.'".');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -243,8 +239,7 @@ class AppController extends Controller
|
|||||||
|
|
||||||
if ($callback !== null) {
|
if ($callback !== null) {
|
||||||
$content = call_user_func($callback, $source, $params);
|
$content = call_user_func($callback, $source, $params);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$content = file_get_contents($source);
|
$content = file_get_contents($source);
|
||||||
}
|
}
|
||||||
if (is_file($target)) {
|
if (is_file($target)) {
|
||||||
@@ -261,15 +256,12 @@ class AppController extends Controller
|
|||||||
$answer = trim(fgets(STDIN));
|
$answer = trim(fgets(STDIN));
|
||||||
if (!strncasecmp($answer, 'q', 1)) {
|
if (!strncasecmp($answer, 'q', 1)) {
|
||||||
return;
|
return;
|
||||||
}
|
} elseif (!strncasecmp($answer, 'y', 1)) {
|
||||||
elseif(!strncasecmp($answer, 'y', 1)) {
|
|
||||||
echo " overwrite $name\n";
|
echo " overwrite $name\n";
|
||||||
}
|
} elseif (!strncasecmp($answer, 'a', 1)) {
|
||||||
elseif(!strncasecmp($answer, 'a', 1)) {
|
|
||||||
echo " overwrite $name\n";
|
echo " overwrite $name\n";
|
||||||
$overwriteAll = true;
|
$overwriteAll = true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
echo " skip $name\n";
|
echo " skip $name\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,50 +57,58 @@ class MessageController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function actionIndex($config)
|
public function actionIndex($config)
|
||||||
{
|
{
|
||||||
if(!is_file($config))
|
if (!is_file($config)) {
|
||||||
$this->usageError("the configuration file {$config} does not exist.");
|
$this->usageError("the configuration file {$config} does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
$config = require_once($config);
|
$config = require_once($config);
|
||||||
|
|
||||||
$translator='Yii::t';
|
$translator='Yii::t';
|
||||||
extract($config);
|
extract($config);
|
||||||
|
|
||||||
if(!isset($sourcePath,$messagePath,$languages))
|
if (!isset($sourcePath, $messagePath, $languages)) {
|
||||||
$this->usageError('The configuration file must specify "sourcePath", "messagePath" and "languages".');
|
$this->usageError('The configuration file must specify "sourcePath", "messagePath" and "languages".');
|
||||||
if(!is_dir($sourcePath))
|
}
|
||||||
|
if (!is_dir($sourcePath)) {
|
||||||
$this->usageError("The source path $sourcePath is not a valid directory.");
|
$this->usageError("The source path $sourcePath is not a valid directory.");
|
||||||
if(!is_dir($messagePath))
|
}
|
||||||
|
if (!is_dir($messagePath)) {
|
||||||
$this->usageError("The message path $messagePath is not a valid directory.");
|
$this->usageError("The message path $messagePath is not a valid directory.");
|
||||||
if(empty($languages))
|
}
|
||||||
|
if (empty($languages)) {
|
||||||
$this->usageError("Languages cannot be empty.");
|
$this->usageError("Languages cannot be empty.");
|
||||||
|
}
|
||||||
|
|
||||||
if(!isset($overwrite))
|
if (!isset($overwrite)) {
|
||||||
$overwrite = false;
|
$overwrite = false;
|
||||||
|
}
|
||||||
if(!isset($removeOld))
|
if (!isset($removeOld)) {
|
||||||
$removeOld = false;
|
$removeOld = false;
|
||||||
|
}
|
||||||
if(!isset($sort))
|
if (!isset($sort)) {
|
||||||
$sort = false;
|
$sort = false;
|
||||||
|
}
|
||||||
|
|
||||||
$options = array();
|
$options = array();
|
||||||
if(isset($fileTypes))
|
if (isset($fileTypes)) {
|
||||||
$options['fileTypes'] = $fileTypes;
|
$options['fileTypes'] = $fileTypes;
|
||||||
if(isset($exclude))
|
}
|
||||||
|
if (isset($exclude)) {
|
||||||
$options['exclude'] = $exclude;
|
$options['exclude'] = $exclude;
|
||||||
|
}
|
||||||
$files = CFileHelper::findFiles(realpath($sourcePath), $options);
|
$files = CFileHelper::findFiles(realpath($sourcePath), $options);
|
||||||
|
|
||||||
$messages = array();
|
$messages = array();
|
||||||
foreach($files as $file)
|
foreach ($files as $file) {
|
||||||
$messages = array_merge_recursive($messages, $this->extractMessages($file, $translator));
|
$messages = array_merge_recursive($messages, $this->extractMessages($file, $translator));
|
||||||
|
}
|
||||||
|
|
||||||
foreach($languages as $language)
|
foreach ($languages as $language) {
|
||||||
{
|
|
||||||
$dir = $messagePath . DIRECTORY_SEPARATOR . $language;
|
$dir = $messagePath . DIRECTORY_SEPARATOR . $language;
|
||||||
if(!is_dir($dir))
|
if (!is_dir($dir)) {
|
||||||
@mkdir($dir);
|
@mkdir($dir);
|
||||||
foreach($messages as $category=>$msgs)
|
}
|
||||||
{
|
foreach ($messages as $category => $msgs) {
|
||||||
$msgs = array_values(array_unique($msgs));
|
$msgs = array_values(array_unique($msgs));
|
||||||
$this->generateMessageFile($msgs, $dir . DIRECTORY_SEPARATOR . $category . '.php', $overwrite, $removeOld, $sort);
|
$this->generateMessageFile($msgs, $dir . DIRECTORY_SEPARATOR . $category . '.php', $overwrite, $removeOld, $sort);
|
||||||
}
|
}
|
||||||
@@ -111,14 +119,16 @@ class MessageController extends Controller
|
|||||||
{
|
{
|
||||||
echo "Extracting messages from $fileName...\n";
|
echo "Extracting messages from $fileName...\n";
|
||||||
$subject = file_get_contents($fileName);
|
$subject = file_get_contents($fileName);
|
||||||
$n=preg_match_all('/\b'.$translator.'\s*\(\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*,\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*[,\)]/s',$subject,$matches,PREG_SET_ORDER);
|
$n = preg_match_all(
|
||||||
|
'/\b' . $translator . '\s*\(\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*,\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*[,\)]/s',
|
||||||
|
$subject, $matches, PREG_SET_ORDER);
|
||||||
$messages = array();
|
$messages = array();
|
||||||
for($i=0;$i<$n;++$i)
|
for ($i = 0; $i < $n; ++$i) {
|
||||||
{
|
if (($pos = strpos($matches[$i][1], '.')) !== false) {
|
||||||
if(($pos=strpos($matches[$i][1],'.'))!==false)
|
|
||||||
$category=substr($matches[$i][1], $pos + 1, -1);
|
$category=substr($matches[$i][1], $pos + 1, -1);
|
||||||
else
|
} else {
|
||||||
$category=substr($matches[$i][1], 1, -1);
|
$category=substr($matches[$i][1], 1, -1);
|
||||||
|
}
|
||||||
$message = $matches[$i][2];
|
$message = $matches[$i][2];
|
||||||
$messages[$category][] = eval("return $message;"); // use eval to eliminate quote escape
|
$messages[$category][] = eval("return $message;"); // use eval to eliminate quote escape
|
||||||
}
|
}
|
||||||
@@ -128,53 +138,53 @@ class MessageController extends Controller
|
|||||||
protected function generateMessageFile($messages, $fileName, $overwrite, $removeOld, $sort)
|
protected function generateMessageFile($messages, $fileName, $overwrite, $removeOld, $sort)
|
||||||
{
|
{
|
||||||
echo "Saving messages to $fileName...";
|
echo "Saving messages to $fileName...";
|
||||||
if(is_file($fileName))
|
if (is_file($fileName)) {
|
||||||
{
|
|
||||||
$translated = require($fileName);
|
$translated = require($fileName);
|
||||||
sort($messages);
|
sort($messages);
|
||||||
ksort($translated);
|
ksort($translated);
|
||||||
if(array_keys($translated)==$messages)
|
if (array_keys($translated) == $messages) {
|
||||||
{
|
|
||||||
echo "nothing new...skipped.\n";
|
echo "nothing new...skipped.\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$merged = array();
|
$merged = array();
|
||||||
$untranslated = array();
|
$untranslated = array();
|
||||||
foreach($messages as $message)
|
foreach ($messages as $message) {
|
||||||
{
|
if (!empty($translated[$message])) {
|
||||||
if(!empty($translated[$message]))
|
|
||||||
$merged[$message] = $translated[$message];
|
$merged[$message] = $translated[$message];
|
||||||
else
|
} else {
|
||||||
$untranslated[] = $message;
|
$untranslated[] = $message;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ksort($merged);
|
ksort($merged);
|
||||||
sort($untranslated);
|
sort($untranslated);
|
||||||
$todo = array();
|
$todo = array();
|
||||||
foreach($untranslated as $message)
|
foreach ($untranslated as $message) {
|
||||||
$todo[$message] = '';
|
$todo[$message] = '';
|
||||||
|
}
|
||||||
ksort($translated);
|
ksort($translated);
|
||||||
foreach($translated as $message=>$translation)
|
foreach ($translated as $message => $translation) {
|
||||||
{
|
|
||||||
if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeOld)
|
if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeOld)
|
||||||
{
|
{
|
||||||
if(substr($translation,0,2)==='@@' && substr($translation,-2)==='@@')
|
if (substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') {
|
||||||
$todo[$message]=$translation;
|
$todo[$message]=$translation;
|
||||||
else
|
} else {
|
||||||
$todo[$message] = '@@' . $translation . '@@';
|
$todo[$message] = '@@' . $translation . '@@';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$merged=array_merge($todo,$merged);
|
|
||||||
if($sort)
|
|
||||||
ksort($merged);
|
|
||||||
if($overwrite === false)
|
|
||||||
$fileName.='.merged';
|
|
||||||
echo "translation merged.\n";
|
|
||||||
}
|
}
|
||||||
else
|
$merged = array_merge($todo, $merged);
|
||||||
{
|
if ($sort) {
|
||||||
|
ksort($merged);
|
||||||
|
}
|
||||||
|
if (false === $overwrite) {
|
||||||
|
$fileName .= '.merged';
|
||||||
|
}
|
||||||
|
echo "translation merged.\n";
|
||||||
|
} else {
|
||||||
$merged = array();
|
$merged = array();
|
||||||
foreach($messages as $message)
|
foreach ($messages as $message) {
|
||||||
$merged[$message] = '';
|
$merged[$message] = '';
|
||||||
|
}
|
||||||
ksort($merged);
|
ksort($merged);
|
||||||
echo "saved.\n";
|
echo "saved.\n";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,7 +132,8 @@ class Migration extends \yii\base\Component
|
|||||||
* Executes a SQL statement.
|
* Executes a SQL statement.
|
||||||
* This method executes the specified SQL statement using [[db]].
|
* This method executes the specified SQL statement using [[db]].
|
||||||
* @param string $sql the SQL statement to be executed
|
* @param string $sql the SQL statement to be executed
|
||||||
* @param array $params input parameters (name=>value) for the SQL execution. See [[Command::execute()]] for more details.
|
* @param array $params input parameters (name => value) for the SQL execution.
|
||||||
|
* See [[Command::execute()]] for more details.
|
||||||
*/
|
*/
|
||||||
public function execute($sql, $params = array())
|
public function execute($sql, $params = array())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -191,16 +191,15 @@ $title = $context->htmlEncode($exception instanceof \yii\base\Exception ? $excep
|
|||||||
var traceReg = new RegExp("(^|\\s)trace-file(\\s|$)");
|
var traceReg = new RegExp("(^|\\s)trace-file(\\s|$)");
|
||||||
var collapsedReg = new RegExp("(^|\\s)collapsed(\\s|$)");
|
var collapsedReg = new RegExp("(^|\\s)collapsed(\\s|$)");
|
||||||
|
|
||||||
var e = document.getElementsByTagName("div");
|
var e = document.getElementsByTagName('div');
|
||||||
for (var j = 0, len = e.length; j < len; j++) {
|
for (var j = 0, len = e.length; j < len; j++) {
|
||||||
if (traceReg.test(e[j].className)) {
|
if (traceReg.test(e[j].className)) {
|
||||||
e[j].onclick = function() {
|
e[j].onclick = function() {
|
||||||
var trace = this.parentNode.parentNode;
|
var trace = this.parentNode.parentNode;
|
||||||
if (collapsedReg.test(trace.className)) {
|
if (collapsedReg.test(trace.className)) {
|
||||||
trace.className = trace.className.replace("collapsed", "expanded");
|
trace.className = trace.className.replace('collapsed', 'expanded');
|
||||||
}
|
} else {
|
||||||
else{
|
trace.className = trace.className.replace('expanded', 'collapsed');
|
||||||
trace.className = trace.className.replace("expanded", "collapsed");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user