CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 1.2 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 1.2
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Classes

  • AclBase
  • AclBehavior
  • AclComponent
  • AclNode
  • AclShell
  • Aco
  • AcoAction
  • AjaxHelper
  • ApcEngine
  • ApiShell
  • App
  • AppController
  • AppHelper
  • AppModel
  • Aro
  • AuthComponent
  • BakeShell
  • BehaviorCollection
  • Cache
  • CacheEngine
  • CacheHelper
  • CakeErrorController
  • CakeLog
  • CakeSchema
  • CakeSession
  • CakeSocket
  • ClassRegistry
  • Component
  • Configure
  • ConnectionManager
  • ConsoleShell
  • ContainableBehavior
  • Controller
  • ControllerTask
  • CookieComponent
  • DataSource
  • DbAcl
  • DbAclSchema
  • DbConfigTask
  • DboAdodb
  • DboDb2
  • DboFirebird
  • DboMssql
  • DboMysql
  • DboMysqlBase
  • DboMysqli
  • DboOdbc
  • DboOracle
  • DboPostgres
  • DboSource
  • DboSqlite
  • DboSybase
  • Debugger
  • EmailComponent
  • ErrorHandler
  • ExtractTask
  • File
  • FileEngine
  • Flay
  • Folder
  • FormHelper
  • Helper
  • HtmlHelper
  • HttpSocket
  • I18n
  • I18nModel
  • i18nSchema
  • I18nShell
  • Inflector
  • IniAcl
  • JavascriptHelper
  • JsHelper
  • JsHelperObject
  • L10n
  • MagicDb
  • MagicFileResource
  • MediaView
  • MemcacheEngine
  • Model
  • ModelBehavior
  • ModelTask
  • Multibyte
  • NumberHelper
  • Object
  • Overloadable
  • Overloadable2
  • PagesController
  • PaginatorHelper
  • Permission
  • PluginTask
  • ProjectTask
  • RequestHandlerComponent
  • Router
  • RssHelper
  • Sanitize
  • Scaffold
  • ScaffoldView
  • SchemaShell
  • Security
  • SecurityComponent
  • SessionComponent
  • SessionHelper
  • SessionsSchema
  • Set
  • Shell
  • String
  • TestSuiteShell
  • TestTask
  • TextHelper
  • ThemeView
  • TimeHelper
  • TranslateBehavior
  • TreeBehavior
  • Validation
  • View
  • ViewTask
  • XcacheEngine
  • Xml
  • XmlElement
  • XmlHelper
  • XmlManager
  • XmlNode
  • XmlTextNode

Functions

  • __enclose
  • make_clean_css
  • mb_encode_mimeheader
  • mb_stripos
  • mb_stristr
  • mb_strlen
  • mb_strpos
  • mb_strrchr
  • mb_strrichr
  • mb_strripos
  • mb_strrpos
  • mb_strstr
  • mb_strtolower
  • mb_strtoupper
  • mb_substr
  • mb_substr_count
  • write_css_cache
  1: <?php
  2: /* SVN FILE: $Id$ */
  3: /**
  4:  * MagicDb parser and file analyzer
  5:  *
  6:  * PHP versions 4 and 5
  7:  *
  8:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  9:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 10:  *
 11:  * Licensed under The MIT License
 12:  * Redistributions of files must retain the above copyright notice.
 13:  *
 14:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 15:  * @link          http://cakephp.org CakePHP(tm) Project
 16:  * @package       cake
 17:  * @subpackage    cake.cake.libs
 18:  * @since         CakePHP(tm) v 1.2.0
 19:  * @version       $Revision$
 20:  * @modifiedby    $LastChangedBy$
 21:  * @lastmodified  $Date$
 22:  * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 23:  */
 24: if (!class_exists('File')) {
 25:     uses('object', 'file');
 26: }
 27: /**
 28:  * A class to parse and use the MagicDb for file type analysis
 29:  *
 30:  * @package       cake.tests
 31:  * @subpackage    cake.tests.cases.libs
 32:  */
 33: class MagicDb extends Object {
 34: /**
 35:  * Holds the parsed MagicDb for this class instance
 36:  *
 37:  * @var array
 38:  **/
 39:     var $db = array();
 40: 
 41: /**
 42:  * Reads a MagicDb from various formats
 43:  *
 44:  * @var $magicDb mixed Can be an array containing the db, a magic db as a string, or a filename pointing to a magic db in .db or magic.db.php format
 45:  * @return boolean Returns false if reading / validation failed or true on success.
 46:  * @author        Felix
 47:  **/
 48:     function read($magicDb = null) {
 49:         if (!is_string($magicDb) && !is_array($magicDb)) {
 50:             return false;
 51:         }
 52:         if (is_array($magicDb) || strpos($magicDb, '# FILE_ID DB') === 0) {
 53:             $data = $magicDb;
 54:         } else {
 55:             $File =& new File($magicDb);
 56:             if (!$File->exists()) {
 57:                 return false;
 58:             }
 59:             if ($File->ext() == 'php') {
 60:                 include($File->pwd());
 61:                 $data = $magicDb;
 62:             } else {
 63:                 // @TODO: Needs test coverage
 64:                 $data = $File->read();
 65:             }
 66:         }
 67: 
 68:         $magicDb = $this->toArray($data);
 69:         if (!$this->validates($magicDb)) {
 70:             return false;
 71:         }
 72:         return !!($this->db = $magicDb);
 73:     }
 74: 
 75: /**
 76:  * Parses a MagicDb $data string into an array or returns the current MagicDb instance as an array
 77:  *
 78:  * @param string $data A MagicDb string to turn into an array
 79:  * @return array A parsed MagicDb array or an empty array if the $data param was invalid. Returns the db property if $data is not set.
 80:  * @access public
 81:  */
 82:     function toArray($data = null) {
 83:         if (is_array($data)) {
 84:             return $data;
 85:         }
 86:         if ($data === null) {
 87:             return $this->db;
 88:         }
 89: 
 90:         if (strpos($data, '# FILE_ID DB') !== 0) {
 91:             return array();
 92:         }
 93: 
 94:         $lines = explode("\r\n", $data);
 95:         $db = array();
 96: 
 97:         $validHeader = count($lines) > 3
 98:                     && preg_match('/^# Date:([0-9]{4}-[0-9]{2}-[0-9]{2})$/', $lines[1], $date)
 99:                     && preg_match('/^# Source:(.+)$/', $lines[2], $source)
100:                     && strlen($lines[3]) == 0;
101:         if (!$validHeader) {
102:             return $db;
103:         }
104: 
105:         $db = array('header' => array('Date' => $date[1], 'Source' => $source[1]), 'database' => array());
106:         $lines = array_splice($lines, 3);
107: 
108:         $format = array();
109:         while (!empty($lines)) {
110:             $line = array_shift($lines);
111:             if (isset($line[0]) && $line[0] == '#' || empty($line)) {
112:                 continue;
113:             }
114: 
115:             $columns = explode("\t", $line);
116:             if (in_array($columns[0]{0}, array('>', '&'))) {
117:                 $format[] = $columns;
118:             } elseif (!empty($format)) {
119:                 $db['database'][] = $format;
120:                 $format = array($columns);
121:             } else {
122:                 $format = array($columns);
123:             }
124:         }
125: 
126:         return $db;
127:     }
128: 
129: /**
130:  * Returns true if the MagicDb instance or the passed $magicDb is valid
131:  *
132:  * @param mixed $magicDb A $magicDb string / array to validate (optional)
133:  * @return boolean True if the $magicDb / instance db validates, false if not
134:  * @access public
135:  */
136:     function validates($magicDb = null) {
137:         if (is_null($magicDb)) {
138:             $magicDb = $this->db;
139:         } elseif (!is_array($magicDb)) {
140:             $magicDb = $this->toArray($magicDb);
141:         }
142: 
143:         return isset($magicDb['header'], $magicDb['database']) && is_array($magicDb['header']) && is_array($magicDb['database']);
144:     }
145: 
146: /**
147:  * Analyzes a given $file using the currently loaded MagicDb information based on the desired $options
148:  *
149:  * @param string $file Absolute path to the file to analyze
150:  * @param array $options TBT
151:  * @return mixed
152:  * @access public
153:  */
154:     function analyze($file, $options = array()) {
155:         if (!is_string($file)) {
156:             return false;
157:         }
158: 
159:         $matches = array();
160:         $MagicFileResource =& new MagicFileResource($file);
161:         foreach ($this->db['database'] as $format) {
162:             $magic = $format[0];
163:             $match = $MagicFileResource->test($magic);
164:             if ($match === false) {
165:                 continue;
166:             }
167:             $matches[] = $magic;
168:         }
169: 
170:         return $matches;
171:     }
172: }
173: 
174: /**
175:  * undocumented class
176:  *
177:  * @package       cake.tests
178:  * @subpackage    cake.tests.cases.libs
179:  */
180: class MagicFileResource extends Object{
181: /**
182:  * undocumented variable
183:  *
184:  * @var unknown
185:  * @access public
186:  */
187:     var $resource = null;
188: /**
189:  * undocumented variable
190:  *
191:  * @var unknown
192:  * @access public
193:  */
194:     var $offset = 0;
195: /**
196:  * undocumented function
197:  *
198:  * @param unknown $file
199:  * @return void
200:  * @access public
201:  */
202:     function __construct($file) {
203:         if (file_exists($file)) {
204:             $this->resource =& new File($file);
205:         } else {
206:             $this->resource = $file;
207:         }
208:     }
209: /**
210:  * undocumented function
211:  *
212:  * @param unknown $magic
213:  * @return void
214:  * @access public
215:  */
216:     function test($magic) {
217:         $offset = null;
218:         $type = null;
219:         $expected = null;
220:         $comment = null;
221:         if (isset($magic[0])) {
222:             $offset = $magic[0];
223:         }
224:         if (isset($magic[1])) {
225:             $type = $magic[1];
226:         }
227:         if (isset($magic[2])) {
228:             $expected = $magic[2];
229:         }
230:         if (isset($magic[3])) {
231:             $comment = $magic[3];
232:         }
233:         $val = $this->extract($offset, $type, $expected);
234:         return $val == $expected;
235:     }
236: /**
237:  * undocumented function
238:  *
239:  * @param unknown $type
240:  * @param unknown $length
241:  * @return void
242:  * @access public
243:  */
244:     function read($length = null) {
245:         if (!is_object($this->resource)) {
246:             return substr($this->resource, $this->offset, $length);
247:         }
248:         return $this->resource->read($length);
249:     }
250: /**
251:  * undocumented function
252:  *
253:  * @param unknown $type
254:  * @param unknown $expected
255:  * @return void
256:  * @access public
257:  */
258:     function extract($offset, $type, $expected) {
259:         switch ($type) {
260:             case 'string':
261:                 $this->offset($offset);
262:                 $val = $this->read(strlen($expected));
263:                 if ($val === $expected) {
264:                     return true;
265:                 }
266:                 break;
267:         }
268:     }
269: /**
270:  * undocumented function
271:  *
272:  * @param unknown $offset
273:  * @param unknown $whence
274:  * @return void
275:  * @access public
276:  */
277:     function offset($offset = null) {
278:         if (is_null($offset)) {
279:             if (!is_object($this->resource)) {
280:                 return $this->offset;
281:             }
282:             return $this->offset;
283:         }
284: 
285:         if (!ctype_digit($offset)) {
286:             return false;
287:         }
288:         if (is_object($this->resource)) {
289:             $this->resource->offset($offset);
290:         } else {
291:             $this->offset = $offset;
292:         }
293:     }
294: }
295: 
296: ?>
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs