Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: spiral-modules/odm
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.9.1
Choose a base ref
...
head repository: spiral-modules/odm
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 18 commits
  • 28 files changed
  • 1 contributor

Commits on Feb 6, 2017

  1. Update CHANGELOG.md

    wolfy-j authored Feb 6, 2017
    Copy the full SHA
    9522542 View commit details

Commits on Feb 7, 2017

  1. deps

    wolfy-j committed Feb 7, 2017
    Copy the full SHA
    a4deacf View commit details
  2. Copy the full SHA
    ae4761d View commit details
  3. deps

    wolfy-j committed Feb 7, 2017
    Copy the full SHA
    43d5d74 View commit details
  4. deps

    wolfy-j committed Feb 7, 2017
    Copy the full SHA
    3d8a141 View commit details
  5. refactoring

    wolfy-j committed Feb 7, 2017
    Copy the full SHA
    cb8d493 View commit details
  6. exception

    wolfy-j committed Feb 7, 2017
    Copy the full SHA
    4f6c1fb View commit details
  7. CS

    wolfy-j committed Feb 7, 2017
    Copy the full SHA
    e9b9d9c View commit details
  8. no public fields

    wolfy-j committed Feb 7, 2017
    Copy the full SHA
    aec85bd View commit details
  9. no public fields

    wolfy-j committed Feb 7, 2017
    Copy the full SHA
    dfd97c8 View commit details
  10. no public fields

    wolfy-j committed Feb 7, 2017
    Copy the full SHA
    0380f47 View commit details

Commits on Feb 8, 2017

  1. better accessor

    wolfy-j committed Feb 8, 2017
    Copy the full SHA
    db4eb55 View commit details
  2. Update CHANGELOG.md

    wolfy-j authored Feb 8, 2017
    Copy the full SHA
    2e2c683 View commit details

Commits on Feb 12, 2017

  1. new pagination

    wolfy-j committed Feb 12, 2017
    Copy the full SHA
    1940c53 View commit details
  2. Copy the full SHA
    9349050 View commit details

Commits on Mar 22, 2017

  1. Update DocumentEntity.php

    wolfy-j authored Mar 22, 2017
    Copy the full SHA
    907fe0c View commit details

Commits on Mar 23, 2017

  1. Update .travis.yml

    wolfy-j authored Mar 23, 2017
    Copy the full SHA
    af55950 View commit details

Commits on Apr 5, 2017

  1. Update composer.json

    wolfy-j authored Apr 5, 2017
    Copy the full SHA
    0608769 View commit details
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -15,8 +15,8 @@ install:
- composer install --no-interaction --prefer-source

script:
- phpunit --coverage-clover=clover.xml
- vendor/bin/phpunit --coverage-clover=clover.xml

after_script:
- wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar
- php coveralls.phar --verbose --config .coveralls.yml
- php coveralls.phar --verbose --config .coveralls.yml
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
CHANGELOG for 0.9.0 RC
======================

0.9.6 (08.02.2017)
-----
* bugfix: arrayAccessor did not track change when value was changed directly

0.9.1 (07.02.2017)
-----
* DocumentSource now depends on ODMInterface, not ODM itself
* Code coverage

0.9.0 (04.02.2017)
-----
* Split from components package
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -12,9 +12,12 @@
"require": {
"php": ">=7.0",
"ext-mongodb": ">1.1.0",
"spiral/common": "^0.9",
"spiral/common": "^1.0",
"spiral/models": "^1.0",
"spiral/tokenizer": "^1.0",
"spiral/pagination": "~1.0",
"mongodb/mongodb": "^1.1"
"mongodb/mongodb": "^1.1",
"doctrine/inflector": "^1.1"
},
"require-dev": {
"phpunit/phpunit": "~5.0",
11 changes: 10 additions & 1 deletion source/Spiral/ODM/Accessors/AbstractArray.php
Original file line number Diff line number Diff line change
@@ -20,6 +20,13 @@ abstract class AbstractArray implements CompositableInterface, \Countable, \Iter
{
use SolidableTrait;

/**
* When value changed directly.
*
* @var bool
*/
private $changed = false;

/**
* @var array
*/
@@ -142,6 +149,7 @@ public function setValue($data)
{
//Manually altered arrays must always end in solid state
$this->solidState = true;
$this->changed = true;

//Flushing existed values
$this->values = [];
@@ -155,14 +163,15 @@ public function setValue($data)
*/
public function hasChanges(): bool
{
return !empty($this->atomics);
return $this->changed || !empty($this->atomics);
}

/**
* {@inheritdoc}
*/
public function flushChanges()
{
$this->changed = false;
$this->atomics = [];
}

24 changes: 0 additions & 24 deletions source/Spiral/ODM/Document.php
Original file line number Diff line number Diff line change
@@ -65,12 +65,6 @@ abstract class Document extends DocumentEntity implements ActiveEntityInterface
const DATABASE = null;
const COLLECTION = null;

/**
* When set to true publicFields() method (and jsonSerialize) will replace '_id' property with
* 'id'.
*/
const HIDE_UNDERSCORE_ID = true;

/**
* Set of indexes to be created for associated collection. Use "@options" for additional
* index options.
@@ -129,24 +123,6 @@ public function primaryKey()
return $this->getField('_id', null, false);
}

/**
* {@inheritdoc}
*
* Check model setting HIDE_UNDERSCORE_ID in order to enable/disable automatic conversion of
* '_id' to 'id'.
*/
public function publicValue(): array
{
$public = parent::publicValue();
if (static::HIDE_UNDERSCORE_ID) {
//Replace '_id' property with 'id'
unset($public['_id']);
$public = ['id' => (string)$this->primaryKey()] + $public;
}

return $public;
}

/**
* {@inheritdoc}
*
7 changes: 3 additions & 4 deletions source/Spiral/ODM/DocumentEntity.php
Original file line number Diff line number Diff line change
@@ -57,8 +57,8 @@ abstract class DocumentEntity extends SchematicEntity implements CompositableInt
*/
const SH_INSTANTIATION = 0;
const SH_DEFAULTS = 1;
const SH_COMPOSITIONS = 6;
const SH_AGGREGATIONS = 7;
const SH_COMPOSITIONS = 5;
const SH_AGGREGATIONS = 6;

/**
* Constants used to describe aggregation relations (also used internally to identify
@@ -125,7 +125,6 @@ abstract class DocumentEntity extends SchematicEntity implements CompositableInt
* Model behaviour configurations.
*/
const SECURED = '*';
const HIDDEN = [];
const FILLABLE = [];
const SETTERS = [];
const GETTERS = [];
@@ -502,4 +501,4 @@ private function assertField(string $name)
));
}
}
}
}
26 changes: 2 additions & 24 deletions source/Spiral/ODM/Entities/DocumentCompositor.php
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@

namespace Spiral\ODM\Entities;

use Spiral\Models\PublishableInterface;
use Spiral\Models\Traits\SolidableTrait;
use Spiral\ODM\CompositableInterface;
use Spiral\ODM\Exceptions\CompositorException;
@@ -21,11 +20,7 @@
*
* @todo ArrayAccess?
*/
class DocumentCompositor implements
CompositableInterface,
PublishableInterface,
\Countable,
\IteratorAggregate
class DocumentCompositor implements CompositableInterface, \Countable, \IteratorAggregate
{
use SolidableTrait;

@@ -336,29 +331,12 @@ public function buildAtomics(string $container = ''): array
return $atomics;
}

/**
* Packs only public values of all nested documents.
*
* @return array
*/
public function publicValue(): array
{
$result = [];
foreach ($this->entities as $entity) {
if ($entity instanceof PublishableInterface) {
$result[] = $entity->publicValue();
}
}

return $result;
}

/**
* {@inheritdoc}
*/
public function jsonSerialize()
{
return $this->publicValue();
return $this->packValue();
}

/**
2 changes: 1 addition & 1 deletion source/Spiral/ODM/Entities/DocumentSelector.php
Original file line number Diff line number Diff line change
@@ -317,7 +317,7 @@ public function __destruct()
protected function createCursor(array $fields = [])
{
if ($this->hasPaginator()) {
$paginator = $this->configurePaginator($this->count());
$paginator = $this->getPaginator(true);

//Paginate in isolation
$selector = clone $this;
4 changes: 2 additions & 2 deletions source/Spiral/ODM/ODM.php
Original file line number Diff line number Diff line change
@@ -135,7 +135,7 @@ public function schemaBuilder(bool $locate = true): SchemaBuilder
* @param SchemaBuilder $builder
* @param bool $remember Set to true to remember packed schema in memory.
*/
public function buildSchema(SchemaBuilder $builder, bool $remember = false)
public function setSchema(SchemaBuilder $builder, bool $remember = false)
{
$this->schema = $builder->packSchema();

@@ -151,7 +151,7 @@ public function define(string $class, int $property)
{
if (empty($this->schema)) {
//Update and remember
$this->buildSchema($this->schemaBuilder(), true);
$this->setSchema($this->schemaBuilder(), true);
}

//Check value
1 change: 0 additions & 1 deletion source/Spiral/ODM/Schemas/DocumentSchema.php
Original file line number Diff line number Diff line change
@@ -293,7 +293,6 @@ public function packSchema(SchemaBuilder $builder): array
DocumentEntity::SH_DEFAULTS => $this->packDefaults($builder),

//Entity behaviour
DocumentEntity::SH_HIDDEN => $this->reflection->getHidden(),
DocumentEntity::SH_SECURED => $this->reflection->getSecured(),
DocumentEntity::SH_FILLABLE => $this->reflection->getFillable(),

4 changes: 2 additions & 2 deletions source/Spiral/ODM/Schemas/InheritanceHelper.php
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ public function makeDefinition()

if (empty($fields)) {
throw new DefinitionException(
"Child document '{$schema->getClass()}' of {$this->schema->getClass()} does not have any fields"
"Child document '{$schema->getClass()}' of '{$this->schema->getClass()}' does not have any fields"
);
}

@@ -95,7 +95,7 @@ public function makeDefinition()

if (empty($uniqueField)) {
throw new DefinitionException(
"Child document {$schema} of {$this} does not have any unique field"
"Child document '{$schema->getClass()}' of '{$this->schema->getClass()}' does not have any unique field"
);
}

12 changes: 6 additions & 6 deletions tests/ODM/AccessorsTest.php
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ public function testAccessorConstruction()
$odm = $this->makeODM();

$builder->addSchema($this->makeSchema(Accessed::class));
$odm->buildSchema($builder);
$odm->setSchema($builder);

$entity = $odm->make(Accessed::class, []);
$this->assertInstanceOf(Accessed::class, $entity);
@@ -37,7 +37,7 @@ public function testAccessorWithDefaults()
$odm = $this->makeODM();

$builder->addSchema($this->makeSchema(Accessed::class));
$odm->buildSchema($builder);
$odm->setSchema($builder);

$entity = $odm->make(Accessed::class, [
'tags' => ['a', 'b', 'c']
@@ -59,7 +59,7 @@ public function testArrayAccessorAdd()
$odm = $this->makeODM();

$builder->addSchema($this->makeSchema(Accessed::class));
$odm->buildSchema($builder);
$odm->setSchema($builder);

$entity = $odm->make(Accessed::class, [
'tags' => ['a', 'b', 'c']
@@ -86,7 +86,7 @@ public function testArrayAccessorPull()
$odm = $this->makeODM();

$builder->addSchema($this->makeSchema(Accessed::class));
$odm->buildSchema($builder);
$odm->setSchema($builder);

$entity = $odm->make(Accessed::class, [
'tags' => ['a', 'b', 'c']
@@ -111,7 +111,7 @@ public function testSerilization()
$odm = $this->makeODM();

$builder->addSchema($this->makeSchema(Accessed::class));
$odm->buildSchema($builder);
$odm->setSchema($builder);

$entity = $odm->make(Accessed::class, [
'tags' => ['a', 'b', 'c']
@@ -149,7 +149,7 @@ public function testException()
$odm = $this->makeODM();

$builder->addSchema($this->makeSchema(Accessed::class));
$odm->buildSchema($builder);
$odm->setSchema($builder);

$entity = $odm->make(Accessed::class, [
'tags' => ['a', 'b', 'c']
10 changes: 5 additions & 5 deletions tests/ODM/ActiveRecordTest.php
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ public function testSaving()
$odm = $this->makeODM($manager);

$builder->addSchema($this->makeSchema(User::class));
$odm->buildSchema($builder);
$odm->setSchema($builder);

$user = $odm->make(User::class, []);
$this->assertInstanceOf(User::class, $user);
@@ -65,7 +65,7 @@ public function testUnchanged()
$odm = $this->makeODM($manager);

$builder->addSchema($this->makeSchema(User::class));
$odm->buildSchema($builder);
$odm->setSchema($builder);

$user = $odm->make(User::class, [
'_id' => new ObjectID('507f191e810c19729de860ea'),
@@ -85,7 +85,7 @@ public function testUpdate()
$odm = $this->makeODM($manager);

$builder->addSchema($this->makeSchema(User::class));
$odm->buildSchema($builder);
$odm->setSchema($builder);

$user = $odm->make(User::class, [
'_id' => $_id = new ObjectID('507f191e810c19729de860ea'),
@@ -120,7 +120,7 @@ public function testDelete()
$odm = $this->makeODM($manager);

$builder->addSchema($this->makeSchema(User::class));
$odm->buildSchema($builder);
$odm->setSchema($builder);

$user = $odm->make(User::class, [
'_id' => $_id = new ObjectID('507f191e810c19729de860ea'),
@@ -152,7 +152,7 @@ public function testDeleteNonCreated()
$odm = $this->makeODM($manager);

$builder->addSchema($this->makeSchema(User::class));
$odm->buildSchema($builder);
$odm->setSchema($builder);

$user = $odm->make(User::class, [
//'_id' => $_id = new ObjectID('507f191e810c19729de860ea'),
8 changes: 4 additions & 4 deletions tests/ODM/AggregationsTest.php
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ public function testUndefinedAggregationOrMethod()

$manager = m::mock(MongoManager::class);
$odm = $this->makeODM($manager);
$odm->buildSchema($builder);
$odm->setSchema($builder);

$aggr = $odm->make(GoodAggregates::class, [
'userId' => new ObjectID('507f1f77bcf86cd799439011')
@@ -52,7 +52,7 @@ public function testGetAggregationWithArguments()

$manager = m::mock(MongoManager::class);
$odm = $this->makeODM($manager);
$odm->buildSchema($builder);
$odm->setSchema($builder);

$aggr = $odm->make(GoodAggregates::class, [
'userId' => new ObjectID('507f1f77bcf86cd799439011')
@@ -69,7 +69,7 @@ public function testAggregationHelper()

$manager = m::mock(MongoManager::class);
$odm = $this->makeODM($manager);
$odm->buildSchema($builder);
$odm->setSchema($builder);

$aggr = $odm->make(GoodAggregates::class, [
'userId' => new ObjectID('507f1f77bcf86cd799439011')
@@ -94,7 +94,7 @@ public function testAggregationHelperWithQueryTemplate()

$manager = m::mock(MongoManager::class);
$odm = $this->makeODM($manager);
$odm->buildSchema($builder);
$odm->setSchema($builder);

$aggr = $odm->make(GoodAggregates::class, [
'userId' => new ObjectID('507f1f77bcf86cd799439011')
Loading