首页 > 其他 > 详细

每天laravel-20160726| Genaerator command-4

时间:2016-04-28 12:34:41      阅读:179      评论:0      收藏:0      [点我收藏+]
   /**
    * 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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!