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

T15038 factory newinstance #15039

Merged
merged 2 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Changed return type hint for `Phalcon\Mvc\Model\Manager::getCustomEventsManager` to return NULL instead of boolean FALSE if there is no special events manager [#15008](https://github.com/phalcon/cphalcon/issues/15008)
- Changed `Phalcon\Mvc\Model\MetaData::getDI` so that now it will throw a `Phalcon\Mvc\Model\Exception` if there is no `DiInterface` instance [#15011](https://github.com/phalcon/cphalcon/issues/15011)
- Changed `Phalcon\Http\Request::getJsonRawBody` to use `json_decode` instead of `Phalcon\Json::decode` [#14936](https://github.com/phalcon/cphalcon/issues/14936)
- Changed `Phalcon\Factory\AbstractFactory` to expose `getService` which will throw an exception if it does not exist. Removed `checkService` and adjusted all references in `newInstance()` calls. [#15038](https://github.com/phalcon/cphalcon/issues/15038)

## Fixed
- Fixed `Phalcon\Mvc\Model\Query\Builder::getPhql` to add single quote between string value on a simple condition [#14874](https://github.com/phalcon/cphalcon/issues/14874)
Expand Down
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