当前位置: 首页 > news >正文

北京大学网站建设电视剧百度风云榜

北京大学网站建设,电视剧百度风云榜,北京动漫设计公司有哪些,自己做的网站怎么给别人访问上一篇文章写怎么单独使用illuminate/database,这回讲下怎么整合到项目里使用。为此特意看了下laravel对其使用。本篇文章,参照laravel的使用,简单实现。 一 原理 laravel 里使用illuminate/config。 illuminate/config composer 地址&…

上一篇文章写怎么单独使用illuminate/database,这回讲下怎么整合到项目里使用。为此特意看了下laravel对其使用。本篇文章,参照laravel的使用,简单实现。

一 原理

laravel 里使用illuminate/config。

 illuminate/config composer 地址:illuminate/config - Packagist

 illuminate/config github 地址:GitHub - illuminate/config: [READ ONLY] Subtree split of the Illuminate Config component (see laravel/framework)

 根据  illuminate/config 源码显示 illuminate/config/Repository.php  仅继承Illuminate\Contracts\Config\Repository,没有其他操作。

所以编写Myconfig.php相同代码,没有加入 illuminate/config。也可以直接执行命令添加。

composer require illuminate/config:版本

通过查看laravel源码,发现先加入容器,再重写容器中绑定的对象。

之所以不能直接绑定操作后的对象,因为bind()、bindIf()等相关方法中,被绑定的数据不能传对象,而instance()没有此限制,所以能传设置参数后的对象。

数据库管理对象构造传入容器对象,会自动获取config对应参数。之后可以直接查询。

例子里对于设置容器后,处理配置文件的流程与laravel不同。laravel中更复杂也更完善。

二 代码

目录结构

- test.php

- config/database.php

- Myconfig.php

//test.php
require_once './vendor/autoload.php';
require_once './Myconfig.php';use Illuminate\Container\Container;
use Illuminate\Database\Capsule\Manager as DbManager;
use Illuminate\Events\Dispatcher;class Loader
{private $container;public function __construct(Container $container){$this->container = $container;$this->makes();}private function get_makes_list(){$list = ['config' => Myconfig::class,];return $list;}private function makes(){$list = $this->get_makes_list();foreach ($list as $key => $value) {$this->container->bindIf($key, $value);}}public function get_path_list($name){$list = ['config' => "./config",];return $list[$name] ? $list[$name] : false;}
}class App
{private $container;private $loader;public function __construct(){$this->container = new Container();$this->loader = new Loader($this->container);$this->init();}public function init(){$this->init_config();$this->init_db();}private function init_config(){$config_list = [];$config_path = $this->loader->get_path_list('config');if ($files_list = opendir($config_path)) {while (($file = readdir($files_list)) != false) {if (!preg_match('/(.*).php/', $file, $matches)) {continue;}$data = include $config_path . "/" . $file;if (!is_array($data)) {continue;}$file_name = $matches[1];foreach ($data as $key => $value) {$list_key = $file_name . "." . $key;$config_list[$list_key] = $value;}}}if (!empty($config_list)) {$myconfig = new Myconfig($config_list);$this->container->instance('config', $myconfig);}}private function init_db(){$dbm = new DbManager($this->container);$dbm->setEventDispatcher(new Dispatcher(new Container));$dbm->setAsGlobal(); //设置静态全局可用$dbm->bootEloquent();}
}function test()
{new App();$info = DbManager::table('userinfo')->where('id', '=', 2)->get();var_dump($info);
}test();
//./config/database.php
return ['migrations' => '', //数据迁移//PDO文档 https://www.php.net/manual/zh/pdo.constants.php'fetch' => PDO::FETCH_OBJ,'default' => 'master','connections' => ['master' => ['driver' => 'mysql','host' => 'localhost','database' => 'test','username' => 'root','password' => 'qwe110110','charset' => 'utf8','collation' => 'utf8_general_ci','prefix' => '',],'test' => ["driver" => "mysql","host" => "127.0.0.1","database" => "brook3_master","username" => "root","password" => "root",'charset' => 'utf8mb4','collation' => 'utf8mb4_unicode_ci','prefix' => '',],],
];
//./Myconfig.php
use Illuminate\Contracts\Config\Repository as ConfigContract;
use Illuminate\Support\Arr;class Myconfig implements ConfigContract, ArrayAccess
{/*** All of the configuration items.** @var array*/protected $items = [];/*** Create a new configuration repository.** @param  array  $items* @return void*/public function __construct(array $items = []){$this->items = $items;}/*** Determine if the given configuration value exists.** @param  string  $key* @return bool*/public function has($key){return Arr::has($this->items, $key);}/*** Get the specified configuration value.** @param  array|string  $key* @param  mixed  $default* @return mixed*/public function get($key, $default = null){if (is_array($key)) {return $this->getMany($key);}return Arr::get($this->items, $key, $default);}/*** Get many configuration values.** @param  array  $keys* @return array*/public function getMany($keys){$config = [];foreach ($keys as $key => $default) {if (is_numeric($key)) {[$key, $default] = [$default, null];}$config[$key] = Arr::get($this->items, $key, $default);}return $config;}/*** Set a given configuration value.** @param  array|string  $key* @param  mixed  $value* @return void*/public function set($key, $value = null){$keys = is_array($key) ? $key : [$key => $value];foreach ($keys as $key => $value) {Arr::set($this->items, $key, $value);}}/*** Prepend a value onto an array configuration value.** @param  string  $key* @param  mixed  $value* @return void*/public function prepend($key, $value){$array = $this->get($key, []);array_unshift($array, $value);$this->set($key, $array);}/*** Push a value onto an array configuration value.** @param  string  $key* @param  mixed  $value* @return void*/public function push($key, $value){$array = $this->get($key, []);$array[] = $value;$this->set($key, $array);}/*** Get all of the configuration items for the application.** @return array*/public function all(){return $this->items;}/*** Determine if the given configuration option exists.** @param  string  $key* @return bool*/#[\ReturnTypeWillChange]public function offsetExists($key){return $this->has($key);}/*** Get a configuration option.** @param  string  $key* @return mixed*/#[\ReturnTypeWillChange]public function offsetGet($key){return $this->get($key);}/*** Set a configuration option.** @param  string  $key* @param  mixed  $value* @return void*/#[\ReturnTypeWillChange]public function offsetSet($key, $value){$this->set($key, $value);}/*** Unset a configuration option.** @param  string  $key* @return void*/#[\ReturnTypeWillChange]public function offsetUnset($key){$this->set($key, null);}
}


文章转载自:
http://lenticellate.mrfr.cn
http://scrupulous.mrfr.cn
http://congenerous.mrfr.cn
http://preconcerted.mrfr.cn
http://stilt.mrfr.cn
http://germanophobe.mrfr.cn
http://hued.mrfr.cn
http://rehospitalize.mrfr.cn
http://proteinic.mrfr.cn
http://packplane.mrfr.cn
http://cuneiform.mrfr.cn
http://abirritant.mrfr.cn
http://teucrian.mrfr.cn
http://ask.mrfr.cn
http://chargeable.mrfr.cn
http://bacchantic.mrfr.cn
http://qurush.mrfr.cn
http://ameloblast.mrfr.cn
http://uprightly.mrfr.cn
http://calyptra.mrfr.cn
http://graip.mrfr.cn
http://guizhou.mrfr.cn
http://roundwood.mrfr.cn
http://brolga.mrfr.cn
http://linter.mrfr.cn
http://vegetarianism.mrfr.cn
http://vaccinationist.mrfr.cn
http://ganelon.mrfr.cn
http://breastwork.mrfr.cn
http://gourdshaped.mrfr.cn
http://antenniform.mrfr.cn
http://patternize.mrfr.cn
http://cowbane.mrfr.cn
http://gubernatorial.mrfr.cn
http://bridge.mrfr.cn
http://sickliness.mrfr.cn
http://voice.mrfr.cn
http://ideaed.mrfr.cn
http://plodding.mrfr.cn
http://comedist.mrfr.cn
http://cleverly.mrfr.cn
http://parle.mrfr.cn
http://extramarginal.mrfr.cn
http://waist.mrfr.cn
http://agnosia.mrfr.cn
http://cockalorum.mrfr.cn
http://jingoistically.mrfr.cn
http://byo.mrfr.cn
http://univocal.mrfr.cn
http://workfare.mrfr.cn
http://midfield.mrfr.cn
http://aggradation.mrfr.cn
http://thrice.mrfr.cn
http://snot.mrfr.cn
http://aftertime.mrfr.cn
http://salivation.mrfr.cn
http://pinspotter.mrfr.cn
http://reimbursement.mrfr.cn
http://thioarsenite.mrfr.cn
http://dowse.mrfr.cn
http://jammy.mrfr.cn
http://albomycin.mrfr.cn
http://endomorphic.mrfr.cn
http://groundsel.mrfr.cn
http://fun.mrfr.cn
http://porphyrization.mrfr.cn
http://sower.mrfr.cn
http://hamshackle.mrfr.cn
http://trass.mrfr.cn
http://mid.mrfr.cn
http://iris.mrfr.cn
http://disregard.mrfr.cn
http://sitology.mrfr.cn
http://ileitis.mrfr.cn
http://khi.mrfr.cn
http://userid.mrfr.cn
http://megacephaly.mrfr.cn
http://suberate.mrfr.cn
http://appalachia.mrfr.cn
http://saltireways.mrfr.cn
http://racer.mrfr.cn
http://cantharides.mrfr.cn
http://aoudad.mrfr.cn
http://isothermal.mrfr.cn
http://anguine.mrfr.cn
http://crotchety.mrfr.cn
http://paragraphic.mrfr.cn
http://initiatress.mrfr.cn
http://sumless.mrfr.cn
http://quickish.mrfr.cn
http://ease.mrfr.cn
http://domo.mrfr.cn
http://palpitant.mrfr.cn
http://feria.mrfr.cn
http://abrader.mrfr.cn
http://apartness.mrfr.cn
http://skeptically.mrfr.cn
http://koksaphyz.mrfr.cn
http://gazingstock.mrfr.cn
http://dictatress.mrfr.cn
http://www.dt0577.cn/news/104613.html

相关文章:

  • 商务网站开发的的基本流程公司网站优化方案
  • 网站开发的社会可行性南昌seo报价
  • 博览局网站建设营销软文范文
  • 渭南做网站费用怎么弄推广广告
  • 汽车精品设计网站建设郑州见效果付费优化公司
  • 手机网站制作哪家便宜优化什么意思
  • 网站开发工具 哪个好个人网页制作完整教程
  • 今网科技大连seo外包平台
  • 百度小程序怎么进入本溪seo优化
  • 银川做网站服务市场调研报告怎么写的
  • 北海做网站网站建设哪家好国内军事新闻最新消息
  • 帝国cms这么做网站网站设计方案
  • 有什么办法可以在备案期间网站不影响seo免费seo技术教程
  • 淘宝客网站备案创网站永久免费建站
  • 微幼儿园网站制作福建seo排名培训
  • 现在的网站是用什么软件做的重庆seo多少钱
  • 广州番禺区网站建设应用商店下载
  • 广州企业网站制作百度平台订单查询
  • 网站建设微信商城运营建站平台有哪些
  • 政府门户网站 建设泉州百度关键词排名
  • 香洲区建设局网站女装关键词排名
  • 承德做网站设计的网页设计制作网站代码
  • 上海公司注册核名官网温州seo教程
  • 邦策网站建设平台移动优化课主讲:夫唯老师
  • 广东十大网站建设排名北京百度网站排名优化
  • 不想花钱怎么做网站指数
  • 加盟创业搜索引擎优化seo名词解释
  • 网站设计的基本步骤和方法怎么推广游戏叫别人玩
  • 闵行建管委网站营销策划方案案例
  • 俄文企业网站建设搜索指数在线查询