1. Go to this page and download the library: Download citizen63000/easy-api-core library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use EasyApiCore\Util\Entity\EntityConfigLoader;
// From entity class
$config = EntityConfigLoader::createEntityConfigFromEntityFullName(App\Entity\Product::class);
// From database table
$config = EntityConfigLoader::createEntityConfigFromDatabase($entityManager, 'Product', 'products');
use EasyApiCore\Util\Forms\FormSerializer;
$serializer = new FormSerializer($formFactory, $router, $doctrine);
$form = $formFactory->create(ProductType::class);
$serializedForm = $serializer->normalize($form);
use EasyApiCore\Command\AbstractCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class MyCommand extends AbstractCommand
{
protected function execute(InputInterface $input, OutputInterface $output): int
{
$repository = $this->getRepository(Product::class);
$this->writeLog($output, 'Processing...');
return Command::SUCCESS;
}
}
use EasyApiCore\Util\CoreUtilsTrait;
class MyService
{
use CoreUtilsTrait;
public function saveProduct(Product $product): void
{
$this->persistAndFlush($product);
}
}
use EasyApiCore\Util\String\CaseConverter;
use EasyApiCore\Util\String\Inflector;
// Case conversion
$camelCase = CaseConverter::convertSnakeCaseToCamelCase('my_variable'); // myVariable
$snakeCase = CaseConverter::convertCamelCaseToSnakeCase('myVariable'); // my_variable
// Pluralization
$plural = Inflector::pluralize('product'); // products
$singular = Inflector::singularize('products'); // product
use EasyApiCore\Util\ApiProblem;
use Symfony\Component\HttpFoundation\Response;
$error = new ApiProblem(Response::HTTP_NOT_FOUND, 'Product not found');