Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
Overview
Overview
Details
Activity
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
Commits
0455c10a
Commit
0455c10a
authored
Mar 22, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added "for else" support to Blade.
parent
8839138a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
0 deletions
+65
-0
laravel/blade.php
+65
-0
No files found.
laravel/blade.php
View file @
0455c10a
...
@@ -9,6 +9,9 @@ class Blade {
...
@@ -9,6 +9,9 @@ class Blade {
*/
*/
protected
static
$compilers
=
array
(
protected
static
$compilers
=
array
(
'echos'
,
'echos'
,
'forelse'
,
'empty'
,
'endforelse'
,
'structure_openings'
,
'structure_openings'
,
'structure_closings'
,
'structure_closings'
,
'else'
,
'else'
,
...
@@ -94,6 +97,68 @@ class Blade {
...
@@ -94,6 +97,68 @@ class Blade {
}
}
/**
/**
* Rewrites Blade "for else" statements into valid PHP.
*
* @param string $value
* @return string
*/
protected
static
function
compile_forelse
(
$value
)
{
preg_match_all
(
'/(\s*)@forelse(\s*\(.*\))(\s*)/'
,
$value
,
$matches
);
// First we'll loop through all of the "@forelse" lines. We need to
// wrap each loop in an "if/else" statement that checks the count
// of the variable being iterated against.
if
(
isset
(
$matches
[
0
]))
{
foreach
(
$matches
[
0
]
as
$forelse
)
{
preg_match
(
'/\$[^\s]*/'
,
$forelse
,
$variable
);
// Once we have extracted the variable being looped against, we cab
// prepend an "if" statmeent to the start of the loop that checks
// that the count of the variable is greater than zero.
$if
=
"<?php if (count(
{
$variable
[
0
]
}
) > 0): ?>"
;
$search
=
'/(\s*)@forelse(\s*\(.*\))/'
;
$replace
=
'$1'
.
$if
.
'<?php foreach$2: ?>'
;
$blade
=
preg_replace
(
$search
,
$replace
,
$forelse
);
// Finally, once we have the check prepended to the loop, we will
// replace all instances of this "forelse" structure in the
// content of the view being compiled to Blade syntax.
$value
=
str_replace
(
$forelse
,
$blade
,
$value
);
}
}
return
$value
;
}
/**
* Rewrites Blade "empty" statements into valid PHP.
*
* @param string $value
* @return string
*/
protected
static
function
compile_empty
(
$value
)
{
return
str_replace
(
'@empty'
,
'<?php endforeach; ?><?php else: ?>'
,
$value
);
}
/**
* Rewrites Blade "forelse" endings into valid PHP.
*
* @param string $value
* @return string
*/
protected
static
function
compile_endforelse
(
$value
)
{
return
str_replace
(
'@endforelse'
,
'<?php endif; ?>'
,
$value
);
}
/**
* Rewrites Blade structure openings into PHP structure openings.
* Rewrites Blade structure openings into PHP structure openings.
*
*
* @param string $value
* @param string $value
...
...
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