Skip to content

Commit

Permalink
Merge pull request #99 from SerafimArts/5.1
Browse files Browse the repository at this point in the history
IteratorAggregate has no method `current`
  • Loading branch information
RemiCollin committed May 25, 2016
2 parents af1a7bd + e82eb22 commit f5b0b10
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/System/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Analogue\ORM\System;

use Analogue\ORM\Entity;
use Analogue\ORM\Plugins\AnaloguePluginInterface;
use Analogue\ORM\ValueMap;
use Exception;
use Analogue\ORM\EntityMap;
use Analogue\ORM\Repository;
Expand Down Expand Up @@ -42,7 +45,7 @@ class Manager
/**
* Key value store of ValueObject Classes and corresponding map classes
*
* @var array
* @var array|ValueMap[]
*/
protected $valueClasses = [];

Expand Down Expand Up @@ -119,6 +122,7 @@ public function __construct(DriverManager $driverManager, Dispatcher $event)
* @param null|EntityMap $entityMap
* @throws MappingException
* @return Mapper
* @throws \InvalidArgumentException
*/
public static function getMapper($entity, $entityMap = null)
{
Expand Down Expand Up @@ -169,7 +173,7 @@ protected function resolveEntityClass($entity)
throw new \InvalidArgumentException('Length of Entity collection must be greater than 0');
}

$firstEntityItem = ($entity instanceof \Iterator || $entity instanceof \IteratorAggregate)
$firstEntityItem = ($entity instanceof \Iterator)
? $entity->current()
: current($entity);

Expand Down Expand Up @@ -231,7 +235,7 @@ protected function buildMapper($entity, $entityMap)
/**
* Check if the entity is already registered
*
* @param string|object $entity
* @param string|Entity $entity
* @return boolean
*/
public function isRegisteredEntity($entity)
Expand Down Expand Up @@ -287,7 +291,7 @@ public function register($entity, $entityMap = null)
throw new MappingException("Class $entity does not exists");
}

if (is_null($entityMap)) {
if ($entityMap === null) {
$entityMap = $this->getEntityMapInstanceFor($entity);
}

Expand All @@ -311,6 +315,7 @@ public function register($entity, $entityMap = null)
*
* @param string $entity
* @return \Analogue\ORM\Mappable
* @throws EntityMapNotFoundException
*/
protected function getEntityMapInstanceFor($entity)
{
Expand Down Expand Up @@ -412,6 +417,8 @@ public function getValueMap($valueObject)
if (!array_key_exists($valueObject, $this->valueClasses)) {
$this->registerValueObject($valueObject);
}

/** @var ValueMap $valueMap */
$valueMap = new $this->valueClasses[$valueObject];

$valueMap->setClass($valueObject);
Expand All @@ -433,7 +440,7 @@ public function registerValueObject($valueObject, $valueMap = null)
$valueObject = get_class($valueObject);
}

if (is_null($valueMap)) {
if ($valueMap === null) {
$valueMap = $valueObject . 'Map';
}

Expand Down Expand Up @@ -465,6 +472,7 @@ public function getValueObjectInstance($valueObject)
*/
public function registerPlugin($plugin)
{
/** @var AnaloguePluginInterface $plugin */
$plugin = new $plugin($this);

$this->events = array_merge($this->events, $plugin->getCustomEvents());
Expand All @@ -478,14 +486,15 @@ public function registerPlugin($plugin)
*
* @param string $event
* @param \Closure $callback
* @throws \Exception
* @throws \LogicException
* @return void
*/
public function registerGlobalEvent($event, $callback)
{
if (!in_array($event, $this->events)) {
throw new \Exception("Analogue : Event $event doesn't exist");
if (!in_array($event, $this->events, false)) {
throw new \LogicException("Analogue : Event $event doesn't exist");
}

$this->eventDispatcher->listen("analogue.{$event}.*", $callback);
}

Expand All @@ -495,6 +504,7 @@ public function registerGlobalEvent($event, $callback)
* @param mixed $entity
* @throws MappingException
* @return mixed
* @throws \InvalidArgumentException
*/
public function store($entity)
{
Expand All @@ -507,6 +517,7 @@ public function store($entity)
* @param mixed $entity
* @throws MappingException
* @return \Illuminate\Support\Collection|null
* @throws \InvalidArgumentException
*/
public function delete($entity)
{
Expand All @@ -519,6 +530,7 @@ public function delete($entity)
* @param mixed $entity
* @throws MappingException
* @return Query
* @throws \InvalidArgumentException
*/
public function query($entity)
{
Expand All @@ -531,6 +543,7 @@ public function query($entity)
* @param mixed $entity
* @throws MappingException
* @return Query
* @throws \InvalidArgumentException
*/
public function globalQuery($entity)
{
Expand All @@ -554,7 +567,7 @@ public function morphMap(array $morphMap)
*/
public function getMorphMap($class)
{
$key = array_search($class, $this->morphMap);
$key = array_search($class, $this->morphMap, false);

return $key !== false ? $key : $class;
}
Expand Down
1 change: 1 addition & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Analogue\ORM\System\Manager;
use Analogue\ORM\System\Mapper;

if (! function_exists('analogue')) {

Expand Down

0 comments on commit f5b0b10

Please sign in to comment.