Skip to content

Commit

Permalink
Added uncompressed Silex.
Browse files Browse the repository at this point in the history
  • Loading branch information
umpirsky committed Jul 20, 2011
1 parent 9ae64de commit 7356fdb
Show file tree
Hide file tree
Showing 402 changed files with 28,233 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/bootstrap.php
Expand Up @@ -6,7 +6,7 @@
* (c) Saša Stamenković <umpirsky@gmail.com>
*/

include __DIR__ . '/../vendor/silex.phar';
include __DIR__ . '/../vendor/silex/autoload.php';

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
Expand Down
19 changes: 19 additions & 0 deletions vendor/silex/LICENSE
@@ -0,0 +1,19 @@
Copyright (c) 2010 Fabien Potencier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
38 changes: 38 additions & 0 deletions vendor/silex/README.md
@@ -0,0 +1,38 @@
Silex, a simple Web Framework
=============================

Silex is a simple web framework to develop simple websites based on
[Symfony2][1] components:


```php
<?php
require_once __DIR__.'/silex.phar';

$app = new Silex\Application();

$app->get('/hello/{name}', function ($name) use ($app) {
return 'Hello '.$app->escape($name);
});

$app->run();
```

Silex works with PHP 5.3.2 or later.

## Installation

Installing Silex is as easy as it can get. Download the [`silex.phar`][2] file
and you're done!

## More Information

Read the [documentation][3] for more information.

## License

Silex is licensed under the MIT license.

[1]: http://symfony.com
[2]: http://silex-project.org/get/silex.phar
[3]: http://silex-project.org/documentation
17 changes: 17 additions & 0 deletions vendor/silex/autoload.php
@@ -0,0 +1,17 @@
<?php

if (false === class_exists('Symfony\Component\ClassLoader\UniversalClassLoader', false)) {
require_once __DIR__.'/../../vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
}

use Symfony\Component\ClassLoader\UniversalClassLoader;

$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
'Symfony' => __DIR__.'/../../vendor/symfony/src',
'Silex' => __DIR__.'/src',
));
$loader->registerPrefixes(array(
'Pimple' => __DIR__.'/vendor/pimple/lib',
));
$loader->register();
9 changes: 9 additions & 0 deletions vendor/silex/compile
@@ -0,0 +1,9 @@
#!/usr/bin/env php
<?php

require_once __DIR__.'/autoload.php';

use Silex\Compiler;

$compiler = new Compiler();
$compiler->compile();
17 changes: 17 additions & 0 deletions vendor/silex/doc/conf.py
@@ -0,0 +1,17 @@
import sys, os
from sphinx.highlighting import lexers
from pygments.lexers.web import PhpLexer

sys.path.append(os.path.abspath('_exts'))

extensions = []
master_doc = 'index'
highlight_language = 'php'

project = u'Silex'
copyright = u'2010 Fabien Potencier'

version = '0'
release = '0.0.0'

lexers['php'] = PhpLexer(startinline=True)
24 changes: 24 additions & 0 deletions vendor/silex/doc/contributing.rst
@@ -0,0 +1,24 @@
Contributing
============

We are open to contributions to the Silex code. If you find
a bug or want to contribute an extension, just follow these
steps.

* Fork `the Silex repository <https://github.com/fabpot/Silex>`_
on github.

* Make your feature addition or bug fix.

* Add tests for it. This is important so we don't break it in a future version unintentionally.

* Send a pull request. Bonus points for topic branches.

If you have a big change or would like to discuss something,
please join us on the `mailing list
<http://groups.google.com/group/silex-php>`_.

.. note::

Any code you contribute must be licensed under the MIT
License.
172 changes: 172 additions & 0 deletions vendor/silex/doc/extensions.rst
@@ -0,0 +1,172 @@
Extensions
==========

Silex provides a common interface for extensions. These
define services on the application.

Loading extensions
------------------

In order to load and use an extension, you must register it
on the application. ::

$app = new Silex\Application();

$app->register(new Acme\DatabaseExtension());

You can also provide some parameters as a second argument. These
will be set **before** the extension is registered.

::

$app->register(new Acme\DatabaseExtension(), array(
'database.dsn' => 'mysql:host=localhost;dbname=myapp',
'database.user' => 'root',
'database.password' => 'secret_root_password',
));

Conventions
-----------

You need to watch out in what order you do certain things when
interacting with extensions. Just keep to these rules:

* Class paths (for the autoloader) must be defined **before**
the extension is registered. Passing it as a second argument
to ``Application::register`` qualifies too, because it sets
the passed parameters first.

*Reason: The extension will set up the autoloader at
extension register time. If the class path is not set
at that point, no autoloader can be registered.*

* Overriding existing services must occur **after** the
extension is registered.

*Reason: If the services already exist, the extension
will overwrite it.*

* You can set parameters any time before the service is
accessed.

Make sure to stick to this behavior when creating your
own extensions.

Included extensions
-------------------

There are a few extensions that you get out of the box.
All of these are within the ``Silex\Extension`` namespace.

* :doc:`DoctrineExtension <extensions/doctrine>`
* :doc:`MonologExtension <extensions/monolog>`
* :doc:`SessionExtension <extensions/session>`
* :doc:`TwigExtension <extensions/twig>`
* :doc:`TranslationExtension <extensions/translation>`
* :doc:`UrlGeneratorExtension <extensions/url_generator>`
* :doc:`ValidatorExtension <extensions/validator>`
* :doc:`HttpCacheExtension <extensions/http_cache>`

Creating an extension
---------------------

Extensions must implement the ``Silex\ExtensionInterface``.

::

interface ExtensionInterface
{
function register(Application $app);
}

This is very straight forward, just create a new class that
implements the ``register`` method. In this method you must
define services on the application which then may make use
of other services and parameters.

Here is an example of such an extension::

namespace Acme;

use Silex\Application;
use Silex\ExtensionInterface;

class HelloExtension implements ExtensionInterface
{
public function register(Application $app)
{
$app['hello'] = $app->protect(function ($name) use ($app) {
$default = $app['hello.default_name'] ? $app['hello.default_name'] : '';
$name = $name ?: $default;

return 'Hello '.$app->escape($name);
});
}
}

This class provides a ``hello`` service which is a protected
closure. It takes a name argument and will return
``hello.default_name`` if no name is given. If the default
is also missing, it will use an empty string.

You can now use this extension as follows::

$app = new Silex\Application();

$app->register(new Acme\HelloExtension(), array(
'hello.default_name' => 'Igor',
));

$app->get('/hello', function () use ($app) {
$name = $app['request']->get('name');

return $app['hello']($name);
});

In this example we are getting the ``name`` parameter from the
query string, so the request path would have to be ``/hello?name=Fabien``.

Class loading
~~~~~~~~~~~~~

Extensions are great for tying in external libraries as you
can see by looking at the ``MonologExtension`` and
``TwigExtension``. If the library is decent and follows the
`PSR-0 Naming Standard <http://groups.google.com/group/php-standards/web/psr-0-final-proposal>`_
or the PEAR Naming Convention, it is possible to autoload
classes using the ``UniversalClassLoader``.

As described in the *Services* chapter, there is an
*autoloader* service which can be used for this.

Here is an example of how to use it (based on `Buzz <https://github.com/kriswallsmith/Buzz>`_)::

namespace Acme;

use Silex\Application;
use Silex\ExtensionInterface;

class BuzzExtension implements ExtensionInterface
{
public function register(Application $app)
{
$app['buzz'] = $app->share(function () { ... });

if (isset($app['buzz.class_path'])) {
$app['autoloader']->registerNamespace('Buzz', $app['buzz.class_path']);
}
}
}

This allows you to simply provide the class path as an
option when registering the extension::

$app->register(new BuzzExtension(), array(
'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.
87 changes: 87 additions & 0 deletions vendor/silex/doc/extensions/doctrine.rst
@@ -0,0 +1,87 @@
DoctrineExtension
=================

The *DoctrineExtension* provides integration with the `Doctrine DBAL
<http://www.doctrine-project.org/projects/dbal>`_ for easy database acccess.

.. note::

There is only a Doctrine DBAL. An ORM service is **not** supplied.

Parameters
----------

* **db.options**: Array of Doctrine DBAL options.

These options are available:

* **driver**: The database driver to use, defaults to ``pdo_mysql``.
Can be any of: ``pdo_mysql``, ``pdo_sqlite``, ``pdo_pgsql``,
``pdo_oci``, ``oci8``, ``ibm_db2``, ``pdo_ibm``, ``pdo_sqlsrv``.

* **dbname**: The name of the database to connect to.

* **host**: The host of the database to connect to. Defaults to
localhost.

* **user**: The user of the database to connect to. Defaults to
root.

* **password**: The password of the database to connect to.

* **path**: Only relevant for ``pdo_sqlite``, specifies the path to
the SQLite database.

These and additional options are described in detail in the `Doctrine DBAL
configuration documentation <http://www.doctrine-project.org/docs/dbal/2.0/en/reference/configuration.html>`_.

* **db.dbal.class_path** (optional): Path to where the
Doctrine DBAL is located.

* **db.common.class_path** (optional): Path to where
Doctrine Common is located.

Services
--------

* **db**: The database connection, instance of
``Doctrine\DBAL\Connection``.

* **db.config**: Configuration object for Doctrine. Defaults to
an empty ``Doctrine\DBAL\Configuration``.

* **db.event_manager**: Event Manager for Doctrine.

Registering
-----------

Make sure you place a copy of *Doctrine DBAL* in ``vendor/doctrine-dbal``
and *Doctrine Common* in ``vendor/doctrine-common``.

::

$app->register(new Silex\Extension\DoctrineExtension(), array(
'db.options' => array(
'driver' => 'pdo_sqlite',
'path' => __DIR__.'/app.db',
),
'db.dbal.class_path' => __DIR__.'/vendor/doctrine-dbal/lib',
'db.common.class_path' => __DIR__.'/vendor/doctrine-common/lib',
));

Usage
-----

The Doctrine extension provides a ``db`` service. Here is a usage
example::

$app->get('/blog/show/{id}', function ($id) use ($app) {
$sql = "SELECT * FROM posts WHERE id = ?";
$post = $app['db']->fetchAssoc($sql, array((int) $id));

return "<h1>{$post['title']}</h1>".
"<p>{$post['body']}</p>";
});

For more information, consult the `Doctrine DBAL documentation
<http://www.doctrine-project.org/docs/dbal/2.0/en/>`_.

0 comments on commit 7356fdb

Please sign in to comment.