Skip to content

Commit

Permalink
fix #1, update readme and composer.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdmunir committed Jul 23, 2015
1 parent e54ce2e commit 9a79bab
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
23 changes: 23 additions & 0 deletions Bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace mdm\autonumber;

use yii\base\BootstrapInterface;
use yii\validators\Validator;

/**
* Description of Bootstrap
*
* @author Misbahul D Munir <misbahuldmunir@gmail.com>
* @since 1.0
*/
class Bootstrap implements BootstrapInterface
{
/**
* @inheritdoc
*/
public function bootstrap($app)
{
Validator::$builtInValidators['nextValue'] = __NAMESPACE__ . '\NextValueValidator';
}
}
8 changes: 4 additions & 4 deletions NextValueValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* ~~~
* return [
* [['sales_num'], 'mdm\autonumber\NextValueValidator', 'format'=>'SA.'.date('Ymd').'?'],
* [['sales_num'], 'nextValue', 'format'=>'SA.'.date('Ymd').'?'],
* ...
* ]
* ~~~
Expand Down Expand Up @@ -97,7 +97,7 @@ public function nextValue($object, $attribute)
$group = md5(serialize([
'class' => $this->unique ? get_class($object) : false,
'group' => $this->group,
'attribute' => $this->attribute,
'attribute' => $attribute,
'value' => $value
]));
$model = AutoNumber::findOne($group);
Expand Down Expand Up @@ -131,10 +131,10 @@ public function beforeSave($event)
{
/* @var $model AutoNumber */
list($model, $id) = $event->data;
if (isset(static::$_executed[$id])) {
if (isset(self::$_executed[$id])) {
return;
}
static::$_executed[$id] = true;
self::$_executed[$id] = true;
try {
$model->save();
} catch (\Exception $exc) {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Instead of behavior, you can use this extension as validator
public function rules()
{
return [
[['sales_num'],'mdm\autonumber\NextValueValidator','format'=>'SA.'.date('Y-m-d').'.?'],
[['sales_num'],'nextValue','format'=>'SA.'.date('Y-m-d').'.?'],
...
];
}
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
}
},
"extra": {
"bootstrap": "mdm\\autonumber\\Bootstrap",
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "1.x-dev"
}
}
}

0 comments on commit 9a79bab

Please sign in to comment.