Commit 801ed458 by Klimov Paul

Merge branch 'master' of github.com:yiisoft/yii2

parents fb125b9f 48448864
......@@ -2,5 +2,5 @@ Contributing to Yii2
====================
- [Report an issue](docs/internals/report-an-issue.md)
- [Traslate documentation or messages](docs/internals/translations.md)
- [Contribute to the core code or fix bugs](docs/internals/getting-started.md)
\ No newline at end of file
- [Translate documentation or messages](docs/internals/translations.md)
- [Contribute to the core code or fix bugs](docs/internals/getting-started.md)
......@@ -5,7 +5,7 @@ use yii\widgets\ActiveForm;
/**
* @var yii\web\View $this
* @var yii\widgets\ActiveForm $form
* @var app\models\LoginForm $model
* @var common\models\LoginForm $model
*/
$this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title;
......
......@@ -11,8 +11,9 @@
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
// fcgi doesn't have STDIN defined by default
// fcgi doesn't have STDIN and STDOUT defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDIN') or define('STDOUT', fopen('php://stdout', 'w'));
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
......
......@@ -11,8 +11,9 @@
defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod');
// fcgi doesn't have STDIN defined by default
// fcgi doesn't have STDIN and STDOUT defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDIN') or define('STDOUT', fopen('php://stdout', 'w'));
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
......
......@@ -126,12 +126,16 @@ class SiteController extends Controller
public function actionResetPassword($token)
{
if (empty($token) || is_array($token)) {
throw new BadRequestHttpException('Invalid password reset token.');
}
$model = User::find([
'password_reset_token' => $token,
'status' => User::STATUS_ACTIVE,
]);
if (!$model) {
if ($model === null) {
throw new BadRequestHttpException('Wrong password reset token.');
}
......
......@@ -6,7 +6,7 @@ use yii\captcha\Captcha;
/**
* @var yii\web\View $this
* @var yii\widgets\ActiveForm $form
* @var app\models\ContactForm $model
* @var frontend\models\ContactForm $model
*/
$this->title = 'Contact';
$this->params['breadcrumbs'][] = $this->title;
......
......@@ -5,7 +5,7 @@ use yii\widgets\ActiveForm;
/**
* @var yii\web\View $this
* @var yii\widgets\ActiveForm $form
* @var app\models\LoginForm $model
* @var common\models\LoginForm $model
*/
$this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title;
......
......@@ -10,8 +10,9 @@
defined('YII_DEBUG') or define('YII_DEBUG', true);
// fcgi doesn't have STDIN defined by default
// fcgi doesn't have STDIN and STDOUT defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDIN') or define('STDOUT', fopen('php://stdout', 'w'));
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
......
......@@ -8,8 +8,9 @@
* @license http://www.yiiframework.com/license/
*/
// fcgi doesn't have STDIN defined by default
// fcgi doesn't have STDIN and STDOUT defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDIN') or define('STDOUT', fopen('php://stdout', 'w'));
define('YII_DEBUG', true);
......
......@@ -73,7 +73,7 @@
"ext-mbstring": "*",
"lib-pcre": "*",
"yiisoft/yii2-composer": "*",
"yiisoft/jquery": "2.0.*",
"yiisoft/jquery": "~2.0 | ~1.10",
"phpspec/php-diff": ">=1.0.2",
"ezyang/htmlpurifier": "4.6.*",
"michelf/php-markdown": "1.3.*"
......
......@@ -210,7 +210,7 @@ assets file like the following:
'components' => [
// ...
'assetManager' => [
'bundles' => require /path/to/myapp/config/assets_compressed.php,
'bundles' => require '/path/to/myapp/config/assets_compressed.php',
],
],
```
......
......@@ -118,7 +118,7 @@ in cache and we should regenerate it:
public function getCachedData()
{
$key = /* generate unique key here */;
$value = Yii::$app->getCache()->get($key);
$value = Yii::$app->cache->get($key);
if ($value === false) {
$value = /* regenerate value because it is not found in cache and then save it in cache for later use */;
Yii::$app->cache->set($key, $value);
......
......@@ -24,7 +24,7 @@ Adding more packages to your project
The act of [installing a Yii application](installation.md) creates the `composer.json` file in the root directory of your project.
In this file you list the packages that your application requires. For Yii sites, the most important part of the file is the `require` section:
```
```json
{
"require": {
"Michelf/php-markdown": ">=1.3",
......@@ -63,6 +63,25 @@ In both cases, after some waiting, the required packages will be installed and r
No additional configuration of those packages will be required.
Using a specifc version of a package
------------------------------------
Yii always comes with the latest version of a required library that it is compatible with but allows you to use an
older version if you need to.
A good example for this is jQuery which has [dropped old IE browser support](http://jquery.com/browser-support/) in version 2.x.
When installing Yii via composer the installed jQuery version will be the latest 2.x release. When you want to use jQuery 1.10
because of IE browser support you can adjust your composer.json by requiring a specific version of jQuery like this:
```json
{
"require": {
...
"yiisoft/jquery": "1.10.*"
}
}
```
FAQ
---
......
......@@ -41,8 +41,9 @@ code like the following:
defined('YII_DEBUG') or define('YII_DEBUG', true);
// fcgi doesn't have STDIN defined by default
// fcgi doesn't have STDIN and STDOUT defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDIN') or define('STDOUT', fopen('php://stdout', 'w'));
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
......
......@@ -48,6 +48,7 @@ Extensions and 3rd party libraries
- [Composer](composer.md) - How to manage applications dependencies via composer
- [Extending Yii](extensions.md)
- [Template engines](template.md) - Using template engines such as Smarty or Twig
- [Using Yii together with 3rd-Party Systems](using-3rd-party-libraries.md) - Using Yii in 3rd-Party Systems and using Yii 1 and 2 together
Security and access control
===========================
......
......@@ -523,3 +523,8 @@ up to date updating it semi-automatically and manages autoloading for third part
these are using.
In order to learn more refer to [composer](composer.md) and [installation](installation.md) sections of the guide.
Using Yii 1.1 and 2.x together
------------------------------
Check the guide on [using Yii together with 3rd-Party Systems](using-3rd-party-libraries.md) on this topic.
Using 3rd-Party Libraries
=========================
Yii is carefully designed so that third-party libraries can be
easily integrated to further extend Yii's functionalities.
TODO: namespaces and composer explanations
Using Yii in 3rd-Party Systems
------------------------------
Yii can also be used as a self-contained library to support developing and enhancing
existing 3rd-party systems, such as WordPress, Joomla, etc. To do so, include
the following code in the bootstrap code of the 3rd-party system:
```php
$yiiConfig = require(__DIR__ . '/../config/yii/web.php');
new yii\web\Application($yiiConfig); // No 'run()' invocation!
```
The above code is very similar to the bootstrap code used by a typical Yii application
except one thing: it does not call the `run()` method after creating the Web application
instance.
Now we can use most features offered by Yii when developing 3rd-party enhancements. For example,
we can use `Yii::$app` to access the application instance; we can use the database features
such as ActiveRecord; we can use the model and validation feature; and so on.
Using Yii2 with Yii1
--------------------
Yii2 can be used along with Yii1 at the same project.
Since Yii2 uses namespaced class names they will not conflict with any class from Yii1.
However there is single class, which name is used both in Yii1 and Yii2, it named 'Yii'.
In order to use both Yii1 and Yii2 you need to resolve this collision.
To do so you need to define your own 'Yii' class, which will combine content of 'Yii' from 1.x
and 'Yii' from 2.x.
When using composer you add the following to your composer.json in order to add both versions of yii to your project:
```json
"require": {
"yiisoft/yii": "*",
"yiisoft/yii2": "*",
},
```
Start from defining your own descendant of [[\yii\BaseYii]]:
```php
$yii2path = '/path/to/yii2';
require($yii2path . '/BaseYii.php');
class Yii extends \yii\BaseYii
{
}
Yii::$classMap = include($yii2path . '/classes.php');
```
Now we have a class, which suites Yii2, but causes fatal errors for Yii1.
So, first of all, we need to include [[\YiiBase]] of Yii1 source code to our 'Yii' class
definition file:
```php
$yii2path = '/path/to/yii2';
require($yii2path . '/BaseYii.php'); // Yii 2.x
$yii1path = '/path/to/yii1';
require($yii1path . '/YiiBase.php'); // Yii 1.x
class Yii extends \yii\BaseYii
{
}
Yii::$classMap = include($yii2path . '/classes.php');
```
Using this, defines all necessary constants and autoloader of Yii1.
Now we need to add all fields and methods from [[\YiiBase]] of Yii1 to our 'Yii' class.
Unfortunally, there is no way to do so but copy-paste:
```php
$yii2path = '/path/to/yii2';
require($yii2path . '/BaseYii.php');
$yii1path = '/path/to/yii1';
require($yii1path . '/YiiBase.php');
class Yii extends \yii\BaseYii
{
public static $classMap = [];
public static $enableIncludePath = true;
private static $_aliases = ['system'=>YII_PATH,'zii'=>YII_ZII_PATH];
private static $_imports = [];
private static $_includePaths;
private static $_app;
private static $_logger;
public static function getVersion()
{
return '1.1.15-dev';
}
public static function createWebApplication($config=null)
{
return self::createApplication('CWebApplication',$config);
}
public static function app()
{
return self::$_app;
}
// Rest of \YiiBase internal code placed here
...
}
Yii::$classMap = include($yii2path . '/classes.php');
Yii::registerAutoloader(['Yii', 'autoload']); // Register Yii2 autoloader via Yii1
```
Note: while copying methods you should NOT copy method "autoload()"!
Also you may avoid copying "log()", "trace()", "beginProfile()", "endProfile()"
in case you want to use Yii2 logging instead of Yii1 one.
Now we have 'Yii' class, which suites both Yii 1.x and Yii 2.x.
So bootstrap code used by your application will looks like following:
```php
require(__DIR__ . '/../components/my/Yii.php'); // include created 'Yii' class
$yii2Config = require(__DIR__ . '/../config/yii2/web.php');
new yii\web\Application($yii2Config); // create Yii 2.x application
$yii1Config = require(__DIR__ . '/../config/yii1/main.php');
Yii::createWebApplication($yii1Config)->run(); // create Yii 1.x application
```
Then in any part of your program ```Yii::$app``` refers to Yii 2.x application,
while ```Yii::app()``` refers to Yii 1.x application:
```php
echo get_class(Yii::app()); // outputs 'CWebApplication'
echo get_class(Yii::$app); // outputs 'yii\web\Application'
```
\ No newline at end of file
Creating issues
Report an Issue
===============
You got into rough corner while working with yii, or you found a bug? We are very sorry for that, but we can sort that
out together.
Please follow the guidelines below when creating an issue so that your issue can be more promptly resolved:
- If you are unsure about a function, you may ask on IRC or the forums. If the documentation is unclear, open a separate
issue.
- Please use English if possible.
- Make sure it is clear what is the problem and how to reproduce it.
* Provide information including: the version of PHP and Yii, the type of operating system and Web server, browser type and version;
* Provide the **complete** error call stack if available. A screenshot to explain the issue is very welcome.
* Describe the steps for reproducing the issue. It would be even better if you could provide code to reproduce the issue.
If you are going to report security issue please **do not** use the issue tracker and instead
[contact us directly](http://www.yiiframework.com/security/).
**Do not report an issue if**
* you are asking how to use some Yii feature. You should use [the forum](http://www.yiiframework.com/forum/index.php/forum/42-general-discussions-for-yii-20/) or [chat room](http://www.yiiframework.com/chat/) for this purpose.
* your issue is about security. Please [contact us directly](http://www.yiiframework.com/security/) to report security issues.
**Avoid duplicated issues**
Before you report an issue, please search through [existing issues](https://github.com/yiisoft/yii2/issues) to see if your issue is already reported or fixed to make sure you are not reporting a duplicated issue. Also make sure you have the latest version of Yii and see if the issue still exists.
......@@ -44,6 +44,9 @@ class RenderController extends Controller
}
$renderer = $this->findRenderer();
if ($renderer === false) {
return 1;
}
$renderer->targetDir = $targetDir;
$this->stdout('Searching files to process... ');
......@@ -103,15 +106,11 @@ class RenderController extends Controller
*/
protected function findRenderer()
{
$file = Yii::getAlias('@yii/apidoc/templates/' . $this->template . '/Renderer.php');
$reflection = new FileReflector($file, true);
$reflection->process();
$classes = $reflection->getClasses();
if (empty($classes)) {
$rendererClass = 'yii\\apidoc\\templates\\' . $this->template . '\\Renderer';
if (!class_exists($rendererClass)) {
$this->stderr('Renderer not found.' . PHP_EOL);
return false;
}
$rendererClass = reset($classes)->getName();
require($file);
return new $rendererClass();
}
......
......@@ -8,6 +8,7 @@
namespace yii\debug;
use Yii;
use yii\base\InvalidConfigException;
use yii\log\Target;
/**
......@@ -45,15 +46,10 @@ class LogTarget extends Target
if (!is_dir($path)) {
mkdir($path);
}
$indexFile = "$path/index.data";
if (!is_file($indexFile)) {
$manifest = [];
} else {
$manifest = unserialize(file_get_contents($indexFile));
}
$request = Yii::$app->getRequest();
$response = Yii::$app->getResponse();
$manifest[$this->tag] = $summary = [
$summary = [
'tag' => $this->tag,
'url' => $request->getAbsoluteUrl(),
'ajax' => $request->getIsAjax(),
......@@ -63,7 +59,6 @@ class LogTarget extends Target
'statusCode' => $response->statusCode,
'sqlCount' => $this->getSqlTotalCount(),
];
$this->gc($manifest);
$dataFile = "$path/{$this->tag}.data";
$data = [];
......@@ -72,7 +67,38 @@ class LogTarget extends Target
}
$data['summary'] = $summary;
file_put_contents($dataFile, serialize($data));
file_put_contents($indexFile, serialize($manifest));
$indexFile = "$path/index.data";
$this->updateIndexFile($indexFile, $summary);
}
private function updateIndexFile($indexFile, $summary)
{
touch($indexFile);
if (($fp = @fopen($indexFile, 'r+')) === false) {
throw new InvalidConfigException("Unable to open debug data index file: $indexFile");
}
@flock($fp, LOCK_EX);
$manifest = '';
while (($buffer = fgets($fp)) !== false) {
$manifest .= $buffer;
}
if (!feof($fp) || empty($manifest)) {
// error while reading index data, ignore and create new
$manifest = [];
} else {
$manifest = unserialize($manifest);
}
$manifest[$this->tag] = $summary;
$this->gc($manifest);
ftruncate($fp, 0);
rewind($fp);
fwrite($fp, serialize($manifest));
@flock($fp, LOCK_UN);
@fclose($fp);
}
/**
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\mongodb;
use Yii;
use yii\base\InvalidConfigException;
use yii\test\BaseActiveFixture;
/**
* ActiveFixture represents a fixture backed up by a [[modelClass|MongoDB ActiveRecord class]] or a [[collectionName|MongoDB collection]].
*
* Either [[modelClass]] or [[collectionName]] must be set. You should also provide fixture data in the file
* specified by [[dataFile]] or overriding [[getData()]] if you want to use code to generate the fixture data.
*
* When the fixture is being loaded, it will first call [[resetCollection()]] to remove any existing data in the collection.
* It will then populate the table with the data returned by [[getData()]].
*
* After the fixture is loaded, you can access the loaded data via the [[data]] property. If you set [[modelClass]],
* you will also be able to retrieve an instance of [[modelClass]] with the populated data via [[getModel()]].
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class ActiveFixture extends BaseActiveFixture
{
/**
* @var Connection|string the DB connection object or the application component ID of the DB connection.
*/
public $db = 'mongodb';
/**
* @var string|array the collection name that this fixture is about. If this property is not set,
* the table name will be determined via [[modelClass]].
* @see [[yii\mongodb\Connection::getCollection()]]
*/
public $collectionName;
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (!isset($this->modelClass) && !isset($this->collectionName)) {
throw new InvalidConfigException('Either "modelClass" or "collectionName" must be set.');
}
}
/**
* Loads the fixture data.
* The default implementation will first reset the DB table and then populate it with the data
* returned by [[getData()]].
*/
public function load()
{
$this->resetCollection();
$data = $this->getData();
$this->getCollection()->batchInsert($data);
foreach ($data as $alias => $row) {
$this->data[$alias] = $row;
}
}
protected function getCollection()
{
return $this->db->getCollection($this->getCollectionName());
}
protected function getCollectionName()
{
if ($this->collectionName) {
return $this->collectionName;
} else {
/** @var ActiveRecord $modelClass */
$modelClass = $this->modelClass;
return $modelClass::collectionName();
}
}
/**
* Returns the fixture data.
*
* This method is called by [[loadData()]] to get the needed fixture data.
*
* The default implementation will try to return the fixture data by including the external file specified by [[dataFile]].
* The file should return an array of data rows (column name => column value), each corresponding to a row in the table.
*
* If the data file does not exist, an empty array will be returned.
*
* @return array the data rows to be inserted into the collection.
*/
protected function getData()
{
if ($this->dataFile === null) {
$class = new \ReflectionClass($this);
$dataFile = dirname($class->getFileName()) . '/data/' . $this->getCollectionName() . '.php';
return is_file($dataFile) ? require($dataFile) : [];
} else {
return parent::getData();
}
}
/**
* Removes all existing data from the specified collection and resets sequence number if any.
* This method is called before populating fixture data into the collection associated with this fixture.
*/
protected function resetCollection()
{
$this->getCollection()->remove();
}
}
......@@ -716,7 +716,7 @@ class QueryBuilder extends Object
return "$column $operator (" . implode(', ', $values) . ')';
} else {
$operator = $operator === 'IN' ? '=' : '<>';
return "$column$operator{$values[0]}";
return $column . $operator . reset($values);
}
}
......
......@@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.0 beta under development
----------------------------
- Bug #1265: AssetController does not override 'js' and 'css' for compressed bundles (klimov-paul)
- Bug #1326: The `visible` setting for `DetailView` doesn't work as expected (qiangxue)
- Bug #1446: Logging while logs are processed causes infinite loop (qiangxue)
- Bug #1497: Localized view files are not correctly returned (mintao)
......@@ -34,6 +35,8 @@ Yii Framework 2 Change Log
- Bug #1992: In module scenario that use 'site/captcha' will get wrong refreshUrl (callmez)
- Bug #1993: afterFind event in AR is now called after relations have been populated (cebe, creocoder)
- Bug #1998: Unchecked required checkbox never pass client validation (klevron)
- Bug #2084: AssetController adjusting CSS URLs declared at same line fixed (klimov-paul)
- Bug #2091: `QueryBuilder::buildInCondition()` fails to handle array not starting with index 0 (qiangxue)
- Bug: Fixed `Call to a member function registerAssetFiles() on a non-object` in case of wrong `sourcePath` for an asset bundle (samdark)
- Bug: Fixed incorrect event name for `yii\jui\Spinner` (samdark)
- Bug: Json::encode() did not handle objects that implement JsonSerializable interface correctly (cebe)
......@@ -56,6 +59,7 @@ Yii Framework 2 Change Log
- Enh #1572: Added `yii\web\Controller::createAbsoluteUrl()` (samdark)
- Enh #1579: throw exception when the given AR relation name does not match in a case sensitive manner (qiangxue)
- Enh #1581: Added `ActiveQuery::joinWith()` and `ActiveQuery::innerJoinWith()` to support joining with relations (qiangxue)
- Enh #1585: added schema parameter to createAbsoluteUrl() to force 'http' or 'https' (cebe)
- Enh #1601: Added support for tagName and encodeLabel parameters in ButtonDropdown (omnilight)
- Enh #1611: Added `BaseActiveRecord::markAttributeDirty()` (qiangxue)
- Enh #1633: Advanced application template now works with MongoDB by default (samdark)
......
......@@ -53,7 +53,7 @@
"ext-mbstring": "*",
"lib-pcre": "*",
"yiisoft/yii2-composer": "*",
"yiisoft/jquery": "2.0.*",
"yiisoft/jquery": "~2.0 | ~1.10",
"phpspec/php-diff": ">=1.0.2",
"ezyang/htmlpurifier": "4.6.*",
"michelf/php-markdown": "1.3.*"
......
......@@ -80,7 +80,7 @@ class AssetController extends Controller
* Default value relies on usage of "YUI Compressor"
* @see https://github.com/yui/yuicompressor/
*/
public $cssCompressor = 'java -jar yuicompressor.jar {from} -o {to}';
public $cssCompressor = 'java -jar yuicompressor.jar -o --type css {from} {to}';
/**
* @var array|\yii\web\AssetManager [[yii\web\AssetManager]] instance or its array configuration, which will be used
......@@ -558,7 +558,7 @@ EOD;
return str_replace($inputUrl, $outputUrl, $fullMatch);
};
$cssContent = preg_replace_callback('/url\(["\']?([^"]*)["\']?\)/is', $callback, $cssContent);
$cssContent = preg_replace_callback('/url\(["\']?([^)^"^\']*)["\']?\)/is', $callback, $cssContent);
return $cssContent;
}
......@@ -585,7 +585,7 @@ return [
],
// Asset bundle for compression output:
'targets' => [
'app\config\AllAsset' => [
'app\assets\AllAsset' => [
'basePath' => 'path/to/web',
'baseUrl' => '',
'js' => 'js/all-{ts}.js',
......
......@@ -592,7 +592,8 @@ class MigrateController extends Controller
*/
protected function createMigrationHistoryTable()
{
echo 'Creating migration history table "' . $this->migrationTable . '"...';
$tableName = $this->db->schema->getRawTableName($this->migrationTable);
echo "Creating migration history table \"$tableName\"...";
$this->db->createCommand()->createTable($this->migrationTable, [
'version' => 'varchar(180) NOT NULL PRIMARY KEY',
'apply_time' => 'integer',
......
......@@ -988,7 +988,7 @@ class QueryBuilder extends \yii\base\Object
return "$column $operator (" . implode(', ', $values) . ')';
} else {
$operator = $operator === 'IN' ? '=' : '<>';
return "$column$operator{$values[0]}";
return $column . $operator . reset($values);
}
}
......
......@@ -283,7 +283,7 @@ SQL;
// Index is an expression like "lower(colname::text)"
$indexColumns = preg_replace("/.*\(([^\:]+).*/mi", "$1", $index['indexcolumns']);
} else {
$indexColumns = array_map('trim', explode(',', str_replace(['{', '}'], '', $index['indexcolumns'])));
$indexColumns = array_map('trim', explode(',', str_replace(['{', '}', '"', '\\'], '', $index['indexcolumns'])));
}
$uniqueIndexes[$indexName] = $indexColumns;
......
......@@ -100,16 +100,13 @@ class ActiveFixture extends BaseActiveFixture
*/
protected function getData()
{
if ($this->dataFile === false) {
return [];
}
if ($this->dataFile !== null) {
$dataFile = Yii::getAlias($this->dataFile);
} else {
if ($this->dataFile === null) {
$class = new \ReflectionClass($this);
$dataFile = dirname($class->getFileName()) . '/data/' . $this->getTableSchema()->fullName . '.php';
return is_file($dataFile) ? require($dataFile) : [];
} else {
return parent::getData();
}
return is_file($dataFile) ? require($dataFile) : [];
}
/**
......
......@@ -31,6 +31,11 @@ abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate
*/
public $data = [];
/**
* @var string|boolean the file path or path alias of the data file that contains the fixture data
* to be returned by [[getData()]]. You can set this property to be false to prevent loading any data.
*/
public $dataFile;
/**
* @var \yii\db\ActiveRecord[] the loaded AR models
*/
private $_models = [];
......@@ -66,4 +71,37 @@ abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate
}
return $this->_models[$name] = $modelClass::find($keys);
}
/**
* Loads the fixture.
*
* The default implementation simply stores the data returned by [[getData()]] in [[data]].
* You should usually override this method by putting the data into the underlying database.
*/
public function load()
{
$this->data = $this->getData();
}
/**
* Returns the fixture data.
*
* The default implementation will try to return the fixture data by including the external file specified by [[dataFile]].
* The file should return the data array that will be stored in [[data]] after inserting into the database.
*
* @return array the data to be put into the database
* @throws InvalidConfigException if the specified data file does not exist.
*/
protected function getData()
{
if ($this->dataFile === false || $this->dataFile === null) {
return [];
}
$dataFile = Yii::getAlias($this->dataFile);
if (is_file($dataFile)) {
return require($dataFile);
} else {
throw new InvalidConfigException("Fixture data file does not exist: {$this->dataFile}");
}
}
}
......@@ -167,12 +167,14 @@ class Controller extends \yii\base\Controller
*
* @param string $route the route. This can be either an absolute route or a relative route.
* @param array $params the parameters (name-value pairs) to be included in the generated URL
* @param string $schema the schema to use for the url. e.g. 'http' or 'https'. If not specified
* the schema of the current request will be used.
* @return string the created absolute URL
*/
public function createAbsoluteUrl($route, $params = [])
public function createAbsoluteUrl($route, $params = [], $schema = null)
{
$route = $this->getNormalizedRoute($route);
return Yii::$app->getUrlManager()->createAbsoluteUrl($route, $params);
return Yii::$app->getUrlManager()->createAbsoluteUrl($route, $params, $schema);
}
/**
......
......@@ -277,17 +277,21 @@ class UrlManager extends Component
* This method prepends the URL created by [[createUrl()]] with the [[hostInfo]].
* @param string $route the route
* @param array $params the parameters (name-value pairs)
* @param string $schema the schema to use for the url. e.g. 'http' or 'https'. If not specified
* the schema of the current request will be used.
* @return string the created URL
* @see createUrl()
*/
public function createAbsoluteUrl($route, $params = [])
public function createAbsoluteUrl($route, $params = [], $schema = null)
{
$url = $this->createUrl($route, $params);
if (strpos($url, '://') !== false) {
return $url;
} else {
return $this->getHostInfo() . $url;
if (strpos($url, '://') === false) {
$url = $this->getHostInfo($schema) . $url;
}
if ($schema !== null && ($pos = strpos($url, '://')) !== false) {
$url = $schema . substr($url, $pos);
}
return $url;
}
/**
......
......@@ -10,8 +10,9 @@
defined('YII_DEBUG') or define('YII_DEBUG', true);
// fcgi doesn't have STDIN defined by default
// fcgi doesn't have STDIN and STDOUT defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDIN') or define('STDOUT', fopen('php://stdout', 'w'));
require(__DIR__ . '/Yii.php');
......
......@@ -338,6 +338,18 @@ EOL;
'/test/base/path/assets/output',
'.absolute-url-secure-class {background-image: url(https://secure.domain.com/img/image.gif);}',
],
[
"@font-face {
src: url('../fonts/glyphicons-halflings-regular.eot');
src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype');
}",
'/test/base/path/assets/input/css',
'/test/base/path/assets/output',
"@font-face {
src: url('../input/fonts/glyphicons-halflings-regular.eot');
src: url('../input/fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype');
}",
],
];
}
......
......@@ -124,6 +124,13 @@ class UrlManagerTest extends TestCase
]);
$url = $manager->createAbsoluteUrl('post/view', ['id' => 1, 'title' => 'sample post']);
$this->assertEquals('http://www.example.com?r=post/view&id=1&title=sample+post', $url);
$url = $manager->createAbsoluteUrl('post/view', ['id' => 1, 'title' => 'sample post'], 'https');
$this->assertEquals('https://www.example.com?r=post/view&id=1&title=sample+post', $url);
$manager->hostInfo = 'https://www.example.com';
$url = $manager->createAbsoluteUrl('post/view', ['id' => 1, 'title' => 'sample post'], 'http');
$this->assertEquals('http://www.example.com?r=post/view&id=1&title=sample+post', $url);
}
public function testParseRequest()
......
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