Skip to content

Commit

Permalink
Merge pull request #3 from edcoreweb/master
Browse files Browse the repository at this point in the history
Added support for PHP 5.3 using Illuminate 4.1.*
  • Loading branch information
cretueusebiu committed Feb 25, 2016
2 parents 90f8bad + adfc281 commit 7f1d930
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 28 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
}
],
"require": {
"php": ">=5.4",
"illuminate/validation": "5.0.*|5.1.*"
"php": ">=5.3.0",
"illuminate/validation": "4.1.*"
},
"autoload": {
"psr-4": {
Expand Down
34 changes: 34 additions & 0 deletions src/Arr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Hazzard\Validation;

use ArrayAccess;

class Arr
{
/**
* Get an item from an array using "dot" notation.
*
* @param \ArrayAccess|array $array
* @param string $key
* @param mixed $default
* @return mixed
*/
public static function get($array, $key, $default = null)
{
if (is_null($key)) {
return $array;
}
if (isset($array[$key])) {
return $array[$key];
}
foreach (explode('.', $key) as $segment) {
if ((! is_array($array) || ! array_key_exists($segment, $array)) &&
(! $array instanceof ArrayAccess || ! $array->offsetExists($segment))) {
return value($default);
}
$array = $array[$segment];
}
return $array;
}
}
10 changes: 5 additions & 5 deletions src/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Hazzard\Validation;

use Illuminate\Support\Arr;
use Hazzard\Validation\Arr;
use Illuminate\Support\Collection;
use Symfony\Component\Translation\TranslatorInterface;

Expand All @@ -20,7 +20,7 @@ class Translator implements TranslatorInterface
*
* @param array $lines
*/
public function __construct(array $lines = [])
public function __construct(array $lines = array())
{
if (count($lines)) {
$this->setLines($lines);
Expand All @@ -35,7 +35,7 @@ public function __construct(array $lines = [])
*/
public function setLines(array $lines)
{
$this->lines = ['validation' => $lines];
$this->lines = array('validation' => $lines);
}

/**
Expand All @@ -47,7 +47,7 @@ public function setLines(array $lines)
* @param string $locale
* @return string
*/
public function trans($id, array $parameters = [], $domain = 'messages', $locale = null)
public function trans($id, array $parameters = array(), $domain = 'messages', $locale = null)
{
$line = Arr::get($this->lines, $id);

Expand Down Expand Up @@ -81,7 +81,7 @@ protected function makeReplacements($line, array $replace)
/**
* @inheritDoc
*/
public function transChoice($id, $number, array $parameters = [], $domain = 'messages', $locale = null)
public function transChoice($id, $number, array $parameters = array(), $domain = 'messages', $locale = null)
{

}
Expand Down
12 changes: 6 additions & 6 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Hazzard\Validation;

use Illuminate\Validation\Factory;
use Illuminate\Contracts\Container\Container;
use Illuminate\Container\Container;
use Illuminate\Validation\DatabasePresenceVerifier;
use Illuminate\Database\ConnectionResolverInterface;

Expand All @@ -24,7 +24,7 @@ class Validator
/**
* Register the validator.
*
* @param \Illuminate\Contracts\Container\Container $container
* @param \Illuminate\Container\Container $container
*/
public function __construct(Container $container = null)
{
Expand Down Expand Up @@ -85,7 +85,7 @@ class_alias(get_class($this), $alias);
/**
* Get the validation factory instance.
*
* @return \Illuminate\Contracts\Validation\Factory
* @return \Illuminate\Validation\Factory
*/
public function getFactory()
{
Expand All @@ -95,7 +95,7 @@ public function getFactory()
/**
* Get a translator instance.
*
* @param \Illuminate\Contracts\Container\Container $container
* @param \Illuminate\Container\Container $container
* @return \Symfony\Component\Translation\TranslatorInterface
*/
protected function getTranslator(Container $container = null)
Expand Down Expand Up @@ -126,7 +126,7 @@ public function setAsGlobal()
*/
public function __call($method, $arguments)
{
return call_user_func_array([$this->factory, $method], $arguments);
return call_user_func_array(array($this->factory, $method), $arguments);
}

/**
Expand All @@ -140,6 +140,6 @@ public static function __callStatic($method, $arguments)
{
$factory = static::$instance->getFactory();

return call_user_func_array([$factory, $method], $arguments);
return call_user_func_array(array($factory, $method), $arguments);
}
}
30 changes: 15 additions & 15 deletions src/validation.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

return [
return array(

/*
|--------------------------------------------------------------------------
Expand All @@ -21,12 +21,12 @@
'alpha_num' => 'The :attribute may only contain letters and numbers.',
'array' => 'The :attribute must be an array.',
'before' => 'The :attribute must be a date before :date.',
'between' => [
'between' => array(
'numeric' => 'The :attribute must be between :min and :max.',
'file' => 'The :attribute must be between :min and :max kilobytes.',
'string' => 'The :attribute must be between :min and :max characters.',
'array' => 'The :attribute must have between :min and :max items.',
],
),
'boolean' => 'The :attribute field must be true or false.',
'confirmed' => 'The :attribute confirmation does not match.',
'date' => 'The :attribute is not a valid date.',
Expand All @@ -41,19 +41,19 @@
'in' => 'The selected :attribute is invalid.',
'integer' => 'The :attribute must be an integer.',
'ip' => 'The :attribute must be a valid IP address.',
'max' => [
'max' => array(
'numeric' => 'The :attribute may not be greater than :max.',
'file' => 'The :attribute may not be greater than :max kilobytes.',
'string' => 'The :attribute may not be greater than :max characters.',
'array' => 'The :attribute may not have more than :max items.',
],
),
'mimes' => 'The :attribute must be a file of type: :values.',
'min' => [
'min' => array(
'numeric' => 'The :attribute must be at least :min.',
'file' => 'The :attribute must be at least :min kilobytes.',
'string' => 'The :attribute must be at least :min characters.',
'array' => 'The :attribute must have at least :min items.',
],
),
'not_in' => 'The selected :attribute is invalid.',
'numeric' => 'The :attribute must be a number.',
'regex' => 'The :attribute format is invalid.',
Expand All @@ -64,12 +64,12 @@
'required_without' => 'The :attribute field is required when :values is not present.',
'required_without_all' => 'The :attribute field is required when none of :values are present.',
'same' => 'The :attribute and :other must match.',
'size' => [
'size' => array(
'numeric' => 'The :attribute must be :size.',
'file' => 'The :attribute must be :size kilobytes.',
'string' => 'The :attribute must be :size characters.',
'array' => 'The :attribute must contain :size items.',
],
),
'string' => 'The :attribute must be a string.',
'timezone' => 'The :attribute must be a valid zone.',
'unique' => 'The :attribute has already been taken.',
Expand All @@ -86,11 +86,11 @@
|
*/

'custom' => [
'attribute-name' => [
'custom' => array(
'attribute-name' => array(
'rule-name' => 'custom-message',
],
],
),
),

/*
|--------------------------------------------------------------------------
Expand All @@ -103,6 +103,6 @@
|
*/

'attributes' => [],
'attributes' => array(),

];
);

0 comments on commit 7f1d930

Please sign in to comment.