| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | namespace HDNET\Focuspoint\Service\WizardHandler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use HDNET\Focuspoint\Utility\GlobalUtility; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use TYPO3\CMS\Core\Utility\GeneralUtility; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * Group | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class Group extends AbstractWizardHandler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * The table name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     const TABLE = 'tx_focuspoint_domain_model_filestandalone'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * Check if the handler can handle the current request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @return boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     public function canHandle() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         return $this->getRelativeFilePath() !== null; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * Return the current point | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * @return integer[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     public function getCurrentPoint() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $connection = GlobalUtility::getDatabaseConnection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $row = $connection->exec_SELECTgetSingleRow( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             'uid,focus_point_x,focus_point_y', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             self::TABLE, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             'relative_file_path = ' . $connection->fullQuoteStr($this->getRelativeFilePath(), self::TABLE) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         if ($row === false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             return [0, 0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         return $this->cleanupPosition([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             $row['focus_point_x'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             $row['focus_point_y'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * Set the point (between -100 and 100) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * @param int $x | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * @param int $y | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     public function setCurrentPoint($x, $y) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $connection = GlobalUtility::getDatabaseConnection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $row = $connection->exec_SELECTgetSingleRow( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             'uid', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             self::TABLE, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             'relative_file_path = ' . $connection->fullQuoteStr($this->getRelativeFilePath(), self::TABLE) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $values = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             'focus_point_x' => $x, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             'focus_point_y' => $y, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             'relative_file_path' => $this->getRelativeFilePath() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         if ($row) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             $connection->exec_UPDATEquery(self::TABLE, 'uid=' . $row['uid'], $values); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             $connection->exec_INSERTquery(self::TABLE, $values); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * Get the public URL for the current handler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 84 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |     public function getPublicUrl() | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |         return $this->displayableImageUrl($this->getRelativeFilePath()); | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * get the arguments for same request call | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     public function getArguments() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         $parameter = GeneralUtility::_GET(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         $p = $parameter['P']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             'P' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                 'table' => $p['table'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                 'field' => $p['field'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                 'file' => $p['file'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * get the file name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * @return null|string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     protected function getRelativeFilePath() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         $parameter = GeneralUtility::_GET(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         if (!isset($parameter['P'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         $p = $parameter['P']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         if (!isset($p['table']) || !isset($p['field']) || !isset($p['file'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |             return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         if (!isset($GLOBALS['TCA'][$p['table']])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |             return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         $tableTca = $GLOBALS['TCA'][$p['table']]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         if (!isset($tableTca['columns'][$p['field']])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |             return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         $fieldTca = $tableTca['columns'][$p['field']]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         $uploadFolder = isset($fieldTca['config']['uploadfolder']) ? $fieldTca['config']['uploadfolder'] : ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         $baseFolder = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         if (trim($uploadFolder, '/') !== '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |             $baseFolder = rtrim($uploadFolder, '/') . '/'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         $filePath = $baseFolder . $p['file']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         if (!is_file(GeneralUtility::getFileAbsFileName($filePath))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |             return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         return $filePath; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 144 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 145 |  |  |  | 
            
                        
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.