Skip to content

Commit

Permalink
fix arrayhelper to accept all yii components
Browse files Browse the repository at this point in the history
  • Loading branch information
TonisOrmisson committed Feb 4, 2019
1 parent c405e71 commit b16f630
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/MyArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use yii\base\Component;
use yii\base\InvalidArgumentException;
use yii\base\Model;
use yii\db\ActiveRecord;
use yii\helpers\ArrayHelper;

Expand Down Expand Up @@ -101,12 +102,13 @@ public static function indexByColumn($array, $colName) {
if (!empty($array)) {
$newArray = [];
foreach ($array as $key => $row) {
if ($row instanceof ActiveRecord) {
if ($row instanceof Component) {
/** @var Model $row */
$rowArr = (array) $row->attributes;
} else if (is_array($row)) {
$rowArr = $row;
} else {
throw new InvalidArgumentException('Only arrays or ActiveRecord Objects can be used in '.__CLASS__.'::'.__FUNCTION__);
throw new InvalidArgumentException('Only arrays or yii Component objects can be used in '.__CLASS__.'::'.__FUNCTION__);
}
// make it array if input is object

Expand Down

0 comments on commit b16f630

Please sign in to comment.