PHP code example of pimcore / static-resolver-bundle

1. Go to this page and download the library: Download pimcore/static-resolver-bundle 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/ */

    

pimcore / static-resolver-bundle example snippets


   use Pimcore\Bundle\StaticResolverBundle\PimcoreStaticResolverBundle;
   // ...

   return [
       // ...
       PimcoreStaticResolverBundle::class => ['all' => true],
       // ...
   ];
   

use Pimcore\Tool\Authentication;

final class SecurityService implements SecurityServiceInterface
{
    public function getPimcoreUser(): User
    {
        $pimcoreUser = Authentication::authenticateSession();
        if (!$pimcoreUser instanceof User) {
            throw new Exception('No pimcore user found');
        }

        return $pimcoreUser;
    }
}

use Pimcore\Bundle\StaticResolverBundle\Contract\Lib\Tools\Authentication\AuthenticationResolverContractInterface;

final class SecurityService implements SecurityServiceInterface
{
     public function __construct(private readonly AuthenticationResolverContractInterface $authenticationResolver
    ) {
    }

    public function getPimcoreUser(): User
    {
        $pimcoreUser = $this->authenticationResolver->authenticateSession();
        if (!$pimcoreUser instanceof User) {
            throw new Exception('No pimcore user found');
        }

        return $pimcoreUser;
    }
}

use Pimcore\Db;

$connection = Db::getConnection();
$data = $connection->fetchAllAssociative('SELECT * FROM users');

use Pimcore\Bundle\StaticResolverBundle\Contract\Db\DbResolverContractInterface;

class UserRepository
{
    public function __construct(private readonly DbResolverContractInterface $dbResolver)
    {
    }

    public function getAllUsers(): array
    {
        $connection = $this->dbResolver->getConnection();
        return $connection->fetchAllAssociative('SELECT * FROM users');
    }
}

use Pimcore\Tool\Authentication;

$user = Authentication::authenticateSession();

use Pimcore\Bundle\StaticResolverBundle\Contract\Lib\Tools\Authentication\AuthenticationResolverContractInterface;

class AuthService
{
    public function __construct(private readonly AuthenticationResolverContractInterface $authenticationResolver)
    {
    }

    public function getCurrentUser()
    {
        return $this->authenticationResolver->authenticateSession();
    }
}

use Pimcore\Bundle\StaticResolverBundle\Db\DbResolverInterface;

/**
 * @internal This class is for internal Pimcore use only
 */
class InternalPimcoreService
{
    public function __construct(private readonly DbResolverInterface $dbResolver)
    {
    }

    public function executeInternalQuery(): array
    {
        $connection = $this->dbResolver->getConnection();
        return $connection->fetchAllAssociative('SELECT * FROM internal_table');
    }
}

use Pimcore\Bundle\StaticResolverBundle\Lib\Tools\Authentication\AuthenticationResolverInterface;

/**
 * @internal This class is for internal Pimcore use only
 */
class InternalAuthService
{
    public function __construct(private readonly AuthenticationResolverInterface $authenticationResolver)
    {
    }

    public function validateInternalUser()
    {
        return $this->authenticationResolver->authenticateSession();
    }
}