comparison vendor/symfony/translation/Dumper/FileDumper.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children 12f9dff5fda9
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
9 * file that was distributed with this source code. 9 * file that was distributed with this source code.
10 */ 10 */
11 11
12 namespace Symfony\Component\Translation\Dumper; 12 namespace Symfony\Component\Translation\Dumper;
13 13
14 use Symfony\Component\Translation\MessageCatalogue;
15 use Symfony\Component\Translation\Exception\InvalidArgumentException; 14 use Symfony\Component\Translation\Exception\InvalidArgumentException;
16 use Symfony\Component\Translation\Exception\RuntimeException; 15 use Symfony\Component\Translation\Exception\RuntimeException;
16 use Symfony\Component\Translation\MessageCatalogue;
17 17
18 /** 18 /**
19 * FileDumper is an implementation of DumperInterface that dump a message catalogue to file(s). 19 * FileDumper is an implementation of DumperInterface that dump a message catalogue to file(s).
20 * Performs backup of already existing files. 20 * Performs backup of already existing files.
21 * 21 *
51 } 51 }
52 52
53 /** 53 /**
54 * Sets backup flag. 54 * Sets backup flag.
55 * 55 *
56 * @param bool 56 * @param bool $backup
57 */ 57 */
58 public function setBackup($backup) 58 public function setBackup($backup)
59 { 59 {
60 $this->backup = $backup; 60 $this->backup = $backup;
61 } 61 }
62 62
63 /** 63 /**
64 * {@inheritdoc} 64 * {@inheritdoc}
65 */ 65 */
66 public function dump(MessageCatalogue $messages, $options = array()) 66 public function dump(MessageCatalogue $messages, $options = [])
67 { 67 {
68 if (!array_key_exists('path', $options)) { 68 if (!array_key_exists('path', $options)) {
69 throw new InvalidArgumentException('The file dumper needs a path option.'); 69 throw new InvalidArgumentException('The file dumper needs a path option.');
70 } 70 }
71 71
77 if ($this->backup) { 77 if ($this->backup) {
78 @trigger_error('Creating a backup while dumping a message catalogue is deprecated since Symfony 3.1 and will be removed in 4.0. Use TranslationWriter::disableBackup() to disable the backup.', E_USER_DEPRECATED); 78 @trigger_error('Creating a backup while dumping a message catalogue is deprecated since Symfony 3.1 and will be removed in 4.0. Use TranslationWriter::disableBackup() to disable the backup.', E_USER_DEPRECATED);
79 copy($fullpath, $fullpath.'~'); 79 copy($fullpath, $fullpath.'~');
80 } 80 }
81 } else { 81 } else {
82 $directory = dirname($fullpath); 82 $directory = \dirname($fullpath);
83 if (!file_exists($directory) && !@mkdir($directory, 0777, true)) { 83 if (!file_exists($directory) && !@mkdir($directory, 0777, true)) {
84 throw new RuntimeException(sprintf('Unable to create directory "%s".', $directory)); 84 throw new RuntimeException(sprintf('Unable to create directory "%s".', $directory));
85 } 85 }
86 } 86 }
87 // save file 87 // save file
96 * @param string $domain 96 * @param string $domain
97 * @param array $options 97 * @param array $options
98 * 98 *
99 * @return string representation 99 * @return string representation
100 */ 100 */
101 abstract public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array()); 101 abstract public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = []);
102 102
103 /** 103 /**
104 * Gets the file extension of the dumper. 104 * Gets the file extension of the dumper.
105 * 105 *
106 * @return string file extension 106 * @return string file extension
115 * 115 *
116 * @return string The relative file path 116 * @return string The relative file path
117 */ 117 */
118 private function getRelativePath($domain, $locale) 118 private function getRelativePath($domain, $locale)
119 { 119 {
120 return strtr($this->relativePathTemplate, array( 120 return strtr($this->relativePathTemplate, [
121 '%domain%' => $domain, 121 '%domain%' => $domain,
122 '%locale%' => $locale, 122 '%locale%' => $locale,
123 '%extension%' => $this->getExtension(), 123 '%extension%' => $this->getExtension(),
124 )); 124 ]);
125 } 125 }
126 } 126 }