@@ -90,6 +90,10 @@ |
||
| 90 | 90 | return $reversedEntities; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | + /** |
|
| 94 | + * @param string $entityType |
|
| 95 | + * @param string $idName |
|
| 96 | + */ |
|
| 93 | 97 | public static function transform($value, $context, EntityManagerInterface $entityManager, $entityType, $idName, array $contextPropertyMap = array()) { |
| 94 | 98 | $data = static::transformHelper($value, $context, $idName, $contextPropertyMap); |
| 95 | 99 | $entity = $entityManager->repository($entityType)->byId($data['id']); |
@@ -47,8 +47,7 @@ |
||
| 47 | 47 | $this->_raw->{$prop} = $val; |
| 48 | 48 | if (method_exists($val, 'raw')) { |
| 49 | 49 | $this->_raw->{$prop} = $val->raw(); |
| 50 | - } |
|
| 51 | - elseif (is_array($val)) { |
|
| 50 | + } elseif (is_array($val)) { |
|
| 52 | 51 | $this->_raw->{$prop} = array(); |
| 53 | 52 | foreach ($val as $v) { |
| 54 | 53 | $this->_raw->{$prop}[] = method_exists($v, 'raw') ? $v->raw() : $v; |
@@ -220,7 +220,8 @@ |
||
| 220 | 220 | /** |
| 221 | 221 | * Gets the property map. |
| 222 | 222 | * |
| 223 | - * @return FastNorth\PropertyMapper\Map |
|
| 223 | + * @param string $entityType |
|
| 224 | + * @return \FastNorth\PropertyMapper\MapInterface |
|
| 224 | 225 | * The property map. |
| 225 | 226 | */ |
| 226 | 227 | protected function getPropertyMap($entityType) { |
@@ -199,13 +199,13 @@ |
||
| 199 | 199 | $transform = $args[2][0]; |
| 200 | 200 | $reverse = $args[2][1]; |
| 201 | 201 | $args[2] = new Callback( |
| 202 | - function ($value, $context) use ($entityManager, $transform) { |
|
| 202 | + function($value, $context) use ($entityManager, $transform) { |
|
| 203 | 203 | if ($entityManager->isEmptyValue($value)) { |
| 204 | 204 | return $value; |
| 205 | 205 | } |
| 206 | 206 | return call_user_func_array($transform, array($value, $context, $entityManager)); |
| 207 | 207 | }, |
| 208 | - function ($value, $context) use ($entityManager, $reverse) { |
|
| 208 | + function($value, $context) use ($entityManager, $reverse) { |
|
| 209 | 209 | if ($entityManager->isEmptyValue($value)) { |
| 210 | 210 | return $value; |
| 211 | 211 | } |
@@ -77,8 +77,7 @@ |
||
| 77 | 77 | if (isset($this->repository[$mapped->id])) { |
| 78 | 78 | $entity = $this->repository[$mapped->id]; |
| 79 | 79 | $entity->update($mapped); |
| 80 | - } |
|
| 81 | - else { |
|
| 80 | + } else { |
|
| 82 | 81 | $factory = $this->entityManager->factory($this->getEntityTypeName()); |
| 83 | 82 | $this->repository[$mapped->id] = $factory->create($mapped, $this->getEntityTypeName(), FALSE); |
| 84 | 83 | } |
@@ -6,10 +6,10 @@ |
||
| 6 | 6 | |
| 7 | 7 | namespace TheSportsDb\Entity; |
| 8 | 8 | |
| 9 | +use FastNorth\PropertyMapper\Map; |
|
| 10 | +use FastNorth\PropertyMapper\MapperInterface; |
|
| 9 | 11 | use TheSportsDb\Entity\Factory\FactoryContainerInterface; |
| 10 | 12 | use TheSportsDb\Entity\Repository\RepositoryContainerInterface; |
| 11 | -use FastNorth\PropertyMapper\MapperInterface; |
|
| 12 | -use FastNorth\PropertyMapper\Map; |
|
| 13 | 13 | use TheSportsDb\PropertyMapper\Transformer\Callback; |
| 14 | 14 | |
| 15 | 15 | /** |
@@ -32,16 +32,10 @@ discard block |
||
| 32 | 32 | /** |
| 33 | 33 | * Creates a \TheSportsDb\Facotory\Factory object. |
| 34 | 34 | * |
| 35 | - * @param TheSportsDb\Http\TheSportsDbClientInterface $sportsDbClient |
|
| 35 | + * @param TheSportsDbClientInterface $sportsDbClient |
|
| 36 | 36 | * The sports db client to make the requests. |
| 37 | - * @param string $realClass |
|
| 38 | - * The fully qualified classname of the entity to create. |
|
| 39 | - * @param string $proxyClass |
|
| 40 | - * The fully qualified classname of the proxy entity to create. |
|
| 41 | - * @param TheSportsDb\Entity\EntityManagerInterface $entityManager |
|
| 37 | + * @param EntityManagerInterface $entityManager |
|
| 42 | 38 | * The factory container. |
| 43 | - * @param MapperInterface $propertyMapper |
|
| 44 | - * The property mapper. |
|
| 45 | 39 | */ |
| 46 | 40 | public function __construct(TheSportsDbClientInterface $sportsDbClient, EntityManagerInterface $entityManager = NULL) { |
| 47 | 41 | $this->sportsDbClient = $sportsDbClient; |
@@ -76,6 +70,9 @@ discard block |
||
| 76 | 70 | return $entity; |
| 77 | 71 | } |
| 78 | 72 | |
| 73 | + /** |
|
| 74 | + * @param string $entityType |
|
| 75 | + */ |
|
| 79 | 76 | public function isFullObject(\stdClass $object, $entityType) { |
| 80 | 77 | $reflection = new \ReflectionClass($this->entityManager->getClass($entityType)); |
| 81 | 78 | $defaultProperties = $reflection->getDefaultProperties(); |
@@ -57,16 +57,14 @@ |
||
| 57 | 57 | $reflection = new \ReflectionClass($this->entityManager->getClass($entityType)); |
| 58 | 58 | if ($mapProperties) { |
| 59 | 59 | $givenProperties = $this->entityManager->mapProperties($values, $entityType); |
| 60 | - } |
|
| 61 | - else { |
|
| 60 | + } else { |
|
| 62 | 61 | $givenProperties = $values; |
| 63 | 62 | } |
| 64 | 63 | // Not all properties are loaded, return a proxy. |
| 65 | 64 | if (!$this->isFullObject($givenProperties, $entityType)) { |
| 66 | 65 | $proxyReflection = new \ReflectionClass($this->entityManager->getClass($entityType, 'proxy')); |
| 67 | 66 | $entity = $proxyReflection->newInstance($givenProperties); |
| 68 | - } |
|
| 69 | - else { |
|
| 67 | + } else { |
|
| 70 | 68 | // All properties are loaded, return a full object. |
| 71 | 69 | $entity = $reflection->newInstance($givenProperties); |
| 72 | 70 | } |
@@ -6,12 +6,12 @@ |
||
| 6 | 6 | |
| 7 | 7 | namespace TheSportsDb\Entity\Factory; |
| 8 | 8 | |
| 9 | -use TheSportsDb\Http\TheSportsDbClientInterface; |
|
| 10 | -use TheSportsDb\Entity\EntityInterface; |
|
| 11 | -use TheSportsDb\Entity\Proxy\ProxyInterface; |
|
| 12 | 9 | use FastNorth\PropertyMapper\MapperInterface; |
| 13 | -use TheSportsDb\Entity\EntityManagerInterface; |
|
| 10 | +use TheSportsDb\Entity\EntityInterface; |
|
| 14 | 11 | use TheSportsDb\Entity\EntityManagerConsumerTrait; |
| 12 | +use TheSportsDb\Entity\EntityManagerInterface; |
|
| 13 | +use TheSportsDb\Entity\Proxy\ProxyInterface; |
|
| 14 | +use TheSportsDb\Http\TheSportsDbClientInterface; |
|
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * Default implementation of factories. |
@@ -44,10 +44,6 @@ |
||
| 44 | 44 | * |
| 45 | 45 | * @param \stdClass $values |
| 46 | 46 | * The sport data. |
| 47 | - * @param \TheSportsDb\Http\TheSportsDbClientInterface $sportsDbClient |
|
| 48 | - * A sports db client |
|
| 49 | - * @param \TheSportsDb\Entity\Factory\FactoryInterface $factory |
|
| 50 | - * The sport factory. |
|
| 51 | 47 | */ |
| 52 | 48 | public function __construct(\stdClass $values) { |
| 53 | 49 | $this->properties = new \stdClass(); |
@@ -100,8 +100,7 @@ discard block |
||
| 100 | 100 | // full yet, so load it first and repeat the operation. |
| 101 | 101 | if (method_exists($this, 'load' . ucfirst($name))) { |
| 102 | 102 | $this->{'load' . ucfirst($name)}(); |
| 103 | - } |
|
| 104 | - else { |
|
| 103 | + } else { |
|
| 105 | 104 | $this->load(); |
| 106 | 105 | } |
| 107 | 106 | return $this->get($name); |
@@ -136,8 +135,7 @@ discard block |
||
| 136 | 135 | $this->_raw->{$prop} = $val; |
| 137 | 136 | if (method_exists($val, 'raw')) { |
| 138 | 137 | $this->_raw->{$prop} = $val->raw(); |
| 139 | - } |
|
| 140 | - elseif (is_array($val)) { |
|
| 138 | + } elseif (is_array($val)) { |
|
| 141 | 139 | $this->_raw->{$prop} = array(); |
| 142 | 140 | foreach ($val as $v) { |
| 143 | 141 | $this->_raw->{$prop}[] = method_exists($v, 'raw') ? $v->raw() : $v; |
@@ -6,10 +6,10 @@ |
||
| 6 | 6 | |
| 7 | 7 | namespace TheSportsDb\Entity\Proxy; |
| 8 | 8 | |
| 9 | -use TheSportsDb\Http\TheSportsDbClientInterface; |
|
| 10 | -use TheSportsDb\Entity\EntityManagerInterface; |
|
| 11 | 9 | use TheSportsDb\Entity\EntityInterface; |
| 12 | 10 | use TheSportsDb\Entity\EntityManagerConsumerTrait; |
| 11 | +use TheSportsDb\Entity\EntityManagerInterface; |
|
| 12 | +use TheSportsDb\Http\TheSportsDbClientInterface; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * Default implementation of proxy objects. |
@@ -51,7 +51,7 @@ |
||
| 51 | 51 | /** |
| 52 | 52 | * Get a league by id. |
| 53 | 53 | * |
| 54 | - * @param int $league_id |
|
| 54 | + * @param int $leagueId |
|
| 55 | 55 | * The league id. |
| 56 | 56 | * |
| 57 | 57 | * @return \TheSportsDb\Entity\LeagueInterface |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | )), |
| 30 | 30 | array('strDescriptionEN', 'description'), |
| 31 | 31 | array('intHomeScore', 'homeScore'), |
| 32 | - array('intRound' , 'round'), |
|
| 32 | + array('intRound', 'round'), |
|
| 33 | 33 | array('intAwayScore', 'awayScore'), |
| 34 | 34 | array('intSpectators', 'spectators'), |
| 35 | 35 | array('strHomeGoalDetails', 'homeGoalDetails'), |
@@ -31,47 +31,47 @@ |
||
| 31 | 31 | )), |
| 32 | 32 | array('strDivision', 'division'), |
| 33 | 33 | array('strManager', 'manager'), |
| 34 | - array('strStadium', 'stadium'), |
|
| 34 | + array('strStadium', 'stadium'), |
|
| 35 | 35 | array('strKeywords', 'keywords'), |
| 36 | - array('strRSS', 'rss'), |
|
| 36 | + array('strRSS', 'rss'), |
|
| 37 | 37 | array('strStadiumThumb', 'stadiumThumb'), |
| 38 | 38 | array('strStadiumDescription', 'stadiumDescription'), |
| 39 | - array('strStadiumLocation', 'stadiumLocation'), |
|
| 40 | - array('intStadiumCapacity', 'stadiumCapacity'), |
|
| 41 | - array('strWebsite', 'website'), |
|
| 39 | + array('strStadiumLocation', 'stadiumLocation'), |
|
| 40 | + array('intStadiumCapacity', 'stadiumCapacity'), |
|
| 41 | + array('strWebsite', 'website'), |
|
| 42 | 42 | array('strFacebook', 'facebook'), |
| 43 | - array('strTwitter', 'twitter'), |
|
| 44 | - array('strInstagram', 'instagram'), |
|
| 45 | - array('strDescriptionEN', 'description'), |
|
| 46 | - array('strGender', 'gender'), |
|
| 43 | + array('strTwitter', 'twitter'), |
|
| 44 | + array('strInstagram', 'instagram'), |
|
| 45 | + array('strDescriptionEN', 'description'), |
|
| 46 | + array('strGender', 'gender'), |
|
| 47 | 47 | array('strCountry', 'country'), |
| 48 | - array('strTeamBadge', 'badge'), |
|
| 48 | + array('strTeamBadge', 'badge'), |
|
| 49 | 49 | array('strTeamJersey', 'jersey'), |
| 50 | - array('strTeamLogo', 'logo'), |
|
| 51 | - array('strTeamBanner', 'banner'), |
|
| 52 | - array('strYoutube', 'youtube'), |
|
| 50 | + array('strTeamLogo', 'logo'), |
|
| 51 | + array('strTeamBanner', 'banner'), |
|
| 52 | + array('strYoutube', 'youtube'), |
|
| 53 | 53 | array('strLocked', 'locked'), |
| 54 | 54 | // idSoccerXML |
| 55 | 55 | // intLoved |
| 56 | 56 | // strLeague |
| 57 | 57 | // strDescriptionDE |
| 58 | - // strDescriptionFR |
|
| 59 | - // strDescriptionCN |
|
| 60 | - // strDescriptionIT |
|
| 61 | - // strDescriptionJP |
|
| 62 | - // strDescriptionRU |
|
| 63 | - // strDescriptionES |
|
| 64 | - // strDescriptionPT |
|
| 65 | - // strDescriptionSE |
|
| 66 | - // strDescriptionNL |
|
| 67 | - // strDescriptionHU |
|
| 68 | - // strDescriptionNO |
|
| 69 | - // strDescriptionIL |
|
| 70 | - // strDescriptionPL |
|
| 58 | + // strDescriptionFR |
|
| 59 | + // strDescriptionCN |
|
| 60 | + // strDescriptionIT |
|
| 61 | + // strDescriptionJP |
|
| 62 | + // strDescriptionRU |
|
| 63 | + // strDescriptionES |
|
| 64 | + // strDescriptionPT |
|
| 65 | + // strDescriptionSE |
|
| 66 | + // strDescriptionNL |
|
| 67 | + // strDescriptionHU |
|
| 68 | + // strDescriptionNO |
|
| 69 | + // strDescriptionIL |
|
| 70 | + // strDescriptionPL |
|
| 71 | 71 | // strTeamFanart1 |
| 72 | - // strTeamFanart2 |
|
| 73 | - // strTeamFanart3 |
|
| 74 | - // strTeamFanart4 |
|
| 72 | + // strTeamFanart2 |
|
| 73 | + // strTeamFanart3 |
|
| 74 | + // strTeamFanart4 |
|
| 75 | 75 | ); |
| 76 | 76 | |
| 77 | 77 | protected $id; |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | public function byId($id) { |
| 50 | 50 | if (!isset($this->repository[$id])) { |
| 51 | - $factory = $this->entityManager->factory($this->getEntityTypeName()); |
|
| 51 | + $factory = $this->entityManager->factory($this->getEntityTypeName()); |
|
| 52 | 52 | $this->repository[$id] = $factory->create( |
| 53 | 53 | (object) array('id' => $id), |
| 54 | 54 | $this->getEntityTypeName(), |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $entity->update($mapped); |
| 80 | 80 | } |
| 81 | 81 | else { |
| 82 | - $factory = $this->entityManager->factory($this->getEntityTypeName()); |
|
| 82 | + $factory = $this->entityManager->factory($this->getEntityTypeName()); |
|
| 83 | 83 | $this->repository[$mapped->id] = $factory->create($mapped, $this->getEntityTypeName(), FALSE); |
| 84 | 84 | } |
| 85 | 85 | return $this->repository[$mapped->id]; |
@@ -77,8 +77,7 @@ |
||
| 77 | 77 | if (isset($this->repository[$mapped->id])) { |
| 78 | 78 | $entity = $this->repository[$mapped->id]; |
| 79 | 79 | $entity->update($mapped); |
| 80 | - } |
|
| 81 | - else { |
|
| 80 | + } else { |
|
| 82 | 81 | $factory = $this->entityManager->factory($this->getEntityTypeName()); |
| 83 | 82 | $this->repository[$mapped->id] = $factory->create($mapped, $this->getEntityTypeName(), FALSE); |
| 84 | 83 | } |
@@ -6,8 +6,8 @@ |
||
| 6 | 6 | |
| 7 | 7 | namespace TheSportsDb\Entity\Repository; |
| 8 | 8 | |
| 9 | -use TheSportsDb\Entity\EntityManagerInterface; |
|
| 10 | 9 | use TheSportsDb\Entity\EntityManagerConsumerTrait; |
| 10 | +use TheSportsDb\Entity\EntityManagerInterface; |
|
| 11 | 11 | use TheSportsDb\Http\TheSportsDbClientInterface; |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | public function byId($id) { |
| 22 | 22 | if (!isset($this->repository[$id])) { |
| 23 | 23 | list($name, $league) = explode('|', $id); |
| 24 | - $factory = $this->entityManager->factory($this->getEntityTypeName()); |
|
| 24 | + $factory = $this->entityManager->factory($this->getEntityTypeName()); |
|
| 25 | 25 | $this->repository[$id] = $factory->create( |
| 26 | 26 | $this->entityManager->reverseMapProperties( |
| 27 | 27 | (object) array('id' => $id, 'name' => $name, 'league' => (object) array('id' => $league)), |