/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
setup/src/Magento/Setup/Model/Dictionary.php
79 строк
2 KB
Alexandra Zota
ACP2E-4019: CE copyright updates for 2.4.9-beta1
22 окт 2025, 11:23
22 окт 2025, 11:23
6c2f6e6
Код
Авторство
О чём код?
<?php /** * Copyright 2017 Adobe * All Rights Reserved. */ namespace Magento\Setup\Model; /** * Provide random word from dictionary */ class Dictionary { /** * @var string */ private $dictionaryFilePath; /** * @var \SplFixedArray */ private $dictionary; /** * @param string $dictionaryFilePath * @throws \Magento\Setup\Exception */ public function __construct($dictionaryFilePath) { $this->dictionaryFilePath = $dictionaryFilePath; } /** * Returns random word from dictionary * * @return string */ public function getRandWord() { if ($this->dictionary === null) { $this->readDictionary(); } // mt_rand() here is not for cryptographic use. // phpcs:ignore Magento2.Security.InsecureFunction $randIndex = mt_rand(0, count($this->dictionary) - 1); return trim($this->dictionary[$randIndex]); } /** * Read dictionary file * * @return void * @throws \Magento\Setup\Exception */ private function readDictionary() { if (!is_readable($this->dictionaryFilePath)) { throw new \Magento\Setup\Exception( sprintf('Description file %s not found or is not readable', $this->dictionaryFilePath) ); } $rows = file($this->dictionaryFilePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); if ($rows === false) { throw new \Magento\Setup\Exception( sprintf('Error occurred while reading dictionary file %s', $this->dictionaryFilePath) ); } if (empty($rows)) { throw new \Magento\Setup\Exception( sprintf('Dictionary file %s is empty', $this->dictionaryFilePath) ); } $this->dictionary = \SplFixedArray::fromArray($rows); } }