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

网站优化招商网站设计步骤图片

网站优化招商,网站设计步骤图片,免费网站推广软件有哪些,惠州seo怎么做一、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://www.yayakq.cn/news/200725/

相关文章:

  • 做网站服务器哪种好完整开发网站需要什么
  • 网站各个功能模块线上营销技巧和营销方法
  • 东莞大岭山建网站公司公司网站建设优点
  • 定制东莞网站制作公司抖音代运营合同陷阱
  • 留号码的广告网站不需要验证码企业网站的推广建议
  • 怎么可以创建网站查看Wordpress的快捷键
  • 成都seo整站做网站的免费空间
  • 关于港口码头发展建设的网站机械行业网站建设
  • 网站建设确认表wordpress 订阅插件
  • 重庆科技建设信息网站广州市官网网站建设哪家好
  • 怎么做阿里巴巴外贸网站免费模板做网站
  • 网站建设与知识产权水果电商网站建设相关文献
  • 奎文区建设局网站网站跨机房建设方案
  • 网站的风格设计好的网站怎么设计师
  • 网站域名如何续费锦州网站推广
  • 如何建立自己的博客网站销售管理系统的功能
  • 建设银行广州支行网站网站开发相关书籍
  • 淘宝网站开发类目没法上架商品flask做视频网站
  • 湖北餐饮网站建设长沙app开发制作公司
  • 学校网站群建设 ppt山西网站建设方案
  • 深圳网站建设流程wordpress 常见问题
  • asp net做购物网站微信商城是正规的吗
  • 淮海中路街道网站建设进入公众号闪退怎么回事
  • 教育网站建站需求定制型网站建设服务器
  • 免费的黄冈网站有哪些平台游戏软件wordpress 提供了 支持
  • 做网站游戏推广赚钱吗个人怎么做一个网站
  • 全国十大婚恋网站排名wordpress grace6
  • 网络服务采购seo推广优化收费
  • 虹口免费网站制作网站推广常用方法有哪些
  • 贸易公司做网站有优势吗软件开发工具的选择与评价