Skip to content

Commit

Permalink
Make source code compatible with PHP 5.3 / Laravel 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nthachus committed Feb 23, 2018
1 parent 51444ec commit c747378
Show file tree
Hide file tree
Showing 17 changed files with 386 additions and 370 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
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
}
],
"require": {
"php": ">=5.4.0",
"illuminate/config": "~4.2",
"illuminate/html": "~4.2",
"illuminate/support": "~4.2",
"php": ">=5.3.0",
"illuminate/config": "~4.0",
"illuminate/html": "~4.0",
"illuminate/support": "~4.0",
"illuminate/validation": "~4.0",
"illuminate/routing": "~4.0",
"illuminate/translation": "~4.0"
Expand Down
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
22 changes: 11 additions & 11 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 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
48 changes: 24 additions & 24 deletions src/Bllim/Laravalid/converter/JqueryValidation/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ class Message extends \Bllim\Laravalid\Converter\Base\Message {
public function ip($parsedRule, $attribute)
{
$message = $this->getValidationMessage($attribute, $parsedRule['name']);
return ['data-msg-ipv4' => $message];
return array('data-msg-ipv4' => $message);
}

public function same($parsedRule, $attribute)
{
$other = $this->getValidationAttribute(reset($parsedRule['parameters']));
$message = $this->getValidationMessage($attribute, $parsedRule['name'], compact('other'));
return ['data-msg-equalto' => $message];
return array('data-msg-equalto' => $message);
}

public function different($parsedRule, $attribute)
{
$other = $this->getValidationAttribute(reset($parsedRule['parameters']));
$message = $this->getValidationMessage($attribute, $parsedRule['name'], compact('other'));
return ['data-msg-notequalto' => $message];
return array('data-msg-notequalto' => $message);
}

public function alpha($parsedRule, $attribute)
Expand All @@ -35,79 +35,79 @@ public function alpha_num($parsedRule, $attribute)
public function regex($parsedRule, $attribute)
{
$message = $this->getValidationMessage($attribute, $parsedRule['name']);
return ['data-msg-pattern' => $message];
return array('data-msg-pattern' => $message);
}

public function image($parsedRule, $attribute)
{
$message = $this->getValidationMessage($attribute, $parsedRule['name']);
return ['data-msg-accept' => $message];
return array('data-msg-accept' => $message);
}

public function before($parsedRule, $attribute)
{
$message = $this->getValidationMessage($attribute, $parsedRule['name'], ['date' => '{0}']);
return ['data-msg-max' => $message];
$message = $this->getValidationMessage($attribute, $parsedRule['name'], array('date' => '{0}'));
return array('data-msg-max' => $message);
}

public function after($parsedRule, $attribute)
{
$message = $this->getValidationMessage($attribute, $parsedRule['name'], ['date' => '{0}']);
return ['data-msg-min' => $message];
$message = $this->getValidationMessage($attribute, $parsedRule['name'], array('date' => '{0}'));
return array('data-msg-min' => $message);
}

public function numeric($parsedRule, $attribute)
{
$message = $this->getValidationMessage($attribute, $parsedRule['name']);
return ['data-msg-number' => $message];
return array('data-msg-number' => $message);
}

public function max($parsedRule, $attribute, $type)
{
$message = $this->getValidationMessage($attribute, $parsedRule['name'], ['max' => '{0}'], $type);
$message = $this->getValidationMessage($attribute, $parsedRule['name'], array('max' => '{0}'), $type);
switch ($type) {
case 'numeric':
return ['data-msg-max' => $message];
return array('data-msg-max' => $message);
break;

default:
return ['data-msg-maxlength' => $message];
return array('data-msg-maxlength' => $message);
break;
}
}

public function min($parsedRule, $attribute, $type)
{
$message = $this->getValidationMessage($attribute, $parsedRule['name'], ['min' => '{0}'], $type);
$message = $this->getValidationMessage($attribute, $parsedRule['name'], array('min' => '{0}'), $type);
switch ($type) {
case 'numeric':
return ['data-msg-min' => $message];
return array('data-msg-min' => $message);
break;

default:
return ['data-msg-minlength' => $message];
return array('data-msg-minlength' => $message);
break;
}
}

public function between($parsedRule, $attribute, $type)
{
$message = $this->getValidationMessage($attribute, $parsedRule['name'], ['min' => '{0}', 'max' => '{1}'], $type);
$message = $this->getValidationMessage($attribute, $parsedRule['name'], array('min' => '{0}', 'max' => '{1}'), $type);
switch ($type) {
case 'numeric':
return ['data-msg-range' => $message];
return array('data-msg-range' => $message);
break;

default:
return ['data-msg-rangelength' => $message/*, 'data-msg-maxlength' => $message*/];
return array('data-msg-rangelength' => $message/*, 'data-msg-maxlength' => $message*/);
break;
}
}

public function unique($parsedRule, $attribute)
{
$message = $this->getValidationMessage($attribute, $parsedRule['name']);
return ['data-msg-remote' => $message];
return array('data-msg-remote' => $message);
}

public function exists($parsedRule, $attribute)
Expand All @@ -117,9 +117,9 @@ public function exists($parsedRule, $attribute)

public function required_with($parsedRule, $attribute)
{
$values = implode(', ', array_map([$this, 'getValidationAttribute'], $parsedRule['parameters']));
$values = implode(', ', array_map(array($this, 'getValidationAttribute'), $parsedRule['parameters']));
$message = $this->getValidationMessage($attribute, $parsedRule['name'], compact('values'));
return ['data-msg-required' => $message];
return array('data-msg-required' => $message);
}

public function required_without($parsedRule, $attribute)
Expand All @@ -134,8 +134,8 @@ public function active_url($parsedRule, $attribute)

public function mimes($parsedRule, $attribute)
{
$message = $this->getValidationMessage($attribute, $parsedRule['name'], ['values' => implode(', ', $parsedRule['parameters'])]);
return ['data-msg-accept' => $message];
$message = $this->getValidationMessage($attribute, $parsedRule['name'], array('values' => implode(', ', $parsedRule['parameters'])));
return array('data-msg-accept' => $message);
}

}
Loading

0 comments on commit c747378

Please sign in to comment.