9
9
namespace MessageQueue ;
10
10
11
11
12
+ use Exception \FileCreateError ;
12
13
use Symfony \Component \OptionsResolver \OptionsResolver ;
13
14
14
15
class Environment
@@ -67,104 +68,89 @@ public function rotateAmount()
67
68
public function create ()
68
69
{
69
70
$ queueDir = $ this ->queueDir ();
70
- if (!is_dir ($ queueDir )) {
71
- if (!@mkdir ($ queueDir )) {
72
- throw new \ErrorException (error_get_last ());
73
- }
71
+ if (!@mkdir ($ queueDir , 0775 , true ) && !is_dir ($ queueDir )) {
72
+ throw new FileCreateError (error_get_last ());
74
73
}
75
74
$ readFile = $ this ->readFile ();
76
- if (!is_file ($ readFile )) {
77
- if (!@touch ($ readFile )) {
78
- throw new \ErrorException (error_get_last ());
79
- }
75
+ if (!is_file ($ readFile ) && !@touch ($ readFile )) {
76
+ throw new FileCreateError (error_get_last ());
80
77
}
81
78
$ readPointerFile = $ this ->rotateFile ();
82
- if (!is_file ($ readPointerFile )) {
83
- if (!@touch ($ readPointerFile )) {
84
- throw new \ErrorException (error_get_last ());
85
- }
79
+ if (!is_file ($ readPointerFile ) && !@touch ($ readPointerFile )) {
80
+ throw new FileCreateError (error_get_last ());
86
81
}
87
82
$ writeFile = $ this ->writeFile ();
88
- if (!is_file ($ writeFile )) {
89
- if (!@touch ($ writeFile )) {
90
- throw new \ErrorException (error_get_last ());
91
- }
83
+ if (!is_file ($ writeFile ) && !@touch ($ writeFile )) {
84
+ throw new FileCreateError (error_get_last ());
92
85
}
93
86
}
94
87
95
88
public function reset ()
96
89
{
97
- $ fp = fopen ($ this ->readFile (), "r + " );
90
+ $ fp = fopen ($ this ->readFile (), "br + " );
98
91
ftruncate ($ fp , 0 );
99
92
fclose ($ fp );
100
93
101
- $ fp = fopen ($ this ->rotateFile (), "r + " );
94
+ $ fp = fopen ($ this ->rotateFile (), "br + " );
102
95
ftruncate ($ fp , 0 );
103
96
fclose ($ fp );
104
97
105
- $ fp = fopen ($ this ->writeFile (), "r + " );
98
+ $ fp = fopen ($ this ->writeFile (), "br + " );
106
99
ftruncate ($ fp , 0 );
107
100
fclose ($ fp );
108
101
}
109
102
110
103
public function remove ()
111
104
{
112
- $ dir = $ this ->options ['dir ' ];
113
105
$ readFile = $ this ->readFile ();
114
- if (is_file ($ readFile )) {
115
- if (!@unlink ($ readFile )) {
116
- throw new \ErrorException (error_get_last ());
117
- }
106
+ if (is_file ($ readFile ) && !@unlink ($ readFile )) {
107
+ throw new FileCreateError (error_get_last ());
118
108
}
119
109
$ readPointerFile = $ this ->rotateFile ();
120
- if (is_file ($ readPointerFile )) {
121
- if (!@unlink ($ readPointerFile )) {
122
- throw new \ErrorException (error_get_last ());
123
- }
110
+ if (is_file ($ readPointerFile ) && !@unlink ($ readPointerFile )) {
111
+ throw new FileCreateError (error_get_last ());
124
112
}
113
+
125
114
$ writeFile = $ this ->writeFile ();
126
- if (is_file ($ writeFile )) {
127
- if (!@unlink ($ writeFile )) {
128
- throw new \ErrorException (error_get_last ());
129
- }
115
+ if (is_file ($ writeFile ) && !@unlink ($ writeFile )) {
116
+ throw new FileCreateError (error_get_last ());
130
117
}
118
+
131
119
$ queueDir = $ this ->queueDir ();
132
- if (is_dir ($ queueDir )) {
133
- if (!@rmdir ($ queueDir )) {
134
- throw new \ErrorException (error_get_last ());
135
- }
120
+ if (is_dir ($ queueDir ) && !@rmdir ($ queueDir )) {
121
+ throw new FileCreateError (error_get_last ());
136
122
}
137
123
}
138
124
139
125
public function validate ()
140
126
{
141
127
$ queueDir = $ this ->queueDir ();
142
128
if (!is_dir ($ queueDir )) {
143
- throw new \ ErrorException ('Queue Directory not created ' );
129
+ throw new FileCreateError ('Queue Directory not created ' );
144
130
}
145
131
if (!is_writable ($ queueDir )) {
146
- throw new \ ErrorException ('Queue Directory not writable ' );
132
+ throw new FileCreateError ('Queue Directory not writable ' );
147
133
}
148
134
$ readFile = $ this ->readFile ();
149
135
if (!is_file ($ readFile )) {
150
- throw new \ ErrorException ('Read file not created ' );
136
+ throw new FileCreateError ('Read file not created ' );
151
137
}
152
138
if (!is_writable ($ readFile )) {
153
- throw new \ ErrorException ('Read file not writable ' );
139
+ throw new FileCreateError ('Read file not writable ' );
154
140
}
155
141
$ readPointerFile = $ this ->rotateFile ();
156
142
if (!is_file ($ readPointerFile )) {
157
- throw new \ ErrorException ('Read pointer file not created ' );
143
+ throw new FileCreateError ('Read pointer file not created ' );
158
144
}
159
145
if (!is_writable ($ readPointerFile )) {
160
- throw new \ ErrorException ('Read pointer file not writable ' );
146
+ throw new FileCreateError ('Read pointer file not writable ' );
161
147
}
162
148
$ writeFile = $ this ->writeFile ();
163
149
if (!is_file ($ writeFile )) {
164
- throw new \ ErrorException ('Write file not created ' );
150
+ throw new FileCreateError ('Write file not created ' );
165
151
}
166
152
if (!is_writable ($ writeFile )) {
167
- throw new \ ErrorException ('Write file not writable ' );
153
+ throw new FileCreateError ('Write file not writable ' );
168
154
}
169
155
}
170
156
}
0 commit comments