1: <?php
2: /**
3: * LICENSE (BSD)
4: *
5: * Copyright (c) 2012, Gerd Christian Kunze
6: * All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions are
10: * met:
11: *
12: * * Redistributions of source code must retain the above copyright
13: * notice, this list of conditions and the following disclaimer.
14: *
15: * * Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: *
19: * * Neither the name of Gerd Christian Kunze nor the names of the
20: * contributors may be used to endorse or promote products derived from
21: * this software without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24: * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34: *
35: * Read
36: * 31.07.2012 16:49
37: */
38: namespace MOC\Core\Drive\File;
39: use MOC\Api;
40: /**
41: * File-Read
42: */
43: class Read extends Write {
44:
45: /**
46: * Get Dependencies
47: *
48: * @static
49: * @return \MOC\Core\Depending
50: */
51: public static function InterfaceDepending() {
52: return Api::Core()->Depending();
53: }
54:
55: /**
56: * Get Singleton/Instance
57: *
58: * @static
59: * @return object
60: */
61: public static function InterfaceInstance() {
62: return new Read();
63: }
64:
65: /**
66: * Get Changelog
67: *
68: * @static
69: * @return \MOC\Core\Changelog
70: */
71: public static function InterfaceChangelog() {
72: return Api::Core()->Changelog()->Create( __CLASS__ );
73: }
74:
75: const AS_STRING = 0;
76: const AS_ARRAY = 1;
77: const AS_PHP = 2;
78:
79: /**
80: * Read-as-String
81: */
82: protected function ReadAsString() {
83: if( is_file( $this->Location() ) ) {
84: $this->Content = file_get_contents( $this->Location() );
85: } else {
86: $this->Content = '';
87: }
88: }
89:
90: /**
91: * Read-as-Array
92: */
93: protected function ReadAsArray() {
94: if( is_file( $this->Location() ) ) {
95: $this->Content = file( $this->Location() );
96: } else {
97: $this->Content = array();
98: }
99: }
100:
101: /**
102: * Read-as-PHP-Code
103: */
104: protected function ReadAsPhpCode() {
105: if( is_file( $this->Location() ) ) {
106: ob_start();
107: /** @noinspection PhpIncludeInspection */
108: include( $this->Location() ); $this->Content = ob_get_clean();
109: } else {
110: $this->Content = '';
111: }
112: }
113: }
114: