@@ -63,26 +63,34 @@ public function setBackup($backup)
63
63
*/
64
64
public function dump (MessageCatalogue $ messages , $ options = array ())
65
65
{
66
- if (!array_key_exists ('path ' , $ options )) {
67
- throw new \InvalidArgumentException ('The file dumper needs a path option. ' );
66
+ if (!array_key_exists ('path ' , $ options ) && ! array_key_exists ( ' format_callback ' , $ options ) ) {
67
+ throw new \InvalidArgumentException ('The file dumper needs a path or format_callback option. ' );
68
68
}
69
69
70
70
// save a file for each domain
71
71
foreach ($ messages ->getDomains () as $ domain ) {
72
- // backup
73
- $ fullpath = $ options ['path ' ].'/ ' .$ this ->getRelativePath ($ domain , $ messages ->getLocale ());
74
- if (file_exists ($ fullpath )) {
75
- if ($ this ->backup ) {
76
- copy ($ fullpath , $ fullpath .'~ ' );
77
- }
78
- } else {
79
- $ directory = dirname ($ fullpath );
80
- if (!file_exists ($ directory ) && !@mkdir ($ directory , 0777 , true )) {
81
- throw new \RuntimeException (sprintf ('Unable to create directory "%s". ' , $ directory ));
72
+ $ content = $ this ->formatCatalogue ($ messages , $ domain , $ options );
73
+ if (array_key_exists ('path ' , $ options )) {
74
+ // backup
75
+ $ fullpath = $ options ['path ' ].'/ ' .$ this ->getRelativePath ($ domain , $ messages ->getLocale ());
76
+ if (file_exists ($ fullpath )) {
77
+ if ($ this ->backup ) {
78
+ copy ($ fullpath , $ fullpath .'~ ' );
79
+ }
80
+ } else {
81
+ $ directory = dirname ($ fullpath );
82
+ if (!file_exists ($ directory ) && !@mkdir ($ directory , 0777 , true )) {
83
+ throw new \RuntimeException (sprintf ('Unable to create directory "%s". ' , $ directory ));
84
+ }
82
85
}
86
+
87
+ // save file
88
+ file_put_contents ($ fullpath , $ content );
89
+ }
90
+
91
+ if (array_key_exists ('format_callback ' , $ options ) && is_callable ($ options ['format_callback ' ])) {
92
+ call_user_func ($ options ['format_callback ' ], $ content );
83
93
}
84
- // save file
85
- file_put_contents ($ fullpath , $ this ->formatCatalogue ($ messages , $ domain , $ options ));
86
94
}
87
95
}
88
96
0 commit comments