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
f96d5421
Commit
f96d5421
authored
Aug 23, 2015
by
Henrik Bjornskov
Committed by
Fabien Potencier
Aug 29, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move Services into ServiceProvider
parent
a3881a5a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
47 deletions
+52
-47
src/Silex/Application.php
src/Silex/Application.php
+0
-44
src/Silex/Provider/KernelServiceProvider.php
src/Silex/Provider/KernelServiceProvider.php
+29
-3
src/Silex/Provider/RoutingServiceProvider.php
src/Silex/Provider/RoutingServiceProvider.php
+23
-0
No files found.
src/Silex/Application.php
View file @
f96d5421
...
...
@@ -15,7 +15,6 @@ use Pimple\Container;
use
Pimple\ServiceProviderInterface
;
use
Symfony\Component\EventDispatcher\EventDispatcherInterface
;
use
Symfony\Component\HttpFoundation\BinaryFileResponse
;
use
Symfony\Component\HttpKernel\HttpKernel
;
use
Symfony\Component\HttpKernel\HttpKernelInterface
;
use
Symfony\Component\HttpKernel\TerminableInterface
;
use
Symfony\Component\HttpKernel\Event\FilterResponseEvent
;
...
...
@@ -24,12 +23,10 @@ use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use
Symfony\Component\HttpKernel\Exception\HttpException
;
use
Symfony\Component\HttpKernel\KernelEvents
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\RequestStack
;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\HttpFoundation\RedirectResponse
;
use
Symfony\Component\HttpFoundation\StreamedResponse
;
use
Symfony\Component\HttpFoundation\JsonResponse
;
use
Symfony\Component\Routing\RouteCollection
;
use
Silex\Api\BootableProviderInterface
;
use
Silex\Api\EventListenerProviderInterface
;
use
Silex\Api\ControllerProviderInterface
;
...
...
@@ -62,47 +59,6 @@ class Application extends Container implements HttpKernelInterface, TerminableIn
{
parent
::
__construct
();
$this
[
'routes_factory'
]
=
$this
->
factory
(
function
()
{
return
new
RouteCollection
();
});
$this
[
'routes'
]
=
function
(
$app
)
{
return
$app
[
'routes_factory'
];
};
$this
[
'controllers'
]
=
function
(
$app
)
{
return
$app
[
'controllers_factory'
];
};
$this
[
'controllers_factory'
]
=
$this
->
factory
(
function
(
$app
)
{
return
new
ControllerCollection
(
$app
[
'route_factory'
],
$app
[
'routes_factory'
]);
});
$this
[
'route_class'
]
=
'Silex\\Route'
;
$this
[
'route_factory'
]
=
$this
->
factory
(
function
(
$app
)
{
return
new
$app
[
'route_class'
]();
});
$this
[
'exception_handler'
]
=
function
(
$app
)
{
return
new
ExceptionHandler
(
$app
[
'debug'
]);
};
$this
[
'callback_resolver'
]
=
function
(
$app
)
{
return
new
CallbackResolver
(
$app
);
};
$this
[
'resolver'
]
=
function
(
$app
)
{
return
new
ControllerResolver
(
$app
,
$app
[
'logger'
]);
};
$this
[
'kernel'
]
=
function
(
$app
)
{
return
new
HttpKernel
(
$app
[
'dispatcher'
],
$app
[
'resolver'
],
$app
[
'request_stack'
]);
};
$this
[
'request_stack'
]
=
function
()
{
return
new
RequestStack
();
};
$this
[
'request.http_port'
]
=
80
;
$this
[
'request.https_port'
]
=
443
;
$this
[
'debug'
]
=
false
;
...
...
src/Silex/Provider/KernelServiceProvider.php
View file @
f96d5421
...
...
@@ -2,26 +2,52 @@
namespace
Silex\Provider
;
use
Pimple\ServiceProviderInterface
;
use
Pimple\Container
;
use
Pimple\ServiceProviderInterface
;
use
Silex\Api\EventListenerProviderInterface
;
use
Silex\CallbackResolver
;
use
Silex\ControllerResolver
;
use
Silex\EventListener\ConverterListener
;
use
Silex\EventListener\MiddlewareListener
;
use
Silex\EventListener\StringToResponseListener
;
use
Silex\ExceptionHandler
;
use
Symfony\Component\EventDispatcher\EventDispatcher
;
use
Symfony\Component\EventDispatcher\EventDispatcherInterface
;
use
Symfony\Component\HttpFoundation\RequestStack
;
use
Symfony\Component\HttpKernel\EventListener\ResponseListener
;
use
Symfony\Component\HttpKernel\HttpKernel
;
class
KernelServiceProvider
implements
ServiceProviderInterface
,
EventListenerProviderInterface
{
/**
* {@inheritdoc}
*/
public
function
register
(
Container
$
pimple
)
public
function
register
(
Container
$
app
)
{
$pimple
[
'dispatcher'
]
=
function
()
{
$app
[
'exception_handler'
]
=
function
(
$app
)
{
return
new
ExceptionHandler
(
$app
[
'debug'
]);
};
$app
[
'resolver'
]
=
function
(
$app
)
{
return
new
ControllerResolver
(
$app
,
$app
[
'logger'
]);
};
$app
[
'kernel'
]
=
function
(
$app
)
{
return
new
HttpKernel
(
$app
[
'dispatcher'
],
$app
[
'resolver'
],
$app
[
'request_stack'
]);
};
$app
[
'request_stack'
]
=
function
()
{
return
new
RequestStack
();
};
$app
[
'dispatcher'
]
=
function
()
{
return
new
EventDispatcher
();
};
$app
[
'callback_resolver'
]
=
function
(
$app
)
{
return
new
CallbackResolver
(
$app
);
};
}
/**
...
...
src/Silex/Provider/RoutingServiceProvider.php
View file @
f96d5421
...
...
@@ -13,9 +13,11 @@ namespace Silex\Provider;
use
Pimple\Container
;
use
Pimple\ServiceProviderInterface
;
use
Silex\ControllerCollection
;
use
Silex\Api\EventListenerProviderInterface
;
use
Silex\Provider\Routing\RedirectableUrlMatcher
;
use
Silex\Provider\Routing\LazyRequestMatcher
;
use
Symfony\Component\Routing\RouteCollection
;
use
Symfony\Component\Routing\Generator\UrlGenerator
;
use
Symfony\Component\Routing\RequestContext
;
use
Symfony\Component\HttpKernel\EventListener\RouterListener
;
...
...
@@ -30,6 +32,19 @@ class RoutingServiceProvider implements ServiceProviderInterface, EventListenerP
{
public
function
register
(
Container
$app
)
{
$app
[
'route_class'
]
=
'Silex\\Route'
;
$app
[
'route_factory'
]
=
$app
->
factory
(
function
(
$app
)
{
return
new
$app
[
'route_class'
]();
});
$app
[
'routes_factory'
]
=
$app
->
factory
(
function
()
{
return
new
RouteCollection
();
});
$app
[
'routes'
]
=
function
(
$app
)
{
return
$app
[
'routes_factory'
];
};
$app
[
'url_generator'
]
=
function
(
$app
)
{
return
new
UrlGenerator
(
$app
[
'routes'
],
$app
[
'request_context'
]);
};
...
...
@@ -47,6 +62,14 @@ class RoutingServiceProvider implements ServiceProviderInterface, EventListenerP
return
$context
;
};
$app
[
'controllers'
]
=
function
(
$app
)
{
return
$app
[
'controllers_factory'
];
};
$app
[
'controllers_factory'
]
=
$app
->
factory
(
function
(
$app
)
{
return
new
ControllerCollection
(
$app
[
'route_factory'
],
$app
[
'routes_factory'
]);
});
$app
[
'routing.listener'
]
=
function
(
$app
)
{
$urlMatcher
=
new
LazyRequestMatcher
(
function
()
use
(
$app
)
{
return
$app
[
'request_matcher'
];
...
...
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