Skip to content

Commit

Permalink
Ability to use JSON::toArray with non-entity objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
GregaMohorko committed Sep 29, 2018
1 parent 9009e70 commit 18f40f1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/BlueDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* Bootstrap file for BlueDB library.
*
* Version 1.2.3.1
* Version 1.2.4.0
*
* @project BlueDB
* @author Grega Mohorko <[email protected]>
Expand Down
14 changes: 9 additions & 5 deletions src/Entity/FieldEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,16 @@ public static function toArrayList($entities,$fieldsToIgnore=null,$includeHidden
private static function toArrayListInternal($entities,$fieldsToIgnore,$includeHiddenFields,&$session)
{
$elements=[];
foreach($entities as $entityKey => $entity){
if(is_array($entity)){
$elements[$entityKey]=self::toArrayListInternal($entity, $fieldsToIgnore, $includeHiddenFields, $session);
foreach($entities as $key => $value){
if(is_array($value)){
$elements[$key]=self::toArrayListInternal($value, $fieldsToIgnore, $includeHiddenFields, $session);
}else{
/* @var $entity FieldEntity */
$elements[$entityKey]=$entity->toArrayInternal($fieldsToIgnore,$includeHiddenFields, $session);
if(is_a($value, FieldEntity::class)){
/* @var $value FieldEntity */
$elements[$key]=$value->toArrayInternal($fieldsToIgnore,$includeHiddenFields, $session);
}else{
$elements[$key]=$value;
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/Entity/SubEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ public function getID()
{
$baseStrongEntity=$this->getBaseStrongEntity();
if($baseStrongEntity===null){
echo "<pre>";
var_dump($this);
echo "</pre>";
throw new \Exception("WTF");
throw new \Exception("Trying to get ID of a sub entity without parent.");
}
return $baseStrongEntity->ID;
}
Expand Down

0 comments on commit 18f40f1

Please sign in to comment.