Skip to content

Instantly share code, notes, and snippets.

@Airone2000
Airone2000 / storagePolyfill.js
Created March 28, 2018 20:22 — forked from jarrodirwin/storagePolyfill.js
LocalStorage/SessionStorage Polyfill with Safari Private Browsing support.
// Refer to https://gist.github.com/remy/350433
try {
// Test webstorage existence.
if (!window.localStorage || !window.sessionStorage) throw "exception";
// Test webstorage accessibility - Needed for Safari private browsing.
localStorage.setItem('storage_test', 1);
localStorage.removeItem('storage_test');
} catch(e) {
(function () {
var Storage = function (type) {
// Refer to https://gist.github.com/remy/350433
try {
// Test webstorage existence.
if (!window.localStorage || !window.sessionStorage) throw "exception";
// Test webstorage accessibility - Needed for Safari private browsing.
localStorage.setItem('storage_test', 1);
localStorage.removeItem('storage_test');
} catch(e) {
(function () {
var Storage = function (type) {
@Airone2000
Airone2000 / API Platform
Last active April 25, 2018 21:10
Using voter with API Platform
https://stackoverflow.com/questions/47713642/api-platform-how-secure-custom-operation
https://symfony.com/doc/current/security/voters.html
Extending request to fit our needs :
https://api-platform.com/docs/core/data-providers/#data-providers
https://api-platform.com/docs/core/extensions
A priori, I only must write the extension and register it so that APIPlatform internal machanism can automatically extend the request for a route.
Let's test it!
@Airone2000
Airone2000 / gist:cf4dcd0f6585b068a8282659cb50ae94
Created April 28, 2018 09:19
API Platform : POST / PUT (relation)
Given I have a User entity and a Profile entity.
A User has a Profile (OneToOne).
When I send a POST request to "/users", with body:
"""
{
"username": "Erwan29",
"profile": {
"firstname": "Erwan",
"lastname": "Guillou"
@Airone2000
Airone2000 / OperationPathResolver.php
Created May 15, 2018 13:40 — forked from soyuka/OperationPathResolver.php
Workflow bridge for api platform
<?php
declare(strict_types=1);
namespace ApiPlatform\Workflow\PathResolver;
use ApiPlatform\Core\PathResolver\OperationPathResolverInterface;
final class OperationPathResolver implements OperationPathResolverInterface
{