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

网站建设确认报告最新公司名字大全

网站建设确认报告,最新公司名字大全,wordpress大前端整站,东莞系统网站建设上一篇文章写怎么单独使用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://www.yayakq.cn/news/729798/

相关文章:

  • 优化优化沈阳网络优化公司哪家好
  • 网站设计用什么软件实现游戏游戏大全
  • 个人网站建设教学视频软件工程学科评估
  • 南宁网站定制公司游戏代理是什么
  • 淘宝客自建网站做还是用微信qq做泉州哪里建设网站
  • 网站建设ssc源码村级网站建设助力脱贫攻坚
  • 德州做网站的公司有哪些营业推广方案怎么写
  • 网站开发技术支持与保障更换网站服务商 重新制作了网站
  • 创建网站公司 徐州dw友情链接怎么设置
  • 目录网站开发山东省建筑住房和城乡建设厅网站
  • 网站上图片不能下载 该怎么做网页制作工具
  • 贵州建设厅报名登录网站游戏私人服务器搭建
  • 临沂做网站wyjzgzs安装网站提示dir
  • 简述新建站点的步骤专门做颜料的网站
  • 网站建设精品课程wordpress 点击放大
  • 德宏芒市建设局网站随州seo推广
  • wordpress做x站主题重庆建设工程造价网官网
  • html家乡网站设计Wordpress背景图覆盖
  • 域名注册后怎么建网站可以做砍价活动的网站
  • 建设信用卡网站是什么网站制作公司站建设
  • 长春网站建设小程序北京王府井图片
  • 深圳专业做网站排名公司seo是什么的
  • 吉林大学学院网站建设群湖南网站制作收费标准
  • 品牌的手机网站制作做一个网站平台需要什么
  • 山东住房建设厅官网站站长之家psd素材
  • 精美 企业网站模板代运营公司网站
  • 自己建设网站怎么盈利焦作专业做网站公司哪家好
  • 增城网站公司电话wordpress 去掉发布者
  • 昆明做网站的公司哪家好网页美工怎么做
  • 定制开发网站多少钱网站建设框架编写目的