Composer模块化,降低代码复用成本统一的第三方代码组织方式版本更新内容更科学我的demo实现了类似tp3的路由功能。文献目录和代码如下:app_path=dirname(dirname(__DIR__));}functionhandle(){if($this->mode==1){//get传递方式解析方式$controllerName=empty($_GET['c'])?'index':$_GET['c'];$actionName=empty($_GET['a'])?'index':$_GET['a'];$ucController=ucfirst($controllerName);$controllerNameAll=$this->controllerNamespace。'\\'。$uc控制器。'控制器';$controllerFile=$this->app_path.'/'.$this->controllerNamespace.'/'.$ucController。'控制器.php';include_once$controllerFile;$controller=new$controllerNameAll();返回call_user_func([$controller,ucfirst($actionName)]);}elseif($this->mode==2){//斜切分路径分析法$controllerName='Index';$actionName='索引';$参数=数组();$_SERVER['REQUEST_URI'];$position=strpos($url,'?');$url=$position===false?$url:substr($url,0,$position);$query_str=str_replace($url,'',$_SERVER['REQUEST_URI']);$query_str=trim($query_str,'?');parse_str($query_str,$query_arr);,'/');如果($url){$urlArray=explode('/',$url);$urlArray=array_filter($urlArray);$controllerName=ucfirst($urlArray[0]););$actionName=$urlArray?$urlArray[0]:$actionName;array_shift($urlArray);//$param=$urlArray?=$this->app_path.'/'.$this->controllerNamespace.'/'.$controllerName.'控制器.php';include_once$controllerFile;$controller=$this->controllerNamespace。'\\'。$controllerName.'控制器';if(!class_exists($controller)){exit($controller.'控制器不存在');}if(!method_exists($controller,$actionName)){exit($actionName.'方法不存在');}$dispatch=new$controller();call_user_func_array(array($dispatch,$actionName),$query_arr);然后执行初始化命令:composerinit这里进入终端命令行交互:欢迎使用Composer配置生成器这个命令将引导你创建你的composer.jsonconfig.Packagename(
