Skip to content

Instantly share code, notes, and snippets.

@soyuka
soyuka / Alert.js
Last active March 22, 2019 09:45
Code react talk symfony api platform mercure hooks
const Alert = ({ error }) => {
if (!error) {
return null
}
return <div className='alert alert-error'>{error}</div>
}
export default Alert
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiProperty;
use App\Dto\Input;
/**
* @ApiResource(messenger="input", input=Input::class)
@soyuka
soyuka / DataTransformer.php
Created March 8, 2019 10:39
CQRS with Api Platform
<?php
namespace App\DataTransformer;
use ApiPlatform\Core\DataTransformer\DataTransformerInterface;
use App\Entity\InputTodo;
use App\Entity\Todo;
final class DataTransformer implements DataTransformerInterface {
public function transform($object, string $to, array $context = [])
@soyuka
soyuka / exists.rs
Created November 9, 2018 09:37
path exist rust
fn exists<P: AsRef<Path>>(path: P) -> Result<bool> {
if let Err(e) = fs::metadata(path) {
if e.kind() != io::ErrorKind::NotFound {
return Err(e.into())
}
return Ok(false)
}
Ok(true)
@soyuka
soyuka / rmdir.rs
Created November 8, 2018 16:18
rmdir rust
use std::fs;
use std::path::Path;
use std::io;
/// Remove dir, if non empty just skip
fn rmdir<P: AsRef<Path>>(path: P) -> Result<(), io::Error> {
if let Err(e) = fs::remove_dir(path) {
if e.kind() != io::ErrorKind::Other {
return Err(e);
}
@soyuka
soyuka / IriConverter.php
Created September 6, 2018 10:19
Override IriConverter and allow an ApiResource to not have any item route associated with it.
<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
@soyuka
soyuka / main.rs
Created July 9, 2018 14:04
Use case forward from param
// Entrypoint
#[get("/")]
fn index(path: DirectoryPath) -> Result<Template, Failure> {
list(path)
}
// Directory listing
#[get("/<path..>", rank = 2)]
fn dir(path: DirectoryPath) -> Result<Template, Failure> {
if !path.is_dir() {
@soyuka
soyuka / index.js
Last active July 12, 2018 07:56
Transform mime-db (js) to mime_guess (rust)
const fs = require('fs')
/**
* Usage:
* npm install
* node index.js > mime_types.rs
*
* IANA takes precedence over other sources.
*/
@soyuka
soyuka / Embedded.php
Created June 5, 2018 17:58 — forked from oxan/Embedded.php
Override API platform embedding decisions
<?php
// src/Serializer/Embedding/Embedded.php
namespace App\Serializer\Embedding;
/**
* @Annotation
* @Target({"PROPERTY", "METHOD"})
*/
class Embedded
@soyuka
soyuka / OperationPathResolver.php
Created May 15, 2018 13:24
Workflow bridge for api platform
<?php
declare(strict_types=1);
namespace ApiPlatform\Workflow\PathResolver;
use ApiPlatform\Core\PathResolver\OperationPathResolverInterface;
final class OperationPathResolver implements OperationPathResolverInterface
{