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: * Property
36: * 31.07.2012 16:48
37: */
38: namespace MOC\Core\Drive\File;
39: use MOC\Api;
40: use MOC\Generic\Device\Core;
41:
42: /**
43: * File-Property
44: */
45: class Property implements Core {
46:
47: /**
48: * Get Dependencies
49: *
50: * @static
51: * @return \MOC\Core\Depending
52: */
53: public static function InterfaceDepending() {
54: return Api::Core()->Depending();
55: }
56:
57: /**
58: * Get Singleton/Instance
59: *
60: * @static
61: * @return object
62: */
63: public static function InterfaceInstance() {
64: return new Property();
65: }
66:
67: /**
68: * Get Changelog
69: *
70: * @static
71: * @return \MOC\Core\Changelog
72: */
73: public static function InterfaceChangelog() {
74: return Api::Core()->Changelog()->Create( __CLASS__ );
75: }
76:
77: /** @var null|string $Location */
78: private $Location = null;
79: /** @var null|array|string $Content */
80: protected $Content = null;
81: /** @var bool $Changed */
82: private $Changed = false;
83:
84: /** @var null|string $Name */
85: private $Name = null;
86: /** @var null|string $Extension */
87: private $Extension = null;
88: /** @var null|string $Path */
89: private $Path = null;
90: /** @var null|int $Size */
91: private $Size = null;
92: /** @var null|int $Time */
93: private $Time = null;
94:
95: /**
96: * File-Location
97: *
98: * @param null|string $Location
99: *
100: * @return null|string
101: */
102: public function Location( $Location = null ) {
103: if( $Location !== null ) {
104: $this->Location = $this->UpdateSyntax( $Location );
105: } return $this->Location;
106: }
107:
108: /**
109: * File-Name
110: *
111: * @param string|null $Name
112: *
113: * @return string|null
114: */
115: public function Name( $Name = null ) {
116: if( $Name !== null ) {
117: $this->Name = $Name;
118: } return $this->Name;
119: }
120:
121: /**
122: * File-Extension
123: *
124: * @param string|null $Extension
125: *
126: * @return string|null
127: */
128: public function Extension( $Extension = null ) {
129: if( $Extension !== null ) {
130: $this->Extension = $Extension;
131: } return $this->Extension;
132: }
133:
134: /**
135: * File-Path
136: *
137: * @param string|null $Path
138: *
139: * @return string|null
140: */
141: public function Path( $Path = null ) {
142: if( $Path !== null ) {
143: $this->Path = $this->UpdateSyntax( $Path );
144: } return $this->Path;
145: }
146:
147: /**
148: * File-Size
149: *
150: * @param int|null $Size
151: *
152: * @return int|null
153: */
154: public function Size( $Size = null ) {
155: if( $Size !== null ) {
156: $this->Size = $Size;
157: } return $this->Size;
158: }
159:
160: /**
161: * File-Timestamp
162: *
163: * @param int|null $Time
164: *
165: * @return int|null
166: */
167: public function Time( $Time = null ) {
168: if( $Time !== null ) {
169: $this->Time = $Time;
170: } return $this->Time;
171: }
172:
173: /**
174: * File-Changed
175: *
176: * @param null|bool $Toggle
177: *
178: * @return bool
179: */
180: public function Changed( $Toggle = null ) {
181: if( $Toggle !== null ) {
182: $this->Changed = $Toggle;
183: } return $this->Changed;
184: }
185:
186: /**
187: * Read File-Properties
188: */
189: protected function UpdateProperties() {
190: $this->Name( pathinfo( $this->Location(), PATHINFO_FILENAME ) );
191: $this->Extension( pathinfo( $this->Location(), PATHINFO_EXTENSION ) );
192: $this->Path( pathinfo( $this->Location(), PATHINFO_DIRNAME ) );
193: if( file_exists( $this->Location() ) ) {
194: $this->Size( filesize( $this->Location() ) );
195: $this->Time( filemtime( $this->Location() ) );
196: }
197: }
198:
199: /**
200: * Correct Path-Syntax
201: *
202: * @param string $Path
203: *
204: * @return string
205: */
206: protected function UpdateSyntax( $Path ) {
207: return rtrim( preg_replace( '![\\\/]+!', DIRECTORY_SEPARATOR, $Path ), '\\/' );
208: }
209:
210: }
211: