Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DescriptionSentenceGenerator.php
Go to the documentation of this file.
1 <?php
7 
12 {
16  private $dictionary;
17 
21  private $sentenceConfig;
22 
27  public function __construct(
28  \Magento\Setup\Model\Dictionary $dictionary,
29  array $sentenceConfig
30  ) {
31  $this->dictionary = $dictionary;
32  $this->sentenceConfig = $sentenceConfig;
33  }
34 
40  public function generate()
41  {
42  $sentenceWordsCount = random_int(
43  $this->sentenceConfig['words']['count-min'],
44  $this->sentenceConfig['words']['count-max']
45  );
46  $sentence = '';
47 
48  while ($sentenceWordsCount) {
49  $sentence .= $this->dictionary->getRandWord();
50  $sentence .= ' ';
51  $sentenceWordsCount--;
52  }
53 
54  return ucfirst(rtrim($sentence)) . '.';
55  }
56 }
__construct(\Magento\Setup\Model\Dictionary $dictionary, array $sentenceConfig)