@@ -354,7 +354,7 @@ public function initialize(array $config): void {
354354 * @param array<string, mixed> $query
355355 * @return string Full URL
356356 */
357- public function apiUrl (array $ query = []) {
357+ public function apiUrl (array $ query = []): string {
358358 $ url = $ this ->_protocol () . static ::API ;
359359
360360 if ($ this ->_runtimeConfig ['map ' ]['api ' ]) {
@@ -381,7 +381,7 @@ public function apiUrl(array $query = []) {
381381 * @deprecated Not in use.
382382 * @return string
383383 */
384- public function gearsUrl () {
384+ public function gearsUrl (): string {
385385 $ this ->_gearsIncluded = true ;
386386 $ url = $ this ->_protocol () . 'code.google.com/apis/gears/gears_init.js ' ;
387387
@@ -391,14 +391,14 @@ public function gearsUrl() {
391391 /**
392392 * @return string currentMapObject
393393 */
394- public function name () {
394+ public function name (): string {
395395 return 'map ' . static ::$ mapCount ;
396396 }
397397
398398 /**
399399 * @return string currentContainerId
400400 */
401- public function id () {
401+ public function id (): string {
402402 return $ this ->_runtimeConfig ['div ' ]['id ' ];
403403 }
404404
@@ -409,7 +409,7 @@ public function id() {
409409 * @param bool $full true=optionsAsWell
410410 * @return void
411411 */
412- public function reset ($ full = true ) {
412+ public function reset (bool $ full = true ): void {
413413 static ::$ markerCount = static ::$ infoWindowCount = 0 ;
414414 $ this ->markers = $ this ->infoWindows = [];
415415 if ($ full ) {
@@ -430,7 +430,7 @@ public function reset($full = true) {
430430 * @param array<string, mixed> $options
431431 * @return void
432432 */
433- public function setControls (array $ options = []) {
433+ public function setControls (array $ options = []): void {
434434 if (isset ($ options ['streetView ' ])) {
435435 $ this ->_runtimeConfig ['map ' ]['streetViewControl ' ] = $ options ['streetView ' ];
436436 }
@@ -455,7 +455,7 @@ public function setControls(array $options = []) {
455455 * @param array<string, mixed> $options associative array of settings are passed
456456 * @return string divContainer
457457 */
458- public function map (array $ options = []) {
458+ public function map (array $ options = []): string {
459459 $ this ->reset ();
460460 $ this ->_runtimeConfig = Hash::merge ($ this ->_runtimeConfig , $ options );
461461 $ this ->_runtimeConfig ['map ' ] = $ options + $ this ->_runtimeConfig ['map ' ];
@@ -560,7 +560,7 @@ protected function _initialLocation() {
560560 * @throws \Cake\Core\Exception\CakeException
561561 * @return mixed Integer marker count or boolean false on failure
562562 */
563- public function addMarker ($ options ) {
563+ public function addMarker (array $ options ): mixed {
564564 $ defaults = $ this ->_runtimeConfig ['marker ' ];
565565 if (isset ($ options ['icon ' ]) && is_array ($ options ['icon ' ])) {
566566 $ defaults = $ options ['icon ' ] + $ defaults ;
@@ -732,7 +732,7 @@ protected function _directions($directions, array $markerOptions = []) {
732732 * @param string $content
733733 * @return int Current marker counter
734734 */
735- public function addInfoContent ($ content ) {
735+ public function addInfoContent (string $ content ): int {
736736 $ this ->infoContents [static ::$ markerCount ] = $ this ->escapeString ($ content );
737737 $ event = "
738738 gWindowContents " . static ::$ mapCount . '.push( ' . $ this ->escapeString ($ content ) . ");
@@ -762,7 +762,7 @@ public function addInfoContent($content) {
762762 * NOTE: for special ones only first parameter counts!
763763 * @return array Array(icon, shadow, shape, ...)
764764 */
765- public function iconSet ($ color , $ char = null , $ size = 'm ' ) {
765+ public function iconSet (string $ color , ? string $ char = null , string $ size = 'm ' ): array {
766766 $ colors = ['red ' , 'green ' , 'yellow ' , 'blue ' , 'purple ' , 'white ' , 'black ' ];
767767 if (!in_array ($ color , $ colors )) {
768768 $ color = 'red ' ;
@@ -833,7 +833,7 @@ public function iconSet($color, $char = null, $size = 'm') {
833833 * @param array<string, mixed> $shadowOptions Shadow image options
834834 * @return array Resulting array
835835 */
836- public function addIcon ($ image , $ shadow = null , array $ imageOptions = [], array $ shadowOptions = []) {
836+ public function addIcon (string $ image , ? string $ shadow = null , array $ imageOptions = [], array $ shadowOptions = []): array {
837837 $ res = ['url ' => $ image ];
838838 $ res ['icon ' ] = $ this ->icon ($ image , $ imageOptions );
839839 if ($ shadow ) {
@@ -864,14 +864,18 @@ public function addIcon($image, $shadow = null, array $imageOptions = [], array
864864 * - anchor: array(width=>x, height=>y)
865865 * @return int Icon count
866866 */
867- public function icon (string $ url , array $ options = []) {
867+ public function icon (string $ url , array $ options = []): int {
868868 // The shadow image is larger in the horizontal dimension
869869 // while the position and offset are the same as for the main image.
870870 if (empty ($ options ['size ' ])) {
871871 // We will deprecate this in the future maybe as this is super slow!
872872 //trigger_error('Please specify size manually [width => ..., height => ...] for performance reasons.', E_USER_DEPRECATED);
873873 if (!empty ($ options ['imagePath ' ])) {
874874 $ path = realpath ($ options ['imagePath ' ]);
875+ $ allowedDir = realpath (WWW_ROOT . 'img ' . DS );
876+ if (!$ path || !$ allowedDir || strpos ($ path , $ allowedDir ) !== 0 ) {
877+ throw new CakeException ('Invalid image path ' );
878+ }
875879 } else {
876880 $ path = $ url ;
877881 if (!preg_match ('#^((https?://)|//)#i ' , $ path )) {
@@ -919,7 +923,7 @@ public function icon(string $url, array $options = []) {
919923 * - lat, lng, content, maxWidth, pixelOffset, zIndex
920924 * @return int windowCount
921925 */
922- public function addInfoWindow (array $ options = []) {
926+ public function addInfoWindow (array $ options = []): int {
923927 $ defaults = $ this ->_runtimeConfig ['infoWindow ' ];
924928 $ options += $ defaults ;
925929
@@ -951,7 +955,7 @@ public function addInfoWindow(array $options = []) {
951955 * @param bool $open Also open it right away.
952956 * @return void
953957 */
954- public function addEvent ($ marker , $ infoWindow , $ open = false ) {
958+ public function addEvent (int $ marker , int $ infoWindow , bool $ open = false ): void {
955959 $ this ->map .= "
956960 google.maps.event.addListener(gMarkers " . static ::$ mapCount . "[ {$ marker }], 'click', function() {
957961 gInfoWindows " . static ::$ mapCount . "[ $ infoWindow].open( " . $ this ->name () . ", this);
@@ -971,7 +975,7 @@ public function addEvent($marker, $infoWindow, $open = false) {
971975 * @param string $event (js)
972976 * @return void
973977 */
974- public function addCustomEvent ($ marker , $ event ) {
978+ public function addCustomEvent (int $ marker , string $ event ): void {
975979 $ this ->map .= "
976980 google.maps.event.addListener(gMarkers " . static ::$ mapCount . "[ {$ marker }], 'click', function() {
977981 $ event
@@ -985,7 +989,7 @@ public function addCustomEvent($marker, $event) {
985989 * @param string $js Custom JS
986990 * @return void
987991 */
988- public function addCustom ($ js ) {
992+ public function addCustom (string $ js ): void {
989993 $ this ->map .= $ js ;
990994 }
991995
@@ -1008,7 +1012,7 @@ public function addCustom($js) {
10081012 * - region: String
10091013 * @return void
10101014 */
1011- public function addDirections ($ from , $ to , array $ options = []) {
1015+ public function addDirections (array | string $ from , array | string $ to , array $ options = []): void {
10121016 $ id = 'd ' . static ::$ markerCount ++;
10131017 $ defaults = $ this ->_runtimeConfig ['directions ' ];
10141018 $ options += $ defaults ;
@@ -1066,7 +1070,7 @@ public function addDirections($from, $to, array $options = []) {
10661070 * - weight in pixels (defaults to 2)
10671071 * @return void
10681072 */
1069- public function addPolyline ($ from , $ to , array $ options = []) {
1073+ public function addPolyline (array | string $ from , array | string $ to , array $ options = []): void {
10701074 if (is_array ($ from )) {
10711075 $ from = 'new google.maps.LatLng( ' . (float )$ from ['lat ' ] . ', ' . (float )$ from ['lng ' ] . ') ' ;
10721076 } else {
@@ -1110,7 +1114,7 @@ public function addPolyline($from, $to, array $options = []) {
11101114 * @param int $index infoWindowCount
11111115 * @return void
11121116 */
1113- public function setContentInfoWindow ($ content , $ index ) {
1117+ public function setContentInfoWindow (string $ content , int $ index ): void {
11141118 $ this ->map .= "
11151119 gInfoWindows " . static ::$ mapCount . "[ $ index]. setContent( " . $ this ->escapeString ($ content ) . '); ' ;
11161120 }
@@ -1121,7 +1125,7 @@ public function setContentInfoWindow($content, $index) {
11211125 * @param mixed $content
11221126 * @return string JSON
11231127 */
1124- public function escapeString ($ content ) {
1128+ public function escapeString (mixed $ content ): string {
11251129 $ result = json_encode ($ content );
11261130 if ($ result === false ) {
11271131 return '' ;
0 commit comments