Skip to content

Commit

Permalink
Merge pull request #50 from nthachus/laravel4
Browse files Browse the repository at this point in the history
Update to release branch laravel4 as version 0.9.1
  • Loading branch information
bgultekin committed Feb 24, 2018
2 parents 992b645 + c747378 commit 0b33e18
Show file tree
Hide file tree
Showing 19 changed files with 555 additions and 481 deletions.
15 changes: 14 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,21 @@ php:
- 5.6
- hhvm

matrix:
include:
- php: 5.3
dist: precise
allow_failures:
- php: hhvm
fast_finish: true

cache:
directories:
- vendor
- $HOME/.composer/cache

before_script:
- travis_retry composer self-update
- travis_retry composer install --prefer-source --no-interaction --dev
- travis_retry composer install --no-interaction --no-progress

script: phpunit
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class UserController extends Controller {

if ($validator->fails())
{
// actually withErrors is not really neccessary because we already show errors at client side for normal users
// actually withErrors is not really necessary because we already show errors at client side for normal users
return Redirect::back()->withErrors($validator);
}

Expand Down Expand Up @@ -187,7 +187,7 @@ Form::converter()->route()->extend('someotherrule', function($name, $parameters)
});
```

Second, you can create your own converter (which extends baseconverter or any current plugin converter) in `Bllim\Laravalid\Converter\` namespace and change plugin configuration in config file with your own plugin name.
Second, you can create your own converter (which extends `Base\Converter` or any current plugin converter) in `Bllim\Laravalid\Converter\` namespace and change plugin configuration in config file with your own plugin name.

> **Note:** If you are creating a converter for some existed html/js plugin please create it in `converter` folder and send a pull-request.
Expand Down Expand Up @@ -244,7 +244,7 @@ To use Jquery Validation, change plugin to `JqueryValidation` in config file and
### Contribution
You can fork and contribute to development of the package. All pull requests is welcome.

**Convertion Logic**
**Conversion Logic**
Package converts rules by using converters (in `src/Bllim/Laravalid/converter`). It uses `Converter` class of chosen plugin which extends `Converter/Base/Converter` class.
You can look at existed methods and plugins to understand how it works. Explanation will be ready, soon.

Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@
],
"require": {
"php": ">=5.3.0",
"illuminate/config": "~4.2",
"illuminate/html": "~4.2",
"illuminate/support": "~4.2",
"illuminate/config": "~4.0",
"illuminate/html": "~4.0",
"illuminate/support": "~4.0",
"illuminate/validation": "~4.0",
"illuminate/routing": "~4.0",
"illuminate/translation": "~4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"mockery/mockery": "~0.9"
"phpunit/phpunit": "~4.0"
},
"autoload": {
"psr-0": {
Expand Down
18 changes: 16 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.0/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
Expand All @@ -8,11 +10,23 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist addUncoveredFilesFromWhitelist="false">
<directory suffix=".php">./src/</directory>
<exclude>
<directory suffix=".php">./vendor/</directory>
</exclude>
</whitelist>
</filter>

<logging>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
</logging>
</phpunit>
6 changes: 3 additions & 3 deletions src/Bllim/Laravalid/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function model($model, array $options = array(), $rules = null)
/**
* {@inheritdoc}
*/
public function input($type, $name, $value = null, $options = [])
public function input($type, $name, $value = null, $options = array())
{
$options += $this->getValidationAttributes($name, $type);
return parent::input($type, $name, $value, $options);
Expand All @@ -97,7 +97,7 @@ public function input($type, $name, $value = null, $options = [])
/**
* {@inheritdoc}
*/
public function textarea($name, $value = null, $options = [])
public function textarea($name, $value = null, $options = array())
{
$options += $this->getValidationAttributes($name);
return parent::textarea($name, $value, $options);
Expand All @@ -106,7 +106,7 @@ public function textarea($name, $value = null, $options = [])
/**
* {@inheritdoc}
*/
public function select($name, $list = [], $selected = null, $options = [])
public function select($name, $list = array(), $selected = null, $options = array())
{
$options += $this->getValidationAttributes($name);
return parent::select($name, $list, $selected, $options);
Expand Down
10 changes: 5 additions & 5 deletions src/Bllim/Laravalid/LaravalidServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function boot()
$routeName = $app['config']->get('laravalid::route', 'laravalid');

$app['router']->any($routeName . '/{rule}', function ($rule) use ($app) {
return $app['laravalid']->converter()->route()->convert($rule, [$app['request']->all()]);
return $app['laravalid']->converter()->route()->convert($rule, array($app['request']->all()));
})->where('rule', '[\w-]+');
}

Expand All @@ -35,14 +35,14 @@ public function register()
{
// try to register the HTML builder instance
if (!$this->app->bound('html')) {
$this->app->bindShared('html', function($app)
$this->app->singleton('html', $this->app->share(function($app)
{
return new \Illuminate\Html\HtmlBuilder($app['url']);
});
}));
}

// register the new form builder instance
$this->app->bindShared('laravalid', function ($app) {
$this->app->singleton('laravalid', $this->app->share(function ($app) {
/* @var $app \Illuminate\Container\Container */
$plugin = $app['config']->get('laravalid::plugin');
$converterClass = (strpos($plugin, '\\') === false ? 'Bllim\Laravalid\Converter\\' : '') . $plugin . '\Converter';
Expand All @@ -52,7 +52,7 @@ public function register()
$form = new FormBuilder($app['html'], $app['url'], $session->getToken(), new $converterClass($app));

return $form->setSessionStore($session);
});
}));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Bllim/Laravalid/converter/Base/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

abstract class Container {

protected $customMethods = [];
protected $customMethods = array();

public function convert($name, $parameters = [])
public function convert($name, $parameters = array())
{
$methodName = strtolower($name);

Expand All @@ -24,7 +24,7 @@ public function convert($name, $parameters = [])

if (method_exists($this, $methodName))
{
return call_user_func_array([$this, $methodName], $parameters);
return call_user_func_array(array($this, $methodName), $parameters);
}

return null;
Expand Down
24 changes: 12 additions & 12 deletions src/Bllim/Laravalid/converter/Base/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,29 @@ abstract class Converter {
*
* @var array
*/
protected $validationRules = [];
protected $validationRules = array();

protected static $multiParamRules = [
protected static $multiParamRules = array(
'between', 'digits_between',
'in', 'not_in',
'mimes',
'required_if', 'required_with', 'required_with_all', 'required_without', 'required_without_all',
'exists', 'unique',
];
);

/**
* Rules which specify input type is file
*
* @var array
*/
protected static $fileRules = ['image', 'mimes'];
protected static $fileRules = array('image', 'mimes');

/**
* Rules which specify input type is numeric
*
* @var array
*/
protected static $numericRules = ['integer', 'numeric', 'digits', 'digits_between'];
protected static $numericRules = array('integer', 'numeric', 'digits', 'digits_between');

/**
* @var bool
Expand All @@ -75,7 +75,7 @@ public function __construct($app)
$config = $app['config'];
$routeUrl = $app['url']->to($config->get('laravalid::route', 'laravalid'));

$ns = substr(static::class, 0, -9) ?: '\\';
$ns = substr($class = get_class($this), 0, strrpos($class, '\\')) . '\\';
($class = $ns . 'Rule') and static::$rule = new $class($routeUrl, $app['encrypter']);
($class = $ns . 'Message') and static::$message = new $class($app['translator']);
($class = $ns . 'Route') and static::$route = new $class($app['validator'], $app['encrypter']);
Expand Down Expand Up @@ -114,7 +114,7 @@ public function set($rules)
*/
public function reset()
{
$this->validationRules = [];
$this->validationRules = array();
}

/**
Expand Down Expand Up @@ -154,18 +154,18 @@ protected function checkValidationRule($inputName)
public function convert($inputName, $inputType = null)
{
if (!$this->checkValidationRule($inputName)) {
return [];
return array();
}

$rules = $this->getValidationRule($inputName);
$type = $this->getTypeOfInput($rules);

$outputAttributes = [];
$outputAttributes = array();
foreach ($rules as $rule)
{
$parsedRule = $this->parseValidationRule($rule);

$ruleAttributes = $this->rule()->convert($parsedRule['name'], [$parsedRule, $inputName, $type]);
$ruleAttributes = $this->rule()->convert($parsedRule['name'], array($parsedRule, $inputName, $type));
if (!empty($ruleAttributes)) {
$outputAttributes = $this->rule()->mergeOutputAttributes($outputAttributes, $ruleAttributes, $inputType);

Expand All @@ -174,7 +174,7 @@ public function convert($inputName, $inputType = null)

if ($this->useLaravelMessages)
{
$messageAttributes = $this->message()->convert($parsedRule['name'], [$parsedRule, $inputName, $type]);
$messageAttributes = $this->message()->convert($parsedRule['name'], array($parsedRule, $inputName, $type));

// if empty message attributes
if (empty($messageAttributes) && !empty($ruleAttributes))
Expand Down Expand Up @@ -251,7 +251,7 @@ protected function getDefaultErrorMessage($laravelRule, $attribute)
{
// getting user friendly validation message
$message = $this->message()->getValidationMessage($attribute, $laravelRule);
return ['data-msg-' . $laravelRule => $message];
return array('data-msg-' . $laravelRule => $message);
}

}
4 changes: 2 additions & 2 deletions src/Bllim/Laravalid/converter/Base/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct($translator)
* @return string
* @see Illuminate\Validation\Validator::getMessage()
*/
public function getValidationMessage($attribute, $rule, $data = [], $type = null)
public function getValidationMessage($attribute, $rule, $data = array(), $type = null)
{
$path = Str::snake($rule);
if ($type !== null)
Expand All @@ -49,7 +49,7 @@ public function getValidationMessage($attribute, $rule, $data = [], $type = null

$niceName = $this->getValidationAttribute($attribute);

return $this->translator->get('validation.' . $path, $data + ['attribute' => $niceName]);
return $this->translator->get('validation.' . $path, $data + array('attribute' => $niceName));
}

protected function getValidationAttribute($attribute)
Expand Down
8 changes: 4 additions & 4 deletions src/Bllim/Laravalid/converter/Base/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public function __construct($validatorFactory, $encrypter)
$this->encrypter = $encrypter;
}

public function convert($name, $parameters = [])
public function convert($name, $parameters = array())
{
if (!is_null($result = parent::convert($name, $parameters)))
return $result;

return $this->defaultRoute($name, reset($parameters) ?: []);
return $this->defaultRoute($name, reset($parameters) ?: array());
}

protected function defaultRoute($name, $parameters = [])
protected function defaultRoute($name, $parameters = array())
{
$params = $this->decryptParameters($parameters);

Expand All @@ -60,7 +60,7 @@ protected function defaultRoute($name, $parameters = [])

protected function decryptParameters(array &$parameters)
{
$params = empty($parameters['params']) ? []
$params = empty($parameters['params']) ? array()
: (is_array($parameters['params']) ? $parameters['params'] : array($parameters['params']));
unset($parameters['params'], $parameters['_']);

Expand Down
Loading

0 comments on commit 0b33e18

Please sign in to comment.