Complex classes like File 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 File, and based on these observations, apply Extract Interface, too.
| 1 | <?php | ||
| 69 | class File extends DataObject implements ShortcodeHandler, AssetContainer, Thumbnail, CMSPreviewable { | ||
| 70 | |||
| 71 | use ImageManipulation; | ||
| 72 | |||
| 73 | private static $default_sort = "\"Name\""; | ||
| 74 | |||
| 75 | private static $singular_name = "File"; | ||
| 76 | |||
| 77 | private static $plural_name = "Files"; | ||
| 78 | |||
| 79 | /** | ||
| 80 | * Permissions necessary to view files outside of the live stage (e.g. archive / draft stage). | ||
| 81 | * | ||
| 82 | * @config | ||
| 83 | * @var array | ||
| 84 | */ | ||
| 85 | 	private static $non_live_permissions = array('CMS_ACCESS_LeftAndMain', 'CMS_ACCESS_AssetAdmin', 'VIEW_DRAFT_CONTENT'); | ||
| 86 | |||
| 87 | private static $db = array( | ||
| 88 | "Name" => "Varchar(255)", | ||
| 89 | "Title" => "Varchar(255)", | ||
| 90 | "File" =>"DBFile", | ||
| 91 | // Only applies to files, doesn't inherit for folder | ||
| 92 | 'ShowInSearch' => 'Boolean(1)', | ||
| 93 | ); | ||
| 94 | |||
| 95 | private static $has_one = array( | ||
| 96 | "Parent" => "File", | ||
| 97 | "Owner" => "Member" | ||
| 98 | ); | ||
| 99 | |||
| 100 | private static $defaults = array( | ||
| 101 | "ShowInSearch" => 1, | ||
| 102 | ); | ||
| 103 | |||
| 104 | private static $extensions = array( | ||
| 105 | "Hierarchy", | ||
| 106 | "Versioned" | ||
| 107 | ); | ||
| 108 | |||
| 109 | private static $casting = array ( | ||
| 110 | 'TreeTitle' => 'HTMLText' | ||
| 111 | ); | ||
| 112 | |||
| 113 | /** | ||
| 114 | * @config | ||
| 115 | 	 * @var array List of allowed file extensions, enforced through {@link validate()}. | ||
| 116 | * | ||
| 117 | * Note: if you modify this, you should also change a configuration file in the assets directory. | ||
| 118 | * Otherwise, the files will be able to be uploaded but they won't be able to be served by the | ||
| 119 | * webserver. | ||
| 120 | * | ||
| 121 | * - If you are running Apache you will need to change assets/.htaccess | ||
| 122 | * - If you are running IIS you will need to change assets/web.config | ||
| 123 | * | ||
| 124 | * Instructions for the change you need to make are included in a comment in the config file. | ||
| 125 | */ | ||
| 126 | private static $allowed_extensions = array( | ||
| 127 | '', 'ace', 'arc', 'arj', 'asf', 'au', 'avi', 'bmp', 'bz2', 'cab', 'cda', 'css', 'csv', 'dmg', 'doc', | ||
| 128 | 'docx', 'dotx', 'dotm', 'flv', 'gif', 'gpx', 'gz', 'hqx', 'ico', 'jar', 'jpeg', 'jpg', 'js', 'kml', | ||
| 129 | 'm4a', 'm4v', 'mid', 'midi', 'mkv', 'mov', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'ogg', 'ogv', 'pages', | ||
| 130 | 'pcx', 'pdf', 'png', 'pps', 'ppt', 'pptx', 'potx', 'potm', 'ra', 'ram', 'rm', 'rtf', 'sit', 'sitx', | ||
| 131 | 'tar', 'tgz', 'tif', 'tiff', 'txt', 'wav', 'webm', 'wma', 'wmv', 'xls', 'xlsx', 'xltx', 'xltm', 'zip', | ||
| 132 | 'zipx', | ||
| 133 | ); | ||
| 134 | |||
| 135 | /** | ||
| 136 | * @config | ||
| 137 | * @var array Category identifiers mapped to commonly used extensions. | ||
| 138 | */ | ||
| 139 | private static $app_categories = array( | ||
| 140 | 'archive' => array( | ||
| 141 | 'ace', 'arc', 'arj', 'bz', 'bz2', 'cab', 'dmg', 'gz', 'hqx', 'jar', 'rar', 'sit', 'sitx', 'tar', 'tgz', | ||
| 142 | 'zip', 'zipx', | ||
| 143 | ), | ||
| 144 | 'audio' => array( | ||
| 145 | 'aif', 'aifc', 'aiff', 'apl', 'au', 'avr', 'cda', 'm4a', 'mid', 'midi', 'mp3', 'ogg', 'ra', | ||
| 146 | 'ram', 'rm', 'snd', 'wav', 'wma', | ||
| 147 | ), | ||
| 148 | 'document' => array( | ||
| 149 | 'css', 'csv', 'doc', 'docx', 'dotm', 'dotx', 'htm', 'html', 'gpx', 'js', 'kml', 'pages', 'pdf', | ||
| 150 | 'potm', 'potx', 'pps', 'ppt', 'pptx', 'rtf', 'txt', 'xhtml', 'xls', 'xlsx', 'xltm', 'xltx', 'xml', | ||
| 151 | ), | ||
| 152 | 'image' => array( | ||
| 153 | 'alpha', 'als', 'bmp', 'cel', 'gif', 'ico', 'icon', 'jpeg', 'jpg', 'pcx', 'png', 'ps', 'tif', 'tiff', | ||
| 154 | ), | ||
| 155 | 'image/supported' => array( | ||
| 156 | 'gif', 'jpeg', 'jpg', 'png' | ||
| 157 | ), | ||
| 158 | 'flash' => array( | ||
| 159 | 'fla', 'swf' | ||
| 160 | ), | ||
| 161 | 'video' => array( | ||
| 162 | 'asf', 'avi', 'flv', 'ifo', 'm1v', 'm2v', 'm4v', 'mkv', 'mov', 'mp2', 'mp4', 'mpa', 'mpe', 'mpeg', | ||
| 163 | 'mpg', 'ogv', 'qt', 'vob', 'webm', 'wmv', | ||
| 164 | ), | ||
| 165 | ); | ||
| 166 | |||
| 167 | /** | ||
| 168 | * Map of file extensions to class type | ||
| 169 | * | ||
| 170 | * @config | ||
| 171 | * @var | ||
| 172 | */ | ||
| 173 | private static $class_for_file_extension = array( | ||
| 174 | '*' => 'File', | ||
| 175 | 'jpg' => 'Image', | ||
| 176 | 'jpeg' => 'Image', | ||
| 177 | 'png' => 'Image', | ||
| 178 | 'gif' => 'Image', | ||
| 179 | ); | ||
| 180 | |||
| 181 | /** | ||
| 182 | * @config | ||
| 183 | 	 * @var If this is true, then restrictions set in {@link $allowed_max_file_size} and | ||
| 184 | 	 * {@link $allowed_extensions} will be applied to users with admin privileges as | ||
| 185 | * well. | ||
| 186 | */ | ||
| 187 | private static $apply_restrictions_to_admin = true; | ||
| 188 | |||
| 189 | /** | ||
| 190 | * If enabled, legacy file dataobjects will be automatically imported into the APL | ||
| 191 | * | ||
| 192 | * @config | ||
| 193 | * @var bool | ||
| 194 | */ | ||
| 195 | private static $migrate_legacy_file = false; | ||
| 196 | |||
| 197 | /** | ||
| 198 | * @config | ||
| 199 | * @var boolean | ||
| 200 | */ | ||
| 201 | private static $update_filesystem = true; | ||
| 202 | |||
| 203 | 	public static function get_shortcodes() { | ||
| 204 | return 'file_link'; | ||
| 205 | } | ||
| 206 | |||
| 207 | /** | ||
| 208 | * Replace "[file_link id=n]" shortcode with an anchor tag or link to the file. | ||
| 209 | * | ||
| 210 | * @param array $arguments Arguments passed to the parser | ||
| 211 | * @param string $content Raw shortcode | ||
| 212 | * @param ShortcodeParser $parser Parser | ||
| 213 | * @param string $shortcode Name of shortcode used to register this handler | ||
| 214 | * @param array $extra Extra arguments | ||
| 215 | * @return string Result of the handled shortcode | ||
| 216 | */ | ||
| 217 | 	public static function handle_shortcode($arguments, $content, $parser, $shortcode, $extra = array()) { | ||
| 218 | // Find appropriate record, with fallback for error handlers | ||
| 219 | $record = static::find_shortcode_record($arguments, $errorCode); | ||
| 220 | 		if($errorCode) { | ||
|  | |||
| 221 | $record = static::find_error_record($errorCode); | ||
| 222 | } | ||
| 223 | 		if (!$record) { | ||
| 224 | return null; // There were no suitable matches at all. | ||
| 225 | } | ||
| 226 | |||
| 227 | // build the HTML tag | ||
| 228 | 		if($content) { | ||
| 229 | // build some useful meta-data (file type and size) as data attributes | ||
| 230 | $attrs = ' '; | ||
| 231 | 			if($record instanceof File) { | ||
| 232 | foreach(array( | ||
| 233 | 'class' => 'file', | ||
| 234 | 'data-type' => $record->getExtension(), | ||
| 235 | 'data-size' => $record->getSize() | ||
| 236 | 				) as $name => $value) { | ||
| 237 | 					$attrs .= sprintf('%s="%s" ', $name, $value); | ||
| 238 | } | ||
| 239 | } | ||
| 240 | |||
| 241 | 			return sprintf('<a href="%s"%s>%s</a>', $record->Link(), rtrim($attrs), $parser->parse($content)); | ||
| 242 | 		} else { | ||
| 243 | return $record->Link(); | ||
| 244 | } | ||
| 245 | } | ||
| 246 | |||
| 247 | /** | ||
| 248 | * Find the record to use for a given shortcode. | ||
| 249 | * | ||
| 250 | * @param array $args Array of input shortcode arguments | ||
| 251 | * @param int $errorCode If the file is not found, or is inaccessible, this will be assigned to a HTTP error code. | ||
| 252 | * @return File|null The File DataObject, if it can be found. | ||
| 253 | */ | ||
| 254 | 	public static function find_shortcode_record($args, &$errorCode = null) { | ||
| 255 | // Validate shortcode | ||
| 256 | 		if(!isset($args['id']) || !is_numeric($args['id'])) { | ||
| 257 | return null; | ||
| 258 | } | ||
| 259 | |||
| 260 | // Check if the file is found | ||
| 261 | $file = File::get()->byID($args['id']); | ||
| 262 | 		if (!$file) { | ||
| 263 | $errorCode = 404; | ||
| 264 | return null; | ||
| 265 | } | ||
| 266 | |||
| 267 | // Check if the file is viewable | ||
| 268 | 		if(!$file->canView()) { | ||
| 269 | $errorCode = 403; | ||
| 270 | return null; | ||
| 271 | } | ||
| 272 | |||
| 273 | // Success | ||
| 274 | return $file; | ||
| 275 | } | ||
| 276 | |||
| 277 | /** | ||
| 278 | * Given a HTTP Error, find an appropriate substitute File or SiteTree data object instance. | ||
| 279 | * | ||
| 280 | * @param int $errorCode HTTP Error value | ||
| 281 | * @return File|SiteTree File or SiteTree object to use for the given error | ||
| 282 | */ | ||
| 283 | 	protected static function find_error_record($errorCode) { | ||
| 284 | 		$result = static::singleton()->invokeWithExtensions('getErrorRecordFor', $errorCode); | ||
| 285 | $result = array_filter($result); | ||
| 286 | 		if($result) { | ||
| 287 | return reset($result); | ||
| 288 | } | ||
| 289 | return null; | ||
| 290 | } | ||
| 291 | |||
| 292 | /** | ||
| 293 | * A file only exists if the file_exists() and is in the DB as a record | ||
| 294 | * | ||
| 295 | * Use $file->isInDB() to only check for a DB record | ||
| 296 | * Use $file->File->exists() to only check if the asset exists | ||
| 297 | * | ||
| 298 | * @return bool | ||
| 299 | */ | ||
| 300 | 	public function exists() { | ||
| 303 | |||
| 304 | /** | ||
| 305 | * Find a File object by the given filename. | ||
| 306 | * | ||
| 307 | * @param string $filename Filename to search for, including any custom parent directories. | ||
| 308 | * @return File | ||
| 309 | */ | ||
| 310 | 	public static function find($filename) { | ||
| 326 | |||
| 327 | /** | ||
| 328 | * Just an alias function to keep a consistent API with SiteTree | ||
| 329 | * | ||
| 330 | * @return string The link to the file | ||
| 331 | */ | ||
| 332 | 	public function Link() { | ||
| 335 | |||
| 336 | /** | ||
| 337 | * @deprecated 4.0 | ||
| 338 | */ | ||
| 339 | 	public function RelativeLink() { | ||
| 343 | |||
| 344 | /** | ||
| 345 | * Just an alias function to keep a consistent API with SiteTree | ||
| 346 | * | ||
| 347 | * @return string The absolute link to the file | ||
| 348 | */ | ||
| 349 | 	public function AbsoluteLink() { | ||
| 352 | |||
| 353 | /** | ||
| 354 | * @return string | ||
| 355 | */ | ||
| 356 | 	public function getTreeTitle() { | ||
| 359 | |||
| 360 | /** | ||
| 361 | * @param Member $member | ||
| 362 | * @return bool | ||
| 363 | */ | ||
| 364 | 	public function canView($member = null) { | ||
| 376 | |||
| 377 | /** | ||
| 378 | * Check if this file can be modified | ||
| 379 | * | ||
| 380 | * @param Member $member | ||
| 381 | * @return boolean | ||
| 382 | */ | ||
| 383 | 	public function canEdit($member = null) { | ||
| 395 | |||
| 396 | /** | ||
| 397 | * Check if a file can be created | ||
| 398 | * | ||
| 399 | * @param Member $member | ||
| 400 | * @param array $context | ||
| 401 | * @return boolean | ||
| 402 | */ | ||
| 403 | 	public function canCreate($member = null, $context = array()) { | ||
| 415 | |||
| 416 | /** | ||
| 417 | * Check if this file can be deleted | ||
| 418 | * | ||
| 419 | * @param Member $member | ||
| 420 | * @return boolean | ||
| 421 | */ | ||
| 422 | 	public function canDelete($member = null) { | ||
| 434 | |||
| 435 | /** | ||
| 436 | * Returns the fields to power the edit screen of files in the CMS. | ||
| 437 | 	 * You can modify this FieldList by subclassing folder, or by creating a {@link DataExtension} | ||
| 438 | * and implemeting updateCMSFields(FieldList $fields) on that extension. | ||
| 439 | * | ||
| 440 | * @return FieldList | ||
| 441 | */ | ||
| 442 | 	public function getCMSFields() { | ||
| 485 | |||
| 486 | /** | ||
| 487 | * Returns a category based on the file extension. | ||
| 488 | * This can be useful when grouping files by type, | ||
| 489 | * showing icons on filelinks, etc. | ||
| 490 | * Possible group values are: "audio", "mov", "zip", "image". | ||
| 491 | * | ||
| 492 | * @param string $ext Extension to check | ||
| 493 | * @return string | ||
| 494 | */ | ||
| 495 | 	public static function get_app_category($ext) { | ||
| 502 | |||
| 503 | /** | ||
| 504 | * For a category or list of categories, get the list of file extensions | ||
| 505 | * | ||
| 506 | * @param array|string $categories List of categories, or single category | ||
| 507 | * @return array | ||
| 508 | */ | ||
| 509 | 	public static function get_category_extensions($categories) { | ||
| 537 | |||
| 538 | /** | ||
| 539 | * Returns a category based on the file extension. | ||
| 540 | * | ||
| 541 | * @return string | ||
| 542 | */ | ||
| 543 | 	public function appCategory() { | ||
| 546 | |||
| 547 | |||
| 548 | /** | ||
| 549 | * Should be called after the file was uploaded | ||
| 550 | */ | ||
| 551 | 	public function onAfterUpload() { | ||
| 554 | |||
| 555 | /** | ||
| 556 | * Make sure the file has a name | ||
| 557 | */ | ||
| 558 | 	protected function onBeforeWrite() { | ||
| 574 | |||
| 575 | /** | ||
| 576 | * This will check if the parent record and/or name do not match the name on the underlying | ||
| 577 | * DBFile record, and if so, copy this file to the new location, and update the record to | ||
| 578 | * point to this new file. | ||
| 579 | * | ||
| 580 | 	 * This method will update the File {@see DBFile} field value on success, so it must be called | ||
| 581 | * before writing to the database | ||
| 582 | * | ||
| 583 | * @return bool True if changed | ||
| 584 | */ | ||
| 585 | 	public function updateFilesystem() { | ||
| 586 | 		if(!$this->config()->update_filesystem) { | ||
| 587 | return false; | ||
| 588 | } | ||
| 589 | |||
| 590 | // Check the file exists | ||
| 591 | 		if(!$this->File->exists()) { | ||
| 592 | return false; | ||
| 593 | } | ||
| 594 | |||
| 595 | // Avoid moving files on live; Rely on this being done on stage prior to publish. | ||
| 596 | 		if(Versioned::get_stage() !== Versioned::DRAFT) { | ||
| 597 | return false; | ||
| 598 | } | ||
| 599 | |||
| 600 | // Check path updated record will point to | ||
| 601 | // If no changes necessary, skip | ||
| 602 | $pathBefore = $this->File->getFilename(); | ||
| 603 | $pathAfter = $this->generateFilename(); | ||
| 604 | 		if($pathAfter === $pathBefore) { | ||
| 605 | return false; | ||
| 606 | } | ||
| 607 | |||
| 608 | // Copy record to new location via stream | ||
| 609 | $stream = $this->File->getStream(); | ||
| 610 | $this->File->setFromStream($stream, $pathAfter); | ||
| 611 | return true; | ||
| 612 | } | ||
| 613 | |||
| 614 | /** | ||
| 615 | * Collate selected descendants of this page. | ||
| 616 | * $condition will be evaluated on each descendant, and if it is succeeds, that item will be added | ||
| 617 | * to the $collator array. | ||
| 618 | * | ||
| 619 | * @param string $condition The PHP condition to be evaluated. The page will be called $item | ||
| 620 | * @param array $collator An array, passed by reference, to collect all of the matching descendants. | ||
| 621 | * @return true|null | ||
| 622 | */ | ||
| 623 | 	public function collateDescendants($condition, &$collator) { | ||
| 632 | |||
| 633 | /** | ||
| 634 | * Setter function for Name. Automatically sets a default title, | ||
| 635 | * and removes characters that might be invalid on the filesystem. | ||
| 636 | * Also adds a suffix to the name if the filename already exists | ||
| 637 | 	 * on the filesystem, and is associated to a different {@link File} database record | ||
| 638 | * in the same folder. This means "myfile.jpg" might become "myfile-1.jpg". | ||
| 639 | * | ||
| 640 | 	 * Does not change the filesystem itself, please use {@link write()} for this. | ||
| 641 | * | ||
| 642 | * @param string $name | ||
| 643 | * @return $this | ||
| 644 | */ | ||
| 645 | 	public function setName($name) { | ||
| 690 | |||
| 691 | /** | ||
| 692 | * Gets the URL of this file | ||
| 693 | * | ||
| 694 | * @return string | ||
| 695 | */ | ||
| 696 | 	public function getAbsoluteURL() { | ||
| 702 | |||
| 703 | /** | ||
| 704 | * Gets the URL of this file | ||
| 705 | * | ||
| 706 | * @uses Director::baseURL() | ||
| 707 | * @param bool $grant Ensures that the url for any protected assets is granted for the current user. | ||
| 708 | * @return string | ||
| 709 | */ | ||
| 710 | 	public function getURL($grant = true) { | ||
| 715 | |||
| 716 | /** | ||
| 717 | * Get URL, but without resampling. | ||
| 718 | * | ||
| 719 | * @param bool $grant Ensures that the url for any protected assets is granted for the current user. | ||
| 720 | * @return string | ||
| 721 | */ | ||
| 722 | 	public function getSourceURL($grant = true) { | ||
| 727 | |||
| 728 | /** | ||
| 729 | * @todo Coupling with cms module, remove this method. | ||
| 730 | * | ||
| 731 | * @return string | ||
| 732 | */ | ||
| 733 | 	public function DeleteLink() { | ||
| 736 | |||
| 737 | /** | ||
| 738 | * Get expected value of Filename tuple value. Will be used to trigger | ||
| 739 | * a file move on draft stage. | ||
| 740 | * | ||
| 741 | * @return string | ||
| 742 | */ | ||
| 743 | 	public function generateFilename() { | ||
| 751 | |||
| 752 | /** | ||
| 753 | * Ensure that parent folders are published before this one is published | ||
| 754 | * | ||
| 755 | * @todo Solve this via triggered publishing / ownership in the future | ||
| 756 | */ | ||
| 757 | 	public function onBeforePublish() { | ||
| 764 | |||
| 765 | /** | ||
| 766 | * Update the ParentID and Name for the given filename. | ||
| 767 | * | ||
| 768 | * On save, the underlying DBFile record will move the underlying file to this location. | ||
| 769 | * Thus it will not update the underlying Filename value until this is done. | ||
| 770 | * | ||
| 771 | * @param string $filename | ||
| 772 | * @return $this | ||
| 773 | */ | ||
| 774 | 	public function setFilename($filename) { | ||
| 797 | |||
| 798 | /** | ||
| 799 | * Returns the file extension | ||
| 800 | * | ||
| 801 | * @return string | ||
| 802 | */ | ||
| 803 | 	public function getExtension() { | ||
| 806 | |||
| 807 | /** | ||
| 808 | * Gets the extension of a filepath or filename, | ||
| 809 | * by stripping away everything before the last "dot". | ||
| 810 | * Caution: Only returns the last extension in "double-barrelled" | ||
| 811 | * extensions (e.g. "gz" for "tar.gz"). | ||
| 812 | * | ||
| 813 | * Examples: | ||
| 814 | * - "myfile" returns "" | ||
| 815 | * - "myfile.txt" returns "txt" | ||
| 816 | * - "myfile.tar.gz" returns "gz" | ||
| 817 | * | ||
| 818 | * @param string $filename | ||
| 819 | * @return string | ||
| 820 | */ | ||
| 821 | 	public static function get_file_extension($filename) { | ||
| 824 | |||
| 825 | /** | ||
| 826 | * Given an extension, determine the icon that should be used | ||
| 827 | * | ||
| 828 | * @param string $extension | ||
| 829 | * @return string Icon filename relative to base url | ||
| 830 | */ | ||
| 831 | 	public static function get_icon_for_extension($extension) { | ||
| 846 | |||
| 847 | /** | ||
| 848 | * Return the type of file for the given extension | ||
| 849 | * on the current file name. | ||
| 850 | * | ||
| 851 | * @return string | ||
| 852 | */ | ||
| 853 | 	public function getFileType() { | ||
| 856 | |||
| 857 | /** | ||
| 858 | * Get descriptive type of file based on filename | ||
| 859 | * | ||
| 860 | * @param string $filename | ||
| 861 | * @return string Description of file | ||
| 862 | */ | ||
| 863 | 	public static function get_file_type($filename) { | ||
| 892 | |||
| 893 | /** | ||
| 894 | * Returns the size of the file type in an appropriate format. | ||
| 895 | * | ||
| 896 | * @return string|false String value, or false if doesn't exist | ||
| 897 | */ | ||
| 898 | 	public function getSize() { | ||
| 905 | |||
| 906 | /** | ||
| 907 | * Formats a file size (eg: (int)42 becomes string '42 bytes') | ||
| 908 | * | ||
| 909 | * @todo unit tests | ||
| 910 | * | ||
| 911 | * @param int $size | ||
| 912 | * @return string | ||
| 913 | */ | ||
| 914 | 	public static function format_size($size) { | ||
| 932 | |||
| 933 | /** | ||
| 934 | * Convert a php.ini value (eg: 512M) to bytes | ||
| 935 | * | ||
| 936 | * @todo unit tests | ||
| 937 | * | ||
| 938 | * @param string $iniValue | ||
| 939 | * @return int | ||
| 940 | */ | ||
| 941 | 	public static function ini2bytes($iniValue) { | ||
| 952 | |||
| 953 | /** | ||
| 954 | * Return file size in bytes. | ||
| 955 | * | ||
| 956 | * @return int | ||
| 957 | */ | ||
| 958 | 	public function getAbsoluteSize(){ | ||
| 961 | |||
| 962 | 	public function validate() { | ||
| 968 | |||
| 969 | /** | ||
| 970 | 	 * Maps a {@link File} subclass to a specific extension. | ||
| 971 | * By default, files with common image extensions will be created | ||
| 972 | 	 * as {@link Image} instead of {@link File} when using | ||
| 973 | 	 * {@link Folder::constructChild}, {@link Folder::addUploadToFolder}), | ||
| 974 | 	 * and the {@link Upload} class (either directly or through {@link FileField}). | ||
| 975 | * For manually instanciated files please use this mapping getter. | ||
| 976 | * | ||
| 977 | * Caution: Changes to mapping doesn't apply to existing file records in the database. | ||
| 978 | 	 * Also doesn't hook into {@link Object::getCustomClass()}. | ||
| 979 | * | ||
| 980 | 	 * @param String File extension, without dot prefix. Use an asterisk ('*') | ||
| 981 | * to specify a generic fallback if no mapping is found for an extension. | ||
| 982 | 	 * @return String Classname for a subclass of {@link File} | ||
| 983 | */ | ||
| 984 | 	public static function get_class_for_file_extension($ext) { | ||
| 988 | |||
| 989 | /** | ||
| 990 | 	 * See {@link get_class_for_file_extension()}. | ||
| 991 | * | ||
| 992 | * @param String|array | ||
| 993 | * @param String | ||
| 994 | */ | ||
| 995 | 	public static function set_class_for_file_extension($exts, $class) { | ||
| 1006 | |||
| 1007 | 	public function getMetaData() { | ||
| 1012 | |||
| 1013 | 	public function getMimeType() { | ||
| 1018 | |||
| 1019 | 	public function getStream() { | ||
| 1024 | |||
| 1025 | 	public function getString() { | ||
| 1030 | |||
| 1031 | 	public function setFromLocalFile($path, $filename = null, $hash = null, $variant = null, $config = array()) { | ||
| 1040 | |||
| 1041 | 	public function setFromStream($stream, $filename, $hash = null, $variant = null, $config = array()) { | ||
| 1050 | |||
| 1051 | 	public function setFromString($data, $filename, $hash = null, $variant = null, $config = array()) { | ||
| 1060 | |||
| 1061 | 	public function getIsImage() { | ||
| 1064 | |||
| 1065 | 	public function getFilename() { | ||
| 1068 | |||
| 1069 | 	public function getHash() { | ||
| 1072 | |||
| 1073 | 	public function getVariant() { | ||
| 1076 | |||
| 1077 | /** | ||
| 1078 | * Return a html5 tag of the appropriate for this file (normally img or a) | ||
| 1079 | * | ||
| 1080 | * @return string | ||
| 1081 | */ | ||
| 1082 | 	public function forTemplate() { | ||
| 1085 | |||
| 1086 | /** | ||
| 1087 | * Return a html5 tag of the appropriate for this file (normally img or a) | ||
| 1088 | * | ||
| 1089 | * @return string | ||
| 1090 | */ | ||
| 1091 | 	public function getTag() { | ||
| 1098 | |||
| 1099 | 	public function requireDefaultRecords() { | ||
| 1112 | |||
| 1113 | /** | ||
| 1114 | * Joins one or more segments together to build a Filename identifier. | ||
| 1115 | * | ||
| 1116 | * Note that the result will not have a leading slash, and should not be used | ||
| 1117 | * with local file paths. | ||
| 1118 | * | ||
| 1119 | * @param string $part,... Parts | ||
| 1120 | * @return string | ||
| 1121 | */ | ||
| 1122 | 	public static function join_paths() { | ||
| 1138 | |||
| 1139 | 	public function deleteFile() { | ||
| 1142 | |||
| 1143 | 	public function getVisibility() { | ||
| 1146 | |||
| 1147 | 	public function publishFile() { | ||
| 1150 | |||
| 1151 | 	public function protectFile() { | ||
| 1154 | |||
| 1155 | 	public function grantFile() { | ||
| 1158 | |||
| 1159 | 	public function revokeFile() { | ||
| 1162 | |||
| 1163 | 	public function canViewFile() { | ||
| 1166 | |||
| 1167 | 	public function CMSEditLink() { | ||
| 1172 | |||
| 1173 | 	public function PreviewLink($action = null) { | ||
| 1179 | } | ||
| 1180 | 
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: