From 0eb69526a34f756579c4f3408fdadaa2b59c5b84 Mon Sep 17 00:00:00 2001 From: Egorka Date: Mon, 24 Sep 2018 23:48:11 +0300 Subject: [PATCH] Shop module rewrite --- Yii.php | 1 + core/components/LanguageTranslateTrait.php | 78 ++++++++++++++++-------------- core/events/EventTrait.php | 12 ++--- core/helpers/PhoneHelper.php | 21 ++++++++ 4 files changed, 70 insertions(+), 42 deletions(-) create mode 100644 core/helpers/PhoneHelper.php diff --git a/Yii.php b/Yii.php index 9540874..8a42078 100644 --- a/Yii.php +++ b/Yii.php @@ -27,6 +27,7 @@ abstract class BaseApplication extends yii\base\Application * Include only Web application related components here * * @property \core\components\modules\ModuleManager $moduleManager Module manager + * @property \yii\db\Query $queue * * @property \core\entities\user\User $user The user component. This property is read-only. Extended component. * @ property \app\components\MyResponse $response The response component. This property is read-only. Extended component. diff --git a/core/components/LanguageTranslateTrait.php b/core/components/LanguageTranslateTrait.php index a75d993..0eb412f 100644 --- a/core/components/LanguageTranslateTrait.php +++ b/core/components/LanguageTranslateTrait.php @@ -17,39 +17,45 @@ use Yii; */ trait LanguageTranslateTrait { - /** - * @var string the name of the lang field of the translation table. Default to 'language'. - */ - public $languageField = 'language'; - /** - * Scope for querying by languages - * - * @param string $language - * @param bool $abridge - * - * @return $this - */ - public function localized($language = null, $abridge = true) - { - $language = $language ?: Yii::$app->language; - if (!isset($this->with['translations'])) { - $this->with(['translation' => function ($query) use ($language, $abridge) { - /** @var ActiveQuery $query */ - $query->where([$this->languageField => $abridge ? substr($language, 0, 2) : $language]); - }]); - } - return $this; - } - /** - * Scope for querying by all languages - * @return $this - */ - public function multilingual() - { - if (isset($this->with['translation'])) { - unset($this->with['translation']); - } - $this->with('translations'); - return $this; - } -} \ No newline at end of file + /** + * @var string the name of the lang field of the translation table. Default to 'language'. + */ + public $languageField = 'language'; + + /** + * Scope for querying by languages + * + * @param string $language + * @param bool $abridge + * + * @return $this + */ + public function localized($language = null, $abridge = true) + { + $language = $language ?: Yii::$app->language; + if (!isset($this->with['translations'])) { + $this->with([ + 'translation' => function ($query) use ($language, $abridge) { + /** @var ActiveQuery $query */ + $query->where([$this->languageField => $abridge ? substr($language, 0, 2) : $language]); + } + ]); + } + + return $this; + } + + /** + * Scope for querying by all languages + * @return $this + */ + public function multilingual() + { + if (isset($this->with['translation'])) { + unset($this->with['translation']); + } + $this->with('translations'); + + return $this; + } +} diff --git a/core/events/EventTrait.php b/core/events/EventTrait.php index dbb4914..7ad8634 100644 --- a/core/events/EventTrait.php +++ b/core/events/EventTrait.php @@ -4,17 +4,17 @@ namespace core\events; trait EventTrait { - private $events = []; + private $_events = []; - protected function recordEvent($event): void + public function recordEvent($event): void { - $this->events[] = $event; + $this->_events[] = $event; } public function releaseEvents(): array { - $events = $this->events; - $this->events = []; + $events = $this->_events; + $this->_events = []; return $events; } -} \ No newline at end of file +} diff --git a/core/helpers/PhoneHelper.php b/core/helpers/PhoneHelper.php new file mode 100644 index 0000000..d198d0a --- /dev/null +++ b/core/helpers/PhoneHelper.php @@ -0,0 +1,21 @@ +