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