silex

Silex security provider

狂风中的少年 提交于 2019-12-04 17:52:23
I have a class UserMapper <?php namespace Models; use Symfony\Component\Security\Core\User\UserProviderInterface; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use \PDO; class UserMapper implements UserProviderInterface { /** * Database connection. */ var $db = NULL; /** * Constructor function. Loads model from database if the id is known. * * @param $db * Database connection */ function __construct() { $this->db = ConnectionProvider:

Proper way to configure Silex Firewall to use api keys

蹲街弑〆低调 提交于 2019-12-04 16:54:14
I've been working on making an api that accepts api keys and followed the instructions on http://symfony.com/doc/current/cookbook/security/api_key_authentication.html using a database table to hold the api keys. Is there a better way to handle this strictly using silex's firewall settings? Symfony does not come with an API key authenticator out of the box, but you can create one (not easily, especially for beginers) following the cookbook entry you've posted. So the short answer to your questions is that no, there is no better way if you want to use the security library. But, there is some on

Silex Security success_handler

萝らか妹 提交于 2019-12-04 14:08:08
问题 How i can set a success_handler (and failure_handler) for the form authentication provider? Silex ignores me with this config: <?php use WebFactory\Security\UserProvider; $app->register(new Silex\Provider\SecurityServiceProvider(), array( 'security.firewalls' => array( 'dev' => array( 'pattern' => '^/(_(profiler|wdt)|css|images|js)/', 'security' => false ), 'default' => array( 'pattern' => '^/.*$', 'anonymous' => true, 'form' => array( 'login_path' => '/login', 'check_path' => '/login_check',

How to generate translation file (.po, .xliff, .yml,…) from a Symfony2/Silex project?

走远了吗. 提交于 2019-12-04 12:12:09
问题 Im going to build a Silex/Symfony2 project and I have been looking around for a method to generate XLIFF/PO/YAML translation files based on texts-to-be-translated inside the project but not found any instruction or documentation on it. My question is: Is there an automated way to generate translation file(s) in specific format for a Symfony2/Silex project? If yes, please tell me how to generate the file then update the translation after that. If no, please tell me how to create translation

Capture exceptions with a different handler for applications REST

北战南征 提交于 2019-12-04 11:07:51
The problem I'm building a small application with Silex . It's divided between a REST application and a website. ( two controllers , same app). The website has installed its own custom error handler , which returns a user friendly html page. The problem is that in the part dedicated REST application, I should somehow handle exceptions to return type [json] and content different from the error handler's custom website. With Symfony2 This argument can also be applied to Symfony2, I would like also possible solution for it! A first solution for Silex Wrap the methods in try-catch block in order

How to debug php fatal errors in Silex Framework

蹲街弑〆低调 提交于 2019-12-04 09:39:48
问题 I wonder how can I see syntax errors like this (missing semicolon): <?php var_dump($app) ?> This will cause a WSOD (white screen of death). I tried to include a debug config file which look like this: use Symfony\Component\Debug\ErrorHandler; use Symfony\Component\Debug\Debug; // Include the prod configuration require __DIR__.'/prod.php'; // Enable PHP Error level error_reporting(E_ALL); ini_set('display_errors','On'); // Enable debug mode $app['debug'] = true; // Handle fatal errors

How to handle Swift_TransportException in Silex

巧了我就是萌 提交于 2019-12-03 22:09:14
I'm having quiet weird problem with catching SwiftMailer's exceptions in Silex. I want to send an email like this: try { $message = \Swift_Message::newInstance() ->setSubject('subject') ->setFrom(array('form')) ->setTo(array('to')) ->setBody('body'); $app['mailer']->send($message); } catch (\Swift_TransportException $e) { $app['logger']->addError('Unable to send welcome email'); } I know it's not going to send any email on localhost and I'm expecting it to fail but why I can't catch the Swift_TransportException exception in try - catch block? It just prints: Fatal error: Uncaught exception

How to automatically login a new user after registration with a custom user provider in Silex?

被刻印的时光 ゝ 提交于 2019-12-03 21:23:19
Context : I created a custom user provider for my Silex Application and I can now register and log my own user perfectly. However, I need now to automatically log in my user after registration and this doesn't work. Here is my security section : 'secured' => array( 'pattern' => '^/', 'anonymous' => false, 'form' => array('login_path' => '/login', 'check_path' => '/login_check'), 'logout' => array('logout_path' => '/logout', 'invalidate_session' => true), 'users' => $app->share(function () use ($app) { return new Partner\DAO\PartnerDAO($app['db']); }) ) Here is my userProviderInterface : public

Attempted to call method “share” on class “Silex\\Application” in Silex 2

為{幸葍}努か 提交于 2019-12-03 10:29:52
I am developing a project with silex-skeleton in its most recent version. When trying to use the share method shows me the following error: Code: $app['login'] = $app->share(function() use($app) { return new Model\UserModel($app); }); Error: Attempted to call method "share" on class "Silex\Application" Any suggestions or possible cause of this failure mTorres Silex 2.0 is using Pimple 3.0 which has removed the shared method, now all services are shared by default, if you want a new instance you must call the factory method as stated in the changelog for version 2.0 . So if you want a login

Routing in Silex/Symfony. Providing a default route

这一生的挚爱 提交于 2019-12-03 09:47:29
问题 I'm attempting to do something using Silex (which uses the Symfony routing component - so the answer may be applicable to Symfony as well) I am adding Silex to a legacy application to provide routing but I need to respect the existing applications default implementation for loading files (which is simply to load the file from the file system form the URL specified). edit: for clarification: Existing file is loaded from the file system, as an include within an parent template, after a series