码迷,mamicode.com
首页 > 其他好文 > 详细

每天laravel-20160726| Genaerator command-4

时间:2016-04-28 12:37:01      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:laravel

   /**
    * 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


本文出自 “专注php” 博客,请务必保留此出处http://jingshanls.blog.51cto.com/3357095/1768443

每天laravel-20160726| Genaerator command-4

标签:laravel

原文地址:http://jingshanls.blog.51cto.com/3357095/1768443

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!