Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
4e6591c3
Commit
4e6591c3
authored
May 05, 2015
by
Dave Marshall
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CS Fixes
parent
974b49d1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
18 deletions
+17
-18
src/Silex/Application.php
src/Silex/Application.php
+7
-8
src/Silex/ViewListenerWrapper.php
src/Silex/ViewListenerWrapper.php
+1
-1
tests/Silex/Tests/ApplicationTest.php
tests/Silex/Tests/ApplicationTest.php
+9
-9
No files found.
src/Silex/Application.php
View file @
4e6591c3
...
@@ -18,7 +18,6 @@ use Symfony\Component\HttpKernel\HttpKernelInterface;
...
@@ -18,7 +18,6 @@ use Symfony\Component\HttpKernel\HttpKernelInterface;
use
Symfony\Component\HttpKernel\TerminableInterface
;
use
Symfony\Component\HttpKernel\TerminableInterface
;
use
Symfony\Component\HttpKernel\Event\FilterResponseEvent
;
use
Symfony\Component\HttpKernel\Event\FilterResponseEvent
;
use
Symfony\Component\HttpKernel\Event\GetResponseEvent
;
use
Symfony\Component\HttpKernel\Event\GetResponseEvent
;
use
Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent
;
use
Symfony\Component\HttpKernel\Event\PostResponseEvent
;
use
Symfony\Component\HttpKernel\Event\PostResponseEvent
;
use
Symfony\Component\HttpKernel\EventListener\ResponseListener
;
use
Symfony\Component\HttpKernel\EventListener\ResponseListener
;
use
Symfony\Component\HttpKernel\EventListener\RouterListener
;
use
Symfony\Component\HttpKernel\EventListener\RouterListener
;
...
@@ -408,14 +407,14 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
...
@@ -408,14 +407,14 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
/**
/**
* Registers a view handler.
* Registers a view handler.
*
*
* View handlers are simple callables which take a controller result and the
* View handlers are simple callables which take a controller result and the
* request as arguments, whenever a controller returns a value that is not
* request as arguments, whenever a controller returns a value that is not
* an instance of Response. When this occurs, all suitable handlers will be
* an instance of Response. When this occurs, all suitable handlers will be
* called, until one returns a Response object.
* called, until one returns a Response object.
*
*
* @param callable
$callback View handler callback
* @param callable $callback View handler callback
* @param integer $priority The higher this value, the earlier an event
* @param integer
$priority The higher this value, the earlier an event
* listener will be triggered in the chain (defaults to 0)
*
listener will be triggered in the chain (defaults to 0)
*/
*/
public
function
view
(
$callback
,
$priority
=
0
)
public
function
view
(
$callback
,
$priority
=
0
)
{
{
...
...
src/Silex/ViewListenerWrapper.php
View file @
4e6591c3
...
@@ -49,7 +49,7 @@ class ViewListenerWrapper
...
@@ -49,7 +49,7 @@ class ViewListenerWrapper
if
(
$response
instanceof
Response
)
{
if
(
$response
instanceof
Response
)
{
$event
->
setResponse
(
$response
);
$event
->
setResponse
(
$response
);
}
else
if
(
null
!==
$response
)
{
}
elseif
(
null
!==
$response
)
{
$event
->
setControllerResult
(
$response
);
$event
->
setControllerResult
(
$response
);
}
}
}
}
...
...
tests/Silex/Tests/ApplicationTest.php
View file @
4e6591c3
...
@@ -563,9 +563,9 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
...
@@ -563,9 +563,9 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
public
function
testBeforeFilterOnMountedControllerGroupIsolatedToGroup
()
public
function
testBeforeFilterOnMountedControllerGroupIsolatedToGroup
()
{
{
$app
=
new
Application
();
$app
=
new
Application
();
$app
->
match
(
'/'
,
function
()
{
return
new
Response
(
'ok'
);
});
$app
->
match
(
'/'
,
function
()
{
return
new
Response
(
'ok'
);
});
$mounted
=
$app
[
'controllers_factory'
];
$mounted
=
$app
[
'controllers_factory'
];
$mounted
->
before
(
function
()
{
return
new
Response
(
'not ok'
);
});
$mounted
->
before
(
function
()
{
return
new
Response
(
'not ok'
);
});
$app
->
mount
(
'/group'
,
$mounted
);
$app
->
mount
(
'/group'
,
$mounted
);
$response
=
$app
->
handle
(
Request
::
create
(
'/'
));
$response
=
$app
->
handle
(
Request
::
create
(
'/'
));
...
@@ -575,7 +575,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
...
@@ -575,7 +575,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
public
function
testViewListenerWithPrimitive
()
public
function
testViewListenerWithPrimitive
()
{
{
$app
=
new
Application
();
$app
=
new
Application
();
$app
->
get
(
'/foo'
,
function
()
{
return
123
;
});
$app
->
get
(
'/foo'
,
function
()
{
return
123
;
});
$app
->
view
(
function
(
$view
,
Request
$request
)
{
$app
->
view
(
function
(
$view
,
Request
$request
)
{
return
new
Response
(
$view
);
return
new
Response
(
$view
);
});
});
...
@@ -588,7 +588,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
...
@@ -588,7 +588,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
public
function
testViewListenerWithArrayTypeHint
()
public
function
testViewListenerWithArrayTypeHint
()
{
{
$app
=
new
Application
();
$app
=
new
Application
();
$app
->
get
(
'/foo'
,
function
()
{
return
array
(
'ok'
);
});
$app
->
get
(
'/foo'
,
function
()
{
return
array
(
'ok'
);
});
$app
->
view
(
function
(
array
$view
)
{
$app
->
view
(
function
(
array
$view
)
{
return
new
Response
(
$view
[
0
]);
return
new
Response
(
$view
[
0
]);
});
});
...
@@ -601,7 +601,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
...
@@ -601,7 +601,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
public
function
testViewListenerWithObjectTypeHint
()
public
function
testViewListenerWithObjectTypeHint
()
{
{
$app
=
new
Application
();
$app
=
new
Application
();
$app
->
get
(
'/foo'
,
function
()
{
return
(
object
)
array
(
'name'
=>
'world'
);
});
$app
->
get
(
'/foo'
,
function
()
{
return
(
object
)
array
(
'name'
=>
'world'
);
});
$app
->
view
(
function
(
\stdClass
$view
)
{
$app
->
view
(
function
(
\stdClass
$view
)
{
return
new
Response
(
'Hello '
.
$view
->
name
);
return
new
Response
(
'Hello '
.
$view
->
name
);
});
});
...
@@ -618,7 +618,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
...
@@ -618,7 +618,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
}
}
$app
=
new
Application
();
$app
=
new
Application
();
$app
->
get
(
'/foo'
,
function
()
{
return
function
()
{
return
'world'
;
};
});
$app
->
get
(
'/foo'
,
function
()
{
return
function
()
{
return
'world'
;
};
});
$app
->
view
(
function
(
callable
$view
)
{
$app
->
view
(
function
(
callable
$view
)
{
return
new
Response
(
'Hello '
.
$view
());
return
new
Response
(
'Hello '
.
$view
());
});
});
...
@@ -631,7 +631,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
...
@@ -631,7 +631,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
public
function
testViewListenersCanBeChained
()
public
function
testViewListenersCanBeChained
()
{
{
$app
=
new
Application
();
$app
=
new
Application
();
$app
->
get
(
'/foo'
,
function
()
{
return
(
object
)
array
(
'name'
=>
'world'
);
});
$app
->
get
(
'/foo'
,
function
()
{
return
(
object
)
array
(
'name'
=>
'world'
);
});
$app
->
view
(
function
(
\stdClass
$view
)
{
$app
->
view
(
function
(
\stdClass
$view
)
{
return
array
(
'msg'
=>
'Hello '
.
$view
->
name
);
return
array
(
'msg'
=>
'Hello '
.
$view
->
name
);
...
@@ -649,7 +649,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
...
@@ -649,7 +649,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
public
function
testViewListenersAreIgnoredIfNotSuitable
()
public
function
testViewListenersAreIgnoredIfNotSuitable
()
{
{
$app
=
new
Application
();
$app
=
new
Application
();
$app
->
get
(
'/foo'
,
function
()
{
return
'Hello world'
;
});
$app
->
get
(
'/foo'
,
function
()
{
return
'Hello world'
;
});
$app
->
view
(
function
(
\stdClass
$view
)
{
$app
->
view
(
function
(
\stdClass
$view
)
{
throw
new
\Exception
(
"View listener was called"
);
throw
new
\Exception
(
"View listener was called"
);
...
@@ -667,7 +667,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
...
@@ -667,7 +667,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
public
function
testViewListenersResponsesAreNotUsedIfNull
()
public
function
testViewListenersResponsesAreNotUsedIfNull
()
{
{
$app
=
new
Application
();
$app
=
new
Application
();
$app
->
get
(
'/foo'
,
function
()
{
return
'Hello world'
;
});
$app
->
get
(
'/foo'
,
function
()
{
return
'Hello world'
;
});
$app
->
view
(
function
(
$view
)
{
$app
->
view
(
function
(
$view
)
{
return
'Hello view listener'
;
return
'Hello view listener'
;
...
...
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