PHP code example of randomstate / doctrine-scopes

1. Go to this page and download the library: Download randomstate/doctrine-scopes 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/ */

    

randomstate / doctrine-scopes example snippets


$scopes = new ScopeCollection();
$scope->add('myscope', new MyScope());
$scope->enable('myscope');

// Replace query builders with scopable ones
$em = new DecoratableEntityManager(new EntityManager(...));
$em->setQueryBuilderFactory(function() use($em, $scopes) {
    return new ScopableQueryBuilder($em, $scopes);
});

// Wrap repositories so that they are scoped
$em->extendRepositoryFactory(function(EntityRepository $repository) use($em) {
    return new ScopedEntityRepository($repository, $em);
})

$em->find(MyClass::class, 1); // this query is now scoped by whatever you have in MyScope@apply 🎉


public function boot() {
    $this->app->extend(RandomState\DoctrineScopes\ScopeCollection::class, function($scopes) {
        $scopes->add('myscope', new MyScope);
        $scopes->enable('myscope');
        
        return $scopes;
    });      
}