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
441a9e20
Commit
441a9e20
authored
Feb 23, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working on view engine event.
parent
2b4ab94e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
47 deletions
+45
-47
view.php
laravel/view.php
+45
-47
No files found.
laravel/view.php
View file @
441a9e20
...
...
@@ -62,7 +62,7 @@ class View implements ArrayAccess {
$this
->
path
=
$this
->
path
(
$view
);
// If a session driver has been specified, we will bind an instance of the
// validation error message container to every view. If an error
s
instance
// validation error message container to every view. If an error instance
// exists in the session, we will use that instance.
if
(
!
isset
(
$this
->
data
[
'errors'
]))
{
...
...
@@ -89,18 +89,17 @@ class View implements ArrayAccess {
$root
=
Bundle
::
path
(
Bundle
::
name
(
$view
))
.
'views/'
;
// Views may have the normal PHP extension or the Blade PHP extension, so
// we need to check if either of them exist in the base views directory
// for the bundle and return the first one we find.
foreach
(
array
(
EXT
,
BLADE_EXT
)
as
$extension
)
// We need to make sure that the view exists. If it doesn't, we will
// throw an exception since there is not any point in going further.
// If it does, we can just return the full view path.
$path
=
$root
.
Bundle
::
element
(
$view
)
.
EXT
;
if
(
file_exists
(
$path
))
{
if
(
file_exists
(
$path
=
$root
.
Bundle
::
element
(
$view
)
.
$extension
))
{
return
$path
;
}
return
$path
;
}
throw
new
\Exception
(
"View [
$view
] does
no
t exist."
);
throw
new
\Exception
(
"View [
$view
] does
n'
t exist."
);
}
/**
...
...
@@ -194,27 +193,49 @@ class View implements ArrayAccess {
public
function
render
()
{
// To allow bundles or other pieces of the application to modify the
// view before it is rendered, we
wi
ll fire an event, passing in the
// view before it is rendered, we
'
ll fire an event, passing in the
// view instance so it can modified.
Event
::
fire
(
"laravel.composing:
{
$this
->
view
}
"
,
array
(
$this
));
$data
=
$this
->
data
();
// If there are listeners to the view engine event, we'll pass them
// the view so they can render it according to their needs, which
// allows easy attachment of other view parsers.
if
(
Event
::
listeners
(
'laravel.viewer'
))
{
return
Event
::
first
(
'laravel.viewer'
,
array
(
$this
));
}
else
{
return
$this
->
get
();
}
}
/**
* Get the evaluated contents of the view.
*
* @return string
*/
public
function
get
()
{
$__data
=
$this
->
data
();
ob_start
()
and
extract
(
$data
,
EXTR_SKIP
);
ob_start
()
and
extract
(
$
__
data
,
EXTR_SKIP
);
// If the view is Bladed, we need to check the view for changes and
// get the path to the compiled view file. Otherwise, we'll just
// use the regular path to the view.
//
// Also, if the Blade view has expired or doesn't exist it will be
// re-compiled and placed in the view storage directory. The Blade
// views are re-compiled the original view changes.
if
(
strpos
(
$this
->
path
,
BLADE_EXT
)
!==
false
)
// We'll include the view contents for parsing within a catcher
// so we can avoid any WSOD errors. If an exception occurs we
// will just throw it back out to the exception handler.
try
{
$this
->
path
=
$this
->
compile
()
;
include
$this
->
path
;
}
try
{
include
$this
->
path
;}
catch
(
\Exception
$e
)
{
ob_get_clean
();
throw
$e
;}
// If we caught an exception, we'll silently flush the output
// buffer so that no partially rendered views get thrown out
// to the client and confuse the user.
catch
(
\Exception
$e
)
{
ob_get_clean
();
throw
$e
;
}
return
ob_get_clean
();
}
...
...
@@ -226,7 +247,7 @@ class View implements ArrayAccess {
*
* @return array
*/
p
rotected
function
data
()
p
ublic
function
data
()
{
$data
=
array_merge
(
$this
->
data
,
static
::
$shared
);
...
...
@@ -244,29 +265,6 @@ class View implements ArrayAccess {
return
$data
;
}
/**
* Get the path to the compiled version of the Blade view.
*
* @return string
*/
protected
function
compile
()
{
// Compiled views are stored in the storage directory using the MD5
// hash of their path. This allows us to easily store the views in
// the directory without worrying about structure.
$compiled
=
path
(
'storage'
)
.
'views/'
.
md5
(
$this
->
path
);
// The view will only be re-compiled if the view has been modified
// since the last compiled version of the view was created or no
// compiled view exists at all in storage.
if
(
!
file_exists
(
$compiled
)
or
(
filemtime
(
$this
->
path
)
>
filemtime
(
$compiled
)))
{
file_put_contents
(
$compiled
,
Blade
::
compile
(
$this
->
path
));
}
return
$compiled
;
}
/**
* Add a view instance to the view data.
*
...
...
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