[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_media 6 * 7 * @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Media\Administrator\Event; 12 13 use Joomla\CMS\Event\AbstractImmutableEvent; 14 15 // phpcs:disable PSR1.Files.SideEffects 16 \defined('_JEXEC') or die; 17 // phpcs:enable PSR1.Files.SideEffects 18 19 /** 20 * Event to validate media items. 21 * 22 * @since 4.1.0 23 */ 24 abstract class AbstractMediaItemValidationEvent extends AbstractImmutableEvent 25 { 26 /** 27 * Validate $item to have all attributes with a valid type. 28 * 29 * Properties validated: 30 * - type: The type can be file or dir 31 * - name: The name of the item 32 * - path: The relative path to the root 33 * - extension: The file extension 34 * - size: The size of the file 35 * - create_date: The date created 36 * - modified_date: The date modified 37 * - mime_type: The mime type 38 * - width: The width, when available 39 * - height: The height, when available 40 * 41 * Properties generated: 42 * - created_date_formatted: DATE_FORMAT_LC5 formatted string based on create_date 43 * - modified_date_formatted: DATE_FORMAT_LC5 formatted string based on modified_date 44 * 45 * @param \stdClass $item The item to set 46 * 47 * @return void 48 * 49 * @since 4.1.0 50 * 51 * @throws \BadMethodCallException 52 */ 53 protected function validate(\stdClass $item): void 54 { 55 // Only "dir" or "file" is allowed 56 if (!isset($item->type) || ($item->type !== 'dir' && $item->type !== 'file')) { 57 throw new \BadMethodCallException("Property 'type' of argument 'item' of event {$this->name} has a wrong item. Valid: 'dir' or 'file'"); 58 } 59 60 // Non empty string 61 if (empty($item->name) || !is_string($item->name)) { 62 throw new \BadMethodCallException("Property 'name' of argument 'item' of event {$this->name} has a wrong item. Valid: non empty string"); 63 } 64 65 // Non empty string 66 if (empty($item->path) || !is_string($item->path)) { 67 throw new \BadMethodCallException("Property 'path' of argument 'item' of event {$this->name} has a wrong item. Valid: non empty string"); 68 } 69 70 // A string 71 if ($item->type === 'file' && (!isset($item->extension) || !is_string($item->extension))) { 72 throw new \BadMethodCallException("Property 'extension' of argument 'item' of event {$this->name} has a wrong item. Valid: string"); 73 } 74 75 // An empty string or an integer 76 if ( 77 !isset($item->size) || 78 (!is_integer($item->size) && !is_string($item->size)) || 79 (is_string($item->size) && $item->size !== '') 80 ) { 81 throw new \BadMethodCallException("Property 'size' of argument 'item' of event {$this->name} has a wrong item. Valid: empty string or integer"); 82 } 83 84 // A string 85 if (!isset($item->mime_type) || !is_string($item->mime_type)) { 86 throw new \BadMethodCallException("Property 'mime_type' of argument 'item' of event {$this->name} has a wrong item. Valid: string"); 87 } 88 89 // An integer 90 if (!isset($item->width) || !is_integer($item->width)) { 91 throw new \BadMethodCallException("Property 'width' of argument 'item' of event {$this->name} has a wrong item. Valid: integer"); 92 } 93 94 // An integer 95 if (!isset($item->height) || !is_integer($item->height)) { 96 throw new \BadMethodCallException("Property 'height' of argument 'item' of event {$this->name} has a wrong item. Valid: integer"); 97 } 98 99 // A string 100 if (!isset($item->create_date) || !is_string($item->create_date)) { 101 throw new \BadMethodCallException("Property 'create_date' of argument 'item' of event {$this->name} has a wrong item. Valid: string"); 102 } 103 104 // A string 105 if (!isset($item->create_date_formatted) || !is_string($item->create_date_formatted)) { 106 throw new \BadMethodCallException("Property 'create_date_formatted' of argument 'item' of event {$this->name} has a wrong item. Valid: string"); 107 } 108 109 // A string 110 if (!isset($item->modified_date) || !is_string($item->modified_date)) { 111 throw new \BadMethodCallException("Property 'modified_date' of argument 'item' of event {$this->name} has a wrong item. Valid: string"); 112 } 113 114 // A string 115 if (!isset($item->modified_date_formatted) || !is_string($item->modified_date_formatted)) { 116 throw new \BadMethodCallException("Property 'modified_date_formatted' of argument 'item' of event {$this->name} has a wrong item. Valid: string"); 117 } 118 } 119 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |