Skip to content

Instantly share code, notes, and snippets.

View marydn's full-sized avatar
🦙

Mary De Nóbrega marydn

🦙
View GitHub Profile
@marydn
marydn / clean-file-name-dash.php
Last active June 25, 2017 17:41
Clean the name for a file and avoid rewrite files when they are being uploaded to server. Rename it by adding a sequential number at the end of name, before extension.
<?php
// Just keep letters and numbers.
// Replace everything else with dash, even spaces.
//------------------------------------------------------------------------------
$path = dirname(__FILE__);
$file = 'Dos elefantes.mp4'; // Already exists in server
$filename = substr($file, 0, strrpos($file, '.'));
@marydn
marydn / example.html.twig
Created January 14, 2014 18:30
Render all flash messages from Symfony in Twig.
{% for label, flashes in app.session.flashbag.all %}
{% for flash in flashes %}
<div class="alert alert-{{ label }}">
{{ flash }}
</div>
{% endfor %}
{% endfor %}
@marydn
marydn / LoginSuccessHandler.php
Created December 20, 2013 20:57
Custom URL redirect by role after success login on Symfony 2 using a service listener without FOSUser Bundle.
# src/Acme/DemoBundle/Security/Authentication/Handler/LoginSuccessHandler.php
<?php
namespace Acme\DemoBundle\Security\Authentication\Handler;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Router;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\SecurityContext;