Check if this is a valid Grav extension

@param $extension
@return bool
512151
public function isValidExtension($extension)
    {
        $valid_page_types = implode('|', Grav::instance()['config']->get('system.pages.types'));

        // Strip the file extension for valid page types
        if (preg_match('/(' . $valid_page_types . ')/', $extension)) {
            return true;
        }
        return false;
    }
575228
private function checkAllowedTypes($ext = ''){

            $allowedTypes = $this->getAllowedExt();

            if ('*' === $allowedTypes) {
                return true;
            }else{

              if(is_string($allowedTypes))
              {
                  $allowedTypes = (array) $allowedTypes;
              }

                foreach($allowedTypes as $type)
                {

                    if($type === $ext)
                    {
                      return true;
                    }else{
                        continue;
                    }
                }
            }
            return false;
        }
624694
public function acceptsExtension($ext)
    {
        $ext = trim(strtolower($ext), ".");

        if ($this->getRequiredExtension() && $ext !== $this->getRequiredExtension()) {
            return false;
        }

        if ($this->getAllowedExtensions() && !in_array($ext, $this->getAllowedExtensions())) {
            return false;
        }

        if ($this->getRejectedExtensions() && in_array($ext, $this->getRejectedExtensions())) {
            return false;
        }

        return true;
    }
233119
public function withExtension(string $extension): self
    {
        if ($this->extension === $extension) {
            return $this;
        }

        $clone = clone $this;
        $clone->extension = strtolower($extension);

        return $clone;
    }
782747
protected function _getMimetype($extension)
    {
        $mimetypes = $this->_getMimetypes();

        return isset($mimetypes[$extension]) ? $mimetypes[$extension] : null;
    }
153805
public function matchMimetypeExtension($mimetype, $extension)
    {
        $mime_extensions = self::$mimetypes_extensions;
        if (isset($mime_extensions[$extension]) && $mime_extensions[$extension] == $mimetype) {
            return true;
        }

        return false;
    }
925502
public function resolveFilename($extension = null)
    {
        if ($extension === null) {
            $extension = $this->extension;
        }
        return $this->name . '-' . $this->id . '.' . $extension;
    }
672429
public static function mustBeEnabled(common_ext_Extension $extension) {
        foreach (common_ext_ExtensionsManager::singleton()->getEnabledExtensions() as $ext) {
            foreach ($ext->getDependencies() as $extId => $version) {
                if ($extId == $extension->getId()) {
                    return true;
                }
            }
        }
        return false;
    }
465010
private function verifyExtension($extension)
    {
        $allowed = $this->config['allowed_extensions'];
        if (! empty($allowed) && ! in_array(strtolower($extension), $allowed)) {
            throw FileNotSupportedException::extensionRestricted(strtolower($extension), $allowed);
        }

        return $extension;
    }
173134
public function filterByExtension($extension)
    {
        $extensions = is_array($extension) ? $extension : [$extension];
        if (count($extensions) > 0) {
            $expr = $this->query->expr();
            $or = $expr->orX();
            foreach ($extensions as $extension) {
                $extension = ltrim((string) $extension, '.');
                $or->add($expr->eq('fv.fvExtension', $this->query->createNamedParameter($extension)));
                if ($extension === '') {
                    $or->add($expr->isNull('fv.fvExtension'));
                }
            }
            $this->query->andWhere($or);
        }
    }
272307
public static boolean isValidFileExtension(String extension) {
        for (int i = 0; i < extension.length(); i++) {
            char c = extension.charAt(i);
            if (!(Character.isDigit(c) || Character.isLetter(c) || c == '_')) {
                return false;
            }
        }
        return true;
    }
834035
public function registerExtension(common_ext_Extension $extension)
    {
        $entry = array(
        	'installed' => $extension->getManifest()->getVersion(),
            'enabled' => false 
        );
        $extensions = $this->getExtensionById('generis')->getConfig(self::EXTENSIONS_CONFIG_KEY);
        $extensions[$extension->getId()] = $entry;
        return $this->getExtensionById('generis')->setConfig(self::EXTENSIONS_CONFIG_KEY, $extensions);
    }
1138632
protected function validateExtensions($extensions): Extensions
    {
        if (empty($extensions)) {
            $extensions = new Extensions(['']);
        }

        if (! $extensions instanceof Extensions) {
            $extensions = new Extensions((array)$extensions);
        }

        return $extensions;
    }
77958
private function checkFileExtension($extension)
    {
        $valid = array('jpg', 'jpeg', 'png', 'gif', 'webp');

        in_array(strtolower($extension), $valid)
            or $this->raiseError('Not a valid file extension.');

        return $this;
    }
921225
public function replaceExtension($extension)
    {
        $atoms = $this->nameAtoms();
        if (array('', '') === $atoms) {
            if (null === $extension) {
                return $this;
            }

            return $this->replaceName(
                static::EXTENSION_SEPARATOR . $extension
            );
        }

        $numAtoms = count($atoms);

        if ($numAtoms > 1) {
            if (null === $extension) {
                $replacement = array();
            } else {
                $replacement = array($extension);
            }

            array_splice($atoms, -1, $numAtoms, $replacement);
        } elseif (null !== $extension) {
            $atoms[] = $extension;
        }

        return $this->replaceName(implode(self::EXTENSION_SEPARATOR, $atoms));
    }
1136181
public function toMimeType($extension)
    {
        $extension = strtolower($extension);

        if (array_key_exists($extension, $this->dict)) {
            return $this->dict[$extension];
        }
    }
795081
public function extension($extension = false)
    {
        if($extension === false) {
            return $this->adapter->extension($this->path);
        }

        $newName = $this->name();
        $index = strrpos($newName, '.');
        if ($index !== false) {
            $newName = substr($newName, 0, $index + 1);
        } else {
            $newName .= '.';
        }
        $newName .= $extension;

        return $this->name($newName);
    }