Skip to content

Commit 5f4dfcf

Browse files
committed
[#15038] - Refactor on the factory service discovery
1 parent d59613f commit 5f4dfcf

File tree

14 files changed

+25
-49
lines changed

14 files changed

+25
-49
lines changed

phalcon/Annotations/AnnotationsFactory.zep

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ class AnnotationsFactory extends AbstractFactory
6666
{
6767
var definition;
6868

69-
this->checkService(name);
70-
71-
let definition = this->mapper[name];
69+
let definition = this->getService(name);
7270

7371
return create_instance_params(
7472
definition,

phalcon/Cache/AdapterFactory.zep

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ class AdapterFactory extends AbstractFactory
6363
{
6464
var definition;
6565

66-
this->checkService(name);
67-
68-
let definition = this->mapper[name];
66+
let definition = this->getService(name);
6967

7068
return create_instance_params(
7169
definition,

phalcon/Config/ConfigFactory.zep

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ class ConfigFactory extends AbstractFactory
115115
{
116116
var definition, options;
117117

118-
this->checkService(name);
119-
120-
let definition = this->mapper[name],
118+
let definition = this->getService(name),
121119
options = [],
122120
options[] = fileName;
123121

phalcon/Db/Adapter/PdoFactory.zep

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ class PdoFactory extends AbstractFactory
6262
{
6363
var definition;
6464

65-
this->checkService(name);
66-
67-
let definition = this->mapper[name];
65+
let definition = this->getService(name);
6866

6967
return create_instance_params(
7068
definition,

phalcon/Factory/AbstractFactory.zep

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ abstract class AbstractFactory
2424
*/
2525
protected services = [];
2626

27-
/**
28-
* Checks if a service exists and throws an exception
29-
*/
30-
protected function checkService(string! name) -> void
31-
{
32-
if unlikely !isset this->mapper[name] {
33-
throw new Exception("Service " . name . " is not registered");
34-
}
35-
}
36-
3727
/**
3828
* Checks the config if it is a valid object
3929
*/
@@ -63,6 +53,18 @@ abstract class AbstractFactory
6353
*/
6454
abstract protected function getAdapters() -> array;
6555

56+
/**
57+
* Checks if a service exists and throws an exception
58+
*/
59+
protected function getService(string! name) -> var
60+
{
61+
if unlikely !isset this->mapper[name] {
62+
throw new Exception("Service " . name . " is not registered");
63+
}
64+
65+
return this->mapper[name];
66+
}
67+
6668
/**
6769
* AdapterFactory constructor.
6870
*/

phalcon/Html/TagFactory.zep

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ class TagFactory extends AbstractFactory
4444
{
4545
var definition;
4646

47-
this->checkService(name);
48-
4947
if !isset this->services[name] {
50-
let definition = this->mapper[name],
48+
let definition = this->getService(name),
5149
this->services[name] = create_instance_params(
5250
definition,
5351
[

phalcon/Image/ImageFactory.zep

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ class ImageFactory extends AbstractFactory
7373
{
7474
var definition;
7575

76-
this->checkService(name);
77-
78-
let definition = this->mapper[name];
76+
let definition = this->getService(name);
7977

8078
return create_instance_params(
8179
definition,

phalcon/Logger/AdapterFactory.zep

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ class AdapterFactory extends AbstractFactory
3434
{
3535
var definition;
3636

37-
this->checkService(name);
38-
39-
let definition = this->mapper[name];
37+
let definition = this->getService(name);
4038

4139
return create_instance_params(
4240
definition,

phalcon/Paginator/PaginatorFactory.zep

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ class PaginatorFactory extends AbstractFactory
7272
{
7373
var definition;
7474

75-
this->checkService(name);
76-
77-
let definition = this->mapper[name];
75+
let definition = this->getService(name);
7876

7977
return create_instance_params(
8078
definition,

phalcon/Storage/AdapterFactory.zep

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ class AdapterFactory extends AbstractFactory
5858
{
5959
var definition;
6060

61-
this->checkService(name);
62-
63-
let definition = this->mapper[name];
61+
let definition = this->getService(name);
6462

6563
return create_instance_params(
6664
definition,

0 commit comments

Comments
 (0)