#" . n . " ";
if fetch className, trace["class"] {
-
/**
* We assume that classes starting by Phalcon are framework's
* classes
*/
if preg_match("/^Phalcon/", className) {
-
/**
* Prepare the class name according to the Phalcon's conventions
*/
@@ -586,14 +617,12 @@ class Debug
*/
let classNameWithLink = "" . className . " ";
} else {
-
let classReflection = new \ReflectionClass(className);
/**
* Check if classes are PHP's classes
*/
if classReflection->isInternal() {
-
let prepareInternalClass = str_replace(
"_",
"-",
@@ -621,15 +650,14 @@ class Debug
* Normally the backtrace contains only classes
*/
let functionName = trace["function"];
+
if isset trace["class"] {
let functionNameWithLink = functionName;
} else {
-
/**
* Check if the function exists
*/
if function_exists(functionName) {
-
let functionReflection = new \ReflectionFunction(functionName);
/**
@@ -660,10 +688,9 @@ class Debug
* Check for arguments in the function
*/
if fetch traceArgs, trace["args"] {
-
let arguments = [];
- for argument in traceArgs {
+ for argument in traceArgs {
/**
* Every argument is generated using getVarDump
* Append the HTML generated to the argument's list
@@ -682,7 +709,6 @@ class Debug
* the user
*/
if fetch filez, trace["file"] {
-
let line = (string) trace["line"];
/**
@@ -696,7 +722,6 @@ class Debug
* The developer can change if the files must be opened or not
*/
if showFiles {
-
/**
* Open the file to an array using "file", this respects the
* openbase-dir directive
@@ -747,8 +772,8 @@ class Debug
}
let i = firstLine;
- while i <= lastLine {
+ while i <= lastLine {
/**
* Current line in the file
*/
@@ -794,6 +819,7 @@ class Debug
let i++;
}
+
let html .= "";
}
}
diff --git a/phalcon/Debug/Dump.zep b/phalcon/Debug/Dump.zep
index 35de0b067bc..a9bd8f20fce 100644
--- a/phalcon/Debug/Dump.zep
+++ b/phalcon/Debug/Dump.zep
@@ -108,6 +108,7 @@ class Dump
];
let this->styles = array_merge(defaultStyles, styles);
+
return this->styles;
}
@@ -144,10 +145,13 @@ class Dump
*/
public function variable(var variable, string name = null) -> string
{
- return strtr(":output ", [
- ":style": this->getStyle("pre"),
- ":output": this->output(variable, name)
- ]);
+ return strtr(
+ ":output ",
+ [
+ ":style": this->getStyle("pre"),
+ ":output": this->output(variable, name)
+ ]
+ );
}
/**
@@ -170,8 +174,12 @@ class Dump
var key, value, output;
let output = "";
+
for key, value in func_get_args() {
- let output .= this->one(value, "var " . key);
+ let output .= this->one(
+ value,
+ "var " . key
+ );
}
return output;
@@ -184,11 +192,11 @@ class Dump
{
var style;
- if fetch style, this->styles[type] {
- return style;
- } else {
+ if !fetch style, this->styles[type] {
return "color:gray";
}
+
+ return style;
}
/**
@@ -197,6 +205,7 @@ class Dump
protected function output(var variable, string name = null, int tab = 1) -> string
{
var key, value, output, space, type, attr;
+
let space = " ",
output = "";
@@ -218,10 +227,11 @@ class Dump
if tab == 1 && name != "" && !is_int(key) && name == key {
continue;
- } else {
- let output .= this->output(value, "", tab + 1) . "\n";
}
+
+ let output .= this->output(value, "", tab + 1) . "\n";
}
+
return output . str_repeat(space, tab - 1) . ")";
}
@@ -297,6 +307,7 @@ class Dump
let output .= str_repeat(space, tab + 1) . strtr("->:method ();\n", [":style": this->getStyle("obj"), ":method": value]);
}
}
+
let output .= str_repeat(space, tab) . ")\n";
}
diff --git a/phalcon/Debug/Exception.zep b/phalcon/Debug/Exception.zep
index abaeb1b2f8f..fa91ce74e56 100644
--- a/phalcon/Debug/Exception.zep
+++ b/phalcon/Debug/Exception.zep
@@ -14,7 +14,6 @@ namespace Phalcon\Debug;
* Phalcon\Debug\Exception
*
* Exceptions thrown in Phalcon\Debug will use this class
- *
*/
class Exception extends \Phalcon\Exception
{
diff --git a/phalcon/Di.zep b/phalcon/Di.zep
index fdbd0ba7cc0..7cb64f5fd72 100644
--- a/phalcon/Di.zep
+++ b/phalcon/Di.zep
@@ -123,7 +123,13 @@ class Di implements DiInterface
*/
if starts_with(method, "set") {
if fetch definition, arguments[0] {
- this->set(lcfirst(substr(method, 3)), definition);
+ this->set(
+ lcfirst(
+ substr(method, 3)
+ ),
+ definition
+ );
+
return null;
}
}
@@ -143,13 +149,13 @@ class Di implements DiInterface
*/
public function attempt(string! name, definition, bool shared = false) -> | bool
{
- if !isset this->services[name] {
- let this->services[name] = new Service(definition, shared);
-
- return this->services[name];
+ if isset this->services[name] {
+ return false;
}
- return false;
+ let this->services[name] = new Service(definition, shared);
+
+ return this->services[name];
}
/**
@@ -165,6 +171,7 @@ class Di implements DiInterface
*/
if fetch service, this->services[name] {
let isShared = service->isShared();
+
if isShared && isset this->sharedInstances[name] {
return this->sharedInstances[name];
}
@@ -181,7 +188,7 @@ class Di implements DiInterface
"di:beforeServiceResolve",
this,
[
- "name": name,
+ "name": name,
"parameters": parameters
]
);
@@ -189,7 +196,6 @@ class Di implements DiInterface
if typeof instance != "object" {
if service !== null {
-
// The service is registered in the DI.
try {
let instance = service->resolve(parameters, this);
@@ -204,7 +210,6 @@ class Di implements DiInterface
let this->sharedInstances[name] = instance;
}
} else {
-
/**
* The DI also acts as builder for any class even if it isn't
* defined in the DI
@@ -242,9 +247,9 @@ class Di implements DiInterface
"di:afterServiceResolve",
this,
[
- "name": name,
+ "name": name,
"parameters": parameters,
- "instance": instance
+ "instance": instance
]
);
}
@@ -313,7 +318,6 @@ class Di implements DiInterface
* requests for this service will return the same instance
*
* @param array parameters
- * @return mixed
*/
public function getShared(string! name, parameters = null) -> var
{
@@ -491,9 +495,12 @@ class Di implements DiInterface
* {
* public function register(DiInterface $di)
* {
- * $di->setShared('service', function () {
- * // ...
- * });
+ * $di->setShared(
+ * 'service',
+ * function () {
+ * // ...
+ * }
+ * );
* }
* }
*
@@ -554,6 +561,7 @@ class Di implements DiInterface
public function setRaw(string! name, rawDefinition) ->
{
let this->services[name] = rawDefinition;
+
return rawDefinition;
}
diff --git a/phalcon/Di/Exception/ServiceResolutionException.zep b/phalcon/Di/Exception/ServiceResolutionException.zep
index 584b7d505b0..d851797d30a 100644
--- a/phalcon/Di/Exception/ServiceResolutionException.zep
+++ b/phalcon/Di/Exception/ServiceResolutionException.zep
@@ -14,7 +14,6 @@
/**
* Phalcon\Di\Exception\ServiceResolutionException
- *
*/
class ServiceResolutionException extends \Phalcon\Di\Exception
{
diff --git a/phalcon/Di/Injectable.zep b/phalcon/Di/Injectable.zep
index da09a7c6cbb..68068d6956f 100644
--- a/phalcon/Di/Injectable.zep
+++ b/phalcon/Di/Injectable.zep
@@ -73,8 +73,10 @@ abstract class Injectable implements InjectionAwareInterface, EventsAwareInterfa
var container, service, persistent;
let container = this->container;
+
if typeof container != "object" {
let container = \Phalcon\Di::getDefault();
+
if typeof container != "object" {
throw new Exception(
Exception::containerServiceNotFound("internal services")
@@ -88,11 +90,13 @@ abstract class Injectable implements InjectionAwareInterface, EventsAwareInterfa
if container->has(propertyName) {
let service = container->getShared(propertyName);
let this->{propertyName} = service;
+
return service;
}
if propertyName == "di" {
let this->{"di"} = container;
+
return container;
}
@@ -102,6 +106,7 @@ abstract class Injectable implements InjectionAwareInterface, EventsAwareInterfa
if propertyName == "persistent" {
let persistent = container->get("sessionBag", [get_class(this)]),
this->{"persistent"} = persistent;
+
return persistent;
}
@@ -109,6 +114,7 @@ abstract class Injectable implements InjectionAwareInterface, EventsAwareInterfa
* A notice is shown if the property is not defined and isn't a valid service
*/
trigger_error("Access to undefined property " . propertyName);
+
return null;
}
@@ -120,9 +126,11 @@ abstract class Injectable implements InjectionAwareInterface, EventsAwareInterfa
var container;
let container = this->container;
+
if typeof container != "object" {
let container = Di::getDefault();
}
+
return container;
}
diff --git a/phalcon/Di/Service/Builder.zep b/phalcon/Di/Service/Builder.zep
index 8b661a7761a..92b2e806f05 100644
--- a/phalcon/Di/Service/Builder.zep
+++ b/phalcon/Di/Service/Builder.zep
@@ -127,7 +127,6 @@ class Builder
}
if count(arguments) {
-
/**
* Call the method on the instance
*/
diff --git a/phalcon/Di/ServiceProviderInterface.zep b/phalcon/Di/ServiceProviderInterface.zep
index 4fd4868c66e..c144604bde0 100644
--- a/phalcon/Di/ServiceProviderInterface.zep
+++ b/phalcon/Di/ServiceProviderInterface.zep
@@ -28,9 +28,12 @@ use Phalcon\DiInterface;
* {
* public function register(DiInterface $di)
* {
- * $di->setShared('service', function () {
- * // ...
- * });
+ * $di->setShared(
+ * 'service',
+ * function () {
+ * // ...
+ * }
+ * );
* }
* }
*
diff --git a/phalcon/Dispatcher.zep b/phalcon/Dispatcher.zep
index df4b66a605a..e82bbb432cd 100644
--- a/phalcon/Dispatcher.zep
+++ b/phalcon/Dispatcher.zep
@@ -117,7 +117,10 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
public function callActionMethod(handler, string actionMethod, array! params = [])
{
- return call_user_func_array([handler, actionMethod], params);
+ return call_user_func_array(
+ [handler, actionMethod],
+ params
+ );
}
/**
@@ -134,13 +137,12 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
{
bool hasService, hasEventsManager;
int numberDispatches;
- var value, handler, container, namespaceName, handlerName,
- actionName, params, eventsManager,
- handlerClass, status, actionMethod,
- modelBinder, bindCacheKey,
- isNewHandler, handlerHash, e;
+ var value, handler, container, namespaceName, handlerName, actionName,
+ params, eventsManager, handlerClass, status, actionMethod,
+ modelBinder, bindCacheKey, isNewHandler, handlerHash, e;
let container = this->container;
+
if typeof container != "object" {
this->{"throwDispatchException"}(
PhalconException::containerServiceNotFound(
@@ -148,6 +150,7 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
),
self::EXCEPTION_NO_DI
);
+
return false;
}
@@ -180,6 +183,7 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
*/
let status = this->{"handleException"}(e);
+
if this->finished !== false {
// No forwarding
if status === false {
@@ -214,6 +218,7 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
}
let this->finished = true;
+
this->resolveEmptyProperties();
if hasEventsManager {
@@ -238,6 +243,7 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
* Container
*/
let hasService = (bool) container->has(handlerClass);
+
if !hasService {
/**
* DI doesn't have a service with that name, try to load it
@@ -256,6 +262,7 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
if status === false && this->finished === false {
continue;
}
+
break;
}
@@ -271,12 +278,15 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
if status === false && this->finished === false {
continue;
}
+
break;
}
// Check if the handler is new (hasn't been initialized).
let handlerHash = spl_object_hash(handler);
+
let isNewHandler = !(isset this->handlerHashes[handlerHash]);
+
if isNewHandler {
let this->handlerHashes[handlerHash] = true;
}
@@ -303,6 +313,7 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
if status === false && this->finished === false {
continue;
}
+
break;
}
@@ -358,6 +369,7 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
} catch Exception, e {
if this->{"handleException"}(e) === false || this->finished === false {
container->remove(handlerClass);
+
continue;
}
@@ -370,11 +382,13 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
// Calling "beforeExecuteRoute" as direct method
if handler->beforeExecuteRoute(this) === false || this->finished === false {
container->remove(handlerClass);
+
continue;
}
} catch Exception, e {
if this->{"handleException"}(e) === false || this->finished === false {
container->remove(handlerClass);
+
continue;
}
@@ -385,7 +399,6 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
/**
* Call the "initialize" method just once per request
*
- *
* Note: The `dispatch:afterInitialize` event is called regardless
* of the presence of an `initialize()` method. The naming is
* poor; however, the intent is for a more global "constructor
@@ -404,8 +417,8 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
if method_exists(handler, "initialize") {
try {
let this->isControllerInitialize = true;
- handler->initialize();
+ handler->initialize();
} catch Exception, e {
let this->isControllerInitialize = false;
@@ -706,11 +719,11 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
let modelBinder = this->modelBinder;
- if modelBinder != null {
- return modelBinder->getBoundModels();
+ if modelBinder == null {
+ return [];
}
- return [];
+ return modelBinder->getBoundModels();
}
/**
@@ -782,6 +795,7 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
var params, filter, paramValue, container;
let params = this->params;
+
if !fetch paramValue, params[param] {
return defaultValue;
}
@@ -791,6 +805,7 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
}
let container = this->container;
+
if typeof container != "object" {
this->{"throwDispatchException"}(
PhalconException::containerServiceNotFound(
@@ -799,8 +814,10 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
self::EXCEPTION_NO_DI
);
}
+
let filter = container->getShared("filter");
// let filter = container->getShared("filter");
+
return filter->sanitize(paramValue, filters);
}
@@ -867,8 +884,8 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
*/
public function getHandlerClass() -> string
{
- var handlerSuffix, handlerName, namespaceName,
- camelizedClass, handlerClass;
+ var handlerSuffix, handlerName, namespaceName, camelizedClass,
+ handlerClass;
this->resolveEmptyProperties();
@@ -954,7 +971,10 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
* function() {
* $dispatcher = new Dispatcher();
*
- * $dispatcher->setModelBinder(new Binder(), 'cache');
+ * $dispatcher->setModelBinder(
+ * new Binder(),
+ * 'cache'
+ * );
*
* return $dispatcher;
* }
@@ -967,6 +987,7 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
if typeof cache == "string" {
let container = this->container;
+
let cache = container->get(cache);
}
diff --git a/phalcon/DispatcherInterface.zep b/phalcon/DispatcherInterface.zep
index 3751c729db7..399be48f784 100644
--- a/phalcon/DispatcherInterface.zep
+++ b/phalcon/DispatcherInterface.zep
@@ -19,8 +19,6 @@ interface DispatcherInterface
{
/**
* Dispatches a handle action taking into account the routing parameters
- *
- * @return object
*/
public function dispatch() -> object | bool;
@@ -48,7 +46,6 @@ interface DispatcherInterface
* Gets a param by its name or numeric index
*
* @param string|array filters
- * @return mixed
*/
public function getParam(var param, filters = null) -> var;
diff --git a/phalcon/Escaper.zep b/phalcon/Escaper.zep
index 049c6199b7a..4927e93ddbd 100644
--- a/phalcon/Escaper.zep
+++ b/phalcon/Escaper.zep
@@ -59,6 +59,7 @@ class Escaper implements EscaperInterface
* Check if charset is ASCII or ISO-8859-1
*/
let charset = phalcon_is_basic_charset(str);
+
if typeof charset == "string" {
return charset;
}
@@ -96,7 +97,9 @@ class Escaper implements EscaperInterface
* Normalize encoding to UTF-32
* Escape the string
*/
- return phalcon_escape_css(this->normalizeEncoding(css));
+ return phalcon_escape_css(
+ this->normalizeEncoding(css)
+ );
}
/**
@@ -109,7 +112,9 @@ class Escaper implements EscaperInterface
* Normalize encoding to UTF-32
* Escape the string
*/
- return phalcon_escape_js(this->normalizeEncoding(js));
+ return phalcon_escape_js(
+ this->normalizeEncoding(js)
+ );
}
/**
diff --git a/phalcon/Events/Manager.zep b/phalcon/Events/Manager.zep
index c73206ce469..b94faabb386 100644
--- a/phalcon/Events/Manager.zep
+++ b/phalcon/Events/Manager.zep
@@ -53,7 +53,6 @@ class Manager implements ManagerInterface
}
if !fetch priorityQueue, this->events[eventType] {
-
// Create a SplPriorityQueue to store the events with priorities
let priorityQueue = new SplPriorityQueue();
@@ -103,12 +102,12 @@ class Manager implements ManagerInterface
}
if fetch priorityQueue, this->events[eventType] {
-
/**
* SplPriorityQueue doesn't have a method for element deletion so we
* need to rebuild queue
*/
let newPriorityQueue = new SplPriorityQueue();
+
newPriorityQueue->setExtractFlags(SplPriorityQueue::EXTR_DATA);
priorityQueue->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
@@ -116,9 +115,14 @@ class Manager implements ManagerInterface
while priorityQueue->valid() {
let data = priorityQueue->current();
+
priorityQueue->next();
+
if data["data"] !== handler {
- newPriorityQueue->insert(data["data"], data["priority"]);
+ newPriorityQueue->insert(
+ data["data"],
+ data["priority"]
+ );
}
}
@@ -189,9 +193,7 @@ class Manager implements ManagerInterface
// Check if events are grouped by type
if fetch fireEvents, events[type] {
-
if typeof fireEvents == "object" {
-
// Create the event context
let event = new Event(eventName, source, data, cancelable);
@@ -202,9 +204,7 @@ class Manager implements ManagerInterface
// Check if there are listeners for the event type itself
if fetch fireEvents, events[eventType] {
-
if typeof fireEvents == "object" {
-
// Create the event if it wasn't created before
if event === null {
let event = new Event(eventName, source, data, cancelable);
@@ -258,14 +258,13 @@ class Manager implements ManagerInterface
// Get the current data
let handler = iterator->current();
+
iterator->next();
// Only handler objects are valid
if typeof handler == "object" {
-
// Check if the event is a closure
if handler instanceof \Closure {
-
// Create the closure arguments
if arguments === null {
let arguments = [event, source, data];
@@ -280,18 +279,14 @@ class Manager implements ManagerInterface
}
if cancelable {
-
// Check if the event was stopped by the user
if event->isStopped() {
break;
}
}
-
} else {
-
// Check if the listener has implemented an event with the same name
if method_exists(handler, eventName) {
-
// Call the function in the PHP userland
let status = handler->{eventName}(event, source, data);
@@ -301,7 +296,6 @@ class Manager implements ManagerInterface
}
if cancelable {
-
// Check if the event was stopped by the user
if event->isStopped() {
break;
diff --git a/phalcon/Factory.zep b/phalcon/Factory.zep
index 68d370ecde3..cbb14201e77 100644
--- a/phalcon/Factory.zep
+++ b/phalcon/Factory.zep
@@ -31,6 +31,7 @@ abstract class Factory implements FactoryInterface
if fetch adapter, config["adapter"] {
unset config["adapter"];
+
let className = namespaceClass . "\\" . adapter;
return new {className}(config);
diff --git a/phalcon/Filter/Exception.zep b/phalcon/Filter/Exception.zep
index 6d11caf54b8..02f3e759e09 100644
--- a/phalcon/Filter/Exception.zep
+++ b/phalcon/Filter/Exception.zep
@@ -14,7 +14,6 @@ namespace Phalcon\Filter;
* Phalcon\Filter\Exception
*
* Exceptions thrown in Phalcon\Filter will use this class
- *
*/
class Exception extends \Phalcon\Exception
{
diff --git a/phalcon/Filter/FilterLocator.zep b/phalcon/Filter/FilterLocator.zep
index 9b760c38d40..bbd003aa392 100644
--- a/phalcon/Filter/FilterLocator.zep
+++ b/phalcon/Filter/FilterLocator.zep
@@ -77,9 +77,9 @@ class FilterLocator extends Locator
* The above should produce "-had-a-little-lamb"
*/
- /**
- * Filter is an array
- */
+ /**
+ * Filter is an array
+ */
if typeof sanitizers == "array" {
/**
* Null value - return immediately
@@ -146,6 +146,7 @@ class FilterLocator extends Locator
var arrayValue, itemKey, itemValue;
let arrayValue = [];
+
for itemKey, itemValue in values {
let arrayValue[itemKey] = this->sanitizer(
itemValue,
diff --git a/phalcon/Filter/Sanitize/AbsInt.zep b/phalcon/Filter/Sanitize/AbsInt.zep
index a5be94c399b..e12a1a27bf9 100644
--- a/phalcon/Filter/Sanitize/AbsInt.zep
+++ b/phalcon/Filter/Sanitize/AbsInt.zep
@@ -22,6 +22,10 @@ class AbsInt
*/
public function __invoke(var input)
{
- return abs(intval(filter_var(input, FILTER_SANITIZE_NUMBER_INT)));
+ return abs(
+ intval(
+ filter_var(input, FILTER_SANITIZE_NUMBER_INT)
+ )
+ );
}
}
diff --git a/phalcon/Filter/Sanitize/Email.zep b/phalcon/Filter/Sanitize/Email.zep
index 299d92a753d..e60c6d056c9 100644
--- a/phalcon/Filter/Sanitize/Email.zep
+++ b/phalcon/Filter/Sanitize/Email.zep
@@ -22,6 +22,10 @@ class Email
*/
public function __invoke(var input)
{
- return filter_var(input, FILTER_SANITIZE_EMAIL, FILTER_FLAG_EMAIL_UNICODE);
+ return filter_var(
+ input,
+ FILTER_SANITIZE_EMAIL,
+ FILTER_FLAG_EMAIL_UNICODE
+ );
}
}
diff --git a/phalcon/Filter/Sanitize/Upper.zep b/phalcon/Filter/Sanitize/Upper.zep
index b2018d2d440..ee03d6dacc4 100644
--- a/phalcon/Filter/Sanitize/Upper.zep
+++ b/phalcon/Filter/Sanitize/Upper.zep
@@ -26,6 +26,8 @@ class Upper
return mb_convert_case(input, MB_CASE_UPPER, "UTF-8");
}
- return strtoupper(utf8_decode(input));
+ return strtoupper(
+ utf8_decode(input)
+ );
}
}
diff --git a/phalcon/Flash.zep b/phalcon/Flash.zep
index 99f89d8f7c4..50a744cc8b0 100644
--- a/phalcon/Flash.zep
+++ b/phalcon/Flash.zep
@@ -116,6 +116,7 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
public function getDI() ->
{
var di;
+
let di = this->container;
if typeof di != "object" {
@@ -133,6 +134,7 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
var escaper, container;
let escaper = this->escaperService;
+
if typeof escaper != "object" {
let container = this->getDI();
@@ -160,6 +162,7 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
public function setAutoescape(bool autoescape) ->
{
let this->autoescape = autoescape;
+
return this;
}
@@ -169,6 +172,7 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
public function setAutomaticHtml(bool automaticHtml) ->
{
let this->automaticHtml = automaticHtml;
+
return this;
}
@@ -178,6 +182,7 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
public function setCssClasses(array! cssClasses) ->
{
let this->cssClasses = cssClasses;
+
return this;
}
@@ -187,6 +192,7 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
public function setCustomTemplate(string! customTemplate) ->
{
let this->customTemplate = customTemplate;
+
return this;
}
@@ -196,6 +202,7 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
public function setDI( container) ->
{
let this->container = container;
+
return this;
}
@@ -205,6 +212,7 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
public function setEscaperService( escaperService) ->
{
let this->escaperService = escaperService;
+
return this;
}
@@ -215,6 +223,7 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
public function setImplicitFlush(bool implicitFlush) ->
{
let this->implicitFlush = implicitFlush;
+
return this;
}
@@ -243,12 +252,11 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
public function outputMessage(string type, var message)
{
bool implicitFlush;
- var content, msg,
- htmlMessage, preparedMsg;
+ var content, msg, htmlMessage, preparedMsg;
let implicitFlush = (bool) this->implicitFlush;
- if typeof message == "array" {
+ if typeof message == "array" {
/**
* We create the message with implicit flush or other
*/
@@ -285,7 +293,6 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
if !implicitFlush {
return content;
}
-
} else {
/**
* Check if the message needs to be escaped
@@ -305,6 +312,7 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
echo htmlMessage;
} else {
let this->messages[] = htmlMessage;
+
return htmlMessage;
}
}
@@ -325,8 +333,8 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
private function getTemplate(string cssClassses) -> string
{
- if ("" === this->customTemplate) {
- if ("" === cssClassses) {
+ if "" === this->customTemplate {
+ if "" === cssClassses {
return "%message%
" . PHP_EOL;
} else {
return "%message%
" . PHP_EOL;
@@ -370,6 +378,7 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
}
let classes = this->cssClasses;
+
if fetch typeClasses, classes[type] {
if typeof typeClasses == "array" {
let cssClasses = join(" ", typeClasses);
diff --git a/phalcon/Flash/Exception.zep b/phalcon/Flash/Exception.zep
index 5f2b3188db8..5eb4e29fc26 100644
--- a/phalcon/Flash/Exception.zep
+++ b/phalcon/Flash/Exception.zep
@@ -14,7 +14,6 @@ namespace Phalcon\Flash;
* Phalcon\Flash\Exception
*
* Exceptions thrown in Phalcon\Flash will use this class
- *
*/
class Exception extends \Phalcon\Exception
{
diff --git a/phalcon/Flash/Session.zep b/phalcon/Flash/Session.zep
index 967a0134ca2..0d9ac9f332f 100644
--- a/phalcon/Flash/Session.zep
+++ b/phalcon/Flash/Session.zep
@@ -133,6 +133,7 @@ class Session extends FlashBase
session = container->getShared("session");
session->set("_flashMessages", messages);
+
return messages;
}
}
diff --git a/phalcon/Forms/Element.zep b/phalcon/Forms/Element.zep
index 19f1738d510..dce587b3f3a 100644
--- a/phalcon/Forms/Element.zep
+++ b/phalcon/Forms/Element.zep
@@ -40,8 +40,8 @@ abstract class Element implements ElementInterface
/**
* Phalcon\Forms\Element constructor
*
- * @param string name Attribute name (value of 'name' attribute of HTML element)
- * @param array attributes Additional HTML element attributes
+ * @param string name Attribute name (value of 'name' attribute of HTML element)
+ * @param array attributes Additional HTML element attributes
*/
public function __construct(string name, array attributes = []) -> void
{
@@ -154,11 +154,11 @@ abstract class Element implements ElementInterface
let attributes = this->attributes;
- if fetch value, attributes[attribute] {
- return value;
+ if !fetch value, attributes[attribute] {
+ return defaultValue;
}
- return defaultValue;
+ return value;
}
/**
@@ -170,10 +170,6 @@ abstract class Element implements ElementInterface
let attributes = this->attributes;
- if typeof attributes != "array" {
- return [];
- }
-
return attributes;
}
@@ -235,11 +231,11 @@ abstract class Element implements ElementInterface
{
var value;
- if fetch value, this->options[option] {
- return value;
+ if !fetch value, this->options[option] {
+ return defaultValue;
}
- return defaultValue;
+ return value;
}
/**
@@ -316,12 +312,8 @@ abstract class Element implements ElementInterface
let name = this->name;
}
- if typeof attributes == "array" {
- if !isset attributes["for"] {
- let attributes["for"] = name;
- }
- } else {
- let attributes = ["for": name];
+ if !isset attributes["for"] {
+ let attributes["for"] = name;
}
let code = Tag::renderAttributes("label;
+
if label || is_numeric(label) {
let code .= ">" . label . " ";
} else {
@@ -343,36 +336,23 @@ abstract class Element implements ElementInterface
* Returns an array of prepared attributes for Phalcon\Tag helpers
* according to the element parameters
*/
- public function prepareAttributes(array attributes = null, bool useChecked = false) -> array
+ public function prepareAttributes(array attributes = [], bool useChecked = false) -> array
{
- var value, name, widgetAttributes, mergedAttributes,
- defaultAttributes, currentValue;
+ var value, name, mergedAttributes, defaultAttributes, currentValue;
let name = this->name;
- /**
- * Create an array of parameters
- */
- if typeof attributes != "array" {
- let widgetAttributes = [];
- } else {
- let widgetAttributes = attributes;
- }
-
- let widgetAttributes[0] = name;
+ let attributes[0] = name;
/**
* Merge passed parameters with default ones
*/
let defaultAttributes = this->attributes;
- if typeof defaultAttributes == "array" {
- let mergedAttributes = array_merge(
- defaultAttributes,
- widgetAttributes
- );
- } else {
- let mergedAttributes = widgetAttributes;
- }
+
+ let mergedAttributes = array_merge(
+ defaultAttributes,
+ attributes
+ );
/**
* Get the current element value
diff --git a/phalcon/Forms/Element/Check.zep b/phalcon/Forms/Element/Check.zep
index a7370523aa1..f060d9160b5 100644
--- a/phalcon/Forms/Element/Check.zep
+++ b/phalcon/Forms/Element/Check.zep
@@ -20,12 +20,13 @@ use Phalcon\Forms\Element;
*/
class Check extends Element
{
-
/**
* Renders the element widget returning html
*/
public function render(array attributes = []) -> string
{
- return Tag::checkField(this->prepareAttributes(attributes, true));
+ return Tag::checkField(
+ this->prepareAttributes(attributes, true)
+ );
}
}
diff --git a/phalcon/Forms/Element/Date.zep b/phalcon/Forms/Element/Date.zep
index beb6d9325ec..84c7c5c5c6e 100644
--- a/phalcon/Forms/Element/Date.zep
+++ b/phalcon/Forms/Element/Date.zep
@@ -20,12 +20,13 @@ use Phalcon\Forms\Element;
*/
class Date extends Element
{
-
/**
* Renders the element widget returning html
*/
public function render(array attributes = []) -> string
{
- return Tag::dateField(this->prepareAttributes(attributes));
+ return Tag::dateField(
+ this->prepareAttributes(attributes)
+ );
}
}
diff --git a/phalcon/Forms/Element/Email.zep b/phalcon/Forms/Element/Email.zep
index 1f84f670abb..53d81a874f6 100644
--- a/phalcon/Forms/Element/Email.zep
+++ b/phalcon/Forms/Element/Email.zep
@@ -20,12 +20,13 @@ use Phalcon\Forms\Element;
*/
class Email extends Element
{
-
/**
* Renders the element widget returning html
*/
public function render(array attributes = []) -> string
{
- return Tag::emailField(this->prepareAttributes(attributes));
+ return Tag::emailField(
+ this->prepareAttributes(attributes)
+ );
}
}
diff --git a/phalcon/Forms/Element/File.zep b/phalcon/Forms/Element/File.zep
index feddce1ce74..42cb865c28b 100644
--- a/phalcon/Forms/Element/File.zep
+++ b/phalcon/Forms/Element/File.zep
@@ -20,12 +20,13 @@ use Phalcon\Forms\Element;
*/
class File extends Element
{
-
/**
* Renders the element widget returning html
*/
public function render(array attributes = []) -> string
{
- return Tag::fileField(this->prepareAttributes(attributes));
+ return Tag::fileField(
+ this->prepareAttributes(attributes)
+ );
}
}
diff --git a/phalcon/Forms/Element/Hidden.zep b/phalcon/Forms/Element/Hidden.zep
index 6a1b6d377ff..b6208fa36d5 100644
--- a/phalcon/Forms/Element/Hidden.zep
+++ b/phalcon/Forms/Element/Hidden.zep
@@ -20,12 +20,13 @@ use Phalcon\Forms\Element;
*/
class Hidden extends Element
{
-
/**
* Renders the element widget returning html
*/
public function render(array attributes = []) -> string
{
- return Tag::hiddenField(this->prepareAttributes(attributes));
+ return Tag::hiddenField(
+ this->prepareAttributes(attributes)
+ );
}
}
diff --git a/phalcon/Forms/Element/Numeric.zep b/phalcon/Forms/Element/Numeric.zep
index efc2216264f..db2a6950947 100644
--- a/phalcon/Forms/Element/Numeric.zep
+++ b/phalcon/Forms/Element/Numeric.zep
@@ -20,12 +20,13 @@ use Phalcon\Forms\Element;
*/
class Numeric extends Element
{
-
/**
* Renders the element widget returning html
*/
public function render(array attributes = []) -> string
{
- return Tag::numericField(this->prepareAttributes(attributes));
+ return Tag::numericField(
+ this->prepareAttributes(attributes)
+ );
}
}
diff --git a/phalcon/Forms/Element/Password.zep b/phalcon/Forms/Element/Password.zep
index 1f89b3df149..a3803d629fe 100644
--- a/phalcon/Forms/Element/Password.zep
+++ b/phalcon/Forms/Element/Password.zep
@@ -20,12 +20,13 @@ use Phalcon\Forms\Element;
*/
class Password extends Element
{
-
/**
* Renders the element widget returning html
*/
public function render(array attributes = []) -> string
{
- return Tag::passwordField(this->prepareAttributes(attributes));
+ return Tag::passwordField(
+ this->prepareAttributes(attributes)
+ );
}
}
diff --git a/phalcon/Forms/Element/Radio.zep b/phalcon/Forms/Element/Radio.zep
index 36cd10187c9..a6643d1ffd6 100644
--- a/phalcon/Forms/Element/Radio.zep
+++ b/phalcon/Forms/Element/Radio.zep
@@ -20,12 +20,13 @@ use Phalcon\Forms\Element;
*/
class Radio extends Element
{
-
/**
* Renders the element widget returning html
*/
public function render(array attributes = []) -> string
{
- return Tag::radioField(this->prepareAttributes(attributes, true));
+ return Tag::radioField(
+ this->prepareAttributes(attributes, true)
+ );
}
}
diff --git a/phalcon/Forms/Element/Select.zep b/phalcon/Forms/Element/Select.zep
index 145c5630a54..ffe6c26aab6 100644
--- a/phalcon/Forms/Element/Select.zep
+++ b/phalcon/Forms/Element/Select.zep
@@ -26,11 +26,12 @@ class Select extends Element
* Phalcon\Forms\Element constructor
*
* @param object|array options
- * @param array attributes
+ * @param array attributes
*/
public function __construct(string name, options = null, attributes = null) -> void
{
let this->optionsValues = options;
+
parent::__construct(name, attributes);
}
@@ -86,6 +87,7 @@ class Select extends Element
public function setOptions(var options) ->
{
let this->optionsValues = options;
+
return this;
}
}
diff --git a/phalcon/Forms/Element/Submit.zep b/phalcon/Forms/Element/Submit.zep
index 8293cbf97d3..e31eca74371 100644
--- a/phalcon/Forms/Element/Submit.zep
+++ b/phalcon/Forms/Element/Submit.zep
@@ -20,7 +20,6 @@ use Phalcon\Forms\Element;
*/
class Submit extends Element
{
-
/**
* Renders the element widget
*/
@@ -29,6 +28,8 @@ class Submit extends Element
/**
* Merged passed attributes with previously defined ones
*/
- return Tag::submitButton(this->prepareAttributes(attributes));
+ return Tag::submitButton(
+ this->prepareAttributes(attributes)
+ );
}
}
diff --git a/phalcon/Forms/Element/Text.zep b/phalcon/Forms/Element/Text.zep
index fa6389dcf7a..fe348bfd53a 100644
--- a/phalcon/Forms/Element/Text.zep
+++ b/phalcon/Forms/Element/Text.zep
@@ -20,12 +20,13 @@ use Phalcon\Forms\Element;
*/
class Text extends Element
{
-
/**
* Renders the element widget
*/
public function render(array attributes = []) -> string
{
- return Tag::textField(this->prepareAttributes(attributes));
+ return Tag::textField(
+ this->prepareAttributes(attributes)
+ );
}
}
diff --git a/phalcon/Forms/Element/TextArea.zep b/phalcon/Forms/Element/TextArea.zep
index 76206882c5a..3c3c5f3deee 100644
--- a/phalcon/Forms/Element/TextArea.zep
+++ b/phalcon/Forms/Element/TextArea.zep
@@ -20,12 +20,13 @@ use Phalcon\Forms\Element;
*/
class TextArea extends Element
{
-
/**
* Renders the element widget
*/
public function render(array attributes = []) -> string
{
- return Tag::textArea(this->prepareAttributes(attributes));
+ return Tag::textArea(
+ this->prepareAttributes(attributes)
+ );
}
}
diff --git a/phalcon/Forms/ElementInterface.zep b/phalcon/Forms/ElementInterface.zep
index 5af12685746..af89963563b 100644
--- a/phalcon/Forms/ElementInterface.zep
+++ b/phalcon/Forms/ElementInterface.zep
@@ -126,7 +126,7 @@ interface ElementInterface
* Returns an array of prepared attributes for Phalcon\Tag helpers
* according to the element's parameters
*/
- public function prepareAttributes(array attributes = null, bool useChecked = false) -> array;
+ public function prepareAttributes(array attributes = [], bool useChecked = false) -> array;
/**
* Renders the element widget
@@ -156,7 +156,6 @@ interface ElementInterface
*/
public function setFilters(filters) -> ;
-
/**
* Sets the parent form to the element
*/
diff --git a/phalcon/Forms/Form.zep b/phalcon/Forms/Form.zep
index 819a083b1e3..59052a50cdf 100644
--- a/phalcon/Forms/Form.zep
+++ b/phalcon/Forms/Form.zep
@@ -57,6 +57,7 @@ class Form extends Injectable implements \Countable, \Iterator
if typeof entity != "object" {
throw new Exception("The base entity is not valid");
}
+
let this->entity = entity;
}
@@ -106,12 +107,14 @@ class Form extends Injectable implements \Countable, \Iterator
/**
* Add the element before position
*/
- let elements[name] = element, elements[key] = value;
+ let elements[name] = element,
+ elements[key] = value;
} else {
/**
* Add the element after position
*/
- let elements[key] = value, elements[name] = element;
+ let elements[key] = value,
+ elements[name] = element;
}
} else {
/**
@@ -120,8 +123,10 @@ class Form extends Injectable implements \Countable, \Iterator
let elements[key] = value;
}
}
+
let this->elements = elements;
}
+
return this;
}
@@ -165,7 +170,6 @@ class Form extends Injectable implements \Countable, \Iterator
let filters = element->getFilters();
if filters {
-
if typeof filter != "object" {
let container = this->getDI(),
filter = container->getShared("filter");
@@ -186,6 +190,7 @@ class Form extends Injectable implements \Countable, \Iterator
let method = "set" . camelize(key);
if method_exists(entity, method) {
entity->{method}(filteredValue);
+
continue;
}
@@ -210,6 +215,7 @@ class Form extends Injectable implements \Countable, \Iterator
var elements, element, data, field;
let data = this->data;
+
if fields === null {
let data = [];
} else {
@@ -280,11 +286,11 @@ class Form extends Injectable implements \Countable, \Iterator
{
var element;
- if fetch element, this->elementsIndexed[this->position] {
- return element;
+ if !fetch element, this->elementsIndexed[this->position] {
+ return false;
}
- return false;
+ return element;
}
/**
@@ -294,13 +300,13 @@ class Form extends Injectable implements \Countable, \Iterator
{
var element;
- if fetch element, this->elements[name] {
- return element;
+ if !fetch element, this->elements[name] {
+ throw new Exception(
+ "Element with ID=" . name . " is not part of the form"
+ );
}
- throw new Exception(
- "Element with ID=" . name . " is not part of the form"
- );
+ return element;
}
/**
@@ -389,6 +395,7 @@ class Form extends Injectable implements \Countable, \Iterator
*/
if unlikely byItemName {
let messagesByItem = [];
+
messages->rewind();
while messages->valid() {
@@ -407,8 +414,10 @@ class Form extends Injectable implements \Countable, \Iterator
messages->next();
}
+
return messagesByItem;
}
+
return messages;
}
@@ -423,6 +432,7 @@ class Form extends Injectable implements \Countable, \Iterator
if this->has(name) {
return this->get(name)->getMessages();
}
+
return new Messages();
}
@@ -432,10 +442,12 @@ class Form extends Injectable implements \Countable, \Iterator
public function getUserOption(string option, var defaultValue = null) -> var
{
var value;
- if fetch value, this->options[option] {
- return value;
+
+ if !fetch value, this->options[option] {
+ return defaultValue;
}
- return defaultValue;
+
+ return value;
}
/**
@@ -464,7 +476,6 @@ class Form extends Injectable implements \Countable, \Iterator
}
if typeof entity == "object" {
-
/**
* Check if the entity has a getter
*/
@@ -482,7 +493,6 @@ class Form extends Injectable implements \Countable, \Iterator
}
if typeof data == "array" {
-
/**
* Check if the data is in the data array
*/
@@ -492,18 +502,18 @@ class Form extends Injectable implements \Countable, \Iterator
}
let forbidden = [
- "validation" : true,
- "action" : true,
- "useroption" : true,
- "useroptions" : true,
- "entity" : true,
- "elements" : true,
- "messages" : true,
- "messagesfor" : true,
- "label" : true,
- "value" : true,
- "di" : true,
- "eventsmanager" : true
+ "validation": true,
+ "action": true,
+ "useroption": true,
+ "useroptions": true,
+ "entity": true,
+ "elements": true,
+ "messages": true,
+ "messagesfor": true,
+ "label": true,
+ "value": true,
+ "di": true,
+ "eventsmanager": true
];
/**
@@ -611,8 +621,8 @@ class Form extends Injectable implements \Countable, \Iterator
}
for element in this->elements {
-
let validators = element->getValidators();
+
if count(validators) == 0 {
continue;
}
@@ -651,7 +661,9 @@ class Form extends Injectable implements \Countable, \Iterator
for elementMessage in iterator(messages) {
this->get(elementMessage->getField())->appendMessage(elementMessage);
}
+
messages->rewind();
+
let validationStatus = false;
}
@@ -690,13 +702,13 @@ class Form extends Injectable implements \Countable, \Iterator
{
var element;
- if fetch element, this->elements[name] {
- return element->label(attributes);
+ if !fetch element, this->elements[name] {
+ throw new Exception(
+ "Element with ID=" . name . " is not part of the form"
+ );
}
- throw new Exception(
- "Element with ID=" . name . " is not part of the form"
- );
+ return element->label(attributes);
}
/**
@@ -733,6 +745,7 @@ class Form extends Injectable implements \Countable, \Iterator
*/
if isset this->elements[name] {
unset this->elements[name];
+
return true;
}
@@ -760,6 +773,7 @@ class Form extends Injectable implements \Countable, \Iterator
public function setAction(string! action) ->