DmitryDulepov\Realurl\Decoder\UrlDecoder::handleFileName PHP Method

handleFileName() protected method

2. File name is a segment with suffix appended. We discard the suffix.
protected handleFileName ( array &$urlParts ) : array
$urlParts array
return array
    protected function handleFileName(array &$urlParts)
    {
        $getVars = array();
        if (count($urlParts) > 0) {
            $putBack = TRUE;
            $fileNameSegment = array_pop($urlParts);
            if ($fileNameSegment && strpos($fileNameSegment, '.') !== FALSE) {
                if (!$this->handleFileNameMappingToGetVar($fileNameSegment, $getVars, $putBack)) {
                    $validExtensions = array();
                    foreach (array('acceptHTMLsuffix', 'defaultToHTMLsuffixOnPrev') as $option) {
                        $acceptSuffix = $this->configuration->get('fileName/' . $option);
                        if (is_string($acceptSuffix) && strpos($acceptSuffix, '.') !== FALSE) {
                            $validExtensions[] = $acceptSuffix;
                        } elseif ($acceptSuffix) {
                            $validExtensions[] = '.html';
                        }
                    }
                    $extension = '.' . pathinfo($fileNameSegment, PATHINFO_EXTENSION);
                    if (in_array($extension, $validExtensions)) {
                        $fileNameSegment = pathinfo($fileNameSegment, PATHINFO_FILENAME);
                    }
                    // If no match, we leave it as is => 404.
                } else {
                    if ($putBack && count($urlParts) === 0 && $fileNameSegment === 'index') {
                        $putBack = false;
                    }
                }
            }
            if ($putBack) {
                $urlParts[] = $fileNameSegment;
            }
        }
        return $getVars;
    }