Commit d812cbc6 by Antonio Ramirez

Merge branch 'master' into bootstrap

* master: (33 commits) Skipped ApcCacheTest expire MS Windows EOLs → UNIX EOLs. Build command path fix. refactored RBAC. Added usage example of Theme. Added default class for theme. Fixes issue #172: Implemented new usage of widgets. code style fix of YiiRequirementChecker.php Renamed yiirequirements.php to requirements.php "YiiRequirementChecker" console view has been reworked to display requirements by blocks and in brief for the successful ones. Changed framework in dir structure to yii requirements.php typo fix. "requirements.php" has been added to "bootstrap" application. Doc comments and error messages for "YiiRequirementChecker" have been adjusted. Doc comments for "YiiRequirementChecker" have been updated. PHP version fallback for "YiiRequirementChecker" has been added. "YiiRequirementChecker::check()" has been updated allowing to accept filename for the requirements. Yii core requirements file has been composed. Check helper methods have been added to "YiiRequirementChecker". Web view for "YiiRequirementChecker" has been created. "YiiRequirementChecker::render()" has been implemented, console view has been created. added newline to end of header and body blocks in View ...
parents 6493f7ab a021fbe5
<?php
/**
* Application requirement checker script.
*
* In order to run this script use the following console command:
* php requirements.php
*
* In order to run this script from the web, you should copy it to the web root.
* If you are using Linux you can create a hard link instead, using the following command:
* ln requirements.php ../requirements.php
*/
// you may need to adjust this path to the correct Yii framework path
$frameworkPath = dirname(__FILE__) . '/../../../yii';
require_once($frameworkPath . '/requirements/YiiRequirementChecker.php');
$requirementsChecker = new YiiRequirementChecker();
/**
* Adjust requirements according to your application specifics.
*/
$requirements = array(
// Database :
array(
'name' => 'PDO extension',
'mandatory' => true,
'condition' => extension_loaded('pdo'),
'by' => 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>',
),
array(
'name' => 'PDO SQLite extension',
'mandatory' => false,
'condition' => extension_loaded('pdo_sqlite'),
'by' => 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>',
'memo' => 'Required for SQLite database.',
),
array(
'name' => 'PDO MySQL extension',
'mandatory' => false,
'condition' => extension_loaded('pdo_mysql'),
'by' => 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>',
'memo' => 'Required for MySQL database.',
),
// Cache :
array(
'name' => 'Memcache extension',
'mandatory' => false,
'condition' => extension_loaded('memcache') || extension_loaded('memcached'),
'by' => '<a href="http://www.yiiframework.com/doc/api/CMemCache">CMemCache</a>',
'memo' => extension_loaded('memcached') ? 'To use memcached set <a href="http://www.yiiframework.com/doc/api/CMemCache#useMemcached-detail">CMemCache::useMemcached</a> to <code>true</code>.' : ''
),
array(
'name' => 'APC extension',
'mandatory' => false,
'condition' => extension_loaded('apc') || extension_loaded('apc'),
'by' => '<a href="http://www.yiiframework.com/doc/api/CApcCache">CApcCache</a>',
),
// Additional PHP extensions :
array(
'name' => 'Mcrypt extension',
'mandatory' => false,
'condition' => extension_loaded('mcrypt'),
'by' => '<a href="http://www.yiiframework.com/doc/api/CSecurityManager">CSecurityManager</a>',
'memo' => 'Required by encrypt and decrypt methods.'
),
// PHP ini :
'phpSafeMode' => array(
'name' => 'PHP safe mode',
'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("safe_mode"),
'by' => 'File uploading and console command execution',
'memo' => '"safe_mode" should be disabled at php.ini',
),
'phpExposePhp' => array(
'name' => 'Expose PHP',
'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("expose_php"),
'by' => 'Security reasons',
'memo' => '"expose_php" should be disabled at php.ini',
),
'phpAllowUrlInclude' => array(
'name' => 'PHP allow url include',
'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("allow_url_include"),
'by' => 'Security reasons',
'memo' => '"allow_url_include" should be disabled at php.ini',
),
'phpSmtp' => array(
'name' => 'PHP mail SMTP',
'mandatory' => false,
'condition' => strlen(ini_get('SMTP'))>0,
'by' => 'Email sending',
'memo' => 'PHP mail SMTP server required',
),
);
$requirementsChecker->checkYii()->check($requirements)->render();
\ No newline at end of file
<?php
use yii\helpers\Html;
use yii\widgets\Menu;
use yii\widgets\Breadcrumbs;
use yii\debug\Toolbar;
/**
* @var $this \yii\base\View
......@@ -25,7 +27,7 @@ $this->registerAssetBundle('app');
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<?php $this->widget(Menu::className(), array(
<?php echo Menu::widget($this, array(
'options' => array('class' => 'nav'),
'items' => array(
array('label' => 'Home', 'url' => array('/site/index')),
......@@ -42,7 +44,7 @@ $this->registerAssetBundle('app');
<!-- /.navbar -->
</div>
<?php $this->widget('yii\widgets\Breadcrumbs', array(
<?php echo Breadcrumbs::widget($this, array(
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : array(),
)); ?>
<?php echo $content; ?>
......@@ -58,7 +60,7 @@ $this->registerAssetBundle('app');
</div>
<?php $this->endBody(); ?>
</div>
<?php $this->widget('yii\debug\Toolbar'); ?>
<?php echo Toolbar::widget($this); ?>
</body>
</html>
<?php $this->endPage(); ?>
......@@ -23,7 +23,7 @@ $this->params['breadcrumbs'][] = $this->title;
If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
</p>
<?php $form = $this->beginWidget(ActiveForm::className(), array(
<?php $form = ActiveForm::begin($this, array(
'options' => array('class' => 'form-horizontal'),
'fieldConfig' => array('inputOptions' => array('class' => 'input-xlarge')),
)); ?>
......@@ -33,14 +33,14 @@ $this->params['breadcrumbs'][] = $this->title;
<?php echo $form->field($model, 'body')->textArea(array('rows' => 6)); ?>
<?php
$field = $form->field($model, 'verifyCode');
echo $field->begin();
echo $field->label();
$this->widget(Captcha::className());
echo Html::activeTextInput($model, 'verifyCode', array('class' => 'input-medium'));
echo $field->error();
echo $field->end();
echo $field->begin()
. $field->label()
. Captcha::widget($this)
. Html::activeTextInput($model, 'verifyCode', array('class' => 'input-medium'))
. $field->error()
. $field->end();
?>
<div class="form-actions">
<?php echo Html::submitButton('Submit', null, null, array('class' => 'btn btn-primary')); ?>
</div>
<?php $this->endWidget(); ?>
<?php ActiveForm::end(); ?>
......@@ -14,11 +14,11 @@ $this->params['breadcrumbs'][] = $this->title;
<p>Please fill out the following fields to login:</p>
<?php $form = $this->beginWidget(ActiveForm::className(), array('options' => array('class' => 'form-horizontal'))); ?>
<?php $form = ActiveForm::begin($this, array('options' => array('class' => 'form-horizontal'))); ?>
<?php echo $form->field($model, 'username')->textInput(); ?>
<?php echo $form->field($model, 'password')->passwordInput(); ?>
<?php echo $form->field($model, 'rememberMe')->checkbox(); ?>
<div class="form-actions">
<?php echo Html::submitButton('Login', null, null, array('class' => 'btn btn-primary')); ?>
</div>
<?php $this->endWidget(); ?>
<?php ActiveForm::end(); ?>
......@@ -11,7 +11,7 @@
// fcgi doesn't have STDIN defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
require(__DIR__ . '/../framework/Yii.php');
require(__DIR__ . '/../yii/Yii.php');
$id = 'yiic-build';
$basePath = __DIR__;
......
......@@ -209,6 +209,26 @@ if (isset($_POST['Post'])) {
```
Widgets
-------
Using a widget is more straightforward in 2.0. You mainly use the `begin()`, `end()` and `widget()`
methods of the `Widget` class. For example,
```php
// $this refers to the View object
// Note that you have to "echo" the result to display it
echo \yii\widgets\Menu::widget($this, array('items' => $items));
// $this refers to the View object
$form = \yii\widgets\ActiveForm::begin($this);
... form inputs here ...
\yii\widgets\ActiveForm::end();
```
Previously in 1.1, you would have to enter the widget class names as strings via the `beginWidget()`,
`endWidget()` and `widget()` methods of `CBaseController`. The approach above gets better IDE support.
Themes
------
......@@ -309,13 +329,13 @@ is a container consisting of a label, an input, and an error message. It is repr
as an `ActiveField` object. Using fields, you can build a form more cleanly than before:
```php
<?php $form = $this->beginWidget('yii\widgets\ActiveForm'); ?>
<?php $form = yii\widgets\ActiveForm::begin(); ?>
<?php echo $form->field($model, 'username')->textInput(); ?>
<?php echo $form->field($model, 'password')->passwordInput(); ?>
<div class="form-actions">
<?php echo Html::submitButton('Login'); ?>
</div>
<?php $this->endWidget(); ?>
<?php yii\widgets\ActiveForm::end(); ?>
```
......
......@@ -19,7 +19,7 @@ DIRECTORY STRUCTURE
bootstrap/ a simple app supporting user login and contact page
build/ internally used build tools
docs/ documentation
framework/ framework source files
yii/ framework source files
tests/ tests of the core framework code
......
......@@ -21,9 +21,18 @@ class ApcCacheTest extends CacheTest
$this->markTestSkipped("APC cli is not enabled. Skipping.");
}
if(!ini_get("apc.enabled") || !ini_get("apc.enable_cli")) {
$this->markTestSkipped("APC is installed but not enabled. Skipping.");
}
if ($this->_cacheInstance === null) {
$this->_cacheInstance = new ApcCache();
}
return $this->_cacheInstance;
}
public function testExpire()
{
$this->markTestSkipped("APC keys are expiring only on the next request.");
}
}
<?php
namespace yii\caching;
/**
* Mock for the time() function for caching classes
* @return int
*/
function time() {
return \yiiunit\framework\caching\CacheTest::$time ?: \time();
}
namespace yiiunit\framework\caching;
use yiiunit\TestCase;
use yii\caching\Cache;
......@@ -9,6 +21,12 @@ use yii\caching\Cache;
abstract class CacheTest extends TestCase
{
/**
* @var int virtual time to be returned by mocked time() function.
* Null means normal time() behavior.
*/
public static $time;
/**
* @return Cache
*/
abstract protected function getCacheInstance();
......@@ -18,19 +36,51 @@ abstract class CacheTest extends TestCase
parent::setUp();
$this->mockApplication();
}
protected function tearDown()
{
static::$time = null;
}
/**
* @return Cache
*/
public function prepare()
{
$cache = $this->getCacheInstance();
$cache->flush();
$cache->set('string_test', 'string_test');
$cache->set('number_test', 42);
$cache->set('array_test', array('array_test' => 'array_test'));
$cache['arrayaccess_test'] = new \stdClass();
return $cache;
}
/**
* default value of cache prefix is application id
*/
public function testKeyPrefix()
{
$cache = $this->getCacheInstance();
$this->assertNotNull(\Yii::$app->id);
$this->assertEquals(\Yii::$app->id, $cache->keyPrefix);
}
public function testSet()
{
$cache = $this->getCacheInstance();
$this->assertTrue($cache->set('string_test', 'string_test'));
$this->assertTrue($cache->set('number_test', 42));
$this->assertTrue($cache->set('array_test', array('array_test' => 'array_test')));
$cache['arrayaccess_test'] = new \stdClass();
}
public function testGet()
{
$cache = $this->getCacheInstance();
$cache = $this->prepare();
$this->assertEquals('string_test', $cache->get('string_test'));
$this->assertEquals(42, $cache->get('number_test'));
......@@ -38,51 +88,83 @@ abstract class CacheTest extends TestCase
$array = $cache->get('array_test');
$this->assertArrayHasKey('array_test', $array);
$this->assertEquals('array_test', $array['array_test']);
}
public function testArrayAccess()
{
$cache = $this->getCacheInstance();
$cache['arrayaccess_test'] = new \stdClass();
$this->assertInstanceOf('stdClass', $cache['arrayaccess_test']);
}
public function testMget()
public function testGetNonExistent()
{
$cache = $this->getCacheInstance();
$this->assertFalse($cache->get('non_existent_key'));
}
public function testStoreSpecialValues()
{
$cache = $this->getCacheInstance();
$this->assertTrue($cache->set('null_value', null));
$this->assertNull($cache->get('null_value'));
$this->assertTrue($cache->set('bool_value', true));
$this->assertTrue($cache->get('bool_value'));
}
public function testMget()
{
$cache = $this->prepare();
$this->assertEquals(array('string_test' => 'string_test', 'number_test' => 42), $cache->mget(array('string_test', 'number_test')));
// ensure that order does not matter
$this->assertEquals(array('number_test' => 42, 'string_test' => 'string_test'), $cache->mget(array('number_test', 'string_test')));
$this->assertEquals(array('number_test' => 42, 'non_existent_key' => null), $cache->mget(array('number_test', 'non_existent_key')));
}
public function testExpire()
{
$cache = $this->getCacheInstance();
$this->assertTrue($cache->set('expire_test', 'expire_test', 2));
sleep(1);
$this->assertEquals('expire_test', $cache->get('expire_test'));
sleep(2);
$this->assertEquals(false, $cache->get('expire_test'));
// wait a bit more than 2 sec to avoid random test failure
usleep(2500000);
$this->assertFalse($cache->get('expire_test'));
}
public function testAdd()
{
$cache = $this->getCacheInstance();
$cache = $this->prepare();
// should not change existing keys
$this->assertFalse($cache->add('number_test', 13));
$this->assertEquals(42, $cache->get('number_test'));
// should store data is it's not there yet
// should store data if it's not there yet
$this->assertFalse($cache->get('add_test'));
$this->assertTrue($cache->add('add_test', 13));
$this->assertEquals(13, $cache->get('add_test'));
}
public function testDelete()
{
$cache = $this->getCacheInstance();
$cache = $this->prepare();
$this->assertNotNull($cache->get('number_test'));
$this->assertTrue($cache->delete('number_test'));
$this->assertEquals(null, $cache->get('number_test'));
$this->assertFalse($cache->get('number_test'));
}
public function testFlush()
{
$cache = $this->getCacheInstance();
$cache = $this->prepare();
$this->assertTrue($cache->flush());
$this->assertEquals(null, $cache->get('add_test'));
$this->assertFalse($cache->get('number_test'));
}
}
<?php
namespace yiiunit\framework\caching;
use yii\caching\DbCache;
use yiiunit\TestCase;
......@@ -70,4 +72,16 @@ class DbCacheTest extends CacheTest
}
return $this->_cacheInstance;
}
public function testExpire()
{
$cache = $this->getCacheInstance();
static::$time = \time();
$this->assertTrue($cache->set('expire_test', 'expire_test', 2));
static::$time++;
$this->assertEquals('expire_test', $cache->get('expire_test'));
static::$time++;
$this->assertFalse($cache->get('expire_test'));
}
}
......@@ -22,4 +22,16 @@ class FileCacheTest extends CacheTest
}
return $this->_cacheInstance;
}
public function testExpire()
{
$cache = $this->getCacheInstance();
static::$time = \time();
$this->assertTrue($cache->set('expire_test', 'expire_test', 2));
static::$time++;
$this->assertEquals('expire_test', $cache->get('expire_test'));
static::$time++;
$this->assertFalse($cache->get('expire_test'));
}
}
......@@ -4,7 +4,7 @@ use yii\caching\MemCache;
use yiiunit\TestCase;
/**
* Class for testing memcache cache backend
* Class for testing memcached cache backend
*/
class MemCachedTest extends CacheTest
{
......
......@@ -57,6 +57,7 @@ abstract class ManagerTestBase extends TestCase
$this->assertTrue($item instanceof Item);
$this->assertTrue($this->auth->hasItemChild('reader', 'readPost'));
$item->name = 'readPost2';
$item->save();
$this->assertNull($this->auth->getItem('readPost'));
$this->assertEquals($this->auth->getItem('readPost2'), $item);
$this->assertFalse($this->auth->hasItemChild('reader', 'readPost'));
......
<?php
require_once(realpath(__DIR__.'/../../../../yii/requirements/YiiRequirementChecker.php'));
use yiiunit\TestCase;
/**
* Test case for [[YiiRequirementChecker]].
* @see YiiRequirementChecker
*/
class YiiRequirementCheckerTest extends TestCase
{
public function testCheck()
{
$requirementsChecker = new YiiRequirementChecker();
$requirements = array(
'requirementPass' => array(
'name' => 'Requirement 1',
'mandatory' => true,
'condition' => true,
'by' => 'Requirement 1',
'memo' => 'Requirement 1',
),
'requirementError' => array(
'name' => 'Requirement 2',
'mandatory' => true,
'condition' => false,
'by' => 'Requirement 2',
'memo' => 'Requirement 2',
),
'requirementWarning' => array(
'name' => 'Requirement 3',
'mandatory' => false,
'condition' => false,
'by' => 'Requirement 3',
'memo' => 'Requirement 3',
),
);
$checkResult = $requirementsChecker->check($requirements)->getResult();
$summary = $checkResult['summary'];
$this->assertEquals(count($requirements), $summary['total'], 'Wrong summary total!');
$this->assertEquals(1, $summary['errors'], 'Wrong summary errors!');
$this->assertEquals(1, $summary['warnings'], 'Wrong summary warnings!');
$checkedRequirements = $checkResult['requirements'];
$requirementsKeys = array_flip(array_keys($requirements));
$this->assertEquals(false, $checkedRequirements[$requirementsKeys['requirementPass']]['error'], 'Passed requirement has an error!');
$this->assertEquals(false, $checkedRequirements[$requirementsKeys['requirementPass']]['warning'], 'Passed requirement has a warning!');
$this->assertEquals(true, $checkedRequirements[$requirementsKeys['requirementError']]['error'], 'Error requirement has no error!');
$this->assertEquals(false, $checkedRequirements[$requirementsKeys['requirementWarning']]['error'], 'Error requirement has an error!');
$this->assertEquals(true, $checkedRequirements[$requirementsKeys['requirementWarning']]['warning'], 'Error requirement has no warning!');
}
/**
* @depends testCheck
*/
public function testCheckEval() {
$requirementsChecker = new YiiRequirementChecker();
$requirements = array(
'requirementPass' => array(
'name' => 'Requirement 1',
'mandatory' => true,
'condition' => 'eval:2>1',
'by' => 'Requirement 1',
'memo' => 'Requirement 1',
),
'requirementError' => array(
'name' => 'Requirement 2',
'mandatory' => true,
'condition' => 'eval:2<1',
'by' => 'Requirement 2',
'memo' => 'Requirement 2',
),
);
$checkResult = $requirementsChecker->check($requirements)->getResult();
$checkedRequirements = $checkResult['requirements'];
$requirementsKeys = array_flip(array_keys($requirements));
$this->assertEquals(false, $checkedRequirements[$requirementsKeys['requirementPass']]['error'], 'Passed requirement has an error!');
$this->assertEquals(false, $checkedRequirements[$requirementsKeys['requirementPass']]['warning'], 'Passed requirement has a warning!');
$this->assertEquals(true, $checkedRequirements[$requirementsKeys['requirementError']]['error'], 'Error requirement has no error!');
}
/**
* @depends testCheck
*/
public function testCheckChained()
{
$requirementsChecker = new YiiRequirementChecker();
$requirements1 = array(
array(
'name' => 'Requirement 1',
'mandatory' => true,
'condition' => true,
'by' => 'Requirement 1',
'memo' => 'Requirement 1',
),
);
$requirements2 = array(
array(
'name' => 'Requirement 2',
'mandatory' => true,
'condition' => true,
'by' => 'Requirement 2',
'memo' => 'Requirement 2',
),
);
$checkResult = $requirementsChecker->check($requirements1)->check($requirements2)->getResult();
$mergedRequirements = array_merge($requirements1, $requirements2);
$this->assertEquals(count($mergedRequirements), $checkResult['summary']['total'], 'Wrong total checks count!');
foreach ($mergedRequirements as $key => $mergedRequirement) {
$this->assertEquals($mergedRequirement['name'], $checkResult['requirements'][$key]['name'], 'Wrong requirements list!');
}
}
public function testCheckPhpExtensionVersion()
{
$requirementsChecker = new YiiRequirementChecker();
$this->assertFalse($requirementsChecker->checkPhpExtensionVersion('some_unexisting_php_extension', '0.1'), 'No fail while checking unexisting extension!');
$this->assertTrue($requirementsChecker->checkPhpExtensionVersion('pdo', '1.0'), 'Unable to check PDO version!');
}
/**
* Data provider for [[testGetByteSize()]].
* @return array
*/
public function dataProviderGetByteSize()
{
return array(
array('456', 456),
array('5K', 5*1024),
array('16KB', 16*1024),
array('4M', 4*1024*1024),
array('14MB', 14*1024*1024),
array('7G', 7*1024*1024*1024),
array('12GB', 12*1024*1024*1024),
);
}
/**
* @dataProvider dataProviderGetByteSize
*
* @param string $verboseValue verbose value.
* @param integer $expectedByteSize expected byte size.
*/
public function testGetByteSize($verboseValue, $expectedByteSize)
{
$requirementsChecker = new YiiRequirementChecker();
$this->assertEquals($expectedByteSize, $requirementsChecker->getByteSize($verboseValue), "Wrong byte size for '{$verboseValue}'!");
}
/**
* Data provider for [[testCompareByteSize()]]
* @return array
*/
public function dataProviderCompareByteSize()
{
return array(
array('2M', '2K', '>', true),
array('2M', '2K', '>=', true),
array('1K', '1024', '==', true),
array('10M', '11M', '<', true),
array('10M', '11M', '<=', true),
);
}
/**
* @depends testGetByteSize
* @dataProvider dataProviderCompareByteSize
*
* @param string $a first value.
* @param string $b second value.
* @param string $compare comparison.
* @param boolean $expectedComparisonResult expected comparison result.
*/
public function testCompareByteSize($a, $b, $compare, $expectedComparisonResult)
{
$requirementsChecker = new YiiRequirementChecker();
$this->assertEquals($expectedComparisonResult, $requirementsChecker->compareByteSize($a, $b, $compare), "Wrong compare '{$a}{$compare}{$b}'");
}
}
......@@ -25,7 +25,22 @@ use yii\helpers\FileHelper;
* then the themed version for a view file `/www/views/site/index.php` will be
* `/www/themes/basic/site/index.php`.
*
* @property string $baseUrl the base URL for this theme. This is mainly used by [[getUrl()]].
* To use a theme, you should configure the [[View::theme|theme]] property of the "view" application
* component like the following:
*
* ~~~
* 'view' => array(
* 'theme' => array(
* 'basePath' => '@wwwroot/themes/basic',
* 'baseUrl' => '@www/themes/basic',
* ),
* ),
* ~~~
*
* The above configuration specifies a theme located under the "themes/basic" directory of the Web folder
* that contains the entry script of the application. If your theme is designed to handle modules,
* you may configure the [[pathMap]] property like described above.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
......
......@@ -11,6 +11,9 @@ use Yii;
use yii\base\Application;
use yii\helpers\FileHelper;
use yii\helpers\Html;
use yii\widgets\Block;
use yii\widgets\ContentDecorator;
use yii\widgets\FragmentCache;
/**
* View represents a view object in the MVC pattern.
......@@ -108,12 +111,6 @@ class View extends Component
*/
public $blocks;
/**
* @var Widget[] the widgets that are currently being rendered (not ended). This property
* is maintained by [[beginWidget()]] and [[endWidget()]] methods. Do not modify it directly.
* @internal
*/
public $widgetStack = array();
/**
* @var array a list of currently active fragment cache widgets. This property
* is used internally to implement the content caching feature. Do not modify it directly.
* @internal
......@@ -174,6 +171,9 @@ class View extends Component
{
parent::init();
if (is_array($this->theme)) {
if (!isset($this->theme['class'])) {
$this->theme['class'] = 'yii\base\Theme';
}
$this->theme = Yii::createObject($this->theme);
}
}
......@@ -364,91 +364,16 @@ class View extends Component
}
/**
* Creates a widget.
* This method will use [[Yii::createObject()]] to create the widget.
* @param string $class the widget class name or path alias
* @param array $properties the initial property values of the widget.
* @return Widget the newly created widget instance
*/
public function createWidget($class, $properties = array())
{
$properties['class'] = $class;
if (!isset($properties['view'])) {
$properties['view'] = $this;
}
return Yii::createObject($properties);
}
/**
* Creates and runs a widget.
* Compared with [[createWidget()]], this method does one more thing: it will
* run the widget after it is created.
* @param string $class the widget class name or path alias
* @param array $properties the initial property values of the widget.
* @param boolean $captureOutput whether to capture the output of the widget and return it as a string
* @return string|Widget if $captureOutput is true, the output of the widget will be returned;
* otherwise the widget object will be returned.
*/
public function widget($class, $properties = array(), $captureOutput = false)
{
if ($captureOutput) {
ob_start();
ob_implicit_flush(false);
$widget = $this->createWidget($class, $properties);
$widget->run();
return ob_get_clean();
} else {
$widget = $this->createWidget($class, $properties);
$widget->run();
return $widget;
}
}
/**
* Begins a widget.
* This method is similar to [[createWidget()]] except that it will expect a matching
* [[endWidget()]] call after this.
* @param string $class the widget class name or path alias
* @param array $properties the initial property values of the widget.
* @return Widget the widget instance
*/
public function beginWidget($class, $properties = array())
{
$widget = $this->createWidget($class, $properties);
$this->widgetStack[] = $widget;
return $widget;
}
/**
* Ends a widget.
* Note that the rendering result of the widget is directly echoed out.
* If you want to capture the rendering result of a widget, you may use
* [[createWidget()]] and [[Widget::run()]].
* @return Widget the widget instance
* @throws InvalidCallException if [[beginWidget()]] and [[endWidget()]] calls are not properly nested
*/
public function endWidget()
{
$widget = array_pop($this->widgetStack);
if ($widget instanceof Widget) {
$widget->run();
return $widget;
} else {
throw new InvalidCallException("Unmatched beginWidget() and endWidget() calls.");
}
}
/**
* Begins recording a block.
* This method is a shortcut to beginning [[yii\widgets\Block]]
* This method is a shortcut to beginning [[Block]]
* @param string $id the block ID.
* @param boolean $renderInPlace whether to render the block content in place.
* Defaults to false, meaning the captured block will not be displayed.
* @return \yii\widgets\Block the Block widget instance
* @return Block the Block widget instance
*/
public function beginBlock($id, $renderInPlace = false)
{
return $this->beginWidget('yii\widgets\Block', array(
return Block::begin($this, array(
'id' => $id,
'renderInPlace' => $renderInPlace,
));
......@@ -459,7 +384,7 @@ class View extends Component
*/
public function endBlock()
{
$this->endWidget();
Block::end();
}
/**
......@@ -476,12 +401,12 @@ class View extends Component
* @param string $viewFile the view file that will be used to decorate the content enclosed by this widget.
* This can be specified as either the view file path or path alias.
* @param array $params the variables (name => value) to be extracted and made available in the decorative view.
* @return \yii\widgets\ContentDecorator the ContentDecorator widget instance
* @see \yii\widgets\ContentDecorator
* @return ContentDecorator the ContentDecorator widget instance
* @see ContentDecorator
*/
public function beginContent($viewFile, $params = array())
{
return $this->beginWidget('yii\widgets\ContentDecorator', array(
return ContentDecorator::begin($this, array(
'viewFile' => $viewFile,
'params' => $params,
));
......@@ -492,7 +417,7 @@ class View extends Component
*/
public function endContent()
{
$this->endWidget();
ContentDecorator::end();
}
/**
......@@ -510,15 +435,15 @@ class View extends Component
* ~~~
*
* @param string $id a unique ID identifying the fragment to be cached.
* @param array $properties initial property values for [[\yii\widgets\FragmentCache]]
* @param array $properties initial property values for [[FragmentCache]]
* @return boolean whether you should generate the content for caching.
* False if the cached version is available.
*/
public function beginCache($id, $properties = array())
{
$properties['id'] = $id;
/** @var $cache \yii\widgets\FragmentCache */
$cache = $this->beginWidget('yii\widgets\FragmentCache', $properties);
/** @var $cache FragmentCache */
$cache = FragmentCache::begin($this, $properties);
if ($cache->getCachedContent() !== false) {
$this->endCache();
return false;
......@@ -532,7 +457,7 @@ class View extends Component
*/
public function endCache()
{
$this->endWidget();
FragmentCache::end();
}
......@@ -771,7 +696,7 @@ class View extends Component
if (!empty($this->js[self::POS_HEAD])) {
$lines[] = implode("\n", $this->js[self::POS_HEAD]);
}
return implode("\n", $lines);
return empty($lines) ? '' : implode("\n", $lines) . "\n";
}
/**
......@@ -788,7 +713,7 @@ class View extends Component
if (!empty($this->js[self::POS_BEGIN])) {
$lines[] = implode("\n", $this->js[self::POS_BEGIN]);
}
return implode("\n", $lines);
return empty($lines) ? '' : implode("\n", $lines) . "\n";
}
/**
......@@ -805,6 +730,6 @@ class View extends Component
if (!empty($this->js[self::POS_END])) {
$lines[] = implode("\n", $this->js[self::POS_END]);
}
return implode("\n", $lines);
return empty($lines) ? '' : implode("\n", $lines) . "\n";
}
}
......@@ -8,7 +8,6 @@
namespace yii\base;
use Yii;
use yii\helpers\FileHelper;
/**
* Widget is the base class for widgets.
......@@ -19,9 +18,9 @@ use yii\helpers\FileHelper;
class Widget extends Component
{
/**
* @var View the view object that is used to create this widget.
* This property is automatically set by [[View::createWidget()]].
* This property is required by [[render()]] and [[renderFile()]].
* @var View the view object that this widget is associated with.
* The widget will use this view object to register any needed assets.
* This property is also required by [[render()]] and [[renderFile()]].
*/
public $view;
/**
......@@ -29,9 +28,85 @@ class Widget extends Component
*/
private $_id;
/**
* @var integer a counter used to generate IDs for widgets.
* @var integer a counter used to generate [[id]] for widgets.
* @internal
*/
private static $_counter = 0;
public static $_counter = 0;
/**
* @var Widget[] the widgets that are currently being rendered (not ended). This property
* is maintained by [[begin()]] and [[end()]] methods.
* @internal
*/
public static $_stack = array();
/**
* Constructor.
* @param View $view the view object that this widget is associated with.
* The widget will use this view object to register any needed assets.
* It is also required by [[render()]] and [[renderFile()]].
* @param array $config name-value pairs that will be used to initialize the object properties
*/
public function __construct($view, $config = array())
{
$this->view = $view;
parent::__construct($config);
}
/**
* Begins a widget.
* This method creates an instance of the calling class. It will apply the configuration
* to the created instance. A matching [[end()]] call should be called later.
* @param View $view the view object that the newly created widget is associated with.
* @param array $config name-value pairs that will be used to initialize the object properties
* @return Widget the newly created widget instance
*/
public static function begin($view, $config = array())
{
$config['class'] = get_called_class();
/** @var Widget $widget */
$widget = Yii::createObject($config, $view);
self::$_stack[] = $widget;
return $widget;
}
/**
* Ends a widget.
* Note that the rendering result of the widget is directly echoed out.
* @return Widget the widget instance that is ended.
* @throws InvalidCallException if [[begin()]] and [[end()]] calls are not properly nested
*/
public static function end()
{
if (!empty(self::$_stack)) {
$widget = array_pop(self::$_stack);
if (get_class($widget) === get_called_class()) {
$widget->run();
return $widget;
} else {
throw new InvalidCallException("Expecting end() of " . get_class($widget) . ", found " . get_called_class());
}
} else {
throw new InvalidCallException("Unexpected " . get_called_class() . '::end() call. A matching begin() is not found.');
}
}
/**
* Creates a widget instance and runs it.
* The widget rendering result is returned by this method.
* @param View $view the view object that the newly created widget is associated with.
* @param array $config name-value pairs that will be used to initialize the object properties
* @return string the rendering result of the widget.
*/
public static function widget($view, $config = array())
{
ob_start();
ob_implicit_flush(false);
/** @var Widget $widget */
$config['class'] = get_called_class();
$widget = Yii::createObject($config, $view);
$widget->run();
return ob_get_clean();
}
/**
* Returns the ID of the widget.
......
......@@ -24,7 +24,7 @@ class ApcCache extends Cache
* Retrieves a value from cache with a specified key.
* This is the implementation of the method declared in the parent class.
* @param string $key a unique key identifying the cached value
* @return string the value stored in cache, false if the value is not in the cache or expired.
* @return string|boolean the value stored in cache, false if the value is not in the cache or expired.
*/
protected function getValue($key)
{
......
......@@ -247,7 +247,7 @@ abstract class Cache extends Component implements \ArrayAccess
* This method should be implemented by child classes to retrieve the data
* from specific cache storage.
* @param string $key a unique key identifying the cached value
* @return string the value stored in cache, false if the value is not in the cache or expired.
* @return string|boolean the value stored in cache, false if the value is not in the cache or expired.
*/
abstract protected function getValue($key);
......
......@@ -92,7 +92,7 @@ class DbCache extends Cache
* Retrieves a value from cache with a specified key.
* This is the implementation of the method declared in the parent class.
* @param string $key a unique key identifying the cached value
* @return string the value stored in cache, false if the value is not in the cache or expired.
* @return string|boolean the value stored in cache, false if the value is not in the cache or expired.
*/
protected function getValue($key)
{
......
......@@ -24,7 +24,7 @@ class DummyCache extends Cache
* Retrieves a value from cache with a specified key.
* This is the implementation of the method declared in the parent class.
* @param string $key a unique key identifying the cached value
* @return string the value stored in cache, false if the value is not in the cache or expired.
* @return string|boolean the value stored in cache, false if the value is not in the cache or expired.
*/
protected function getValue($key)
{
......
......@@ -61,7 +61,7 @@ class FileCache extends Cache
* Retrieves a value from cache with a specified key.
* This is the implementation of the method declared in the parent class.
* @param string $key a unique key identifying the cached value
* @return string the value stored in cache, false if the value is not in the cache or expired.
* @return string|boolean the value stored in cache, false if the value is not in the cache or expired.
*/
protected function getValue($key)
{
......
......@@ -7,7 +7,6 @@
namespace yii\caching;
use yii\base\Exception;
use yii\base\InvalidConfigException;
/**
......@@ -21,7 +20,7 @@ use yii\base\InvalidConfigException;
* MemCache can be configured with a list of memcache servers by settings its [[servers]] property.
* By default, MemCache assumes there is a memcache server running on localhost at port 11211.
*
* See [[Cache]] for common cache operations that ApcCache supports.
* See [[Cache]] for common cache operations that MemCache supports.
*
* Note, there is no security measure to protected data in memcache.
* All data in memcache can be accessed by any process running in the system.
......@@ -89,7 +88,7 @@ class MemCache extends Cache
if (count($servers)) {
foreach ($servers as $server) {
if ($server->host === null) {
throw new Exception("The 'host' property must be specified for every memcache server.");
throw new InvalidConfigException("The 'host' property must be specified for every memcache server.");
}
if ($this->useMemcached) {
$cache->addServer($server->host, $server->port, $server->weight);
......@@ -145,7 +144,7 @@ class MemCache extends Cache
* Retrieves a value from cache with a specified key.
* This is the implementation of the method declared in the parent class.
* @param string $key a unique key identifying the cached value
* @return string the value stored in cache, false if the value is not in the cache or expired.
* @return string|boolean the value stored in cache, false if the value is not in the cache or expired.
*/
protected function getValue($key)
{
......
......@@ -24,7 +24,7 @@ class WinCache extends Cache
* Retrieves a value from cache with a specified key.
* This is the implementation of the method declared in the parent class.
* @param string $key a unique key identifying the cached value
* @return string the value stored in cache, false if the value is not in the cache or expired.
* @return string|boolean the value stored in cache, false if the value is not in the cache or expired.
*/
protected function getValue($key)
{
......
......@@ -25,7 +25,7 @@ class XCache extends Cache
* Retrieves a value from cache with a specified key.
* This is the implementation of the method declared in the parent class.
* @param string $key a unique key identifying the cached value
* @return string the value stored in cache, false if the value is not in the cache or expired.
* @return string|boolean the value stored in cache, false if the value is not in the cache or expired.
*/
protected function getValue($key)
{
......
......@@ -24,7 +24,7 @@ class ZendDataCache extends Cache
* Retrieves a value from cache with a specified key.
* This is the implementation of the method declared in the parent class.
* @param string $key a unique key identifying the cached value
* @return string the value stored in cache, false if the value is not in the cache or expired.
* @return string|boolean the value stored in cache, false if the value is not in the cache or expired.
*/
protected function getValue($key)
{
......
......@@ -16,91 +16,40 @@ use yii\base\Object;
* Do not create a Assignment instance using the 'new' operator.
* Instead, call [[Manager::assign()]].
*
* @property mixed $userId User ID (see [[User::id]]).
* @property string $itemName The authorization item name.
* @property string $bizRule The business rule associated with this assignment.
* @property mixed $data Additional data for this assignment.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Alexander Kochetov <creocoder@gmail.com>
* @since 2.0
*/
class Assignment extends Object
{
private $_auth;
private $_userId;
private $_itemName;
private $_bizRule;
private $_data;
/**
* Constructor.
* @param Manager $auth the authorization manager
* @param mixed $userId user ID (see [[User::id]])
* @param string $itemName authorization item name
* @param string $bizRule the business rule associated with this assignment
* @param mixed $data additional data for this assignment
* @var Manager the auth manager of this item
*/
public function __construct($auth, $userId, $itemName, $bizRule = null, $data = null)
{
$this->_auth = $auth;
$this->_userId = $userId;
$this->_itemName = $itemName;
$this->_bizRule = $bizRule;
$this->_data = $data;
}
public $manager;
/**
* @return mixed user ID (see [[User::id]])
* @var string the business rule associated with this assignment
*/
public function getUserId()
{
return $this->_userId;
}
public $bizRule;
/**
* @return string the authorization item name
* @var mixed additional data for this assignment
*/
public function getItemName()
{
return $this->_itemName;
}
public $data;
/**
* @return string the business rule associated with this assignment
* @var mixed user ID (see [[User::id]]). Do not modify this property after it is populated.
* To modify the user ID of an assignment, you must remove the assignment and create a new one.
*/
public function getBizRule()
{
return $this->_bizRule;
}
/**
* @param string $value the business rule associated with this assignment
*/
public function setBizRule($value)
{
if ($this->_bizRule !== $value) {
$this->_bizRule = $value;
$this->_auth->saveAssignment($this);
}
}
public $userId;
/**
* @return mixed additional data for this assignment
* @return string the authorization item name. Do not modify this property after it is populated.
* To modify the item name of an assignment, you must remove the assignment and create a new one.
*/
public function getData()
{
return $this->_data;
}
public $itemName;
/**
* @param mixed $value additional data for this assignment
* Saves the changes to an authorization assignment.
*/
public function setData($value)
public function save()
{
if ($this->_data !== $value) {
$this->_data = $value;
$this->_auth->saveAssignment($this);
}
$this->manager->saveAssignment($this);
}
}
......@@ -18,14 +18,6 @@ use yii\base\Object;
* A user may be assigned one or several authorization items (called [[Assignment]] assignments).
* He can perform an operation only when it is among his assigned items.
*
* @property Manager $authManager The authorization manager.
* @property integer $type The authorization item type. This could be 0 (operation), 1 (task) or 2 (role).
* @property string $name The item name.
* @property string $description The item description.
* @property string $bizRule The business rule associated with this item.
* @property mixed $data The additional data associated with this item.
* @property array $children All child items of this item.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Alexander Kochetov <creocoder@gmail.com>
* @since 2.0
......@@ -36,31 +28,30 @@ class Item extends Object
const TYPE_TASK = 1;
const TYPE_ROLE = 2;
private $_auth;
private $_type;
private $_name;
private $_description;
private $_bizRule;
private $_data;
/**
* Constructor.
* @param Manager $auth authorization manager
* @param string $name authorization item name
* @param integer $type authorization item type. This can be 0 (operation), 1 (task) or 2 (role).
* @param string $description the description
* @param string $bizRule the business rule associated with this item
* @param mixed $data additional data for this item
* @var Manager the auth manager of this item
*/
public function __construct($auth, $name, $type, $description = '', $bizRule = null, $data = null)
{
$this->_type = (int)$type;
$this->_auth = $auth;
$this->_name = $name;
$this->_description = $description;
$this->_bizRule = $bizRule;
$this->_data = $data;
}
public $manager;
/**
* @var string the item description
*/
public $description;
/**
* @var string the business rule associated with this item
*/
public $bizRule;
/**
* @var mixed the additional data associated with this item
*/
public $data;
/**
* @var integer the authorization item type. This could be 0 (operation), 1 (task) or 2 (role).
*/
public $type;
private $_name;
private $_oldName;
/**
* Checks to see if the specified item is within the hierarchy starting from this item.
......@@ -73,11 +64,11 @@ class Item extends Object
public function checkAccess($itemName, $params = array())
{
Yii::trace('Checking permission: ' . $this->_name, __METHOD__);
if ($this->_auth->executeBizRule($this->_bizRule, $params, $this->_data)) {
if ($this->manager->executeBizRule($this->bizRule, $params, $this->data)) {
if ($this->_name == $itemName) {
return true;
}
foreach ($this->_auth->getItemChildren($this->_name) as $item) {
foreach ($this->manager->getItemChildren($this->_name) as $item) {
if ($item->checkAccess($itemName, $params)) {
return true;
}
......@@ -87,22 +78,6 @@ class Item extends Object
}
/**
* @return Manager the authorization manager
*/
public function getManager()
{
return $this->_auth;
}
/**
* @return integer the authorization item type. This could be 0 (operation), 1 (task) or 2 (role).
*/
public function getType()
{
return $this->_type;
}
/**
* @return string the item name
*/
public function getName()
......@@ -116,66 +91,8 @@ class Item extends Object
public function setName($value)
{
if ($this->_name !== $value) {
$oldName = $this->_name;
$this->_oldName = $this->_name;
$this->_name = $value;
$this->_auth->saveItem($this, $oldName);
}
}
/**
* @return string the item description
*/
public function getDescription()
{
return $this->_description;
}
/**
* @param string $value the item description
*/
public function setDescription($value)
{
if ($this->_description !== $value) {
$this->_description = $value;
$this->_auth->saveItem($this);
}
}
/**
* @return string the business rule associated with this item
*/
public function getBizRule()
{
return $this->_bizRule;
}
/**
* @param string $value the business rule associated with this item
*/
public function setBizRule($value)
{
if ($this->_bizRule !== $value) {
$this->_bizRule = $value;
$this->_auth->saveItem($this);
}
}
/**
* @return mixed the additional data associated with this item
*/
public function getData()
{
return $this->_data;
}
/**
* @param mixed $value the additional data associated with this item
*/
public function setData($value)
{
if ($this->_data !== $value) {
$this->_data = $value;
$this->_auth->saveItem($this);
}
}
......@@ -188,7 +105,7 @@ class Item extends Object
*/
public function addChild($name)
{
return $this->_auth->addItemChild($this->_name, $name);
return $this->manager->addItemChild($this->_name, $name);
}
/**
......@@ -200,7 +117,7 @@ class Item extends Object
*/
public function removeChild($name)
{
return $this->_auth->removeItemChild($this->_name, $name);
return $this->manager->removeItemChild($this->_name, $name);
}
/**
......@@ -211,7 +128,7 @@ class Item extends Object
*/
public function hasChild($name)
{
return $this->_auth->hasItemChild($this->_name, $name);
return $this->manager->hasItemChild($this->_name, $name);
}
/**
......@@ -221,7 +138,7 @@ class Item extends Object
*/
public function getChildren()
{
return $this->_auth->getItemChildren($this->_name);
return $this->manager->getItemChildren($this->_name);
}
/**
......@@ -236,7 +153,7 @@ class Item extends Object
*/
public function assign($userId, $bizRule = null, $data = null)
{
return $this->_auth->assign($userId, $this->_name, $bizRule, $data);
return $this->manager->assign($userId, $this->_name, $bizRule, $data);
}
/**
......@@ -247,7 +164,7 @@ class Item extends Object
*/
public function revoke($userId)
{
return $this->_auth->revoke($userId, $this->_name);
return $this->manager->revoke($userId, $this->_name);
}
/**
......@@ -258,7 +175,7 @@ class Item extends Object
*/
public function isAssigned($userId)
{
return $this->_auth->isAssigned($userId, $this->_name);
return $this->manager->isAssigned($userId, $this->_name);
}
/**
......@@ -270,6 +187,15 @@ class Item extends Object
*/
public function getAssignment($userId)
{
return $this->_auth->getAssignment($userId, $this->_name);
return $this->manager->getAssignment($userId, $this->_name);
}
/**
* Saves an authorization item to persistent storage.
*/
public function save()
{
$this->manager->saveItem($this, $this->_oldName);
unset($this->_oldName);
}
}
......@@ -161,7 +161,7 @@ abstract class Manager extends Component
{
static $types = array('operation', 'task', 'role');
if ($parentType < $childType) {
throw new InvalidParamException("Cannot add an item of type '$types[$childType]' to an item of type '$types[$parentType]'.");
throw new InvalidParamException("Cannot add an item of type '{$types[$childType]}' to an item of type '{$types[$parentType]}'.");
}
}
......
......@@ -80,14 +80,14 @@ class PhpManager extends Manager
if (!isset($params['userId'])) {
$params['userId'] = $userId;
}
if ($this->executeBizRule($item->getBizRule(), $params, $item->getData())) {
if ($this->executeBizRule($item->bizRule, $params, $item->data)) {
if (in_array($itemName, $this->defaultRoles)) {
return true;
}
if (isset($this->_assignments[$userId][$itemName])) {
/** @var $assignment Assignment */
$assignment = $this->_assignments[$userId][$itemName];
if ($this->executeBizRule($assignment->getBizRule(), $params, $assignment->getData())) {
if ($this->executeBizRule($assignment->bizRule, $params, $assignment->data)) {
return true;
}
}
......@@ -117,7 +117,7 @@ class PhpManager extends Manager
$child = $this->_items[$childName];
/** @var $item Item */
$item = $this->_items[$itemName];
$this->checkItemChildType($item->getType(), $child->getType());
$this->checkItemChildType($item->type, $child->type);
if ($this->detectLoop($itemName, $childName)) {
throw new InvalidCallException("Cannot add '$childName' as a child of '$itemName'. A loop has been detected.");
}
......@@ -194,7 +194,13 @@ class PhpManager extends Manager
} elseif (isset($this->_assignments[$userId][$itemName])) {
throw new InvalidParamException("Authorization item '$itemName' has already been assigned to user '$userId'.");
} else {
return $this->_assignments[$userId][$itemName] = new Assignment($this, $userId, $itemName, $bizRule, $data);
return $this->_assignments[$userId][$itemName] = new Assignment(array(
'manager' => $this,
'userId' => $userId,
'itemName' => $itemName,
'bizRule' => $bizRule,
'data' => $data,
));
}
}
......@@ -265,15 +271,15 @@ class PhpManager extends Manager
if ($userId === null) {
foreach ($this->_items as $name => $item) {
/** @var $item Item */
if ($item->getType() == $type) {
if ($item->type == $type) {
$items[$name] = $item;
}
}
} elseif (isset($this->_assignments[$userId])) {
foreach ($this->_assignments[$userId] as $assignment) {
/** @var $assignment Assignment */
$name = $assignment->getItemName();
if (isset($this->_items[$name]) && ($type === null || $this->_items[$name]->getType() == $type)) {
$name = $assignment->itemName;
if (isset($this->_items[$name]) && ($type === null || $this->_items[$name]->type == $type)) {
$items[$name] = $this->_items[$name];
}
}
......@@ -301,7 +307,14 @@ class PhpManager extends Manager
if (isset($this->_items[$name])) {
throw new Exception('Unable to add an item whose name is the same as an existing item.');
}
return $this->_items[$name] = new Item($this, $name, $type, $description, $bizRule, $data);
return $this->_items[$name] = new Item(array(
'manager' => $this,
'name' => $name,
'type' => $type,
'description' => $description,
'bizRule' => $bizRule,
'data' => $data,
));
}
/**
......@@ -390,10 +403,10 @@ class PhpManager extends Manager
foreach ($this->_items as $name => $item) {
/** @var $item Item */
$items[$name] = array(
'type' => $item->getType(),
'description' => $item->getDescription(),
'bizRule' => $item->getBizRule(),
'data' => $item->getData(),
'type' => $item->type,
'description' => $item->description,
'bizRule' => $item->bizRule,
'data' => $item->data,
);
if (isset($this->_children[$name])) {
foreach ($this->_children[$name] as $child) {
......@@ -408,8 +421,8 @@ class PhpManager extends Manager
/** @var $assignment Assignment */
if (isset($items[$name])) {
$items[$name]['assignments'][$userId] = array(
'bizRule' => $assignment->getBizRule(),
'data' => $assignment->getData(),
'bizRule' => $assignment->bizRule,
'data' => $assignment->data,
);
}
}
......@@ -428,7 +441,14 @@ class PhpManager extends Manager
$items = $this->loadFromFile($this->authFile);
foreach ($items as $name => $item) {
$this->_items[$name] = new Item($this, $name, $item['type'], $item['description'], $item['bizRule'], $item['data']);
$this->_items[$name] = new Item(array(
'manager' => $this,
'name' => $name,
'type' => $item['type'],
'description' => $item['description'],
'bizRule' => $item['bizRule'],
'data' => $item['data'],
));
}
foreach ($items as $name => $item) {
......@@ -441,8 +461,14 @@ class PhpManager extends Manager
}
if (isset($item['assignments'])) {
foreach ($item['assignments'] as $userId => $assignment) {
$this->_assignments[$userId][$name] = new Assignment($this, $name, $userId, $assignment['bizRule'], $assignment['data']);
}
$this->_assignments[$userId][$name] = new Assignment(array(
'manager' => $this,
'userId' => $userId,
'itemName' => $name,
'bizRule' => $assignment['bizRule'],
'data' => $assignment['data'],
));
}
}
}
}
......
......@@ -18,9 +18,10 @@ create table [tbl_auth_item]
[name] varchar(64) not null,
[type] integer not null,
[description] text,
[bizrule] text,
[biz_rule] text,
[data] text,
primary key ([name])
primary key ([name]),
key [type] ([type])
);
create table [tbl_auth_item_child]
......@@ -36,7 +37,7 @@ create table [tbl_auth_assignment]
(
[item_name] varchar(64) not null,
[user_id] varchar(64) not null,
[bizrule] text,
[biz_rule] text,
[data] text,
primary key ([item_name],[user_id]),
foreign key ([item_name]) references [tbl_auth_item] ([name]) on delete cascade on update cascade
......
......@@ -18,9 +18,10 @@ create table `tbl_auth_item`
`name` varchar(64) not null,
`type` integer not null,
`description` text,
`bizrule` text,
`biz_rule` text,
`data` text,
primary key (`name`)
primary key (`name`),
key `type` (`type`)
) engine InnoDB;
create table `tbl_auth_item_child`
......@@ -36,7 +37,7 @@ create table `tbl_auth_assignment`
(
`item_name` varchar(64) not null,
`user_id` varchar(64) not null,
`bizrule` text,
`biz_rule` text,
`data` text,
primary key (`item_name`,`user_id`),
foreign key (`item_name`) references `tbl_auth_item` (`name`) on delete cascade on update cascade
......
......@@ -18,9 +18,10 @@ create table "tbl_auth_item"
"name" varchar(64) not null,
"type" integer not null,
"description" text,
"bizrule" text,
"biz_rule" text,
"data" text,
primary key ("name")
primary key ("name"),
key "type" ("type")
);
create table "tbl_auth_item_child"
......@@ -36,7 +37,7 @@ create table "tbl_auth_assignment"
(
"item_name" varchar(64) not null,
"user_id" varchar(64) not null,
"bizrule" text,
"biz_rule" text,
"data" text,
primary key ("item_name","user_id"),
foreign key ("item_name") references "tbl_auth_item" ("name") on delete cascade on update cascade
......
......@@ -18,9 +18,10 @@ create table "tbl_auth_item"
"name" varchar(64) not null,
"type" integer not null,
"description" text,
"bizrule" text,
"biz_rule" text,
"data" text,
primary key ("name")
primary key ("name"),
key "type" ("type")
);
create table "tbl_auth_item_child"
......@@ -36,7 +37,7 @@ create table "tbl_auth_assignment"
(
"item_name" varchar(64) not null,
"user_id" varchar(64) not null,
"bizrule" text,
"biz_rule" text,
"data" text,
primary key ("item_name","user_id"),
foreign key ("item_name") references "tbl_auth_item" ("name") on delete cascade on update cascade
......
......@@ -18,9 +18,10 @@ create table 'tbl_auth_item'
"name" varchar(64) not null,
"type" integer not null,
"description" text,
"bizrule" text,
"biz_rule" text,
"data" text,
primary key ("name")
primary key ("name"),
key "type" ("type")
);
create table 'tbl_auth_item_child'
......@@ -36,7 +37,7 @@ create table 'tbl_auth_assignment'
(
"item_name" varchar(64) not null,
"user_id" varchar(64) not null,
"bizrule" text,
"biz_rule" text,
"data" text,
primary key ("item_name","user_id"),
foreign key ("item_name") references 'tbl_auth_item' ("name") on delete cascade on update cascade
......
<?php
/**
* This is the Yii core requirements for the [[YiiRequirementChecker]] instance.
* These requirements are mandatory for any Yii application.
*/
return array(
array(
'name' => 'PHP version',
'mandatory' => true,
'condition' => version_compare(PHP_VERSION, '5.3.0', '>='),
'by' => '<a href="http://www.yiiframework.com">Yii Framework</a>',
'memo' => 'PHP 5.3.0 or higher is required.',
),
array(
'name' => 'Reflection extension',
'mandatory' => true,
'condition' => class_exists('Reflection', false),
'by' => '<a href="http://www.yiiframework.com">Yii Framework</a>',
),
array(
'name' => 'PCRE extension',
'mandatory' => true,
'condition' => extension_loaded('pcre'),
'by' => '<a href="http://www.yiiframework.com">Yii Framework</a>',
),
array(
'name' => 'SPL extension',
'mandatory' => true,
'condition' => extension_loaded('SPL'),
'by' => '<a href="http://www.yiiframework.com">Yii Framework</a>',
),
array(
'name' => 'MBString extension',
'mandatory' => true,
'condition' => extension_loaded('mbstring'),
'by' => '<a href="http://www.php.net/manual/en/book.mbstring.php">Multibyte string</a> processing',
'memo' => 'Required for multibyte encoding string processing.'
),
);
\ No newline at end of file
<?php
/* @var $this YiiRequirementChecker */
/* @var $summary array */
/* @var $requirements array[] */
echo "\nYii Application Requirement Checker\n\n";
echo "This script checks if your server configuration meets the requirements\n";
echo "for running Yii application.\n";
echo "It checks if the server is running the right version of PHP,\n";
echo "if appropriate PHP extensions have been loaded, and if php.ini file settings are correct.\n";
$header = 'Check conclusion:';
echo "\n{$header}\n";
echo str_pad('', strlen($header), '-')."\n\n";
foreach ($requirements as $key => $requirement) {
if ($requirement['condition']) {
echo $requirement['name'].": OK\n";
echo "\n";
} else {
echo $requirement['name'].': '.($requirement['mandatory'] ? 'FAILED!!!' : 'WARNING!!!')."\n";
echo 'Required by: '.strip_tags($requirement['by'])."\n";
$memo = strip_tags($requirement['memo']);
if (!empty($memo)) {
echo 'Memo: '.strip_tags($requirement['memo'])."\n";
}
echo "\n";
}
}
$summaryString = 'Errors: '.$summary['errors'].' Warnings: '.$summary['warnings'].' Total checks: '.$summary['total'];
echo str_pad('', strlen($summaryString), '-')."\n";
echo $summaryString;
echo "\n\n";
\ No newline at end of file
body
{
background: white;
font-family:'Lucida Grande',Verdana,Geneva,Lucida,Helvetica,Arial,sans-serif;
font-size:10pt;
font-weight:normal;
}
#page
{
width: 800px;
margin: 0 auto;
}
#header
{
}
#content
{
}
#footer
{
color: gray;
font-size:8pt;
border-top:1px solid #aaa;
margin-top:10px;
}
h1
{
color:black;
font-size:1.6em;
font-weight:bold;
margin:0.5em 0pt;
}
h2
{
color:black;
font-size:1.25em;
font-weight:bold;
margin:0.3em 0pt;
}
h3
{
color:black;
font-size:1.1em;
font-weight:bold;
margin:0.2em 0pt;
}
table.result
{
background:#E6ECFF none repeat scroll 0% 0%;
border-collapse:collapse;
width:100%;
}
table.result th
{
background:#CCD9FF none repeat scroll 0% 0%;
text-align:left;
}
table.result th, table.result td
{
border:1px solid #BFCFFF;
padding:0.2em;
}
td.passed
{
background-color: #60BF60;
border: 1px solid silver;
padding: 2px;
}
td.warning
{
background-color: #FFFFBF;
border: 1px solid silver;
padding: 2px;
}
td.failed
{
background-color: #FF8080;
border: 1px solid silver;
padding: 2px;
}
<?php
/* @var $this YiiRequirementChecker */
/* @var $summary array */
/* @var $requirements array[] */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="content-language" content="en"/>
<style type="text/css">
<?php $this->renderViewFile(dirname(__FILE__).DIRECTORY_SEPARATOR.'css.php'); ?>
</style>
<title>Yii Application Requirement Checker</title>
</head>
<body>
<div id="page">
<div id="header">
<h1>Yii Application Requirement Checker</h1>
</div><!-- header-->
<div id="content">
<h2>Description</h2>
<p>
This script checks if your server configuration meets the requirements
for running Yii application.
It checks if the server is running the right version of PHP,
if appropriate PHP extensions have been loaded, and if php.ini file settings are correct.
</p>
<h2>Conclusion</h2>
<p>
<?php if ($summary['errors']>0): ?>
Unfortunately your server configuration does not satisfy the requirements by this application.
<?php elseif ($summary['warnings']>0): ?>
Your server configuration satisfies the minimum requirements by this application. Please pay attention to the warnings listed below if your application will use the corresponding features.
<?php else: ?>
Congratulations! Your server configuration satisfies all requirements.
<?php endif; ?>
</p>
<h2>Details</h2>
<table class="result">
<tr><th>Name</th><th>Result</th><th>Required By</th><th>Memo</th></tr>
<?php foreach($requirements as $requirement): ?>
<tr>
<td>
<?php echo $requirement['name']; ?>
</td>
<td class="<?php echo $requirement['condition'] ? 'passed' : ($requirement['mandatory'] ? 'failed' : 'warning'); ?>">
<?php echo $requirement['condition'] ? 'Passed' : ($requirement['mandatory'] ? 'Failed' : 'Warning'); ?>
</td>
<td>
<?php echo $requirement['by']; ?>
</td>
<td>
<?php echo $requirement['memo']; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<table>
<tr>
<td class="passed">&nbsp;</td><td>passed</td>
<td class="failed">&nbsp;</td><td>failed</td>
<td class="warning">&nbsp;</td><td>warning</td>
</tr>
</table>
</div><!-- content -->
<div id="footer">
<?php echo $this->getServerInfo().' '.$this->getNowDate(); ?>
</div><!-- footer -->
</div><!-- page -->
</body>
</html>
\ No newline at end of file
......@@ -47,7 +47,7 @@ use Yii;
* }
*
* // display pagination
* $this->widget('yii\widgets\LinkPager', array(
* LinkPager::widget($this, array(
* 'pages' => $pages,
* ));
* ~~~
......
......@@ -19,10 +19,11 @@ use yii\helpers\Html;
* for the "Sample Post". He can click on "Sample Post" to view that page, or he can click on "Home"
* to return to the homepage.
*
* To use Breadcrumbs, you need to configure its [[links]] property, which specifiesthe links to be displayed. For example,
* To use Breadcrumbs, you need to configure its [[links]] property, which specifies the links to be displayed. For example,
*
* ~~~
* $this->widget('yii\widgets\Breadcrumbs', array(
* // $this is the view object currently being used
* echo Breadcrumbs::widget($this, array(
* 'links' => array(
* array('label' => 'Sample Post', 'url' => array('post/edit', 'id' => 1)),
* 'Edit',
......@@ -30,12 +31,13 @@ use yii\helpers\Html;
* ));
* ~~~
*
* Because breadcrumbs usually appears in nearly every page of a website, you may consider place it in a layout view.
* You can then use a view parameter (e.g. `$this->params['breadcrumbs']`) to configure the links in different
* Because breadcrumbs usually appears in nearly every page of a website, you may consider placing it in a layout view.
* You can use a view parameter (e.g. `$this->params['breadcrumbs']`) to configure the links in different
* views. In the layout view, you assign this view parameter to the [[links]] property like the following:
*
* ~~~
* $this->widget('yii\widgets\Breadcrumbs', array(
* // $this is the view object currently being used
* echo Breadcrumbs::widget($this, array(
* 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : array(),
* ));
* ~~~
......
......@@ -26,10 +26,11 @@ use yii\helpers\Html;
* The following example shows how to use Menu:
*
* ~~~
* $this->widget('yii\widgets\Menu', array(
* // $this is the view object currently being used
* echo Menu::widget($this, array(
* 'items' => array(
* // Important: you need to specify url as 'controller/action',
* // not just as 'controller' even if default acion is used.
* // not just as 'controller' even if default action is used.
* array('label' => 'Home', 'url' => array('site/index')),
* // 'Products' menu item will be selected as long as the route is 'product/index'
* array('label' => 'Products', 'url' => array('product/index'), 'items' => array(
......
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