每天laravel-20160726| Genaerator command-4

    /** * Get the destination class path. * * @param string $name * @return string */
    protected function getPath($name)
    {
        $name = str_replace($this->laravel->getNamespace(), '', $name);// change name to the right name

        return $this->laravel['path'].'/'.str_replace('\\', '/', $name).'.php';// connect with the base path like more framework DIR. yeah
    }// get the destination class path
    // get you want the class path by the name

    /** * Parse the name and format according to the root namespace. * * @param string $name * @return string */
    protected function parseName($name)// Parse the name and format according to the root namespace.
    {
        $rootNamespace = $this->laravel->getNamespace();// get the root name space

        if (Str::startsWith($name, $rootNamespace)) {
            return $name;
        }// check the name type ,if has the base root namespace ,back it to the , do nothing, only return it.

        if (Str::contains($name, '/')) {// other if it has / ,so we need replace it with \
            $name = str_replace('/', '\\', $name);
        }// this is be like to get a normal namespace

        return $this->parseName($this->getDefaultNamespace(trim($rootNamespace, '\\')).'\\'.$name);
        // this is use root namespace connect with \ and the name,then check it again.
        // getDefaultNamespace function just return the variable itself.
    }

    /** * Get the default namespace for the class. * * @param string $rootNamespace * @return string */
    protected function getDefaultNamespace($rootNamespace)
    {
        return $rootNamespace;
    }// Get the default namespace for the class. return you self

你可能感兴趣的:(每天laravel-20160726| Genaerator command-4)