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
35e53b8c
Commit
35e53b8c
authored
Mar 22, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reintegrating Blade with Laravel using View engine event.
parent
b6615ddb
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
213 additions
and
3 deletions
+213
-3
application.php
application/config/application.php
+1
-0
start.php
application/start.php
+13
-0
blade.php
laravel/blade.php
+187
-0
core.php
laravel/core.php
+1
-0
laravel.php
laravel/laravel.php
+1
-0
view.php
laravel/view.php
+10
-3
.gitignore
storage/views/.gitignore
+0
-0
No files found.
application/config/application.php
View file @
35e53b8c
...
...
@@ -119,6 +119,7 @@ return array(
'Auth'
=>
'Laravel\\Auth'
,
'Asset'
=>
'Laravel\\Asset'
,
'Autoloader'
=>
'Laravel\\Autoloader'
,
'Blade'
=>
'Laravel\\Blade'
,
'Bundle'
=>
'Laravel\\Bundle'
,
'Cache'
=>
'Laravel\\Cache'
,
'Config'
=>
'Laravel\\Config'
,
...
...
application/start.php
View file @
35e53b8c
...
...
@@ -112,6 +112,19 @@ Event::listen(Lang::loader, function($bundle, $language, $file)
return
Lang
::
file
(
$bundle
,
$language
,
$file
);
});
/*
|--------------------------------------------------------------------------
| Enable The Blade View Engine
|--------------------------------------------------------------------------
|
| The Blade view engine provides a clean, beautiful templating language
| for your application, including syntax for echoing data and all of
| the typical PHP control structures. We'll simply enable it here.
|
*/
Blade
::
sharpen
();
/*
|--------------------------------------------------------------------------
| Set The Default Timezone
...
...
laravel/blade.php
0 → 100644
View file @
35e53b8c
<?php
namespace
Laravel
;
class
Blade
{
/**
* All of the compiler functions used by Blade.
*
* @var array
*/
protected
static
$compilers
=
array
(
'echos'
,
'structure_openings'
,
'structure_closings'
,
'else'
,
'yields'
,
'section_start'
,
'section_end'
,
);
/**
* Register the Blade view engine with Laravel.
*
* @return void
*/
public
static
function
sharpen
()
{
Event
::
listen
(
View
::
engine
,
function
(
$view
)
{
// The Blade view engine should only handle the rendering of views which
// end with the Blade extension. If the given view does not, we will
// return false so the View can be rendered as normal.
if
(
!
str_contains
(
$view
->
path
,
BLADE_EXT
))
{
return
false
;
}
$compiled
=
path
(
'storage'
)
.
'views/'
.
md5
(
$view
->
path
);
// If the view doesn't exist or has been modified since the last time it
// was compiled, we will recompile the view into pure PHP from it's
// Blade representation, writing it to cached storage.
if
(
!
file_exists
(
$compiled
)
or
(
filemtime
(
$view
->
path
)
>
filemtime
(
$compiled
)))
{
file_put_contents
(
$compiled
,
Blade
::
compile
(
$view
->
path
));
}
$view
->
path
=
$compiled
;
// Once the view has been compiled, we can simply set the path to the
// compiled view on the view instance and call the typical "get"
// method on the view to evaluate the compiled PHP view.
return
$view
->
get
();
});
}
/**
* Compiles the specified file containing Blade pseudo-code into valid PHP.
*
* @param string $path
* @return string
*/
public
static
function
compile
(
$path
)
{
return
static
::
compile_string
(
file_get_contents
(
$path
));
}
/**
* Compiles the given string containing Blade pseudo-code into valid PHP.
*
* @param string $value
* @return string
*/
public
static
function
compile_string
(
$value
)
{
foreach
(
static
::
$compilers
as
$compiler
)
{
$method
=
"compile_
{
$compiler
}
"
;
$value
=
static
::
$method
(
$value
);
}
return
$value
;
}
/**
* Rewrites Blade echo statements into PHP echo statements.
*
* @param string $value
* @return string
*/
protected
static
function
compile_echos
(
$value
)
{
return
preg_replace
(
'/\{\{(.+?)\}\}/'
,
'<?php echo $1; ?>'
,
$value
);
}
/**
* Rewrites Blade structure openings into PHP structure openings.
*
* @param string $value
* @return string
*/
protected
static
function
compile_structure_openings
(
$value
)
{
$pattern
=
'/(\s*)@(if|elseif|foreach|for|while)(\s*\(.*\))/'
;
return
preg_replace
(
$pattern
,
'$1<?php $2$3: ?>'
,
$value
);
}
/**
* Rewrites Blade structure closings into PHP structure closings.
*
* @param string $value
* @return string
*/
protected
static
function
compile_structure_closings
(
$value
)
{
$pattern
=
'/(\s*)@(endif|endforeach|endfor|endwhile)(\s*)/'
;
return
preg_replace
(
$pattern
,
'$1<?php $2; ?>$3'
,
$value
);
}
/**
* Rewrites Blade else statements into PHP else statements.
*
* @param string $value
* @return string
*/
protected
static
function
compile_else
(
$value
)
{
return
preg_replace
(
'/(\s*)@(else)(\s*)/'
,
'$1<?php $2: ?>$3'
,
$value
);
}
/**
* Rewrites Blade @yield statements into Section statements.
*
* The Blade @yield statement is a shortcut to the Section::yield method.
*
* @param string $value
* @return string
*/
protected
static
function
compile_yields
(
$value
)
{
$pattern
=
static
::
matcher
(
'yield'
);
return
preg_replace
(
$pattern
,
'$1<?php echo \\Laravel\\Section::yield$2; ?>'
,
$value
);
}
/**
* Rewrites Blade @section statements into Section statements.
*
* The Blade @section statement is a shortcut to the Section::start method.
*
* @param string $value
* @return string
*/
protected
static
function
compile_section_start
(
$value
)
{
$pattern
=
static
::
matcher
(
'section'
);
return
preg_replace
(
$pattern
,
'$1<?php \\Laravel\\Section::start$2; ?>'
,
$value
);
}
/**
* Rewrites Blade @endsection statements into Section statements.
*
* The Blade @endsection statement is a shortcut to the Section::stop method.
*
* @param string $value
* @return string
*/
protected
static
function
compile_section_end
(
$value
)
{
return
preg_replace
(
'/@endsection/'
,
'<?php \\Laravel\\Section::stop(); ?>'
,
$value
);
}
/**
* Get the regular expression for a generic Blade function.
*
* @param string $function
* @return string
*/
protected
static
function
matcher
(
$function
)
{
return
'/(\s*)@'
.
$function
.
'(\s*\(.*\))/'
;
}
}
\ No newline at end of file
laravel/core.php
View file @
35e53b8c
...
...
@@ -13,6 +13,7 @@
define
(
'EXT'
,
'.php'
);
define
(
'CRLF'
,
"
\r\n
"
);
define
(
'BLADE_EXT'
,
'.blade.php'
);
define
(
'DEFAULT_BUNDLE'
,
'application'
);
define
(
'MB_STRING'
,
(
int
)
function_exists
(
'mb_get_info'
));
...
...
laravel/laravel.php
View file @
35e53b8c
...
...
@@ -11,6 +11,7 @@
| may be used by the developer.
|
*/
require
'core.php'
;
/*
...
...
laravel/view.php
View file @
35e53b8c
...
...
@@ -117,9 +117,9 @@ class View implements ArrayAccess {
$view
=
str_replace
(
'.'
,
'/'
,
$view
);
// We delegate the determination of view paths to the view loader
//
event so that the developer is free to override and manage
//
the loading views in any way they see fit
.
// We delegate the determination of view paths to the view loader
event
//
so that the developer is free to override and manage the loading
//
of views in any way they see fit for their application
.
$path
=
Event
::
first
(
static
::
loader
,
array
(
$bundle
,
$view
));
if
(
!
is_null
(
$path
))
...
...
@@ -141,10 +141,17 @@ class View implements ArrayAccess {
{
$root
=
Bundle
::
path
(
$bundle
)
.
'views/'
;
// Views may have either the default PHP fiel extension of the "Blade"
// extension, so we will need to check for both in the view path
// and return the first one we find for the given view.
if
(
file_exists
(
$path
=
$root
.
$view
.
EXT
))
{
return
$path
;
}
elseif
(
file_exists
(
$path
=
$root
.
$view
.
BLADE_EXT
))
{
return
$path
;
}
}
/**
...
...
storage/views/.gitignore
0 → 100644
View file @
35e53b8c
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