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

Create instance #14419

Merged
merged 7 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# [4.0.0-rc.2](https://github.com/phalcon/cphalcon/releases/tag/v4.0.0-rc.2) (2019-XX-XX)
## Changed
- Changed all calls to `new <object>` to use the `create_instance` or `create_instance_params` for better performance. [#14419](https://github.com/phalcon/cphalcon/pull/14419)

## Fixed
- Fixed `Phalcon\Mvc\View\Engine\Volt\Compiler::parse()` Corrected syntax recognize for "set" keyword. [#14288](https://github.com/phalcon/cphalcon/issues/14288)
- Fixed `Phalcon\Mvc\View\Engine\Volt\Compiler::parse()` Corrected syntax recognize for "is" keyword. [#11683](https://github.com/phalcon/cphalcon/issues/11683)
Expand Down
2 changes: 1 addition & 1 deletion build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ Please, refer to [Phalcon documentation](https://phalcon.link/docs)

## Building extension for Windows

Please, refer to [Phalcon Internals documentation](https://internals.phalconphp.com)
Please, refer to [PHP's step by step guide](https://wiki.php.net/internals/windows/stepbystepbuild)
sergeyklay marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{
"name": "Phalcon Team",
"email": "[email protected]",
"homepage": "https://phalconphp.com/en/team"
"homepage": "https://phalcon.io/en/team"
},
{
"name": "Contributors",
Expand Down
13 changes: 9 additions & 4 deletions phalcon/Annotations/AnnotationsFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ class AnnotationsFactory extends AbstractFactory

if !isset this->services[name] {
let definition = this->mapper[name],
this->services[name] = new {definition}(options);
this->services[name] = create_instance_params(
definition,
[
options
]
);
}

return this->services[name];
Expand All @@ -67,9 +72,9 @@ class AnnotationsFactory extends AbstractFactory
protected function getAdapters() -> array
{
return [
"apcu" : "\\Phalcon\\Annotations\\Adapter\\Apcu",
"memory" : "\\Phalcon\\Annotations\\Adapter\\Memory",
"stream" : "\\Phalcon\\Annotations\\Adapter\\Stream"
"apcu" : "Phalcon\\Annotations\\Adapter\\Apcu",
"memory" : "Phalcon\\Annotations\\Adapter\\Memory",
"stream" : "Phalcon\\Annotations\\Adapter\\Stream"
];
}
}
18 changes: 12 additions & 6 deletions phalcon/Cache/AdapterFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ class AdapterFactory extends AbstractFactory

if !isset this->services[name] {
let definition = this->mapper[name],
this->services[name] = new {definition}(this->serializerFactory, options);
this->services[name] = create_instance_params(
definition,
[
this->serializerFactory,
options
]
);
}

return this->services[name];
Expand All @@ -58,11 +64,11 @@ class AdapterFactory extends AbstractFactory
protected function getAdapters() -> array
{
return [
"apcu" : "\\Phalcon\\Cache\\Adapter\\Apcu",
"libmemcached" : "\\Phalcon\\Cache\\Adapter\\Libmemcached",
"memory" : "\\Phalcon\\Cache\\Adapter\\Memory",
"redis" : "\\Phalcon\\Cache\\Adapter\\Redis",
"stream" : "\\Phalcon\\Cache\\Adapter\\Stream"
"apcu" : "Phalcon\\Cache\\Adapter\\Apcu",
"libmemcached" : "Phalcon\\Cache\\Adapter\\Libmemcached",
"memory" : "Phalcon\\Cache\\Adapter\\Memory",
"redis" : "Phalcon\\Cache\\Adapter\\Redis",
"stream" : "Phalcon\\Cache\\Adapter\\Stream"
];
}
}
24 changes: 13 additions & 11 deletions phalcon/Config/ConfigFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,20 @@ class ConfigFactory extends AbstractFactory
*/
public function newInstance(string name, string fileName, var params = null) -> object
{
var definition;
var definition, options;

this->checkService(name);

if !isset this->services[name] {
let definition = this->mapper[name];
let definition = this->mapper[name],
options = [],
options[] = fileName;

if "json" === name || "php" === name {
let this->services[name] = new {definition}(fileName);
} else {
let this->services[name] = new {definition}(fileName, params);
if "json" !== name && "php" !== name {
let options[] = params;
}

let this->services[name] = create_instance_params(definition, options);
}

return this->services[name];
Expand All @@ -136,11 +138,11 @@ class ConfigFactory extends AbstractFactory
protected function getAdapters() -> array
{
return [
"grouped" : "\\Phalcon\\Config\\Adapter\\Grouped",
"ini" : "\\Phalcon\\Config\\Adapter\\Ini",
"json" : "\\Phalcon\\Config\\Adapter\\Json",
"php" : "\\Phalcon\\Config\\Adapter\\Php",
"yaml" : "\\Phalcon\\Config\\Adapter\\Yaml"
"grouped" : "Phalcon\\Config\\Adapter\\Grouped",
"ini" : "Phalcon\\Config\\Adapter\\Ini",
"json" : "Phalcon\\Config\\Adapter\\Json",
"php" : "Phalcon\\Config\\Adapter\\Php",
"yaml" : "Phalcon\\Config\\Adapter\\Yaml"
];
}
}
2 changes: 1 addition & 1 deletion phalcon/Db/Adapter/AbstractAdapter.zep
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ abstract class AbstractAdapter implements AdapterInterface, EventsAwareInterface
* Create the instance only if the dialect is a string
*/
if typeof dialectClass == "string" {
let this->dialect = new {dialectClass}();
let this->dialect = create_instance(dialectClass);
} elseif typeof dialectClass == "object" {
let this->dialect = dialectClass;
}
Expand Down
13 changes: 9 additions & 4 deletions phalcon/Db/Adapter/PdoFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ class PdoFactory extends AbstractFactory

if !isset this->services[name] {
let definition = this->mapper[name],
this->services[name] = new {definition}(options);
this->services[name] = create_instance_params(
definition,
[
options
]
);
}

return this->services[name];
Expand All @@ -64,9 +69,9 @@ class PdoFactory extends AbstractFactory
protected function getAdapters() -> array
{
return [
"mysql" : "\\Phalcon\\Db\\Adapter\\Pdo\\Mysql",
"postgresql" : "\\Phalcon\\Db\\Adapter\\Pdo\\Postgresql",
"sqlite" : "\\Phalcon\\Db\\Adapter\\Pdo\\Sqlite"
"mysql" : "Phalcon\\Db\\Adapter\\Pdo\\Mysql",
"postgresql" : "Phalcon\\Db\\Adapter\\Pdo\\Postgresql",
"sqlite" : "Phalcon\\Db\\Adapter\\Pdo\\Sqlite"
];
}
}
42 changes: 21 additions & 21 deletions phalcon/Filter/FilterFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ class FilterFactory
protected function getAdapters() -> array
{
return [
"absint" : "\\Phalcon\\Filter\\Sanitize\\AbsInt",
"alnum" : "\\Phalcon\\Filter\\Sanitize\\Alnum",
"alpha" : "\\Phalcon\\Filter\\Sanitize\\Alpha",
"bool" : "\\Phalcon\\Filter\\Sanitize\\BoolVal",
"email" : "\\Phalcon\\Filter\\Sanitize\\Email",
"float" : "\\Phalcon\\Filter\\Sanitize\\FloatVal",
"int" : "\\Phalcon\\Filter\\Sanitize\\IntVal",
"lower" : "\\Phalcon\\Filter\\Sanitize\\Lower",
"lowerFirst" : "\\Phalcon\\Filter\\Sanitize\\LowerFirst",
"regex" : "\\Phalcon\\Filter\\Sanitize\\Regex",
"remove" : "\\Phalcon\\Filter\\Sanitize\\Remove",
"replace" : "\\Phalcon\\Filter\\Sanitize\\Replace",
"special" : "\\Phalcon\\Filter\\Sanitize\\Special",
"specialFull" : "\\Phalcon\\Filter\\Sanitize\\SpecialFull",
"string" : "\\Phalcon\\Filter\\Sanitize\\StringVal",
"striptags" : "\\Phalcon\\Filter\\Sanitize\\Striptags",
"trim" : "\\Phalcon\\Filter\\Sanitize\\Trim",
"upper" : "\\Phalcon\\Filter\\Sanitize\\Upper",
"upperFirst" : "\\Phalcon\\Filter\\Sanitize\\UpperFirst",
"upperWords" : "\\Phalcon\\Filter\\Sanitize\\UpperWords",
"url" : "\\Phalcon\\Filter\\Sanitize\\Url"
"absint" : "Phalcon\\Filter\\Sanitize\\AbsInt",
"alnum" : "Phalcon\\Filter\\Sanitize\\Alnum",
"alpha" : "Phalcon\\Filter\\Sanitize\\Alpha",
"bool" : "Phalcon\\Filter\\Sanitize\\BoolVal",
"email" : "Phalcon\\Filter\\Sanitize\\Email",
"float" : "Phalcon\\Filter\\Sanitize\\FloatVal",
"int" : "Phalcon\\Filter\\Sanitize\\IntVal",
"lower" : "Phalcon\\Filter\\Sanitize\\Lower",
"lowerFirst" : "Phalcon\\Filter\\Sanitize\\LowerFirst",
"regex" : "Phalcon\\Filter\\Sanitize\\Regex",
"remove" : "Phalcon\\Filter\\Sanitize\\Remove",
"replace" : "Phalcon\\Filter\\Sanitize\\Replace",
"special" : "Phalcon\\Filter\\Sanitize\\Special",
"specialFull" : "Phalcon\\Filter\\Sanitize\\SpecialFull",
"string" : "Phalcon\\Filter\\Sanitize\\StringVal",
"striptags" : "Phalcon\\Filter\\Sanitize\\Striptags",
"trim" : "Phalcon\\Filter\\Sanitize\\Trim",
"upper" : "Phalcon\\Filter\\Sanitize\\Upper",
"upperFirst" : "Phalcon\\Filter\\Sanitize\\UpperFirst",
"upperWords" : "Phalcon\\Filter\\Sanitize\\UpperWords",
"url" : "Phalcon\\Filter\\Sanitize\\Url"
];
}
}
29 changes: 17 additions & 12 deletions phalcon/Html/TagFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ class TagFactory extends AbstractFactory

if !isset this->services[name] {
let definition = this->mapper[name],
this->services[name] = new {definition}(this->escaper);
this->services[name] = create_instance_params(
definition,
[
this->escaper
]
);
}

return this->services[name];
Expand All @@ -57,17 +62,17 @@ class TagFactory extends AbstractFactory
protected function getAdapters() -> array
{
return [
"a" : "\\Phalcon\\Html\\Helper\\Anchor",
"aRaw" : "\\Phalcon\\Html\\Helper\\AnchorRaw",
"body" : "\\Phalcon\\Html\\Helper\\Body",
"button" : "\\Phalcon\\Html\\Helper\\Button",
"close" : "\\Phalcon\\Html\\Helper\\Close",
"element" : "\\Phalcon\\Html\\Helper\\Element",
"elementRaw" : "\\Phalcon\\Html\\Helper\\ElementRaw",
"form" : "\\Phalcon\\Html\\Helper\\Form",
"img" : "\\Phalcon\\Html\\Helper\\Img",
"label" : "\\Phalcon\\Html\\Helper\\Label",
"textarea" : "\\Phalcon\\Html\\Helper\\TextArea"
"a" : "Phalcon\\Html\\Helper\\Anchor",
"aRaw" : "Phalcon\\Html\\Helper\\AnchorRaw",
"body" : "Phalcon\\Html\\Helper\\Body",
"button" : "Phalcon\\Html\\Helper\\Button",
"close" : "Phalcon\\Html\\Helper\\Close",
"element" : "Phalcon\\Html\\Helper\\Element",
"elementRaw" : "Phalcon\\Html\\Helper\\ElementRaw",
"form" : "Phalcon\\Html\\Helper\\Form",
"img" : "Phalcon\\Html\\Helper\\Img",
"label" : "Phalcon\\Html\\Helper\\Label",
"textarea" : "Phalcon\\Html\\Helper\\TextArea"
];
}
}
13 changes: 10 additions & 3 deletions phalcon/Image/ImageFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ class ImageFactory extends AbstractFactory

if !isset this->services[name] {
let definition = this->mapper[name],
this->services[name] = new {definition}(file, width, height);
this->services[name] = create_instance_params(
definition,
[
file,
width,
height
]
);
}

return this->services[name];
Expand All @@ -79,8 +86,8 @@ class ImageFactory extends AbstractFactory
protected function getAdapters() -> array
{
return [
"gd" : "\\Phalcon\\Image\\Adapter\\Gd",
"imagick" : "\\Phalcon\\Image\\Adapter\\Imagick"
"gd" : "Phalcon\\Image\\Adapter\\Gd",
"imagick" : "Phalcon\\Image\\Adapter\\Imagick"
];
}
}
2 changes: 1 addition & 1 deletion phalcon/Logger/Adapter/AbstractAdapter.zep
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ abstract class AbstractAdapter implements AdapterInterface
if typeof this->formatter !== "object" {
let className = "Phalcon\\Logger\\Formatter\\" . this->defaultFormatter;

let this->formatter = new {className}();
let this->formatter = create_instance(className);
}

return this->formatter;
Expand Down
14 changes: 10 additions & 4 deletions phalcon/Logger/AdapterFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ class AdapterFactory extends AbstractFactory

if !isset this->services[name] {
let definition = this->mapper[name],
this->services[name] = new {definition}(fileName, options);
this->services[name] = create_instance_params(
definition,
[
fileName,
options
]
);
}

return this->services[name];
Expand All @@ -47,9 +53,9 @@ class AdapterFactory extends AbstractFactory
protected function getAdapters() -> array
{
return [
"noop" : "\\Phalcon\\Logger\\Adapter\\Noop",
"stream" : "\\Phalcon\\Logger\\Adapter\\Stream",
"syslog" : "\\Phalcon\\Logger\\Adapter\\Syslog"
"noop" : "Phalcon\\Logger\\Adapter\\Noop",
"stream" : "Phalcon\\Logger\\Adapter\\Stream",
"syslog" : "Phalcon\\Logger\\Adapter\\Syslog"
];
}
}
8 changes: 7 additions & 1 deletion phalcon/Logger/LoggerFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ class LoggerFactory
*/
public function newInstance(string! name, array! adapters = []) -> <Logger>
{
return new Logger(name, adapters);
return create_instance_params(
niden marked this conversation as resolved.
Show resolved Hide resolved
"Phalcon\\Logger",
[
name,
adapters
]
);
}
}
25 changes: 18 additions & 7 deletions phalcon/Mvc/Model.zep
Original file line number Diff line number Diff line change
Expand Up @@ -959,10 +959,13 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface,
*/
if this->_exists(metaData, this->getWriteConnection()) {
let this->errorMessages = [
new Message(
"Record cannot be created because it already exists",
null,
"InvalidCreateAttempt"
create_instance_params(
niden marked this conversation as resolved.
Show resolved Hide resolved
"Phalcon\\Messages\\Message",
[
"Record cannot be created because it already exists",
null,
"InvalidCreateAttempt"
]
)
];

Expand Down Expand Up @@ -3135,7 +3138,11 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface,
* Create a message
*/
this->appendMessage(
new Message(message, fields, "ConstraintViolation")
new Message(
message,
fields,
"ConstraintViolation"
)
);

let error = true;
Expand Down Expand Up @@ -3378,7 +3385,11 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface,
* Create a message
*/
this->appendMessage(
new Message(message, fields, "ConstraintViolation")
new Message(
message,
fields,
"ConstraintViolation"
)
);

let error = true;
Expand Down Expand Up @@ -4247,7 +4258,7 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface,
);
}

let model = new {modelName}(),
let model = create_instance(modelName),
metaData = model->getModelsMetaData();

/**
Expand Down
Loading