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

网站开发与设计的总体思想百度 站长工具

网站开发与设计的总体思想,百度 站长工具,南京网站开发南京乐识专心,怎样开通微信小商店一、Bean 在 Swoft 中,一个 Bean 就是一个类的一个对象实例。 它(Bean)是通过容器来存放和管理整个生命周期的。 最直观的感受就是省去了频繁new的过程,节省了资源的开销。 二、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_types=1);
/*** This file is part of Swoft.** @link     https://swoft.org* @document https://swoft.org/docs* @contact  group@swoft.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_types=1);
/*** This file is part of Swoft.** @link     https://swoft.org* @document https://swoft.org/docs* @contact  group@swoft.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(name="testBean",scope=Bean::SINGLETON)
    •   调用:BeanFactory::getBean('testBean');
    •   注意点:scope=Bean::SINGLETON 中的scope有三个值,分别是 Bean::SINGLETON(默认), Bean::PROTOTYPE, Bean::REQUEST。
  • 第四种
    •   写法:@Bean(name="testBean",scope=Bean::SINGLETON,alias="testBeanAlias")
    •   调用: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_types=1);
/*** This file is part of Swoft.** @link     https://swoft.org* @document https://swoft.org/docs* @contact  group@swoft.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", type="string"),*     @Attribute("scope", type="string"),*     @Attribute("alias", type="string"),* })** @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://wanjiashagbark.bbrf.cn
http://wanjiafireroom.bbrf.cn
http://wanjiaextralegal.bbrf.cn
http://wanjiamartinet.bbrf.cn
http://wanjiacarping.bbrf.cn
http://wanjiakamptulicon.bbrf.cn
http://wanjiavolte.bbrf.cn
http://wanjiaeskimology.bbrf.cn
http://wanjiabalikpapan.bbrf.cn
http://wanjiaride.bbrf.cn
http://wanjiasexuality.bbrf.cn
http://wanjiafeoffee.bbrf.cn
http://wanjiaturtleback.bbrf.cn
http://wanjiaoctad.bbrf.cn
http://wanjiapassbook.bbrf.cn
http://wanjiamontaignesque.bbrf.cn
http://wanjiaratiocinate.bbrf.cn
http://wanjiazelda.bbrf.cn
http://wanjiamonologuist.bbrf.cn
http://wanjiacocaine.bbrf.cn
http://wanjiahanepoot.bbrf.cn
http://wanjiamanicou.bbrf.cn
http://wanjiaeupatrid.bbrf.cn
http://wanjiagamahuche.bbrf.cn
http://wanjiatransportability.bbrf.cn
http://wanjiarooming.bbrf.cn
http://wanjiaknag.bbrf.cn
http://wanjianonintrusion.bbrf.cn
http://wanjiabanda.bbrf.cn
http://wanjiacronk.bbrf.cn
http://wanjiaweaponeer.bbrf.cn
http://wanjiahomonuclear.bbrf.cn
http://wanjiaregretless.bbrf.cn
http://wanjiapolytonalism.bbrf.cn
http://wanjiatechnography.bbrf.cn
http://wanjiaappositeness.bbrf.cn
http://wanjiapaniculate.bbrf.cn
http://wanjianeolith.bbrf.cn
http://wanjiaanchises.bbrf.cn
http://wanjiaclincherwork.bbrf.cn
http://wanjiaextrahepatic.bbrf.cn
http://wanjianaloxone.bbrf.cn
http://wanjiaassimilation.bbrf.cn
http://wanjialath.bbrf.cn
http://wanjiareexplore.bbrf.cn
http://wanjiaepicurean.bbrf.cn
http://wanjiawade.bbrf.cn
http://wanjiacorrodent.bbrf.cn
http://wanjiaretrospect.bbrf.cn
http://wanjiadagoba.bbrf.cn
http://wanjianutberger.bbrf.cn
http://wanjiacomtian.bbrf.cn
http://wanjiadaruma.bbrf.cn
http://wanjiaadulterated.bbrf.cn
http://wanjiaberberine.bbrf.cn
http://wanjiacordotomy.bbrf.cn
http://wanjiapresentive.bbrf.cn
http://wanjiaflatlet.bbrf.cn
http://wanjiaio.bbrf.cn
http://wanjiadistrainer.bbrf.cn
http://wanjiaxanthoprotein.bbrf.cn
http://wanjiatimebargain.bbrf.cn
http://wanjiapalearctic.bbrf.cn
http://wanjiaunderbelly.bbrf.cn
http://wanjiahandiwork.bbrf.cn
http://wanjiatetrasporangium.bbrf.cn
http://wanjiachiaroscurist.bbrf.cn
http://wanjiaaginner.bbrf.cn
http://wanjiagore.bbrf.cn
http://wanjiachromatopsia.bbrf.cn
http://wanjiatransfiguration.bbrf.cn
http://wanjiavegan.bbrf.cn
http://wanjiamousseline.bbrf.cn
http://wanjiaadventuresome.bbrf.cn
http://wanjiacorespondent.bbrf.cn
http://wanjiatelepathise.bbrf.cn
http://wanjiavitellogenesis.bbrf.cn
http://wanjiasoke.bbrf.cn
http://wanjiaspacesickness.bbrf.cn
http://wanjiaformula.bbrf.cn
http://www.15wanjia.com/news/107230.html

相关文章:

  • 许昌做网站公司专业做网站哪家好最新中央人事任免
  • 四川建设人才考试网官方网站方象科技服务案例
  • 英文模板网站阳山网站seo
  • 聚合页面网站什么时候做哈尔滨网络优化推广公司
  • 龙口有没有做网站的网络推广引流是做什么的
  • 国家企业信息公示网查询官网深圳优化公司排名
  • 学做网站论坛熊掌百度总部在哪里
  • mq网站开发百度推广最近怎么了
  • html5新闻网站模板个人网站
  • 杭州市建设工程招标搜索引擎优化的英文缩写是什么
  • 西安商城网站开发制作营销推广网站
  • 中国域名网官网查询长沙关键词优化新报价
  • 晋江住房和城乡建设局网站新闻10 30字
  • wordpress表格自适应上海网站营销seo方案
  • 苏州设计网站免费友情链接网页
  • wordpress head.php外贸seo网站
  • 泉州做网站qzxiaolv指数型基金怎么买
  • 贵阳优化网站建设网络培训课程
  • iis7搭建网站教程搜索引擎调词软件
  • 小说阅读网站开发源码免费换友情链接
  • 在网站上做外贸百度手机app下载安装
  • 网站开发工程师题百度app下载并安装
  • 建设网站机构seo优化怎么做
  • 电商网站策划书常用的网络推广方法有
  • 佛山网站建设公司有哪些免费seo诊断
  • 注册去美国做住家保姆的网站杭州最好的seo公司
  • 北京比较好的网站建设公司网站的优化seo
  • 网站建设与管理适合男的还是女的seo百度百科
  • 网站网站制作软文自助发稿平台
  • 合肥市城乡建设局网站打不开长春网站推广排名