/** * Construit la pioche * @param Configuration $configuration */ public function __construct(Configuration $configuration) { $configurationArray = $configuration->toArray(); foreach ($configurationArray['letters'] as $letter => $data) { for ($i = 0; $i < $data['count']; $i++) { $this->push(new LetterTile($letter, $data['score'])); } } }
/** * Construit un objet de configuration * @param type $filename * @throws InvalidArgumentException * @throws LoadFileException */ public function __construct($filename) { if ($filename == NULL || !is_string($filename)) { throw new InvalidArgumentException('$filename arg cannot be null and must be a string'); } if (!is_readable($filename)) { throw new LoadFileException('Cannot read the file ' . $filename); } $this->filename = $filename; $values = Yaml::parse(file_get_contents($filename)); if (array_key_exists('extends', $values)) { $extendsFilename = dirname($filename) . DIRECTORY_SEPARATOR . $values['extends']; if (!is_readable($extendsFilename)) { throw new LoadFileException('Cannot read the file ' . $extendsFilename); } $extends = new Configuration($extendsFilename); $values = array_replace_recursive($extends->toArray(), $values); } $this->values = $values; }