1. 19 Jun, 2012 12 commits
    • Romain Neutron's avatar
    • Fabien Potencier's avatar
      merged branch fabpot/php54 (PR #378) · 3be840d4
      Fabien Potencier authored
      Commits
      -------
      
      63e660fa added more docs
      acf60818 added some unit tests
      72ac7c5a merged the render and stream method of TwigTrait
      a439ae7f added traits for the routes
      3266c735 added application traits for PHP 5.4
      
      Discussion
      ----------
      
      PHP 5.4 support
      
      This is a first attempt to provide useful shortcut methods on the Application class via traits. It also contains a `secure` method for routes.
      
      Here is how you can make use of these features on PHP 5.4:
      
          use Silex\Application;
          use Silex\Route;
      
          class MyApp extends Application
          {
              use Application\TwigTrait;
              use Application\SecurityTrait;
              use Application\FormTrait;
              use Application\UrlGeneratorTrait;
              use Application\SwiftmailerTrait;
              use Application\MonologTrait;
              use Application\TranslationTrait;
          }
      
          class MyRoute extends Route
          {
              use Route\SecurityTrait;
          }
      
          $app = new MyApp();
          $app['route_factory'] = function () use ($app) {
              return new MyRoute();
          };
      
      This PR depends on #376.
      
      And here is a sample controller using the traits:
      
          $app->get('/{name}', function(Application $app, Request $request, $name) {
      
              $app->mail(\Swift_Message::newInstance()
                  ->setSubject('[YourSite] Feedback')
                  ->setFrom(array('noreply@yoursite.com'))
                  ->setTo(array('feedback@yoursite.com'))
                  ->setBody($request->get('message')));
      
              $app->log('Foo Bar');
      
              return $app->render('hello', [
                  'name' => $name,
                  'url'  => $app->url('home', ['name' => 'Fabien']),
                  'user' => $app->user(),
              ]);
          })
          ->bind('home')
          ->assert('name', '\w+')
          ->secure('ROLE_ADMIN') // <- method defined in Route\SecurityTrait
          ;
      
      As you can see, it makes things much more readable and easier to understand. And of course, it makes Silex very flexible as you can add any method on Application and Route. You just need to define a trait and register it on your custom Application or Route.
      
      ---------------------------------------------------------------------------
      
      by fabpot at 2012-06-17T15:32:15Z
      
      Another option to avoid having to override the route factory is to define a parameter for the route class:
      
          $app['route_class'] = 'MyRoute';
      
      Most of the time this should be sufficient.
      
      ---------------------------------------------------------------------------
      
      by fzaninotto at 2012-06-17T16:56:59Z
      
      VERY readable. This change makes Silex even better. Great idea!
      
      ---------------------------------------------------------------------------
      
      by mrmark at 2012-06-18T17:42:57Z
      
      This is really awesome!  Really shows off the power of traits.
      
      I was trying out Silex a while ago, and I wanted to try to extend the Silex\Application class, but this sort of broke down at the [Silex\ControllerProviderInterface](https://github.com/fabpot/Silex/blob/master/src/Silex/ControllerProviderInterface.php#L28) because it expects the Silex\Application class.  This means that IDE's and the like wouldn't know about any new methods in my new class.  This is probably more important now with this PR because the IDE wouldn't know about any of the traits used.
      
      ---------------------------------------------------------------------------
      
      by stof at 2012-06-18T17:46:55Z
      
      @mrmark There is nothing we can do for it. We cannot document the doc by mentioning your own application class. It would be wrong as the silex application class is valid, and it would be impossible as your own application class is not part of silex.
      
      ---------------------------------------------------------------------------
      
      by mrmark at 2012-06-18T18:17:20Z
      
      @stof Sorry, I wasn't suggesting that Silex be modified to accommodate my application class specifically.  I'm not actually sure of the solution here, perhaps change the interface to look like so:
      
          public function connect($app);
      
      And then depend upon the PHPDoc to tell the IDE what $app really is?  In the end, it would be nice if we knew what $app really was so we would know what methods and the like are available.
      
      ---------------------------------------------------------------------------
      
      by stof at 2012-06-18T18:19:20Z
      
      @mrmark the issue is the same: the phpdoc is still in the Silex code. And removing typehints just because inheritance is allowed is wrong IMO
      
      ---------------------------------------------------------------------------
      
      by fabpot at 2012-06-19T07:51:38Z
      
      I've just added a bunch of unit tests for the new traits. Any other thoughts before I merge?
      
      ---------------------------------------------------------------------------
      
      by GromNaN at 2012-06-19T08:05:22Z
      
      Trait tests should be skipped for PHP < 5.4
      
      ---------------------------------------------------------------------------
      
      by fabpot at 2012-06-19T08:07:38Z
      
      @GromNaN That's already the case.
      
      ---------------------------------------------------------------------------
      
      by igorw at 2012-06-19T11:17:26Z
      
      👍 Ship it!
      3be840d4
    • Fabien Potencier's avatar
      added more docs · 63e660fa
      Fabien Potencier authored
      63e660fa
    • Fabien Potencier's avatar
      added some unit tests · acf60818
      Fabien Potencier authored
      acf60818
    • Fabien Potencier's avatar
      72ac7c5a
    • Fabien Potencier's avatar
      added traits for the routes · a439ae7f
      Fabien Potencier authored
      a439ae7f
    • Fabien Potencier's avatar
      added application traits for PHP 5.4 · 3266c735
      Fabien Potencier authored
      3266c735
    • Fabien Potencier's avatar
    • Fabien Potencier's avatar
      updated the changelog · a105baec
      Fabien Potencier authored
      a105baec
    • Fabien Potencier's avatar
      updated docs · ef658842
      Fabien Potencier authored
      ef658842
    • Fabien Potencier's avatar
    • Fabien Potencier's avatar
  2. 18 Jun, 2012 7 commits
    • Fabien Potencier's avatar
      merged branch davedevelopment/monolog-logger-class (PR #382) · 71310c08
      Fabien Potencier authored
      Commits
      -------
      
      030713de Monolog class is configurable
      
      Discussion
      ----------
      
      Monolog logger class is configurable and accessible
      
      As an alternative to #379
      
      ---------------------------------------------------------------------------
      
      by igorw at 2012-06-18T13:43:36Z
      
      👍
      71310c08
    • Fabien Potencier's avatar
      merged branch fabpot/route-factory (PR #376) · b65b30e7
      Fabien Potencier authored
      Commits
      -------
      
      c463a6e1 added some unit tests
      e29c91ed added an exception when a method does not exist to ease debugging
      3fd92830 made controller methods (before, after, ...) extensible
      
      Discussion
      ----------
      
      made controller methods (before, after, ...) extensible
      
      You can now add your own methods on controllers (like the built-in
      after, before, convert, ...) by defining your own Route class:
      
          class MyRoute extends Route
          {
              public function secure($roles, $app)
              {
                  // do something
              }
          }
      
      and then change the "route_factory" accordingly:
      
          $this['route_factory'] = function () {
              return new MyRoute();
          };
      
      If you want to benefit from the new methods in a custom controller
      collection, pass an instance of your Route to the ControllerCollection
      constructor:
      
          $controllers = new ControllerCollection(new MyRoute());
      
      or even better, use the "controllers_factory" service:
      
          $controllers = $app['controllers_factory'];
      
      The limitation is that you can only have one custom Route class in an
      Application. But this PR is just the first step. Thanks to PHP 5.4 and
      the new traits support, the next pull request (#378) uses this new
      refactoring to provide traits that you can add to your
      custom Application Route class.
      
      ---------------------------------------------------------------------------
      
      by igorw at 2012-06-18T12:13:33Z
      
      Looks good to me. One thing, what about a method_exists() in `__call` to give a better error message?
      
      ---------------------------------------------------------------------------
      
      by fabpot at 2012-06-18T17:41:34Z
      
      I've added an exception for when the method does not exist.
      
      ---------------------------------------------------------------------------
      
      by fabpot at 2012-06-18T18:03:00Z
      
      And now with some unit tests.
      
      ---------------------------------------------------------------------------
      
      by igorw at 2012-06-18T18:33:33Z
      
      👍
      b65b30e7
    • Fabien Potencier's avatar
      added some unit tests · c463a6e1
      Fabien Potencier authored
      c463a6e1
    • Fabien Potencier's avatar
    • Dave Marshall's avatar
      Monolog class is configurable · 030713de
      Dave Marshall authored
      030713de
    • Fabien Potencier's avatar
      made controller methods (before, after, ...) extensible · 3fd92830
      Fabien Potencier authored
      You can now add your own methods on controllers (like the built-in
      after, before, convert, ...) by defining your own Route class:
      
          class MyRoute extends Route
          {
              public function secure($roles, $app)
              {
                  // do something
              }
          }
      
      and then change the route class accordingly:
      
          $this['route_class'] = 'MyRoute';
      
      or change the "route_factory" if you need to pass some arguments to the
      route constructor:
      
          $this['route_factory'] = function () {
              return new MyRoute();
          };
      
      If you want to benefit from the new methods in a custom controller
      collection, pass an instance of your Route to the ControllerCollection
      constructor:
      
          $controllers = new ControllerCollection(new MyRoute());
      
      or even better, use the "controllers_factory" service:
      
          $controllers = $app['controllers_factory'];
      
      The limitation is that you can only have one custom Route class in an
      Application. But this PR is just the first step. Thanks to PHP 5.4 and
      the new traits support, the next pull request will use this new
      refactoring to provide traits that you will be able to add to your
      custom Application Route class.
      3fd92830
    • Fabien Potencier's avatar
      7e603906
  3. 17 Jun, 2012 15 commits
    • Fabien Potencier's avatar
      merged branch besnikb/master (PR #380) · 3732ec18
      Fabien Potencier authored
      Commits
      -------
      
      e35830cf added missing php command
      
      Discussion
      ----------
      
      Added missing php command
      
      ---------------------------------------------------------------------------
      
      by stof at 2012-06-17T20:34:18Z
      
      if you make the phar executable, it will work without using ``php``, thanks to the shebang. But adding the command is indeed a good idea for windows users.
      3732ec18
    • Fabien Potencier's avatar
      fixed typo in the doc · 5bda6d80
      Fabien Potencier authored
      5bda6d80
    • Fabien Potencier's avatar
      merged branch lyrixx/fix-translation (PR #381) · 8b663670
      Fabien Potencier authored
      Commits
      -------
      
      64cb149a Added a default translator.domains
      c0321197 [Doc] Fixed typo in translator recipes
      
      Discussion
      ----------
      
      Fix translation
      
      Fixed a typo in the doc + Added a default translator.domains :
      
      If someone registers its translations via yaml, he will not provide $app['translator.domains'], so pimple will raise an exeption.
      
      I don't know if it's better to set a default $app['translator.domains'] or to checks if it set before using it.
      8b663670
    • Grégoire Pineau's avatar
      Added a default translator.domains · 64cb149a
      Grégoire Pineau authored
      If someone registers its translation via yaml,
      he will not provide $app['translator.domains'],
      so pimple will raise an exeption.
      64cb149a
    • Grégoire Pineau's avatar
      [Doc] Fixed typo in translator recipes · c0321197
      Grégoire Pineau authored
      c0321197
    • Besnik Br.'s avatar
      added missing php command · e35830cf
      Besnik Br. authored
      e35830cf
    • Fabien Potencier's avatar
      tweaked previous commit · 55d7a266
      Fabien Potencier authored
      55d7a266
    • Fabien Potencier's avatar
      merged branch j0k3r/patch-1 (PR #370) · b3992382
      Fabien Potencier authored
      Commits
      -------
      
      ebd3bbca [docs] Add config example for lighttpd
      
      Discussion
      ----------
      
      [docs] Add config example for lighttpd
      
      ---------------------------------------------------------------------------
      
      by fabpot at 2012-06-15T17:11:49Z
      
      This is a very specific configuration (assets, ...). I don't see any value to add that to the Silex documentation.
      
      ---------------------------------------------------------------------------
      
      by j0k3r at 2012-06-16T11:06:48Z
      
      I can remove the assets & favicon part.
      I know that few people were looking for the lighttpd configuration for Silex. I put this few lines in the readme file of one my little project so I thought it would be worth it in the official documentation.
      b3992382
    • Fabien Potencier's avatar
      fixed documentation (closes #375) · 496aa805
      Fabien Potencier authored
      496aa805
    • Fabien Potencier's avatar
      merged branch denniscoorn/http-authentication-fix (PR #374) · 315c9626
      Fabien Potencier authored
      Commits
      -------
      
      51596d47 Fixed a bug when using http authentication on the security service provider
      
      Discussion
      ----------
      
      Fixed a bug when using http authentication on the security service provider
      
      Hi Fabien,
      
      When I added HTTP authentication to my Silex application an exception was thrown. Due the exception I wasn't able to use HTTP authentication when I accessed the application through the browser.
      
      I used the following security firewall:
      ```php
      'http-auth' => array(
          'pattern' => '^.*$',
          'http' => true,
          'users' => array(
              // password is foo
              'admin'  => array('ROLE_ADMIN', '5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg=='),
          ),
      )
      ```
      
      The following exception was thrown:
      ```
      InvalidArgumentException: Identifier "security.entry_point.http" is not defined
      ```
      
      It's a small fix and I also added some tests. All tests passed before I committed my changes.
      
      I would appreciate it when you take a look at this pull request.
      315c9626
    • Dennis Coorn (thuis)'s avatar
      Fixed a bug when using http authentication on the · 51596d47
      Dennis Coorn (thuis) authored
      security service provider
      51596d47
    • Fabien Potencier's avatar
      updated vendors · bc8cdd18
      Fabien Potencier authored
      bc8cdd18
    • Fabien Potencier's avatar
      fixed doc · 2da348ac
      Fabien Potencier authored
      2da348ac
    • Fabien Potencier's avatar
      merged branch stof/swift_autoload (PR #373) · b5f025c2
      Fabien Potencier authored
      Commits
      -------
      
      1c41a6be Removed the swiftmailer autoloading from the service provider
      
      Discussion
      ----------
      
      Removed the swiftmailer autoloading from the service provider
      
      It is now handled by composer directly once swiftmailer/swiftmailer#212 is merged.
      b5f025c2
    • Christophe Coevoet's avatar
      Removed the swiftmailer autoloading from the service provider · 1c41a6be
      Christophe Coevoet authored
      It is now handled by composer directly.
      1c41a6be
  4. 16 Jun, 2012 6 commits