Commit e7b7b89f by Carsten Brandt

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

* 'master' of github.com:yiisoft/yii2: minor doc fix. minor doc improvement. Add echo into docs for link pager Update migration.md. Fix missed quotes handle array in importNamespaces. import namespaces. import namespaces. renamed autoload to classmap. Added autoload command. Rewording Added readme and license files to extensions. fixed the "only" option for FileHelper::findFiles() Added Query::indexBy Improved FileHelper::filterPath() Enhanced file options for FileHelper. Fixed locale command.
parents cee45fdf 4f70506c
...@@ -5,6 +5,7 @@ defined('YII_DEBUG') or define('YII_DEBUG', true); ...@@ -5,6 +5,7 @@ defined('YII_DEBUG') or define('YII_DEBUG', true);
require(__DIR__ . '/../../vendor/yiisoft/yii2/yii/Yii.php'); require(__DIR__ . '/../../vendor/yiisoft/yii2/yii/Yii.php');
require(__DIR__ . '/../../vendor/autoload.php'); require(__DIR__ . '/../../vendor/autoload.php');
Yii::importNamespaces(require(__DIR__ . '/../../vendor/composer/autoload_namespaces.php'));
$config = yii\helpers\ArrayHelper::merge( $config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../config/main.php'), require(__DIR__ . '/../config/main.php'),
......
...@@ -15,6 +15,7 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); ...@@ -15,6 +15,7 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php'); require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php');
require(__DIR__ . '/vendor/autoload.php'); require(__DIR__ . '/vendor/autoload.php');
Yii::importNamespaces(require(__DIR__ . '/vendor/composer/autoload_namespaces.php'));
$config = yii\helpers\ArrayHelper::merge( $config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/console/config/main.php'), require(__DIR__ . '/console/config/main.php'),
......
...@@ -5,6 +5,7 @@ defined('YII_DEBUG') or define('YII_DEBUG', false); ...@@ -5,6 +5,7 @@ defined('YII_DEBUG') or define('YII_DEBUG', false);
require(__DIR__ . '/../../vendor/yiisoft/yii2/yii/Yii.php'); require(__DIR__ . '/../../vendor/yiisoft/yii2/yii/Yii.php');
require(__DIR__ . '/../../vendor/autoload.php'); require(__DIR__ . '/../../vendor/autoload.php');
Yii::importNamespaces(require(__DIR__ . '/../../vendor/composer/autoload_namespaces.php'));
$config = yii\helpers\ArrayHelper::merge( $config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../config/main.php'), require(__DIR__ . '/../config/main.php'),
......
...@@ -15,6 +15,7 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); ...@@ -15,6 +15,7 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php'); require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php');
require(__DIR__ . '/vendor/autoload.php'); require(__DIR__ . '/vendor/autoload.php');
Yii::importNamespaces(require(__DIR__ . '/vendor/composer/autoload_namespaces.php'));
$config = yii\helpers\ArrayHelper::merge( $config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/console/config/main.php'), require(__DIR__ . '/console/config/main.php'),
......
...@@ -10,6 +10,7 @@ defined('YII_ENV') or define('YII_ENV', 'test'); ...@@ -10,6 +10,7 @@ defined('YII_ENV') or define('YII_ENV', 'test');
require_once(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php'); require_once(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php');
require_once(__DIR__ . '/../vendor/autoload.php'); require_once(__DIR__ . '/../vendor/autoload.php');
Yii::importNamespaces(require(__DIR__ . '/../vendor/composer/autoload_namespaces.php'));
$config = require(__DIR__ . '/../config/web-test.php'); $config = require(__DIR__ . '/../config/web-test.php');
......
...@@ -6,6 +6,7 @@ defined('YII_ENV') or define('YII_ENV', 'dev'); ...@@ -6,6 +6,7 @@ defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php'); require(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php');
require(__DIR__ . '/../vendor/autoload.php'); require(__DIR__ . '/../vendor/autoload.php');
Yii::importNamespaces(require(__DIR__ . '/../vendor/composer/autoload_namespaces.php'));
$config = require(__DIR__ . '/../config/web.php'); $config = require(__DIR__ . '/../config/web.php');
......
...@@ -15,6 +15,7 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); ...@@ -15,6 +15,7 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php'); require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php');
require(__DIR__ . '/vendor/autoload.php'); require(__DIR__ . '/vendor/autoload.php');
Yii::importNamespaces(require(__DIR__ . '/vendor/composer/autoload_namespaces.php'));
$config = require(__DIR__ . '/config/console.php'); $config = require(__DIR__ . '/config/console.php');
......
...@@ -13,8 +13,9 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); ...@@ -13,8 +13,9 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
require(__DIR__ . '/../framework/yii/Yii.php'); require(__DIR__ . '/../framework/yii/Yii.php');
$id = 'yii-build'; $application = new yii\console\Application(array(
$basePath = __DIR__; 'id' => 'yii-build',
'basePath' => __DIR__,
$application = new yii\console\Application(array('id' => $id, 'basePath' => $basePath)); 'controllerNamespace' => 'yii\build\controllers',
));
$application->run(); $application->run();
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\build\controllers;
use yii\console\Controller;
use yii\helpers\FileHelper;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class ClassmapController extends Controller
{
public $defaultAction = 'create';
/**
* Creates a class map for the core Yii classes.
* @param string $root the root path of Yii framework. Defaults to YII_PATH.
* @param string $mapFile the file to contain the class map. Defaults to YII_PATH . '/classes.php'.
*/
public function actionCreate($root = null, $mapFile = null)
{
if ($root === null) {
$root = YII_PATH;
}
$root = FileHelper::normalizePath($root);
if ($mapFile === null) {
$mapFile = YII_PATH . '/classes.php';
}
$options = array(
'filter' => function($path) {
if (is_file($path)) {
$file = basename($path);
if ($file[0] < 'A' || $file[0] > 'Z') {
return false;
}
}
return null;
},
'only' => array('.php'),
'except' => array(
'Yii.php',
'YiiBase.php',
'/debug/',
'/console/',
'/test/',
),
);
$files = FileHelper::findFiles($root, $options);
$map = array();
foreach ($files as $file) {
if (($pos = strpos($file, $root)) !== 0) {
die("Something wrong: $file");
}
$path = str_replace('\\', '/', substr($file, strlen($root)));
$map[] = "\t'yii" . substr(str_replace('/', '\\', $path), 0, -4) . "' => YII_PATH . '$path',";
}
$map = implode("\n", $map);
$output = <<<EOD
<?php
/**
* Yii core class map.
*
* This file is automatically generated by the "build classmap" command under the "build" folder.
* Do not modify it directly.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
return array(
$map
);
EOD;
if (is_file($mapFile) && file_get_contents($mapFile) === $output) {
echo "Nothing changed.";
} else {
file_put_contents($mapFile, $output);
echo "Class map saved in $mapFile";
}
}
}
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace app\controllers; namespace yii\build\controllers;
use yii\console\Exception;
use yii\console\Controller; use yii\console\Controller;
use yii\helpers\FileHelper;
/** /**
* http://www.unicode.org/cldr/charts/supplemental/language_plural_rules.html * http://www.unicode.org/cldr/charts/supplemental/language_plural_rules.html
......
...@@ -3,7 +3,7 @@ Active Record ...@@ -3,7 +3,7 @@ Active Record
ActiveRecord implements the [Active Record design pattern](http://en.wikipedia.org/wiki/Active_record). ActiveRecord implements the [Active Record design pattern](http://en.wikipedia.org/wiki/Active_record).
The idea is that an ActiveRecord object is associated with a row in a database table so object properties are mapped The idea is that an ActiveRecord object is associated with a row in a database table so object properties are mapped
to colums of the corresponding database row. For example, a `Customer` object is associated with a row in the to columns of the corresponding database row. For example, a `Customer` object is associated with a row in the
`tbl_customer` table. `tbl_customer` table.
Instead of writing raw SQL statements to access the data in the table, you can call intuitive methods available in the Instead of writing raw SQL statements to access the data in the table, you can call intuitive methods available in the
...@@ -21,7 +21,7 @@ Declaring ActiveRecord Classes ...@@ -21,7 +21,7 @@ Declaring ActiveRecord Classes
------------------------------ ------------------------------
To declare an ActiveRecord class you need to extend [[\yii\db\ActiveRecord]] and To declare an ActiveRecord class you need to extend [[\yii\db\ActiveRecord]] and
implement `tableName` method like the following: implement the `tableName` method like the following:
```php ```php
class Customer extends \yii\db\ActiveRecord class Customer extends \yii\db\ActiveRecord
...@@ -39,10 +39,10 @@ class Customer extends \yii\db\ActiveRecord ...@@ -39,10 +39,10 @@ class Customer extends \yii\db\ActiveRecord
Connecting to Database Connecting to Database
---------------------- ----------------------
ActiveRecord relies on a [[Connection|DB connection]]. By default, it assumes that ActiveRecord relies on a [[Connection|DB connection]] to perform the underlying DB operations.
there is an application component named `db` that gives the needed [[Connection]] By default, it assumes that there is an application component named `db` which gives the needed
instance which serves as the DB connection. Usually this component is configured [[Connection]] instance. Usually this component is configured via application configuration
via application configuration like the following: like the following:
```php ```php
return array( return array(
...@@ -52,26 +52,27 @@ return array( ...@@ -52,26 +52,27 @@ return array(
'dsn' => 'mysql:host=localhost;dbname=testdb', 'dsn' => 'mysql:host=localhost;dbname=testdb',
'username' => 'demo', 'username' => 'demo',
'password' => 'demo', 'password' => 'demo',
// turn on schema caching to improve performance // turn on schema caching to improve performance in production mode
// 'schemaCacheDuration' => 3600, // 'schemaCacheDuration' => 3600,
), ),
), ),
); );
``` ```
Check [Database basics](database-basics.md) section in order to learn more on how to configure and use database Please read the [Database basics](database-basics.md) section to learn more on how to configure
connections. and use database connections.
Getting Data from Database Getting Data from Database
-------------------------- --------------------------
There are two ActiveRecord methods for getting data: There are two ActiveRecord methods for getting data from database:
- [[find()]] - [[find()]]
- [[findBySql()]] - [[findBySql()]]
They both return an [[ActiveQuery]] instance. Coupled with the various customization and query methods They both return an [[ActiveQuery]] instance. Coupled with various query methods provided
provided by [[ActiveQuery]], ActiveRecord supports very flexible and powerful data retrieval approaches. by [[ActiveQuery]], ActiveRecord supports very flexible and powerful data retrieval approaches.
The followings are some examples, The followings are some examples,
...@@ -83,13 +84,13 @@ $customers = Customer::find() ...@@ -83,13 +84,13 @@ $customers = Customer::find()
->all(); ->all();
// to return a single customer whose ID is 1: // to return a single customer whose ID is 1:
$customer = Customer::find(1);
// the above code is equivalent to the following:
$customer = Customer::find() $customer = Customer::find()
->where(array('id' => 1)) ->where(array('id' => 1))
->one(); ->one();
// or use the following shortcut approach:
$customer = Customer::find(1);
// to retrieve customers using a raw SQL statement: // to retrieve customers using a raw SQL statement:
$sql = 'SELECT * FROM tbl_customer'; $sql = 'SELECT * FROM tbl_customer';
$customers = Customer::findBySql($sql)->all(); $customers = Customer::findBySql($sql)->all();
...@@ -132,10 +133,10 @@ $values = $customer->attributes; ...@@ -132,10 +133,10 @@ $values = $customer->attributes;
``` ```
Persisting Data to Database Saving Data to Database
--------------------------- -----------------------
ActiveRecord provides the following methods to insert, update and delete data: ActiveRecord provides the following methods to insert, update and delete data in the database:
- [[save()]] - [[save()]]
- [[insert()]] - [[insert()]]
...@@ -206,9 +207,9 @@ a one-many relationship. For example, a customer has many orders. And the [[hasO ...@@ -206,9 +207,9 @@ a one-many relationship. For example, a customer has many orders. And the [[hasO
method declares a many-one or one-one relationship. For example, an order has one customer. method declares a many-one or one-one relationship. For example, an order has one customer.
Both methods take two parameters: Both methods take two parameters:
- `$class`: the name of the class related models should use. If specified without - `$class`: the name of the class of the related model(s). If specified without
a namespace, the namespace will be taken from the declaring class. a namespace, the namespace of the related model class will be taken from the declaring class.
- `$link`: the association between columns from two tables. This should be given as an array. - `$link`: the association between columns from the two tables. This should be given as an array.
The keys of the array are the names of the columns from the table associated with `$class`, The keys of the array are the names of the columns from the table associated with `$class`,
while the values of the array are the names of the columns from the declaring class. while the values of the array are the names of the columns from the declaring class.
It is a good practice to define relationships based on table foreign keys. It is a good practice to define relationships based on table foreign keys.
...@@ -262,8 +263,8 @@ class Order extends \yii\db\ActiveRecord ...@@ -262,8 +263,8 @@ class Order extends \yii\db\ActiveRecord
``` ```
[[ActiveRelation::via()]] method is similar to [[ActiveRelation::viaTable()]] except that [[ActiveRelation::via()]] method is similar to [[ActiveRelation::viaTable()]] except that
the first parameter of [[ActiveRelation::via()]] takes a relation name declared in the ActiveRecord class. the first parameter of [[ActiveRelation::via()]] takes a relation name declared in the ActiveRecord class
For example, the above `items` relation can be equivalently declared as follows: instead of the pivot table name. For example, the above `items` relation can be equivalently declared as follows:
```php ```php
class Order extends \yii\db\ActiveRecord class Order extends \yii\db\ActiveRecord
...@@ -314,7 +315,7 @@ How many SQL queries will be performed in the above code, assuming there are mor ...@@ -314,7 +315,7 @@ How many SQL queries will be performed in the above code, assuming there are mor
the database? 101! The first SQL query brings back 100 customers. Then for each customer, a SQL query the database? 101! The first SQL query brings back 100 customers. Then for each customer, a SQL query
is performed to bring back the customer's orders. is performed to bring back the customer's orders.
To solve the above performance problem, you can use the so-called *eager loading* by calling [[ActiveQuery::with()]]: To solve the above performance problem, you can use the so-called *eager loading* approach by calling [[ActiveQuery::with()]]:
```php ```php
// SQL executed: SELECT * FROM tbl_customer LIMIT 100 // SQL executed: SELECT * FROM tbl_customer LIMIT 100
...@@ -472,7 +473,7 @@ TODO: FIXME: WIP, TBD, https://github.com/yiisoft/yii2/issues/226 ...@@ -472,7 +473,7 @@ TODO: FIXME: WIP, TBD, https://github.com/yiisoft/yii2/issues/226
Imagine situation where you have to save something related to the main model in [[beforeSave()]], Imagine situation where you have to save something related to the main model in [[beforeSave()]],
[[afterSave()]], [[beforeDelete()]] and/or [[afterDelete()]] life cycle methods. Developer may come [[afterSave()]], [[beforeDelete()]] and/or [[afterDelete()]] life cycle methods. Developer may come
to solution of overriding ActiveRecord [[save()]] method with database transaction wrapping or to the solution of overriding ActiveRecord [[save()]] method with database transaction wrapping or
even using transaction in controller action, which is strictly speaking doesn't seems to be a good even using transaction in controller action, which is strictly speaking doesn't seems to be a good
practice (recall skinny-controller fat-model fundamental rule). practice (recall skinny-controller fat-model fundamental rule).
......
...@@ -82,7 +82,7 @@ class m101129_185401_create_news_table extends \yii\db\Migration ...@@ -82,7 +82,7 @@ class m101129_185401_create_news_table extends \yii\db\Migration
{ {
public function up() public function up()
{ {
$this->db->createCommand()->createTable('tbl_news, array( $this->db->createCommand()->createTable('tbl_news', array(
'id' => 'pk', 'id' => 'pk',
'title' => 'string(128) NOT NULL', 'title' => 'string(128) NOT NULL',
'content' => 'text', 'content' => 'text',
...@@ -128,7 +128,7 @@ class m101129_185401_create_news_table extends \yii\db\Migration ...@@ -128,7 +128,7 @@ class m101129_185401_create_news_table extends \yii\db\Migration
$transaction=$this->getDbConnection()->beginTransaction(); $transaction=$this->getDbConnection()->beginTransaction();
try try
{ {
$this->db->createCommand()->createTable('tbl_news, array( $this->db->createCommand()->createTable('tbl_news', array(
'id' => 'pk', 'id' => 'pk',
'title' => 'string NOT NULL', 'title' => 'string NOT NULL',
'content' => 'text', 'content' => 'text',
......
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.
Yii 2.0 Public Preview - Composer Installer
======================
Thank you for choosing Yii - a high-performance component-based PHP framework.
If you are looking for a production-ready PHP framework, please use
[Yii v1.1](https://github.com/yiisoft/yii).
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.**
[![Build Status](https://secure.travis-ci.org/yiisoft/yii2.png)](http://travis-ci.org/yiisoft/yii2)
This is the yii2 composer installer.
Installation
----------------
This extension offers you enhanced composer handling for your yii2-project. It will therefor require you to use composer.
`
php composer.phar require yiisoft/yii2-composer *
`
*Note: You might have to run `php composer.phar selfupdate` before using this extension.*
Usage & Documentation
-----------
This extensions allows you to hook to certain composer events and prepare your yii2-app for usage.
After the package is installed, the composer.json file has to be modified to enable this extension.
To see it in action take a look at the example apps in the repository:
[Basic](https://github.com/suralc/yii2/blob/master/apps/basic/composer.json#L27)
[Advanced](https://github.com/suralc/yii2/blob/extensions-readme/apps/advanced/composer.json)
However it might be useful to read through the official composer [documentation](http://getcomposer.org/doc/articles/scripts.md) to understand what this extension can to for you and what it can't.
You can also use this as an template to create your own composer additions to ease development and deployment of your app.
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.
Yii 2.0 Public Preview - JUI Extension
======================
Thank you for choosing Yii - a high-performance component-based PHP framework.
If you are looking for a production-ready PHP framework, please use
[Yii v1.1](https://github.com/yiisoft/yii).
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.**
[![Build Status](https://secure.travis-ci.org/yiisoft/yii2.png)](http://travis-ci.org/yiisoft/yii2)
This is the yii2-jui extension.
Installation
----------------
The preferred way to install this extension is [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require yiisoft/yii2-jui*
```
or add
```
"yiisoft/yii2-jui": "*"
```
to the require section of your composer.json.
*Note: You might have to run `php composer.phar selfupdate`*
Usage & Documentation
-----------
This extension provides multiple widgets to work with jquery.ui, as well as a set of compatible jquery.ui files.
You can use these widgets in your view files after you have registered the corresponding assets.
Example:
-----------
```php
echo ProgressBar::widget(array(
'clientOptions' => array(
'value' => 75,
),
));
For further instructions refer to the guide (once it is finished)
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.
Yii 2.0 Public Preview - Mutex Extension
======================
Thank you for choosing Yii - a high-performance component-based PHP framework.
If you are looking for a production-ready PHP framework, please use
[Yii v1.1](https://github.com/yiisoft/yii).
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.**
[![Build Status](https://secure.travis-ci.org/yiisoft/yii2.png)](http://travis-ci.org/yiisoft/yii2)
This is the yii2-mutex extension.
Installation
----------------
The prefered way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require yiisoft/yii2-mutex *
```
or add
```
"yiisoft/yii2-mutex": "*"
```
to the require section of your composer.json.
*Note: You might have to run `php composer.phar selfupdate`*
Usage & Documentation
-----------
This component can be used to perform actions similar to the concept of [mutual exclusion](http://en.wikipedia.org/wiki/Mutual_exclusion).
For concrete examples and advanced usage refer to the guide.
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.
Yii 2.0 Public Preview - Smarty View Renderer
======================
Thank you for choosing Yii - a high-performance component-based PHP framework.
If you are looking for a production-ready PHP framework, please use
[Yii v1.1](https://github.com/yiisoft/yii).
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.**
[![Build Status](https://secure.travis-ci.org/yiisoft/yii2.png)](http://travis-ci.org/yiisoft/yii2)
This is the yii2-smarty extension.
Installation
----------------
The prefered way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require yiisoft/yii2-smarty *
```
or add
```json
"yiisoft/yii2-smarty": "*"
```
to the require section of your composer.json.
*Note: You might have to run `php composer.phar selfupdate`*
Usage & Documentation
-----------
This extension has to be registered prior to usage.
To enable this view renderer add it to the $rendereres property of your view object.
Example:
```php
<?php
// config.php
return array(
//....
'components' => array(
'view' => array(
'class' => 'yii\base\View',
'viewRenderers' => array(
'tpl' => array(
'class' => 'yii\smarty\ViewRenderer',
//'cachePath' => '@runtime/Smarty/cache',
),
),
),
),
);
```
For further instructions refer to the related section in the guide.
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.
Yii 2.0 Public Preview - Twig View Renderer
======================
Thank you for choosing Yii - a high-performance component-based PHP framework.
If you are looking for a production-ready PHP framework, please use
[Yii v1.1](https://github.com/yiisoft/yii).
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.**
[![Build Status](https://secure.travis-ci.org/yiisoft/yii2.png)](http://travis-ci.org/yiisoft/yii2)
This is the yii2-twig extension.
Installation
----------------
The prefered way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require yiisoft/yii2-twig *
```
or add
```
"yiisoft/yii2-twig": "*"
```
to the require section of your composer.json.
*Note: You might have to run `php composer.phar selfupdate`*
Usage & Documentation
-----------
This extension has to be registered prior to usage.
To enable this view renderer add it to the $rendereres property of your view object.
Example:
```php
<?php
// config.php
return array(
//....
'components' => array(
'view' => array(
'class' => 'yii\base\View',
'viewRenderers' => array(
'twig' => array(
'class' => 'yii\twig\ViewRenderer',
//'cachePath' => '@runtime/Twig/cache',
//'options' => array(), /* Array of twig options */
),
),
),
),
);
```
For further instructions refer to the related section in the guide.
...@@ -93,7 +93,6 @@ class YiiBase ...@@ -93,7 +93,6 @@ class YiiBase
public static $objectConfig = array(); public static $objectConfig = array();
private static $_imported = array(); // alias => class name or directory private static $_imported = array(); // alias => class name or directory
private static $_logger;
/** /**
* @return string the version of Yii framework * @return string the version of Yii framework
...@@ -156,6 +155,9 @@ class YiiBase ...@@ -156,6 +155,9 @@ class YiiBase
foreach ($namespaces as $name => $path) { foreach ($namespaces as $name => $path) {
if ($name !== '') { if ($name !== '') {
$name = trim(strtr($name, array('\\' => '/', '_' => '/')), '/'); $name = trim(strtr($name, array('\\' => '/', '_' => '/')), '/');
if (is_array($path)) {
$path = reset($path);
}
static::setAlias('@' . $name, rtrim($path, '/\\') . '/' . $name); static::setAlias('@' . $name, rtrim($path, '/\\') . '/' . $name);
} }
} }
......
...@@ -48,7 +48,7 @@ use yii\base\Object; ...@@ -48,7 +48,7 @@ use yii\base\Object;
* } * }
* *
* // display pagination * // display pagination
* LinkPager::widget(array( * echo LinkPager::widget(array(
* 'pagination' => $pages, * 'pagination' => $pages,
* )); * ));
* ~~~ * ~~~
......
...@@ -130,6 +130,13 @@ class Query extends Component ...@@ -130,6 +130,13 @@ class Query extends Component
* For example, `array(':name' => 'Dan', ':age' => 31)`. * For example, `array(':name' => 'Dan', ':age' => 31)`.
*/ */
public $params; public $params;
/**
* @var string|callable $column the name of the column by which the query results should be indexed by.
* This can also be a callable (e.g. anonymous function) that returns the index value based on the given
* row data. For more details, see [[indexBy()]]. This property is only used by [[all()]].
*/
public $indexBy;
/** /**
* Creates a DB command that can be used to execute this query. * Creates a DB command that can be used to execute this query.
...@@ -147,6 +154,27 @@ class Query extends Component ...@@ -147,6 +154,27 @@ class Query extends Component
} }
/** /**
* Sets the [[indexBy]] property.
* @param string|callable $column the name of the column by which the query results should be indexed by.
* This can also be a callable (e.g. anonymous function) that returns the index value based on the given
* row data. The signature of the callable should be:
*
* ~~~
* function ($row)
* {
* // return the index value corresponding to $row
* }
* ~~~
*
* @return Query the query object itself
*/
public function indexBy($column)
{
$this->indexBy = $column;
return $this;
}
/**
* Executes the query and returns all results as an array. * Executes the query and returns all results as an array.
* @param Connection $db the database connection used to generate the SQL statement. * @param Connection $db the database connection used to generate the SQL statement.
* If this parameter is not given, the `db` application component will be used. * If this parameter is not given, the `db` application component will be used.
...@@ -154,7 +182,20 @@ class Query extends Component ...@@ -154,7 +182,20 @@ class Query extends Component
*/ */
public function all($db = null) public function all($db = null)
{ {
return $this->createCommand($db)->queryAll(); $rows = $this->createCommand($db)->queryAll();
if ($this->indexBy === null) {
return $rows;
}
$result = array();
foreach ($rows as $row) {
if (is_string($this->indexBy)) {
$key = $row[$this->indexBy];
} else {
$key = call_user_func($this->indexBy, $row);
}
$result[$key] = $row;
}
return $result;
} }
/** /**
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
namespace yii\helpers\base; namespace yii\helpers\base;
use Yii; use Yii;
use yii\helpers\StringHelper as StringHelper2;
/** /**
* Filesystem helper * Filesystem helper
...@@ -133,16 +134,25 @@ class FileHelper ...@@ -133,16 +134,25 @@ class FileHelper
* *
* - dirMode: integer, the permission to be set for newly copied directories. Defaults to 0777. * - dirMode: integer, the permission to be set for newly copied directories. Defaults to 0777.
* - fileMode: integer, the permission to be set for newly copied files. Defaults to the current environment setting. * - fileMode: integer, the permission to be set for newly copied files. Defaults to the current environment setting.
* - filter: callback, a PHP callback that is called for each sub-directory or file. * - filter: callback, a PHP callback that is called for each directory or file.
* If the callback returns false, then the sub-directory or file will not be copied. * The signature of the callback should be: `function ($path)`, where `$path` refers the full path to be filtered.
* The signature of the callback should be: `function ($path)`, where `$path` refers the full path to be copied. * The callback can return one of the following values:
* - only: array, list of patterns that the files or directories should match if they want to be copied. *
* A path matches a pattern if it contains the pattern string at its end. For example, * * true: the directory or file will be copied (the "only" and "except" options will be ignored)
* '/a/b' will match all files and directories ending with '/a/b'; and the '.svn' will match all files and * * false: the directory or file will NOT be copied (the "only" and "except" options will be ignored)
* directories whose name ends with '.svn'. Note, the '/' characters in a pattern matches both '/' and '\'. * * null: the "only" and "except" options will determine whether the directory or file should be copied
* If a file/directory matches a pattern in both "only" and "except", it will NOT be copied. *
* - except: array, list of patterns that the files or directories should NOT match if they want to be copied. * - only: array, list of patterns that the file paths should match if they want to be copied.
* For more details on how to specify the patterns, please refer to the "only" option. * A path matches a pattern if it contains the pattern string at its end.
* For example, '.php' matches all file paths ending with '.php'.
* Note, the '/' characters in a pattern matches both '/' and '\' in the paths.
* If a file path matches a pattern in both "only" and "except", it will NOT be copied.
* - except: array, list of patterns that the files or directories should match if they want to be excluded from being copied.
* A path matches a pattern if it contains the pattern string at its end.
* Patterns ending with '/' apply to directory paths only, and patterns not ending with '/'
* apply to file paths only. For example, '/a/b' matches all file paths ending with '/a/b';
* and '.svn/' matches directory paths ending with '.svn'. Note, the '/' characters in a pattern matches
* both '/' and '\' in the paths.
* - recursive: boolean, whether the files under the subdirectories should also be copied. Defaults to true. * - recursive: boolean, whether the files under the subdirectories should also be copied. Defaults to true.
* - afterCopy: callback, a PHP callback that is called after each sub-directory or file is successfully copied. * - afterCopy: callback, a PHP callback that is called after each sub-directory or file is successfully copied.
* The signature of the callback should be: `function ($from, $to)`, where `$from` is the sub-directory or * The signature of the callback should be: `function ($from, $to)`, where `$from` is the sub-directory or
...@@ -207,16 +217,25 @@ class FileHelper ...@@ -207,16 +217,25 @@ class FileHelper
* @param string $dir the directory under which the files will be looked for. * @param string $dir the directory under which the files will be looked for.
* @param array $options options for file searching. Valid options are: * @param array $options options for file searching. Valid options are:
* *
* - filter: callback, a PHP callback that is called for each sub-directory or file. * - filter: callback, a PHP callback that is called for each directory or file.
* If the callback returns false, then the sub-directory or file will be excluded from the returning result.
* The signature of the callback should be: `function ($path)`, where `$path` refers the full path to be filtered. * The signature of the callback should be: `function ($path)`, where `$path` refers the full path to be filtered.
* - only: array, list of patterns that the files or directories should match if they want to be returned. * The callback can return one of the following values:
* A path matches a pattern if it contains the pattern string at its end. For example, *
* '/a/b' will match all files and directories ending with '/a/b'; and the '.svn' will match all files and * * true: the directory or file will be returned (the "only" and "except" options will be ignored)
* directories whose name ends with '.svn'. Note, the '/' characters in a pattern matches both '/' and '\'. * * false: the directory or file will NOT be returned (the "only" and "except" options will be ignored)
* If a file/directory matches a pattern in both in "only" and "except", it will NOT be returned. * * null: the "only" and "except" options will determine whether the directory or file should be returned
* - except: array, list of patterns that the files or directories should NOT match if they want to be returned. *
* For more details on how to specify the patterns, please refer to the "only" option. * - only: array, list of patterns that the file paths should match if they want to be returned.
* A path matches a pattern if it contains the pattern string at its end.
* For example, '.php' matches all file paths ending with '.php'.
* Note, the '/' characters in a pattern matches both '/' and '\' in the paths.
* If a file path matches a pattern in both "only" and "except", it will NOT be returned.
* - except: array, list of patterns that the file paths or directory paths should match if they want to be excluded from the result.
* A path matches a pattern if it contains the pattern string at its end.
* Patterns ending with '/' apply to directory paths only, and patterns not ending with '/'
* apply to file paths only. For example, '/a/b' matches all file paths ending with '/a/b';
* and '.svn/' matches directory paths ending with '.svn'. Note, the '/' characters in a pattern matches
* both '/' and '\' in the paths.
* - recursive: boolean, whether the files under the subdirectories should also be looked for. Defaults to true. * - recursive: boolean, whether the files under the subdirectories should also be looked for. Defaults to true.
* @return array files found under the directory. The file list is sorted. * @return array files found under the directory. The file list is sorted.
*/ */
...@@ -250,24 +269,33 @@ class FileHelper ...@@ -250,24 +269,33 @@ class FileHelper
*/ */
public static function filterPath($path, $options) public static function filterPath($path, $options)
{ {
if (isset($options['filter']) && !call_user_func($options['filter'], $path)) { if (isset($options['filter'])) {
return false; $result = call_user_func($options['filter'], $path);
if (is_bool($result)) {
return $result;
}
} }
$path = str_replace('\\', '/', $path); $path = str_replace('\\', '/', $path);
$n = \yii\helpers\StringHelper::strlen($path); if ($isDir = is_dir($path)) {
$path .= '/';
}
$n = StringHelper2::strlen($path);
if (!empty($options['except'])) { if (!empty($options['except'])) {
foreach ($options['except'] as $name) { foreach ($options['except'] as $name) {
if (\yii\helpers\StringHelper::substr($path, -\yii\helpers\StringHelper::strlen($name), $n) === $name) { if (StringHelper2::substr($path, -StringHelper2::strlen($name), $n) === $name) {
return false; return false;
} }
} }
} }
if (!empty($options['only'])) {
if (!$isDir && !empty($options['only'])) {
foreach ($options['only'] as $name) { foreach ($options['only'] as $name) {
if (\yii\helpers\StringHelper::substr($path, -\yii\helpers\StringHelper::strlen($name), $n) !== $name) { if (StringHelper2::substr($path, -StringHelper2::strlen($name), $n) === $name) {
return false; return true;
} }
} }
return false;
} }
return true; return true;
} }
......
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