Projekt

Allgemein

Profil

GX-Bug #44633 » Refactored_EmailAttachment_class_in_order_to_work_with_DIR_FS_CATALOG_that_equals_a_slash.patch

Alexandros Tselegidis, 18.12.2015 14:01

Unterschiede anzeigen:

src/GXEngine/Classes/CoreServices/Email/Entities/EmailAttachment.inc.php (revision )
39 39
	 *
40 40
	 * Entity representing an email attachment.
41 41
	 *
42
	 * Update: Added fix for supporting DIR_FS_CATALOG = '/'
43
	 *
42 44
	 * @param AttachmentPathInterface $path (optional)
43 45
	 * @param AttachmentNameInterface $name (optional)
44 46
	 */
45 47
	public function __construct(AttachmentPathInterface $path = null, AttachmentNameInterface $name = null)
46 48
	{
47
		$this->path = str_replace(DIR_FS_CATALOG, '', (string)$path);
49
		$this->path = $this->_convertToRelativePath($path);
48 50
		$this->name = (string)$name;
49 51
	}
50 52
	
......
56 58
	 */
57 59
	public function setPath(AttachmentPathInterface $path)
58 60
	{
59
		$this->path = str_replace(DIR_FS_CATALOG, '', (string)$path);
61
		$this->path = $this->_convertToRelativePath($path);
60 62
	}
61 63
	
62 64
	
63 65
	/**
64 66
	 * Path Getter
65 67
	 *
68
	 * @param bool $absolutePath (optional) Whether to return the absolute path or the relative one.
69
	 * 
66 70
	 * @return AttachmentPathInterface
67 71
	 */
68 72
	public function getPath($absolutePath = true)
......
92 96
	public function getName()
93 97
	{
94 98
		return MainFactory::create('AttachmentName', $this->name);
99
	}
100
	
101
	
102
	/**
103
	 * Convert a path to relative.
104
	 *
105
	 * Due to different server setups this process can be tedious and hard to foresee. The
106
	 * following method contains the convertion logic and must be used in any setter of the class.
107
	 *
108
	 * @param \AttachmentPathInterface $path
109
	 *
110
	 * @return string Returns the converted path.
111
	 */
112
	protected function _convertToRelativePath(AttachmentPathInterface $path = null)
113
	{
114
		if(DIR_FS_CATALOG === '/' && substr((string)$path, 0, 1) === '/')
115
		{
116
			$relativePath = substr((string)$path, 1); // Remove the initial slash.
117
		}
118
		else if(DIR_FS_CATALOG !== '/')
119
		{
120
			$relativePath = str_replace(DIR_FS_CATALOG, '',
121
			                            (string)$path); // Remove the entire DIR_FS_CATALOG from the path.
122
		}
123
		else
124
		{
125
			$relativePath = (string)$path; // Path is already relative.
126
		}
127
		
128
		return $relativePath;
95 129
	}
96 130
}
    (1-1/1)