PHP code example of api-skeletons / laravel-doctrine-apikey
1. Go to this page and download the library: Download api-skeletons/laravel-doctrine-apikey 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/ */
api-skeletons / laravel-doctrine-apikey example snippets
declare(strict_types=1);
namespace App\ORM\Event\Subscriber;
use ApiSkeletons\Laravel\Doctrine\ApiKey\Entity\ApiKey;
use App\ORM\Entity\Customer;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Events;
class ApiKeyEventSubscriber implements
EventSubscriber
{
/**
* {@inheritDoc}
*/
public function getSubscribedEvents()
{
return [
Events::loadClassMetadata,
];
}
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void
{
// the $metadata is the whole mapping info for this class
$metadata = $eventArgs->getClassMetadata();
switch ($metadata->getName()) {
case Customer::class:
$metadata->mapOneToOne([
'targetEntity' => ApiKey::class,
'fieldName' => 'apiKey',
]);
break;
default:
break;
}
}
}
use ApiSkeletons\Laravel\Doctrine\ApiKey\Service\ApiKeyService;
public function register(): void
{
$this->app->singleton('ApiKeyService2', static function ($app) {
return new ApiKeyService();
});
}
public function boot()
{
app('ApiKeyService2')->init(app('em2'));
}