Skip to content

Commit

Permalink
[#15038] - Refactor on the factory service discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed May 16, 2020
1 parent 00ad4c9 commit 65edf89
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 49 deletions.
4 changes: 1 addition & 3 deletions phalcon/Annotations/AnnotationsFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ class AnnotationsFactory extends AbstractFactory
{
var definition;

this->checkService(name);

let definition = this->mapper[name];
let definition = this->getService(name);

return create_instance_params(
definition,
Expand Down
4 changes: 1 addition & 3 deletions phalcon/Cache/AdapterFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ class AdapterFactory extends AbstractFactory
{
var definition;

this->checkService(name);

let definition = this->mapper[name];
let definition = this->getService(name);

return create_instance_params(
definition,
Expand Down
4 changes: 1 addition & 3 deletions phalcon/Config/ConfigFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ class ConfigFactory extends AbstractFactory
{
var definition, options;

this->checkService(name);

let definition = this->mapper[name],
let definition = this->getService(name),
options = [],
options[] = fileName;

Expand Down
4 changes: 1 addition & 3 deletions phalcon/Db/Adapter/PdoFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ class PdoFactory extends AbstractFactory
{
var definition;

this->checkService(name);

let definition = this->mapper[name];
let definition = this->getService(name);

return create_instance_params(
definition,
Expand Down
22 changes: 12 additions & 10 deletions phalcon/Factory/AbstractFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ abstract class AbstractFactory
*/
protected services = [];

/**
* Checks if a service exists and throws an exception
*/
protected function checkService(string! name) -> void
{
if unlikely !isset this->mapper[name] {
throw new Exception("Service " . name . " is not registered");
}
}

/**
* Checks the config if it is a valid object
*/
Expand Down Expand Up @@ -63,6 +53,18 @@ abstract class AbstractFactory
*/
abstract protected function getAdapters() -> array;

/**
* Checks if a service exists and throws an exception
*/
protected function getService(string! name) -> var
{
if unlikely !isset this->mapper[name] {
throw new Exception("Service " . name . " is not registered");
}

return this->mapper[name];
}

/**
* AdapterFactory constructor.
*/
Expand Down
4 changes: 1 addition & 3 deletions phalcon/Html/TagFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ class TagFactory extends AbstractFactory
{
var definition;

this->checkService(name);

if !isset this->services[name] {
let definition = this->mapper[name],
let definition = this->getService(name),
this->services[name] = create_instance_params(
definition,
[
Expand Down
4 changes: 1 addition & 3 deletions phalcon/Image/ImageFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ class ImageFactory extends AbstractFactory
{
var definition;

this->checkService(name);

let definition = this->mapper[name];
let definition = this->getService(name);

return create_instance_params(
definition,
Expand Down
4 changes: 1 addition & 3 deletions phalcon/Logger/AdapterFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ class AdapterFactory extends AbstractFactory
{
var definition;

this->checkService(name);

let definition = this->mapper[name];
let definition = this->getService(name);

return create_instance_params(
definition,
Expand Down
4 changes: 1 addition & 3 deletions phalcon/Paginator/PaginatorFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ class PaginatorFactory extends AbstractFactory
{
var definition;

this->checkService(name);

let definition = this->mapper[name];
let definition = this->getService(name);

return create_instance_params(
definition,
Expand Down
4 changes: 1 addition & 3 deletions phalcon/Storage/AdapterFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ class AdapterFactory extends AbstractFactory
{
var definition;

this->checkService(name);

let definition = this->mapper[name];
let definition = this->getService(name);

return create_instance_params(
definition,
Expand Down
4 changes: 1 addition & 3 deletions phalcon/Storage/SerializerFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ class SerializerFactory extends AbstractFactory
{
var definition;

this->checkService(name);

let definition = this->mapper[name];
let definition = this->getService(name);

return create_instance(definition);
}
Expand Down
4 changes: 1 addition & 3 deletions phalcon/Translate/InterpolatorFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ class InterpolatorFactory extends AbstractFactory
{
var definition;

this->checkService(name);

let definition = this->mapper[name];
let definition = this->getService(name);

return create_instance(definition);
}
Expand Down
4 changes: 1 addition & 3 deletions phalcon/Translate/TranslateFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ class TranslateFactory extends AbstractFactory
{
var definition;

this->checkService(name);

let definition = this->mapper[name];
let definition = this->getService(name);

return create_instance_params(
definition,
Expand Down
4 changes: 1 addition & 3 deletions phalcon/Validation/ValidatorFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ class ValidatorFactory extends AbstractFactory
{
var definition;

this->checkService(name);

let definition = this->mapper[name];
let definition = this->getService(name);

return create_instance(definition);
}
Expand Down

0 comments on commit 65edf89

Please sign in to comment.