Skip to content

Instantly share code, notes, and snippets.

<?php
class SwaggerDecorator implements NormalizerInterface
{
private $decorated;
public function __construct(NormalizerInterface $decorated)
{
$this->decorated = $decorated;
}
<?php
class OwnerExtension implements QueryCollectionExtensionInterface
{
private $tokenStorage;
public function __construct(TokenStorageInterface $tokenStorage)
{
$this->tokenStorage = $tokenStorage;
@piotrbrzezina
piotrbrzezina / App\Entity\Subject.php
Created June 26, 2019 18:19
Flashcard step 9 (security advance)
<?php
/**
* @ApiResource(
* ...
* itemOperations={
* "get" = { object.user == user" },
* "put" = { object.user == user" }
* },
* )
@piotrbrzezina
piotrbrzezina / App\Entity\Subject.php
Created June 26, 2019 16:27
Flashcard step 9 (security)
/**
* @ApiResource(
* normalizationContext={"groups"={"subjectList"}},
* denormalizationContext={"groups"={"subjectCreate"}},
* itemOperations={"get","put"},
* attributes={"access_control"="is_granted('ROLE_USER')"}
* )
*
* @ORM\Entity
*/
@piotrbrzezina
piotrbrzezina / App\EventSubscriber\UserSubscriber.php
Created January 27, 2019 21:21
Flashcard step 8 (Event system)
<?php
namespace App\EventSubscriber;
use ApiPlatform\Core\EventListener\EventPriorities;
use App\Entity\User;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
@piotrbrzezina
piotrbrzezina / App\Entity\User.php
Created January 27, 2019 21:07
Flashcard step 8 (Event system)
<?php
// ...
class User implements UserInterface
{
// ...
public $roles = ['ROLE_USER'];
/**
* ...
* @Assert\Length(min="8", max="255", groups={"userCreate", "userChangePassword"})
@piotrbrzezina
piotrbrzezina / api\config\packages\security.yaml
Created January 27, 2019 21:01
configure security step 3
encoders:
App\Entity\User:
algorithm: 'argon2i'
memory_cost: 1024
time_cost: 2
threads: 2
@piotrbrzezina
piotrbrzezina / api\config\routes.yaml
Created January 27, 2019 10:29
configure security login path
login:
path: /login
@piotrbrzezina
piotrbrzezina / api\config\packages\security.yaml
Last active January 27, 2019 10:25
configure security step 2
...
firewalls:
login:
pattern: ^/login
stateless: true
anonymous: true
provider: db_provider
json_login:
check_path: /login
@piotrbrzezina
piotrbrzezina / api\config\packages\security.yaml
Last active January 26, 2019 07:01
configure security step 1
security:
providers:
db_provider:
entity:
class: App\Entity\User
property: email