1. Go to this page and download the library: Download din9xtr/source-context 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/ */
din9xtr / source-context example snippets
#[AutoValidateSources]
class UserService implements SomeInterface // it's important
{
// ...
}
class UserService implements SomeInterface // it's important
{
#[AllowedSources([Source::API, Source::WEB])]
public function createUser(array $data): User
{
}
#[AllowedSources([Source::CLI, Source::CRON])]
public function listUsers(): void
{
}
}
readonly class SomeInstance
{
public function __construct(
private SourceContextInterface $context,
) {
}
public function exec(): ?SourceInterface
{
$this->context->set(NoSource::CLI);
}
}
#[AutoValidateSources]
class YourService
{
// ...
}
#[AllowedSources([Source::API, Source::WEB])]
public function someMethod(): void
{
// ...
}
use App\SourceContext\Contract\SourceContextInterface;
use App\SourceContext\Implementation\InMemorySourceContext;
$context = new InMemorySourceContext();
$context->set(Source::API);
$service = new UserService();
$proxy = ProxyGenerator::createProxy($service, $context);
enum YourSource: string implements SourceInterface
{
case API = 'api';
case WEB = 'web';
case NEW_SOURCE = 'new_source';
public function is(self|string|SourceInterface $other): bool
{
return $this->value === (string) $other;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.