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
ed9e04db
Commit
ed9e04db
authored
Sep 07, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring.
parent
16716097
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
174 additions
and
24 deletions
+174
-24
filters.php
application/filters.php
+2
-2
routes.php
application/routes.php
+4
-4
arr.php
laravel/arr.php
+13
-0
asset.php
laravel/asset.php
+22
-8
caller.php
laravel/routing/caller.php
+3
-3
route.php
laravel/routing/route.php
+3
-5
ArrTest.php
tests/ArrTest.php
+0
-1
AssetTest.php
tests/AssetTest.php
+121
-0
ConfigTest.php
tests/ConfigTest.php
+6
-1
No files found.
application/filters.php
View file @
ed9e04db
...
...
@@ -42,13 +42,13 @@ return array(
|
*/
'before'
=>
function
(
$laravel
)
'before'
=>
function
()
{
// Do stuff before every request to your application.
},
'after'
=>
function
(
$
laravel
,
$
response
)
'after'
=>
function
(
$response
)
{
// Do stuff after every request to your application.
},
...
...
application/routes.php
View file @
ed9e04db
...
...
@@ -16,28 +16,28 @@ return array(
|
| Here is how to respond to a simple GET request to http://example.com/hello:
|
| 'GET /hello' => function(
$laravel
)
| 'GET /hello' => function()
| {
| return 'Hello World!';
| }
|
| You can even respond to more than one URI:
|
| 'GET /hello, GET /world' => function(
$laravel
)
| 'GET /hello, GET /world' => function()
| {
| return 'Hello World!';
| }
|
| It's easy to allow URI wildcards using the (:num) or (:any) place-holders:
|
| 'GET /hello/(:any)' => function($
laravel, $
name)
| 'GET /hello/(:any)' => function($name)
| {
| return "Welcome, $name.";
| }
|
*/
'GET /'
=>
function
(
$laravel
)
'GET /'
=>
function
()
{
return
View
::
make
(
'home.index'
);
},
...
...
laravel/arr.php
View file @
ed9e04db
...
...
@@ -9,6 +9,14 @@ class Arr {
* also be accessed using JavaScript "dot" style notation. Retrieving items nested
* in multiple arrays is supported.
*
* <code>
* // Get the "name" item from the array
* $name = Arr::get(array('name' => 'Fred'), 'name');
*
* // Get the "age" item from the array, or return 25 if it doesn't exist
* $name = Arr::get(array('name' => 'Fred'), 'age', 25);
* </code>
*
* @param array $array
* @param string $key
* @param mixed $default
...
...
@@ -38,6 +46,11 @@ class Arr {
* a variable depth, such as configuration arrays. Like the Arr::get
* method, JavaScript "dot" syntax is supported.
*
* <code>
* // Set the "name" item to "Fred" in the array
* Arr::set($array, 'name', 'Fred');
* </code>
*
* @param array $array
* @param string $key
* @param mixed $value
...
...
laravel/asset.php
View file @
ed9e04db
...
...
@@ -5,8 +5,6 @@ class Asset {
/**
* All of the instantiated asset containers.
*
* Asset containers are created through the container method, and are singletons.
*
* @var array
*/
public
$containers
=
array
();
...
...
@@ -36,6 +34,14 @@ class Asset {
* Containers provide a convenient method of grouping assets while maintaining
* expressive code and a clean API.
*
* <code>
* // Get the default asset container
* $container = Asset::container();
*
* // Get the "footer" asset container
* $container = Asset::container('footer');
* </code>
*
* @param string $container
* @return Asset_Container
*/
...
...
@@ -54,6 +60,14 @@ class Asset {
*
* This provides a convenient API, allowing the develop to skip the "container"
* method when using the default container.
*
* <code>
* // Add a JavaScript file to the default container
* Asset::script('jquery', 'js/jquery.js');
*
* // Get all of the styles from the default container
* echo Asset::styles();
* </code>
*/
public
function
__call
(
$method
,
$parameters
)
{
...
...
@@ -169,7 +183,7 @@ class Asset_Container {
* @param array $attributes
* @return void
*/
pr
ivate
function
register
(
$type
,
$name
,
$source
,
$dependencies
,
$attributes
)
pr
otected
function
register
(
$type
,
$name
,
$source
,
$dependencies
,
$attributes
)
{
$dependencies
=
(
array
)
$dependencies
;
...
...
@@ -202,7 +216,7 @@ class Asset_Container {
* @param string $group
* @return string
*/
pr
ivate
function
get_group
(
$group
)
pr
otected
function
get_group
(
$group
)
{
if
(
!
isset
(
$this
->
assets
[
$group
])
or
count
(
$this
->
assets
[
$group
])
==
0
)
return
''
;
...
...
@@ -245,7 +259,7 @@ class Asset_Container {
* @param string $name
* @return string
*/
pr
ivate
function
get_asset
(
$group
,
$name
)
pr
otected
function
get_asset
(
$group
,
$name
)
{
if
(
!
isset
(
$this
->
assets
[
$group
][
$name
]))
return
''
;
...
...
@@ -260,7 +274,7 @@ class Asset_Container {
* @param array $assets
* @return array
*/
pr
ivate
function
arrange
(
$assets
)
pr
otected
function
arrange
(
$assets
)
{
list
(
$original
,
$sorted
)
=
array
(
$assets
,
array
());
...
...
@@ -285,7 +299,7 @@ class Asset_Container {
* @param array $assets
* @return void
*/
pr
ivate
function
evaluate_asset
(
$asset
,
$value
,
$original
,
&
$sorted
,
&
$assets
)
pr
otected
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
...
...
@@ -327,7 +341,7 @@ class Asset_Container {
* @param array $assets
* @return bool
*/
pr
ivate
function
dependency_is_valid
(
$asset
,
$dependency
,
$original
,
$assets
)
pr
otected
function
dependency_is_valid
(
$asset
,
$dependency
,
$original
,
$assets
)
{
if
(
!
isset
(
$original
[
$dependency
]))
return
false
;
...
...
laravel/routing/caller.php
View file @
ed9e04db
...
...
@@ -60,7 +60,7 @@ class Caller {
return
$this
->
finish
(
$route
,
$response
);
}
if
(
!
is_null
(
$response
=
$route
->
call
(
$this
->
container
)))
if
(
!
is_null
(
$response
=
$route
->
call
()))
{
if
(
is_array
(
$response
))
$response
=
$this
->
delegator
->
delegate
(
$route
,
$response
);
...
...
@@ -83,7 +83,7 @@ class Caller {
{
$before
=
array_merge
(
array
(
'before'
),
$route
->
filters
(
'before'
));
return
$this
->
filterer
->
filter
(
$before
,
array
(
$this
->
container
),
true
);
return
$this
->
filterer
->
filter
(
$before
,
array
(),
true
);
}
/**
...
...
@@ -99,7 +99,7 @@ class Caller {
{
if
(
!
$response
instanceof
Response
)
$response
=
new
Response
(
$response
);
$this
->
filterer
->
filter
(
array_merge
(
$route
->
filters
(
'after'
),
array
(
'after'
)),
array
(
$
this
->
container
,
$
response
));
$this
->
filterer
->
filter
(
array_merge
(
$route
->
filters
(
'after'
),
array
(
'after'
)),
array
(
$response
));
return
$response
;
}
...
...
laravel/routing/route.php
View file @
ed9e04db
...
...
@@ -52,17 +52,15 @@ class Route {
/**
* Call the route closure.
*
* If no closure is defined for the route, null will be returned. The IoC container instance will be
* passed to the route closure so it has access to all of the framework components.
* If no closure is defined for the route, null will be returned.
*
* @param Container $container
* @return mixed
*/
public
function
call
(
Container
$container
)
public
function
call
()
{
if
(
is_null
(
$closure
=
$this
->
find_closure
()))
return
;
return
call_user_func_array
(
$closure
,
array_merge
(
$this
->
parameters
,
array
(
$container
))
);
return
call_user_func_array
(
$closure
,
$this
->
parameters
);
}
/**
...
...
tests/ArrTest.php
View file @
ed9e04db
...
...
@@ -2,7 +2,6 @@
class
ArrTest
extends
PHPUnit_Framework_TestCase
{
/**
* @dataProvider getArray
*/
...
...
tests/AssetTest.php
0 → 100644
View file @
ed9e04db
<?php
class
AssetTest
extends
PHPUnit_Framework_TestCase
{
public
function
testContainerMethodReturnsContainer
()
{
$asset
=
Laravel\IoC
::
resolve
(
'laravel.asset'
);
$this
->
assertInstanceOf
(
'Laravel\\Asset_Container'
,
$asset
->
container
());
$this
->
assertInstanceOf
(
'Laravel\\Asset_Container'
,
$asset
->
container
(
'footer'
));
$this
->
assertEquals
(
$asset
->
container
()
->
name
,
'default'
);
$this
->
assertEquals
(
$asset
->
container
(
'footer'
)
->
name
,
'footer'
);
}
public
function
testAssetManagerMagicallyCallsDefaultContainer
()
{
$asset
=
Laravel\IoC
::
resolve
(
'laravel.asset'
);
$mock
=
$this
->
getMockBuilder
(
'Laravel\\Asset_Container'
)
->
disableOriginalConstructor
()
->
getMock
();
$mock
->
expects
(
$this
->
any
())
->
method
(
'styles'
)
->
will
(
$this
->
returnValue
(
'styles'
));
$asset
->
containers
[
'default'
]
=
$mock
;
$this
->
assertEquals
(
$asset
->
styles
(),
'styles'
);
}
public
function
testAddMethodAddsAssetBasedOnExtension
()
{
$container
=
$this
->
getContainer
();
$container
->
add
(
'jquery'
,
'js/jquery.js'
);
$container
->
add
(
'jquery-css'
,
'css/jquery.css'
);
$this
->
assertEquals
(
$container
->
assets
[
'script'
][
'jquery'
][
'source'
],
'js/jquery.js'
);
$this
->
assertEquals
(
$container
->
assets
[
'style'
][
'jquery-css'
][
'source'
],
'css/jquery.css'
);
}
/**
* @dataProvider assetProvider
*/
public
function
testStyleMethodRegistersStylesheetAsset
(
$type
,
$source
,
$attributes
,
$testAttributes
)
{
$container
=
$this
->
getContainer
();
$dependencies
=
array
(
'jquery'
);
$container
->
$type
(
'reset'
,
$source
,
$dependencies
,
$attributes
);
$this
->
assertEquals
(
$container
->
assets
[
$type
][
'reset'
][
'source'
],
$source
);
$this
->
assertEquals
(
$container
->
assets
[
$type
][
'reset'
][
'dependencies'
],
$dependencies
);
$this
->
assertEquals
(
$container
->
assets
[
$type
][
'reset'
][
'attributes'
],
$testAttributes
);
}
public
function
assetProvider
()
{
$attributes
=
array
(
'test'
=>
'test'
);
return
array
(
array
(
'style'
,
'css/reset.css'
,
$attributes
,
array_merge
(
$attributes
,
array
(
'media'
=>
'all'
))),
array
(
'script'
,
'js/jquery.js'
,
$attributes
,
$attributes
),
);
}
public
function
testStylesCanBeRetrieved
()
{
$container
=
new
Laravel\Asset_Container
(
'default'
,
new
HTMLAssetStub
);
$container
->
style
(
'reset'
,
'css/reset.css'
);
$container
->
style
(
'jquery'
,
'css/jquery.css'
);
$this
->
assertEquals
(
$container
->
get_style
(
'reset'
),
'css/reset.css media:all'
);
$this
->
assertEquals
(
$container
->
styles
(),
'css/reset.css media:allcss/jquery.css media:all'
);
}
public
function
testScriptsCanBeRetrieved
()
{
$container
=
new
Laravel\Asset_Container
(
'default'
,
new
HTMLAssetStub
);
$container
->
script
(
'jquery-ui'
,
'js/jquery-ui.js'
);
$container
->
script
(
'jquery'
,
'js/jquery.js'
,
array
(),
array
(
'test'
=>
'value'
));
$this
->
assertEquals
(
$container
->
get_script
(
'jquery-ui'
),
'js/jquery-ui.js '
);
$this
->
assertEquals
(
$container
->
scripts
(),
'js/jquery-ui.js js/jquery.js test:value'
);
}
private
function
getContainer
()
{
return
new
Laravel\Asset_Container
(
'default'
,
Laravel\IoC
::
resolve
(
'laravel.html'
));
}
}
class
HTMLAssetStub
extends
Laravel\HTML
{
public
function
__construct
()
{}
public
function
style
(
$source
,
$attributes
)
{
return
$source
.
' '
.
$this
->
getAttributes
(
$attributes
);
}
public
function
script
(
$source
,
$attributes
)
{
return
$source
.
' '
.
$this
->
getAttributes
(
$attributes
);
}
private
function
getAttributes
(
$attributes
)
{
$html
=
''
;
foreach
(
$attributes
as
$key
=>
$value
)
{
$html
.=
$key
.
':'
.
$value
;
}
return
$html
;
}
}
\ No newline at end of file
tests/ConfigTest.php
View file @
ed9e04db
...
...
@@ -2,7 +2,12 @@
class
ConfigTest
extends
PHPUnit_Framework_TestCase
{
public
function
setUp
()
public
static
function
setUpBeforeClass
()
{
IoC
::
container
()
->
singletons
=
array
();
}
public
function
tearDown
()
{
IoC
::
container
()
->
singletons
=
array
();
}
...
...
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