Skip to content

Instantly share code, notes, and snippets.

@baptistedonaux
baptistedonaux / iis_url_rewrite_rules.xml
Last active December 29, 2015 17:28
IIS URL Rewrite Rules
<rewrite>
<rules>
<rule name="Rewriter" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{R:1}" pattern="^(app\\.php|favicon\\.ico)" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="./app.php/{R:1}" appendQueryString="true" />
<?php
function unzip($path_zip, $tmp_folder = "/tmp/") {
$all_files = array();
$zip = zip_open($path_zip);
if ($zip) {
$stream = zip_read($zip);
while ($stream) {
var_dump($zip_name);
$zip_name = zip_entry_name($stream);
<?php
function execute ($sql_query, $id = null, $delay = 3600) {
//On déclare une instance de cache
$cacheDriver = new \Doctrine\Common\Cache\XcacheCache();
$results = null;
//Si un ID a été saisie et que le système de cache contient des données pour un ID "x"
if ($id != null && $cacheDriver->contains($id)) {
//Alors on prend les données en cache pour un ID "x"
$results = $cacheDriver->fetch($id);
@baptistedonaux
baptistedonaux / services.yml
Last active January 1, 2016 07:19
Abus lors de la déclaration d'un manager Symfony, avec l'utilisation du @service_container.
services:
namespace.x.yManager:
class: Namespace\NameBundle\Manager\NameManager
arguments: [@service_container]
@baptistedonaux
baptistedonaux / services.yml
Created December 24, 2013 12:59
Exemple d'injection propre sans passer le @service_container.
services:
namespace.x.yManager:
class: Namespace\NameBundle\Manager\NameManager
arguments: [@doctrine.orm.entity_manager]
@baptistedonaux
baptistedonaux / config.yml
Last active January 1, 2016 23:29
Comment déporter la session sous Symfony2.
# config.yml
framework:
# …
session:
# La session sera déportée dans app/var/sessions/
# N'oubliez pas de créer les deux dossiers, sinon Symfony2 n'arrivera pas à écrire dans votre répertoire
save_path: %kernel.root_dir%/var/sessions
# …
@baptistedonaux
baptistedonaux / auto_encode.php
Last active August 29, 2015 13:56
Auto detect encod string and return the same string to UTF-8 encode.
<?php
mb_convert_encoding($string, "UTF-8", mb_detect_encoding($string));
?>
@baptistedonaux
baptistedonaux / del_invisible_ascii_chars.php
Created June 4, 2014 09:54
Delete invisible ASCII chars which can generate errors.
<?php
gc_disable();
$content = file_get_contents("db.csv");
if ($content === false) {
echo "ERROR: impossible to read the file.";
die();
}
@baptistedonaux
baptistedonaux / SecurityController.php
Last active August 29, 2015 14:05
SecurityController for Symfony2 Framework
<?php
use JMS\SecurityExtraBundle\Annotation\Secure;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
@baptistedonaux
baptistedonaux / UserProvider.php
Created August 20, 2014 15:25
UserProvider.php
<?php
namespace Namespace\MyBundle\Security\User;
use Doctrine\ORM\EntityManager;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\Expr\Comparison;
use Symfony\Component\Security\Core\Exception\DisabledException;
use Symfony\Component\Security\Core\Exception\LockedException;