@@ -16,8 +16,8 @@ discard block |
||
| 16 | 16 | $picture_directory = $this->build_path_to_directory(); |
| 17 | 17 | $thumbnail_directory = $picture_directory; |
| 18 | 18 | |
| 19 | - if(!file_exists($picture_directory) && mkdir($picture_directory) === false) |
|
| 20 | - return []; |
|
| 19 | + if(!file_exists($picture_directory) && mkdir($picture_directory) === false) |
|
| 20 | + return []; |
|
| 21 | 21 | |
| 22 | 22 | $filenames = self::preg_scandir($picture_directory, '/^[0-9]+_[0-9]+\.[a-zA-Z]+/');// ID_SEQUENCENUMBER.ext |
| 23 | 23 | |
@@ -75,11 +75,11 @@ discard block |
||
| 75 | 75 | $filepath = $this->build_filename() . '.' . self::file_ext($_FILES[$this->get_type()]['name']); |
| 76 | 76 | $filepath = $this->locate_file($filepath); |
| 77 | 77 | |
| 78 | - if(file_exists($filepath)) |
|
| 78 | + if(file_exists($filepath)) |
|
| 79 | 79 | throw new \Exception($this->get_type()." new path '$filepath' already exists"); |
| 80 | 80 | |
| 81 | - if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) |
|
| 82 | - throw new \Exception(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
|
| 81 | + if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) |
|
| 82 | + throw new \Exception(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
|
| 83 | 83 | |
| 84 | 84 | $this->make_thumbnail($filepath); |
| 85 | 85 | } |
@@ -95,64 +95,64 @@ discard block |
||
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | public function make_thumbnail($filepath) |
| 98 | - { |
|
| 98 | + { |
|
| 99 | 99 | global $settings; |
| 100 | 100 | |
| 101 | - $cover_iri = null; |
|
| 102 | - |
|
| 103 | - $mime_type = mime_content_type($filepath); |
|
| 104 | - switch($mime_type) |
|
| 105 | - { |
|
| 106 | - case 'image/jpeg': |
|
| 107 | - case 'image/pjpeg': |
|
| 108 | - $cover_iri = imagecreatefromjpeg($filepath); |
|
| 109 | - break; |
|
| 101 | + $cover_iri = null; |
|
| 110 | 102 | |
| 111 | - case 'image/png': |
|
| 112 | - $cover_iri = imagecreatefrompng($filepath); |
|
| 113 | - break; |
|
| 114 | - |
|
| 115 | - case 'image/gif': |
|
| 116 | - $cover_iri = imagecreatefromgif($filepath); |
|
| 117 | - break; |
|
| 118 | - } |
|
| 103 | + $mime_type = mime_content_type($filepath); |
|
| 104 | + switch($mime_type) |
|
| 105 | + { |
|
| 106 | + case 'image/jpeg': |
|
| 107 | + case 'image/pjpeg': |
|
| 108 | + $cover_iri = imagecreatefromjpeg($filepath); |
|
| 109 | + break; |
|
| 110 | + |
|
| 111 | + case 'image/png': |
|
| 112 | + $cover_iri = imagecreatefrompng($filepath); |
|
| 113 | + break; |
|
| 114 | + |
|
| 115 | + case 'image/gif': |
|
| 116 | + $cover_iri = imagecreatefromgif($filepath); |
|
| 117 | + break; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - if(!is_null($cover_iri)) |
|
| 121 | - { |
|
| 122 | - $width = imagesx( $cover_iri ); |
|
| 123 | - $height = imagesy( $cover_iri ); |
|
| 120 | + if(!is_null($cover_iri)) |
|
| 121 | + { |
|
| 122 | + $width = imagesx( $cover_iri ); |
|
| 123 | + $height = imagesy( $cover_iri ); |
|
| 124 | 124 | |
| 125 | - // calculate thumbnail size |
|
| 125 | + // calculate thumbnail size |
|
| 126 | 126 | |
| 127 | - $new_width = $settings[get_class($this->pmi)::model_type()][$this->get_type()]['thumbnail']['width']; |
|
| 128 | - $new_height = floor( $height * ( $new_width / $width ) ); |
|
| 127 | + $new_width = $settings[get_class($this->pmi)::model_type()][$this->get_type()]['thumbnail']['width']; |
|
| 128 | + $new_height = floor( $height * ( $new_width / $width ) ); |
|
| 129 | 129 | |
| 130 | - // create a new temporary image |
|
| 131 | - $thumb_iri = imagecreatetruecolor($new_width, $new_height); |
|
| 130 | + // create a new temporary image |
|
| 131 | + $thumb_iri = imagecreatetruecolor($new_width, $new_height); |
|
| 132 | 132 | |
| 133 | - // copy and resize old image into new image |
|
| 134 | - imagecopyresized( $thumb_iri, $cover_iri, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); |
|
| 133 | + // copy and resize old image into new image |
|
| 134 | + imagecopyresized( $thumb_iri, $cover_iri, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); |
|
| 135 | 135 | |
| 136 | - // save thumbnail into a file |
|
| 136 | + // save thumbnail into a file |
|
| 137 | 137 | imagejpeg($thumb_iri, $this->locate_thumbnail(pathinfo($filepath, PATHINFO_BASENAME))); |
| 138 | - } |
|
| 139 | - } |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | 141 | public function remove_all() |
| 142 | 142 | { |
| 143 | 143 | $filenames = $this->filenames(); |
| 144 | 144 | |
| 145 | 145 | foreach($filenames as $filename) |
| 146 | - $this->remove($filename); |
|
| 146 | + $this->remove($filename); |
|
| 147 | 147 | |
| 148 | 148 | $directory = $this->build_path_to_directory(); |
| 149 | - if(file_exists($directory) === true) |
|
| 149 | + if(file_exists($directory) === true) |
|
| 150 | 150 | { |
| 151 | 151 | if(is_dir($directory) === false) |
| 152 | 152 | throw new \Exception($this->get_type()."' directory '$directory' is not a directory"); |
| 153 | 153 | |
| 154 | - if(rmdir($directory) === false) |
|
| 155 | - throw new \Exception("rmdir($directory) failed like a bitch"); |
|
| 154 | + if(rmdir($directory) === false) |
|
| 155 | + throw new \Exception("rmdir($directory) failed like a bitch"); |
|
| 156 | 156 | } |
| 157 | 157 | else trigger_error($this->get_type()." $directory doesn't exist", E_USER_WARNING); |
| 158 | 158 | } |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | foreach($pathes as $what => $path) |
| 170 | 170 | { |
| 171 | 171 | $error = null; |
| 172 | - if(!file_exists($path)) |
|
| 172 | + if(!file_exists($path)) |
|
| 173 | 173 | $error = 'file does not exist'; |
| 174 | 174 | elseif(unlink($path)===false) |
| 175 | 175 | $error = 'unlink() failed'; |
@@ -223,16 +223,16 @@ discard block |
||
| 223 | 223 | global $settings; |
| 224 | 224 | $pi_manager = new PictureManager($item, $picture_type); |
| 225 | 225 | |
| 226 | - $pictures = $pi_manager->filenames(); |
|
| 226 | + $pictures = $pi_manager->filenames(); |
|
| 227 | 227 | |
| 228 | 228 | $item_model_type = get_class($item)::model_type(); |
| 229 | 229 | if(count($pictures)===0) |
| 230 | 230 | return $settings[$item_model_type][$picture_type]['generic_picture']; |
| 231 | 231 | |
| 232 | - if($settings[$item_model_type][$picture_type]['cycle_on_load']) |
|
| 233 | - $filename = $pictures[array_rand($pictures, 1)]; |
|
| 234 | - else |
|
| 235 | - $filename = array_shift($pictures); |
|
| 232 | + if($settings[$item_model_type][$picture_type]['cycle_on_load']) |
|
| 233 | + $filename = $pictures[array_rand($pictures, 1)]; |
|
| 234 | + else |
|
| 235 | + $filename = array_shift($pictures); |
|
| 236 | 236 | |
| 237 | 237 | return $thumbnail===true ? $pi_manager->locate_thumbnail($filename) : $pi_manager->locate_file($filename); |
| 238 | 238 | } |
@@ -11,35 +11,35 @@ discard block |
||
| 11 | 11 | { |
| 12 | 12 | use FileManager; |
| 13 | 13 | |
| 14 | - public function filenames($replace_by_thumbs_if_exists=false) : array |
|
| 14 | + public function filenames($replace_by_thumbs_if_exists = false) : array |
|
| 15 | 15 | { |
| 16 | 16 | $picture_directory = $this->build_path_to_directory(); |
| 17 | 17 | $thumbnail_directory = $picture_directory; |
| 18 | 18 | |
| 19 | - if(!file_exists($picture_directory) && mkdir($picture_directory) === false) |
|
| 19 | + if (!file_exists($picture_directory) && mkdir($picture_directory) === false) |
|
| 20 | 20 | return []; |
| 21 | 21 | |
| 22 | - $filenames = self::preg_scandir($picture_directory, '/^[0-9]+_[0-9]+\.[a-zA-Z]+/');// ID_SEQUENCENUMBER.ext |
|
| 22 | + $filenames = self::preg_scandir($picture_directory, '/^[0-9]+_[0-9]+\.[a-zA-Z]+/'); // ID_SEQUENCENUMBER.ext |
|
| 23 | 23 | |
| 24 | 24 | sort($filenames); |
| 25 | 25 | return $filenames; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - public function filepathes($replace_by_thumbs_if_exists=false) |
|
| 28 | + public function filepathes($replace_by_thumbs_if_exists = false) |
|
| 29 | 29 | { |
| 30 | 30 | $filenames = $this->filenames($replace_by_thumbs_if_exists); |
| 31 | 31 | $filepathes = []; |
| 32 | - foreach($filenames as $filename) |
|
| 32 | + foreach ($filenames as $filename) |
|
| 33 | 33 | $filepathes[] = $this->locate_thumbnail($filename); |
| 34 | 34 | |
| 35 | 35 | return $filepathes; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - public function file_uris($replace_by_thumbs_if_exists=false) |
|
| 38 | + public function file_uris($replace_by_thumbs_if_exists = false) |
|
| 39 | 39 | { |
| 40 | 40 | $filenames = $this->filenames($replace_by_thumbs_if_exists); |
| 41 | 41 | $uris = []; |
| 42 | - foreach($filenames as $filename) |
|
| 42 | + foreach ($filenames as $filename) |
|
| 43 | 43 | $uris[] = $this->locate_file($filename); |
| 44 | 44 | |
| 45 | 45 | dd($uris); |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | 'image/gif' => 'imagecreatefromgif', |
| 56 | 56 | ); |
| 57 | 57 | $mime = mime_content_type($filepath); |
| 58 | - if(array_key_exists($mime, $picture_mime_to_gd_create_function)) |
|
| 58 | + if (array_key_exists($mime, $picture_mime_to_gd_create_function)) |
|
| 59 | 59 | return true; |
| 60 | 60 | return $mime; |
| 61 | 61 | } |
@@ -63,22 +63,22 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | public function upload() |
| 65 | 65 | { |
| 66 | - if(!array_key_exists($this->get_type(), $_FILES)) |
|
| 66 | + if (!array_key_exists($this->get_type(), $_FILES)) |
|
| 67 | 67 | throw new \Exception($this->get_type()." not found in _FILES"); |
| 68 | 68 | |
| 69 | - if(!array_key_exists('size', $_FILES[$this->get_type()]) || $_FILES[$this->get_type()]['size'] == 0) |
|
| 69 | + if (!array_key_exists('size', $_FILES[$this->get_type()]) || $_FILES[$this->get_type()]['size'] == 0) |
|
| 70 | 70 | throw new \Exception('uploaded file has no size'); |
| 71 | 71 | |
| 72 | - if(($file_type = self::is_picture_file($_FILES[$this->get_type()]['tmp_name'])) !== true) |
|
| 72 | + if (($file_type = self::is_picture_file($_FILES[$this->get_type()]['tmp_name'])) !== true) |
|
| 73 | 73 | throw new \Exception('data sent is not an image but a '.$file_type.''); |
| 74 | 74 | |
| 75 | - $filepath = $this->build_filename() . '.' . self::file_ext($_FILES[$this->get_type()]['name']); |
|
| 75 | + $filepath = $this->build_filename().'.'.self::file_ext($_FILES[$this->get_type()]['name']); |
|
| 76 | 76 | $filepath = $this->locate_file($filepath); |
| 77 | 77 | |
| 78 | - if(file_exists($filepath)) |
|
| 78 | + if (file_exists($filepath)) |
|
| 79 | 79 | throw new \Exception($this->get_type()." new path '$filepath' already exists"); |
| 80 | 80 | |
| 81 | - if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) |
|
| 81 | + if (copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) |
|
| 82 | 82 | throw new \Exception(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
| 83 | 83 | |
| 84 | 84 | $this->make_thumbnail($filepath); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | public function download($url) |
| 88 | 88 | { |
| 89 | - $filepath = $this->build_filename() . '.' . self::file_ext($url); |
|
| 89 | + $filepath = $this->build_filename().'.'.self::file_ext($url); |
|
| 90 | 90 | $filepath = $this->locate_file($filepath); |
| 91 | 91 | |
| 92 | 92 | \qivive\Curlyb::fetch($url, $filepath); |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | $cover_iri = null; |
| 102 | 102 | |
| 103 | 103 | $mime_type = mime_content_type($filepath); |
| 104 | - switch($mime_type) |
|
| 104 | + switch ($mime_type) |
|
| 105 | 105 | { |
| 106 | 106 | case 'image/jpeg': |
| 107 | 107 | case 'image/pjpeg': |
@@ -117,21 +117,21 @@ discard block |
||
| 117 | 117 | break; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - if(!is_null($cover_iri)) |
|
| 120 | + if (!is_null($cover_iri)) |
|
| 121 | 121 | { |
| 122 | - $width = imagesx( $cover_iri ); |
|
| 123 | - $height = imagesy( $cover_iri ); |
|
| 122 | + $width = imagesx($cover_iri); |
|
| 123 | + $height = imagesy($cover_iri); |
|
| 124 | 124 | |
| 125 | 125 | // calculate thumbnail size |
| 126 | 126 | |
| 127 | 127 | $new_width = $settings[get_class($this->pmi)::model_type()][$this->get_type()]['thumbnail']['width']; |
| 128 | - $new_height = floor( $height * ( $new_width / $width ) ); |
|
| 128 | + $new_height = floor($height * ($new_width / $width)); |
|
| 129 | 129 | |
| 130 | 130 | // create a new temporary image |
| 131 | 131 | $thumb_iri = imagecreatetruecolor($new_width, $new_height); |
| 132 | 132 | |
| 133 | 133 | // copy and resize old image into new image |
| 134 | - imagecopyresized( $thumb_iri, $cover_iri, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); |
|
| 134 | + imagecopyresized($thumb_iri, $cover_iri, 0, 0, 0, 0, $new_width, $new_height, $width, $height); |
|
| 135 | 135 | |
| 136 | 136 | // save thumbnail into a file |
| 137 | 137 | imagejpeg($thumb_iri, $this->locate_thumbnail(pathinfo($filepath, PATHINFO_BASENAME))); |
@@ -142,16 +142,16 @@ discard block |
||
| 142 | 142 | { |
| 143 | 143 | $filenames = $this->filenames(); |
| 144 | 144 | |
| 145 | - foreach($filenames as $filename) |
|
| 145 | + foreach ($filenames as $filename) |
|
| 146 | 146 | $this->remove($filename); |
| 147 | 147 | |
| 148 | 148 | $directory = $this->build_path_to_directory(); |
| 149 | - if(file_exists($directory) === true) |
|
| 149 | + if (file_exists($directory) === true) |
|
| 150 | 150 | { |
| 151 | - if(is_dir($directory) === false) |
|
| 151 | + if (is_dir($directory) === false) |
|
| 152 | 152 | throw new \Exception($this->get_type()."' directory '$directory' is not a directory"); |
| 153 | 153 | |
| 154 | - if(rmdir($directory) === false) |
|
| 154 | + if (rmdir($directory) === false) |
|
| 155 | 155 | throw new \Exception("rmdir($directory) failed like a bitch"); |
| 156 | 156 | } |
| 157 | 157 | else trigger_error($this->get_type()." $directory doesn't exist", E_USER_WARNING); |
@@ -162,27 +162,27 @@ discard block |
||
| 162 | 162 | // removing a picture, and maybe a thumbnail? build the $pathes array accordingly |
| 163 | 163 | $pathes = []; |
| 164 | 164 | $pathes[$this->get_type()] = $this->locate_file($picture_filename); |
| 165 | - $pathes[$this->get_type() . ' thumbnail'] = $this->locate_thumbnail($picture_filename); |
|
| 165 | + $pathes[$this->get_type().' thumbnail'] = $this->locate_thumbnail($picture_filename); |
|
| 166 | 166 | |
| 167 | 167 | $deleted = []; |
| 168 | 168 | $still_walking = []; |
| 169 | - foreach($pathes as $what => $path) |
|
| 169 | + foreach ($pathes as $what => $path) |
|
| 170 | 170 | { |
| 171 | 171 | $error = null; |
| 172 | - if(!file_exists($path)) |
|
| 172 | + if (!file_exists($path)) |
|
| 173 | 173 | $error = 'file does not exist'; |
| 174 | - elseif(unlink($path)===false) |
|
| 174 | + elseif (unlink($path) === false) |
|
| 175 | 175 | $error = 'unlink() failed'; |
| 176 | 176 | |
| 177 | - if(is_null($error)) |
|
| 178 | - $deleted[]= $what; |
|
| 177 | + if (is_null($error)) |
|
| 178 | + $deleted[] = $what; |
|
| 179 | 179 | else |
| 180 | 180 | { |
| 181 | 181 | trigger_error(__FUNCTION__." '$picture_filename' ($what @ $path) impossible because ", E_USER_NOTICE); |
| 182 | - $still_walking[]=$what; |
|
| 182 | + $still_walking[] = $what; |
|
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | - return count($still_walking)===0; |
|
| 185 | + return count($still_walking) === 0; |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | public function locate_thumbnail($filename) |
@@ -196,11 +196,11 @@ discard block |
||
| 196 | 196 | return $settings['thumbnail']['file_prefix'].''.pathinfo($picture_basename, PATHINFO_FILENAME).'.jpg'; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - public static function file_info($absolute_path_to_picture, $what=null) |
|
| 199 | + public static function file_info($absolute_path_to_picture, $what = null) |
|
| 200 | 200 | { |
| 201 | - $ret = parent::file_info($absolute_path_to_picture, $what=null); |
|
| 201 | + $ret = parent::file_info($absolute_path_to_picture, $what = null); |
|
| 202 | 202 | |
| 203 | - if(is_array($ret)) |
|
| 203 | + if (is_array($ret)) |
|
| 204 | 204 | { |
| 205 | 205 | $t = getimagesize($absolute_path_to_picture); |
| 206 | 206 | $ret['width'] = $t[0]; |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | |
| 221 | - public static function uri_for($item, $picture_type, $thumbnail=true) |
|
| 221 | + public static function uri_for($item, $picture_type, $thumbnail = true) |
|
| 222 | 222 | { |
| 223 | 223 | global $settings; |
| 224 | 224 | $pi_manager = new PictureManager($item, $picture_type); |
@@ -226,24 +226,24 @@ discard block |
||
| 226 | 226 | $pictures = $pi_manager->filenames(); |
| 227 | 227 | |
| 228 | 228 | $item_model_type = get_class($item)::model_type(); |
| 229 | - if(count($pictures)===0) |
|
| 229 | + if (count($pictures) === 0) |
|
| 230 | 230 | return $settings[$item_model_type][$picture_type]['generic_picture']; |
| 231 | 231 | |
| 232 | - if($settings[$item_model_type][$picture_type]['cycle_on_load']) |
|
| 232 | + if ($settings[$item_model_type][$picture_type]['cycle_on_load']) |
|
| 233 | 233 | $filename = $pictures[array_rand($pictures, 1)]; |
| 234 | 234 | else |
| 235 | 235 | $filename = array_shift($pictures); |
| 236 | 236 | |
| 237 | - return $thumbnail===true ? $pi_manager->locate_thumbnail($filename) : $pi_manager->locate_file($filename); |
|
| 237 | + return $thumbnail === true ? $pi_manager->locate_thumbnail($filename) : $pi_manager->locate_file($filename); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | public function last_index() |
| 241 | 241 | { |
| 242 | 242 | $last_index = 0; |
| 243 | - if(count($filenames = $this->filenames()) > 0) |
|
| 243 | + if (count($filenames = $this->filenames()) > 0) |
|
| 244 | 244 | { |
| 245 | 245 | $last_filename = array_pop($filenames); // last cover name FIXME sort should be done here, check cost if sort already done |
| 246 | - if(preg_match('/[0-9]+\_([0-9]+)\.[a-z]+/', $last_filename, $last_index) !== 1) |
|
| 246 | + if (preg_match('/[0-9]+\_([0-9]+)\.[a-z]+/', $last_filename, $last_index) !== 1) |
|
| 247 | 247 | throw new \Exception("FAILED_COMPUTING_NEW_INDEX_USING_REGEX"); |
| 248 | 248 | |
| 249 | 249 | $last_index = $last_index[1]; |
@@ -257,9 +257,9 @@ discard block |
||
| 257 | 257 | return sprintf('%s%s.jpg', $settings['thumbnail']['file_prefix'], pathinfo($picture_basename, PATHINFO_FILENAME)); |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - public function build_filename($index=null) |
|
| 260 | + public function build_filename($index = null) |
|
| 261 | 261 | { |
| 262 | - if(is_null($index)) |
|
| 262 | + if (is_null($index)) |
|
| 263 | 263 | $index = $this->last_index()+1; |
| 264 | 264 | |
| 265 | 265 | return $this->pmi->id.'_'.sprintf("%'.09d", $index); // prepend bean id |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | $new_thumbname_path = $this->locate_file($this->build_thumb_filename($new_filename_path)); //move current to zero |
| 279 | 279 | $this->rename($selected_thumbname_path, $new_thumbname_path); |
| 280 | 280 | |
| 281 | - for($i=$filename_index-1; $i>=0; --$i) |
|
| 281 | + for ($i = $filename_index-1; $i >= 0; --$i) |
|
| 282 | 282 | { |
| 283 | 283 | $move_this = $this->locate_file($files[$i]); |
| 284 | 284 | $to_that = $this->locate_file($files[$i+1]); |
@@ -16,8 +16,9 @@ discard block |
||
| 16 | 16 | $picture_directory = $this->build_path_to_directory(); |
| 17 | 17 | $thumbnail_directory = $picture_directory; |
| 18 | 18 | |
| 19 | - if(!file_exists($picture_directory) && mkdir($picture_directory) === false) |
|
| 20 | - return []; |
|
| 19 | + if(!file_exists($picture_directory) && mkdir($picture_directory) === false) { |
|
| 20 | + return []; |
|
| 21 | + } |
|
| 21 | 22 | |
| 22 | 23 | $filenames = self::preg_scandir($picture_directory, '/^[0-9]+_[0-9]+\.[a-zA-Z]+/');// ID_SEQUENCENUMBER.ext |
| 23 | 24 | |
@@ -29,8 +30,9 @@ discard block |
||
| 29 | 30 | { |
| 30 | 31 | $filenames = $this->filenames($replace_by_thumbs_if_exists); |
| 31 | 32 | $filepathes = []; |
| 32 | - foreach($filenames as $filename) |
|
| 33 | - $filepathes[] = $this->locate_thumbnail($filename); |
|
| 33 | + foreach($filenames as $filename) { |
|
| 34 | + $filepathes[] = $this->locate_thumbnail($filename); |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | return $filepathes; |
| 36 | 38 | } |
@@ -39,8 +41,9 @@ discard block |
||
| 39 | 41 | { |
| 40 | 42 | $filenames = $this->filenames($replace_by_thumbs_if_exists); |
| 41 | 43 | $uris = []; |
| 42 | - foreach($filenames as $filename) |
|
| 43 | - $uris[] = $this->locate_file($filename); |
|
| 44 | + foreach($filenames as $filename) { |
|
| 45 | + $uris[] = $this->locate_file($filename); |
|
| 46 | + } |
|
| 44 | 47 | |
| 45 | 48 | dd($uris); |
| 46 | 49 | return $uris; |
@@ -55,31 +58,37 @@ discard block |
||
| 55 | 58 | 'image/gif' => 'imagecreatefromgif', |
| 56 | 59 | ); |
| 57 | 60 | $mime = mime_content_type($filepath); |
| 58 | - if(array_key_exists($mime, $picture_mime_to_gd_create_function)) |
|
| 59 | - return true; |
|
| 61 | + if(array_key_exists($mime, $picture_mime_to_gd_create_function)) { |
|
| 62 | + return true; |
|
| 63 | + } |
|
| 60 | 64 | return $mime; |
| 61 | 65 | } |
| 62 | 66 | |
| 63 | 67 | |
| 64 | 68 | public function upload() |
| 65 | 69 | { |
| 66 | - if(!array_key_exists($this->get_type(), $_FILES)) |
|
| 67 | - throw new \Exception($this->get_type()." not found in _FILES"); |
|
| 70 | + if(!array_key_exists($this->get_type(), $_FILES)) { |
|
| 71 | + throw new \Exception($this->get_type()." not found in _FILES"); |
|
| 72 | + } |
|
| 68 | 73 | |
| 69 | - if(!array_key_exists('size', $_FILES[$this->get_type()]) || $_FILES[$this->get_type()]['size'] == 0) |
|
| 70 | - throw new \Exception('uploaded file has no size'); |
|
| 74 | + if(!array_key_exists('size', $_FILES[$this->get_type()]) || $_FILES[$this->get_type()]['size'] == 0) { |
|
| 75 | + throw new \Exception('uploaded file has no size'); |
|
| 76 | + } |
|
| 71 | 77 | |
| 72 | - if(($file_type = self::is_picture_file($_FILES[$this->get_type()]['tmp_name'])) !== true) |
|
| 73 | - throw new \Exception('data sent is not an image but a '.$file_type.''); |
|
| 78 | + if(($file_type = self::is_picture_file($_FILES[$this->get_type()]['tmp_name'])) !== true) { |
|
| 79 | + throw new \Exception('data sent is not an image but a '.$file_type.''); |
|
| 80 | + } |
|
| 74 | 81 | |
| 75 | 82 | $filepath = $this->build_filename() . '.' . self::file_ext($_FILES[$this->get_type()]['name']); |
| 76 | 83 | $filepath = $this->locate_file($filepath); |
| 77 | 84 | |
| 78 | - if(file_exists($filepath)) |
|
| 79 | - throw new \Exception($this->get_type()." new path '$filepath' already exists"); |
|
| 85 | + if(file_exists($filepath)) { |
|
| 86 | + throw new \Exception($this->get_type()." new path '$filepath' already exists"); |
|
| 87 | + } |
|
| 80 | 88 | |
| 81 | - if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) |
|
| 82 | - throw new \Exception(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
|
| 89 | + if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) { |
|
| 90 | + throw new \Exception(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
|
| 91 | + } |
|
| 83 | 92 | |
| 84 | 93 | $this->make_thumbnail($filepath); |
| 85 | 94 | } |
@@ -142,19 +151,23 @@ discard block |
||
| 142 | 151 | { |
| 143 | 152 | $filenames = $this->filenames(); |
| 144 | 153 | |
| 145 | - foreach($filenames as $filename) |
|
| 146 | - $this->remove($filename); |
|
| 154 | + foreach($filenames as $filename) { |
|
| 155 | + $this->remove($filename); |
|
| 156 | + } |
|
| 147 | 157 | |
| 148 | 158 | $directory = $this->build_path_to_directory(); |
| 149 | 159 | if(file_exists($directory) === true) |
| 150 | 160 | { |
| 151 | - if(is_dir($directory) === false) |
|
| 152 | - throw new \Exception($this->get_type()."' directory '$directory' is not a directory"); |
|
| 161 | + if(is_dir($directory) === false) { |
|
| 162 | + throw new \Exception($this->get_type()."' directory '$directory' is not a directory"); |
|
| 163 | + } |
|
| 153 | 164 | |
| 154 | - if(rmdir($directory) === false) |
|
| 155 | - throw new \Exception("rmdir($directory) failed like a bitch"); |
|
| 165 | + if(rmdir($directory) === false) { |
|
| 166 | + throw new \Exception("rmdir($directory) failed like a bitch"); |
|
| 167 | + } |
|
| 168 | + } else { |
|
| 169 | + trigger_error($this->get_type()." $directory doesn't exist", E_USER_WARNING); |
|
| 156 | 170 | } |
| 157 | - else trigger_error($this->get_type()." $directory doesn't exist", E_USER_WARNING); |
|
| 158 | 171 | } |
| 159 | 172 | |
| 160 | 173 | public function remove($picture_filename) |
@@ -169,14 +182,15 @@ discard block |
||
| 169 | 182 | foreach($pathes as $what => $path) |
| 170 | 183 | { |
| 171 | 184 | $error = null; |
| 172 | - if(!file_exists($path)) |
|
| 173 | - $error = 'file does not exist'; |
|
| 174 | - elseif(unlink($path)===false) |
|
| 175 | - $error = 'unlink() failed'; |
|
| 176 | - |
|
| 177 | - if(is_null($error)) |
|
| 178 | - $deleted[]= $what; |
|
| 179 | - else |
|
| 185 | + if(!file_exists($path)) { |
|
| 186 | + $error = 'file does not exist'; |
|
| 187 | + } elseif(unlink($path)===false) { |
|
| 188 | + $error = 'unlink() failed'; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + if(is_null($error)) { |
|
| 192 | + $deleted[]= $what; |
|
| 193 | + } else |
|
| 180 | 194 | { |
| 181 | 195 | trigger_error(__FUNCTION__." '$picture_filename' ($what @ $path) impossible because ", E_USER_NOTICE); |
| 182 | 196 | $still_walking[]=$what; |
@@ -226,13 +240,15 @@ discard block |
||
| 226 | 240 | $pictures = $pi_manager->filenames(); |
| 227 | 241 | |
| 228 | 242 | $item_model_type = get_class($item)::model_type(); |
| 229 | - if(count($pictures)===0) |
|
| 230 | - return $settings[$item_model_type][$picture_type]['generic_picture']; |
|
| 243 | + if(count($pictures)===0) { |
|
| 244 | + return $settings[$item_model_type][$picture_type]['generic_picture']; |
|
| 245 | + } |
|
| 231 | 246 | |
| 232 | - if($settings[$item_model_type][$picture_type]['cycle_on_load']) |
|
| 233 | - $filename = $pictures[array_rand($pictures, 1)]; |
|
| 234 | - else |
|
| 235 | - $filename = array_shift($pictures); |
|
| 247 | + if($settings[$item_model_type][$picture_type]['cycle_on_load']) { |
|
| 248 | + $filename = $pictures[array_rand($pictures, 1)]; |
|
| 249 | + } else { |
|
| 250 | + $filename = array_shift($pictures); |
|
| 251 | + } |
|
| 236 | 252 | |
| 237 | 253 | return $thumbnail===true ? $pi_manager->locate_thumbnail($filename) : $pi_manager->locate_file($filename); |
| 238 | 254 | } |
@@ -243,8 +259,9 @@ discard block |
||
| 243 | 259 | if(count($filenames = $this->filenames()) > 0) |
| 244 | 260 | { |
| 245 | 261 | $last_filename = array_pop($filenames); // last cover name FIXME sort should be done here, check cost if sort already done |
| 246 | - if(preg_match('/[0-9]+\_([0-9]+)\.[a-z]+/', $last_filename, $last_index) !== 1) |
|
| 247 | - throw new \Exception("FAILED_COMPUTING_NEW_INDEX_USING_REGEX"); |
|
| 262 | + if(preg_match('/[0-9]+\_([0-9]+)\.[a-z]+/', $last_filename, $last_index) !== 1) { |
|
| 263 | + throw new \Exception("FAILED_COMPUTING_NEW_INDEX_USING_REGEX"); |
|
| 264 | + } |
|
| 248 | 265 | |
| 249 | 266 | $last_index = $last_index[1]; |
| 250 | 267 | } |
@@ -259,8 +276,9 @@ discard block |
||
| 259 | 276 | |
| 260 | 277 | public function build_filename($index=null) |
| 261 | 278 | { |
| 262 | - if(is_null($index)) |
|
| 263 | - $index = $this->last_index()+1; |
|
| 279 | + if(is_null($index)) { |
|
| 280 | + $index = $this->last_index()+1; |
|
| 281 | + } |
|
| 264 | 282 | |
| 265 | 283 | return $this->pmi->id.'_'.sprintf("%'.09d", $index); // prepend bean id |
| 266 | 284 | } |
@@ -11,9 +11,9 @@ |
||
| 11 | 11 | return $this->breadcrumbs; |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | - public function breadcrumb($show, $route=null) |
|
| 14 | + public function breadcrumb($show, $route = null) |
|
| 15 | 15 | { |
| 16 | - $this->breadcrumbs[]= ['show' => $show, 'route' => $route]; |
|
| 16 | + $this->breadcrumbs[] = ['show' => $show, 'route' => $route]; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | public function reset_breadcrumbs() : array |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | $headers = explode(',', trim($language_data[0])); |
| 34 | 34 | array_shift($language_data); |
| 35 | 35 | |
| 36 | - foreach($language_data as $i => $lang) |
|
| 36 | + foreach ($language_data as $i => $lang) |
|
| 37 | 37 | { |
| 38 | 38 | $data = array_combine($headers, explode(',', $lang)); |
| 39 | 39 | |
@@ -9,11 +9,13 @@ discard block |
||
| 9 | 9 | { |
| 10 | 10 | private static function compute_field_value($model,$field_name) |
| 11 | 11 | { |
| 12 | - if(method_exists($model,$field_name)) |
|
| 13 | - return $model->$field_name(); |
|
| 12 | + if(method_exists($model,$field_name)) { |
|
| 13 | + return $model->$field_name(); |
|
| 14 | + } |
|
| 14 | 15 | |
| 15 | - if(property_exists($model,$field_name)) |
|
| 16 | - return $model->$field_name; |
|
| 16 | + if(property_exists($model,$field_name)) { |
|
| 17 | + return $model->$field_name; |
|
| 18 | + } |
|
| 17 | 19 | |
| 18 | 20 | return ''; |
| 19 | 21 | } |
@@ -51,74 +53,66 @@ discard block |
||
| 51 | 53 | |
| 52 | 54 | $table = get_class($model)::table(); |
| 53 | 55 | |
| 54 | - if(is_null($table->column($field_name))) |
|
| 55 | - return Form::input($field_name,$field_value,$attributes,$errors); |
|
| 56 | + if(is_null($table->column($field_name))) { |
|
| 57 | + return Form::input($field_name,$field_value,$attributes,$errors); |
|
| 58 | + } |
|
| 56 | 59 | |
| 57 | 60 | $ret = ''; |
| 58 | 61 | |
| 59 | 62 | $field = $table->column($field_name); |
| 60 | 63 | |
| 61 | 64 | |
| 62 | - if(isset($attributes['required']) && $attributes['required'] === false) |
|
| 63 | - unset($attributes['required']); |
|
| 64 | - |
|
| 65 | - elseif(!$field->is_nullable()) |
|
| 66 | - $attributes[] = 'required'; |
|
| 65 | + if(isset($attributes['required']) && $attributes['required'] === false) { |
|
| 66 | + unset($attributes['required']); |
|
| 67 | + } elseif(!$field->is_nullable()) { |
|
| 68 | + $attributes[] = 'required'; |
|
| 69 | + } |
|
| 67 | 70 | |
| 68 | 71 | if($field->is_auto_incremented()) |
| 69 | 72 | { |
| 70 | 73 | $ret .= Form::hidden($field->name(),$field_value); |
| 71 | - } |
|
| 72 | - elseif($field->type()->is_boolean()) |
|
| 74 | + } elseif($field->type()->is_boolean()) |
|
| 73 | 75 | { |
| 74 | 76 | $option_list = $attributes['values'] ?? [0 => 0, 1 => 1]; |
| 75 | 77 | $ret .= Form::select($field->name(), $option_list ,$field_value, $attributes); // |
| 76 | - } |
|
| 77 | - elseif($field->type()->is_integer()) |
|
| 78 | + } elseif($field->type()->is_integer()) |
|
| 78 | 79 | { |
| 79 | 80 | $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
| 80 | - } |
|
| 81 | - elseif($field->type()->is_year()) |
|
| 81 | + } elseif($field->type()->is_year()) |
|
| 82 | 82 | { |
| 83 | 83 | $attributes['size'] = $attributes['maxlength'] = 4; |
| 84 | 84 | $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
| 85 | - } |
|
| 86 | - elseif($field->type()->is_date()) |
|
| 85 | + } elseif($field->type()->is_date()) |
|
| 87 | 86 | { |
| 88 | 87 | $ret .= Form::date($field->name(),$field_value,$attributes,$errors); |
| 89 | - } |
|
| 90 | - elseif($field->type()->is_time()) |
|
| 88 | + } elseif($field->type()->is_time()) |
|
| 91 | 89 | { |
| 92 | 90 | $ret .= Form::time($field->name(),$field_value,$attributes,$errors); |
| 93 | - } |
|
| 94 | - elseif($field->type()->is_datetime()) |
|
| 91 | + } elseif($field->type()->is_datetime()) |
|
| 95 | 92 | { |
| 96 | 93 | $ret .= Form::datetime($field->name(),$field_value,$attributes,$errors); |
| 97 | - } |
|
| 98 | - elseif($field->type()->is_text()) |
|
| 94 | + } elseif($field->type()->is_text()) |
|
| 99 | 95 | { |
| 100 | 96 | $ret .= Form::textarea($field->name(),$field_value,$attributes,$errors); |
| 101 | - } |
|
| 102 | - elseif($field->type()->is_enum()) |
|
| 97 | + } elseif($field->type()->is_enum()) |
|
| 103 | 98 | { |
| 104 | 99 | |
| 105 | 100 | $enum_values = []; |
| 106 | - foreach($field->type()->enum_values() as $e_val) |
|
| 107 | - $enum_values[$e_val] = $e_val; |
|
| 101 | + foreach($field->type()->enum_values() as $e_val) { |
|
| 102 | + $enum_values[$e_val] = $e_val; |
|
| 103 | + } |
|
| 108 | 104 | |
| 109 | 105 | $selected = $attributes['value'] ?? $field_value ?? ''; |
| 110 | 106 | // foreach($field->) |
| 111 | 107 | $ret .= Form::select($field->name(), $enum_values, $selected, $attributes); // |
| 112 | 108 | |
| 113 | 109 | // throw new \Exception('ENUM IS NOT HANDLED BY TableToFom'); |
| 114 | - } |
|
| 115 | - elseif($field->type()->is_string()) |
|
| 110 | + } elseif($field->type()->is_string()) |
|
| 116 | 111 | { |
| 117 | 112 | $max_length = $field->type()->length(); |
| 118 | 113 | $attributes['size'] = $attributes['maxlength'] = $max_length; |
| 119 | 114 | $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
| 120 | - } |
|
| 121 | - else |
|
| 115 | + } else |
|
| 122 | 116 | { |
| 123 | 117 | $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
| 124 | 118 | } |
@@ -130,8 +124,9 @@ discard block |
||
| 130 | 124 | public static function field_with_label($model,$field_name,$attributes=[],$errors=[]) : string |
| 131 | 125 | { |
| 132 | 126 | $field_attributes = $attributes; |
| 133 | - if(isset($attributes['label'])) |
|
| 134 | - unset($field_attributes['label']); |
|
| 127 | + if(isset($attributes['label'])) { |
|
| 128 | + unset($field_attributes['label']); |
|
| 129 | + } |
|
| 135 | 130 | |
| 136 | 131 | return sprintf('%s %s', self::label($model,$field_name,$attributes,$errors), self::field($model,$field_name,$field_attributes,$errors)); |
| 137 | 132 | } |
@@ -148,14 +143,15 @@ discard block |
||
| 148 | 143 | $form_field = ''; |
| 149 | 144 | if($column->is_auto_incremented()) |
| 150 | 145 | { |
| 151 | - if(!$model->is_new()) |
|
| 152 | - $form_field = self::field($model,$column_name); |
|
| 153 | - } |
|
| 154 | - else |
|
| 146 | + if(!$model->is_new()) { |
|
| 147 | + $form_field = self::field($model,$column_name); |
|
| 148 | + } |
|
| 149 | + } else |
|
| 155 | 150 | { |
| 156 | 151 | $form_field = self::field_with_label($model,$column_name); |
| 157 | - if(!is_null($group_class)) |
|
| 158 | - $form_field = new Element('div',$form_field, ['class' => $group_class]); |
|
| 152 | + if(!is_null($group_class)) { |
|
| 153 | + $form_field = new Element('div',$form_field, ['class' => $group_class]); |
|
| 154 | + } |
|
| 159 | 155 | } |
| 160 | 156 | $ret .= PHP_EOL.$form_field; |
| 161 | 157 | } |
@@ -3,26 +3,26 @@ discard block |
||
| 3 | 3 | namespace HexMakina\kadro; |
| 4 | 4 | |
| 5 | 5 | use \HexMakina\Crudites\Interfaces\ModelInterface; |
| 6 | -use \HexMakina\Format\HTML\{Form,Element}; |
|
| 6 | +use \HexMakina\Format\HTML\{Form, Element}; |
|
| 7 | 7 | |
| 8 | 8 | class TableToForm |
| 9 | 9 | { |
| 10 | - private static function compute_field_value($model,$field_name) |
|
| 10 | + private static function compute_field_value($model, $field_name) |
|
| 11 | 11 | { |
| 12 | - if(method_exists($model,$field_name)) |
|
| 12 | + if (method_exists($model, $field_name)) |
|
| 13 | 13 | return $model->$field_name(); |
| 14 | 14 | |
| 15 | - if(property_exists($model,$field_name)) |
|
| 15 | + if (property_exists($model, $field_name)) |
|
| 16 | 16 | return $model->$field_name; |
| 17 | 17 | |
| 18 | 18 | return ''; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - public static function label($model,$field_name,$attributes=[],$errors=[]) |
|
| 21 | + public static function label($model, $field_name, $attributes = [], $errors = []) |
|
| 22 | 22 | { |
| 23 | 23 | $label_content = $field_name; |
| 24 | 24 | |
| 25 | - if(isset($attributes['label'])) |
|
| 25 | + if (isset($attributes['label'])) |
|
| 26 | 26 | { |
| 27 | 27 | $label_content = $attributes['label']; |
| 28 | 28 | unset($attributes['label']); |
@@ -44,66 +44,66 @@ discard block |
||
| 44 | 44 | return $ret; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - public static function field(ModelInterface $model,$field_name,$attributes=[],$errors=[]) : string |
|
| 47 | + public static function field(ModelInterface $model, $field_name, $attributes = [], $errors = []) : string |
|
| 48 | 48 | { |
| 49 | - $field_value = $attributes['value'] ?? self::compute_field_value($model,$field_name); |
|
| 49 | + $field_value = $attributes['value'] ?? self::compute_field_value($model, $field_name); |
|
| 50 | 50 | $attributes['name'] = $attributes['name'] ?? $field_name; |
| 51 | 51 | |
| 52 | 52 | $table = get_class($model)::table(); |
| 53 | 53 | |
| 54 | - if(is_null($table->column($field_name))) |
|
| 55 | - return Form::input($field_name,$field_value,$attributes,$errors); |
|
| 54 | + if (is_null($table->column($field_name))) |
|
| 55 | + return Form::input($field_name, $field_value, $attributes, $errors); |
|
| 56 | 56 | |
| 57 | 57 | $ret = ''; |
| 58 | 58 | |
| 59 | 59 | $field = $table->column($field_name); |
| 60 | 60 | |
| 61 | 61 | |
| 62 | - if(isset($attributes['required']) && $attributes['required'] === false) |
|
| 62 | + if (isset($attributes['required']) && $attributes['required'] === false) |
|
| 63 | 63 | unset($attributes['required']); |
| 64 | 64 | |
| 65 | - elseif(!$field->is_nullable()) |
|
| 65 | + elseif (!$field->is_nullable()) |
|
| 66 | 66 | $attributes[] = 'required'; |
| 67 | 67 | |
| 68 | - if($field->is_auto_incremented()) |
|
| 68 | + if ($field->is_auto_incremented()) |
|
| 69 | 69 | { |
| 70 | - $ret .= Form::hidden($field->name(),$field_value); |
|
| 70 | + $ret .= Form::hidden($field->name(), $field_value); |
|
| 71 | 71 | } |
| 72 | - elseif($field->type()->is_boolean()) |
|
| 72 | + elseif ($field->type()->is_boolean()) |
|
| 73 | 73 | { |
| 74 | 74 | $option_list = $attributes['values'] ?? [0 => 0, 1 => 1]; |
| 75 | - $ret .= Form::select($field->name(), $option_list ,$field_value, $attributes); // |
|
| 75 | + $ret .= Form::select($field->name(), $option_list, $field_value, $attributes); // |
|
| 76 | 76 | } |
| 77 | - elseif($field->type()->is_integer()) |
|
| 77 | + elseif ($field->type()->is_integer()) |
|
| 78 | 78 | { |
| 79 | - $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
|
| 79 | + $ret .= Form::input($field->name(), $field_value, $attributes, $errors); |
|
| 80 | 80 | } |
| 81 | - elseif($field->type()->is_year()) |
|
| 81 | + elseif ($field->type()->is_year()) |
|
| 82 | 82 | { |
| 83 | 83 | $attributes['size'] = $attributes['maxlength'] = 4; |
| 84 | - $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
|
| 84 | + $ret .= Form::input($field->name(), $field_value, $attributes, $errors); |
|
| 85 | 85 | } |
| 86 | - elseif($field->type()->is_date()) |
|
| 86 | + elseif ($field->type()->is_date()) |
|
| 87 | 87 | { |
| 88 | - $ret .= Form::date($field->name(),$field_value,$attributes,$errors); |
|
| 88 | + $ret .= Form::date($field->name(), $field_value, $attributes, $errors); |
|
| 89 | 89 | } |
| 90 | - elseif($field->type()->is_time()) |
|
| 90 | + elseif ($field->type()->is_time()) |
|
| 91 | 91 | { |
| 92 | - $ret .= Form::time($field->name(),$field_value,$attributes,$errors); |
|
| 92 | + $ret .= Form::time($field->name(), $field_value, $attributes, $errors); |
|
| 93 | 93 | } |
| 94 | - elseif($field->type()->is_datetime()) |
|
| 94 | + elseif ($field->type()->is_datetime()) |
|
| 95 | 95 | { |
| 96 | - $ret .= Form::datetime($field->name(),$field_value,$attributes,$errors); |
|
| 96 | + $ret .= Form::datetime($field->name(), $field_value, $attributes, $errors); |
|
| 97 | 97 | } |
| 98 | - elseif($field->type()->is_text()) |
|
| 98 | + elseif ($field->type()->is_text()) |
|
| 99 | 99 | { |
| 100 | - $ret .= Form::textarea($field->name(),$field_value,$attributes,$errors); |
|
| 100 | + $ret .= Form::textarea($field->name(), $field_value, $attributes, $errors); |
|
| 101 | 101 | } |
| 102 | - elseif($field->type()->is_enum()) |
|
| 102 | + elseif ($field->type()->is_enum()) |
|
| 103 | 103 | { |
| 104 | 104 | |
| 105 | 105 | $enum_values = []; |
| 106 | - foreach($field->type()->enum_values() as $e_val) |
|
| 106 | + foreach ($field->type()->enum_values() as $e_val) |
|
| 107 | 107 | $enum_values[$e_val] = $e_val; |
| 108 | 108 | |
| 109 | 109 | $selected = $attributes['value'] ?? $field_value ?? ''; |
@@ -112,50 +112,50 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | // throw new \Exception('ENUM IS NOT HANDLED BY TableToFom'); |
| 114 | 114 | } |
| 115 | - elseif($field->type()->is_string()) |
|
| 115 | + elseif ($field->type()->is_string()) |
|
| 116 | 116 | { |
| 117 | 117 | $max_length = $field->type()->length(); |
| 118 | 118 | $attributes['size'] = $attributes['maxlength'] = $max_length; |
| 119 | - $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
|
| 119 | + $ret .= Form::input($field->name(), $field_value, $attributes, $errors); |
|
| 120 | 120 | } |
| 121 | 121 | else |
| 122 | 122 | { |
| 123 | - $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
|
| 123 | + $ret .= Form::input($field->name(), $field_value, $attributes, $errors); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | |
| 127 | 127 | return $ret; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - public static function field_with_label($model,$field_name,$attributes=[],$errors=[]) : string |
|
| 130 | + public static function field_with_label($model, $field_name, $attributes = [], $errors = []) : string |
|
| 131 | 131 | { |
| 132 | 132 | $field_attributes = $attributes; |
| 133 | - if(isset($attributes['label'])) |
|
| 133 | + if (isset($attributes['label'])) |
|
| 134 | 134 | unset($field_attributes['label']); |
| 135 | 135 | |
| 136 | - return sprintf('%s %s', self::label($model,$field_name,$attributes,$errors), self::field($model,$field_name,$field_attributes,$errors)); |
|
| 136 | + return sprintf('%s %s', self::label($model, $field_name, $attributes, $errors), self::field($model, $field_name, $field_attributes, $errors)); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | |
| 140 | - public static function fields(ModelInterface $model,$group_class=null) : string |
|
| 140 | + public static function fields(ModelInterface $model, $group_class = null) : string |
|
| 141 | 141 | { |
| 142 | 142 | $table = get_class($model)::table(); |
| 143 | 143 | $ret = ''; |
| 144 | - foreach($table->columns() as $column_name => $column) |
|
| 144 | + foreach ($table->columns() as $column_name => $column) |
|
| 145 | 145 | { |
| 146 | 146 | // vd($column_name); |
| 147 | 147 | |
| 148 | 148 | $form_field = ''; |
| 149 | - if($column->is_auto_incremented()) |
|
| 149 | + if ($column->is_auto_incremented()) |
|
| 150 | 150 | { |
| 151 | - if(!$model->is_new()) |
|
| 152 | - $form_field = self::field($model,$column_name); |
|
| 151 | + if (!$model->is_new()) |
|
| 152 | + $form_field = self::field($model, $column_name); |
|
| 153 | 153 | } |
| 154 | 154 | else |
| 155 | 155 | { |
| 156 | - $form_field = self::field_with_label($model,$column_name); |
|
| 157 | - if(!is_null($group_class)) |
|
| 158 | - $form_field = new Element('div',$form_field, ['class' => $group_class]); |
|
| 156 | + $form_field = self::field_with_label($model, $column_name); |
|
| 157 | + if (!is_null($group_class)) |
|
| 158 | + $form_field = new Element('div', $form_field, ['class' => $group_class]); |
|
| 159 | 159 | } |
| 160 | 160 | $ret .= PHP_EOL.$form_field; |
| 161 | 161 | } |
@@ -31,10 +31,10 @@ discard block |
||
| 31 | 31 | return $this->iso_name().' ('.$this->Part3.')'; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - public function traceable() : bool |
|
| 35 | - { |
|
| 36 | - return false; |
|
| 37 | - } |
|
| 34 | + public function traceable() : bool |
|
| 35 | + { |
|
| 36 | + return false; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | public function iso_name() |
| 40 | 40 | { |
@@ -102,9 +102,9 @@ discard block |
||
| 102 | 102 | public static function search_language($term, $authority=null) |
| 103 | 103 | { |
| 104 | 104 | $rows = self::query_retrieve(['term' => $term, 'requires_authority' => $authority])->ret_ass(); |
| 105 | - $ret = []; |
|
| 106 | - foreach($rows as $row) |
|
| 107 | - $ret[$row[self::ISO_3]] = $row[self::ISO_NAME]; |
|
| 105 | + $ret = []; |
|
| 106 | + foreach($rows as $row) |
|
| 107 | + $ret[$row[self::ISO_3]] = $row[self::ISO_NAME]; |
|
| 108 | 108 | |
| 109 | 109 | return $ret; |
| 110 | 110 | } |
@@ -52,39 +52,39 @@ discard block |
||
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
| 55 | - public static function query_retrieve($filter=[], $options=[]) : \HexMakina\Crudites\Queries\BaseQuery |
|
| 55 | + public static function query_retrieve($filter = [], $options = []) : \HexMakina\Crudites\Queries\BaseQuery |
|
| 56 | 56 | { |
| 57 | 57 | |
| 58 | 58 | $searchable_fields = [self::ISO_NAME, self::ISO_3, self::ISO_2B, self::ISO_2T, self::ISO_1]; |
| 59 | 59 | |
| 60 | 60 | $Query = static::table()->select(); |
| 61 | 61 | |
| 62 | - if(isset($filter['name'])) |
|
| 62 | + if (isset($filter['name'])) |
|
| 63 | 63 | { |
| 64 | 64 | |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - if(isset($filter['code'])) |
|
| 67 | + if (isset($filter['code'])) |
|
| 68 | 68 | { |
| 69 | 69 | |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - if(isset($filter['term'])) |
|
| 72 | + if (isset($filter['term'])) |
|
| 73 | 73 | { |
| 74 | 74 | $Query->aw_filter_content(['term' => $filter['term'], 'fields' => $searchable_fields], $Query->table_label(), 'OR'); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - if(isset($filter['requires_authority']) && isset(self::ISO_SETS[$filter['requires_authority']])) |
|
| 77 | + if (isset($filter['requires_authority']) && isset(self::ISO_SETS[$filter['requires_authority']])) |
|
| 78 | 78 | { |
| 79 | 79 | $Query->aw_not_empty($filter['requires_authority']); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - if(isset($filter['types'])) |
|
| 82 | + if (isset($filter['types'])) |
|
| 83 | 83 | { |
| 84 | 84 | $wc = sprintf('AND Type IN (\'%s\') ', implode('\', \'', array_keys(self::types()))); |
| 85 | 85 | $Query->and_where($wc); |
| 86 | 86 | } |
| 87 | - if(isset($filter['scopes'])) |
|
| 87 | + if (isset($filter['scopes'])) |
|
| 88 | 88 | { |
| 89 | 89 | $wc = sprintf('AND Scope IN (\'%s\') ', implode('\', \'', array_keys(self::scopes()))); |
| 90 | 90 | $Query->and_where($wc); |
@@ -99,11 +99,11 @@ discard block |
||
| 99 | 99 | return $Query; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - public static function search_language($term, $authority=null) |
|
| 102 | + public static function search_language($term, $authority = null) |
|
| 103 | 103 | { |
| 104 | 104 | $rows = self::query_retrieve(['term' => $term, 'requires_authority' => $authority])->ret_ass(); |
| 105 | 105 | $ret = []; |
| 106 | - foreach($rows as $row) |
|
| 106 | + foreach ($rows as $row) |
|
| 107 | 107 | $ret[$row[self::ISO_3]] = $row[self::ISO_NAME]; |
| 108 | 108 | |
| 109 | 109 | return $ret; |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | $Query->aw_eq(self::ISO_3, $code); |
| 116 | 116 | $rows = $Query->ret_col(); |
| 117 | 117 | |
| 118 | - if(isset($rows[0])) // only 1 result |
|
| 118 | + if (isset($rows[0])) // only 1 result |
|
| 119 | 119 | return current($rows); |
| 120 | 120 | |
| 121 | 121 | return null; // no results |
@@ -103,8 +103,9 @@ discard block |
||
| 103 | 103 | { |
| 104 | 104 | $rows = self::query_retrieve(['term' => $term, 'requires_authority' => $authority])->ret_ass(); |
| 105 | 105 | $ret = []; |
| 106 | - foreach($rows as $row) |
|
| 107 | - $ret[$row[self::ISO_3]] = $row[self::ISO_NAME]; |
|
| 106 | + foreach($rows as $row) { |
|
| 107 | + $ret[$row[self::ISO_3]] = $row[self::ISO_NAME]; |
|
| 108 | + } |
|
| 108 | 109 | |
| 109 | 110 | return $ret; |
| 110 | 111 | } |
@@ -115,8 +116,10 @@ discard block |
||
| 115 | 116 | $Query->aw_eq(self::ISO_3, $code); |
| 116 | 117 | $rows = $Query->ret_col(); |
| 117 | 118 | |
| 118 | - if(isset($rows[0])) // only 1 result |
|
| 119 | + if(isset($rows[0])) { |
|
| 120 | + // only 1 result |
|
| 119 | 121 | return current($rows); |
| 122 | + } |
|
| 120 | 123 | |
| 121 | 124 | return null; // no results |
| 122 | 125 | } |
@@ -10,10 +10,10 @@ |
||
| 10 | 10 | const TABLE_NAME = 'kadro_traduki'; |
| 11 | 11 | const TABLE_ALIAS = 'traduko'; |
| 12 | 12 | |
| 13 | - public function traceable() : bool |
|
| 14 | - { |
|
| 15 | - return false; |
|
| 16 | - } |
|
| 13 | + public function traceable() : bool |
|
| 14 | + { |
|
| 15 | + return false; |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | 18 | public function immortal() : bool |
| 19 | 19 | { |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | return false; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - public static function query_retrieve($filters=[], $options=[]) : Select |
|
| 23 | + public static function query_retrieve($filters = [], $options = []) : Select |
|
| 24 | 24 | { |
| 25 | 25 | $Query = static::table()->select(); |
| 26 | 26 | $Query->order_by(['kategorio', 'ASC']); |
@@ -23,22 +23,22 @@ |
||
| 23 | 23 | |
| 24 | 24 | public static function today($format=Dato::FORMAT) |
| 25 | 25 | { |
| 26 | - return Dato::today($format); |
|
| 27 | - } |
|
| 26 | + return Dato::today($format); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | 29 | public static function date($date=null, $format=Dato::FORMAT) : string |
| 30 | - { |
|
| 31 | - return Dato::format($date); |
|
| 32 | - } |
|
| 30 | + { |
|
| 31 | + return Dato::format($date); |
|
| 32 | + } |
|
| 33 | 33 | // |
| 34 | 34 | // //------------------------------------------------------------ MySQL DateTime helpers |
| 35 | 35 | // public static function year($date=null) : string |
| 36 | - // { |
|
| 37 | - // return Dato::format($date, Dato::FORMAT_YEAR); |
|
| 38 | - // } |
|
| 36 | + // { |
|
| 37 | + // return Dato::format($date, Dato::FORMAT_YEAR); |
|
| 38 | + // } |
|
| 39 | 39 | // |
| 40 | - // public static function datetime($date=null) : string |
|
| 41 | - // { |
|
| 42 | - // return DatoTempo::format($date); |
|
| 43 | - // } |
|
| 40 | + // public static function datetime($date=null) : string |
|
| 41 | + // { |
|
| 42 | + // return DatoTempo::format($date); |
|
| 43 | + // } |
|
| 44 | 44 | } |
@@ -21,12 +21,12 @@ |
||
| 21 | 21 | return $this->__toString(); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - public static function today($format=Dato::FORMAT) |
|
| 24 | + public static function today($format = Dato::FORMAT) |
|
| 25 | 25 | { |
| 26 | 26 | return Dato::today($format); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - public static function date($date=null, $format=Dato::FORMAT) : string |
|
| 29 | + public static function date($date = null, $format = Dato::FORMAT) : string |
|
| 30 | 30 | { |
| 31 | 31 | return Dato::format($date); |
| 32 | 32 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | public function __debugInfo() |
| 17 | 17 | { |
| 18 | 18 | $dbg = get_object_vars($this); |
| 19 | - $dbg['configurations']['template_engine'] = isset($dbg['configurations']['template_engine'])? get_class($dbg['configurations']['template_engine']) : 'NOT SET'; |
|
| 19 | + $dbg['configurations']['template_engine'] = isset($dbg['configurations']['template_engine']) ? get_class($dbg['configurations']['template_engine']) : 'NOT SET'; |
|
| 20 | 20 | |
| 21 | 21 | return $dbg; |
| 22 | 22 | } |
@@ -34,45 +34,45 @@ discard block |
||
| 34 | 34 | public function get($configuration) |
| 35 | 35 | { |
| 36 | 36 | |
| 37 | - if(!is_string($configuration)) |
|
| 37 | + if (!is_string($configuration)) |
|
| 38 | 38 | throw new LamentException($configuration); |
| 39 | 39 | |
| 40 | - if($this->has($configuration)) |
|
| 40 | + if ($this->has($configuration)) |
|
| 41 | 41 | return $this->configurations[$configuration]; |
| 42 | 42 | |
| 43 | 43 | |
| 44 | 44 | // fallbacks |
| 45 | - if(preg_match('/^settings\./', $configuration, $m) === 1) |
|
| 45 | + if (preg_match('/^settings\./', $configuration, $m) === 1) |
|
| 46 | 46 | { |
| 47 | 47 | $ret = $this->configurations; |
| 48 | - foreach(explode('.', $configuration) as $k) |
|
| 48 | + foreach (explode('.', $configuration) as $k) |
|
| 49 | 49 | { |
| 50 | - if(!isset($ret[$k])) |
|
| 50 | + if (!isset($ret[$k])) |
|
| 51 | 51 | throw new ConfigurationException($configuration); |
| 52 | 52 | $ret = $ret[$k]; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | return $ret; |
| 56 | 56 | } |
| 57 | - elseif(class_exists($configuration)) // auto create instances |
|
| 57 | + elseif (class_exists($configuration)) // auto create instances |
|
| 58 | 58 | { |
| 59 | 59 | |
| 60 | 60 | $rc = new \ReflectionClass($configuration); |
| 61 | 61 | |
| 62 | 62 | $construction_args = []; |
| 63 | 63 | $instance = null; |
| 64 | - if(!is_null($rc->getConstructor())) |
|
| 64 | + if (!is_null($rc->getConstructor())) |
|
| 65 | 65 | { |
| 66 | - foreach($rc->getConstructor()->getParameters() as $param) |
|
| 66 | + foreach ($rc->getConstructor()->getParameters() as $param) |
|
| 67 | 67 | { |
| 68 | - $construction_args []= $this->get($param->getType().''); |
|
| 68 | + $construction_args [] = $this->get($param->getType().''); |
|
| 69 | 69 | } |
| 70 | 70 | $instance = $rc->newInstanceArgs($construction_args); |
| 71 | 71 | } |
| 72 | 72 | else |
| 73 | 73 | $instance = $rc->newInstanceArgs(); |
| 74 | 74 | |
| 75 | - if($rc->hasMethod('set_container')) |
|
| 75 | + if ($rc->hasMethod('set_container')) |
|
| 76 | 76 | $instance->set_container($this); |
| 77 | 77 | |
| 78 | 78 | return $instance; |
@@ -34,11 +34,13 @@ discard block |
||
| 34 | 34 | public function get($configuration) |
| 35 | 35 | { |
| 36 | 36 | |
| 37 | - if(!is_string($configuration)) |
|
| 38 | - throw new LamentException($configuration); |
|
| 37 | + if(!is_string($configuration)) { |
|
| 38 | + throw new LamentException($configuration); |
|
| 39 | + } |
|
| 39 | 40 | |
| 40 | - if($this->has($configuration)) |
|
| 41 | - return $this->configurations[$configuration]; |
|
| 41 | + if($this->has($configuration)) { |
|
| 42 | + return $this->configurations[$configuration]; |
|
| 43 | + } |
|
| 42 | 44 | |
| 43 | 45 | |
| 44 | 46 | // fallbacks |
@@ -47,17 +49,19 @@ discard block |
||
| 47 | 49 | $ret = $this->configurations; |
| 48 | 50 | foreach(explode('.', $configuration) as $k) |
| 49 | 51 | { |
| 50 | - if(!isset($ret[$k])) |
|
| 51 | - throw new ConfigurationException($configuration); |
|
| 52 | + if(!isset($ret[$k])) { |
|
| 53 | + throw new ConfigurationException($configuration); |
|
| 54 | + } |
|
| 52 | 55 | $ret = $ret[$k]; |
| 53 | 56 | } |
| 54 | 57 | |
| 55 | 58 | return $ret; |
| 56 | - } |
|
| 57 | - elseif(class_exists($configuration)) // auto create instances |
|
| 59 | + } elseif(class_exists($configuration)) { |
|
| 60 | + // auto create instances |
|
| 58 | 61 | { |
| 59 | 62 | |
| 60 | 63 | $rc = new \ReflectionClass($configuration); |
| 64 | + } |
|
| 61 | 65 | |
| 62 | 66 | $construction_args = []; |
| 63 | 67 | $instance = null; |
@@ -68,12 +72,13 @@ discard block |
||
| 68 | 72 | $construction_args []= $this->get($param->getType().''); |
| 69 | 73 | } |
| 70 | 74 | $instance = $rc->newInstanceArgs($construction_args); |
| 75 | + } else { |
|
| 76 | + $instance = $rc->newInstanceArgs(); |
|
| 71 | 77 | } |
| 72 | - else |
|
| 73 | - $instance = $rc->newInstanceArgs(); |
|
| 74 | 78 | |
| 75 | - if($rc->hasMethod('set_container')) |
|
| 76 | - $instance->set_container($this); |
|
| 79 | + if($rc->hasMethod('set_container')) { |
|
| 80 | + $instance->set_container($this); |
|
| 81 | + } |
|
| 77 | 82 | |
| 78 | 83 | return $instance; |
| 79 | 84 | } |
@@ -265,7 +265,7 @@ |
||
| 265 | 265 | * const NOTICE = 'notice'; // Normal but significant events. |
| 266 | 266 | * const INFO = 'info'; // Interesting events. User logs in, SQL logs. |
| 267 | 267 | * const DEBUG = 'debug'; // Detailed debug information. |
| 268 | - */ |
|
| 268 | + */ |
|
| 269 | 269 | private static function map_error_level_to_log_level($level) : string |
| 270 | 270 | { |
| 271 | 271 | // http://php.net/manual/en/errorfunc.constants.php |
@@ -68,11 +68,11 @@ discard block |
||
| 68 | 68 | $context['class'] = get_class($throwable); |
| 69 | 69 | $context['trace'] = $throwable->getTrace(); |
| 70 | 70 | |
| 71 | - if(is_subclass_of($throwable, 'Error') || get_class($throwable) === 'Error') |
|
| 72 | - (new LogLaddy())->alert(self::INTERNAL_ERROR, $context); |
|
| 73 | - elseif(is_subclass_of($throwable, 'Exception') || get_class($throwable) === 'Exception') |
|
| 74 | - (new LogLaddy())->notice(self::USER_EXCEPTION, $context); |
|
| 75 | - else |
|
| 71 | + if(is_subclass_of($throwable, 'Error') || get_class($throwable) === 'Error') { |
|
| 72 | + (new LogLaddy())->alert(self::INTERNAL_ERROR, $context); |
|
| 73 | + } elseif(is_subclass_of($throwable, 'Exception') || get_class($throwable) === 'Exception') { |
|
| 74 | + (new LogLaddy())->notice(self::USER_EXCEPTION, $context); |
|
| 75 | + } else |
|
| 76 | 76 | { |
| 77 | 77 | die('This Throwable is not an Error or an Exception. This is unfortunate.'); |
| 78 | 78 | } |
@@ -108,15 +108,15 @@ discard block |
||
| 108 | 108 | error_log($display_error); |
| 109 | 109 | $display_error.= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false); |
| 110 | 110 | self::HTTP_500($display_error); |
| 111 | - } |
|
| 112 | - elseif($this->system_halted($level)) // analyses error level |
|
| 111 | + } elseif($this->system_halted($level)) { |
|
| 112 | + // analyses error level |
|
| 113 | 113 | { |
| 114 | 114 | $display_error = sprintf(PHP_EOL.'%s in file %s:%d'.PHP_EOL.'%s', $level, \HexMakina\Debugger\Debugger::format_file($context['file']), $context['line'], $message); |
| 115 | + } |
|
| 115 | 116 | error_log($display_error); |
| 116 | 117 | $display_error.= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false); |
| 117 | 118 | self::HTTP_500($display_error); |
| 118 | - } |
|
| 119 | - else |
|
| 119 | + } else |
|
| 120 | 120 | {// --- Handles user messages, through SESSION storage |
| 121 | 121 | $this->report_to_user($level, $message, $context); |
| 122 | 122 | } |
@@ -165,11 +165,13 @@ discard block |
||
| 165 | 165 | // ----------------------------------------------------------- User messages:add one |
| 166 | 166 | public function report_to_user($level, $message, $context = []) |
| 167 | 167 | { |
| 168 | - if(!isset($_SESSION[self::REPORTING_USER])) |
|
| 169 | - $_SESSION[self::REPORTING_USER] = []; |
|
| 168 | + if(!isset($_SESSION[self::REPORTING_USER])) { |
|
| 169 | + $_SESSION[self::REPORTING_USER] = []; |
|
| 170 | + } |
|
| 170 | 171 | |
| 171 | - if(!isset($_SESSION[self::REPORTING_USER][$level])) |
|
| 172 | - $_SESSION[self::REPORTING_USER][$level] = []; |
|
| 172 | + if(!isset($_SESSION[self::REPORTING_USER][$level])) { |
|
| 173 | + $_SESSION[self::REPORTING_USER][$level] = []; |
|
| 174 | + } |
|
| 173 | 175 | |
| 174 | 176 | $_SESSION[self::REPORTING_USER][$level][] = [$message, $context]; |
| 175 | 177 | } |
@@ -206,9 +208,11 @@ discard block |
||
| 206 | 208 | public function changes($options=[]) |
| 207 | 209 | { |
| 208 | 210 | |
| 209 | - if(!isset($options['limit']) || empty($options['limit'])) |
|
| 210 | - $limit = 1000; |
|
| 211 | - else $limit = intval($options['limit']); |
|
| 211 | + if(!isset($options['limit']) || empty($options['limit'])) { |
|
| 212 | + $limit = 1000; |
|
| 213 | + } else { |
|
| 214 | + $limit = intval($options['limit']); |
|
| 215 | + } |
|
| 212 | 216 | |
| 213 | 217 | // TODO SELECT field order can't change without adapting the result parsing code (foreach $res) |
| 214 | 218 | $table = Crudites::inspect(self::LOG_TABLE_NAME); |
@@ -226,16 +230,22 @@ discard block |
||
| 226 | 230 | |
| 227 | 231 | foreach($options as $o => $v) |
| 228 | 232 | { |
| 229 | - if(preg_match('/id/', $o)) $q->aw_eq('query_id', $v); |
|
| 230 | - elseif(preg_match('/tables/', $o)) $q->aw_string_in('query_table', is_array($v) ? $v : [$v]); |
|
| 231 | - elseif(preg_match('/table/', $o)) $q->aw_eq('query_table', $v); |
|
| 232 | - elseif(preg_match('/(type|action)/', $o)) $q->aw_string_in('query_type', is_array($v) ? $v : [$v]); |
|
| 233 | - elseif(preg_match('/(date|query_on)/', $o)) $q->aw_like('query_on', "$v%"); |
|
| 234 | - elseif(preg_match('/(oper|user|query_by)/', $o)) $q->aw_eq('query_by', $v); |
|
| 233 | + if(preg_match('/id/', $o)) { |
|
| 234 | + $q->aw_eq('query_id', $v); |
|
| 235 | + } elseif(preg_match('/tables/', $o)) { |
|
| 236 | + $q->aw_string_in('query_table', is_array($v) ? $v : [$v]); |
|
| 237 | + } elseif(preg_match('/table/', $o)) { |
|
| 238 | + $q->aw_eq('query_table', $v); |
|
| 239 | + } elseif(preg_match('/(type|action)/', $o)) { |
|
| 240 | + $q->aw_string_in('query_type', is_array($v) ? $v : [$v]); |
|
| 241 | + } elseif(preg_match('/(date|query_on)/', $o)) { |
|
| 242 | + $q->aw_like('query_on', "$v%"); |
|
| 243 | + } elseif(preg_match('/(oper|user|query_by)/', $o)) { |
|
| 244 | + $q->aw_eq('query_by', $v); |
|
| 245 | + } |
|
| 235 | 246 | } |
| 236 | 247 | |
| 237 | - try{$q->run();} |
|
| 238 | - catch(CruditesException $e){vdt($e);return false;} |
|
| 248 | + try{$q->run();} catch(CruditesException $e){vdt($e);return false;} |
|
| 239 | 249 | |
| 240 | 250 | $res = $q->ret_num(); // ret num to list() |
| 241 | 251 | // ddt($res); |
@@ -245,10 +255,12 @@ discard block |
||
| 245 | 255 | { |
| 246 | 256 | list($working_day, $class, $instance_id, $logs) = $r; |
| 247 | 257 | |
| 248 | - if(!isset($ret[$working_day])) |
|
| 249 | - $ret[$working_day] = []; |
|
| 250 | - if(!isset($ret[$working_day][$class])) |
|
| 251 | - $ret[$working_day][$class] = []; |
|
| 258 | + if(!isset($ret[$working_day])) { |
|
| 259 | + $ret[$working_day] = []; |
|
| 260 | + } |
|
| 261 | + if(!isset($ret[$working_day][$class])) { |
|
| 262 | + $ret[$working_day][$class] = []; |
|
| 263 | + } |
|
| 252 | 264 | |
| 253 | 265 | $ret[$working_day][$class][$instance_id] = $logs; |
| 254 | 266 | } |
@@ -282,8 +294,9 @@ discard block |
||
| 282 | 294 | $m[E_STRICT]=$m[E_DEPRECATED]=$m[E_USER_DEPRECATED]=$m[E_ALL]=LogLevel::DEBUG; |
| 283 | 295 | $m[2048]=$m[8192]=$m[16384]=$m[32767]=LogLevel::DEBUG; |
| 284 | 296 | |
| 285 | - if(isset($m[$level])) |
|
| 286 | - return $m[$level]; |
|
| 297 | + if(isset($m[$level])) { |
|
| 298 | + return $m[$level]; |
|
| 299 | + } |
|
| 287 | 300 | |
| 288 | 301 | throw new \Exception(__FUNCTION__."($level): $level is unknown"); |
| 289 | 302 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | namespace HexMakina\kadro\Logger; |
| 13 | 13 | |
| 14 | -use \HexMakina\Crudites\{Crudites,CruditesException,Table}; |
|
| 14 | +use \HexMakina\Crudites\{Crudites, CruditesException, Table}; |
|
| 15 | 15 | use \HexMakina\Crudites\TableInterface; |
| 16 | 16 | |
| 17 | 17 | |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | $context['class'] = get_class($throwable); |
| 69 | 69 | $context['trace'] = $throwable->getTrace(); |
| 70 | 70 | |
| 71 | - if(is_subclass_of($throwable, 'Error') || get_class($throwable) === 'Error') |
|
| 71 | + if (is_subclass_of($throwable, 'Error') || get_class($throwable) === 'Error') |
|
| 72 | 72 | (new LogLaddy())->alert(self::INTERNAL_ERROR, $context); |
| 73 | - elseif(is_subclass_of($throwable, 'Exception') || get_class($throwable) === 'Exception') |
|
| 73 | + elseif (is_subclass_of($throwable, 'Exception') || get_class($throwable) === 'Exception') |
|
| 74 | 74 | (new LogLaddy())->notice(self::USER_EXCEPTION, $context); |
| 75 | 75 | else |
| 76 | 76 | { |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | public function system_halted($level) |
| 83 | 83 | { |
| 84 | 84 | |
| 85 | - switch($level) |
|
| 85 | + switch ($level) |
|
| 86 | 86 | { |
| 87 | 87 | case LogLevel::ERROR: |
| 88 | 88 | case LogLevel::CRITICAL: |
@@ -101,19 +101,19 @@ discard block |
||
| 101 | 101 | $display_error = null; |
| 102 | 102 | |
| 103 | 103 | // --- Handles Throwables (exception_handler()) |
| 104 | - if($message==self::INTERNAL_ERROR || $message== self::USER_EXCEPTION) |
|
| 104 | + if ($message == self::INTERNAL_ERROR || $message == self::USER_EXCEPTION) |
|
| 105 | 105 | { |
| 106 | 106 | $this->has_halting_messages = true; |
| 107 | 107 | $display_error = \HexMakina\Debugger\Debugger::format_throwable_message($context['class'], $context['code'], $context['file'], $context['line'], $context['text']); |
| 108 | 108 | error_log($display_error); |
| 109 | - $display_error.= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false); |
|
| 109 | + $display_error .= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false); |
|
| 110 | 110 | self::HTTP_500($display_error); |
| 111 | 111 | } |
| 112 | - elseif($this->system_halted($level)) // analyses error level |
|
| 112 | + elseif ($this->system_halted($level)) // analyses error level |
|
| 113 | 113 | { |
| 114 | 114 | $display_error = sprintf(PHP_EOL.'%s in file %s:%d'.PHP_EOL.'%s', $level, \HexMakina\Debugger\Debugger::format_file($context['file']), $context['line'], $message); |
| 115 | 115 | error_log($display_error); |
| 116 | - $display_error.= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false); |
|
| 116 | + $display_error .= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false); |
|
| 117 | 117 | self::HTTP_500($display_error); |
| 118 | 118 | } |
| 119 | 119 | else |
@@ -165,10 +165,10 @@ discard block |
||
| 165 | 165 | // ----------------------------------------------------------- User messages:add one |
| 166 | 166 | public function report_to_user($level, $message, $context = []) |
| 167 | 167 | { |
| 168 | - if(!isset($_SESSION[self::REPORTING_USER])) |
|
| 168 | + if (!isset($_SESSION[self::REPORTING_USER])) |
|
| 169 | 169 | $_SESSION[self::REPORTING_USER] = []; |
| 170 | 170 | |
| 171 | - if(!isset($_SESSION[self::REPORTING_USER][$level])) |
|
| 171 | + if (!isset($_SESSION[self::REPORTING_USER][$level])) |
|
| 172 | 172 | $_SESSION[self::REPORTING_USER][$level] = []; |
| 173 | 173 | |
| 174 | 174 | $_SESSION[self::REPORTING_USER][$level][] = [$message, $context]; |
@@ -203,16 +203,16 @@ discard block |
||
| 203 | 203 | // } |
| 204 | 204 | |
| 205 | 205 | // ----------------------------------------------------------- CRUD Tracking:get for many models |
| 206 | - public function changes($options=[]) |
|
| 206 | + public function changes($options = []) |
|
| 207 | 207 | { |
| 208 | 208 | |
| 209 | - if(!isset($options['limit']) || empty($options['limit'])) |
|
| 209 | + if (!isset($options['limit']) || empty($options['limit'])) |
|
| 210 | 210 | $limit = 1000; |
| 211 | 211 | else $limit = intval($options['limit']); |
| 212 | 212 | |
| 213 | 213 | // TODO SELECT field order can't change without adapting the result parsing code (foreach $res) |
| 214 | 214 | $table = Crudites::inspect(self::LOG_TABLE_NAME); |
| 215 | - $select_fields = ['SUBSTR(query_on, 1, 10) AS working_day', 'query_table', 'query_id', 'GROUP_CONCAT(DISTINCT query_type, "-", query_by) as action_by']; |
|
| 215 | + $select_fields = ['SUBSTR(query_on, 1, 10) AS working_day', 'query_table', 'query_id', 'GROUP_CONCAT(DISTINCT query_type, "-", query_by) as action_by']; |
|
| 216 | 216 | $q = $table->select($select_fields); |
| 217 | 217 | $q->order_by(['', 'working_day', 'DESC']); |
| 218 | 218 | $q->order_by([self::LOG_TABLE_NAME, 'query_table', 'DESC']); |
@@ -224,30 +224,30 @@ discard block |
||
| 224 | 224 | $q->having("action_by NOT LIKE '%D%'"); |
| 225 | 225 | $q->limit($limit); |
| 226 | 226 | |
| 227 | - foreach($options as $o => $v) |
|
| 227 | + foreach ($options as $o => $v) |
|
| 228 | 228 | { |
| 229 | - if(preg_match('/id/', $o)) $q->aw_eq('query_id', $v); |
|
| 230 | - elseif(preg_match('/tables/', $o)) $q->aw_string_in('query_table', is_array($v) ? $v : [$v]); |
|
| 231 | - elseif(preg_match('/table/', $o)) $q->aw_eq('query_table', $v); |
|
| 232 | - elseif(preg_match('/(type|action)/', $o)) $q->aw_string_in('query_type', is_array($v) ? $v : [$v]); |
|
| 233 | - elseif(preg_match('/(date|query_on)/', $o)) $q->aw_like('query_on', "$v%"); |
|
| 234 | - elseif(preg_match('/(oper|user|query_by)/', $o)) $q->aw_eq('query_by', $v); |
|
| 229 | + if (preg_match('/id/', $o)) $q->aw_eq('query_id', $v); |
|
| 230 | + elseif (preg_match('/tables/', $o)) $q->aw_string_in('query_table', is_array($v) ? $v : [$v]); |
|
| 231 | + elseif (preg_match('/table/', $o)) $q->aw_eq('query_table', $v); |
|
| 232 | + elseif (preg_match('/(type|action)/', $o)) $q->aw_string_in('query_type', is_array($v) ? $v : [$v]); |
|
| 233 | + elseif (preg_match('/(date|query_on)/', $o)) $q->aw_like('query_on', "$v%"); |
|
| 234 | + elseif (preg_match('/(oper|user|query_by)/', $o)) $q->aw_eq('query_by', $v); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - try{$q->run();} |
|
| 238 | - catch(CruditesException $e){vdt($e);return false;} |
|
| 237 | + try {$q->run(); } |
|
| 238 | + catch (CruditesException $e) {vdt($e); return false; } |
|
| 239 | 239 | |
| 240 | 240 | $res = $q->ret_num(); // ret num to list() |
| 241 | 241 | // ddt($res); |
| 242 | 242 | $ret = []; |
| 243 | 243 | |
| 244 | - foreach($res as $r) |
|
| 244 | + foreach ($res as $r) |
|
| 245 | 245 | { |
| 246 | 246 | list($working_day, $class, $instance_id, $logs) = $r; |
| 247 | 247 | |
| 248 | - if(!isset($ret[$working_day])) |
|
| 248 | + if (!isset($ret[$working_day])) |
|
| 249 | 249 | $ret[$working_day] = []; |
| 250 | - if(!isset($ret[$working_day][$class])) |
|
| 250 | + if (!isset($ret[$working_day][$class])) |
|
| 251 | 251 | $ret[$working_day][$class] = []; |
| 252 | 252 | |
| 253 | 253 | $ret[$working_day][$class][$instance_id] = $logs; |
@@ -269,21 +269,21 @@ discard block |
||
| 269 | 269 | private static function map_error_level_to_log_level($level) : string |
| 270 | 270 | { |
| 271 | 271 | // http://php.net/manual/en/errorfunc.constants.php |
| 272 | - $m=[]; |
|
| 272 | + $m = []; |
|
| 273 | 273 | |
| 274 | - $m[E_ERROR]=$m[E_PARSE]=$m[E_CORE_ERROR]=$m[E_COMPILE_ERROR]=$m[E_USER_ERROR]=$m[E_RECOVERABLE_ERROR]=LogLevel::ALERT; |
|
| 275 | - $m[1]=$m[4]=$m[16]=$m[64]=$m[256]=$m[4096]=LogLevel::ALERT; |
|
| 274 | + $m[E_ERROR] = $m[E_PARSE] = $m[E_CORE_ERROR] = $m[E_COMPILE_ERROR] = $m[E_USER_ERROR] = $m[E_RECOVERABLE_ERROR] = LogLevel::ALERT; |
|
| 275 | + $m[1] = $m[4] = $m[16] = $m[64] = $m[256] = $m[4096] = LogLevel::ALERT; |
|
| 276 | 276 | |
| 277 | - $m[E_WARNING]=$m[E_CORE_WARNING]=$m[E_COMPILE_WARNING]=$m[E_USER_WARNING]=LogLevel::CRITICAL; |
|
| 278 | - $m[2]=$m[32]=$m[128]=$m[512]=LogLevel::CRITICAL; |
|
| 277 | + $m[E_WARNING] = $m[E_CORE_WARNING] = $m[E_COMPILE_WARNING] = $m[E_USER_WARNING] = LogLevel::CRITICAL; |
|
| 278 | + $m[2] = $m[32] = $m[128] = $m[512] = LogLevel::CRITICAL; |
|
| 279 | 279 | |
| 280 | - $m[E_NOTICE]=$m[E_USER_NOTICE]=LogLevel::ERROR; |
|
| 281 | - $m[8]=$m[1024]=LogLevel::ERROR; |
|
| 280 | + $m[E_NOTICE] = $m[E_USER_NOTICE] = LogLevel::ERROR; |
|
| 281 | + $m[8] = $m[1024] = LogLevel::ERROR; |
|
| 282 | 282 | |
| 283 | - $m[E_STRICT]=$m[E_DEPRECATED]=$m[E_USER_DEPRECATED]=$m[E_ALL]=LogLevel::DEBUG; |
|
| 284 | - $m[2048]=$m[8192]=$m[16384]=$m[32767]=LogLevel::DEBUG; |
|
| 283 | + $m[E_STRICT] = $m[E_DEPRECATED] = $m[E_USER_DEPRECATED] = $m[E_ALL] = LogLevel::DEBUG; |
|
| 284 | + $m[2048] = $m[8192] = $m[16384] = $m[32767] = LogLevel::DEBUG; |
|
| 285 | 285 | |
| 286 | - if(isset($m[$level])) |
|
| 286 | + if (isset($m[$level])) |
|
| 287 | 287 | return $m[$level]; |
| 288 | 288 | |
| 289 | 289 | throw new \Exception(__FUNCTION__."($level): $level is unknown"); |