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
cc4b5758
Commit
cc4b5758
authored
Apr 03, 2011
by
Igor Wiedler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[docs] better examples for the extensions chapter
parent
e0bfc17f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
11 deletions
+19
-11
doc/extensions.rst
doc/extensions.rst
+19
-11
No files found.
doc/extensions.rst
View file @
cc4b5758
...
@@ -10,18 +10,20 @@ Loading extensions
...
@@ -10,18 +10,20 @@ Loading extensions
In order to load and use an extension, you must register it
In order to load and use an extension, you must register it
on the application. ::
on the application. ::
use Acme\
God
Extension;
use Acme\
Database
Extension;
$app = new Application();
$app = new Application();
$app->register(new
God
Extension());
$app->register(new
Database
Extension());
You can also provide some parameters as a second argument.
You can also provide some parameters as a second argument.
::
::
$app->register(new GodExtension(), array(
$app->register(new DatabaseExtension(), array(
'god.deity' => 'thor',
'database.dsn' => 'mysql:host=localhost;dbname=myapp',
'database.user' => 'root',
'database.password' => 'secret_root_password',
));
));
Included extensions
Included extensions
...
@@ -104,20 +106,20 @@ classes using the ``UniversalClassLoader``.
...
@@ -104,20 +106,20 @@ classes using the ``UniversalClassLoader``.
As described in the *Services* chapter, there is an
As described in the *Services* chapter, there is an
*autoloader* service that you can use for this.
*autoloader* service that you can use for this.
Here is an example of how to use it::
Here is an example of how to use it
(based on `Buzz <https://github.com/kriswallsmith/Buzz>`_)
::
namespace Acme;
namespace Acme;
use Silex\ExtensionInterface;
use Silex\ExtensionInterface;
class
God
Extension implements ExtensionInterface
class
Buzz
Extension implements ExtensionInterface
{
{
public function register(Application $app)
public function register(Application $app)
{
{
$app['
god
'] = $app->share(function() { ... });
$app['
buzz
'] = $app->share(function() { ... });
if (isset($app['
god
.class_path'])) {
if (isset($app['
buzz
.class_path'])) {
$app['autoloader']->register
Prefix('God_', $app['god
.class_path']);
$app['autoloader']->register
Namespace('Buzz', $app['buzz
.class_path']);
}
}
}
}
}
}
...
@@ -125,6 +127,12 @@ Here is an example of how to use it::
...
@@ -125,6 +127,12 @@ Here is an example of how to use it::
This allows you to simply provide the class path as an
This allows you to simply provide the class path as an
option when registering the extension::
option when registering the extension::
$app->register(new
God
Extension(), array(
$app->register(new
Buzz
Extension(), array(
'
god.class_path' => __DIR__.'/vendor/god/src
',
'
buzz.class_path' => __DIR__.'/vendor/buzz/lib
',
));
));
.. note::
For libraries that do not use PHP 5.3 namespaces you can use ``registerPrefix``
instead of ``registerNamespace``, which will use an underscore as directory
delimiter.
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