<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jeffersongoncalves / laravel-zero-credentials example snippets
use JeffersonGoncalves\LaravelZero\Credentials\CredentialsContract;
final class Credentials implements CredentialsContract
{
public function __construct(
public readonly string $username,
public readonly string $apiToken,
) {}
public static function fromArray(array $data): static
{
return new static(
username: $data['username'] ?? '',
apiToken: $data['api_token'] ?? '',
);
}
public function toArray(): array
{
return ['username' => $this->username, 'api_token' => $this->apiToken];
}
public function isValid(): bool
{
return $this->username !== '' && $this->apiToken !== '';
}
}
use JeffersonGoncalves\LaravelZero\Credentials\AbstractAuthService;
use JeffersonGoncalves\LaravelZero\Credentials\CredentialsContract;
final class AuthService extends AbstractAuthService
{
protected function appName(): string
{
return 'bb-cli'; // => ~/.bb-cli/config.json
}
protected function fromArray(array $data): CredentialsContract
{
return Credentials::fromArray($data);
}
}
use JeffersonGoncalves\LaravelZero\Credentials\AuthenticationException;
if (! $auth->isAuthenticated()) {
throw new AuthenticationException("Run 'bb auth:save' first.");
}