public function renderJsContainerMarkerCluster(Map $map)
    {
        $output = array(
            $this->markerClusterHelper->renderMarkers($map->getMarkerCluster(), $map),
            $this->markerClusterHelper->render($map->getMarkerCluster(), $map),
        );

        return implode('', $output);
    }

public function renderJsContainerMarkerCluster ( Map $ map ) { $ output = array ( $ this -> markerClusterHelper -> renderMarkers ( $ map -> getMarkerCluster ( ) , $ map ) , $ this -> markerClusterHelper -> render ( $ map -> getMarkerCluster ( ) , $ map ) , ) ; return implode ( '' , $ output ) ; }

Renders the javascript container marker cluster.

@param \Ivory\GoogleMap\Map $map The map.

@return string The JS output.

Renders the javascript container marker cluster .


public function renderJsContainerKMLLayers(Map $map)
    {
        $output = array();

        foreach ($map->getKMLLayers() as $kmlLayer) {
            $output[] = sprintf(
                '%s.kml_layers.%s = %s',
                $this->getJsContainerName($map),
                $kmlLayer->getJavascriptVariable(),
                $this->kmlLayerHelper->render($kmlLayer, $map)
            );
        }

        return implode('', $output);
    }

public
function
renderJsContainerKMLLayers
(
Map
$
map
)
{
$
output
=
array
(
)
;
foreach
(
$
map
->
getKMLLayers
(
)
as
$
kmlLayer
)
{
$
output
[
]
=
sprintf
(
'%s.kml_layers.%s = %s'
,
$
this
->
getJsContainerName
(
$
map
)
,
$
kmlLayer
->
getJavascriptVariable
(
)
,
$
this
->
kmlLayerHelper
->
render
(
$
kmlLayer
,
$
map
)
)
;
}
return
implode
(
''
,
$
output
)
;
}

Renders the javascript container KML layer.

@param \Ivory\GoogleMap\Map $map The map.

@return string The JS output.

Renders the javascript container KML layer .


public function renderJsContainerEventManager(Map $map)
    {
        $output = array();

        foreach ($map->getEventManager()->getDomEvents() as $domEvent) {
            $output[] = sprintf(
                '%s.event_manager.dom_events.%s = %s',
                $this->getJsContainerName($map),
                $domEvent->getJavascriptVariable(),
                $this->eventManagerHelper->renderDomEvent($domEvent)
            );
        }

        foreach ($map->getEventManager()->getDomEventsOnce() as $domEventOnce) {
            $output[] = sprintf(
                '%s.event_manager.dom_events_once.%s = %s',
                $this->getJsContainerName($map),
                $domEventOnce->getJavascriptVariable(),
                $this->eventManagerHelper->renderDomEventOnce($domEventOnce)
            );
        }

        foreach ($map->getEventManager()->getEvents() as $event) {
            $output[] = sprintf(
                '%s.event_manager.events.%s = %s',
                $this->getJsContainerName($map),
                $event->getJavascriptVariable(),
                $this->eventManagerHelper->renderEvent($event)
            );
        }

        foreach ($map->getEventManager()->getEventsOnce() as $eventOnce) {
            $output[] = sprintf(
                '%s.event_manager.events_once.%s = %s',
                $this->getJsContainerName($map),
                $eventOnce->getJavascriptVariable(),
                $this->eventManagerHelper->renderEventOnce($eventOnce)
            );
        }

        return implode('', $output);
    }

Renders the javascript container event manager.

@param \Ivory\GoogleMap\Map $map The map.

@return string The JS output.

Renders the javascript container event manager .


public function renderJsContainerExtra(Map $map)
    {
        $output = array();

        foreach ($map->getInfoWindows() as $infoWindow) {
            if ($infoWindow->isOpen()) {
                $output[] = $this->infoWindowHelper->renderOpen($infoWindow, $map);
            }
        }

        foreach ($map->getMarkers() as $marker) {
            if ($marker->hasInfoWindow() && $marker->getInfoWindow()->isOpen()) {
                $output[] = $this->infoWindowHelper->renderOpen($marker->getInfoWindow(), $map, $marker);
            }
        }

        foreach ($this->computeBounds($map) as $bound) {
            if ($bound->hasExtends()) {
                $output[] = $this->boundHelper->renderExtends($bound);
            }
        }

        if ($map->isAutoZoom()) {
            $output[] = $this->renderMapBound($map);
        } else {
            $output[] = $this->renderMapCenter($map);
        }

        return implode('', $output);
    }

public function renderJsContainerExtra ( Map $ map ) { $ output = array ( ) ; foreach ( $ map -> getInfoWindows ( ) as $ infoWindow ) { if ( $ infoWindow -> isOpen ( ) ) { $ output [ ] = $ this -> infoWindowHelper -> renderOpen ( $ infoWindow , $ map ) ; } } foreach ( $ map -> getMarkers ( ) as $ marker ) { if ( $ marker -> hasInfoWindow ( ) && $ marker -> getInfoWindow ( ) -> isOpen ( ) ) { $ output [ ] = $ this -> infoWindowHelper -> renderOpen ( $ marker -> getInfoWindow ( ) , $ map , $ marker ) ; } } foreach ( $ this -> computeBounds ( $ map ) as $ bound ) { if ( $ bound -> hasExtends ( ) ) { $ output [ ] = $ this -> boundHelper -> renderExtends ( $ bound ) ; } } if ( $ map -> isAutoZoom ( ) ) { $ output [ ] = $ this -> renderMapBound ( $ map ) ; } else { $ output [ ] = $ this -> renderMapCenter ( $ map ) ; } return implode ( '' , $ output ) ; }

Renders the js container extra.

@param \Ivory\GoogleMap\Map $map The map.

@return string The JS output.


public function renderMap(Map $map)
    {
        $mapTypeId = $map->getMapOption('mapTypeId');
        $map->removeMapOption('mapTypeId');

        $this->jsonBuilder
            ->reset()
            ->setValue('[mapTypeId]', $this->mapTypeIdHelper->render($mapTypeId), false);

        $this->renderMapControls($map);

        if ($map->isAutoZoom()) {
            $map->removeMapOption('zoom');
        }

        $this->jsonBuilder->setValues($map->getMapOptions());

        return sprintf(
            '%s = new google.maps.Map(document.getElementById("%s"), {
                zoom: 5,
                scrollwheel: false,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                zoomControl: true,
                mapTypeControl: false,
                scaleControl: false,
                panControl: false,
                navigationControl: false,
                streetViewControl: false,
                gestureHandling: "cooperative",
                styles: [{"featureType":"poi","elementType":"labels.text.fill","stylers":[{"color":"#747474"},{"lightness":"23"}]},{"featureType":"poi.attraction","elementType":"geometry.fill","stylers":[{"color":"#f38eb0"}]},{"featureType":"poi.government","elementType":"geometry.fill","stylers":[{"color":"#ced7db"}]},{"featureType":"poi.medical","elementType":"geometry.fill","stylers":[{"color":"#ffa5a8"}]},{"featureType":"poi.park","elementType":"geometry.fill","stylers":[{"color":"#c7e5c8"}]},{"featureType":"poi.place_of_worship","elementType":"geometry.fill","stylers":[{"color":"#d6cbc7"}]},{"featureType":"poi.school","elementType":"geometry.fill","stylers":[{"color":"#c4c9e8"}]},{"featureType":"poi.sports_complex","elementType":"geometry.fill","stylers":[{"color":"#b1eaf1"}]},{"featureType":"road","elementType":"geometry","stylers":[{"lightness":"100"}]},{"featureType":"road","elementType":"labels","stylers":[{"visibility":"off"},{"lightness":"100"}]},{"featureType":"road.highway","elementType":"geometry.fill","stylers":[{"color":"#ffd4a5"}]},{"featureType":"road.arterial","elementType":"geometry.fill","stylers":[{"color":"#ffe9d2"}]},{"featureType":"road.local","elementType":"all","stylers":[{"visibility":"simplified"}]},{"featureType":"road.local","elementType":"geometry.fill","stylers":[{"weight":"3.00"}]},{"featureType":"road.local","elementType":"geometry.stroke","stylers":[{"weight":"0.30"}]},{"featureType":"road.local","elementType":"labels.text","stylers":[{"visibility":"on"}]},{"featureType":"road.local","elementType":"labels.text.fill","stylers":[{"color":"#747474"},{"lightness":"36"}]},{"featureType":"road.local","elementType":"labels.text.stroke","stylers":[{"color":"#e9e5dc"},{"lightness":"30"}]},{"featureType":"transit.line","elementType":"geometry","stylers":[{"visibility":"on"},{"lightness":"100"}]},{"featureType":"water","elementType":"all","stylers":[{"color":"#d2e7f7"}]}]
            });'.PHP_EOL,
            $map->getJavascriptVariable(),
            $map->getHtmlContainerId()//,
            //$this->jsonBuilder->build()
        );
    }

Renders the map.

@param \Ivory\GoogleMap\Map $map The map.

@return string The JS output.


public function renderMapCenter(Map $map)
    {
        return sprintf(
            '%s.setCenter(%s);'.PHP_EOL,
            $map->getJavascriptVariable(),
            $map->getCenter()->getJavascriptVariable()
        );
    }

public function renderMapCenter ( Map $ map ) { return sprintf ( '%s.setCenter(%s);' . PHP_EOL , $ map -> getJavascriptVariable ( ) , $ map -> getCenter ( ) -> getJavascriptVariable ( ) ) ; }

Renders the map center.

@param \Ivory\GoogleMap\Map $map The map.

@return string Ths JS output.


public function renderMapBound(Map $map)
    {
        return sprintf(
            '%s.fitBounds(%s);'.PHP_EOL,
            $map->getJavascriptVariable(),
            $map->getBound()->getJavascriptVariable()
        );
    }

public function renderMapBound ( Map $ map ) { return sprintf ( '%s.fitBounds(%s);' . PHP_EOL , $ map -> getJavascriptVariable ( ) , $ map -> getBound ( ) -> getJavascriptVariable ( ) ) ; }

Renders the map bound.

@param \Ivory\GoogleMap\Map $map The map.

@return string The JS output.


protected function computeCoordinates(Map $map)
    {
        $coordinates = array();

        if (!$map->isAutoZoom() && !in_array($map->getCenter(), $coordinates)) {
            $coordinates[] = $map->getCenter();
        }

        foreach ($this->computeBounds($map) as $bound) {
            if (!$bound->hasExtends() && $bound->hasCoordinates()) {
                if (!in_array($bound->getSouthWest(), $coordinates)) {
                    $coordinates[] = $bound->getSouthWest();
                }

                if (!in_array($bound->getNorthEast(), $coordinates)) {
                    $coordinates[] = $bound->getNorthEast();
                }
            }
        }

        foreach ($map->getCircles() as $circle) {
            if (!in_array($circle->getCenter(), $coordinates)) {
                $coordinates[] = $circle->getCenter();
            }
        }

        foreach ($map->getInfoWindows() as $infoWindow) {
            if (!in_array($infoWindow->getPosition(), $coordinates)) {
                $coordinates[] = $infoWindow->getPosition();
            }
        }

        foreach ($map->getMarkers() as $marker) {
            if (!in_array($marker->getPosition(), $coordinates)) {
                $coordinates[] = $marker->getPosition();
            }
        }

        foreach ($map->getPolygons() as $polygon) {
            foreach ($polygon->getCoordinates() as $polygonCoordinate) {
                if (!in_array($polygonCoordinate, $coordinates)) {
                    $coordinates[] = $polygonCoordinate;
                }
            }
        }

        foreach ($map->getPolylines() as $polyline) {
            foreach ($polyline->getCoordinates() as $polylineCoordinate) {
                if (!in_array($polylineCoordinate, $coordinates)) {
                    $coordinates[] = $polylineCoordinate;
                }
            }
        }

        return $coordinates;
    }

protected function computeCoordinates ( Map $ map ) { $ coordinates = array ( ) ; if ( ! $ map -> isAutoZoom ( ) && ! in_array ( $ map -> getCenter ( ) , $ coordinates ) ) { $ coordinates [ ] = $ map -> getCenter ( ) ; } foreach ( $ this -> computeBounds ( $ map ) as $ bound ) { if ( ! $ bound -> hasExtends ( ) && $ bound -> hasCoordinates ( ) ) { if ( ! in_array ( $ bound -> getSouthWest ( ) , $ coordinates ) ) { $ coordinates [ ] = $ bound -> getSouthWest ( ) ; } if ( ! in_array ( $ bound -> getNorthEast ( ) , $ coordinates ) ) { $ coordinates [ ] = $ bound -> getNorthEast ( ) ; } } } foreach ( $ map -> getCircles ( ) as $ circle ) { if ( ! in_array ( $ circle -> getCenter ( ) , $ coordinates ) ) { $ coordinates [ ] = $ circle -> getCenter ( ) ; } } foreach ( $ map -> getInfoWindows ( ) as $ infoWindow ) { if ( ! in_array ( $ infoWindow -> getPosition ( ) , $ coordinates ) ) { $ coordinates [ ] = $ infoWindow -> getPosition ( ) ; } } foreach ( $ map -> getMarkers ( ) as $ marker ) { if ( ! in_array ( $ marker -> getPosition ( ) , $ coordinates ) ) { $ coordinates [ ] = $ marker -> getPosition ( ) ; } } foreach ( $ map -> getPolygons ( ) as $ polygon ) { foreach ( $ polygon -> getCoordinates ( ) as $ polygonCoordinate ) { if ( ! in_array ( $ polygonCoordinate , $ coordinates ) ) { $ coordinates [ ] = $ polygonCoordinate ; } } } foreach ( $ map -> getPolylines ( ) as $ polyline ) { foreach ( $ polyline -> getCoordinates ( ) as $ polylineCoordinate ) { if ( ! in_array ( $ polylineCoordinate , $ coordinates ) ) { $ coordinates [ ] = $ polylineCoordinate ; } } } return $ coordinates ; }

Computes the coordinates of a map.

@param \Ivory\GoogleMap\Map $map The map.

@return array The computed coordinated.


protected function computeBounds(Map $map)
    {
        $bounds = array();

        if ($map->isAutoZoom() && !in_array($map->getBound(), $bounds)) {
            $bounds[] = $map->getBound();
        }

        foreach ($map->getGroundOverlays() as $groundOverlay) {
            if (!in_array($groundOverlay->getBound(), $bounds)) {
                $bounds[] = $groundOverlay->getBound();
            }
        }

        foreach ($map->getRectangles() as $rectangle) {
            if (!in_array($rectangle->getBound(), $bounds)) {
                $bounds[] = $rectangle->getBound();
            }
        }

        return $bounds;
    }

protected function computeBounds ( Map $ map ) { $ bounds = array ( ) ; if ( $ map -> isAutoZoom ( ) && ! in_array ( $ map -> getBound ( ) , $ bounds ) ) { $ bounds [ ] = $ map -> getBound ( ) ; } foreach ( $ map -> getGroundOverlays ( ) as $ groundOverlay ) { if ( ! in_array ( $ groundOverlay -> getBound ( ) , $ bounds ) ) { $ bounds [ ] = $ groundOverlay -> getBound ( ) ; } } foreach ( $ map -> getRectangles ( ) as $ rectangle ) { if ( ! in_array ( $ rectangle -> getBound ( ) , $ bounds ) ) { $ bounds [ ] = $ rectangle -> getBound ( ) ; } } return $ bounds ; }

Computes the bounds of a map.

@param \Ivory\GoogleMap\Map $map The map.

@return array The computed bounds.


protected function computePoints(Map $map)
    {
        $points = array();

        foreach ($map->getMarkers() as $marker) {
            if ($marker->hasIcon()) {
                if ($marker->getIcon()->hasAnchor() && !in_array($marker->getIcon()->getAnchor(), $points)) {
                    $points[] = $marker->getIcon()->getAnchor();
                }

                if ($marker->getIcon()->hasOrigin() && !in_array($marker->getIcon()->getOrigin(), $points)) {
                    $points[] = $marker->getIcon()->getOrigin();
                }
            }

            if ($marker->hasShadow()) {
                if ($marker->getShadow()->hasAnchor() && !in_array($marker->getShadow()->getAnchor(), $points)) {
                    $points[] = $marker->getShadow()->getAnchor();
                }

                if ($marker->getShadow()->hasOrigin() && !in_array($marker->getShadow()->getOrigin(), $points)) {
                    $points[] = $marker->getShadow()->getOrigin();
                }
            }
        }

        return $points;
    }

protected function computePoints ( Map $ map ) { $ points = array ( ) ; foreach ( $ map -> getMarkers ( ) as $ marker ) { if ( $ marker -> hasIcon ( ) ) { if ( $ marker -> getIcon ( ) -> hasAnchor ( ) && ! in_array ( $ marker -> getIcon ( ) -> getAnchor ( ) , $ points ) ) { $ points [ ] = $ marker -> getIcon ( ) -> getAnchor ( ) ; } if ( $ marker -> getIcon ( ) -> hasOrigin ( ) && ! in_array ( $ marker -> getIcon ( ) -> getOrigin ( ) , $ points ) ) { $ points [ ] = $ marker -> getIcon ( ) -> getOrigin ( ) ; } } if ( $ marker -> hasShadow ( ) ) { if ( $ marker -> getShadow ( ) -> hasAnchor ( ) && ! in_array ( $ marker -> getShadow ( ) -> getAnchor ( ) , $ points ) ) { $ points [ ] = $ marker -> getShadow ( ) -> getAnchor ( ) ; } if ( $ marker -> getShadow ( ) -> hasOrigin ( ) && ! in_array ( $ marker -> getShadow ( ) -> getOrigin ( ) , $ points ) ) { $ points [ ] = $ marker -> getShadow ( ) -> getOrigin ( ) ; } } } return $ points ; }

Computes the points of a map.

@param \Ivory\GoogleMap\Map $map The map.

@return array The computed points.


protected function computeSizes(Map $map)
    {
        $sizes = array();

        foreach (array_merge($map->getInfoWindows(), $this->computeMarkerInfoWindows($map)) as $infoWindow) {
            if ($infoWindow->hasPixelOffset() && !in_array($infoWindow->getPixelOffset(), $sizes)) {
                $sizes[] = $infoWindow->getPixelOffset();
            }
        }

        foreach ($map->getMarkers() as $marker) {
            if ($marker->hasIcon()) {
                if ($marker->getIcon()->hasSize() && !in_array($marker->getIcon()->getSize(), $sizes)) {
                    $sizes[] = $marker->getIcon()->getSize();
                }

                if ($marker->getIcon()->hasScaledSize() && !in_array($marker->getIcon()->getScaledSize(), $sizes)) {
                    $sizes[] = $marker->getIcon()->getScaledSize();
                }
            }

            if ($marker->hasShadow()) {
                if ($marker->getShadow()->hasSize() && !in_array($marker->getShadow()->getSize(), $sizes)) {
                    $sizes[] = $marker->getShadow()->getSize();
                }

                if ($marker->getShadow()->hasScaledSize() && !in_array($marker->getShadow()->getScaledSize(), $sizes)) {
                    $sizes[] = $marker->getShadow()->getScaledSize();
                }
            }
        }

        return $sizes;
    }

protected function computeSizes ( Map $ map ) { $ sizes = array ( ) ; foreach ( array_merge ( $ map -> getInfoWindows ( ) , $ this -> computeMarkerInfoWindows ( $ map ) ) as $ infoWindow ) { if ( $ infoWindow -> hasPixelOffset ( ) && ! in_array ( $ infoWindow -> getPixelOffset ( ) , $ sizes ) ) { $ sizes [ ] = $ infoWindow -> getPixelOffset ( ) ; } } foreach ( $ map -> getMarkers ( ) as $ marker ) { if ( $ marker -> hasIcon ( ) ) { if ( $ marker -> getIcon ( ) -> hasSize ( ) && ! in_array ( $ marker -> getIcon ( ) -> getSize ( ) , $ sizes ) ) { $ sizes [ ] = $ marker -> getIcon ( ) -> getSize ( ) ; } if ( $ marker -> getIcon ( ) -> hasScaledSize ( ) && ! in_array ( $ marker -> getIcon ( ) -> getScaledSize ( ) , $ sizes ) ) { $ sizes [ ] = $ marker -> getIcon ( ) -> getScaledSize ( ) ; } } if ( $ marker -> hasShadow ( ) ) { if ( $ marker -> getShadow ( ) -> hasSize ( ) && ! in_array ( $ marker -> getShadow ( ) -> getSize ( ) , $ sizes ) ) { $ sizes [ ] = $ marker -> getShadow ( ) -> getSize ( ) ; } if ( $ marker -> getShadow ( ) -> hasScaledSize ( ) && ! in_array ( $ marker -> getShadow ( ) -> getScaledSize ( ) , $ sizes ) ) { $ sizes [ ] = $ marker -> getShadow ( ) -> getScaledSize ( ) ; } } } return $ sizes ; }

Computes the sizes of a map.

@param \Ivory\GoogleMap\Map $map The map.

@return array The computed sizes.


protected function computeMarkerImages(Map $map)
    {
        $markerImages = array();

        foreach ($map->getMarkers() as $marker) {
            if ($marker->hasIcon() && !in_array($marker->getIcon(), $markerImages)) {
                $markerImages[] = $marker->getIcon();
            }

            if ($marker->hasShadow() && !in_array($marker->getShadow(), $markerImages)) {
                $markerImages[] = $marker->getShadow();
            }
        }

        return $markerImages;
    }

protected function computeMarkerImages ( Map $ map ) { $ markerImages = array ( ) ; foreach ( $ map -> getMarkers ( ) as $ marker ) { if ( $ marker -> hasIcon ( ) && ! in_array ( $ marker -> getIcon ( ) , $ markerImages ) ) { $ markerImages [ ] = $ marker -> getIcon ( ) ; } if ( $ marker -> hasShadow ( ) && ! in_array ( $ marker -> getShadow ( ) , $ markerImages ) ) { $ markerImages [ ] = $ marker -> getShadow ( ) ; } } return $ markerImages ; }

Computes the marker images of a map.

@param \Ivory\GoogleMap\Map $map The map.

@return array The computed marker images.


protected function computeMarkerShapes(Map $map)
    {
        $markerShapes = array();

        foreach ($map->getMarkers() as $marker) {
            if ($marker->hasShape() && !in_array($marker->getShape(), $markerShapes)) {
                $markerShapes[] = $marker->getShape();
            }
        }

        return $markerShapes;
    }

protected function computeMarkerShapes ( Map $ map ) { $ markerShapes = array ( ) ; foreach ( $ map -> getMarkers ( ) as $ marker ) { if ( $ marker -> hasShape ( ) && ! in_array ( $ marker -> getShape ( ) , $ markerShapes ) ) { $ markerShapes [ ] = $ marker -> getShape ( ) ; } } return $ markerShapes ; }

Computes the marker shapes of a map.

@param \Ivory\GoogleMap\Map $map The map.

@return array The computed marker shapes.


protected function computeMarkerInfoWindows(Map $map)
    {
        $infoWinfows = array();

        foreach ($map->getMarkers() as $marker) {
            if ($marker->hasInfoWindow() && !in_array($marker->getInfoWindow(), $infoWinfows)) {
                $infoWinfows[] = $marker->getInfoWindow();
            }
        }

        return $infoWinfows;
    }

protected function computeMarkerInfoWindows ( Map $ map ) { $ infoWinfows = array ( ) ; foreach ( $ map -> getMarkers ( ) as $ marker ) { if ( $ marker -> hasInfoWindow ( ) && ! in_array ( $ marker -> getInfoWindow ( ) , $ infoWinfows ) ) { $ infoWinfows [ ] = $ marker -> getInfoWindow ( ) ; } } return $ infoWinfows ; }

Computes the marker info windows of a map.

@param \Ivory\GoogleMap\Map $map The map.

@return array The computed marker info windows.

Computes the marker info windows of a map .


protected function renderMapControls(Map $map)
    {
        $controlNames = array(
            'MapTypeControl',
            'OverviewMapControl',
            'PanControl',
            'RotateControl',
            'ScaleControl',
            'StreetViewControl',
            'ZoomControl',
        );

        foreach ($controlNames as $controlName) {
            $controlHelper = lcfirst($controlName).'Helper';
            $this->renderMapControl($map, $controlName, $this->$controlHelper);
        }
    }

protected function renderMapControls ( Map $ map ) { $ controlNames = array ( 'MapTypeControl' , 'OverviewMapControl' , 'PanControl' , 'RotateControl' , 'ScaleControl' , 'StreetViewControl' , 'ZoomControl' , ) ; foreach ( $ controlNames as $ controlName ) { $ controlHelper = lcfirst ( $ controlName ) . 'Helper' ; $ this -> renderMapControl ( $ map , $ controlName , $ this -> $ controlHelper ) ; } }

Renders the map controls in the json builder.

@param \Ivory\GoogleMap\Map $map The map.

Renders the map controls in the json builder .


protected function renderMapControl(Map $map, $controlName, $controlHelper)
    {
        $lcFirstControlName = lcfirst($controlName);

        if (!$map->hasMapOption($lcFirstControlName)) {
            return;
        }

        $this->jsonBuilder->setValue(
            sprintf('[%s]', $lcFirstControlName),
            (bool) $map->getMapOption($lcFirstControlName)
        );

        if ($map->getMapOption($lcFirstControlName)) {
            $hasControlMethod = 'has'.$controlName;
            if ($map->$hasControlMethod()) {
                $getControlMethod = 'get'.$controlName;

                $this->jsonBuilder->setValue(
                    sprintf('[%sOptions]', $lcFirstControlName),
                    $controlHelper->render($map->$getControlMethod()),
                    false
                );
            }
        }

        $map->removeMapOption($lcFirstControlName);
    }

protected function renderMapControl ( Map $ map , $ controlName , $ controlHelper ) { $ lcFirstControlName = lcfirst ( $ controlName ) ; if ( ! $ map -> hasMapOption ( $ lcFirstControlName ) ) { return ; } $ this -> jsonBuilder -> setValue ( sprintf ( '[%s]' , $ lcFirstControlName ) , ( bool ) $ map -> getMapOption ( $ lcFirstControlName ) ) ; if ( $ map -> getMapOption ( $ lcFirstControlName ) ) { $ hasControlMethod = 'has' . $ controlName ; if ( $ map -> $ hasControlMethod ( ) ) { $ getControlMethod = 'get' . $ controlName ; $ this -> jsonBuilder -> setValue ( sprintf ( '[%sOptions]' , $ lcFirstControlName ) , $ controlHelper -> render ( $ map -> $ getControlMethod ( ) ) , false ) ; } } $ map -> removeMapOption ( $ lcFirstControlName ) ; }

Renders a map control in the json builder.

@param \Ivory\GoogleMap\Map $map           The map.
@param string               $controlName   The control name.
@param mixed                $controlHelper The control helper.

Renders a map control in the json builder .


public function v1(bool $optimize = true): string
    {
        $uuid = UuidGen::uuid1()->toString();

        if ($optimize) {
            // See: <http://jas.xyz/1ODZilT>
            $uuid = substr($uuid, 14, 4).
                substr($uuid, 9, 4).
                substr($uuid, 0, 8).
                substr($uuid, 19, 4).
                substr($uuid, 24);
        }
        return $uuid; // Possibly optimized now.
    }

public
function
v1
(
bool
$
optimize
=
true
)
:
string
{
$
uuid
=
UuidGen
::
uuid1
(
)
->
toString
(
)
;
if
(
$
optimize
)
{
// See: <http://jas.xyz/1ODZilT>
$
uuid
=
substr
(
$
uuid
,
14
,
4
)
.
substr
(
$
uuid
,
9
,
4
)
.
substr
(
$
uuid
,
0
,
8
)
.
substr
(
$
uuid
,
19
,
4
)
.
substr
(
$
uuid
,
24
)
;
}
return
$
uuid
;
// Possibly optimized now.
}

UUID v1 generator.

@since 150424 Initial release.

@param bool $optimize Optimize?

@return string Version 1 UUID (32 bytes optimized).
Or 36 bytes unoptimized; i.e., w/ dashes.


public function v3(string $namespace, string $identifier, bool $optimize = true): string
    {
        switch ($namespace) {
            case 'dns':
                $namespace = UuidGen::NAMESPACE_DNS;
                break; // Stop here.

            case 'url':
                $namespace = UuidGen::NAMESPACE_URL;
                break; // Stop here.

            case 'oid':
                $namespace = UuidGen::NAMESPACE_OID;
                break; // Stop here.

            case 'x500':
                $namespace = UuidGen::NAMESPACE_X500;
                break; // Stop here.

            default:
                $this->c::issue('Invalid namespace.');
        }
        $uuid = UuidGen::uuid3($namespace, $identifier)->toString();

        return $optimize ? str_replace('-', '', $uuid) : $uuid;
    }

public
function
v3
(
string
$
namespace
,
string
$
identifier
,
bool
$
optimize
=
true
)
:
string
{
switch
(
$
namespace
)
{
case
'dns'
:
$
namespace
=
UuidGen
::
NAMESPACE_DNS
;
break
;
// Stop here.
case
'url'
:
$
namespace
=
UuidGen
::
NAMESPACE_URL
;
break
;
// Stop here.
case
'oid'
:
$
namespace
=
UuidGen
::
NAMESPACE_OID
;
break
;
// Stop here.
case
'x500'
:
$
namespace
=
UuidGen
::
NAMESPACE_X500
;
break
;
// Stop here.
default
:
$
this
->
c
::
issue
(
'Invalid namespace.'
)
;
}
$
uuid
=
UuidGen
::
uuid3
(
$
namespace
,
$
identifier
)
->
toString
(
)
;
return
$
optimize
str_replace
(
'-'
,
''
,
$
uuid
)
:
$
uuid
;
}

UUID v3 generator.

@since 150424 Initial release.

@param string $namespace  Namespace.
@param string $identifier Identifier.
@param bool   $optimize   Optimize?

@return string Version 3 UUID (32 bytes optimized).
Or 36 bytes unoptimized; i.e., w/ dashes.

@internal {@link v5()} is a suggested alternative, as this version uses MD5.


public function v4(bool $optimize = true): string
    {
        $uuid = UuidGen::uuid4()->toString();

        return $optimize ? str_replace('-', '', $uuid) : $uuid;
    }

public function v4 ( bool $ optimize = true ) : string { $ uuid = UuidGen :: uuid4 ( ) -> toString ( ) ; return $ optimize ? str_replace ( '-' , '' , $ uuid ) : $ uuid ; }

UUID v4 generator.

@since 150424 Initial release.

@param bool $optimize Optimize?

@return string Version 4 UUID (32 bytes optimized).
Or 36 bytes unoptimized; i.e., w/ dashes.


public function v4x2(bool $optimize = true): string
    {
        $uuid1 = UuidGen::uuid4()->toString();
        $uuid2 = UuidGen::uuid4()->toString();

        return $optimize ? str_replace('-', '', $uuid1.$uuid2) : $uuid1.'-'.$uuid2;
    }

public function v4x2 ( bool $ optimize = true ) : string { $ uuid1 = UuidGen :: uuid4 ( ) -> toString ( ) ; $ uuid2 = UuidGen :: uuid4 ( ) -> toString ( ) ; return $ optimize ? str_replace ( '-' , '' , $ uuid1 . $ uuid2 ) : $ uuid1 . '-' . $ uuid2 ; }

UUID v4 generator x 2.

@since 170824.30708 Initial release.

@param bool $optimize Optimize?

@return string Version 4 UUID x 2 (64 bytes optimized).
Or 73 bytes unoptimized; i.e., w/ dashes + one extra.


public function get($name): PackageContract
    {
        if (array_key_exists($name, $this->items)) {
            return $this->items[$name];
        }
        throw new Exceptions\ModuleNotFoundException("Package '$name' not found.");
    }

public
function
get
(
$
name
)
:
PackageContract
{
if
(
array_key_exists
(
$
name
,
$
this
->
items
)
)
{
return
$
this
->
items
[
$
name
]
;
}
throw
new
Exceptions
\
ModuleNotFoundException
(
"Package '$name' not found."
)
;
}

Get module by name.

@param string $name

@return PackageContract
@throws ModuleNotFoundException


public function each(callable $callback)
    {
        foreach ($this->items as $name => $item) {
            $callback($item, $name);
        }
    }

public function each ( callable $ callback ) { foreach ( $ this -> items as $ name => $ item ) { $ callback ( $ item , $ name ) ; } }

Run function for each module.

@param callable $callback


public function filter(callable $callback):Repository
    {
        $result = new Repository();
        foreach ($this->items as $name => $item) {
            if ($callback($item, $name)) {
                $result->add($item);
            }
        }

        return $result;
    }

public function filter ( callable $ callback ) : Repository { $ result = new Repository ( ) ; foreach ( $ this -> items as $ name => $ item ) { if ( $ callback ( $ item , $ name ) ) { $ result -> add ( $ item ) ; } } return $ result ; }

Filter modules.

@param callable $callback

@return Repository


public function add(PackageContract ...$items)
    {
        foreach ($items as $item) {
            $this->items[$item->getName()] = $item;
        }
    }

public function add ( PackageContract ... $ items ) { foreach ( $ items as $ item ) { $ this -> items [ $ item -> getName ( ) ] = $ item ; } }

Add module to repository.

@param PackageContract[] ...$items


public function setAddress($address)
    {
        if (!is_string($address) && ($address !== null)) {
            throw GeocodingException::invalidGeocoderRequestAddress();
        }

        $this->address = $address;
    }

public function setAddress ( $ address ) { if ( ! is_string ( $ address ) && ( $ address !== null ) ) { throw GeocodingException :: invalidGeocoderRequestAddress ( ) ; } $ this -> address = $ address ; }

Sets the geocoder request address.

@param string $address The geocoder request address.

@throws \Ivory\GoogleMap\Exception\GeocodingException If the address is not valid.


public function setCoordinate()
    {
        $args = func_get_args();

        if (isset($args[0]) && ($args[0] instanceof Coordinate)) {
            $this->coordinate = $args[0];
        } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) {
            if (!$this->hasCoordinate()) {
                $this->coordinate = new Coordinate();
            }

            $this->coordinate->setLatitude($args[0]);
            $this->coordinate->setLongitude($args[1]);

            if (isset($args[2]) && is_bool($args[2])) {
                $this->coordinate->setNoWrap($args[2]);
            }
        } elseif (!isset($args[0])) {
            $this->coordinate = null;
        } else {
            throw GeocodingException::invalidGeocoderRequestCoordinate();
        }

        return $this;
    }

public function setCoordinate ( ) { $ args = func_get_args ( ) ; if ( isset ( $ args [ 0 ] ) && ( $ args [ 0 ] instanceof Coordinate ) ) { $ this -> coordinate = $ args [ 0 ] ; } elseif ( ( isset ( $ args [ 0 ] ) && is_numeric ( $ args [ 0 ] ) ) && ( isset ( $ args [ 1 ] ) && is_numeric ( $ args [ 1 ] ) ) ) { if ( ! $ this -> hasCoordinate ( ) ) { $ this -> coordinate = new Coordinate ( ) ; } $ this -> coordinate -> setLatitude ( $ args [ 0 ] ) ; $ this -> coordinate -> setLongitude ( $ args [ 1 ] ) ; if ( isset ( $ args [ 2 ] ) && is_bool ( $ args [ 2 ] ) ) { $ this -> coordinate -> setNoWrap ( $ args [ 2 ] ) ; } } elseif ( ! isset ( $ args [ 0 ] ) ) { $ this -> coordinate = null ; } else { throw GeocodingException :: invalidGeocoderRequestCoordinate ( ) ; } return $ this ; }

Sets the geocoder request coordinate

Available prototypes:
- function setCoordinate(\Ivory\GoogleMap\Base\Coordinate $coordinate = null)
- function setCoordinate(double $latitude, double $longitude, boolean $noWrap = true)

@throws \Ivory\GoogleMap\Exception\GeocodingException If the coordinate is not valid (prototypes).


public function setBound()
    {
        $args = func_get_args();

        if (isset($args[0]) && ($args[0] instanceof Bound)) {
            $this->bound = $args[0];
        } elseif ((isset($args[0]) && ($args[0] instanceof Coordinate))
            && (isset($args[1]) && ($args[1] instanceof Coordinate))
        ) {
            if (!$this->hasBound()) {
                $this->bound = new Bound();
            }

            $this->bound->setSouthWest($args[0]);
            $this->bound->setNorthEast($args[1]);
        } elseif ((isset($args[0]) && is_numeric($args[0]))
            && (isset($args[1]) && is_numeric($args[1]))
            && (isset($args[2]) && is_numeric($args[2]))
            && (isset($args[3]) && is_numeric($args[3]))
        ) {
            if (!$this->hasBound()) {
                $this->bound = new Bound();
            }

            $this->bound->setSouthWest(new Coordinate($args[0], $args[1]));
            $this->bound->setNorthEast(new Coordinate($args[2], $args[3]));

            if (isset($args[4]) && is_bool($args[4])) {
                $this->bound->getSouthWest()->setNoWrap($args[4]);
            }

            if (isset($args[5]) && is_bool($args[5])) {
                $this->bound->getNorthEast()->setNoWrap($args[5]);
            }
        } elseif (!isset($args[0])) {
            $this->bound = null;
        } else {
            throw GeocodingException::invalidGeocoderRequestBound();
        }
    }

public function setBound ( ) { $ args = func_get_args ( ) ; if ( isset ( $ args [ 0 ] ) && ( $ args [ 0 ] instanceof Bound ) ) { $ this -> bound = $ args [ 0 ] ; } elseif ( ( isset ( $ args [ 0 ] ) && ( $ args [ 0 ] instanceof Coordinate ) ) && ( isset ( $ args [ 1 ] ) && ( $ args [ 1 ] instanceof Coordinate ) ) ) { if ( ! $ this -> hasBound ( ) ) { $ this -> bound = new Bound ( ) ; } $ this -> bound -> setSouthWest ( $ args [ 0 ] ) ; $ this -> bound -> setNorthEast ( $ args [ 1 ] ) ; } elseif ( ( isset ( $ args [ 0 ] ) && is_numeric ( $ args [ 0 ] ) ) && ( isset ( $ args [ 1 ] ) && is_numeric ( $ args [ 1 ] ) ) && ( isset ( $ args [ 2 ] ) && is_numeric ( $ args [ 2 ] ) ) && ( isset ( $ args [ 3 ] ) && is_numeric ( $ args [ 3 ] ) ) ) { if ( ! $ this -> hasBound ( ) ) { $ this -> bound = new Bound ( ) ; } $ this -> bound -> setSouthWest ( new Coordinate ( $ args [ 0 ] , $ args [ 1 ] ) ) ; $ this -> bound -> setNorthEast ( new Coordinate ( $ args [ 2 ] , $ args [ 3 ] ) ) ; if ( isset ( $ args [ 4 ] ) && is_bool ( $ args [ 4 ] ) ) { $ this -> bound -> getSouthWest ( ) -> setNoWrap ( $ args [ 4 ] ) ; } if ( isset ( $ args [ 5 ] ) && is_bool ( $ args [ 5 ] ) ) { $ this -> bound -> getNorthEast ( ) -> setNoWrap ( $ args [ 5 ] ) ; } } elseif ( ! isset ( $ args [ 0 ] ) ) { $ this -> bound = null ; } else { throw GeocodingException :: invalidGeocoderRequestBound ( ) ; } }

Sets the geocoder request bound.

Available prototypes:
- function setBound(Ivory\GoogleMap\Base\Bound $bound = null)
- function setBount(Ivory\GoogleMap\Base\Coordinate $southWest, Ivory\GoogleMap\Base\Coordinate $northEast)
- function setBound(
double $southWestLatitude,
double $southWestLongitude,
double $northEastLatitude,
double $northEastLongitude,
boolean southWestNoWrap = true,
boolean $northEastNoWrap = true
)

@throws \Ivory\GoogleMap\Exception\GeocodingException If the bound is not valid.


public function setRegion($region = null)
    {
        if ((!is_string($region) || (strlen($region) !== 2)) && ($region !== null)) {
            throw GeocodingException::invalidGeocoderRequestRegion();
        }

        $this->region = $region;
    }

public function setRegion ( $ region = null ) { if ( ( ! is_string ( $ region ) || ( strlen ( $ region ) !== 2 ) ) && ( $ region !== null ) ) { throw GeocodingException :: invalidGeocoderRequestRegion ( ) ; } $ this -> region = $ region ; }

Sets the geocoder request region.

@param string $region The geocoder request region.

@throws \Ivory\GoogleMap\Exception\GeocodingException If the regin is not valid.


public function setLanguage($language = null)
    {
        if ((!is_string($language) || ((strlen($language) !== 2) && (strlen($language) !== 5))) && ($language !== null)) {
            throw GeocodingException::invalidGeocoderRequestLanguage();
        }

        $this->language = $language;
    }

public function setLanguage ( $ language = null ) { if ( ( ! is_string ( $ language ) || ( ( strlen ( $ language ) !== 2 ) && ( strlen ( $ language ) !== 5 ) ) ) && ( $ language !== null ) ) { throw GeocodingException :: invalidGeocoderRequestLanguage ( ) ; } $ this -> language = $ language ; }

Sets the geocoder request language.

@param string $language The geocoder request language.

@throws \Ivory\GoogleMap\Exception\GeocodingException If the language is not valid.


public function load(array $args = [])
    {
        $default_args = [
            'path'        => '',
            'dir'         => '',
            'vars'        => [],
            'on_resolved' => null,
        ];
        $args += $default_args;

        $args['path'] = (string) $args['path'];
        $args['dir']  = (string) $args['dir'];
        $args['vars'] = (array) $args['vars'];

        if (($resolved = $this->resolve($args['path'], $args['dir'], $args))) {
            if (isset($args['on_resolved']) && is_callable($args['on_resolved'])) {
                $args['on_resolved']($resolved);
            }
            exit($this->get($resolved)->parse($args['vars']));
        } else {
            $this->c::die(404); // Unable to resolve.
        }
    }

public
function
load
(
array
$
args
=
[
]
)
{
$
default_args
=
[
'path'
=>
''
,
'dir'
=>
''
,
'vars'
=>
[
]
,
'on_resolved'
=>
,
]
;
$
args
+=
$
default_args
;
$
args
[
'path'
]
=
(
string
)
$
args
[
'path'
]
;
$
args
[
'dir'
]
=
(
string
)
$
args
[
'dir'
]
;
$
args
[
'vars'
]
=
(
array
)
$
args
[
'vars'
]
;
if
(
(
$
resolved
=
$
this
->
resolve
(
$
args
[
'path'
]
,
$
args
[
'dir'
]
,
$
args
)
)
)
{
if
(
isset
(
$
args
[
'on_resolved'
]
)
&&
is_callable
(
$
args
[
'on_resolved'
]
)
)
{
$
args
[
'on_resolved'
]
(
$
resolved
)
;
}
exit
(
$
this
->
get
(
$
resolved
)
->
parse
(
$
args
[
'vars'
]
)
)
;
}
else
{
$
this
->
c
::
die
(
404
)
;
// Unable to resolve.
}
}

Loads route file.

@since 161008 Route utilities.
@since 17xxxx Exit instead of return.

@param array $args Behavioral args.


public function get(array $args = []): Classes\Core\Route
    {
        return $this->App->Di->get(Classes\Core\Route::class, compact('args'));
    }

public function get ( array $ args = [ ] ) : Classes \ Core \ Route { return $ this -> App -> Di -> get ( Classes \ Core \ Route :: class , compact ( 'args' ) ) ; }

Gets route.

@since 161008 Route utilities.

@param array $args Route instance args.

@return Classes\Core\Route Route instance.


public function parse($value)
    {
        if (is_array($value) || is_object($value)) {
            foreach ($value as $_key => &$_value) {
                $_value = $this->parse($_value, $args);
            } // unset($_key, $_value);

            return $value;
        }
        if (!($yaml = (string) $value)) {
            return []; // Empty.
        }
        try {
            $array = Parser::parse($yaml);
        } catch (\Throwable $Throwable) {
            $array = []; // Empty.
        }
        return is_array($array) ? $array : [];
    }

public
function
parse
(
$
value
)
{
if
(
is_array
(
$
value
)
||
is_object
(
$
value
)
)
{
foreach
(
$
value
as
$
_key
=>
&
$
_value
)
{
$
_value
=
$
this
->
parse
(
$
_value
,
$
args
)
;
}
// unset($_key, $_value);
return
$
value
;
}
if
(
!
(
$
yaml
=
(
string
)
$
value
)
)
{
return
[
]
;
// Empty.
}
try
{
$
array
=
Parser
::
parse
(
$
yaml
)
;
}
catch
(
\
Throwable
$
Throwable
)
{
$
array
=
[
]
;
// Empty.
}
return
is_array
(
$
array
)
$
array
:
[
]
;
}

YAML parser.

@since 150424 Initial release.

@param mixed $value Any input value.

@return array|object Converted value(s).


public function setFlags()
    {
        if ($this->c::isWordPress()) {
            if (!defined('DONOTCACHEPAGE')) {
                define('DONOTCACHEPAGE', true);
            }
            if (!defined('COMET_CACHE_ALLOWED')) {
                define('COMET_CACHE_ALLOWED', false);
            }
            $_SERVER['COMET_CACHE_ALLOWED'] = false;
        }
    }

public function setFlags ( ) { if ( $ this -> c :: isWordPress ( ) ) { if ( ! defined ( 'DONOTCACHEPAGE' ) ) { define ( 'DONOTCACHEPAGE' , true ) ; } if ( ! defined ( 'COMET_CACHE_ALLOWED' ) ) { define ( 'COMET_CACHE_ALLOWED' , false ) ; } $ _SERVER [ 'COMET_CACHE_ALLOWED' ] = false ; } }

Set no-cache flags.

@since 160606 No-cache utils.


public function byKey(array $array, int $flags = SORT_REGULAR): array
    {
        ksort($array, $flags);

        foreach ($array as $_key => &$_value) {
            if (is_array($_value)) {
                $_value = $this->byKey($_value, $flags);
            }
        } // unset($_key, $_value); // Housekeeping.

        return $array;
    }

Sorts by key.

@since 150424 Array utils.

@param array $array Input array.
@param int   $flags Defaults to `SORT_REGULAR`.

@return array Output array.


public function method(): string
    {
        if (($method = &$this->cacheKey(__FUNCTION__)) !== null) {
            return $method; // Cached this already.
        }
        return $method = mb_strtoupper($_SERVER['REQUEST_METHOD']);
    }

public
function
method
(
)
:
string
{
if
(
(
$
method
=
&
$
this
->
cacheKey
(
__FUNCTION__
)
)
!==
)
{
return
$
method
;
// Cached this already.
}
return
$
method
=
mb_strtoupper
(
$
_SERVER
[
'REQUEST_METHOD'
]
)
;
}

Current request method.

@since 170824.30708 Current method.

@return string Current method.


public function scheme(): string
    {
        if (($scheme = &$this->cacheKey(__FUNCTION__)) !== null) {
            return $scheme; // Cached this already.
        }
        return $scheme = $this->isSsl() ? 'https' : 'http';
    }

public
function
scheme
(
)
:
string
{
if
(
(
$
scheme
=
&
$
this
->
cacheKey
(
__FUNCTION__
)
)
!==
)
{
return
$
scheme
;
// Cached this already.
}
return
$
scheme
=
$
this
->
isSsl
(
)
'https'
:
'http'
;
}

Current scheme; lowercase.

@since 150424 Initial release.

@return string Current scheme; lowercase.


public function host(bool $with_port = true): string
    {
        if (($host = &$this->cacheKey(__FUNCTION__, $with_port)) !== null) {
            return $host; // Cached this already.
        }
        $host = mb_strtolower($_SERVER['HTTP_HOST']);

        if (!$with_port) { // Strip port number?
            $host = preg_replace('/\:[0-9]+$/u', '', $host);
        }
        return $host; // With or without port number.
    }

public
function
host
(
bool
$
with_port
=
true
)
:
string
{
if
(
(
$
host
=
&
$
this
->
cacheKey
(
__FUNCTION__
,
$
with_port
)
)
!==
)
{
return
$
host
;
// Cached this already.
}
$
host
=
mb_strtolower
(
$
_SERVER
[
'HTTP_HOST'
]
)
;
if
(
!
$
with_port
)
{
// Strip port number?
$
host
=
preg_replace
(
'/\:[0-9]+$/u'
,
''
,
$
host
)
;
}
return
$
host
;
// With or without port number.
}

Current host name; lowercase.

@since 150424 Initial release.

@param bool $with_port With port number?

@return string Current host name; lowercase.


public function rootHost(bool $with_port = true): string
    {
        if (($root_host = &$this->cacheKey(__FUNCTION__, $with_port)) !== null) {
            return $root_host; // Cached this already.
        }
        $name_parts       = explode('.', $this->host(false));
        $root_name        = implode('.', array_slice($name_parts, -2));
        $port             = $this->port(); // Might be needed in next line.
        return $root_host = $root_name.(!$with_port ? '' : (isset($port[0]) ? ':'.$port : ''));
    }

public
function
rootHost
(
bool
$
with_port
=
true
)
:
string
{
if
(
(
$
root_host
=
&
$
this
->
cacheKey
(
__FUNCTION__
,
$
with_port
)
)
!==
)
{
return
$
root_host
;
// Cached this already.
}
$
name_parts
=
explode
(
'.'
,
$
this
->
host
(
false
)
)
;
$
root_name
=
implode
(
'.'
,
array_slice
(
$
name_parts
,
2
)
)
;
$
port
=
$
this
->
port
(
)
;
// Might be needed in next line.
return
$
root_host
=
$
root_name
.
(
!
$
with_port
''
:
(
isset
(
$
port
[
0
]
)
':'
.
$
port
:
''
)
)
;
}

Current root host name; lowercase.

@since 151002 Adding root host support.

@param bool $with_port With port number?

@return string Current root host name; lowercase.


public function isSsl(): bool
    {
        if (($is = &$this->cacheKey(__FUNCTION__)) !== null) {
            return $is; // Cached this already.
        }
        if (!empty($_SERVER['SERVER_PORT'])) {
            if ((int) $_SERVER['SERVER_PORT'] === 443) {
                return $is = true;
            }
        }
        if (!empty($_SERVER['HTTPS'])) {
            if (filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN)) {
                return $is = true;
            }
        }
        if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
            if ($this->c::mbStrCaseCmp($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') === 0) {
                return $is = true;
            }
        }
        return $is = false;
    }

public
function
isSsl
(
)
:
bool
{
if
(
(
$
is
=
&
$
this
->
cacheKey
(
__FUNCTION__
)
)
!==
)
{
return
$
is
;
// Cached this already.
}
if
(
!
empty
(
$
_SERVER
[
'SERVER_PORT'
]
)
)
{
if
(
(
int
)
$
_SERVER
[
'SERVER_PORT'
]
===
443
)
{
return
$
is
=
true
;
}
}
if
(
!
empty
(
$
_SERVER
[
'HTTPS'
]
)
)
{
if
(
filter_var
(
$
_SERVER
[
'HTTPS'
]
,
FILTER_VALIDATE_BOOLEAN
)
)
{
return
$
is
=
true
;
}
}
if
(
!
empty
(
$
_SERVER
[
'HTTP_X_FORWARDED_PROTO'
]
)
)
{
if
(
$
this
->
c
::
mbStrCaseCmp
(
$
_SERVER
[
'HTTP_X_FORWARDED_PROTO'
]
,
'https'
)
===
0
)
{
return
$
is
=
true
;
}
}
return
$
is
=
false
;
}

Is an SSL scheme?

@since 150424 Initial release.

@return bool Is an SSL scheme?


public function isLocalhost(): bool
    {
        if (($is = &$this->cacheKey(__FUNCTION__)) !== null) {
            return $is; // Cached this already.
        }
        if (defined('LOCALHOST') && LOCALHOST) {
            return $is = true;
        } elseif (preg_match('/(?:\b(?:localhost|127\.0\.0\.1)\b|\.vm)$/ui', $this->host(false))) {
            return $is = true;
        }
        return $is = false;
    }

Current URL is on a localhost?

@since 150424 Initial release.

@return bool `TRUE` if current URL is on a localhost.


public function setLocationType($locationType)
    {
        if (!in_array($locationType, GeocoderLocationType::getGeocoderLocationTypes())) {
            throw GeocodingException::invalidGeocoderLocationType();
        }

        $this->locationType = $locationType;
    }

public function setLocationType ( $ locationType ) { if ( ! in_array ( $ locationType , GeocoderLocationType :: getGeocoderLocationTypes ( ) ) ) { throw GeocodingException :: invalidGeocoderLocationType ( ) ; } $ this -> locationType = $ locationType ; }

Sets the geometry location type.

@param string $locationType The geometry location type.

@throws \Ivory\GoogleMap\Exception\GeocodingException If the location type is not valid.


public function m0EscNoVws(string $escapable_chars, bool $ungreedy = false): string
    {
        $escapable_chars = $this->__invoke($escapable_chars);
        return '(?:[^\v'.$escapable_chars.'\\\\]|\\\\['.$escapable_chars.'])*'.($ungreedy ? '?' : '');
    }

public function m0EscNoVws ( string $ escapable_chars , bool $ ungreedy = false ) : string { $ escapable_chars = $ this -> __invoke ( $ escapable_chars ) ; return '(?:[^\v' . $ escapable_chars . '\\\\]|\\\\[' . $ escapable_chars . '])*' . ( $ ungreedy ? '?' : '' ) ; }

Matches zero or more escapable chars,
and anything that's not vertical whitespace.

@since 170211.63148 Markdown enhancements.

@param string $escapable_chars Escapable chars.
@param bool   $ungreedy        Ungreedy matching?

@return string Regex fragment suitable for `preg_*()`.

Matches zero or more escapable chars and anything that s not vertical whitespace .


public static function getDirectionsStatus()
    {
        return array(
            self::INVALID_REQUEST,
            self::MAX_WAYPOINTS_EXCEEDED,
            self::NOT_FOUND,
            self::OK,
            self::OVER_QUERY_LIMIT,
            self::REQUEST_DENIED,
            self::UNKNOWN_ERROR,
            self::ZERO_RESULTS,
        );
    }

public static function getDirectionsStatus ( ) { return array ( self :: INVALID_REQUEST , self :: MAX_WAYPOINTS_EXCEEDED , self :: NOT_FOUND , self :: OK , self :: OVER_QUERY_LIMIT , self :: REQUEST_DENIED , self :: UNKNOWN_ERROR , self :: ZERO_RESULTS , ) ; }

Gets the available directions status.

@return array The available directions status.


protected function overloadData(): array
    {
        foreach ($this->x___overload_data as $_key => $_value) {
            $properties[$_key] = $_value;
        } // unset($_key, $_value);

        return $properties ?? [];
    }

protected
function
overloadData
(
)
:
array
{
foreach
(
$
this
->
x___overload_data
as
$
_key
=>
$
_value
)
{
$
properties
[
$
_key
]
=
$
_value
;
}
// unset($_key, $_value);
return
$
properties
??
[
]
;
}

Current overload data.

@since 17xxxx Overload conditional.

@return array Current overload data.


protected function overloadPropertyData(): array
    {
        foreach ($this->x___overload_data as $_key => $_value) {
            if (!is_callable($_value)) {
                $properties[$_key] = $_value;
            }
        } // unset($_key, $_value);

        return $properties ?? [];
    }

protected
function
overloadPropertyData
(
)
:
array
{
foreach
(
$
this
->
x___overload_data
as
$
_key
=>
$
_value
)
{
if
(
!
is_callable
(
$
_value
)
)
{
$
properties
[
$
_key
]
=
$
_value
;
}
}
// unset($_key, $_value);
return
$
properties
??
[
]
;
}

Overload property data.

@since 17xxxx Enhance overload utils.

@return array Overload property data.


protected function writableOverloadPropertyData(): array
    {
        foreach ($this->x___overload_data as $_key => $_value) {
            if (isset($this->x___writable_overload_keys[$_key]) && !is_callable($_value)) {
                $properties[$_key] = $_value;
            }
        } // unset($_key, $_value);

        return $properties ?? [];
    }

protected
function
writableOverloadPropertyData
(
)
:
array
{
foreach
(
$
this
->
x___overload_data
as
$
_key
=>
$
_value
)
{
if
(
isset
(
$
this
->
x___writable_overload_keys
[
$
_key
]
)
&&
!
is_callable
(
$
_value
)
)
{
$
properties
[
$
_key
]
=
$
_value
;
}
}
// unset($_key, $_value);
return
$
properties
??
[
]
;
}

Writable overload property data.

@since 17xxxx Enhance overload utils.

@return array Writable overload property data.


protected function overload($properties, bool $writable = false)
    {
        if (is_object($properties)) {
            foreach ($properties as $_property => &$_value) {
                if ($writable) {
                    unset($this->{$_property});
                    unset($this->x___overload_data[$_property]);
                    $this->x___writable_overload_keys[$_property] = 1;
                    $this->{$_property}                           = null;
                    $this->{$_property}                           = &$_value;
                    $this->x___overload_data[$_property]          = &$this->{$_property};
                } else { // NOT writable.
                    unset($this->{$_property});
                    unset($this->x___overload_data[$_property]);
                    unset($this->x___writable_overload_keys[$_property]);
                    $this->x___overload_data[$_property] = &$_value;
                }
            } // unset($_property, $_value);
            return; // Stop now; all done here.
            //
        } elseif (is_array($properties)) {
            foreach ($properties as $_key => $_property) {
                if (!property_exists($this, $_property)) {
                    throw $this->c::issue([], sprintf('No `%1$s` property.', $_property), __METHOD__);
                }
                if ($writable) {
                    unset($this->x___overload_data[$_property]);
                    $this->x___writable_overload_keys[$_property] = -1;
                    $this->x___overload_data[$_property]          = &$this->{$_property};
                } else { // NOT writable.
                    unset($this->x___overload_data[$_property]);
                    unset($this->x___writable_overload_keys[$_property]);
                    $this->x___overload_data[$_property] = &$this->{$_property};
                }
            } // unset($_key, $_property);
            return; // Stop now; all done here.
        }
        throw $this->c::issue([], sprintf('`%1$s`; expecting object/array.', gettype($properties)), __METHOD__);
    }

protected
function
overload
(
$
properties
,
bool
$
writable
=
false
)
{
if
(
is_object
(
$
properties
)
)
{
foreach
(
$
properties
as
$
_property
=>
&
$
_value
)
{
if
(
$
writable
)
{
unset
(
$
this
->
{
$
_property
}
)
;
unset
(
$
this
->
x___overload_data
[
$
_property
]
)
;
$
this
->
x___writable_overload_keys
[
$
_property
]
=
1
;
$
this
->
{
$
_property
}
=
;
$
this
->
{
$
_property
}
=
&
$
_value
;
$
this
->
x___overload_data
[
$
_property
]
=
&
$
this
->
{
$
_property
}
;
}
else
{
// NOT writable.
unset
(
$
this
->
{
$
_property
}
)
;
unset
(
$
this
->
x___overload_data
[
$
_property
]
)
;
unset
(
$
this
->
x___writable_overload_keys
[
$
_property
]
)
;
$
this
->
x___overload_data
[
$
_property
]
=
&
$
_value
;
}
}
// unset($_property, $_value);
return
;
// Stop now; all done here.
//
}
elseif
(
is_array
(
$
properties
)
)
{
foreach
(
$
properties
as
$
_key
=>
$
_property
)
{
if
(
!
property_exists
(
$
this
,
$
_property
)
)
{
throw
$
this
->
c
::
issue
(
[
]
,
sprintf
(
'No `%1$s` property.'
,
$
_property
)
,
__METHOD__
)
;
}
if
(
$
writable
)
{
unset
(
$
this
->
x___overload_data
[
$
_property
]
)
;
$
this
->
x___writable_overload_keys
[
$
_property
]
=
1
;
$
this
->
x___overload_data
[
$
_property
]
=
&
$
this
->
{
$
_property
}
;
}
else
{
// NOT writable.
unset
(
$
this
->
x___overload_data
[
$
_property
]
)
;
unset
(
$
this
->
x___writable_overload_keys
[
$
_property
]
)
;
$
this
->
x___overload_data
[
$
_property
]
=
&
$
this
->
{
$
_property
}
;
}
}
// unset($_key, $_property);
return
;
// Stop now; all done here.
}
throw
$
this
->
c
::
issue
(
[
]
,
sprintf
(
'`%1$s`; expecting object/array.'
,
gettype
(
$
properties
)
)
,
__METHOD__
)
;
}

Setup overloads.

@since 150424 Initial release.

@param array|object $properties Property(s).

@internal This will overload properties by reference.
Object properties can be set as writable or not writable.
-
@internal Property names can be overloaded to provide public or JSON access.
Overloaded object property names can be set as writable or not writable.

@param bool $writable Overloaded properties are writable?


public function openUrl(string $url)
    {
        if (!($url = $this->c::mbTrim($url))) {
            return; // Not possible.
        }
        $url_arg = escapeshellarg($url);

        if ($this->c::isMac()) {
            `open $url_arg`;
        } elseif ($this->c::isLinux()) {
            `xdg-open $url_arg`;
        } elseif ($this->c::isWindows()) {
            `start $url_arg`;
        } else {
            throw $this->c::issue('Unable to open <'.$url.'>. Unsupported operating system.');
        }
    }

Open a URL from the command line.

@since 150424 Initial release.

@param string $url The URL to open.


public function setAnchor()
    {
        $args = func_get_args();

        if ($args[0] instanceof Point) {
            $this->anchor = $args[0];
        } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) {
            if ($this->anchor === null) {
                $this->anchor = new Point();
            }

            $this->anchor->setX($args[0]);
            $this->anchor->setY($args[1]);
        } elseif (!isset($args[0])) {
            $this->anchor = null;
        } else {
            throw OverlayException::invalidMarkerImageAnchor();
        }
    }

public function setAnchor ( ) { $ args = func_get_args ( ) ; if ( $ args [ 0 ] instanceof Point ) { $ this -> anchor = $ args [ 0 ] ; } elseif ( ( isset ( $ args [ 0 ] ) && is_numeric ( $ args [ 0 ] ) ) && ( isset ( $ args [ 1 ] ) && is_numeric ( $ args [ 1 ] ) ) ) { if ( $ this -> anchor === null ) { $ this -> anchor = new Point ( ) ; } $ this -> anchor -> setX ( $ args [ 0 ] ) ; $ this -> anchor -> setY ( $ args [ 1 ] ) ; } elseif ( ! isset ( $ args [ 0 ] ) ) { $ this -> anchor = null ; } else { throw OverlayException :: invalidMarkerImageAnchor ( ) ; } }

Sets the anchor of the marker image

Available prototypes:
- function setAnchor(Ivory\GoogleMap\Base\Point $anchor = null)
- function setAnchor(double x, double y)

@throws \Ivory\GoogleMap\Exception\OverlayException If the anchor is not valid (prototypes).


public function setOrigin()
    {
        $args = func_get_args();

        if (isset($args[0]) && ($args[0] instanceof Point)) {
            $this->origin = $args[0];
        } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) {
            if ($this->origin === null) {
                $this->origin = new Point();
            }

            $this->origin->setX($args[0]);
            $this->origin->setY($args[1]);
        } elseif (!isset($args[0])) {
            $this->origin = null;
        } else {
            throw OverlayException::invalidMarkerImageOrigin();
        }
    }

public function setOrigin ( ) { $ args = func_get_args ( ) ; if ( isset ( $ args [ 0 ] ) && ( $ args [ 0 ] instanceof Point ) ) { $ this -> origin = $ args [ 0 ] ; } elseif ( ( isset ( $ args [ 0 ] ) && is_numeric ( $ args [ 0 ] ) ) && ( isset ( $ args [ 1 ] ) && is_numeric ( $ args [ 1 ] ) ) ) { if ( $ this -> origin === null ) { $ this -> origin = new Point ( ) ; } $ this -> origin -> setX ( $ args [ 0 ] ) ; $ this -> origin -> setY ( $ args [ 1 ] ) ; } elseif ( ! isset ( $ args [ 0 ] ) ) { $ this -> origin = null ; } else { throw OverlayException :: invalidMarkerImageOrigin ( ) ; } }

Sets the origin of the marker image

Available prototypes:
- function setOrigin(Ivory\GoogleMap\Base\Point $origin = null)
- function setOrigin(double x, double y)

@throws \Ivory\GoogleMap\Exception\OverlayException If the origin is not valid.


public function setScaledSize()
    {
        $args = func_get_args();

        if (isset($args[0]) && ($args[0] instanceof Size)) {
            $this->scaledSize = $args[0];
        } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) {
            if ($this->scaledSize === null) {
                $this->scaledSize = new Size();
            }

            $this->scaledSize->setWidth($args[0]);
            $this->scaledSize->setHeight($args[1]);

            if (isset($args[2]) && is_string($args[2])) {
                $this->scaledSize->setWidthUnit($args[2]);
            }

            if (isset($args[3]) && is_string($args[3])) {
                $this->scaledSize->setHeightUnit($args[3]);
            }
        } elseif (!isset($args[0])) {
            $this->scaledSize = null;
        } else {
            throw OverlayException::invalidMarkerImageScaledSize();
        }
    }

public function setScaledSize ( ) { $ args = func_get_args ( ) ; if ( isset ( $ args [ 0 ] ) && ( $ args [ 0 ] instanceof Size ) ) { $ this -> scaledSize = $ args [ 0 ] ; } elseif ( ( isset ( $ args [ 0 ] ) && is_numeric ( $ args [ 0 ] ) ) && ( isset ( $ args [ 1 ] ) && is_numeric ( $ args [ 1 ] ) ) ) { if ( $ this -> scaledSize === null ) { $ this -> scaledSize = new Size ( ) ; } $ this -> scaledSize -> setWidth ( $ args [ 0 ] ) ; $ this -> scaledSize -> setHeight ( $ args [ 1 ] ) ; if ( isset ( $ args [ 2 ] ) && is_string ( $ args [ 2 ] ) ) { $ this -> scaledSize -> setWidthUnit ( $ args [ 2 ] ) ; } if ( isset ( $ args [ 3 ] ) && is_string ( $ args [ 3 ] ) ) { $ this -> scaledSize -> setHeightUnit ( $ args [ 3 ] ) ; } } elseif ( ! isset ( $ args [ 0 ] ) ) { $ this -> scaledSize = null ; } else { throw OverlayException :: invalidMarkerImageScaledSize ( ) ; } }

Sets the scaled size of the marker image

Available prototypes:
- function setScaledSize(Ivory\GoogleMap\Base\Size $scaledSize = null)
- function setScaledSize(double $width, double $height, string $widthUnit = null, string $heightUnit = null)

@throws \Ivory\GoogleMap\Exception\OverlayException If the scaled size is not valid.


public function setSize()
    {
        $args = func_get_args();

        if (isset($args[0]) && ($args[0] instanceof Size)) {
            $this->size = $args[0];
        } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) {
            if ($this->size === null) {
                $this->size = new Size($args[0], $args[1]);
            }

            $this->size->setWidth($args[0]);
            $this->size->setHeight($args[1]);

            if (isset($args[2]) && is_string($args[2])) {
                $this->size->setWidthUnit($args[2]);
            }

            if (isset($args[3]) && is_string($args[3])) {
                $this->size->setHeightUnit($args[3]);
            }
        } elseif (!isset($args[0])) {
            $this->size = null;
        } else {
            throw OverlayException::invalidMarkerImageSize();
        }
    }

public function setSize ( ) { $ args = func_get_args ( ) ; if ( isset ( $ args [ 0 ] ) && ( $ args [ 0 ] instanceof Size ) ) { $ this -> size = $ args [ 0 ] ; } elseif ( ( isset ( $ args [ 0 ] ) && is_numeric ( $ args [ 0 ] ) ) && ( isset ( $ args [ 1 ] ) && is_numeric ( $ args [ 1 ] ) ) ) { if ( $ this -> size === null ) { $ this -> size = new Size ( $ args [ 0 ] , $ args [ 1 ] ) ; } $ this -> size -> setWidth ( $ args [ 0 ] ) ; $ this -> size -> setHeight ( $ args [ 1 ] ) ; if ( isset ( $ args [ 2 ] ) && is_string ( $ args [ 2 ] ) ) { $ this -> size -> setWidthUnit ( $ args [ 2 ] ) ; } if ( isset ( $ args [ 3 ] ) && is_string ( $ args [ 3 ] ) ) { $ this -> size -> setHeightUnit ( $ args [ 3 ] ) ; } } elseif ( ! isset ( $ args [ 0 ] ) ) { $ this -> size = null ; } else { throw OverlayException :: invalidMarkerImageSize ( ) ; } }

Sets the size of the marker image.

Available prototypes:
- function setSize(Ivory\GoogleMap\Base\Size $size = null)
- function setSize(double $width, double $height, string $widthUnit = null, string $heightUnit = null)

@throws \Ivory\GoogleMap\Exception\OverlayException If the size is not valid.


public function render(InfoWindow $infoWindow, $renderPosition = true)
    {
        $this->doRender($infoWindow, $renderPosition);

        return sprintf(
            '%s = new google.maps.InfoWindow(%s);'.PHP_EOL,
            $infoWindow->getJavascriptVariable(),
            $this->jsonBuilder->build()
        );
    }

public
function
render
(
InfoWindow
$
infoWindow
,
$
renderPosition
=
true
)
{
$
this
->
doRender
(
$
infoWindow
,
$
renderPosition
)
;
return
sprintf
(
'%s = new google.maps.InfoWindow(%s);'
.
PHP_EOL
,
$
infoWindow
->
getJavascriptVariable
(
)
,
$
this
->
jsonBuilder
->
build
(
)
)
;
}

Renders an info window.

@param \Ivory\GoogleMap\Overlays\InfoWindow $infoWindow     The info window.
@param boolean                              $renderPosition TRUE if the position is rendered else FALSE.

@return string The JS output.


public function renderOpen(InfoWindow $infoWindow, Map $map, Marker $marker = null)
    {
        if ($marker !== null) {
            return sprintf(
                '%s.open(%s, %s);'.PHP_EOL,
                $infoWindow->getJavascriptVariable(),
                $map->getJavascriptVariable(),
                $marker->getJavascriptVariable()
            );
        }

        return sprintf('%s.open(%s);'.PHP_EOL, $infoWindow->getJavascriptVariable(), $map->getJavascriptVariable());
    }

public
function
renderOpen
(
InfoWindow
$
infoWindow
,
Map
$
map
,
Marker
$
marker
=
)
{
if
(
$
marker
!==
)
{
return
sprintf
(
'%s.open(%s, %s);'
.
PHP_EOL
,
$
infoWindow
->
getJavascriptVariable
(
)
,
$
map
->
getJavascriptVariable
(
)
,
$
marker
->
getJavascriptVariable
(
)
)
;
}
return
sprintf
(
'%s.open(%s);'
.
PHP_EOL
,
$
infoWindow
->
getJavascriptVariable
(
)
,
$
map
->
getJavascriptVariable
(
)
)
;
}

Renders the info window open flag.

@param \Ivory\GoogleMap\Overlays\InfoWindow $infoWindow The info window.
@param \Ivory\GoogleMap\Map                 $map        The map.
@param \Ivory\GoogleMap\Overlays\Marker     $marker     The marker.

@return string The JS output.


protected function doRender(InfoWindow $infoWindow, $renderPosition)
    {
        $this->jsonBuilder->reset();

        if ($renderPosition) {
            $this->jsonBuilder->setValue('[position]', $infoWindow->getPosition()->getJavascriptVariable(), false);
        }

        if ($infoWindow->hasPixelOffset()) {
            $this->jsonBuilder->setValue(
                '[pixelOffset]',
                $infoWindow->getPixelOffset()->getJavascriptVariable(),
                false
            );
        }

        $this->jsonBuilder
            ->setValue('[content]', $infoWindow->getContent())
            ->setValues($infoWindow->getOptions());
    }

protected function doRender ( InfoWindow $ infoWindow , $ renderPosition ) { $ this -> jsonBuilder -> reset ( ) ; if ( $ renderPosition ) { $ this -> jsonBuilder -> setValue ( '[position]' , $ infoWindow -> getPosition ( ) -> getJavascriptVariable ( ) , false ) ; } if ( $ infoWindow -> hasPixelOffset ( ) ) { $ this -> jsonBuilder -> setValue ( '[pixelOffset]' , $ infoWindow -> getPixelOffset ( ) -> getJavascriptVariable ( ) , false ) ; } $ this -> jsonBuilder -> setValue ( '[content]' , $ infoWindow -> getContent ( ) ) -> setValues ( $ infoWindow -> getOptions ( ) ) ; }

Configures the json builder in order to render an info window.

@param \Ivory\GoogleMap\Helper\Overlays\InfoWinfow $infoWindow     The info window.
@param boolean                                     $renderPosition TRUE if the position is rendered else FALSE.

Configures the json builder in order to render an info window .


public function register(Application $app)
    {
        $this->enabled()->each(function (Module $module) use ($app) {
            array_map(function ($class) use ($app) {
                /* @var ServiceProvider $provider */
                $provider = new $class($app);
                if ($provider->isDeferred()) {
                    $app->addDeferredServices(array_fill_keys($provider->provides(), $provider));
                } else {
                    $app->register($provider);
                }
            }, array_filter($module->getProviders(), 'class_exists'));
        });
    }

public
function
register
(
Application
$
app
)
{
$
this
->
enabled
(
)
->
each
(
function
(
Module
$
module
)
use
(
$
app
)
{
array_map
(
function
(
$
class
)
use
(
$
app
)
{
/* @var ServiceProvider $provider */
$
provider
=
new
$
class
(
$
app
)
;
if
(
$
provider
->
isDeferred
(
)
)
{
$
app
->
addDeferredServices
(
array_fill_keys
(
$
provider
->
provides
(
)
,
$
provider
)
)
;
}
else
{
$
app
->
register
(
$
provider
)
;
}
}
,
array_filter
(
$
module
->
getProviders
(
)
,
'class_exists'
)
)
;
}
)
;
}

Register module providers.

@param Application $app


public function asset(string $module, string $path, $secure = null): string
    {
        if ($this->assetResolver && ($url = call_user_func($this->assetResolver, $module, $path, $secure)) !== null) {
            return $url;
        }

        return $this->app->make('url')->asset($this->getAssetsPath() . "/{$module}/" . $path, $secure);
    }

public function asset ( string $ module , string $ path , $ secure = null ) : string { if ( $ this -> assetResolver && ( $ url = call_user_func ( $ this -> assetResolver , $ module , $ path , $ secure ) ) !== null ) { return $ url ; } return $ this -> app -> make ( 'url' ) -> asset ( $ this -> getAssetsPath ( ) . "/{$module}/" . $ path , $ secure ) ; }

Get module asset.

@param string $module
@param string $path
@param null   $secure

@return string


public function loadRoutes(string $scope = 'web')
    {
        $this->app->make('router')->group([
            'as' => $scope === 'web' ? '' : "{$scope}.",
        ], function (Router $router) use ($scope) {
            $this->enabled()->each(function (Module $module) use ($scope, $router) {
                $path = $module->getPath("routes/{$scope}.php");
                if (file_exists($path)) {
                    $router->group([
                        'namespace' => $module->getNamespace() . '\\Http\\Controllers',
                    ], function (Router $router) use ($module, $path, $scope) {
                        $options = array_merge([
                            'namespace'  => $scope === 'web' ? null : Str::studly($scope),
                            'as'         => $module->getName() . '.',
                            'prefix'     => $module->getName(),
                            'middleware' => $scope,
                        ], $module->config("routes.{$scope}", []));
                        $router->group($options, function (Router $router) use ($path, $module) {
                            require($path);
                        });
                    });
                }
            });
        });
    }

public function loadRoutes ( string $ scope = 'web' ) { $ this -> app -> make ( 'router' ) -> group ( [ 'as' => $ scope === 'web' ? '' : "{$scope}." , ] , function ( Router $ router ) use ( $ scope ) { $ this -> enabled ( ) -> each ( function ( Module $ module ) use ( $ scope , $ router ) { $ path = $ module -> getPath ( "routes/{$scope}.php" ) ; if ( file_exists ( $ path ) ) { $ router -> group ( [ 'namespace' => $ module -> getNamespace ( ) . '\\Http\\Controllers' , ] , function ( Router $ router ) use ( $ module , $ path , $ scope ) { $ options = array_merge ( [ 'namespace' => $ scope === 'web' ? null : Str :: studly ( $ scope ) , 'as' => $ module -> getName ( ) . '.' , 'prefix' => $ module -> getName ( ) , 'middleware' => $ scope , ] , $ module -> config ( "routes.{$scope}" , [ ] ) ) ; $ router -> group ( $ options , function ( Router $ router ) use ( $ path , $ module ) { require ( $ path ) ; } ) ; } ) ; } } ) ; } ) ; }

Load modules routes.

@param string $scope


public function callableFunc(string $function): bool
    {
        $function = mb_strtolower($function);

        if (isset(static::$cache[__FUNCTION__][$function])) {
            return static::$cache[__FUNCTION__][$function];
        }
        if (!isset(static::$cache[__FUNCTION__.'s_disabled'])) {
            static::$cache[__FUNCTION__.'s_disabled'] = []; // Initialize.
            $_functions_disabled                      = &static::$cache[__FUNCTION__.'s_disabled'];

            if (($_ini_disable_functions = (string) ini_get('disable_functions'))) {
                $_ini_disable_functions = mb_strtolower($_ini_disable_functions);
                $_functions_disabled    = array_merge($_functions_disabled, preg_split('/[\s;,]+/u', $_ini_disable_functions, -1, PREG_SPLIT_NO_EMPTY));
            }
            if (($_ini_suhosin_blacklist_functions = (string) ini_get('suhosin.executor.func.blacklist'))) {
                $_ini_suhosin_blacklist_functions = mb_strtolower($_ini_suhosin_blacklist_functions);
                $_functions_disabled              = array_merge($_functions_disabled, preg_split('/[\s;,]+/u', $_ini_suhosin_blacklist_functions, -1, PREG_SPLIT_NO_EMPTY));
            }
            if (($_ini_opcache_restrict_api = (string) ini_get('opcache.restrict_api')) && mb_stripos(__FILE__, $_ini_opcache_restrict_api) !== 0) {
                $_functions_disabled = array_merge($_functions_disabled, ['opcache_compile_file', 'opcache_get_configuration', 'opcache_get_status', 'opcache_invalidate', 'opcache_is_script_cached', 'opcache_reset']);
            }
            if (filter_var(@ini_get('suhosin.executor.disable_eval'), FILTER_VALIDATE_BOOLEAN)) {
                $_functions_disabled[] = 'eval'; // The `eval()` construct is disabled also.
            }
        } // We now have a full list of all disabled functions.

        static::$cache[__FUNCTION__][$function] = null; // Initialize.
        $has                                    = &static::$cache[__FUNCTION__][$function];
        $functions_disabled                     = &static::$cache[__FUNCTION__.'s_disabled'];

        if ($functions_disabled && in_array($function, $functions_disabled, true)) {
            return $has = false; // Not possible; e.g., `eval()`.
        } elseif ((!function_exists($function) || !is_callable($function)) && !in_array($function, $this::CONSTRUCTS, true)) {
            return $has = false; // Not possible.
        }
        return $has = true;
    }

Is function callable?

@since 150424 Initial release.

@param string $function A PHP function.

@return bool True if the function is callable.

@internal This checks (among other things) if the function exists and that it's callable.
It also checks INI `disable_functions` & `suhosin.executor.func.blacklist`.
In addition, it also checks `suhosin.executor.disable_eval`.


public function render(GroundOverlay $groundOverlay, Map $map)
    {
        $this->jsonBuilder
            ->reset()
            ->setValue('[map]', $map->getJavascriptVariable(), false)
            ->setValues($groundOverlay->getOptions());

        return sprintf(
            '%s = new google.maps.GroundOverlay("%s", %s, %s);'.PHP_EOL,
            $groundOverlay->getJavascriptVariable(),
            $groundOverlay->getUrl(),
            $groundOverlay->getBound()->getJavascriptVariable(),
            $this->jsonBuilder->build()
        );
    }

Renders a ground overlay.

@param \Ivory\GoogleMap\Overlays\GroundOverlay $groundOverlay The ground overlay.
@param \Ivory\GoogleMap\Map                    $map           The map.

@return string The JS output.


public function emit(ResponseInterface $response): void
    {
        // Emit http status code
        echo sprintf(
            'HTTP/%s %s %s',
            $response->getProtocolVersion(),
            $response->getStatusCode(),
            $response->getReasonPhrase()
        ) . PHP_EOL;

        // Emit headers iteratively
        foreach ($response->getHeaders() as $name => $values) {
            foreach ($values as $value) {
                echo sprintf('%s: %s', $name, $value) . PHP_EOL;
            }
        }

        // End the headers
        echo PHP_EOL;

        // Emit body
        echo $response->getBody();
    }

public
function
emit
(
ResponseInterface
$
response
)
:
void
{
// Emit http status code
echo
sprintf
(
'HTTP/%s %s %s'
,
$
response
->
getProtocolVersion
(
)
,
$
response
->
getStatusCode
(
)
,
$
response
->
getReasonPhrase
(
)
)
.
PHP_EOL
;
// Emit headers iteratively
foreach
(
$
response
->
getHeaders
(
)
as
$
name
=>
$
values
)
{
foreach
(
$
values
as
$
value
)
{
echo
sprintf
(
'%s: %s'
,
$
name
,
$
value
)
.
PHP_EOL
;
}
}
// End the headers
echo
PHP_EOL
;
// Emit body
echo
$
response
->
getBody
(
)
;
}

Emit the response.

@param ResponseInterface $response

@return void


protected function &cacheSet(string $primary_key, $sub_key, $value)
    {
        if ($primary_key === 'x___keys' || $primary_key === 'x___refs') {
            throw $this->c::issue('Attempting to set a reserved primary key.');
        }
        $sub_key                                 = (string) $sub_key;
        $this->x___cache[$primary_key][$sub_key] = $value;
        return $this->x___cache[$primary_key][$sub_key];
    }

Set a cache sub-key.

@since 150424 Initial release.

@param string     $primary_key Primary key.
@param string|int $sub_key     Sub-key to set.
@param mixed      $value       New cache key value.

@return mixed|null Value (by reference) for the cache sub-key.

@internal Returns by reference. The use of `&` is highly recommended when calling this utility.
See also: <http://php.net/manual/en/language.references.return.php>


protected function &cacheGet(string $primary_key, $sub_key)
    {
        if ($primary_key === 'x___keys' || $primary_key === 'x___refs') {
            throw $this->c::issue('Attempting to get a reserved primary key.');
        }
        $sub_key = (string) $sub_key; // Force string.

        if (isset($this->x___cache[$primary_key][$sub_key])) {
            return $this->x___cache[$primary_key][$sub_key];
        } else {
            $this->x___cache[$primary_key][$sub_key] = null;
            return $this->x___cache[$primary_key][$sub_key];
        }
    }

Get a cache sub-key.

@since 150424 Initial release.

@param string     $primary_key Primary key.
@param string|int $sub_key     Sub-key to get.

@return mixed|null Value (by reference) for the cache sub-key.

@internal Returns by reference. The use of `&` is suggested when calling this utility.
See also: <http://php.net/manual/en/language.references.return.php>


protected function cacheUnset(string $primary_key, $sub_key)
    {
        if ($primary_key === 'x___keys' || $primary_key === 'x___refs') {
            throw $this->c::issue('Attempting to unset a reserved primary key.');
        }
        $sub_key                                 = (string) $sub_key;
        $this->x___cache[$primary_key][$sub_key] = null;
        unset($this->x___cache[$primary_key][$sub_key]);
    }

Unset a cache sub-key.

@since 150424 Initial release.

@param string     $primary_key Primary key.
@param string|int $sub_key     Sub-key to unset.


protected function cacheUnsetPattern(string $primary_key, string $sub_key_pattern)
    {
        if ($primary_key === 'x___keys' || $primary_key === 'x___refs') {
            throw $this->c::issue('Attempting to unset a reserved primary key.');
        }
        if (empty($this->x___cache[$primary_key])) {
            return; // Nothing to do here.
        }
        $sub_key_regex = // Allow `**` to indicate everything quickly.
            $sub_key_pattern === '**' ? '' : $this->c::wRegx($sub_key_pattern, '/', true);

        if (!$sub_key_regex && $sub_key_pattern !== '**') {
            return; // Nothing to do; i.e., no regex.
        }
        foreach (array_keys($this->x___cache[$primary_key]) as $_sub_key) {
            if ($sub_key_pattern === '**' || preg_match($sub_key_regex.'i', (string) $_sub_key)) {
                $this->x___cache[$primary_key][$_sub_key] = null;
                unset($this->x___cache[$primary_key][$_sub_key]);
            }
        } // unset($_sub_key); // Housekeeping.
    }

Unset a cache sub-key pattern.

@since 150424 Initial release.

@param string $primary_key     Primary key.
@param string $sub_key_pattern Sub-key pattern (watered-down regex).


protected function cacheAddByRef(string $primary_key, $ref_key, &$value)
    {
        $ref_key                                               = (string) $ref_key;
        $this->x___cache['x___refs'][$primary_key][$ref_key][] = &$value;
    }

protected function cacheAddByRef ( string $ primary_key , $ ref_key , & $ value ) { $ ref_key = ( string ) $ ref_key ; $ this -> x___cache [ 'x___refs' ] [ $ primary_key ] [ $ ref_key ] [ ] = & $ value ; }

Add a new cache ref-key.

@since 150424 Initial release.

@param string     $primary_key Primary key.
@param string|int $ref_key     Ref-key to set.
@param mixed      $value       New value (by reference).


protected function cacheUnsetByRef(string $primary_key, $ref_key)
    {
        $ref_key = (string) $ref_key; // Force string.

        if (empty($this->x___cache['x___refs'][$primary_key][$ref_key])) {
            return; // Nothing to do here.
        }
        foreach (array_keys($this->x___cache['x___refs'][$primary_key][$ref_key]) as $_key) {
            $this->x___cache['x___refs'][$primary_key][$ref_key][$_key] = null;
        } // unset($_key); // Housekeeping.
        unset($this->x___cache['x___refs'][$primary_key][$ref_key]);
    }

protected
function
cacheUnsetByRef
(
string
$
primary_key
,
$
ref_key
)
{
$
ref_key
=
(
string
)
$
ref_key
;
// Force string.
if
(
empty
(
$
this
->
x___cache
[
'x___refs'
]
[
$
primary_key
]
[
$
ref_key
]
)
)
{
return
;
// Nothing to do here.
}
foreach
(
array_keys
(
$
this
->
x___cache
[
'x___refs'
]
[
$
primary_key
]
[
$
ref_key
]
)
as
$
_key
)
{
$
this
->
x___cache
[
'x___refs'
]
[
$
primary_key
]
[
$
ref_key
]
[
$
_key
]
=
;
}
// unset($_key); // Housekeeping.
unset
(
$
this
->
x___cache
[
'x___refs'
]
[
$
primary_key
]
[
$
ref_key
]
)
;
}

Unset a cache ref-key.

@since 150424 Initial release.

@param string     $primary_key Primary key.
@param string|int $ref_key     Ref-key to unset.


protected function cacheUnsetByRefPattern(string $primary_key, string $ref_key_pattern)
    {
        if (empty($this->x___cache['x___refs'][$primary_key])) {
            return; // Nothing to do here.
        }
        $ref_key_regex = // Allow `**` to indicate everything quickly.
            $ref_key_pattern === '**' ? '' : $this->c::wRegx($ref_key_pattern, '/', true);

        if (!$ref_key_regex && $ref_key_pattern !== '**') {
            return; // Nothing to do; i.e., no regex.
        }
        foreach (array_keys($this->x___cache['x___refs'][$primary_key]) as $_ref_key) {
            if ($ref_key_pattern === '**' || preg_match($ref_key_regex.'i', (string) $_ref_key)) {
                foreach (array_keys($this->x___cache['x___refs'][$primary_key][$_ref_key]) as $_key) {
                    $this->x___cache['x___refs'][$primary_key][$_ref_key][$_key] = null;
                } // unset($_key); // Housekeeping.
                unset($this->x___cache['x___refs'][$primary_key][$_ref_key]);
            }
        } // unset($_ref_key); // Housekeeping.
    }

Unset a cache ref-key pattern.

@since 150424 Initial release.

@param string $primary_key     Primary key.
@param string $ref_key_pattern Ref-key pattern (watered-down regex).


public function render(MapTypeControl $mapTypeControl)
    {
        $this->jsonBuilder->reset();

        foreach ($mapTypeControl->getMapTypeIds() as $index => $mapTypeId) {
            $this->jsonBuilder->setValue(
                sprintf('[mapTypeIds][%d]', $index),
                $this->mapTypeIdHelper->render($mapTypeId),
                false
            );
        }

        return $this->jsonBuilder
            ->setValue(
                '[position]',
                $this->controlPositionHelper->render($mapTypeControl->getControlPosition()),
                false
            )
            ->setValue(
                '[style]',
                $this->mapTypeControlStyleHelper->render($mapTypeControl->getMapTypeControlStyle()),
                false
            )
            ->build();
    }

public function render ( MapTypeControl $ mapTypeControl ) { $ this -> jsonBuilder -> reset ( ) ; foreach ( $ mapTypeControl -> getMapTypeIds ( ) as $ index => $ mapTypeId ) { $ this -> jsonBuilder -> setValue ( sprintf ( '[mapTypeIds][%d]' , $ index ) , $ this -> mapTypeIdHelper -> render ( $ mapTypeId ) , false ) ; } return $ this -> jsonBuilder -> setValue ( '[position]' , $ this -> controlPositionHelper -> render ( $ mapTypeControl -> getControlPosition ( ) ) , false ) -> setValue ( '[style]' , $ this -> mapTypeControlStyleHelper -> render ( $ mapTypeControl -> getMapTypeControlStyle ( ) ) , false ) -> build ( ) ; }

Renders a map type control.

@param \Ivory\GoogleMap\Controls\MapTypeControl $mapTypeControl The map type control.

@return string The JS output.


public function sq($value)
    {
        if (is_array($value) || is_object($value)) {
            foreach ($value as $_key => &$_value) {
                $_value = $this->sq($_value);
            } // unset($_key, $_value);
            return $value;
        }
        return str_replace("'", "\\'", (string) $value);
    }

public
function
sq
(
$
value
)
{
if
(
is_array
(
$
value
)
||
is_object
(
$
value
)
)
{
foreach
(
$
value
as
$
_key
=>
&
$
_value
)
{
$
_value
=
$
this
->
sq
(
$
_value
)
;
}
// unset($_key, $_value);
return
$
value
;
}
return
str_replace
(
"'"
,
"\\'"
,
(
string
)
$
value
)
;
}

Escape single-quote.

@since 160708 Quotes.

@param mixed $value Input value.

@return string|array|object Output value.


public function singleQuote($value, bool $maybe_use_sld = false)
    {
        if (is_array($value) || is_object($value)) {
            foreach ($value as $_key => &$_value) {
                $_value = $this->singleQuote($_value);
            } // unset($_key, $_value);
            return $value;
        }
        $string = (string) $value;

        if ($maybe_use_sld) {
            if (!isset($string[0])) {
                return "''"; // Empty string.
            } elseif ($string === "''" || $string === '""') {
                return "''"; // Empty string.
            } elseif (mb_strpos($string, "'") === 0 && mb_substr($string, -1) === "'") {
                return "'".str_replace("'", "\\'", mb_substr($string, 1, -1))."'";
            } elseif (mb_strpos($string, '"') === 0 && mb_substr($string, -1) === '"') {
                return "'".str_replace("'", "\\'", mb_substr($string, 1, -1))."'";
            } else {
                return "'".str_replace("'", "\\'", $string)."'"; // Defaul behavior.
            }
        } else {
            return "'".str_replace("'", "\\'", $string)."'"; // Defaul behavior.
        }
    }

public
function
singleQuote
(
$
value
,
bool
$
maybe_use_sld
=
false
)
{
if
(
is_array
(
$
value
)
||
is_object
(
$
value
)
)
{
foreach
(
$
value
as
$
_key
=>
&
$
_value
)
{
$
_value
=
$
this
->
singleQuote
(
$
_value
)
;
}
// unset($_key, $_value);
return
$
value
;
}
$
string
=
(
string
)
$
value
;
if
(
$
maybe_use_sld
)
{
if
(
!
isset
(
$
string
[
0
]
)
)
{
return
"''"
;
// Empty string.
}
elseif
(
$
string
===
"''"
||
$
string
===
'""'
)
{
return
"''"
;
// Empty string.
}
elseif
(
mb_strpos
(
$
string
,
"'"
)
===
0
&&
mb_substr
(
$
string
,
1
)
===
"'"
)
{
return
"'"
.
str_replace
(
"'"
,
"\\'"
,
mb_substr
(
$
string
,
1
,
1
)
)
.
"'"
;
}
elseif
(
mb_strpos
(
$
string
,
'"'
)
===
0
&&
mb_substr
(
$
string
,
1
)
===
'"'
)
{
return
"'"
.
str_replace
(
"'"
,
"\\'"
,
mb_substr
(
$
string
,
1
,
1
)
)
.
"'"
;
}
else
{
return
"'"
.
str_replace
(
"'"
,
"\\'"
,
$
string
)
.
"'"
;
// Defaul behavior.
}
}
else
{
return
"'"
.
str_replace
(
"'"
,
"\\'"
,
$
string
)
.
"'"
;
// Defaul behavior.
}
}

Single-quote encapsulation.

@since 160708 Quotes.

@param mixed $value         Input value.
@param bool  $maybe_use_sld Maybe; i.e., detect string-literals?

@return string|array|object Output value.

--- When `$maybe_use_sld` = `true` ...

String literals are detected automatically; e.g., `'an already-quoted string'`.

@note This trims existing 'single' and/or "double" quoted encapsulations before quoting again.
For that reason, escaped quotes inside an already-quoted string are always escaped again.
So if you're going to quote a string literal, you should NOT escape inner quotes.

e.g., `'Here's a good example, don't escape inner quotes.'`.

@note This function is used by our Simple Expression parser.


public function doubleQuote($value, bool $for_csv = false)
    {
        if (is_array($value) || is_object($value)) {
            foreach ($value as $_key => &$_value) {
                $_value = $this->doubleQuote($_value);
            } // unset($_key, $_value);
            return $value;
        }
        return '"'.str_replace('"', $for_csv ? '""' : '\\"', (string) $value).'"';
    }

public
function
doubleQuote
(
$
value
,
bool
$
for_csv
=
false
)
{
if
(
is_array
(
$
value
)
||
is_object
(
$
value
)
)
{
foreach
(
$
value
as
$
_key
=>
&
$
_value
)
{
$
_value
=
$
this
->
doubleQuote
(
$
_value
)
;
}
// unset($_key, $_value);
return
$
value
;
}
return
'"'
.
str_replace
(
'"'
,
$
for_csv
'""'
:
'\\"'
,
(
string
)
$
value
)
.
'"'
;
}

Double-quote encapsulation.

@since 160708 Quotes.

@param mixed $value   Input value.
@param bool  $for_csv Changes quote-style for CSV compat.
CSV quoting requires the use of a double-quote as the escape char.

@return string|array|object Output value.

@WARNING Double-quotes, in most languages, result in evaluation.


public function render($mapTypeControlStyle)
    {
        switch ($mapTypeControlStyle) {
            case MapTypeControlStyle::DEFAULT_:
            case MapTypeControlStyle::DROPDOWN_MENU:
            case MapTypeControlStyle::HORIZONTAL_BAR:
                return sprintf('google.maps.MapTypeControlStyle.%s', strtoupper($mapTypeControlStyle));
            default:
                throw HelperException::invalidMapTypeControlStyle();
        }
    }

public function render ( $ mapTypeControlStyle ) { switch ( $ mapTypeControlStyle ) { case MapTypeControlStyle :: DEFAULT_ : case MapTypeControlStyle :: DROPDOWN_MENU : case MapTypeControlStyle :: HORIZONTAL_BAR : return sprintf ( 'google.maps.MapTypeControlStyle.%s' , strtoupper ( $ mapTypeControlStyle ) ) ; default : throw HelperException :: invalidMapTypeControlStyle ( ) ; } }

Renders a map type control style.

@param string $mapTypeControlStyle The map type control style.

@throws \Ivory\GoogleMap\Exception\ControlException If the map type control style is not valid.

@return string The JS output.


public function signUrl($url)
    {
        $url .= sprintf('&client=gme-%s', $this->clientId);

        if ($this->hasChannel()) {
            $url .= sprintf('&channel=%s', $this->channel);
        }

        $urlParts = parse_url($url);
        $data = sprintf('%s?%s', $urlParts['path'], $urlParts['query']);
        $key = base64_decode(str_replace(array('-', '_'), array('+', '/'), $this->secret));
        $signature = base64_encode(hash_hmac('sha1', $data, $key, true));

        $url .= sprintf('&signature=%s', str_replace(array('+', '/'), array('-', '_'), $signature));

        return $url;
    }

public function signUrl ( $ url ) { $ url .= sprintf ( '&client=gme-%s' , $ this -> clientId ) ; if ( $ this -> hasChannel ( ) ) { $ url .= sprintf ( '&channel=%s' , $ this -> channel ) ; } $ urlParts = parse_url ( $ url ) ; $ data = sprintf ( '%s?%s' , $ urlParts [ 'path' ] , $ urlParts [ 'query' ] ) ; $ key = base64_decode ( str_replace ( array ( '-' , '_' ) , array ( '+' , '/' ) , $ this -> secret ) ) ; $ signature = base64_encode ( hash_hmac ( 'sha1' , $ data , $ key , true ) ) ; $ url .= sprintf ( '&signature=%s' , str_replace ( array ( '+' , '/' ) , array ( '-' , '_' ) , $ signature ) ) ; return $ url ; }

Sign an url for business purpose.

@param string $url The url.

@return string The signed url.


public function getHighlighter(string $q, array $args = []): Classes\Core\SearchTermHighlighter
    {
        return $this->App->Di->get(Classes\Core\SearchTermHighlighter::class, compact('q', 'args'));
    }

public function getHighlighter ( string $ q , array $ args = [ ] ) : Classes \ Core \ SearchTermHighlighter { return $ this -> App -> Di -> get ( Classes \ Core \ SearchTermHighlighter :: class , compact ( 'q' , 'args' ) ) ; }

Get search highlighter.

@since 161006 Search terms.

@param string $q    Input search query.
@param array  $args Additional arguments.

@return Classes\Core\SearchTermHighlighter Instance.


public function shardId(string $string, bool $is_sha1 = false, int $total_shards = 65536): int
    {
        return $this->__invoke($string, $total_shards, $is_sha1);
    }

public function shardId ( string $ string , bool $ is_sha1 = false , int $ total_shards = 65536 ) : int { return $ this -> __invoke ( $ string , $ total_shards , $ is_sha1 ) ; }

SHA-1 modulus shard ID.

@since 150424 SHA-1 modulus.

@param string $string       String or a SHA-1 hash.
@param bool   $is_sha1      String is already a SHA-1 hash?
@param int    $total_shards Total shards; defaults to `65536`.

@return int SHA-1 modulus; i.e., a shard ID.

@internal Shard IDs are always zero-based, because a modulus will never be >= to the divisor.
If `$total_shards is `65536`, min shard ID is `0`, max shard ID is `65535`.


public function assignShardId(string $string, bool $is_sha1 = false)
    {
        if ($this->total_mysql_db_shards < 1) {
            throw $this->c::issue('No MySQL DB shards available.');
        }
        return $this->shardId($string, $is_sha1, $this->total_mysql_db_shards);
    }

public
function
assignShardId
(
string
$
string
,
bool
$
is_sha1
=
false
)
{
if
(
$
this
->
total_mysql_db_shards
<
1
)
{
throw
$
this
->
c
::
issue
(
'No MySQL DB shards available.'
)
;
}
return
$
this
->
shardId
(
$
string
,
$
is_sha1
,
$
this
->
total_mysql_db_shards
)
;
}

Assign shard ID.

@since 150424 SHA-1 modulus.

@param string $string  String or a SHA-1 hash.
@param bool   $is_sha1 String is already a SHA-1 hash?

@return int Assigned shard ID; based on `sha1($string)`.

@internal This one is based on the actual number of configured shards;
i.e., not on the upper limit of the shard ID itself. `65536` is not used here.


public function setTravelMode($travelMode)
    {
        if (!in_array($travelMode, TravelMode::getTravelModes())) {
            throw DirectionsException::invalidDirectionsStepTravelMode();
        }

        $this->travelMode = $travelMode;
    }

public function setTravelMode ( $ travelMode ) { if ( ! in_array ( $ travelMode , TravelMode :: getTravelModes ( ) ) ) { throw DirectionsException :: invalidDirectionsStepTravelMode ( ) ; } $ this -> travelMode = $ travelMode ; }

Sets the step travel mode.

@param string $travelMode The step travel mode.

@throws \Ivory\GoogleMap\Exception\DirectionsException If the travel mode is not valid.


public function setPrefixJavascriptVariable($prefixJavascriptVariable)
    {
        if (!is_string($prefixJavascriptVariable)) {
            throw AssetException::invalidPrefixJavascriptVariable();
        }

        $this->javascriptVariable = $this->generateJavascriptVariable($prefixJavascriptVariable);
    }

public function setPrefixJavascriptVariable ( $ prefixJavascriptVariable ) { if ( ! is_string ( $ prefixJavascriptVariable ) ) { throw AssetException :: invalidPrefixJavascriptVariable ( ) ; } $ this -> javascriptVariable = $ this -> generateJavascriptVariable ( $ prefixJavascriptVariable ) ; }

Sets the prefix of the javascript variable.

@param string $prefixJavascriptVariable The prefix of the javascript variable.

@throws \Ivory\GoogleMap\Exception\AssetException If the prefix javascript variable is not valid.

Sets the prefix of the javascript variable .


public function selectOptions(string $selected = '', array $args = []): string
    {
        $default_args = [
            'ip'     => null,
            'use_ip' => true,
        ];
        $args += $default_args;

        $is_cli = $this->c::isCli();

        if (!isset($args['ip']) && $args['use_ip']) {
            $args['ip'] = $is_cli ? '' : $this->c::currentIp();
        }
        $args['ip']     = (string) $args['ip'];
        $args['use_ip'] = (bool) $args['use_ip'];

        if (!$selected && $args['ip'] && $args['use_ip']) {
            $selected = $is_cli ? '' : $this->c::ipCountry($args['ip']);
        }
        $markup   = ''; // Initialize.
        $selected = mb_strtoupper($selected);

        foreach ($this->ISO3166->getAll() as $_country) {
            $markup .= '<option value="'.$_country['alpha2'].'"'.($selected ? $this->c::selected($selected, $_country['alpha2']) : '').'>'.$_country['name'].'</option>';
        } // unset($_country); // Housekeeping.

        return $markup;
    }

public
function
selectOptions
(
string
$
selected
=
''
,
array
$
args
=
[
]
)
:
string
{
$
default_args
=
[
'ip'
=>
,
'use_ip'
=>
true
,
]
;
$
args
+=
$
default_args
;
$
is_cli
=
$
this
->
c
::
isCli
(
)
;
if
(
!
isset
(
$
args
[
'ip'
]
)
&&
$
args
[
'use_ip'
]
)
{
$
args
[
'ip'
]
=
$
is_cli
''
:
$
this
->
c
::
currentIp
(
)
;
}
$
args
[
'ip'
]
=
(
string
)
$
args
[
'ip'
]
;
$
args
[
'use_ip'
]
=
(
bool
)
$
args
[
'use_ip'
]
;
if
(
!
$
selected
&&
$
args
[
'ip'
]
&&
$
args
[
'use_ip'
]
)
{
$
selected
=
$
is_cli
''
:
$
this
->
c
::
ipCountry
(
$
args
[
'ip'
]
)
;
}
$
markup
=
''
;
// Initialize.
$
selected
=
mb_strtoupper
(
$
selected
)
;
foreach
(
$
this
->
ISO3166
->
getAll
(
)
as
$
_country
)
{
$
markup
.=
'<option value="'
.
$
_country
[
'alpha2'
]
.
'"'
.
(
$
selected
$
this
->
c
::
selected
(
$
selected
,
$
_country
[
'alpha2'
]
)
:
''
)
.
'>'
.
$
_country
[
'name'
]
.
'</option>'
;
}
// unset($_country); // Housekeeping.
return
$
markup
;
}

Select menu options.

@since 170329.13807 Country utils.

@param string $selected Selected value.
@param array  $args     Any behavioral args.

@return string HTML markup.


public function dropdownItems(string $active = '', array $args = []): string
    {
        $default_args = [
            'ip'     => null,
            'use_ip' => true,
            'flags'  => false,
        ];
        $args += $default_args;

        $is_cli = $this->c::isCli();

        if (!isset($args['ip']) && $args['use_ip']) {
            $args['ip'] = $is_cli ? '' : $this->c::currentIp();
        }
        $args['ip']     = (string) $args['ip'];
        $args['use_ip'] = (bool) $args['use_ip'];
        $args['flags']  = (bool) $args['flags'];

        if (!$active && $args['ip'] && $args['use_ip']) {
            $active = $is_cli ? '' : $this->c::ipCountry($args['ip']);
        }
        $markup = ''; // Initialize.
        $active = mb_strtoupper($active);

        foreach ($this->ISO3166->getAll() as $_country) {
            $_alpha2_lc = mb_strtolower($_country['alpha2']);
            $_flag      = $args['flags'] ? '' : '';
            $markup .= '
c::activeSelected($active, $_country['alpha2']) : '').'" data-value="'.$_country['alpha2'].'">'.$_flag.$_country['name'].'
';
        } // unset($_country, $_alpha2_lc, $_flag); // Housekeeping.

        return $markup;
    }

Dropdown menu items.

@since 170329.13807 Country utils.

@param string $active Active value.
@param array  $args   Any behavioral args.

@return string HTML markup.