Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Updated array syntax to PHP 5.4. #294

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions src/Ardent/Ardent.php
Original file line number Diff line number Diff line change
@@ -29,21 +29,21 @@ abstract class Ardent extends Model {
*
* @var array
*/
public static $rules = array();
public static $rules = [];

/**
* The array of custom error messages.
*
* @var array
*/
public static $customMessages = array();
public static $customMessages = [];

/**
* The array of custom attributes.
*
* @var array
*/
public static $customAttributes = array();
public static $customAttributes = [];

/**
* The validator object in case you need it externally (say, for a form builder).
@@ -107,7 +107,7 @@ abstract class Ardent extends Model {
*
* @var array
*/
protected $purgeFilters = array();
protected $purgeFilters = [];

protected $purgeFiltersInitialized = false;

@@ -116,7 +116,7 @@ abstract class Ardent extends Model {
*
* @var array
*/
public static $passwordAttributes = array('password');
public static $passwordAttributes = ['password'];

/**
* If set to true, the model will automatically replace all plain-text passwords
@@ -185,7 +185,7 @@ abstract class Ardent extends Model {
*
* @var array
*/
protected static $relationsData = array();
protected static $relationsData = [];

/** This class "has one model" if its ID is an FK in that model */
const HAS_ONE = 'hasOne';
@@ -215,20 +215,20 @@ abstract class Ardent extends Model {
*
* @var array
*/
protected static $relationTypes = array(
protected static $relationTypes = [
self::HAS_ONE, self::HAS_MANY, self::HAS_MANY_THROUGH,
self::BELONGS_TO, self::BELONGS_TO_MANY,
self::MORPH_TO, self::MORPH_ONE, self::MORPH_MANY,
self::MORPH_TO_MANY, self::MORPHED_BY_MANY
);
];

/**
* Create a new Ardent model instance.
*
* @param array $attributes
* @return \LaravelArdent\Ardent\Ardent
*/
public function __construct(array $attributes = array()) {
public function __construct(array $attributes = []) {
parent::__construct($attributes);
$this->validationErrors = new MessageBag;
}
@@ -244,8 +244,8 @@ public static function boot() {
parent::boot();

$myself = get_called_class();
$hooks = array('before' => 'ing', 'after' => 'ed');
$radicals = array('sav', 'validat', 'creat', 'updat', 'delet');
$hooks = ['before' => 'ing', 'after' => 'ed'];
$radicals = ['sav', 'validat', 'creat', 'updat', 'delet'];

foreach ($radicals as $rad) {
foreach ($hooks as $hook => $event) {
@@ -263,7 +263,7 @@ public static function boot() {
public function getObservableEvents() {
return array_merge(
parent::getObservableEvents(),
array('validating', 'validated')
['validating', 'validated']
);
}

@@ -315,10 +315,10 @@ protected function handleRelationalArray($relationName) {
' is a morphTo relation and should not contain additional arguments.');
}

$verifyArgs = function (array $opt, array $req = array()) use ($relationName, &$relation, $errorHeader) {
$missing = array('req' => array(), 'opt' => array());
$verifyArgs = function (array $opt, array $req = []) use ($relationName, &$relation, $errorHeader) {
$missing = ['req' => [], 'opt' => []];

foreach (array('req', 'opt') as $keyType) {
foreach (['req', 'opt'] as $keyType) {
foreach ($$keyType as $key) {
if (!array_key_exists($key, $relation)) {
$missing[$keyType][] = $key;
@@ -548,7 +548,7 @@ protected static function makeValidator($data, $rules, $customMessages, $customA
* @return bool
* @throws InvalidModelException
*/
public function validate(array $rules = array(), array $customMessages = array(), array $customAttributes = array()) {
public function validate(array $rules = [], array $customMessages = [], array $customAttributes = []) {
if ($this->fireModelEvent('validating') === false) {
if ($this->throwOnValidation) {
throw new InvalidModelException($this);
@@ -620,9 +620,9 @@ public function validate(array $rules = array(), array $customMessages = array()
* @see Ardent::save()
* @see Ardent::forceSave()
*/
protected function internalSave(array $rules = array(),
array $customMessages = array(),
array $options = array(),
protected function internalSave(array $rules = [],
array $customMessages = [],
array $options = [],
Closure $beforeSave = null,
Closure $afterSave = null,
$force = false
@@ -655,9 +655,9 @@ protected function internalSave(array $rules = array(),
* @return bool
* @see Ardent::forceSave()
*/
public function save(array $rules = array(),
array $customMessages = array(),
array $options = array(),
public function save(array $rules = [],
array $customMessages = [],
array $options = [],
Closure $beforeSave = null,
Closure $afterSave = null
) {
@@ -675,9 +675,9 @@ public function save(array $rules = array(),
* @return bool
* @see Ardent::save()
*/
public function forceSave(array $rules = array(),
array $customMessages = array(),
array $options = array(),
public function forceSave(array $rules = [],
array $customMessages = [],
array $options = [],
Closure $beforeSave = null,
Closure $afterSave = null
) {
@@ -723,9 +723,9 @@ protected function addBasicPurgeFilters() {
* @param array $array Input array
* @return array
*/
protected function purgeArray(array $array = array()) {
protected function purgeArray(array $array = []) {

$result = array();
$result = [];
$keys = array_keys($array);

$this->addBasicPurgeFilters();
@@ -797,13 +797,13 @@ protected function hashPassword($value) {
* @param array $passwordAttributes
* @return array
*/
protected function hashPasswordAttributes(array $attributes = array(), array $passwordAttributes = array()) {
protected function hashPasswordAttributes(array $attributes = [], array $passwordAttributes = [])) {

if (empty($passwordAttributes) || empty($attributes)) {
return $attributes;
}

$result = array();
$result = [];
foreach ($attributes as $key => $value) {

if (in_array($key, $passwordAttributes) && !is_null($value)) {
@@ -828,7 +828,7 @@ protected function hashPasswordAttributes(array $attributes = array(), array $pa
* @param array $rules
* @return array Rules with exclusions applied
*/
public function buildUniqueExclusionRules(array $rules = array()) {
public function buildUniqueExclusionRules(array $rules = []) {

if (!count($rules))
$rules = static::$rules;
@@ -842,7 +842,7 @@ public function buildUniqueExclusionRules(array $rules = array()) {
// Stop splitting at 4 so final param will hold optional where clause
$params = explode(',', $rule, 4);

$uniqueRules = array();
$uniqueRules = [];

// Append table name if needed
$table = explode(':', $params[0]);
@@ -891,9 +891,9 @@ public function buildUniqueExclusionRules(array $rules = array()) {
* @param Closure $afterSave
* @return bool
*/
public function updateUniques(array $rules = array(),
array $customMessages = array(),
array $options = array(),
public function updateUniques(array $rules = [],
array $customMessages = [],
array $options = [],
Closure $beforeSave = null,
Closure $afterSave = null
) {
@@ -910,7 +910,7 @@ public function updateUniques(array $rules = array(),
* @return bool
* @see Ardent::validate()
*/
public function validateUniques(array $rules = array(), array $customMessages = array()) {
public function validateUniques(array $rules = [], array $customMessages = []) {
$rules = $this->buildUniqueExclusionRules($rules);
return $this->validate($rules, $customMessages);
}
@@ -923,7 +923,7 @@ public function validateUniques(array $rules = array(), array $customMessages =
* @param array $columns
* @return Ardent|Collection
*/
public static function find($id, $columns = array('*')) {
public static function find($id, $columns = ['*']) {
$debug = debug_backtrace(false);

if (static::$throwOnFind && $debug[1]['function'] != 'findOrFail') {
6 changes: 3 additions & 3 deletions src/Ardent/Builder.php
Original file line number Diff line number Diff line change
@@ -11,11 +11,11 @@ class Builder extends \Illuminate\Database\Eloquent\Builder {
*/
public $throwOnFind = false;

public function find($id, $columns = array('*')) {
public function find($id, $columns = ['*']) {
return $this->maybeFail('find', func_get_args());
}

public function first($columns = array('*')) {
public function first($columns = ['*']) {
return $this->maybeFail('first', func_get_args());
}

@@ -28,7 +28,7 @@ public function first($columns = array('*')) {
protected function maybeFail($method, $args) {
$debug = debug_backtrace(false);
$orFail = $method.'OrFail';
$func = ($this->throwOnFind && $debug[2]['function'] != $orFail)? array($this, $orFail) : "parent::$method";
$func = ($this->throwOnFind && $debug[2]['function'] != $orFail)? [$this, $orFail] : "parent::$method";
return call_user_func_array($func, $args);
}
}
2 changes: 1 addition & 1 deletion src/Ardent/Providers/ArdentServiceProvider.php
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ public function register()
*/
public function provides()
{
return array('ardent');
return ['ardent'];
}

}
24 changes: 12 additions & 12 deletions src/lang/en/validation.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

return array(
'validation' => array(
'validation' => [
/*
|--------------------------------------------------------------------------
| Validation Language Lines
@@ -20,11 +20,11 @@
"alpha_dash" => "The :attribute may only contain letters, numbers, and dashes.",
"alpha_num" => "The :attribute may only contain letters and numbers.",
"before" => "The :attribute must be a date before :date.",
"between" => array(
"between" => [
"numeric" => "The :attribute must be between :min - :max.",
"file" => "The :attribute must be between :min - :max kilobytes.",
"string" => "The :attribute must be between :min - :max characters.",
),
],
"confirmed" => "The :attribute confirmation does not match.",
"date" => "The :attribute is not a valid date.",
"date_format" => "The :attribute does not match the format :format.",
@@ -37,17 +37,17 @@
"in" => "The selected :attribute is invalid.",
"integer" => "The :attribute must be an integer.",
"ip" => "The :attribute must be a valid IP address.",
"max" => array(
"max" => [
"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.",
),
],
"mimes" => "The :attribute must be a file of type: :values.",
"min" => array(
"min" => [
"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.",
),
],
"not_in" => "The selected :attribute is invalid.",
"numeric" => "The :attribute must be a number.",
"regex" => "The :attribute format is invalid.",
@@ -56,11 +56,11 @@
"required_with" => "The :attribute field is required when :values is present.",
"required_without" => "The :attribute field is required when :values is not present.",
"same" => "The :attribute and :other must match.",
"size" => array(
"size" => [
"numeric" => "The :attribute must be :size.",
"file" => "The :attribute must be :size kilobytes.",
"string" => "The :attribute must be :size characters.",
),
],
"unique" => "The :attribute has already been taken.",
"url" => "The :attribute format is invalid.",

@@ -75,7 +75,7 @@
|
*/

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

/*
|--------------------------------------------------------------------------
@@ -88,6 +88,6 @@
|
*/

'attributes' => array(),
)
'attributes' => [],
]
);
20 changes: 10 additions & 10 deletions src/lang/pt-br/validation.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

return array(
'validation' => array(
'validation' => [
/*
|--------------------------------------------------------------------------
| Validation Language Lines
@@ -20,11 +20,11 @@
"alpha_dash" => "O campo :attribute só pode conter letras, números e hífens..",
"alpha_num" => "O campo :attribute só pode conter letras e números",
"before" => "O campo :attribute só pode conter uma data antes de :date.",
"between" => array(
"between" => [
"numeric" => "O campo :attribute deve conter valores entre :min - :max.",
"file" => "O campo :attribute deve ter o tamanho entre :min - :max kilobytes.",
"string" => "O campo :attribute deve ter entre :min - :max caracteres.",
),
],
"confirmed" => "A confirmação do campo :attribute não corresponde.",
"date" => "O campo :attribute contém uma data inválida.",
"date_format" => "O campo :attribute não conrrespode ao formato :format.",
@@ -37,17 +37,17 @@
"in" => "O valor selecionado em :attribute é invalido.",
"integer" => "O campo :attribute deve conter um valor númerico.",
"ip" => "O campo :attribute deve conter um endereço de IP válido.",
"max" => array(
"max" => [
"numeric" => "O campo :attribute não pode ser maior que :max.",
"file" => "O campo :attribute não pode ser maior que :max kilobytes.",
"string" => "O campo :attribute não pode ser maior que :max caracteres.",
),
"mimes" => "O campo :attribute deve conter um arquivo do tipo: :values.",
"min" => array(
"min" => [
"numeric" => "O campo :attribute deve ser no mínimo :min.",
"file" => "O campo :attribute deve ser no mínimo :min kilobytes.",
"string" => "O campo :attribute deve ser no mínimo :min caracteres.",
),
],
"not_in" => "O campo :attribute selecionado é inválido.",
"numeric" => "O campo :attribute deve ser númerico.",
"regex" => "O campo :attribute é inválido.",
@@ -56,11 +56,11 @@
"required_with" => "O campo :attribute é obrigatório quando :values está presente.",
"required_without" => "O campo :attribute é obrigatório quando :values não está presente.",
"same" => "Os campos :attribute e :other devem conrrespoder.",
"size" => array(
"size" => [
"numeric" => "O campo :attribute deve ser :size.",
"file" => "O campo :attribute deve ser de :size kilobytes.",
"string" => "O campo :attribute deve ser de :size caracteres.",
),
],
"unique" => "O campo :attribute já existe.",
"url" => "O campo :attribute tem formato inválido.",

@@ -75,7 +75,7 @@
|
*/

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

/*
|--------------------------------------------------------------------------
@@ -88,6 +88,6 @@
|
*/

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