Commit 18f23ff1 by Antonio Ramirez

Merge branch 'master' of git://github.com/yiisoft/yii2 into 196-add-popvalue-method

* 'master' of git://github.com/yiisoft/yii2: Updated framework paths in composer.json Moved "framework" to "iii". Fixed Yii::importNamespaces() bug. Fixes issue #174: make URL parameters available in $_GET. refactoring. Removed static variable from autoload per qiangxue's suggestion Renamed yii.php -> Yii.php for class, filename consitency created StringHelper::basename() Fixed YiiBaseTest echo Check if trait was loaded
parents 5da62fab 8332e8c6
...@@ -13,4 +13,4 @@ nbproject ...@@ -13,4 +13,4 @@ nbproject
Thumbs.db Thumbs.db
# composer vendor dir # composer vendor dir
/framework/vendor /yii/vendor
\ No newline at end of file \ No newline at end of file
<?php <?php
// Set to false to disable debug mode // comment out the following line to disable debug mode
defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_DEBUG') or define('YII_DEBUG', true);
$frameworkPath = __DIR__ . '/../../framework/'; $frameworkPath = __DIR__ . '/../../yii';
require($frameworkPath . 'yii.php');
$config = require(__DIR__ . '/protected/config/main.php');
$application = new yii\web\Application($config);
require($frameworkPath . '/Yii.php');
// Register Composer autoloader // Register Composer autoloader
@include $frameworkPath . '/vendor/autoload.php'; @include($frameworkPath . '/vendor/autoload.php');
$config = require(__DIR__ . '/protected/config/main.php');
$application = new yii\web\Application($config);
$application->run(); $application->run();
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
// fcgi doesn't have STDIN defined by default // fcgi doesn't have STDIN defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
require(__DIR__ . '/../framework/yii.php'); require(__DIR__ . '/../framework/Yii.php');
$id = 'yiic-build'; $id = 'yiic-build';
$basePath = __DIR__; $basePath = __DIR__;
......
...@@ -64,10 +64,10 @@ ...@@ -64,10 +64,10 @@
"source": "https://github.com/yiisoft/yii2" "source": "https://github.com/yiisoft/yii2"
}, },
"config": { "config": {
"vendor-dir": "framework/vendor" "vendor-dir": "yii/vendor"
}, },
"bin": [ "bin": [
"framework/yiic" "yii/yiic"
], ],
"require": { "require": {
"php": ">=5.3.0", "php": ">=5.3.0",
......
...@@ -5,7 +5,7 @@ define('YII_DEBUG', true); ...@@ -5,7 +5,7 @@ define('YII_DEBUG', true);
$_SERVER['SCRIPT_NAME'] = '/' . __DIR__; $_SERVER['SCRIPT_NAME'] = '/' . __DIR__;
$_SERVER['SCRIPT_FILENAME'] = __FILE__; $_SERVER['SCRIPT_FILENAME'] = __FILE__;
require_once(__DIR__ . '/../../framework/yii.php'); require_once(__DIR__ . '/../../yii/Yii.php');
Yii::setAlias('@yiiunit', __DIR__); Yii::setAlias('@yiiunit', __DIR__);
......
...@@ -47,7 +47,6 @@ class YiiBaseTest extends TestCase ...@@ -47,7 +47,6 @@ class YiiBaseTest extends TestCase
public function testGetVersion() public function testGetVersion()
{ {
echo Yii::getVersion();
$this->assertTrue((boolean)preg_match('~\d+\.\d+(?:\.\d+)?(?:-\w+)?~', \Yii::getVersion())); $this->assertTrue((boolean)preg_match('~\d+\.\d+(?:\.\d+)?(?:-\w+)?~', \Yii::getVersion()));
} }
......
...@@ -70,4 +70,48 @@ class StringHelperTest extends \yii\test\TestCase ...@@ -70,4 +70,48 @@ class StringHelperTest extends \yii\test\TestCase
$this->assertEquals('PostTag', StringHelper::id2camel('post-tag')); $this->assertEquals('PostTag', StringHelper::id2camel('post-tag'));
$this->assertEquals('PostTag', StringHelper::id2camel('post_tag', '_')); $this->assertEquals('PostTag', StringHelper::id2camel('post_tag', '_'));
} }
public function testBasename()
{
$this->assertEquals('', StringHelper::basename(''));
$this->assertEquals('file', StringHelper::basename('file'));
$this->assertEquals('file.test', StringHelper::basename('file.test', '.test2'));
$this->assertEquals('file', StringHelper::basename('file.test', '.test'));
$this->assertEquals('file', StringHelper::basename('/file'));
$this->assertEquals('file.test', StringHelper::basename('/file.test', '.test2'));
$this->assertEquals('file', StringHelper::basename('/file.test', '.test'));
$this->assertEquals('file', StringHelper::basename('/path/to/file'));
$this->assertEquals('file.test', StringHelper::basename('/path/to/file.test', '.test2'));
$this->assertEquals('file', StringHelper::basename('/path/to/file.test', '.test'));
$this->assertEquals('file', StringHelper::basename('\file'));
$this->assertEquals('file.test', StringHelper::basename('\file.test', '.test2'));
$this->assertEquals('file', StringHelper::basename('\file.test', '.test'));
$this->assertEquals('file', StringHelper::basename('C:\file'));
$this->assertEquals('file.test', StringHelper::basename('C:\file.test', '.test2'));
$this->assertEquals('file', StringHelper::basename('C:\file.test', '.test'));
$this->assertEquals('file', StringHelper::basename('C:\path\to\file'));
$this->assertEquals('file.test', StringHelper::basename('C:\path\to\file.test', '.test2'));
$this->assertEquals('file', StringHelper::basename('C:\path\to\file.test', '.test'));
// mixed paths
$this->assertEquals('file.test', StringHelper::basename('/path\to/file.test'));
$this->assertEquals('file.test', StringHelper::basename('/path/to\file.test'));
$this->assertEquals('file.test', StringHelper::basename('\path/to\file.test'));
// \ and / in suffix
$this->assertEquals('file', StringHelper::basename('/path/to/filete/st', 'te/st'));
$this->assertEquals('st', StringHelper::basename('/path/to/filete/st', 'te\st'));
$this->assertEquals('file', StringHelper::basename('/path/to/filete\st', 'te\st'));
$this->assertEquals('st', StringHelper::basename('/path/to/filete\st', 'te/st'));
// http://www.php.net/manual/en/function.basename.php#72254
$this->assertEquals('foo', StringHelper::basename('/bar/foo/'));
$this->assertEquals('foo', StringHelper::basename('\\bar\\foo\\'));
}
} }
<?php <?php
require(__DIR__ . '/../../../framework/yii.php'); require(__DIR__ . '/../../../yii/Yii.php');
$application = new yii\web\Application('test', __DIR__ . '/protected'); $application = new yii\web\Application('test', __DIR__ . '/protected');
$application->run(); $application->run();
...@@ -158,8 +158,8 @@ class YiiBase ...@@ -158,8 +158,8 @@ class YiiBase
{ {
foreach ($namespaces as $name => $path) { foreach ($namespaces as $name => $path) {
if ($name !== '') { if ($name !== '') {
$name = '@' . str_replace('\\', '/', $name); $name = trim(strtr($name, array('\\' => '/', '_' => '/')), '/');
static::setAlias($name, $path); static::setAlias('@' . $name, rtrim($path, '/\\') . '/' . $name);
} }
} }
} }
...@@ -370,7 +370,8 @@ class YiiBase ...@@ -370,7 +370,8 @@ class YiiBase
include($classFile); include($classFile);
if (class_exists($className, false) || interface_exists($className, false)) { if (class_exists($className, false) || interface_exists($className, false) ||
function_exists('trait_exists') && trait_exists($className, false)) {
return true; return true;
} else { } else {
throw new UnknownClassException("Unable to find '$className' in file: $classFile"); throw new UnknownClassException("Unable to find '$className' in file: $classFile");
......
...@@ -252,7 +252,7 @@ class ActiveRecord extends Model ...@@ -252,7 +252,7 @@ class ActiveRecord extends Model
*/ */
public static function tableName() public static function tableName()
{ {
return 'tbl_' . StringHelper::camel2id(basename(get_called_class()), '_'); return 'tbl_' . StringHelper::camel2id(StringHelper::basename(get_called_class()), '_');
} }
/** /**
......
...@@ -44,6 +44,29 @@ class StringHelper ...@@ -44,6 +44,29 @@ class StringHelper
} }
/** /**
* Returns the trailing name component of a path.
* This method does the same as the php function basename() except that it will
* always use \ and / as directory separators, independent of the operating system.
* Note: basename() operates naively on the input string, and is not aware of the
* actual filesystem, or path components such as "..".
* @param string $path A path string.
* @param string $suffix If the name component ends in suffix this will also be cut off.
* @return string the trailing name component of the given path.
* @see http://www.php.net/manual/en/function.basename.php
*/
public static function basename($path, $suffix = '')
{
if (($len = mb_strlen($suffix)) > 0 && mb_substr($path, -$len) == $suffix) {
$path = mb_substr($path, 0, -$len);
}
$path = rtrim(str_replace('\\', '/', $path), '/\\');
if (($pos = mb_strrpos($path, '/')) !== false) {
return mb_substr($path, $pos + 1);
}
return $path;
}
/**
* Converts a word to its plural form. * Converts a word to its plural form.
* Note that this is for English only! * Note that this is for English only!
* For example, 'apple' will become 'apples', and 'child' will become 'children'. * For example, 'apple' will become 'apples', and 'child' will become 'children'.
......
...@@ -69,8 +69,8 @@ class Request extends \yii\base\Request ...@@ -69,8 +69,8 @@ class Request extends \yii\base\Request
$result = Yii::$app->getUrlManager()->parseRequest($this); $result = Yii::$app->getUrlManager()->parseRequest($this);
if ($result !== false) { if ($result !== false) {
list ($route, $params) = $result; list ($route, $params) = $result;
$params = array_merge($_GET, $params); $_GET = array_merge($_GET, $params);
return array($route, $params); return array($route, $_GET);
} else { } else {
throw new HttpException(404, Yii::t('yii|Page not found.')); throw new HttpException(404, Yii::t('yii|Page not found.'));
} }
......
...@@ -12,7 +12,7 @@ defined('YII_DEBUG') or define('YII_DEBUG', true); ...@@ -12,7 +12,7 @@ defined('YII_DEBUG') or define('YII_DEBUG', true);
// fcgi doesn't have STDIN defined by default // fcgi doesn't have STDIN defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
require(__DIR__ . '/yii.php'); require(__DIR__ . '/Yii.php');
$application = new yii\console\Application(array( $application = new yii\console\Application(array(
'id' => 'yiic', 'id' => 'yiic',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment