JonathanTorres\Construct\Helpers\Str::createNamespace PHP Méthode

createNamespace() public méthode

Construct a correct project namespace name.
public createNamespace ( string $namespace, boolean $usesProjectName = false, boolean $useDoubleSlashes = false ) : string
$namespace string The entered namespace.
$usesProjectName boolean Whether or not it's using the project name.
$useDoubleSlashes boolean Whether or not use double slashes \\.
Résultat string
    public function createNamespace($namespace, $usesProjectName = false, $useDoubleSlashes = false)
    {
        $delimiter = $usesProjectName ? '/' : '\\';
        $slash = $useDoubleSlashes ? '\\\\' : '\\';
        // strip dots and dashes from project name
        if ($usesProjectName) {
            $namespace = str_replace(['-', '.'], '_', $namespace);
            $namespace = $this->toStudly($namespace);
        }
        return implode($slash, array_map(function ($v) {
            return $this->toStudly($v);
        }, explode($delimiter, $namespace)));
    }

Usage Example

Exemple #1
0
 /**
  * Construct a correct project namespace name.
  *
  * @param boolean $useDoubleSlashes Whether or not to create the namespace with double slashes \\
  *
  * @return string
  */
 protected function createNamespace($useDoubleSlashes = false)
 {
     $namespace = $this->settings->getNamespace();
     $projectName = $this->settings->getProjectName();
     if ($namespace === 'Vendor\\Project' || $namespace === $projectName) {
         return $this->str->createNamespace($projectName, true, $useDoubleSlashes);
     }
     return $this->str->createNamespace($namespace, false, $useDoubleSlashes);
 }