Completed
Branch 5.1 (8f5aa6)
by Rémi
05:12
created
src/Drivers/IlluminateDBAdapter.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
     /**
28 28
      * Return a new Query instance for this driver
29 29
      *
30
-     * @return QueryAdapter
30
+     * @return IlluminateQueryBuilder
31 31
      */
32 32
     public function getQuery()
33 33
     {
Please login to merge, or discard this patch.
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -10,68 +10,68 @@
 block discarded – undo
10 10
  */
11 11
 class IlluminateDBAdapter implements DBAdapter
12 12
 {
13
-    /**
14
-     * @var Connection
15
-     */
16
-    protected $connection;
13
+	/**
14
+	 * @var Connection
15
+	 */
16
+	protected $connection;
17 17
 
18
-    /**
19
-     * IlluminateDBAdapter constructor.
20
-     * @param Connection $connection
21
-     */
22
-    public function __construct(Connection $connection)
23
-    {
24
-        $this->connection = $connection;
25
-    }
18
+	/**
19
+	 * IlluminateDBAdapter constructor.
20
+	 * @param Connection $connection
21
+	 */
22
+	public function __construct(Connection $connection)
23
+	{
24
+		$this->connection = $connection;
25
+	}
26 26
 
27
-    /**
28
-     * Return a new Query instance for this driver
29
-     *
30
-     * @return QueryAdapter
31
-     */
32
-    public function getQuery()
33
-    {
34
-        $connection = $this->connection;
27
+	/**
28
+	 * Return a new Query instance for this driver
29
+	 *
30
+	 * @return QueryAdapter
31
+	 */
32
+	public function getQuery()
33
+	{
34
+		$connection = $this->connection;
35 35
 
36
-        $grammar = $connection->getQueryGrammar();
36
+		$grammar = $connection->getQueryGrammar();
37 37
 
38
-        return new IlluminateQueryBuilder($connection, $grammar, $connection->getPostProcessor());
39
-    }
38
+		return new IlluminateQueryBuilder($connection, $grammar, $connection->getPostProcessor());
39
+	}
40 40
 
41
-    /**
42
-     * Get the date format supported by the current connection
43
-     *
44
-     * @return string
45
-     */
46
-    public function getDateFormat()
47
-    {
48
-        return $this->connection->getQueryGrammar()->getDateFormat();
49
-    }
41
+	/**
42
+	 * Get the date format supported by the current connection
43
+	 *
44
+	 * @return string
45
+	 */
46
+	public function getDateFormat()
47
+	{
48
+		return $this->connection->getQueryGrammar()->getDateFormat();
49
+	}
50 50
 
51
-    /**
52
-     * Start a DB transaction on driver that supports it.
53
-     * @return void
54
-     */
55
-    public function beginTransaction()
56
-    {
57
-        $this->connection->beginTransaction();
58
-    }
51
+	/**
52
+	 * Start a DB transaction on driver that supports it.
53
+	 * @return void
54
+	 */
55
+	public function beginTransaction()
56
+	{
57
+		$this->connection->beginTransaction();
58
+	}
59 59
 
60
-    /**
61
-     * Commit a DB transaction on driver that supports it.
62
-     * @return void
63
-     */
64
-    public function commit()
65
-    {
66
-        $this->connection->commit();
67
-    }
60
+	/**
61
+	 * Commit a DB transaction on driver that supports it.
62
+	 * @return void
63
+	 */
64
+	public function commit()
65
+	{
66
+		$this->connection->commit();
67
+	}
68 68
 
69
-    /**
70
-     * Rollback a DB transaction
71
-     * @return void
72
-     */
73
-    public function rollback()
74
-    {
75
-        $this->connection->rollBack();
76
-    }
69
+	/**
70
+	 * Rollback a DB transaction
71
+	 * @return void
72
+	 */
73
+	public function rollback()
74
+	{
75
+		$this->connection->rollBack();
76
+	}
77 77
 }
Please login to merge, or discard this patch.
src/Commands/Command.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -7,31 +7,31 @@
 block discarded – undo
7 7
 
8 8
 abstract class Command
9 9
 {
10
-    /**
11
-     * The aggregated entity on which the command is executed
12
-     *
13
-     * @var \Analogue\ORM\System\Aggregate
14
-     */
15
-    protected $aggregate;
10
+	/**
11
+	 * The aggregated entity on which the command is executed
12
+	 *
13
+	 * @var \Analogue\ORM\System\Aggregate
14
+	 */
15
+	protected $aggregate;
16 16
 
17
-    /**
18
-     * Query Builder instance
19
-     *
20
-     * @var \Illuminate\Database\Query\Builder
21
-     */
22
-    protected $query;
17
+	/**
18
+	 * Query Builder instance
19
+	 *
20
+	 * @var \Illuminate\Database\Query\Builder
21
+	 */
22
+	protected $query;
23 23
 
24
-    /**
25
-     * Command constructor.
26
-     * @param Aggregate $aggregate
27
-     * @param QueryAdapter|\Analogue\ORM\Drivers\IlluminateQueryAdapter $query
28
-     */
29
-    public function __construct(Aggregate $aggregate, Builder $query)
30
-    {
31
-        $this->aggregate = $aggregate;
24
+	/**
25
+	 * Command constructor.
26
+	 * @param Aggregate $aggregate
27
+	 * @param QueryAdapter|\Analogue\ORM\Drivers\IlluminateQueryAdapter $query
28
+	 */
29
+	public function __construct(Aggregate $aggregate, Builder $query)
30
+	{
31
+		$this->aggregate = $aggregate;
32 32
 
33
-        $this->query = $query->from($aggregate->getEntityMap()->getTable());
34
-    }
33
+		$this->query = $query->from($aggregate->getEntityMap()->getTable());
34
+	}
35 35
 
36
-    abstract public function execute();
36
+	abstract public function execute();
37 37
 }
Please login to merge, or discard this patch.
src/Commands/Store.php 2 patches
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -14,235 +14,235 @@
 block discarded – undo
14 14
  */
15 15
 class Store extends Command
16 16
 {
17
-    /**
18
-     * Persist the entity in the database
19
-     *
20
-     * @throws \InvalidArgumentException
21
-     * @return false|mixed
22
-     */
23
-    public function execute()
24
-    {
25
-        $entity = $this->aggregate->getEntityObject();
26
-
27
-        $mapper = $this->aggregate->getMapper();
28
-
29
-        if ($mapper->fireEvent('storing', $entity) === false) {
30
-            return false;
31
-        }
32
-
33
-        $this->preStoreProcess();
34
-
35
-        /**
36
-         * We will test the entity for existence
37
-         * and run a creation if it doesn't exists
38
-         */
39
-        if (!$this->aggregate->exists()) {
40
-            if ($mapper->fireEvent('creating', $entity) === false) {
41
-                return false;
42
-            }
43
-
44
-            $this->insert();
45
-
46
-            $mapper->fireEvent('created', $entity, false);
47
-        }
48
-        else if ($this->aggregate->isDirty()) {
49
-            if ($mapper->fireEvent('updating', $entity) === false) {
50
-                return false;
51
-            }
52
-            $this->update();
53
-
54
-            $mapper->fireEvent('updated', $entity, false);
55
-        }
56
-
57
-        $this->postStoreProcess();
58
-
59
-        $mapper->fireEvent('stored', $entity, false);
60
-
61
-        return $entity;
62
-    }
63
-
64
-    /**
65
-     * Run all operations that have to occur before actually
66
-     * storing the entity
67
-     *
68
-     * @throws \InvalidArgumentException
69
-     * @return void
70
-     */
71
-    protected function preStoreProcess()
72
-    {
73
-        // Create any related object that doesn't exist in the database.
74
-        $localRelationships = $this->aggregate->getEntityMap()->getLocalRelationships();
75
-
76
-        $this->createRelatedEntities($localRelationships);
77
-
78
-        // Now we can sync the related collections
79
-        $this->aggregate->syncRelationships($localRelationships);
80
-    }
81
-
82
-    /**
83
-     * Check for existence and create non-existing related entities
84
-     *
85
-     * @param  array
86
-     * @throws \InvalidArgumentException
87
-     * @return void
88
-     */
89
-    protected function createRelatedEntities($relations)
90
-    {
91
-        $entitiesToCreate = $this->aggregate->getNonExistingRelated($relations);
92
-
93
-        foreach ($entitiesToCreate as $aggregate) {
94
-            $this->createStoreCommand($aggregate)->execute();
95
-        }
96
-    }
97
-
98
-    /**
99
-     * Create a new store command
100
-     *
101
-     * @param  Aggregate $aggregate
102
-     * @return Store
103
-     */
104
-    protected function createStoreCommand(Aggregate $aggregate)
105
-    {
106
-        // We gotta retrieve the corresponding query adapter to use.
107
-        $mapper = $aggregate->getMapper();
108
-
109
-        return new Store($aggregate, $mapper->newQueryBuilder());
110
-    }
111
-
112
-    /**
113
-     * Run all operations that have to occur after the entity
114
-     * is stored.
115
-     *
116
-     * @throws \InvalidArgumentException
117
-     * @return void
118
-     */
119
-    protected function postStoreProcess()
120
-    {
121
-        $aggregate = $this->aggregate;
122
-
123
-        // Create any related object that doesn't exist in the database.
124
-        $foreignRelationships = $aggregate->getEntityMap()->getForeignRelationships();
125
-        $this->createRelatedEntities($foreignRelationships);
126
-
127
-        // Update any pivot tables that has been modified.
128
-        $aggregate->updatePivotRecords();
129
-
130
-        // Update any dirty relationship. This include relationships that already exists, have
131
-        // dirty attributes / newly created related entities / dirty related entities.
132
-        $dirtyRelatedAggregates = $aggregate->getDirtyRelationships();
133
-
134
-        foreach ($dirtyRelatedAggregates as $related) {
135
-            $this->createStoreCommand($related)->execute();
136
-        }
137
-
138
-        // Now we can sync the related collections
139
-        if ($this->aggregate->exists()) {
140
-            $this->aggregate->syncRelationships($foreignRelationships);
141
-        }
17
+	/**
18
+	 * Persist the entity in the database
19
+	 *
20
+	 * @throws \InvalidArgumentException
21
+	 * @return false|mixed
22
+	 */
23
+	public function execute()
24
+	{
25
+		$entity = $this->aggregate->getEntityObject();
26
+
27
+		$mapper = $this->aggregate->getMapper();
28
+
29
+		if ($mapper->fireEvent('storing', $entity) === false) {
30
+			return false;
31
+		}
32
+
33
+		$this->preStoreProcess();
34
+
35
+		/**
36
+		 * We will test the entity for existence
37
+		 * and run a creation if it doesn't exists
38
+		 */
39
+		if (!$this->aggregate->exists()) {
40
+			if ($mapper->fireEvent('creating', $entity) === false) {
41
+				return false;
42
+			}
43
+
44
+			$this->insert();
45
+
46
+			$mapper->fireEvent('created', $entity, false);
47
+		}
48
+		else if ($this->aggregate->isDirty()) {
49
+			if ($mapper->fireEvent('updating', $entity) === false) {
50
+				return false;
51
+			}
52
+			$this->update();
53
+
54
+			$mapper->fireEvent('updated', $entity, false);
55
+		}
56
+
57
+		$this->postStoreProcess();
58
+
59
+		$mapper->fireEvent('stored', $entity, false);
60
+
61
+		return $entity;
62
+	}
63
+
64
+	/**
65
+	 * Run all operations that have to occur before actually
66
+	 * storing the entity
67
+	 *
68
+	 * @throws \InvalidArgumentException
69
+	 * @return void
70
+	 */
71
+	protected function preStoreProcess()
72
+	{
73
+		// Create any related object that doesn't exist in the database.
74
+		$localRelationships = $this->aggregate->getEntityMap()->getLocalRelationships();
75
+
76
+		$this->createRelatedEntities($localRelationships);
77
+
78
+		// Now we can sync the related collections
79
+		$this->aggregate->syncRelationships($localRelationships);
80
+	}
81
+
82
+	/**
83
+	 * Check for existence and create non-existing related entities
84
+	 *
85
+	 * @param  array
86
+	 * @throws \InvalidArgumentException
87
+	 * @return void
88
+	 */
89
+	protected function createRelatedEntities($relations)
90
+	{
91
+		$entitiesToCreate = $this->aggregate->getNonExistingRelated($relations);
92
+
93
+		foreach ($entitiesToCreate as $aggregate) {
94
+			$this->createStoreCommand($aggregate)->execute();
95
+		}
96
+	}
97
+
98
+	/**
99
+	 * Create a new store command
100
+	 *
101
+	 * @param  Aggregate $aggregate
102
+	 * @return Store
103
+	 */
104
+	protected function createStoreCommand(Aggregate $aggregate)
105
+	{
106
+		// We gotta retrieve the corresponding query adapter to use.
107
+		$mapper = $aggregate->getMapper();
108
+
109
+		return new Store($aggregate, $mapper->newQueryBuilder());
110
+	}
111
+
112
+	/**
113
+	 * Run all operations that have to occur after the entity
114
+	 * is stored.
115
+	 *
116
+	 * @throws \InvalidArgumentException
117
+	 * @return void
118
+	 */
119
+	protected function postStoreProcess()
120
+	{
121
+		$aggregate = $this->aggregate;
122
+
123
+		// Create any related object that doesn't exist in the database.
124
+		$foreignRelationships = $aggregate->getEntityMap()->getForeignRelationships();
125
+		$this->createRelatedEntities($foreignRelationships);
126
+
127
+		// Update any pivot tables that has been modified.
128
+		$aggregate->updatePivotRecords();
129
+
130
+		// Update any dirty relationship. This include relationships that already exists, have
131
+		// dirty attributes / newly created related entities / dirty related entities.
132
+		$dirtyRelatedAggregates = $aggregate->getDirtyRelationships();
133
+
134
+		foreach ($dirtyRelatedAggregates as $related) {
135
+			$this->createStoreCommand($related)->execute();
136
+		}
137
+
138
+		// Now we can sync the related collections
139
+		if ($this->aggregate->exists()) {
140
+			$this->aggregate->syncRelationships($foreignRelationships);
141
+		}
142 142
         
143
-        // TODO be move it to the wrapper class
144
-        // so it's the same code for the entity builder
145
-        $aggregate->setProxies();
146
-
147
-        // Update Entity Cache
148
-        $aggregate->getMapper()->getEntityCache()->refresh($aggregate);
149
-    }
150
-
151
-    /**
152
-     * Update Related Entities which attributes have
153
-     * been modified.
154
-     *
155
-     * @return void
156
-     */
157
-    protected function updateDirtyRelated()
158
-    {
159
-        $relations = $this->entityMap->getRelationships();
160
-        $attributes = $this->getAttributes();
161
-
162
-        foreach ($relations as $relation) {
163
-            if (!array_key_exists($relation, $attributes)) {
164
-                continue;
165
-            }
166
-
167
-            $value = $attributes[$relation];
168
-
169
-            if ($value == null) {
170
-                continue;
171
-            }
172
-
173
-            if ($value instanceof EntityProxy) {
174
-                continue;
175
-            }
176
-
177
-            if ($value instanceof CollectionProxy && $value->isLoaded()) {
178
-                $value = $value->getUnderlyingCollection();
179
-            }
180
-            if ($value instanceof CollectionProxy && !$value->isLoaded()) {
181
-                foreach ($value->getAddedItems() as $entity) {
182
-                    $this->updateEntityIfDirty($entity);
183
-                }
184
-                continue;
185
-            }
186
-
187
-            if ($value instanceof EntityCollection) {
188
-                foreach ($value as $entity) {
189
-                    if (!$this->createEntityIfNotExists($entity)) {
190
-                        $this->updateEntityIfDirty($entity);
191
-                    }
192
-                }
193
-                continue;
194
-            }
195
-            if ($value instanceof Mappable) {
196
-                $this->updateEntityIfDirty($value);
197
-                continue;
198
-            }
199
-        }
200
-    }
201
-
202
-    /**
203
-     * Execute an insert statement on the database
204
-     *
205
-     * @return void
206
-     */
207
-    protected function insert()
208
-    {
209
-        $aggregate = $this->aggregate;
210
-
211
-        $attributes = $aggregate->getRawAttributes();
143
+		// TODO be move it to the wrapper class
144
+		// so it's the same code for the entity builder
145
+		$aggregate->setProxies();
146
+
147
+		// Update Entity Cache
148
+		$aggregate->getMapper()->getEntityCache()->refresh($aggregate);
149
+	}
150
+
151
+	/**
152
+	 * Update Related Entities which attributes have
153
+	 * been modified.
154
+	 *
155
+	 * @return void
156
+	 */
157
+	protected function updateDirtyRelated()
158
+	{
159
+		$relations = $this->entityMap->getRelationships();
160
+		$attributes = $this->getAttributes();
161
+
162
+		foreach ($relations as $relation) {
163
+			if (!array_key_exists($relation, $attributes)) {
164
+				continue;
165
+			}
166
+
167
+			$value = $attributes[$relation];
168
+
169
+			if ($value == null) {
170
+				continue;
171
+			}
172
+
173
+			if ($value instanceof EntityProxy) {
174
+				continue;
175
+			}
176
+
177
+			if ($value instanceof CollectionProxy && $value->isLoaded()) {
178
+				$value = $value->getUnderlyingCollection();
179
+			}
180
+			if ($value instanceof CollectionProxy && !$value->isLoaded()) {
181
+				foreach ($value->getAddedItems() as $entity) {
182
+					$this->updateEntityIfDirty($entity);
183
+				}
184
+				continue;
185
+			}
186
+
187
+			if ($value instanceof EntityCollection) {
188
+				foreach ($value as $entity) {
189
+					if (!$this->createEntityIfNotExists($entity)) {
190
+						$this->updateEntityIfDirty($entity);
191
+					}
192
+				}
193
+				continue;
194
+			}
195
+			if ($value instanceof Mappable) {
196
+				$this->updateEntityIfDirty($value);
197
+				continue;
198
+			}
199
+		}
200
+	}
201
+
202
+	/**
203
+	 * Execute an insert statement on the database
204
+	 *
205
+	 * @return void
206
+	 */
207
+	protected function insert()
208
+	{
209
+		$aggregate = $this->aggregate;
210
+
211
+		$attributes = $aggregate->getRawAttributes();
212 212
         
213
-        $keyName = $aggregate->getEntityMap()->getKeyName();
213
+		$keyName = $aggregate->getEntityMap()->getKeyName();
214 214
 
215
-        // Check if the primary key is defined in the attributes
216
-        if (array_key_exists($keyName, $attributes) && $attributes[$keyName] != null) {
217
-            $this->query->insert($attributes);
218
-        } else {
219
-            $sequence = $aggregate->getEntityMap()->getSequence();
215
+		// Check if the primary key is defined in the attributes
216
+		if (array_key_exists($keyName, $attributes) && $attributes[$keyName] != null) {
217
+			$this->query->insert($attributes);
218
+		} else {
219
+			$sequence = $aggregate->getEntityMap()->getSequence();
220 220
 
221
-            $id = $this->query->insertGetId($attributes, $sequence);
221
+			$id = $this->query->insertGetId($attributes, $sequence);
222 222
 
223
-            $aggregate->setEntityAttribute($keyName, $id);
224
-        }
225
-    }
223
+			$aggregate->setEntityAttribute($keyName, $id);
224
+		}
225
+	}
226 226
 
227
-    /**
228
-     * Run an update statement on the entity
229
-     *
230
-     * @throws \InvalidArgumentException
231
-     *
232
-     * @return void
233
-     */
234
-    protected function update()
235
-    {
236
-        $query = $this->query;
227
+	/**
228
+	 * Run an update statement on the entity
229
+	 *
230
+	 * @throws \InvalidArgumentException
231
+	 *
232
+	 * @return void
233
+	 */
234
+	protected function update()
235
+	{
236
+		$query = $this->query;
237 237
 
238
-        $keyName = $this->aggregate->getEntityKey();
238
+		$keyName = $this->aggregate->getEntityKey();
239 239
 
240
-        $query = $query->where($keyName, '=', $this->aggregate->getEntityId());
240
+		$query = $query->where($keyName, '=', $this->aggregate->getEntityId());
241 241
 
242
-        $dirtyAttributes = $this->aggregate->getDirtyRawAttributes();
242
+		$dirtyAttributes = $this->aggregate->getDirtyRawAttributes();
243 243
 
244
-        if (count($dirtyAttributes) > 0) {
245
-            $query->update($dirtyAttributes);
246
-        }
247
-    }
244
+		if (count($dirtyAttributes) > 0) {
245
+			$query->update($dirtyAttributes);
246
+		}
247
+	}
248 248
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -44,8 +44,7 @@
 block discarded – undo
44 44
             $this->insert();
45 45
 
46 46
             $mapper->fireEvent('created', $entity, false);
47
-        }
48
-        else if ($this->aggregate->isDirty()) {
47
+        } else if ($this->aggregate->isDirty()) {
49 48
             if ($mapper->fireEvent('updating', $entity) === false) {
50 49
                 return false;
51 50
             }
Please login to merge, or discard this patch.
src/Drivers/IlluminateQueryBuilder.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,5 +6,5 @@
 block discarded – undo
6 6
 
7 7
 class EntityMapNotFoundException extends RuntimeException
8 8
 {
9
-    //
9
+	//
10 10
 }
Please login to merge, or discard this patch.