Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
mvkasatkin committed Sep 14, 2017
1 parent 2887006 commit 54ae704
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 95 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "web-complete/entity",
"name": "web-complete/core",
"description": "WebComplete architecture core for DDD",
"license": "MIT",
"keywords": ["entity", "service", "resource", "core", "DDD"],
Expand All @@ -17,7 +17,6 @@
"php": ">=7.0.0",
"psr/container": "^1.0",
"php-di/php-di": "^5.4",
"php-di/invoker": "*",
"doctrine/dbal": "^2.5"
},
"require-dev": {
Expand Down
3 changes: 0 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
# WebComplete Core

[![Build Status](https://travis-ci.org/web-complete/core.svg?branch=master)](https://travis-ci.org/web-complete/core)
[![Coverage Status](https://coveralls.io/repos/github/web-complete/core/badge.svg?branch=master)](https://coveralls.io/github/web-complete/core?branch=master)

31 changes: 8 additions & 23 deletions src/form/AbstractForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
namespace WebComplete\core\form;


use WebComplete\core\utils\invoker\Invoker;
use WebComplete\core\utils\invoker\InvokerException;
use WebComplete\core\utils\invoker\InvokerInterface;

abstract class AbstractForm
{

Expand All @@ -27,16 +23,11 @@ abstract class AbstractForm
*/
protected $validatorFactory;

/**
* @var InvokerInterface
*/
protected $invoker;

/**
* @return array [[field, validator, params, message], ...]
*
* validator - is a string equals to method of ValidatorFactory, method of the form or callable.
* Validator will be invoked with named params.
* Validator should be declared as ($value, $params) : bool
*
* example
* ```
Expand All @@ -57,7 +48,7 @@ abstract public function rules();
* @return array [[field, filter, params], ...]
*
* filter - is a string equals to method of FilterFactory, method of the form or callable
* Filter will be invoked with named params.
* Filter should be declared as ($value, $params) : mixed, and return filtered value
*
* example
* ```
Expand All @@ -79,19 +70,16 @@ abstract public function filters();
* @param null|array $filters
* @param null|object $filterFactory
* @param null|object $validatorFactory
* @param null|InvokerInterface $invoker
*/
public function __construct(
$rules = null,
$filters = null,
$filterFactory = null,
$validatorFactory = null,
InvokerInterface $invoker = null
$validatorFactory = null
)
{
$this->filterFactory = $filterFactory;
$this->validatorFactory = $validatorFactory;
$this->invoker = $invoker ?: new Invoker();

$this->rules = is_array($rules)
? array_merge($this->rules(), $rules)
Expand Down Expand Up @@ -132,8 +120,7 @@ public function validate()
if(isset($definitions[$field])) {
foreach ($definitions[$field] as $definition) {
$defName = array_shift($definition);
$defParams = array_shift($definition);
$defParams['value'] = $value;
$defParams = array_merge([$value], array_shift($definition));
$defMessage = array_shift($definition) ?: $this->defaultError;

if(is_callable($defName)) {
Expand All @@ -145,7 +132,8 @@ public function validate()
else {
$callable = [$this, $defName];
}
if(!$this->invoker->call($callable, $defParams)) {

if(!call_user_func_array($callable, $defParams)) {
$this->addError($field, $defMessage);
}
}
Expand Down Expand Up @@ -231,8 +219,6 @@ public function resetErrors($field = null)
/**
* @param array $data
* @return array
*
* @throws InvokerException
*/
protected function filter(array $data)
{
Expand All @@ -242,8 +228,7 @@ protected function filter(array $data)
if(isset($definitions[$field])) {
foreach ($definitions[$field] as $definition) {
$defName = array_shift($definition);
$defParams = array_shift($definition);
$defParams['value'] = $value;
$defParams = array_merge([$value], array_shift($definition));

if(is_callable($defName)) {
$callable = $defName;
Expand All @@ -254,7 +239,7 @@ protected function filter(array $data)
else {
$callable = [$this, $defName];
}
$data[$field] = $this->invoker->call($callable, $defParams);
$data[$field] = call_user_func_array($callable, $defParams);
}
}
}
Expand Down
37 changes: 0 additions & 37 deletions src/utils/invoker/Invoker.php

This file was deleted.

9 changes: 0 additions & 9 deletions src/utils/invoker/InvokerException.php

This file was deleted.

21 changes: 0 additions & 21 deletions src/utils/invoker/InvokerInterface.php

This file was deleted.

0 comments on commit 54ae704

Please sign in to comment.