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

泰安做百度推广的公司家庭优化大师

泰安做百度推广的公司,家庭优化大师,做生产计划类的网站,网站注册管理策划方案一、Bean 在 Swoft 中#xff0c;一个 Bean 就是一个类的一个对象实例。 它(Bean)是通过容器来存放和管理整个生命周期的。 最直观的感受就是省去了频繁new的过程#xff0c;节省了资源的开销。 二、Bean的使用 1、创建Bean 在【gateway/app/Http/Controller】下新建一个名为… 一、Bean 在 Swoft 中一个 Bean 就是一个类的一个对象实例。 它(Bean)是通过容器来存放和管理整个生命周期的。 最直观的感受就是省去了频繁new的过程节省了资源的开销。 二、Bean的使用 1、创建Bean 在【gateway/app/Http/Controller】下新建一个名为【TestController.php】的文件文件内容如下。注释“gateway”为我的项目名称。 ?php declare(strict_types1); /*** This file is part of Swoft.** link https://swoft.org* document https://swoft.org/docs* contact groupswoft.org* license https://github.com/swoft-cloud/swoft/blob/master/LICENSE*/namespace App\Http\Controller;use Swoft\Http\Server\Annotation\Mapping\RequestMapping; use Swoft\Bean\Annotation\Mapping\Bean;/*** Class TestController** since 2.0* Bean()*/ class TestController {/*** RequestMapping(index)**/public function index(){return testBean;} }2、调用Bean 在【gateway/app/Http/Controller】目录下随便找个已近存在的文件进行编辑调用本文就选择了【RpcController.php】文件这个文件在项目创建之初就存在了。 ?php declare(strict_types1); /*** This file is part of Swoft.** link https://swoft.org* document https://swoft.org/docs* contact groupswoft.org* license https://github.com/swoft-cloud/swoft/blob/master/LICENSE*/namespace App\Http\Controller;use Swoft\Bean\BeanFactory; use Swoft\Http\Server\Annotation\Mapping\Controller; use Swoft\Http\Server\Annotation\Mapping\RequestMapping;/*** Class RpcController** since 2.0** Controller()*/ class RpcController {/*** RequestMapping(list)* return array*/public function getList(): array{$bean BeanFactory::getBean(TestController::class);return [$bean-index()];}}3、展示结果 在【TestController】文件中的【index】方法中返回的内容是“testBean“调用的时候返回了一个数组。我的浏览器安装了JSON的格式化工具所以返回的数据都格式化了。 4、说明 在上面两个文件中都有标红的地方两个文件的标红处是有关联的。 1、在【TestController】文件中Bean的写法有很多种如下所示 第一种   写法Bean()  调用BeanFactory::getBean(TestController::class); 第二种   写法Bean(testBean)  调用BeanFactory::getBean(testBean);  注意点Bean(testBean)中的引号一定要双引号单引号要报错。 第三种   写法Bean(nametestBean,scopeBean::SINGLETON)  调用BeanFactory::getBean(testBean);  注意点scopeBean::SINGLETON 中的scope有三个值分别是 Bean::SINGLETON(默认), Bean::PROTOTYPE, Bean::REQUEST。 第四种   写法Bean(nametestBean,scopeBean::SINGLETON,aliastestBeanAlias)  调用BeanFactory::getBean(testBeanAlias);  注意点alias 表示别名的意思使用了 alias 那么在调用时可以用别名调用。当然设置别名后也可以不用别名调用还是用原来的name也是可以的。 2、关于Bean的源码可以打开【gateway/vendor/swoft/bean/src/Annotation/Mapping/Bean.php】文件查看。我下载的Swoft版本是2.0的Bean.php文件内容如下 ?php declare(strict_types1); /*** This file is part of Swoft.** link https://swoft.org* document https://swoft.org/docs* contact groupswoft.org* license https://github.com/swoft-cloud/swoft/blob/master/LICENSE*/namespace Swoft\Bean\Annotation\Mapping;use Doctrine\Common\Annotations\Annotation\Attribute; use Doctrine\Common\Annotations\Annotation\Attributes; use Doctrine\Common\Annotations\Annotation\Enum; use Doctrine\Common\Annotations\Annotation\Target;/*** Class Bean** Annotation* Target(CLASS)* Attributes({* Attribute(name, typestring),* Attribute(scope, typestring),* Attribute(alias, typestring),* })** since 2.0*/ final class Bean {/*** Singleton bean*/public const SINGLETON singleton;/*** New bean*/public const PROTOTYPE prototype;/*** New bean from every request*/public const REQUEST request;/*** New bean for one session*/public const SESSION session;/*** Bean name** var string*/private $name ;/*** Bean scope** var string* Enum({Bean::SINGLETON, Bean::PROTOTYPE, Bean::REQUEST})*/private $scope self::SINGLETON;/*** Bean alias** var string*/private $alias ;/*** Bean constructor.** param array $values*/public function __construct(array $values){if (isset($values[value])) {$this-name $values[value];}if (isset($values[name])) {$this-name $values[name];}if (isset($values[scope])) {$this-scope $values[scope];}if (isset($values[alias])) {$this-alias $values[alias];}}/*** return string*/public function getName(): string{return $this-name;}/*** return string*/public function getScope(): string{return $this-scope;}/*** return string*/public function getAlias(): string{return $this-alias;} }
http://www.hkea.cn/news/14436903/

相关文章:

  • 如何制作手机网站河南省建设工程信息网站
  • 建设一个网站平台有经验的常州网站建设
  • 网站上的图标用什么软件做的招远水利建设工程公司网站
  • 北京 网站策划公司怎样将网站开发说清楚
  • 阿里云网站建设方案书模板手机网页源码
  • 中国品牌建设促进会网站wordpress安装网站无法
  • wordpress评论者名字站长工具seo优化系统
  • 阿坝网站制作庐江县建设网站
  • 网站建设技术员中国现货交易网官网
  • 网站开发配置管理计划自建免费网站哪个好
  • 网站logo例子wordpress 默认文本编辑器
  • 网站建设人工费深圳建设工程交易中心网站
  • 怀化政法网站wordpress 页面顺序
  • 昆明网站建设开发建站空间怎么选
  • 北京网站建设有哪些公司网站分布
  • 天津综合网站建设商店马鞍山做网站公司
  • 浙江省院士专家工作站建设网站做网站选择什么服务器
  • 手机网站广告怎么做网站海外运营推广
  • 湖南网站制作英文网站如何做seo
  • 可信网站认证服务商流量主小程序搭建
  • 网站管理员密码忘记了网站域名推广
  • 湖南沙坪建设集团有限公司网站域名解析查询网
  • 杭州建设工程信息网站北京网站域名备案
  • 深圳做网站得外包公司自己做的网站出现左右滑动条
  • 网站建设需要多少g合适竞价推广网站建设
  • 北京建站者公司网站开发预留接口
  • 亚马逊店铺网站建设费用3d网页游戏开服表
  • 网站策划公司厚街网站建设
  • xml网站地图制作兰州电商网站建设
  • 默认网站建立代写企业软文