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
9be3d1a5
Commit
9be3d1a5
authored
Aug 29, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring the view classes.
parent
56044d31
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
109 additions
and
91 deletions
+109
-91
container.php
laravel/config/container.php
+1
-1
manager.php
laravel/database/manager.php
+0
-27
laravel.php
laravel/laravel.php
+1
-1
view.php
laravel/view.php
+107
-62
No files found.
laravel/config/container.php
View file @
9be3d1a5
...
...
@@ -107,7 +107,7 @@ return array(
{
require_once
SYS_PATH
.
'view'
.
EXT
;
return
new
View_Factory
(
require
APP_PATH
.
'composers'
.
EXT
,
VIEW_PATH
);
return
new
View_Factory
(
VIEW_PATH
,
new
View_Composer
(
require
APP_PATH
.
'composers'
.
EXT
)
);
}),
/*
...
...
laravel/database/manager.php
View file @
9be3d1a5
...
...
@@ -40,14 +40,6 @@ class Manager {
*
* Note: Database connections are managed as singletons.
*
* <code>
* // Get the default database connection
* $connection = DB::connection();
*
* // Get a specific database connection
* $connection = DB::connection('mysql');
* </code>
*
* @param string $connection
* @return Database\Connection
*/
...
...
@@ -75,17 +67,6 @@ class Manager {
*
* This method primarily serves as a short-cut to the $connection->table() method.
*
* <code>
* // Begin a fluent query against the "users" table
* $query = DB::table('users');
*
* // Equivalent call using the connection table method.
* $query = DB::connection()->table('users');
*
* // Begin a fluent query against the "users" table for a specific connection
* $query = DB::table('users', 'mysql');
* </code>
*
* @param string $table
* @param string $connection
* @return Database\Query
...
...
@@ -99,14 +80,6 @@ class Manager {
* Magic Method for calling methods on the default database connection.
*
* This provides a convenient API for querying or examining the default database connection.
*
* <code>
* // Run a query against the default database connection
* $results = DB::query('select * from users');
*
* // Equivalent call using the connection instance
* $results = DB::connection()->query('select * from users');
* </code>
*/
public
function
__call
(
$method
,
$parameters
)
{
...
...
laravel/laravel.php
View file @
9be3d1a5
...
...
@@ -8,7 +8,7 @@ require 'bootstrap.php';
// --------------------------------------------------------------
// Set the error reporting and display levels.
// --------------------------------------------------------------
error_reporting
(
E_ALL
|
E_STRICT
);
error_reporting
(
-
1
);
ini_set
(
'display_errors'
,
'Off'
);
...
...
laravel/view.php
View file @
9be3d1a5
<?php
namespace
Laravel
;
/**
* The view composer class is responsible for calling the composer on a view and
* searching through the view composers for a given view name. It is injected
* into the View_Factory and View instances themselves, and is managed as a singleton
* by the application IoC container.
*/
class
View_Composer
{
/**
* Create a new view composer instance.
*
* @param array $composers
* @return void
*/
public
function
__construct
(
$composers
)
{
$this
->
composers
=
$composers
;
}
/**
* Find the key for a view by name.
*
* @param string $name
* @return string
*/
public
function
name
(
$name
)
{
foreach
(
$this
->
composers
as
$key
=>
$value
)
{
if
(
$name
===
$value
or
(
isset
(
$value
[
'name'
])
and
$name
===
$value
[
'name'
]))
{
return
$key
;
}
}
}
/**
* Call the composer for the view instance.
*
* @param View $view
* @return void
*/
public
function
compose
(
View
$view
)
{
if
(
isset
(
$this
->
composers
[
$view
->
view
]))
{
foreach
((
array
)
$this
->
composers
[
$view
->
view
]
as
$key
=>
$value
)
{
if
(
$value
instanceof
\Closure
)
return
call_user_func
(
$value
,
$view
);
}
}
}
}
/**
* The view factory class is responsible for the instantiation of Views. It is typically
* access through the application instance from a route or controller, and is managed
* as a singleton by the application IoC container.
*/
class
View_Factory
{
/**
...
...
@@ -9,10 +66,10 @@ class View_Factory {
* @param string $path
* @return void
*/
public
function
__construct
(
$
composers
,
$path
)
public
function
__construct
(
$
path
,
View_Composer
$composer
)
{
$this
->
path
=
$path
;
$this
->
composer
s
=
$composers
;
$this
->
composer
=
$composer
;
}
/**
...
...
@@ -24,7 +81,7 @@ class View_Factory {
*/
public
function
make
(
$view
,
$data
=
array
())
{
return
new
View
(
$view
,
$
this
->
path
,
$data
,
$this
->
composers
,
$this
);
return
new
View
(
$view
,
$
data
,
$this
->
path
(
$view
),
$this
->
composer
,
$this
);
}
/**
...
...
@@ -36,17 +93,25 @@ class View_Factory {
*/
protected
function
of
(
$name
,
$data
=
array
())
{
foreach
(
$this
->
composers
as
$key
=>
$value
)
if
(
!
is_null
(
$view
=
$this
->
composer
->
name
(
$name
))
)
{
if
(
$name
===
$value
or
(
isset
(
$value
[
'name'
])
and
$name
===
$value
[
'name'
]))
{
return
new
View
(
$key
,
$this
->
path
,
$data
,
$this
->
composers
,
$this
);
}
return
new
View
(
$view
,
$data
,
$this
->
path
(
$view
),
$this
->
composer
,
$this
);
}
throw
new
\Exception
(
"Named view [
$name
] is not defined."
);
}
/**
* Get the path to a given view on disk.
*
* @param string $view
* @return string
*/
protected
function
path
(
$view
)
{
return
$this
->
path
.
str_replace
(
'.'
,
'/'
,
$view
)
.
EXT
;
}
/**
* Magic Method for handling the dynamic creation of named views.
*
...
...
@@ -68,6 +133,11 @@ class View_Factory {
}
/**
* The view class is returned by the View Factory "make" method, and is the primary
* class for working with individual views. It provides methods for binding data to
* views as well as evaluating and rendering their contents.
*/
class
View
{
/**
...
...
@@ -78,25 +148,25 @@ class View {
public
$view
;
/**
* The view
name with dots replaced by slashes
.
* The view
data
.
*
* @var
string
* @var
array
*/
public
$
path
;
public
$
data
;
/**
* The
view data
.
* The
path to the view on disk
.
*
* @var
array
* @var
string
*/
p
ublic
$data
;
p
rotected
$path
;
/**
* The view composer
s defined for the application
.
* The view composer
instance
.
*
* @var
array $composers
* @var
View_Composer
*/
protected
$composer
s
;
protected
$composer
;
/**
* The view factory instance, which is used to create sub-views.
...
...
@@ -108,19 +178,20 @@ class View {
/**
* Create a new view instance.
*
* @param string $view
* @param array $data
* @param string $path
* @param array $composers
* @param string $view
* @param array $data
* @param string $path
* @param View_Composer $composer
* @param View_Factory $factory
* @return void
*/
public
function
__construct
(
$view
,
$
path
,
$data
,
$composers
,
$factory
)
public
function
__construct
(
$view
,
$
data
,
$path
,
View_Composer
$composer
,
View_Factory
$factory
)
{
$this
->
view
=
$view
;
$this
->
data
=
$data
;
$this
->
path
=
$path
;
$this
->
factory
=
$factory
;
$this
->
composers
=
$composers
;
$this
->
path
=
$path
.
str_replace
(
'.'
,
'/'
,
$view
)
.
EXT
;
$this
->
composer
=
$composer
;
if
(
!
file_exists
(
$this
->
path
))
{
...
...
@@ -128,22 +199,6 @@ class View {
}
}
/**
* Call the composer for the view instance.
*
* @return void
*/
protected
function
compose
()
{
if
(
isset
(
$this
->
composers
[
$this
->
view
]))
{
foreach
((
array
)
$this
->
composers
[
$this
->
view
]
as
$key
=>
$value
)
{
if
(
$value
instanceof
\Closure
)
return
call_user_func
(
$value
,
$this
);
}
}
}
/**
* Get the evaluated string content of the view.
*
...
...
@@ -154,7 +209,7 @@ class View {
*/
public
function
render
()
{
$this
->
compose
(
);
$this
->
compose
r
->
compose
(
$this
);
foreach
(
$this
->
data
as
&
$data
)
{
...
...
@@ -163,14 +218,7 @@ class View {
ob_start
()
and
extract
(
$this
->
data
,
EXTR_SKIP
);
try
{
include
$this
->
path
;
}
catch
(
\Exception
$e
)
{
Exception\Handler
::
make
(
new
Exception\Examiner
(
$e
))
->
handle
();
}
try
{
include
$this
->
path
;
}
catch
(
\Exception
$e
)
{
ob_get_clean
();
throw
$e
;
}
return
ob_get_clean
();
}
...
...
@@ -178,14 +226,6 @@ class View {
/**
* Add a view instance to the view data.
*
* <code>
* // Bind the view "partial/login" to the view
* View::make('home')->partial('login', 'partial/login');
*
* // Equivalent binding using the "with" method
* View::make('home')->with('login', View::make('partials/login'));
* </code>
*
* @param string $key
* @param string $view
* @param array $data
...
...
@@ -201,11 +241,6 @@ class View {
*
* Bound data will be available to the view as variables.
*
* <code>
* // Bind a "name" value to the view
* View::make('home')->with('name', 'Fred');
* </code>
*
* @param string $key
* @param mixed $value
* @return View
...
...
@@ -248,4 +283,14 @@ class View {
unset
(
$this
->
data
[
$key
]);
}
/**
* Magic Method for passing undefined static methods to the View_Factory instance
* registered in the application IoC container. This provides easy access to the
* view functions while still maintaining testability within the view classes.
*/
public
static
function
__callStatic
(
$method
,
$parameters
)
{
return
call_user_func_array
(
array
(
IoC
::
container
()
->
resolve
(
'laravel.view'
),
$method
),
$parameters
);
}
}
\ No newline at end of file
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