Contao\CoreBundle\Composer\ScriptHandler::generateRandomSecret PHP Метод

generateRandomSecret() публичный статический Метод

Sets the environment variable for the random secret.
public static generateRandomSecret ( Composer\Script\Event $event )
$event Composer\Script\Event
    public static function generateRandomSecret(Event $event)
    {
        $extra = $event->getComposer()->getPackage()->getExtra();
        if (!isset($extra['incenteev-parameters']) || !self::canGenerateSecret($extra['incenteev-parameters'])) {
            return;
        }
        if (!function_exists('random_bytes')) {
            self::loadRandomCompat($event);
        }
        putenv(static::RANDOM_SECRET_NAME . '=' . bin2hex(random_bytes(32)));
    }

Usage Example

Пример #1
0
 /**
  * Tests that no secret is generated if at least one of multiple configuration files exists.
  */
 public function testGeneratesNoRandomSecretIfFileExistsArray()
 {
     $this->assertRandomSecretDoesNotExist();
     touch(__DIR__ . '/../Fixtures/app/config/parameters.yml');
     $this->handler->generateRandomSecret($this->getComposerEvent(['incenteev-parameters' => [['file' => __DIR__ . '/../Fixtures/app/config/parameters.yml'], ['file' => __DIR__ . '/../Fixtures/app/config/test.yml']]]));
     unlink(__DIR__ . '/../Fixtures/app/config/parameters.yml');
     $this->assertRandomSecretDoesNotExist();
 }