PHP code example of teknoo / east-common
1. Go to this page and download the library: Download teknoo/east-common 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/ */
teknoo / east-common example snippets
//In src/Security\Authenticator\UserConverter.php
declare(strict_types=1);
namespace App\Security\Authenticator;
use DomainException;
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
use Omines\OAuth2\Client\Provider\GitlabResourceOwner;
use Teknoo\East\Common\Object\User;
use Teknoo\East\CommonBundle\Contracts\Security\Authenticator\UserConverterInterface;
use Teknoo\Recipe\Promise\PromiseInterface;
class UserConverter implements UserConverterInterface
{
public function extractEmail(ResourceOwnerInterface $owner, PromiseInterface $promise): UserConverterInterface
{
if (!$owner instanceof GitlabResourceOwner) {
$promise->fail(new DomainException('Resource not manager'));
return $this;
}
$promise->success($owner->getEmail());
return $this;
}
public function convertToUser(ResourceOwnerInterface $owner, PromiseInterface $promise): UserConverterInterface
{
if (!$owner instanceof GitlabResourceOwner) {
$promise->fail(new DomainException('Resource not manager'));
return $this;
}
$promise->success(
(new User())->setEmail($owner->getEmail())
->setLastName($owner->getName())
->setFirstName($owner->getUsername())
);
return $this;
}
}