Skip to content
This repository has been 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
Show file tree
Hide file tree
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
Expand Up @@ -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).
Expand Down Expand Up @@ -107,7 +107,7 @@ abstract class Ardent extends Model {
*
* @var array
*/
protected $purgeFilters = array();
protected $purgeFilters = [];

protected $purgeFiltersInitialized = false;

Expand All @@ -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
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) {
Expand All @@ -263,7 +263,7 @@ public static function boot() {
public function getObservableEvents() {
return array_merge(
parent::getObservableEvents(),
array('validating', 'validated')
['validating', 'validated']
);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
) {
Expand All @@ -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
) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
Expand All @@ -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]);
Expand Down Expand Up @@ -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
) {
Expand All @@ -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);
}
Expand All @@ -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') {
Expand Down
6 changes: 3 additions & 3 deletions src/Ardent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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
Expand Up @@ -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
Expand All @@ -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.",
Expand All @@ -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.",
Expand All @@ -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.",

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

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

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

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