Complex classes like Resource often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Resource, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
32 | class Resource |
||
33 | { |
||
34 | /** |
||
35 | * Available base access modes |
||
36 | * @var string base access mode must be one of these letters |
||
37 | */ |
||
38 | protected static $bases = "rwaxc"; |
||
39 | |||
40 | /** |
||
41 | * Hash of readable/writable stream open mode types. |
||
42 | * |
||
43 | * Mercilessly stolen from: |
||
44 | * https://github.com/guzzle/streams/blob/master/src/Stream.php |
||
45 | * |
||
46 | * My kudos and sincere thanks go out to Michael Dowling and Graham Campbell |
||
47 | * of the guzzle/streams PHP package. Thanks for the inspiration (in some cases) |
||
48 | * and the not suing me for outright theft (in this case). |
||
49 | * |
||
50 | * @var array Hash of readable and writable stream types |
||
51 | * @todo I think I can get rid of this by simply checking whether base is a |
||
52 | * particular letter OR plus is present... try it |
||
53 | * @todo Why are x and c (alone) not even on either of these lists? |
||
54 | * I just figured out why... readable and writable default to false. So |
||
55 | * only modes that change that default behavior are listed here |
||
56 | */ |
||
57 | protected static $readWriteHash = [ |
||
58 | 'read' => [ |
||
59 | 'r' => true, 'w+' => true, 'r+' => true, 'x+' => true, 'c+' => true, |
||
60 | 'rb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true, |
||
61 | 'c+b' => true, 'rt' => true, 'w+t' => true, 'r+t' => true, |
||
62 | 'x+t' => true, 'c+t' => true, 'a+' => true, |
||
63 | ], |
||
64 | 'write' => [ |
||
65 | 'w' => true, 'w+' => true, 'rw' => true, 'r+' => true, 'x+' => true, |
||
66 | 'c+' => true, 'wb' => true, 'w+b' => true, 'r+b' => true, |
||
67 | 'x+b' => true, 'c+b' => true, 'w+t' => true, 'r+t' => true, |
||
68 | 'x+t' => true, 'c+t' => true, 'a' => true, 'a+' => true, |
||
69 | ], |
||
70 | ]; |
||
71 | |||
72 | /** |
||
73 | * Stream URI. |
||
74 | * |
||
75 | * Contains the stream URI to connect to. |
||
76 | * |
||
77 | * @var string The stream uri |
||
78 | */ |
||
79 | protected $uri; |
||
80 | |||
81 | /** |
||
82 | * Stream resource handle. |
||
83 | * |
||
84 | * Contains the underlying stream resource handle (if there is one). |
||
85 | * Otherwise it will be null. |
||
86 | * |
||
87 | * @var resource The stream resource handle |
||
88 | */ |
||
89 | protected $conn; |
||
90 | |||
91 | /** |
||
92 | * Lazy open switch. |
||
93 | * |
||
94 | * Determines whether the actual fopen for this resource should be delayed |
||
95 | * until an I/O operation is performed. |
||
96 | * |
||
97 | * @var boolean True if connection is lazy |
||
98 | */ |
||
99 | protected $lazy; |
||
100 | |||
101 | /** |
||
102 | * Extra context to open the resource with. |
||
103 | * |
||
104 | * An associative array of context options and parameters. |
||
105 | * |
||
106 | * @var array An associative array of stream context options and params |
||
107 | * @see http://php.net/manual/en/stream.contexts.php |
||
108 | */ |
||
109 | protected $context = [ |
||
110 | 'options' => [], |
||
111 | 'params' => [] |
||
112 | ]; |
||
113 | |||
114 | /** |
||
115 | * Context resource handle. |
||
116 | * |
||
117 | * Holds a context resource handle object for $this->context |
||
118 | * |
||
119 | * @var resource The context resource handle |
||
120 | */ |
||
121 | protected $crh; |
||
122 | |||
123 | /** |
||
124 | * Should fopen use include path? |
||
125 | * |
||
126 | * @var boolean True if fopen should use the include path to find potential files |
||
127 | */ |
||
128 | protected $useIncludePath; |
||
129 | |||
130 | /** |
||
131 | * Base open mode. |
||
132 | * |
||
133 | * @var string A single character for base open mode (r, w, a, x or c) |
||
134 | */ |
||
135 | protected $base = ''; |
||
136 | |||
137 | /** |
||
138 | * Plus reading or plus writing. |
||
139 | * |
||
140 | * @var string Either a plus or an empty string |
||
141 | */ |
||
142 | protected $plus = ''; |
||
143 | |||
144 | /** |
||
145 | * Binary or text flag. |
||
146 | * |
||
147 | * @var string Either "b" or "t" for binary or text |
||
148 | */ |
||
149 | protected $flag = ''; |
||
150 | |||
151 | /** |
||
152 | * Does access mode string indicate readability? |
||
153 | * |
||
154 | * @var bool Whether access mode indicates readability |
||
155 | */ |
||
156 | protected $readable = false; |
||
157 | |||
158 | /** |
||
159 | * Does access mode string indicate writability |
||
160 | * |
||
161 | * @var bool Whether access mode indicates writability |
||
162 | */ |
||
163 | protected $writable = false; |
||
164 | |||
165 | /** |
||
166 | * Resource constructor. |
||
167 | * |
||
168 | * Instantiates a stream resource. If lazy is set to true, the connection |
||
169 | * is delayed until the first call to getResource(). |
||
170 | * |
||
171 | * @param string|resource $uri The URI to connect to OR a stream resource handle |
||
172 | * @param string $mode The connection mode |
||
173 | * @param boolean $lazy Whether connection should be deferred until an I/O |
||
174 | * operation is requested (such as read or write) on the attached stream |
||
175 | * @throws \CSVelte\Exception\IOException if connection fails |
||
176 | * @todo Does stream_get_meta_data belong in Stream or Resource? |
||
177 | */ |
||
178 | 95 | public function __construct($uri, $mode = null, $lazy = null, $use_include_path = null, $context_options = null, $context_params = null) |
|
179 | { |
||
180 | // first, check if we're wrapping an existing stream resource |
||
181 | 95 | if (is_resource($handle = $uri)) { |
|
182 | 6 | if (($resource_type = get_resource_type($handle)) != ($exp_resource_type = "stream")) { |
|
183 | 1 | throw new InvalidArgumentException(sprintf( |
|
184 | 1 | 'Invalid stream resource type for %s, expected "%s", got: "%s"', |
|
185 | 1 | __METHOD__, |
|
186 | 1 | $exp_resource_type, |
|
187 | $resource_type |
||
188 | 1 | )); |
|
189 | } |
||
190 | // set all this manually |
||
191 | 5 | $meta = stream_get_meta_data($handle); |
|
192 | 5 | $this->setUri($meta['uri']) |
|
193 | 5 | ->setMode($meta['mode']); |
|
194 | 5 | $this->conn = $handle; |
|
195 | 5 | return; |
|
196 | } |
||
197 | |||
198 | // ok we're opening a new stream resource handle |
||
199 | 89 | $this->setUri($uri) |
|
200 | 88 | ->setMode($mode) |
|
201 | 88 | ->setLazy($lazy) |
|
202 | 88 | ->setUseIncludePath($use_include_path) |
|
203 | 88 | ->setContext($context_options, $context_params); |
|
204 | 88 | if (!$this->isLazy()) { |
|
205 | 3 | $this->connect(); |
|
206 | 2 | } |
|
207 | 87 | } |
|
208 | |||
209 | /** |
||
210 | * Class destructor |
||
211 | */ |
||
212 | 89 | public function __destruct() |
|
216 | |||
217 | /** |
||
218 | * Invoke magic method. |
||
219 | * |
||
220 | * Creates and returns a Stream object for this resource |
||
221 | * |
||
222 | * @return resource The underlying stream resource |
||
223 | */ |
||
224 | 3 | public function __invoke() |
|
228 | |||
229 | /** |
||
230 | * Connect (open connection) to file/stream. |
||
231 | * |
||
232 | * File open is (by default) delayed until the user explicitly calls connect() |
||
233 | * or they request the resource handle with getHandle(). |
||
234 | * |
||
235 | * @return boolean True if connection was successful |
||
236 | * @throws \CSVelte\Exception\IOException if connection fails |
||
237 | */ |
||
238 | 79 | public function connect() |
|
261 | |||
262 | /** |
||
263 | * Close connection. |
||
264 | * |
||
265 | * Close the connection to this stream (if open). |
||
266 | * |
||
267 | * @return boolean|null Whether close was successful, or null if already closed |
||
268 | */ |
||
269 | 89 | public function disconnect() |
|
277 | |||
278 | /** |
||
279 | * Set stream URI. |
||
280 | * |
||
281 | * Set the stream URI. Can only be set if the connection isn't open yet. |
||
282 | * If you try to set the URI on an open resource, an IOException will be thrown |
||
283 | * |
||
284 | * @param string $uri The URI for this stream resource to open |
||
285 | * @return $this |
||
286 | * @throws \InvalidArgumentException if not a valid stream uri |
||
287 | * @throws \CSVelte\Exception\IOException if stream has already been opened |
||
288 | * @todo I'm pretty sure that the parse_url function is too restrictive. It |
||
289 | * will reject URIs that are perfectly valid. |
||
290 | */ |
||
291 | 94 | public function setUri($uri) |
|
310 | |||
311 | /** |
||
312 | * Set the fopen mode. |
||
313 | * |
||
314 | * Thank you to GitHub user "binsoul" whose AccessMode class inspired this |
||
315 | * Also thanks to the author(s) of Guzzle streams implementation, where the |
||
316 | * readwritehash idea came from. Both libraries are MIT licensed, so my |
||
317 | * merciless theft of their code is alright. |
||
318 | * |
||
319 | * @param string $mode A 1-3 character string determining open mode |
||
320 | * @return $this |
||
321 | * @throws \InvalidArgumentException if not a valid stream access mode |
||
322 | * @throws \CSVelte\Exception\IOException if stream has already been opened |
||
323 | * @see http://php.net/manual/en/function.fopen.php |
||
324 | * @see https://github.com/binsoul/io-stream/blob/master/src/AccessMode.php |
||
325 | * @see https://raw.githubusercontent.com/guzzle/streams/master/src/Stream.php |
||
326 | * @todo convert $mode to lower case and test it |
||
327 | */ |
||
328 | 93 | public function setMode($mode = null) |
|
348 | |||
349 | /** |
||
350 | * Update access parameters. |
||
351 | * |
||
352 | * After changing any of the access mode parameters, this method must be |
||
353 | * called in order for readable and writable to stay accurate. |
||
354 | * |
||
355 | * @return $this |
||
356 | */ |
||
357 | 93 | protected function updateAccess() |
|
363 | |||
364 | /** |
||
365 | * Set base access mode character. |
||
366 | * |
||
367 | * @param string $base The base mode character (must be one of "rwaxc") |
||
368 | * @return $this |
||
369 | * @throws \InvalidArgumentException If passed invalid base char |
||
370 | * @throws \CSVelte\Exception\IOException if stream has already been opened |
||
371 | */ |
||
372 | 93 | public function setBaseMode($base) |
|
381 | |||
382 | /** |
||
383 | * Set plus mode. |
||
384 | * |
||
385 | * @param boolean $isPlus Whether base access mode should include the + sign |
||
386 | * @return $this |
||
387 | * @throws \CSVelte\Exception\IOException if stream has already been opened |
||
388 | */ |
||
389 | 93 | public function setIsPlus($isPlus) |
|
395 | |||
396 | /** |
||
397 | * Set binary-safe mode. |
||
398 | * |
||
399 | * @param boolean $isBinary Whether binary safe mode or not |
||
400 | * @return $this |
||
401 | * @throws \CSVelte\Exception\IOException if stream has already been opened |
||
402 | */ |
||
403 | 93 | public function setIsBinary($isBinary) |
|
411 | |||
412 | /** |
||
413 | * Set text mode. |
||
414 | * |
||
415 | * @param boolean $isText Whether text mode or not |
||
416 | * @return $this |
||
417 | * @throws \CSVelte\Exception\IOException if stream has already been opened |
||
418 | */ |
||
419 | 93 | public function setIsText($isText) |
|
420 | { |
||
421 | 93 | $this->assertNotConnected(__METHOD__); |
|
422 | 93 | if ($isText) { |
|
423 | 1 | $this->flag = 't'; |
|
424 | 1 | } |
|
425 | 93 | return $this; |
|
426 | } |
||
427 | |||
428 | /** |
||
429 | * Set lazy flag. |
||
430 | * |
||
431 | * Set the lazy flag, which tells the class whether to defer the connection |
||
432 | * until the user specifically requests it. |
||
433 | * |
||
434 | * @param boolean|null Whether or not to "lazily" open the stream |
||
435 | * @return $this |
||
436 | */ |
||
437 | 88 | protected function setLazy($lazy) |
|
443 | |||
444 | /** |
||
445 | * Set use include path flag. |
||
446 | * |
||
447 | * Sets whether or not fopen should search the include path for files. Can |
||
448 | * only be set if resource isn't open already. If called when resource is |
||
449 | * already open an exception will be thrown. |
||
450 | * |
||
451 | * @param boolean $use_include_path Whether to search include path for files |
||
452 | * @throws \CSVelte\Exception\IOException |
||
453 | * @return $this |
||
454 | */ |
||
455 | 88 | public function setUseIncludePath($use_include_path) |
|
461 | |||
462 | /** |
||
463 | * Set stream context options and params. |
||
464 | * |
||
465 | * Sets arrays of stream context options and params. Check out the URI below |
||
466 | * for more on stream contexts. |
||
467 | * |
||
468 | * @param array|null $options Stream context options |
||
469 | * @param array|null $params Stream Context params |
||
470 | * @return $this |
||
471 | * @see http://php.net/manual/en/stream.contexts.php |
||
472 | */ |
||
473 | 88 | public function setContext($options = null, $params = null) |
|
474 | { |
||
475 | 88 | if (is_array($options)) { |
|
476 | 2 | foreach ($options as $wrap => $opts) { |
|
477 | 2 | $this->setContextOptions($opts, $wrap); |
|
478 | 2 | } |
|
479 | 2 | } |
|
480 | 88 | if (!is_null($params)) { |
|
481 | 2 | $this->setContextParams($params); |
|
482 | 2 | } |
|
483 | 88 | return $this; |
|
484 | } |
||
485 | |||
486 | /** |
||
487 | * Set context resource directly |
||
488 | * @param resource|null $context Stream context resource to set directly |
||
489 | * @return $this |
||
490 | * @see http://php.net/manual/en/function.stream-context-create.php |
||
491 | * @todo Need to write a unit test for passing this method a null value |
||
492 | */ |
||
493 | 75 | public function setContextResource($context) |
|
508 | |||
509 | /** |
||
510 | * Update the stream context. |
||
511 | * |
||
512 | * After setting/updating stream context options and/or params, this method |
||
513 | * must be called in order to update the stream context resource. |
||
514 | * |
||
515 | * @return $this |
||
516 | */ |
||
517 | 2 | protected function updateContext() |
|
518 | { |
||
519 | // if already connected, set the options on the context resource |
||
520 | // otherwise, it will be set at connection time |
||
521 | 2 | if ($this->isConnected()) { |
|
522 | // set options and params on existing stream resource |
||
523 | 1 | stream_context_set_params( |
|
524 | 1 | $this->getContext(), |
|
525 | 1 | $this->getContextParams() + [ |
|
526 | 1 | 'options' => $this->getContextOptions() |
|
527 | 1 | ] |
|
528 | 1 | ); |
|
529 | 1 | } |
|
530 | 2 | return $this; |
|
531 | } |
||
532 | |||
533 | /** |
||
534 | * Set context options. |
||
535 | * |
||
536 | * Sets stream context options for this stream resource. |
||
537 | * |
||
538 | * @param array $options An array of stream context options |
||
539 | * @param string $wrapper The wrapper these options belong to (if no wrapper |
||
540 | * argument, then $options should be an associative array with key being |
||
541 | * a wrapper name and value being its options) |
||
542 | * @return $this |
||
543 | * @throws \InvalidArgumentException if passed invalid options or wrapper |
||
544 | * @see http://php.net/manual/en/stream.contexts.php |
||
545 | */ |
||
546 | 2 | public function setContextOptions($options, $wrapper = null) |
|
547 | { |
||
548 | 2 | if (is_array($options)) { |
|
549 | 2 | if (is_null($wrapper)) { |
|
550 | $this->context['options'] = $options; |
||
551 | } else { |
||
552 | 2 | $this->assertValidWrapper($wrapper); |
|
553 | 2 | $this->context['options'][$wrapper] = $options; |
|
554 | } |
||
555 | 2 | $this->updateContext(); |
|
556 | 2 | return $this; |
|
557 | } |
||
558 | throw new InvalidArgumentException("Context options must be an array, got: " . gettype($options)); |
||
559 | } |
||
560 | |||
561 | /** |
||
562 | * Set context params. |
||
563 | * |
||
564 | * Set the context params for this stream resource. |
||
565 | * |
||
566 | * @param array $params An array of stream resource params |
||
567 | * @return $this |
||
568 | * @throws \InvalidArgumentException if passed invalid params |
||
569 | * @see http://php.net/manual/en/stream.contexts.php |
||
570 | */ |
||
571 | 2 | public function setContextParams($params) |
|
572 | { |
||
573 | 2 | if (is_array($params)) { |
|
574 | 2 | $this->context['params'] = $params; |
|
575 | 2 | $this->updateContext(); |
|
576 | 2 | return $this; |
|
577 | } |
||
578 | throw new InvalidArgumentException("Context parameters must be an array, got: " . gettype($params)); |
||
579 | } |
||
580 | |||
581 | /** |
||
582 | * Get context options for this stream resource. |
||
583 | * |
||
584 | * Returns the stream context options for this stream resource. Either all |
||
585 | * options for all wrappers, or just the options for the specified wrapper. |
||
586 | * |
||
587 | * @param string $wrapper If present, return options only for this wrapper |
||
588 | * @return array Context options (either all or for specified wrapper) |
||
589 | * @throws \InvalidArgumentException if the wrapper doesn't exist |
||
590 | */ |
||
591 | 79 | public function getContextOptions($wrapper = null) |
|
601 | |||
602 | /** |
||
603 | * Get context params for this stream resource. |
||
604 | * |
||
605 | * Returns the stream context params for this stream resource. |
||
606 | * |
||
607 | * @return array Context params for this stream resource |
||
608 | */ |
||
609 | 79 | public function getContextParams() |
|
613 | |||
614 | /** |
||
615 | * Get stream context resource. |
||
616 | * @return resource|null The stream context resource |
||
617 | */ |
||
618 | 82 | public function getContext() |
|
630 | |||
631 | /** |
||
632 | * Retrieve underlying stream resource handle. |
||
633 | * |
||
634 | * An accessor method for the underlying stream resource object. Also triggers |
||
635 | * stream connection if in lazy open mode. Because this method may potentially |
||
636 | * call the connect() method, it is possible that it may throw an exception |
||
637 | * if there is some issue with opening the stream. |
||
638 | * |
||
639 | * @return resource The underlying stream resource handle |
||
640 | * @throws \CSVelte\Exception\IOException |
||
641 | */ |
||
642 | 66 | public function getHandle() |
|
649 | |||
650 | /** |
||
651 | * Is the stream connection open? |
||
652 | * |
||
653 | * Tells you whether this stream resource is open or not. |
||
654 | * |
||
655 | * @return boolean Whether the stream is open |
||
656 | */ |
||
657 | 94 | public function isConnected() |
|
661 | |||
662 | /** |
||
663 | * Get the stream URI. |
||
664 | * |
||
665 | * Accessor method for stream URI. |
||
666 | * |
||
667 | * @return string The stream URI |
||
668 | */ |
||
669 | 79 | public function getUri() |
|
673 | |||
674 | /** |
||
675 | * Get the access mode. |
||
676 | * |
||
677 | * Tells you what the access mode is. This is the short string of characters |
||
678 | * that you would pass to the fopen function to tell it how to open a file/stream |
||
679 | * |
||
680 | * @return string The file/stream access mode |
||
681 | * @see http://php.net/manual/en/function.fopen.php |
||
682 | */ |
||
683 | 93 | public function getMode() |
|
692 | |||
693 | /** |
||
694 | * Is access mode binary-safe? |
||
695 | * @return boolean Whether binary-safe flag is set |
||
696 | */ |
||
697 | 4 | public function isBinary() |
|
701 | |||
702 | /** |
||
703 | * Is stream connected in text mode? |
||
704 | * @return boolean Whether text mode flag is set |
||
705 | */ |
||
706 | 3 | public function isText() |
|
710 | |||
711 | /** |
||
712 | * Is this a lazy open resource? |
||
713 | * @return boolean Whether this is a lazily-opened resource |
||
714 | */ |
||
715 | 88 | public function isLazy() |
|
719 | |||
720 | /** |
||
721 | * Should fopen search include path? |
||
722 | * @return boolean Whether fopen should search include path for files |
||
723 | */ |
||
724 | 79 | public function getUseIncludePath() |
|
728 | |||
729 | /** |
||
730 | * Does the access mode string indicate readability? |
||
731 | * |
||
732 | * Readable, in this context, only refers to the manner in which this stream |
||
733 | * resource was opened (if it even is opened yet). It is no indicator about |
||
734 | * whether or not the underlying stream actually supports read operations. |
||
735 | * It simply refers to the access mode string passed to it by the user. |
||
736 | * |
||
737 | * @return boolean Whether access mode indicates readability |
||
738 | */ |
||
739 | 51 | public function isReadable() |
|
743 | |||
744 | /** |
||
745 | * Does the access mode string indicate writability? |
||
746 | * |
||
747 | * Writable, in this context, only refers to the manner in which this stream |
||
748 | * resource was opened (if it even is opened yet). It is no indicator about |
||
749 | * whether or not the underlying stream actually supports write operations. |
||
750 | * It simply refers to the access mode string passed to it by the user. |
||
751 | * |
||
752 | * @return boolean Whether access mode indicates writability |
||
753 | */ |
||
754 | 21 | public function isWritable() |
|
758 | |||
759 | /** |
||
760 | * Is cursor positioned at the beginning of stream? |
||
761 | * |
||
762 | * Returns true if this stream resource's access mode positions the internal |
||
763 | * cursor at the beginning of the stream. |
||
764 | * |
||
765 | * @return boolean Whether cursor positioned at beginning of stream |
||
766 | */ |
||
767 | 2 | public function isCursorPositionedAtBeginning() |
|
768 | { |
||
769 | 2 | return $this->base != 'a'; |
|
770 | } |
||
771 | |||
772 | /** |
||
773 | * Is cursor positioned at the end of stream? |
||
774 | * |
||
775 | * Returns true if this stream resource's access mode positions the internal |
||
776 | * cursor at the end of the stream. |
||
777 | * |
||
778 | * @return boolean Whether cursor positioned at end of stream |
||
779 | */ |
||
780 | 2 | public function isCursorPositionedAtEnd() |
|
781 | { |
||
782 | 2 | return $this->base == 'a'; |
|
783 | } |
||
784 | |||
785 | /** |
||
786 | * Is content truncated to zero-length on opening? |
||
787 | * |
||
788 | * Returns true if this stream resource's access mode indicates truncation of |
||
789 | * stream content to zero-length upon opening. |
||
790 | * |
||
791 | * @return boolean Whether stream content is truncated on opening |
||
792 | */ |
||
793 | 3 | public function isTruncated() |
|
797 | |||
798 | /** |
||
799 | * Does stream access mode indicate file creation? |
||
800 | * |
||
801 | * Returns true if this stream's access mode implies that PHP will attempt to |
||
802 | * create a file if none exists. |
||
803 | * |
||
804 | * @return boolean Whether PHP should attempt to create file at $uri |
||
805 | */ |
||
806 | 1 | public function attemptsFileCreation() |
|
807 | { |
||
808 | 1 | return $this->base != 'r'; |
|
809 | } |
||
810 | |||
811 | /** |
||
812 | * Does stream access mode indicate the rejection of existing files? |
||
813 | * |
||
814 | * Returns true if this stream's access mode implies that PHP will fail to |
||
815 | * open a file if it already exists. |
||
816 | * |
||
817 | * @return boolean Whether PHP should attempt to create file at $uri |
||
818 | */ |
||
819 | 1 | public function rejectsExistingFiles() |
|
820 | { |
||
821 | 1 | return $this->base == 'x'; |
|
822 | } |
||
823 | |||
824 | /** |
||
825 | * Are write operations appended to the end of the stream? |
||
826 | * |
||
827 | * Returns true if write operations are appended to the end of the stream |
||
828 | * regardless of the position of the read cursor. |
||
829 | * |
||
830 | * @return boolean Whether write operations ore always appended |
||
831 | */ |
||
832 | 1 | public function appendsWriteOps() |
|
833 | { |
||
834 | 1 | return $this->base == 'w'; |
|
835 | } |
||
836 | |||
837 | /** |
||
838 | * Assert that stream resource is not open. |
||
839 | * |
||
840 | * Used internally to ensure that stream is not open, since some methods should |
||
841 | * only be called on unopened stream resources. |
||
842 | * |
||
843 | * @param string The method that is asserting |
||
844 | * @return void |
||
845 | * @throws \CSVelte\Exception\IOException if stream is open |
||
846 | */ |
||
847 | 94 | protected function assertNotConnected($method) |
|
853 | |||
854 | /** |
||
855 | * Assert that given wrapper is a valid, registered stream wrapper |
||
856 | * |
||
857 | * Used internally to ensure that a given stream wrapper is valid and available |
||
858 | * |
||
859 | * @param string The name of the stream wrapper |
||
860 | * @return void |
||
861 | * @throws \InvalidArgumentException if wrapper doesn't exist |
||
862 | */ |
||
863 | 2 | protected function assertValidWrapper($name) |
|
869 | |||
870 | } |
||
871 |