Browse Source
* master: (103 commits) fixed broken test after whitespace changes in view Removed the extra EOLs. I add new line in methods that render code in the head and for body GII update button style GII create object button style [skip ci] Fixes #980: Changed the default way of generating action URLs for ActionColumn. View default value for $params adjusted cubrid version in schema quote removed cubrid env from tavis.yml simplified cubrid db install on travis fixed cubrid schema test for pdo type fixed validator test break added cubrid specific pdo type casting Updated FileValidator tests Better AR connection init in tests Removed @codeCoverageIgnore no xss for attribute error messages that contain {value} Clientvalidation {value} was not what has been validated moved getPdoType() to Schema. optimized datepick js code. ...tags/2.0.0-beta
Carsten Brandt
11 years ago
123 changed files with 3636 additions and 823 deletions
@ -0,0 +1,208 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yii\composer; |
||||
|
||||
use Composer\Package\PackageInterface; |
||||
use Composer\Installer\LibraryInstaller; |
||||
use Composer\Repository\InstalledRepositoryInterface; |
||||
|
||||
/** |
||||
* @author Qiang Xue <qiang.xue@gmail.com> |
||||
* @since 2.0 |
||||
*/ |
||||
class Installer extends LibraryInstaller |
||||
{ |
||||
const EXTRA_WRITABLES = 'yii-writables'; |
||||
const EXTRA_EXECUTABLES = 'yii-executables'; |
||||
const EXTRA_CONFIG = 'yii-config'; |
||||
const EXTRA_COMMANDS = 'yii-commands'; |
||||
const EXTRA_ALIASES = 'yii-aliases'; |
||||
const EXTRA_PREINIT = 'yii-preinit'; |
||||
const EXTRA_INIT = 'yii-init'; |
||||
|
||||
/** |
||||
* @inheritdoc |
||||
*/ |
||||
public function supports($packageType) |
||||
{ |
||||
return $packageType === 'yii2-extension'; |
||||
} |
||||
|
||||
/** |
||||
* @inheritdoc |
||||
*/ |
||||
public function install(InstalledRepositoryInterface $repo, PackageInterface $package) |
||||
{ |
||||
parent::install($repo, $package); |
||||
$this->addPackage($package); |
||||
} |
||||
|
||||
/** |
||||
* @inheritdoc |
||||
*/ |
||||
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target) |
||||
{ |
||||
parent::update($repo, $initial, $target); |
||||
$this->removePackage($initial); |
||||
$this->addPackage($target); |
||||
} |
||||
|
||||
/** |
||||
* @inheritdoc |
||||
*/ |
||||
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) |
||||
{ |
||||
parent::uninstall($repo, $package); |
||||
$this->removePackage($package); |
||||
} |
||||
|
||||
protected function addPackage(PackageInterface $package) |
||||
{ |
||||
$extension = array('name' => $package->getPrettyName()); |
||||
|
||||
$root = $package->getPrettyName(); |
||||
if ($targetDir = $package->getTargetDir()) { |
||||
$root .= '/' . trim($targetDir, '/'); |
||||
} |
||||
$root = trim($root, '/'); |
||||
|
||||
$extra = $package->getExtra(); |
||||
|
||||
if (isset($extra[self::EXTRA_PREINIT]) && is_string($extra[self::EXTRA_PREINIT])) { |
||||
$extension[self::EXTRA_PREINIT] = "<vendor-dir>/$root/" . ltrim(str_replace('\\', '/', $extra[self::EXTRA_PREINIT]), '/'); |
||||
} |
||||
if (isset($extra[self::EXTRA_INIT]) && is_string($extra[self::EXTRA_INIT])) { |
||||
$extension[self::EXTRA_INIT] = "<vendor-dir>/$root/" . ltrim(str_replace('\\', '/', $extra[self::EXTRA_INIT]), '/'); |
||||
} |
||||
|
||||
if (isset($extra['aliases']) && is_array($extra['aliases'])) { |
||||
foreach ($extra['aliases'] as $alias => $path) { |
||||
$extension['aliases']['@' . ltrim($alias, '@')] = "<vendor-dir>/$root/" . ltrim(str_replace('\\', '/', $path), '/'); |
||||
} |
||||
} |
||||
|
||||
if (!empty($aliases)) { |
||||
foreach ($aliases as $alias => $path) { |
||||
if (strncmp($alias, '@', 1) !== 0) { |
||||
$alias = '@' . $alias; |
||||
} |
||||
$path = trim(str_replace('\\', '/', $path), '/'); |
||||
$extension['aliases'][$alias] = $root . '/' . $path; |
||||
} |
||||
} |
||||
|
||||
$extensions = $this->loadExtensions(); |
||||
$extensions[$package->getId()] = $extension; |
||||
$this->saveExtensions($extensions); |
||||
} |
||||
|
||||
protected function removePackage(PackageInterface $package) |
||||
{ |
||||
$packages = $this->loadExtensions(); |
||||
unset($packages[$package->getId()]); |
||||
$this->saveExtensions($packages); |
||||
} |
||||
|
||||
protected function loadExtensions() |
||||
{ |
||||
$file = $this->vendorDir . '/yii-extensions.php'; |
||||
if (!is_file($file)) { |
||||
return array(); |
||||
} |
||||
$extensions = require($file); |
||||
/** @var string $vendorDir defined in yii-extensions.php */ |
||||
$n = strlen($vendorDir); |
||||
foreach ($extensions as &$extension) { |
||||
if (isset($extension['aliases'])) { |
||||
foreach ($extension['aliases'] as $alias => $path) { |
||||
$extension['aliases'][$alias] = '<vendor-dir>' . substr($path, $n); |
||||
} |
||||
} |
||||
if (isset($extension[self::EXTRA_PREINIT])) { |
||||
$extension[self::EXTRA_PREINIT] = '<vendor-dir>' . substr($extension[self::EXTRA_PREINIT], $n); |
||||
} |
||||
if (isset($extension[self::EXTRA_INIT])) { |
||||
$extension[self::EXTRA_INIT] = '<vendor-dir>' . substr($extension[self::EXTRA_INIT], $n); |
||||
} |
||||
} |
||||
return $extensions; |
||||
} |
||||
|
||||
protected function saveExtensions(array $extensions) |
||||
{ |
||||
$file = $this->vendorDir . '/yii-extensions.php'; |
||||
$array = str_replace("'<vendor-dir>", '$vendorDir . \'', var_export($extensions, true)); |
||||
file_put_contents($file, "<?php\n\$vendorDir = __DIR__;\n\nreturn $array;\n");
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* Sets the correct permissions of files and directories. |
||||
* @param CommandEvent $event |
||||
*/ |
||||
public static function setPermissions($event) |
||||
{ |
||||
$options = array_merge(array( |
||||
self::EXTRA_WRITABLES => array(), |
||||
self::EXTRA_EXECUTABLES => array(), |
||||
), $event->getComposer()->getPackage()->getExtra()); |
||||
|
||||
foreach ((array)$options[self::EXTRA_WRITABLES] as $path) { |
||||
echo "Setting writable: $path ..."; |
||||
if (is_dir($path)) { |
||||
chmod($path, 0777); |
||||
echo "done\n"; |
||||
} else { |
||||
echo "The directory was not found: " . getcwd() . DIRECTORY_SEPARATOR . $path; |
||||
return; |
||||
} |
||||
} |
||||
|
||||
foreach ((array)$options[self::EXTRA_EXECUTABLES] as $path) { |
||||
echo "Setting executable: $path ..."; |
||||
if (is_file($path)) { |
||||
chmod($path, 0755); |
||||
echo "done\n"; |
||||
} else { |
||||
echo "\n\tThe file was not found: " . getcwd() . DIRECTORY_SEPARATOR . $path . "\n"; |
||||
return; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Executes a yii command. |
||||
* @param CommandEvent $event |
||||
*/ |
||||
public static function run($event) |
||||
{ |
||||
$options = array_merge(array( |
||||
self::EXTRA_COMMANDS => array(), |
||||
), $event->getComposer()->getPackage()->getExtra()); |
||||
|
||||
if (!isset($options[self::EXTRA_CONFIG])) { |
||||
throw new Exception('Please specify the "' . self::EXTRA_CONFIG . '" parameter in composer.json.'); |
||||
} |
||||
$configFile = getcwd() . '/' . $options[self::EXTRA_CONFIG]; |
||||
if (!is_file($configFile)) { |
||||
throw new Exception("Config file does not exist: $configFile"); |
||||
} |
||||
|
||||
require_once(__DIR__ . '/../../../yii2/yii/Yii.php'); |
||||
$application = new Application(require($configFile)); |
||||
$request = $application->getRequest(); |
||||
|
||||
foreach ((array)$options[self::EXTRA_COMMANDS] as $command) { |
||||
$params = str_getcsv($command, ' '); // see http://stackoverflow.com/a/6609509/291573 |
||||
$request->setParams($params); |
||||
list($route, $params) = $request->resolve(); |
||||
echo "Running command: yii {$command}\n"; |
||||
$application->runAction($route, $params); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,30 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yii\composer; |
||||
|
||||
use Composer\Composer; |
||||
use Composer\IO\IOInterface; |
||||
use Composer\Plugin\PluginInterface; |
||||
|
||||
/** |
||||
* InstallerPlugin is the composer plugin that registers the Yii composer installer. |
||||
* |
||||
* @author Qiang Xue <qiang.xue@gmail.com> |
||||
* @since 2.0 |
||||
*/ |
||||
class InstallerPlugin implements PluginInterface |
||||
{ |
||||
/** |
||||
* @inheritdoc |
||||
*/ |
||||
public function activate(Composer $composer, IOInterface $io) |
||||
{ |
||||
$installer = new Installer($io, $composer); |
||||
$composer->getInstallationManager()->addInstaller($installer); |
||||
} |
||||
} |
@ -0,0 +1,256 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yii\data; |
||||
|
||||
use Yii; |
||||
use yii\base\Component; |
||||
use yii\base\InvalidParamException; |
||||
|
||||
/** |
||||
* BaseDataProvider provides a base class that implements the [[DataProviderInterface]]. |
||||
* |
||||
* @property integer $count The number of data models in the current page. This property is read-only. |
||||
* @property array $keys The list of key values corresponding to [[models]]. Each data model in [[models]] is |
||||
* uniquely identified by the corresponding key value in this array. |
||||
* @property array $models The list of data models in the current page. |
||||
* @property Pagination|boolean $pagination The pagination object. If this is false, it means the pagination |
||||
* is disabled. Note that the type of this property differs in getter and setter. See [[getPagination()]] and |
||||
* [[setPagination()]] for details. |
||||
* @property Sort|boolean $sort The sorting object. If this is false, it means the sorting is disabled. Note |
||||
* that the type of this property differs in getter and setter. See [[getSort()]] and [[setSort()]] for details. |
||||
* @property integer $totalCount Total number of possible data models. |
||||
* |
||||
* @author Qiang Xue <qiang.xue@gmail.com> |
||||
* @since 2.0 |
||||
*/ |
||||
abstract class BaseDataProvider extends Component implements DataProviderInterface |
||||
{ |
||||
/** |
||||
* @var string an ID that uniquely identifies the data provider among all data providers. |
||||
* You should set this property if the same page contains two or more different data providers. |
||||
* Otherwise, the [[pagination]] and [[sort]] mainly not work properly. |
||||
*/ |
||||
public $id; |
||||
|
||||
private $_sort; |
||||
private $_pagination; |
||||
private $_keys; |
||||
private $_models; |
||||
private $_totalCount; |
||||
|
||||
|
||||
/** |
||||
* Prepares the data models that will be made available in the current page. |
||||
* @return array the available data models |
||||
*/ |
||||
abstract protected function prepareModels(); |
||||
|
||||
/** |
||||
* Prepares the keys associated with the currently available data models. |
||||
* @param array $models the available data models |
||||
* @return array the keys |
||||
*/ |
||||
abstract protected function prepareKeys($models); |
||||
|
||||
/** |
||||
* Returns a value indicating the total number of data models in this data provider. |
||||
* @return integer total number of data models in this data provider. |
||||
*/ |
||||
abstract protected function prepareTotalCount(); |
||||
|
||||
/** |
||||
* Prepares the data models and keys. |
||||
* |
||||
* This method will prepare the data models and keys that can be retrieved via |
||||
* [[getModels()]] and [[getKeys()]]. |
||||
* |
||||
* This method will be implicitly called by [[getModels()]] and [[getKeys()]] if it has not been called before. |
||||
* |
||||
* @param boolean $forcePrepare whether to force data preparation even if it has been done before. |
||||
*/ |
||||
public function prepare($forcePrepare = false) |
||||
{ |
||||
if ($forcePrepare || $this->_models === null) { |
||||
$this->_models = $this->prepareModels(); |
||||
} |
||||
if ($forcePrepare || $this->_keys === null) { |
||||
$this->_keys = $this->prepareKeys($this->_models); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Returns the data models in the current page. |
||||
* @return array the list of data models in the current page. |
||||
*/ |
||||
public function getModels() |
||||
{ |
||||
$this->prepare(); |
||||
return $this->_models; |
||||
} |
||||
|
||||
/** |
||||
* Sets the data models in the current page. |
||||
* @param array $models the models in the current page |
||||
*/ |
||||
public function setModels($models) |
||||
{ |
||||
$this->_models = $models; |
||||
} |
||||
|
||||
/** |
||||
* Returns the key values associated with the data models. |
||||
* @return array the list of key values corresponding to [[models]]. Each data model in [[models]] |
||||
* is uniquely identified by the corresponding key value in this array. |
||||
*/ |
||||
public function getKeys() |
||||
{ |
||||
$this->prepare(); |
||||
return $this->_keys; |
||||
} |
||||
|
||||
/** |
||||
* Sets the key values associated with the data models. |
||||
* @param array $keys the list of key values corresponding to [[models]]. |
||||
*/ |
||||
public function setKeys($keys) |
||||
{ |
||||
$this->_keys = $keys; |
||||
} |
||||
|
||||
/** |
||||
* Returns the number of data models in the current page. |
||||
* @return integer the number of data models in the current page. |
||||
*/ |
||||
public function getCount() |
||||
{ |
||||
return count($this->getModels()); |
||||
} |
||||
|
||||
/** |
||||
* Returns the total number of data models. |
||||
* When [[pagination]] is false, this returns the same value as [[count]]. |
||||
* Otherwise, it will call [[prepareTotalCount()]] to get the count. |
||||
* @return integer total number of possible data models. |
||||
*/ |
||||
public function getTotalCount() |
||||
{ |
||||
if ($this->getPagination() === false) { |
||||
return $this->getCount(); |
||||
} elseif ($this->_totalCount === null) { |
||||
$this->_totalCount = $this->prepareTotalCount(); |
||||
} |
||||
return $this->_totalCount; |
||||
} |
||||
|
||||
/** |
||||
* Sets the total number of data models. |
||||
* @param integer $value the total number of data models. |
||||
*/ |
||||
public function setTotalCount($value) |
||||
{ |
||||
$this->_totalCount = $value; |
||||
} |
||||
|
||||
/** |
||||
* Returns the pagination object used by this data provider. |
||||
* Note that you should call [[prepare()]] or [[getModels()]] first to get correct values |
||||
* of [[Pagination::totalCount]] and [[Pagination::pageCount]]. |
||||
* @return Pagination|boolean the pagination object. If this is false, it means the pagination is disabled. |
||||
*/ |
||||
public function getPagination() |
||||
{ |
||||
if ($this->_pagination === null) { |
||||
$this->_pagination = new Pagination; |
||||
if ($this->id !== null) { |
||||
$this->_pagination->pageVar = $this->id . '-page'; |
||||
} |
||||
} |
||||
return $this->_pagination; |
||||
} |
||||
|
||||
/** |
||||
* Sets the pagination for this data provider. |
||||
* @param array|Pagination|boolean $value the pagination to be used by this data provider. |
||||
* This can be one of the following: |
||||
* |
||||
* - a configuration array for creating the pagination object. The "class" element defaults |
||||
* to 'yii\data\Pagination' |
||||
* - an instance of [[Pagination]] or its subclass |
||||
* - false, if pagination needs to be disabled. |
||||
* |
||||
* @throws InvalidParamException |
||||
*/ |
||||
public function setPagination($value) |
||||
{ |
||||
if (is_array($value)) { |
||||
$config = array( |
||||
'class' => Pagination::className(), |
||||
); |
||||
if ($this->id !== null) { |
||||
$config['pageVar'] = $this->id . '-page'; |
||||
} |
||||
$this->_pagination = Yii::createObject(array_merge($config, $value)); |
||||
} elseif ($value instanceof Pagination || $value === false) { |
||||
$this->_pagination = $value; |
||||
} else { |
||||
throw new InvalidParamException('Only Pagination instance, configuration array or false is allowed.'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @return Sort|boolean the sorting object. If this is false, it means the sorting is disabled. |
||||
*/ |
||||
public function getSort() |
||||
{ |
||||
if ($this->_sort === null) { |
||||
$this->setSort(array()); |
||||
} |
||||
return $this->_sort; |
||||
} |
||||
|
||||
/** |
||||
* Sets the sort definition for this data provider. |
||||
* @param array|Sort|boolean $value the sort definition to be used by this data provider. |
||||
* This can be one of the following: |
||||
* |
||||
* - a configuration array for creating the sort definition object. The "class" element defaults |
||||
* to 'yii\data\Sort' |
||||
* - an instance of [[Sort]] or its subclass |
||||
* - false, if sorting needs to be disabled. |
||||
* |
||||
* @throws InvalidParamException |
||||
*/ |
||||
public function setSort($value) |
||||
{ |
||||
if (is_array($value)) { |
||||
$config = array( |
||||
'class' => Sort::className(), |
||||
); |
||||
if ($this->id !== null) { |
||||
$config['sortVar'] = $this->id . '-sort'; |
||||
} |
||||
$this->_sort = Yii::createObject(array_merge($config, $value)); |
||||
} elseif ($value instanceof Sort || $value === false) { |
||||
$this->_sort = $value; |
||||
} else { |
||||
throw new InvalidParamException('Only Sort instance, configuration array or false is allowed.'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Refreshes the data provider. |
||||
* After calling this method, if [[getModels()]], [[getKeys()]] or [[getTotalCount()]] is called again, |
||||
* they will re-execute the query and return the latest data available. |
||||
*/ |
||||
public function refresh() |
||||
{ |
||||
$this->_totalCount = null; |
||||
$this->_models = null; |
||||
$this->_keys = null; |
||||
} |
||||
} |
@ -1,133 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yii\data; |
||||
|
||||
use Yii; |
||||
use yii\base\Component; |
||||
use yii\base\InvalidParamException; |
||||
|
||||
/** |
||||
* DataProvider is the base class of data provider classes. |
||||
* |
||||
* It implements the [[getPagination()]] and [[getSort()]] methods as specified by the [[DataProviderInterface]]. |
||||
* |
||||
* @property integer $count The number of data models in the current page. This property is read-only. |
||||
* @property Pagination|boolean $pagination The pagination object. If this is false, it means the pagination |
||||
* is disabled. Note that the type of this property differs in getter and setter. See [[getPagination()]] and |
||||
* [[setPagination()]] for details. |
||||
* @property Sort|boolean $sort The sorting object. If this is false, it means the sorting is disabled. Note |
||||
* that the type of this property differs in getter and setter. See [[getSort()]] and [[setSort()]] for details. |
||||
* |
||||
* @author Qiang Xue <qiang.xue@gmail.com> |
||||
* @since 2.0 |
||||
*/ |
||||
abstract class DataProvider extends Component implements DataProviderInterface |
||||
{ |
||||
/** |
||||
* @var string an ID that uniquely identifies the data provider among all data providers. |
||||
* You should set this property if the same page contains two or more different data providers. |
||||
* Otherwise, the [[pagination]] and [[sort]] mainly not work properly. |
||||
*/ |
||||
public $id; |
||||
|
||||
private $_sort; |
||||
private $_pagination; |
||||
|
||||
/** |
||||
* @return Pagination|boolean the pagination object. If this is false, it means the pagination is disabled. |
||||
*/ |
||||
public function getPagination() |
||||
{ |
||||
if ($this->_pagination === null) { |
||||
$this->_pagination = new Pagination; |
||||
if ($this->id !== null) { |
||||
$this->_pagination->pageVar = $this->id . '-page'; |
||||
} |
||||
$this->_pagination->totalCount = $this->getTotalCount(); |
||||
} |
||||
return $this->_pagination; |
||||
} |
||||
|
||||
/** |
||||
* Sets the pagination for this data provider. |
||||
* @param array|Pagination|boolean $value the pagination to be used by this data provider. |
||||
* This can be one of the following: |
||||
* |
||||
* - a configuration array for creating the pagination object. The "class" element defaults |
||||
* to 'yii\data\Pagination' |
||||
* - an instance of [[Pagination]] or its subclass |
||||
* - false, if pagination needs to be disabled. |
||||
* |
||||
* @throws InvalidParamException |
||||
*/ |
||||
public function setPagination($value) |
||||
{ |
||||
if (is_array($value)) { |
||||
$config = array( |
||||
'class' => Pagination::className(), |
||||
); |
||||
if ($this->id !== null) { |
||||
$config['pageVar'] = $this->id . '-page'; |
||||
} |
||||
$this->_pagination = Yii::createObject(array_merge($config, $value)); |
||||
} elseif ($value instanceof Pagination || $value === false) { |
||||
$this->_pagination = $value; |
||||
} else { |
||||
throw new InvalidParamException('Only Pagination instance, configuration array or false is allowed.'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @return Sort|boolean the sorting object. If this is false, it means the sorting is disabled. |
||||
*/ |
||||
public function getSort() |
||||
{ |
||||
if ($this->_sort === null) { |
||||
$this->setSort(array()); |
||||
} |
||||
return $this->_sort; |
||||
} |
||||
|
||||
/** |
||||
* Sets the sort definition for this data provider. |
||||
* @param array|Sort|boolean $value the sort definition to be used by this data provider. |
||||
* This can be one of the following: |
||||
* |
||||
* - a configuration array for creating the sort definition object. The "class" element defaults |
||||
* to 'yii\data\Sort' |
||||
* - an instance of [[Sort]] or its subclass |
||||
* - false, if sorting needs to be disabled. |
||||
* |
||||
* @throws InvalidParamException |
||||
*/ |
||||
public function setSort($value) |
||||
{ |
||||
if (is_array($value)) { |
||||
$config = array( |
||||
'class' => Sort::className(), |
||||
); |
||||
if ($this->id !== null) { |
||||
$config['sortVar'] = $this->id . '-sort'; |
||||
} |
||||
$this->_sort = Yii::createObject(array_merge($config, $value)); |
||||
} elseif ($value instanceof Sort || $value === false) { |
||||
$this->_sort = $value; |
||||
} else { |
||||
throw new InvalidParamException('Only Sort instance, configuration array or false is allowed.'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Returns the number of data models in the current page. |
||||
* @return integer the number of data models in the current page. |
||||
*/ |
||||
public function getCount() |
||||
{ |
||||
return count($this->getModels()); |
||||
} |
||||
} |
@ -0,0 +1,44 @@
|
||||
<?php |
||||
|
||||
namespace yiiunit\data\validators; |
||||
|
||||
|
||||
use yii\validators\Validator; |
||||
|
||||
class TestValidator extends Validator |
||||
{ |
||||
private $_validatedAttributes = array(); |
||||
private $_setErrorOnValidateAttribute = false; |
||||
|
||||
public function validateAttribute($object, $attribute) |
||||
{ |
||||
$this->markAttributeValidated($attribute); |
||||
if ($this->_setErrorOnValidateAttribute == true) { |
||||
$this->addError($object, $attribute, sprintf('%s##%s', $attribute, get_class($object))); |
||||
} |
||||
} |
||||
|
||||
protected function markAttributeValidated($attr, $increaseBy = 1) |
||||
{ |
||||
if (!isset($this->_validatedAttributes[$attr])) { |
||||
$this->_validatedAttributes[$attr] = 1; |
||||
} else { |
||||
$this->_validatedAttributes[$attr] = $this->_validatedAttributes[$attr] + $increaseBy; |
||||
} |
||||
} |
||||
|
||||
public function countAttributeValidations($attr) |
||||
{ |
||||
return isset($this->_validatedAttributes[$attr]) ? $this->_validatedAttributes[$attr] : 0; |
||||
} |
||||
|
||||
public function isAttributeValidated($attr) |
||||
{ |
||||
return isset($this->_validatedAttributes[$attr]); |
||||
} |
||||
|
||||
public function enableErrorOnValidateAttribute() |
||||
{ |
||||
$this->_setErrorOnValidateAttribute = true; |
||||
} |
||||
} |
@ -0,0 +1,63 @@
|
||||
<?php |
||||
|
||||
namespace yiiunit\data\validators\models; |
||||
|
||||
use yii\base\Model; |
||||
|
||||
class FakedValidationModel extends Model |
||||
{ |
||||
public $val_attr_a; |
||||
public $val_attr_b; |
||||
public $val_attr_c; |
||||
public $val_attr_d; |
||||
private $attr = array(); |
||||
|
||||
/** |
||||
* @param array $attributes |
||||
* @return self |
||||
*/ |
||||
public static function createWithAttributes($attributes = array()) |
||||
{ |
||||
$m = new static(); |
||||
foreach ($attributes as $attribute => $value) { |
||||
$m->$attribute = $value; |
||||
} |
||||
return $m; |
||||
} |
||||
|
||||
public function rules() |
||||
{ |
||||
return array( |
||||
array('val_attr_a, val_attr_b', 'required', 'on' => 'reqTest'), |
||||
array('val_attr_c', 'integer'), |
||||
); |
||||
} |
||||
|
||||
public function inlineVal($attribute, $params = array()) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
public function __get($name) |
||||
{ |
||||
if (stripos($name, 'attr') === 0) { |
||||
return isset($this->attr[$name]) ? $this->attr[$name] : null; |
||||
} |
||||
|
||||
return parent::__get($name); |
||||
} |
||||
|
||||
public function __set($name, $value) |
||||
{ |
||||
if (stripos($name, 'attr') === 0) { |
||||
$this->attr[$name] = $value; |
||||
} else { |
||||
parent::__set($name, $value); |
||||
} |
||||
} |
||||
|
||||
public function getAttributeLabel($attr) |
||||
{ |
||||
return $attr; |
||||
} |
||||
} |
@ -0,0 +1,21 @@
|
||||
<?php |
||||
|
||||
namespace yiiunit\data\validators\models; |
||||
|
||||
|
||||
use yiiunit\data\ar\ActiveRecord; |
||||
|
||||
class ValidatorTestMainModel extends ActiveRecord |
||||
{ |
||||
public $testMainVal = 1; |
||||
|
||||
public static function tableName() |
||||
{ |
||||
return 'tbl_validator_main'; |
||||
} |
||||
|
||||
public function getReferences() |
||||
{ |
||||
return $this->hasMany(ValidatorTestRefModel::className(), array('ref' => 'id')); |
||||
} |
||||
} |
@ -0,0 +1,23 @@
|
||||
<?php |
||||
|
||||
namespace yiiunit\data\validators\models; |
||||
|
||||
|
||||
use yiiunit\data\ar\ActiveRecord; |
||||
|
||||
class ValidatorTestRefModel extends ActiveRecord |
||||
{ |
||||
|
||||
public $test_val = 2; |
||||
public $test_val_fail = 99; |
||||
|
||||
public static function tableName() |
||||
{ |
||||
return 'tbl_validator_ref'; |
||||
} |
||||
|
||||
public function getMain() |
||||
{ |
||||
return $this->hasOne(ValidatorTestMainModel::className(), array('id' => 'ref')); |
||||
} |
||||
} |
@ -0,0 +1,22 @@
|
||||
<?php |
||||
/** |
||||
* @var $this \yii\base\View |
||||
* @var $content string |
||||
*/ |
||||
?> |
||||
<?php $this->beginPage(); ?> |
||||
<!DOCTYPE html> |
||||
<html> |
||||
<head> |
||||
<title>Test</title> |
||||
<?php $this->head(); ?> |
||||
</head> |
||||
<body> |
||||
<?php $this->beginBody(); ?> |
||||
|
||||
<?php echo $content; ?> |
||||
|
||||
<?php $this->endBody(); ?> |
||||
</body> |
||||
</html> |
||||
<?php $this->endPage(); ?> |
@ -0,0 +1,5 @@
|
||||
<?php |
||||
/** |
||||
* @var $this \yii\base\View |
||||
*/ |
||||
?><?php $this->beginPage(); ?>1<?php $this->head(); ?>2<?php $this->beginBody(); ?>3<?php $this->endBody(); ?>4<?php $this->endPage(); ?> |
@ -0,0 +1,23 @@
|
||||
<?php |
||||
namespace yiiunit\framework\base; |
||||
|
||||
use yii\test\TestCase; |
||||
use yii\base\UserException; |
||||
use yii\base\InvalidCallException; |
||||
|
||||
|
||||
class ExceptionTest extends TestCase |
||||
{ |
||||
public function testToArrayWithPrevious() |
||||
{ |
||||
$e = new InvalidCallException('bar', 0 ,new InvalidCallException('foo')); |
||||
$array = $e->toArray(); |
||||
$this->assertEquals('bar', $array['message']); |
||||
$this->assertEquals('foo', $array['previous']['message']); |
||||
|
||||
$e = new InvalidCallException('bar', 0 ,new UserException('foo')); |
||||
$array = $e->toArray(); |
||||
$this->assertEquals('bar', $array['message']); |
||||
$this->assertEquals('foo', $array['previous']['message']); |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue