-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from CottaCush/fixes/check-deprecation
fix issue with deprecation
- Loading branch information
Showing
32 changed files
with
1,552 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,28 +5,29 @@ | |
use CottaCush\Yii2\Controller\BaseController; | ||
use yii\base\Action; | ||
use yii\db\ActiveRecord; | ||
use yii\web\ForbiddenHttpException; | ||
use yii\web\Response; | ||
|
||
class BaseAction extends Action | ||
{ | ||
/** @var ActiveRecord $model */ | ||
public $model; | ||
public ActiveRecord $model; | ||
|
||
public $postData; | ||
public $returnUrl = ''; | ||
public string $returnUrl = ''; | ||
|
||
public $recordNotFound = 'Record not found'; | ||
public $errorMessage = ''; | ||
public $successMessage = ''; | ||
public string $recordNotFound = 'Record not found'; | ||
public string $errorMessage = ''; | ||
public string $successMessage = ''; | ||
|
||
/** @var bool Checks if the login is required before action is executed */ | ||
public $requireLogin = true; | ||
public bool $requireLogin = true; | ||
|
||
/** | ||
* @return bool|Response | ||
* @throws ForbiddenHttpException | ||
* @author Olawale Lawal <[email protected]> | ||
* @return bool|\yii\web\Response | ||
*/ | ||
public function beforeRun() | ||
public function beforeRun(): Response|bool | ||
{ | ||
if (!$this->requireLogin) { | ||
return true; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
namespace CottaCush\Yii2\Action; | ||
|
||
use CottaCush\Yii2\Controller\BaseController; | ||
use yii\base\ExitException; | ||
use yii\web\Response; | ||
|
||
/** | ||
* Class DeleteAction | ||
|
@@ -17,17 +19,18 @@ class DeleteAction extends BaseAction | |
{ | ||
public $deleteAttribute = 'is_active'; | ||
public $deleteStatus = 0; | ||
public $errorMessage = 'Record not found'; | ||
public string $errorMessage = 'Record not found'; | ||
|
||
public $extraFields = null; | ||
public $formName = ''; | ||
|
||
/** | ||
* @return Response | ||
* @throws ExitException | ||
* @author Adegoke Obasa <[email protected]> | ||
* @author Akinwunmi Taiwo <[email protected]> | ||
* @return \yii\web\Response | ||
*/ | ||
public function run() | ||
public function run(): Response | ||
{ | ||
/** @var BaseController $controller */ | ||
$controller = $this->controller; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,10 @@ | |
|
||
use CottaCush\Yii2\Controller\BaseController; | ||
use CottaCush\Yii2\Model\BaseModel; | ||
use Yii; | ||
use yii\base\ExitException; | ||
use yii\helpers\Json; | ||
use yii\web\Response; | ||
use yii\widgets\ActiveForm; | ||
|
||
/** | ||
|
@@ -20,11 +23,12 @@ class SaveAction extends BaseAction | |
public $enableAjaxValidation = false; | ||
|
||
/** | ||
* @author Adegoke Obasa <[email protected]> | ||
* @return string|Response | ||
* @throws ExitException | ||
* @author Akinwunmi Taiwo <[email protected]> | ||
* @return \yii\web\Response | ||
* @author Adegoke Obasa <[email protected]> | ||
*/ | ||
public function run() | ||
public function run(): Response|string | ||
{ | ||
/** @var BaseController $controller */ | ||
$controller = $this->controller; | ||
|
@@ -40,7 +44,7 @@ public function run() | |
$model = new $this->model; | ||
$model->load($this->postData); | ||
|
||
if (\Yii::$app->request->isAjax && $this->enableAjaxValidation) { | ||
if (Yii::$app->request->isAjax && $this->enableAjaxValidation) { | ||
return Json::encode(ActiveForm::validate($model)); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,9 @@ | |
use CottaCush\Yii2\Constants\Messages; | ||
use CottaCush\Yii2\Controller\BaseController; | ||
use CottaCush\Yii2\Model\BaseModel; | ||
use yii\base\ExitException; | ||
use yii\db\IntegrityException; | ||
use yii\web\Response; | ||
|
||
class SoftDeleteAction extends DeleteAction | ||
{ | ||
|
@@ -17,10 +19,11 @@ class SoftDeleteAction extends DeleteAction | |
public $integrityViolationMessage = Messages::RECORD_USED_ALREADY; | ||
|
||
/** | ||
* @return Response | ||
* @throws ExitException | ||
* @author Olawale Lawal <[email protected]> | ||
* @return \yii\web\Response | ||
*/ | ||
public function run() | ||
public function run(): Response | ||
{ | ||
/** @var BaseController $controller */ | ||
$controller = $this->controller; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,9 @@ | |
namespace CottaCush\Yii2\Action; | ||
|
||
use CottaCush\Yii2\Controller\BaseController; | ||
use yii\base\ExitException; | ||
use yii\db\IntegrityException; | ||
use yii\web\Response; | ||
|
||
/** | ||
* Class UpdateAction | ||
|
@@ -19,11 +21,12 @@ class UpdateAction extends BaseAction | |
public $integrityExceptionMessage = 'Record cannot be updated as it is in use elsewhere'; | ||
|
||
/** | ||
* @return Response | ||
* @throws ExitException | ||
* @author Adegoke Obasa <[email protected]> | ||
* @author Akinwunmi Taiwo <[email protected]> | ||
* @return \yii\web\Response | ||
*/ | ||
public function run() | ||
public function run(): Response | ||
{ | ||
/** @var BaseController $controller */ | ||
$controller = $this->controller; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,11 @@ | |
|
||
namespace CottaCush\Yii2\Controller; | ||
|
||
use Yii; | ||
use yii\base\Action; | ||
use yii\console\Controller; | ||
use yii\db\Connection; | ||
use yii\db\Exception; | ||
use yii\db\Query; | ||
use yii\db\Transaction; | ||
|
||
|
@@ -23,14 +26,14 @@ class BaseConsoleController extends Controller | |
protected $transaction; | ||
|
||
/** | ||
* @author Olawale Lawal <[email protected]> | ||
* @param \yii\base\Action $action | ||
* @param Action $action | ||
* @return bool | ||
* @author Olawale Lawal <[email protected]> | ||
*/ | ||
public function beforeAction($action) | ||
public function beforeAction(Action $action): bool | ||
{ | ||
if (is_null($this->db)) { | ||
$this->db = \Yii::$app->db; | ||
$this->db = Yii::$app->db; | ||
} | ||
return parent::beforeAction($action); | ||
} | ||
|
@@ -44,6 +47,7 @@ public function beginTransaction() | |
} | ||
|
||
/** | ||
* @throws Exception | ||
* @author Olawale Lawal <[email protected]> | ||
*/ | ||
public function commitTransaction() | ||
|
@@ -67,44 +71,46 @@ public function rollbackTransaction() | |
* @param string $returnColumn | ||
* @return false|null|string | ||
*/ | ||
public static function getColumnByField($table, $field, $value, $returnColumn = 'id') | ||
public static function getColumnByField($table, $field, $value, $returnColumn = 'id'): bool|string|null | ||
{ | ||
return (new Query)->select($returnColumn) | ||
->from($table)->filterWhere([$field => $value]) | ||
->scalar(); | ||
} | ||
|
||
public function getRandomOne($table, $column, $conditions = []) | ||
public function getRandomOne($table, $column, $conditions = []): bool|array | ||
{ | ||
return (new Query)->select($column) | ||
->from($table)->filterWhere($conditions)->orderBy('rand()')->one(); | ||
} | ||
|
||
public function getAll($table, $columns, $conditions = []) | ||
public function getAll($table, $columns, $conditions = []): array | ||
{ | ||
return (new Query)->select($columns) | ||
->from($table)->andFilterWhere($conditions)->all(); | ||
} | ||
|
||
/** | ||
* @author Olawale Lawal <[email protected]> | ||
* @param $table | ||
* @param array $columns | ||
* @return int | ||
* @throws Exception | ||
* @author Olawale Lawal <[email protected]> | ||
*/ | ||
public function insert($table, array $columns) | ||
public function insert($table, array $columns): int | ||
{ | ||
return $this->db->createCommand()->insert($table, $columns)->execute(); | ||
} | ||
|
||
/** | ||
* @author Olawale Lawal <[email protected]> | ||
* @param $table | ||
* @param array $columns | ||
* @param array $rows | ||
* @return int | ||
* @return bool|int | ||
* @throws Exception | ||
* @author Olawale Lawal <[email protected]> | ||
*/ | ||
public function batchInsert($table, array $columns, array $rows) | ||
public function batchInsert($table, array $columns, array $rows): bool|int | ||
{ | ||
if (empty($rows)) { | ||
return true; | ||
|
@@ -113,7 +119,7 @@ public function batchInsert($table, array $columns, array $rows) | |
return $this->db->createCommand()->batchInsert($table, $columns, $rows)->execute(); | ||
} | ||
|
||
public function stdout($string) | ||
public function stdout($string): void | ||
{ | ||
parent::stdout($string . PHP_EOL); | ||
} | ||
|
Oops, something went wrong.