Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync master #276

Merged
merged 55 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
97dbca6
Merge pull request #249 from analogueorm/master
RemiCollin Feb 8, 2018
6197c6b
Merge pull request #252 from analogueorm/master
RemiCollin Feb 23, 2018
7ba3d9c
Merge pull request #253 from analogueorm/master
RemiCollin Feb 23, 2018
35d26ed
Merge pull request #255 from analogueorm/master
RemiCollin Feb 26, 2018
e3cb69d
Add support for Collection::sortKeys()
RemiCollin Mar 1, 2018
e988c43
Add failing test. Move builders to own namespace
RemiCollin Mar 1, 2018
0cb22ea
Fix EmbedsMany
cappuc Mar 1, 2018
359f830
ResultBuilder refactoring stage 1
RemiCollin Mar 6, 2018
673c045
Add support for Collection::whereInstanceof()
RemiCollin Mar 7, 2018
9fe221e
Apply fixes from StyleCI
RemiCollin Mar 7, 2018
9375bab
Merge pull request #257 from analogueorm/analysis-zOZWkJ
RemiCollin Mar 7, 2018
b58ff07
Implemented asJson method on embeded relationships
cappuc Mar 7, 2018
4718b82
Fix Style
cappuc Mar 7, 2018
c3b3c46
Merge pull request #256 from cappuc/fix-embeds-many
RemiCollin Mar 8, 2018
21e5f3a
Set has many relationships to empty collection instead of null
cappuc Mar 7, 2018
43ae2b3
Fix Missing Attribute asJson
cappuc Mar 8, 2018
268787f
Merge pull request #258 from cappuc/fix-has-many
RemiCollin Mar 9, 2018
3c19f07
Merge pull request #259 from cappuc/fix-embeds-many
RemiCollin Mar 9, 2018
5a96b9d
Simplify Entity fill
cappuc Mar 15, 2018
e02226c
Cache : handle edge case when entity key is a MongoDB ObjectId
RemiCollin Mar 15, 2018
1de6864
Apply fixes from StyleCI
RemiCollin Mar 15, 2018
cd95fb5
Merge pull request #261 from analogueorm/analysis-XVWADw
RemiCollin Mar 15, 2018
a24a78b
Add version constraints for factory
RemiCollin Mar 15, 2018
efa425d
Merge branch '5.6' of github.com:analogueorm/analogue into 5.6
RemiCollin Mar 15, 2018
34ddeae
Merge pull request #260 from cappuc/entity-fill
RemiCollin Mar 21, 2018
6a72b23
Allow push() and prepend() not to load the full related collection
RemiCollin May 4, 2018
92e732f
Merge branch '5.6' of github.com:analogueorm/analogue into 5.6
RemiCollin May 4, 2018
8f7ab6a
Apply fixes from StyleCI
RemiCollin May 4, 2018
8c94143
Merge pull request #264 from analogueorm/analysis-qJOGwD
RemiCollin May 4, 2018
c518929
Merge branch '5.6' into fix/inheritance-eager-loading
RemiCollin May 28, 2018
8d76589
Refactoring result builders
RemiCollin May 28, 2018
9a20f9c
Do not build same type twice
RemiCollin May 28, 2018
03fddeb
Apply fixes from StyleCI
RemiCollin May 28, 2018
b6d334b
Merge pull request #266 from analogueorm/analysis-XNaRJp
RemiCollin May 28, 2018
41d7556
Merge pull request #265 from analogueorm/fix/inheritance-eager-loading
RemiCollin May 28, 2018
9806b45
Pushed item after a proxy loading would not be pushed into the Base c…
RemiCollin May 29, 2018
ccc862e
Apply fixes from StyleCI
RemiCollin May 29, 2018
e524849
Merge pull request #267 from analogueorm/analysis-8mGOrp
RemiCollin May 29, 2018
9f3abcf
Make softdeletes complient to object events
RemiCollin May 30, 2018
b46fa22
Fix conflicts
RemiCollin May 30, 2018
547f765
Apply fixes from StyleCI
RemiCollin May 30, 2018
8c09f91
Merge pull request #269 from analogueorm/analysis-zERWw9
RemiCollin May 30, 2018
d1548cb
Use base collection for unique(), contains()
RemiCollin May 30, 2018
53a38dc
Add more test for eager loading
RemiCollin Jun 15, 2018
a06ff22
Add more eager loading test
RemiCollin Jun 19, 2018
51546ce
Fix morphTo eagerloading
RemiCollin Jun 19, 2018
9c8db81
Apply fixes from StyleCI
RemiCollin Jun 19, 2018
e953af5
Merge pull request #271 from analogueorm/analysis-z917PP
RemiCollin Jun 19, 2018
13e34b5
Fix building process of lazy loaded relationships when target type is…
RemiCollin Jun 19, 2018
d49cb6d
Merge branch '5.6' of github.com:analogueorm/analogue into 5.6
RemiCollin Jun 19, 2018
5226464
Apply fixes from StyleCI
RemiCollin Jun 19, 2018
9019527
Merge pull request #272 from analogueorm/analysis-86vEw6
RemiCollin Jun 19, 2018
7cdff47
feature - Add the ability to map columns to properities.
adrorocker Jan 31, 2019
99525b5
Update readme.md
RemiCollin Feb 1, 2019
8833e55
Merge pull request #275 from adrorocker/5.6
RemiCollin Feb 1, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,52 @@
# Changelog

## Analogue 5.3
#### Version 5.6
- Laravel 5.6 support
- Bring back ability to map DB columns that name are not equals to the name of the attribute.
- Add ability to map DB snake case columns to camel case properties on entities.

- It is now possible to for the mapper to use IoC when instantiating entities.
- Native implementation of Single Table Inheritance pattern.
#### Version 5.5
- Laravel 5.5 support
- Pushed miminum requirements to PHP7
- Complete support of Plain PHP objects via reflection based hydration/dehydration
- Improved Lazy-loading proxies.
- New, more flexible Value Object implementation, that can now be defined as `embedsOne()`, `embedsMany()` relationships
- Embedded value object can now be stored as a mysql JSON field
- Analogue entities can now be instantiated using laravel's `IoC Container` or any PSR-11 compatible container.
- Added [MongoDB](https://github.com/analogueorm/mongodb) driver.
- Package auto discovery (L5.5)

#### Version 5.4
- Illuminate 5.4 Compatibility.
- Add Abillity to map DB columns that name are not equals to the name of the attribute.

#### Version 5.3
- Illuminate 5.3 Compatibility.
- Now fully support Single Table Inheritance.
- EntityCollection is now correctly keyed by id

#### Version 5.1
- Illuminate 5.1 + 5.2 Compatibility.

#### Version 5.0
- Analogue version now mirrors illuminate version.

#### Version 2.1.3
- Mutator feature in base Entity class.
- Ability to add entities to a proxy collection without lazyloading it.

### Version 2.1

- Package is now framework agnostic.
- Now support any plain object that implements Mappable interface.
- Introducing a MappableTrait for quick implementation.
- Queries can now be run directly on the mapper Object.
- Store/Delete methods now accept a array and collections as argument.
- EntityMap are now autodected when in the same namespace as the entity.
- Base Entity class Supports hidden attributes.
- Many workflow related improvements.

### Version 2.0

- Laravel 5 Support.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"mockery/mockery": "0.9.*",
"symfony/css-selector": "2.8.*|3.0.*|4.0.*",
"symfony/dom-crawler": "2.8.*|3.0.*|4.0.*",
"analogue/factory": "dev-master",
"analogue/factory": "1.2.*|1.3.*",
"laravel/browser-kit-testing": "^1.0"
},
"suggest": {
Expand Down
6 changes: 5 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(this project is looking for a new maintainer)

# Analogue ORM
[![Latest Stable Version](https://poser.pugx.org/analogue/orm/v/stable)](https://packagist.org/packages/analogue/orm)
[![Latest Unstable Version](https://poser.pugx.org/analogue/orm/v/unstable)](https://packagist.org/packages/analogue/orm)
Expand Down Expand Up @@ -122,6 +124,8 @@ Check the [Documentation](https://github.com/analogueorm/analogue/wiki) for more

#### Version 5.6
- Laravel 5.6 support
- Bring back ability to map DB columns that name are not equals to the name of the attribute.
- Add ability to map DB snake case columns to camel case properties on entities.

#### Version 5.5
- Laravel 5.5 support
Expand All @@ -136,7 +140,7 @@ Check the [Documentation](https://github.com/analogueorm/analogue/wiki) for more

#### Version 5.4
- Illuminate 5.4 Compatibility.
- Add Abillity to map DB columns that name are not equals to the name of the attribute.
- Add Ability to map DB columns that name are not equals to the name of the attribute.

#### Version 5.3
- Illuminate 5.3 Compatibility.
Expand Down
1 change: 1 addition & 0 deletions src/AnalogueServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function register()

// If the cache is pre laravel 5.5, it doesn't implements PSR-16, so we'll skip it.
$cache = $app->make(CacheRepository::class);

if ($cache instanceof CacheInterface) {
$manager->setCache($cache);
}
Expand Down
7 changes: 1 addition & 6 deletions src/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,7 @@ public function toArray()
public function fill(array $attributes)
{
foreach ($attributes as $key => $attribute) {
if ($this->hasSetMutator($key)) {
$method = 'set'.$this->getMutatorMethod($key);
$this->attributes[$key] = $this->$method($attribute);
} else {
$this->attributes[$key] = $attribute;
}
$this->{$key} = $attribute;
}
}
}
38 changes: 0 additions & 38 deletions src/EntityCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,27 +139,6 @@ public function offsetSet($key, $value)
}
}

/**
* Determine if a key exists in the collection.
*
* @param mixed $key
* @param mixed|null $value
*
* @return bool
*/
// public function contains($key, $value = null)
// {
// if (func_num_args() == 2) {
// return !$this->where($key, $value)->isEmpty();
// }

// if ($this->useAsCallable($key)) {
// return !is_null($this->first($key));
// }

// return !is_null($this->find($key));
// }

/**
* Fetch a nested element of the collection.
*
Expand Down Expand Up @@ -427,23 +406,6 @@ public function lists($value, $key = null)
return $this->pluck($value, $key);
}

/**
* Return only unique items from the collection.
*
* @param string|null $key
* @param bool $strict
*
* @throws MappingException
*
* @return self
*/
public function unique($key = null, $strict = false)
{
$dictionary = $this->getDictionary();

return new static(array_values($dictionary));
}

/**
* Unset the item at a given offset.
*
Expand Down
129 changes: 120 additions & 9 deletions src/EntityMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,14 @@ class EntityMap
*/
private $isBooted = false;

/**
* Set this property to true if you wish to use camel case
* properties.
*
* @var bool
*/
protected $camelCaseHydratation = false;

/**
* Return Domain class attributes, useful when mapping to a Plain PHP Object.
*
Expand Down Expand Up @@ -1223,21 +1231,29 @@ public function morphTo($entity, string $name = null, string $type = null, strin

if (is_null($class = $wrapper->getEntityAttribute($type))) {
return new MorphTo(
$mapper, $entity, $id, null, $type, $name
$mapper,
$entity,
$id,
null,
$type,
$name
);
}

// If we are not eager loading the relationship we will essentially treat this
// as a belongs-to style relationship since morph-to extends that class and
// we will pass in the appropriate values so that it behaves as expected.
else {
} else {
// If we are not eager loading the relationship we will essentially treat this
// as a belongs-to style relationship since morph-to extends that class and
// we will pass in the appropriate values so that it behaves as expected.
$class = Manager::getInstance()->getInverseMorphMap($class);
$relatedMapper = Manager::getInstance()->mapper($class);

$foreignKey = $relatedMapper->getEntityMap()->getKeyName();

return new MorphTo(
$relatedMapper, $entity, $id, $foreignKey, $type, $name
$relatedMapper,
$entity,
$id,
$foreignKey,
$type,
$name
);
}
}
Expand Down Expand Up @@ -1556,7 +1572,10 @@ public function getMorphClass(): string
*/
public function newCollection(array $entities = []): EntityCollection
{
return new EntityCollection($entities);
$collection = new EntityCollection($entities);
$keyName = $this->getAttributeNameForColumn($this->getKeyName());

return $collection->keyBy($keyName);
}

/**
Expand Down Expand Up @@ -1704,4 +1723,96 @@ public function __call(string $method, array $parameters)

return call_user_func_array($this->dynamicRelationships[$method], $parameters);
}

/**
* Maps the names of the column names to the appropriate attributes
* of an entity if the $attributes property of an EntityMap is an
* associative array.
*
* @param array $array
*
* @return array
*/
public function getAttributeNamesFromColumns($array)
{
if (!empty($this->mappings)) {
$newArray = [];
foreach ($array as $key => $value) {
$attributeName = isset($this->mappings[$key]) ? $this->mappings[$key] : $key;
$newArray[$attributeName] = $value;
}

return $newArray;
}
if ($this->camelCaseHydratation) {
foreach ($array as $key => $value) {
$attributeName = camel_case($key);
$newArray[$attributeName] = $value;
}

return $newArray;
}

return $array;
}

/**
* Gets the entity attribute name of a given column in a table.
*
* @param string $columnName
*
* @return string
*/
public function getAttributeNameForColumn($columnName)
{
if (!empty($this->mappings)) {
if (isset($this->mappings[$columnName])) {
return $this->mappings[$columnName];
}
}

return $columnName;
}

/**
* Maps the attribute names of an entity to the appropriate
* column names in the database if the $attributes property of
* an EntityMap is an associative array.
*
* @param array $array
*
* @return array
*/
public function getColumnNamesFromAttributes($array)
{
if (!empty($this->mappings)) {
$newArray = [];
$flipped = array_flip($this->mappings);
foreach ($array as $key => $value) {
$attributeName = isset($flipped[$key]) ? $flipped[$key] : $key;
$newArray[$attributeName] = $value;
}

return $newArray;
}
if ($this->camelCaseHydratation) {
foreach ($array as $key => $value) {
$attributeName = snake_case($key);
$newArray[$attributeName] = $value;
}

return $newArray;
}

return $array;
}

public function hasAttribute($attribute)
{
if (!empty($this->mappings)) {
return in_array($attribute, array_values($this->mappings));
}

return in_array($attribute, $attributes);
}
}
24 changes: 24 additions & 0 deletions src/LengthAwareEntityPaginator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Analogue\ORM;

use Illuminate\Pagination\LengthAwarePaginator;

class LengthAwareEntityPaginator extends LengthAwarePaginator
{
/**
* Paginator constructor.
*
* @param mixed $items
* @param int $total
* @param int $perPage
* @param null $currentPage
* @param array $options
*/
public function __construct($items, $total, $perPage, $currentPage = null, array $options = [])
{
$items = $items instanceof EntityCollection ? $items : EntityCollection::make($items);

parent::__construct($items, $total, $perPage, $currentPage, $options);
}
}
9 changes: 9 additions & 0 deletions src/Plugins/SoftDeletes/Events/Restored.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Analogue\ORM\Plugins\SoftDeletes\Events;

use Analogue\ORM\Events\Event;

class Restored extends Event
{
}
9 changes: 9 additions & 0 deletions src/Plugins/SoftDeletes/Events/Restoring.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Analogue\ORM\Plugins\SoftDeletes\Events;

use Analogue\ORM\Events\Event;

class Restoring extends Event
{
}
Loading