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
dbdd45d9
Commit
dbdd45d9
authored
Jul 30, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tweaked cache and session namespacing.
parent
5b285882
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
381 additions
and
28 deletions
+381
-28
composers.php
application/composers.php
+27
-0
index.php
public/index.php
+1
-1
asset.php
system/asset.php
+36
-0
container.php
system/asset/container.php
+263
-0
apc.php
system/cache/apc.php
+2
-2
file.php
system/cache/file.php
+2
-2
memcached.php
system/cache/memcached.php
+2
-2
html.php
system/html.php
+11
-4
apc.php
system/session/apc.php
+7
-5
db.php
system/session/db.php
+5
-3
file.php
system/session/file.php
+2
-2
memcached.php
system/session/memcached.php
+8
-5
view.php
system/view.php
+15
-2
No files found.
application/composers.php
0 → 100644
View file @
dbdd45d9
<?php
return
array
(
/*
|--------------------------------------------------------------------------
| View Composers
|--------------------------------------------------------------------------
|
| View composers provide a convenient way to add common elements to a view
| each time it is created. For example, you may wish to bind a header and
| footer partial each time the view is created.
|
| The composer will receive an instance of the view being created, and is
| free to modify the view however you wish. But, always return the view
| instance at the end of the composer.
|
| For more information, check out: http://laravel.com/docs/start/views#composers
|
*/
'home/index'
=>
function
(
$view
)
{
return
$view
;
},
);
\ No newline at end of file
public/index.php
View file @
dbdd45d9
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
* Laravel - A clean and classy framework for PHP web development.
* Laravel - A clean and classy framework for PHP web development.
*
*
* @package Laravel
* @package Laravel
* @version 1.
3.1
* @version 1.
4.0
* @author Taylor Otwell
* @author Taylor Otwell
* @link http://laravel.com
* @link http://laravel.com
*/
*/
...
...
system/asset.php
0 → 100644
View file @
dbdd45d9
<?php
namespace
System
;
class
Asset
{
/**
* All of the asset containers.
*
* @var array
*/
public
static
$containers
=
array
();
/**
* Get an asset container instance.
*
* @param string $container
* @return Container
*/
public
static
function
container
(
$container
=
'default'
)
{
if
(
!
isset
(
static
::
$containers
[
$container
]))
{
static
::
$containers
[
$container
]
=
new
Asset\Container
(
$container
);
}
return
static
::
$containers
[
$container
];
}
/**
* Magic Method for calling methods on the default Asset container.
*/
public
static
function
__callStatic
(
$method
,
$parameters
)
{
return
call_user_func_array
(
array
(
static
::
container
(),
$method
),
$parameters
);
}
}
\ No newline at end of file
system/asset/container.php
0 → 100644
View file @
dbdd45d9
<?php
namespace
System\Asset
;
use
System\HTML
;
class
Container
{
/**
* The asset container name.
*
* @var string
*/
public
$name
;
/**
* All of the registered assets.
*
* @var array
*/
public
$assets
=
array
();
/**
* Create a new asset container instance.
*
* @param string $name
* @return void
*/
public
function
__construct
(
$name
)
{
$this
->
name
=
$name
;
}
/**
* Add an asset to the container.
*
* @param string $name
* @param string $source
* @param array $dependencies
* @param array $attributes
* @return void
*/
public
function
add
(
$name
,
$source
,
$dependencies
=
array
(),
$attributes
=
array
())
{
return
call_user_func
(
array
(
$this
,
(
\System\File
::
extension
(
$source
)
==
'css'
)
?
'style'
:
'script'
),
$name
,
$source
,
$dependencies
,
$attributes
);
}
/**
* Add CSS to the registered assets.
*
* @param string $name
* @param string $source
* @param array $dependencies
* @param array $attributes
* @return void
*/
public
function
style
(
$name
,
$source
,
$dependencies
=
array
(),
$attributes
=
array
())
{
if
(
!
array_key_exists
(
'media'
,
$attributes
))
{
$attributes
[
'media'
]
=
'all'
;
}
$this
->
register
(
'style'
,
$name
,
$source
,
$dependencies
,
$attributes
);
}
/**
* Add JavaScript to the registered assets.
*
* @param string $name
* @param string $source
* @param array $dependencies
* @param array $attributes
* @return void
*/
public
function
script
(
$name
,
$source
,
$dependencies
=
array
(),
$attributes
=
array
())
{
$this
->
register
(
'script'
,
$name
,
$source
,
$dependencies
,
$attributes
);
}
/**
* Add an asset to the registered assets.
*
* @param string $type
* @param string $name
* @param string $source
* @param array $dependencies
* @param array $attributes
* @return void
*/
private
function
register
(
$type
,
$name
,
$source
,
$dependencies
,
$attributes
)
{
$dependencies
=
(
array
)
$dependencies
;
$this
->
assets
[
$type
][
$name
]
=
compact
(
'source'
,
'dependencies'
,
'attributes'
);
}
/**
* Get all of the registered CSS assets.
*
* @return string
*/
public
function
styles
()
{
return
$this
->
get_group
(
'style'
);
}
/**
* Get all of the registered JavaScript assets.
*
* @return string
*/
public
function
scripts
()
{
return
$this
->
get_group
(
'script'
);
}
/**
* Get all of the registered assets for a given group.
*
* @param string $group
* @return string
*/
private
function
get_group
(
$group
)
{
if
(
!
isset
(
$this
->
assets
[
$group
])
or
count
(
$this
->
assets
[
$group
])
==
0
)
return
''
;
$assets
=
''
;
foreach
(
$this
->
arrange
(
$this
->
assets
[
$group
])
as
$name
=>
$data
)
{
$assets
.=
$this
->
get_asset
(
$group
,
$name
);
}
return
$assets
;
}
/**
* Get a registered CSS asset.
*
* @param string $name
* @return string
*/
public
function
get_style
(
$name
)
{
return
$this
->
get_asset
(
'style'
,
$name
);
}
/**
* Get a registered JavaScript asset.
*
* @param string $name
* @return string
*/
public
function
get_script
(
$name
)
{
return
$this
->
get_asset
(
'script'
,
$name
);
}
/**
* Get a registered asset.
*
* @param string $group
* @param string $name
* @return string
*/
private
function
get_asset
(
$group
,
$name
)
{
if
(
!
isset
(
$this
->
assets
[
$group
][
$name
]))
{
return
''
;
}
$asset
=
$this
->
assets
[
$group
][
$name
];
return
HTML
::
$group
(
$asset
[
'source'
],
$asset
[
'attributes'
]);
}
/**
* Sort and retrieve assets based on their dependencies
*
* @param array $assets
* @return array
*/
private
function
arrange
(
$assets
)
{
list
(
$original
,
$sorted
)
=
array
(
$assets
,
array
());
while
(
count
(
$assets
)
>
0
)
{
foreach
(
$assets
as
$asset
=>
$value
)
{
$this
->
evaluate_asset
(
$asset
,
$value
,
$original
,
$sorted
,
$assets
);
}
}
return
$sorted
;
}
/**
* Evaluate an asset and its dependencies.
*
* @param string $asset
* @param string $value
* @param array $original
* @param array $sorted
* @param array $assets
* @return void
*/
private
function
evaluate_asset
(
$asset
,
$value
,
$original
,
&
$sorted
,
&
$assets
)
{
// If the asset has no more dependencies, we can add it to the sorted list
// and remove it from the array of assets. Otherwise, we will not verify
// the asset's dependencies and determine if they have already been sorted.
if
(
count
(
$assets
[
$asset
][
'dependencies'
])
==
0
)
{
$sorted
[
$asset
]
=
$value
;
unset
(
$assets
[
$asset
]);
}
else
{
foreach
(
$assets
[
$asset
][
'dependencies'
]
as
$key
=>
$dependency
)
{
if
(
!
$this
->
dependency_is_valid
(
$asset
,
$dependency
,
$original
,
$assets
))
{
unset
(
$assets
[
$asset
][
'dependencies'
][
$key
]);
continue
;
}
// If the dependency has not yet been added to the sorted list, we can not
// remove it from this asset's array of dependencies. We'll try again on
// the next trip through the loop.
if
(
!
isset
(
$sorted
[
$dependency
]))
continue
;
unset
(
$assets
[
$asset
][
'dependencies'
][
$key
]);
}
}
}
/**
* Check that a dependency is valid.
*
* @param string $asset
* @param string $dependency
* @param array $original
* @param array $assets
* @return bool
*/
private
function
dependency_is_valid
(
$asset
,
$dependency
,
$original
,
$assets
)
{
if
(
!
isset
(
$original
[
$dependency
]))
{
return
false
;
}
elseif
(
$dependency
===
$asset
)
{
throw
new
\Exception
(
"Asset [
$asset
] is dependent on itself."
);
}
elseif
(
isset
(
$assets
[
$dependency
])
and
in_array
(
$asset
,
$assets
[
$dependency
][
'dependencies'
]))
{
throw
new
\Exception
(
"Assets [
$asset
] and [
$dependency
] have a circular dependency."
);
}
}
}
\ No newline at end of file
system/cache/
driver/
apc.php
→
system/cache/apc.php
View file @
dbdd45d9
<?php
namespace
System\Cache
\Driver
;
<?php
namespace
System\Cache
;
use
System\Config
;
use
System\Config
;
class
APC
implements
\System\Cache\
Driver
{
class
APC
implements
Driver
{
/**
/**
* Determine if an item exists in the cache.
* Determine if an item exists in the cache.
...
...
system/cache/
driver/
file.php
→
system/cache/file.php
View file @
dbdd45d9
<?php
namespace
System\Cache
\Driver
;
<?php
namespace
System\Cache
;
class
File
implements
\System\Cache\
Driver
{
class
File
implements
Driver
{
/**
/**
* Determine if an item exists in the cache.
* Determine if an item exists in the cache.
...
...
system/cache/
driver/
memcached.php
→
system/cache/memcached.php
View file @
dbdd45d9
<?php
namespace
System\Cache
\Driver
;
<?php
namespace
System\Cache
;
use
System\Config
;
use
System\Config
;
class
Memcached
implements
\System\Cache\
Driver
{
class
Memcached
implements
Driver
{
/**
/**
* Determine if an item exists in the cache.
* Determine if an item exists in the cache.
...
...
system/html.php
View file @
dbdd45d9
...
@@ -17,22 +17,29 @@ class HTML {
...
@@ -17,22 +17,29 @@ class HTML {
* Generate a JavaScript reference.
* Generate a JavaScript reference.
*
*
* @param string $url
* @param string $url
* @param array $attributes
* @return string
* @return string
*/
*/
public
static
function
script
(
$url
)
public
static
function
script
(
$url
,
$attributes
=
array
()
)
{
{
return
'<script type="text/javascript" src="'
.
static
::
entities
(
URL
::
to_asset
(
$url
))
.
'"></script>'
.
PHP_EOL
;
return
'<script type="text/javascript" src="'
.
static
::
entities
(
URL
::
to_asset
(
$url
))
.
'"
'
.
static
::
attributes
(
$attributes
)
.
'
></script>'
.
PHP_EOL
;
}
}
/**
/**
* Generate a CSS reference.
* Generate a CSS reference.
*
*
* @param string $url
* @param string $url
* @param array $attributes
* @return string
* @return string
*/
*/
public
static
function
style
(
$url
,
$
media
=
'all'
)
public
static
function
style
(
$url
,
$
attributes
=
array
()
)
{
{
return
'<link href="'
.
static
::
entities
(
URL
::
to_asset
(
$url
))
.
'" rel="stylesheet" type="text/css" media="'
.
$media
.
'">'
.
PHP_EOL
;
if
(
!
array_key_exists
(
'media'
,
$attributes
))
{
$attributes
[
'media'
]
=
'all'
;
}
return
'<link href="'
.
static
::
entities
(
URL
::
to_asset
(
$url
))
.
'" rel="stylesheet" type="text/css"'
.
static
::
attributes
(
$attributes
)
.
'>'
.
PHP_EOL
;
}
}
/**
/**
...
...
system/session/
driver/
apc.php
→
system/session/apc.php
View file @
dbdd45d9
<?php
namespace
System\Session
\Driver
;
<?php
namespace
System\Session
;
class
APC
implements
\System\Session\Driver
{
use
System\Cache
;
class
APC
implements
Driver
{
/**
/**
* Load a session by ID.
* Load a session by ID.
...
@@ -10,7 +12,7 @@ class APC implements \System\Session\Driver {
...
@@ -10,7 +12,7 @@ class APC implements \System\Session\Driver {
*/
*/
public
function
load
(
$id
)
public
function
load
(
$id
)
{
{
return
\System\
Cache
::
driver
(
'apc'
)
->
get
(
$id
);
return
Cache
::
driver
(
'apc'
)
->
get
(
$id
);
}
}
/**
/**
...
@@ -21,7 +23,7 @@ class APC implements \System\Session\Driver {
...
@@ -21,7 +23,7 @@ class APC implements \System\Session\Driver {
*/
*/
public
function
save
(
$session
)
public
function
save
(
$session
)
{
{
\System\Cache
::
driver
(
'apc'
)
->
put
(
$session
[
'id'
],
$session
,
\System\
Config
::
get
(
'session.lifetime'
));
Cache
::
driver
(
'apc'
)
->
put
(
$session
[
'id'
],
$session
,
Config
::
get
(
'session.lifetime'
));
}
}
/**
/**
...
@@ -32,7 +34,7 @@ class APC implements \System\Session\Driver {
...
@@ -32,7 +34,7 @@ class APC implements \System\Session\Driver {
*/
*/
public
function
delete
(
$id
)
public
function
delete
(
$id
)
{
{
\System\
Cache
::
driver
(
'apc'
)
->
forget
(
$id
);
Cache
::
driver
(
'apc'
)
->
forget
(
$id
);
}
}
/**
/**
...
...
system/session/d
river/d
b.php
→
system/session/db.php
View file @
dbdd45d9
<?php
namespace
System\Session
\Driver
;
<?php
namespace
System\Session
;
class
DB
implements
\System\Session\Driver
{
use
System\Config
;
class
DB
implements
Driver
{
/**
/**
* Load a session by ID.
* Load a session by ID.
...
@@ -60,7 +62,7 @@ class DB implements \System\Session\Driver {
...
@@ -60,7 +62,7 @@ class DB implements \System\Session\Driver {
*/
*/
private
function
table
()
private
function
table
()
{
{
return
\System\DB
::
table
(
\System\
Config
::
get
(
'session.table'
));
return
\System\DB
::
table
(
Config
::
get
(
'session.table'
));
}
}
}
}
\ No newline at end of file
system/session/
driver/
file.php
→
system/session/file.php
View file @
dbdd45d9
<?php
namespace
System\Session
\Driver
;
<?php
namespace
System\Session
;
class
File
implements
\System\Session\
Driver
{
class
File
implements
Driver
{
/**
/**
* Load a session by ID.
* Load a session by ID.
...
...
system/session/
driver/
memcached.php
→
system/session/memcached.php
View file @
dbdd45d9
<?php
namespace
System\Session
\Driver
;
<?php
namespace
System\Session
;
class
Memcached
implements
\System\Session\Driver
{
use
System\Cache
;
use
System\Config
;
class
Memcached
implements
Driver
{
/**
/**
* Load a session by ID.
* Load a session by ID.
...
@@ -10,7 +13,7 @@ class Memcached implements \System\Session\Driver {
...
@@ -10,7 +13,7 @@ class Memcached implements \System\Session\Driver {
*/
*/
public
function
load
(
$id
)
public
function
load
(
$id
)
{
{
return
\System\
Cache
::
driver
(
'memcached'
)
->
get
(
$id
);
return
Cache
::
driver
(
'memcached'
)
->
get
(
$id
);
}
}
/**
/**
...
@@ -21,7 +24,7 @@ class Memcached implements \System\Session\Driver {
...
@@ -21,7 +24,7 @@ class Memcached implements \System\Session\Driver {
*/
*/
public
function
save
(
$session
)
public
function
save
(
$session
)
{
{
\System\Cache
::
driver
(
'memcached'
)
->
put
(
$session
[
'id'
],
$session
,
\System\
Config
::
get
(
'session.lifetime'
));
Cache
::
driver
(
'memcached'
)
->
put
(
$session
[
'id'
],
$session
,
Config
::
get
(
'session.lifetime'
));
}
}
/**
/**
...
@@ -32,7 +35,7 @@ class Memcached implements \System\Session\Driver {
...
@@ -32,7 +35,7 @@ class Memcached implements \System\Session\Driver {
*/
*/
public
function
delete
(
$id
)
public
function
delete
(
$id
)
{
{
\System\
Cache
::
driver
(
'memcached'
)
->
forget
(
$id
);
Cache
::
driver
(
'memcached'
)
->
forget
(
$id
);
}
}
/**
/**
...
...
system/view.php
View file @
dbdd45d9
...
@@ -23,6 +23,13 @@ class View {
...
@@ -23,6 +23,13 @@ class View {
*/
*/
public
$path
;
public
$path
;
/**
* The view composers.
*
* @var array
*/
private
static
$composers
;
/**
/**
* Create a new view instance.
* Create a new view instance.
*
*
...
@@ -46,7 +53,14 @@ class View {
...
@@ -46,7 +53,14 @@ class View {
*/
*/
public
static
function
make
(
$view
,
$data
=
array
())
public
static
function
make
(
$view
,
$data
=
array
())
{
{
return
new
static
(
$view
,
$data
);
if
(
is_null
(
static
::
$composers
))
{
static
::
$composers
=
require
APP_PATH
.
'composers'
.
EXT
;
}
$instance
=
new
static
(
$view
,
$data
);
return
(
isset
(
static
::
$composers
[
$view
]))
?
call_user_func
(
static
::
$composers
[
$view
],
$instance
)
:
$instance
;
}
}
/**
/**
...
@@ -75,7 +89,6 @@ class View {
...
@@ -75,7 +89,6 @@ class View {
*/
*/
public
function
get
()
public
function
get
()
{
{
// Get the evaluated content of all of the sub-views.
foreach
(
$this
->
data
as
&
$data
)
foreach
(
$this
->
data
as
&
$data
)
{
{
if
(
$data
instanceof
View
or
$data
instanceof
Response
)
if
(
$data
instanceof
View
or
$data
instanceof
Response
)
...
...
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