2017-12-23 8 views
0

ich die Anweisungen in https://symfony.com/doc/master/session/proxy_examples.html,Symfony 4 - Fehler, wenn ich versuche, eine Session Proxy

Ich aktualisiere meine framework.yaml

framework: 
    secret: '%env(APP_SECRET)%' 
    #default_locale: en 
    #csrf_protection: ~ 
    #http_method_override: true 

# uncomment this entire section to enable sessions 
session: 
    # With this config, PHP's native session handling is used 
    handler_id: App\Session\CookieEncryptedSession 

#esi: ~ 
#fragments: ~ 
php_errors: 
    log: true 

Außerdem erstelle ich meine ownclass folgen zu erstellen:

<?php 
namespace App\Session; 

use Defuse\Crypto\Crypto; 
use Defuse\Crypto\Key; 
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy; 

class CookieEncryptedSession extends SessionHandlerProxy 
{ 
    private $key; 

    public function __construct(\SessionHandlerInterface $handler, Key $key) 
    { 
    $this->key = $key; 

    parent::__construct($handler); 
    } 

    public function read($id) 
    { 
    $data = parent::read($id); 

    return Crypto::decrypt($data, $this->key); 
    } 

    public function write($id, $data) 
    { 
    $data = Crypto::encrypt($data, $this->key); 

    return parent::write($id, $data); 
    } 
} 

Wenn ich versuche, den Server mit der Konsole auszuführen bekomme ich diesen Fehler:

In CheckCircularReferencesPass.php line 67: 

    Circular reference detected for service "App\Session\CookieEncryptedSession 
    ", path: "App\Session\CookieEncryptedSession -> App\Session\CookieEncrypted 
    Session".  

Irgendeine Idee wo ist der Fehler?

Dank

Oskar

Antwort

0

Die autowiring versucht, den Dienst selbst zu injizieren, als der Dienst die Schnittstelle an den Konstruktor erforderlich implementiert. CookieEncryptedSession Geräte SessionHandlerInterface über:

class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface 

-Setup in Ihre Dienste der Service: CookieEncryptedSession manuell so können Sie den SessionHandlerInterface Dienst wählen Sie wollen.

  • NativeSessionHandler
  • NativeFileSessionHandler
  • DbalSessionHandler
  • Etc
Verwandte Themen