Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
d802ae83
Commit
d802ae83
authored
Jun 17, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added arr class and tweaked input class.
parent
3038ed7a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
84 deletions
+30
-84
arr.php
system/arr.php
+23
-0
inflector.php
system/inflector.php
+0
-24
input.php
system/input.php
+7
-60
No files found.
system/arr.php
0 → 100644
View file @
d802ae83
<?php
namespace
System
;
class
Arr
{
/**
* Get an item from an array.
*
* @param string $key
* @param string $default
* @param array $array
* @return mixed
*/
public
static
function
get
(
$key
,
$default
=
null
,
$array
=
array
())
{
if
(
is_null
(
$key
))
{
return
$array
;
}
return
(
array_key_exists
(
$key
,
$array
))
?
$array
[
$key
]
:
$default
;
}
}
\ No newline at end of file
system/inflector.php
View file @
d802ae83
...
...
@@ -121,25 +121,16 @@ class Inflector {
*/
public
static
function
plural
(
$value
)
{
// -----------------------------------------------------
// If we have already pluralized this word, return it.
// -----------------------------------------------------
if
(
array_key_exists
(
$value
,
static
::
$plural_cache
))
{
return
static
::
$plural_cache
[
$value
];
}
// -----------------------------------------------------
// Are the singular and plural forms the same?
// -----------------------------------------------------
if
(
in_array
(
Str
::
lower
(
$value
),
static
::
$uncountable
))
{
return
static
::
$plural_cache
[
$value
]
=
$value
;
}
// -----------------------------------------------------
// Is the plural form irregular?
// -----------------------------------------------------
foreach
(
static
::
$irregular
as
$pattern
=>
$irregular
)
{
$pattern
=
'/'
.
$pattern
.
'$/i'
;
...
...
@@ -150,9 +141,6 @@ class Inflector {
}
}
// -----------------------------------------------------
// Check the plural forms for matches.
// -----------------------------------------------------
foreach
(
static
::
$plural
as
$pattern
=>
$plural
)
{
if
(
preg_match
(
$pattern
,
$value
))
...
...
@@ -172,25 +160,16 @@ class Inflector {
*/
public
static
function
singular
(
$value
)
{
// -----------------------------------------------------
// If we have already singularized this word, return it.
// -----------------------------------------------------
if
(
array_key_exists
(
$value
,
static
::
$singular_cache
))
{
return
static
::
$singular_cache
[
$value
];
}
// -----------------------------------------------------
// Are the singular and plural forms the same?
// -----------------------------------------------------
if
(
in_array
(
Str
::
lower
(
$value
),
static
::
$uncountable
))
{
return
static
::
$singular_cache
[
$value
]
=
$value
;
}
// -----------------------------------------------------
// Is the plural form irregular?
// -----------------------------------------------------
foreach
(
static
::
$irregular
as
$irregular
=>
$pattern
)
{
$pattern
=
'/'
.
$pattern
.
'$/i'
;
...
...
@@ -201,9 +180,6 @@ class Inflector {
}
}
// -----------------------------------------------------
// Check the singular forms for matches.
// -----------------------------------------------------
foreach
(
static
::
$singular
as
$pattern
=>
$singular
)
{
if
(
preg_match
(
$pattern
,
$value
))
...
...
system/input.php
View file @
d802ae83
...
...
@@ -9,34 +9,16 @@ class Input {
*/
public
static
$input
;
/**
* Determine if the input data contains an item or set of items.
*
* @return bool
*/
public
static
function
has
()
{
foreach
(
func_get_args
()
as
$key
)
{
if
(
is_null
(
static
::
get
(
$key
)))
{
return
false
;
}
}
return
true
;
}
/**
* Determine if the input data contains an item or set of items that are not empty.
*
* @return bool
*/
public
static
function
filled
()
public
static
function
has
()
{
foreach
(
func_get_args
()
as
$key
)
{
if
(
!
static
::
has
(
$key
)
or
trim
((
string
)
static
::
get
(
$key
))
==
''
)
if
(
is_null
(
static
::
get
(
$key
)
)
or
trim
((
string
)
static
::
get
(
$key
))
==
''
)
{
return
false
;
}
...
...
@@ -59,11 +41,12 @@ class Input {
static
::
hydrate
();
}
return
static
::
from_array
(
static
::
$input
,
$key
,
$defaul
t
);
return
Arr
::
get
(
$key
,
$default
,
static
::
$inpu
t
);
}
/**
* Determine if the old input data contains an item or set of items.
* Determine if the old input data contains an item or set of
* items that are not empty.
*
* @return bool
*/
...
...
@@ -71,25 +54,7 @@ class Input {
{
foreach
(
func_get_args
()
as
$key
)
{
if
(
is_null
(
static
::
old
(
$key
)))
{
return
false
;
}
}
return
true
;
}
/**
* Determine if the old input data contains an item or set of items that are not empty.
*
* @return bool
*/
public
static
function
was_filled
()
{
foreach
(
func_get_args
()
as
$key
)
{
if
(
!
static
::
had
(
$key
)
or
trim
((
string
)
static
::
old
(
$key
))
==
''
)
if
(
is_null
(
static
::
old
(
$key
))
or
trim
((
string
)
static
::
old
(
$key
))
==
''
)
{
return
false
;
}
...
...
@@ -112,25 +77,7 @@ class Input {
throw
new
\Exception
(
"Sessions must be enabled to retrieve old input data."
);
}
return
static
::
from_array
(
Session
::
get
(
'laravel_old_input'
,
array
()),
$key
,
$default
);
}
/**
* Get an item from an array. If no key is specified, the entire array will be returned.
*
* @param array $array
* @param string $key
* @param mixed $default
* @return string
*/
private
static
function
from_array
(
$array
,
$key
,
$default
)
{
if
(
is_null
(
$key
))
{
return
$array
;
}
return
(
array_key_exists
(
$key
,
$array
))
?
$array
[
$key
]
:
$default
;
return
Arr
::
get
(
$key
,
$default
,
Session
::
get
(
'laravel_old_input'
,
array
()));
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment