Skip to content

Instantly share code, notes, and snippets.

View shubaivan's full-sized avatar
🏠
Working from home

shubaivan shubaivan

🏠
Working from home
View GitHub Profile
<?php
require_once 'vendor/autoload.php';
$expressionLang = new \Symfony\Component\Security\Core\Authorization\ExpressionLanguage(
new \Symfony\Component\Cache\Adapter\NullAdapter()
);
$iterations = 500000;
$rawExpression = "1 in [1, 2, 3, 4] and (1 == 2 or 1 > 2 or 'foo' in ['bar', 'foo'])";
##
## How to install mcrypt in php7.2 / php7.3
## Linux / MacOS / OSX
##
## https://lukasmestan.com/install-mcrypt-extension-in-php7-2/
#
@dmaicher
dmaicher / TagAwareQueryResultCache.php
Last active April 16, 2020 08:47
use symfony/cache 3.2 tag aware cache as Doctrine DBAL query result cache
<?php
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Cache\DoctrineProvider;
class TagAwareQueryResultCache extends DoctrineProvider
{
/**
<?php
namespace Geekhub\UserBundle\Tests\UserProvider;
use Geekhub\UserBundle\Entity\User;
use Geekhub\UserBundle\UserProvider\FacebookProvider;
use HWI\Bundle\OAuthBundle\OAuth\Response\PathUserResponse;
class FacebookProviderTest extends \PHPUnit_Framework_TestCase
{
<?php
if (is_cli()) {
echo "********************************\n";
echo "* *\n";
echo "* Symfony requirements check *\n";
echo "* *\n";
echo "********************************\n\n";
echo sprintf("php.ini used by PHP: %s\n\n", get_ini_path());
@kelvinn
kelvinn / cmd.sh
Created July 24, 2014 02:55
Example of using Apache Bench (ab) to POST JSON to an API
# post_loc.txt contains the json you want to post
# -p means to POST it
# -H adds an Auth header (could be Basic or Token)
# -T sets the Content-Type
# -c is concurrent clients
# -n is the number of requests to run in the test
ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/
<?php
namespace NoxLogic\DemoBundle\Form\Type;
use Doctrine\ORM\EntityManager;
use NoxLogic\DemoBundle\Entity\Province;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
@samsamm777
samsamm777 / gist:7230159
Last active April 26, 2024 13:24
PHP set private property value using reflection. This allows you to set a private property value from outside the object, great for PHPUnit testing.
<?php
$a = new A();
$reflection = new \ReflectionClass($a);
$property = $reflection->getProperty('privateProperty');
$property->setAccessible(true);
$property->setValue($a, 'new-value');
echo $a->getPrivateProperty();
//outputs:
@phpfour
phpfour / AppController.php
Last active September 30, 2018 16:14
Amazon S3 with Symfony2 and Gaufrette
<?php
namespace LM\Bundle\CoreBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class AppController extends Controller
{
@danvbe
danvbe / 1-Explanations.md
Last active April 21, 2023 15:39
A way to integrate FosUserBundle and HWIOAuthBundle

I have managed to install this… and make it work. I implemented it for Facebook and Google, but you can extend it. My solution it is mostly as described in #116, with a bit of more code presented. The key aspects that lack in the #116 presentation (IMO) are:

  • the registration as service of your custom FOSUBUserProvider (with the necessary parameters)
  • set the service for oauth_user_provider in the security.yml with your custom created service

Here are the steps:

  1. Routing. In routing.yml I have added all the routes for both bundles.
  2. Configuration. I have set the config.yml mostly as it is presented in the HWIOAuthBundle.
  3. Security. I have set the security.yml mostly as it is presented in the HWIOAuthBundle (though my routes are using /login pattern, not /connect). Also, the oauth_user_provider is set for my custom service.