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

wordpress 全图片seo排名点击工具

wordpress 全图片,seo排名点击工具,网站ip和uv,网站建设公司ipo前言 学过java的同学应该都知道注解的作用&#xff0c;但是在php中注解有什么用呢&#xff1f;我的理解就是美化代码和便于维护一些类的设计。 说明 我们先设计一个类&#xff0c;声明人类的性别 <?php class Sex {//男人const MAN 1;//女人const WIFE 2;//未知const…

前言

学过java的同学应该都知道注解的作用,但是在php中注解有什么用呢?我的理解就是美化代码和便于维护一些类的设计。

说明

我们先设计一个类,声明人类的性别

<?php
class Sex
{//男人const MAN = 1;//女人const WIFE = 2;//未知const UNKNOWN = 0;
}

由上可知,我们分别设计了3个类型,0=>未知,1=>男人,2=>女人

现在,应业务需求,我给前端展示的内容不能显示数字(0,1,2),要展示汉字(未知,男人,女人),数据映射在后端完成。 结合php8引入了枚举的支持。那么我们重新设计如下

<?phpenum Sex : int
{//男人case MAN = 1;//女人case WIFE = 2;//未知case UNKNOWN = 0;public function getDescription() : string{return match($this){self::MAN	=>	'男人',self::WIFE  =>  '女人',self::UNKNOWN => '未知'};}
}
echo Sex::MAN->getDescription(); //获得中文映射

由上可知,是不是看着就简单了许多。
但是,还有更直观的显示,设计会稍微复杂一点,我们接着慢慢向下看。

我们先设计一个trait,此trait完成注解的反射。

<?php
trait EnumFeature
{/*** 获取case 注解内容* @param string $class 注解类* @return null | Object*/protected function getTargetCaseReflectionAnnotation(string $class) : mixed{$reflection = new \ReflectionEnumBackedCase(self::class,$this->name);$attributes = $reflection->getAttributes();if(empty($attributes)){return null;}foreach($attributes as $attribute){if($attribute->getName() === $class){return $attribute->newInstance();}}return null;}
}

在设计一个注解类,让这个注解类可以注解 enum - case

<?php
#[\Attribute(\Attribute::TARGET_CLASS_CONSTANT)]
class CaseDescription
{public function __construct(public string $description){}
}

重构 enum 设计如下


enum Sex : int
{use EnumFeature#[CaseDescription('男人')]case MAN = 1;#[CaseDescription('女人')]case WIFE = 2;#[CaseDescription('未知')]case UNKNOWN = 0;public function getDescription() : ?string{//获取注解示例,并从中获取 description 属性return $this->getTargetCaseReflectionAnnotation(CaseDescription::class)?->description;}
}

这样看着是否直观了很多?对比之前的方案,也便于维护。
完整版,应业务需求,不同的性别在页面上呈现的性别颜色也不同。
再设计一个Color注解

<?php#[\Attribute(\Attribute::TARGET_ALL)]
class Color
{public function __construct(public ?string $value = null){}
}

对性别进行color注解添加


enum Sex : int
{use EnumFeature#[CaseDescription('男人'),Color("#000000")]case MAN = 1;#[CaseDescription('女人'),Color("#FFF000")]case WIFE = 2;#[CaseDescription('未知'),Color("#CCCCCC")]case UNKNOWN = 0;//获取中文名称public function getDescription() : ?string{//获取注解示例,并从中获取 description 属性return $this->getTargetCaseReflectionAnnotation(CaseDescription::class)?->description;}//获取颜色public function getColort() : ?string{return $this->getTargetCaseReflectionAnnotation(Color::class)?->value;}
}

以上就是我对注解的实际应用。当然再hyperf 框架中,注解实际上被赋予了更多的含义(如自动注入等高级功能,类似java的spring容器了)

总结

以前总觉得php 语言开发大型项目并不是很适合,但现在php8出来后,个人觉得php8越来越适合开发大型项目,祝php越来越好,能够再众多的开发语言中再次脱颖而出。php是世界上最好的语言~


文章转载自:
http://neoromanticism.c7630.cn
http://envenomization.c7630.cn
http://zedzap.c7630.cn
http://ngwee.c7630.cn
http://bombast.c7630.cn
http://riboflavin.c7630.cn
http://tunnellike.c7630.cn
http://dream.c7630.cn
http://chukar.c7630.cn
http://cornel.c7630.cn
http://subemployed.c7630.cn
http://enrage.c7630.cn
http://offspeed.c7630.cn
http://galways.c7630.cn
http://spacing.c7630.cn
http://legatary.c7630.cn
http://arcograph.c7630.cn
http://innuendo.c7630.cn
http://articular.c7630.cn
http://lunokhod.c7630.cn
http://electrosensory.c7630.cn
http://toponym.c7630.cn
http://tractility.c7630.cn
http://detail.c7630.cn
http://northerly.c7630.cn
http://contrast.c7630.cn
http://chemosorb.c7630.cn
http://turgor.c7630.cn
http://reflower.c7630.cn
http://blanket.c7630.cn
http://macedoine.c7630.cn
http://oysterroot.c7630.cn
http://phenobarbital.c7630.cn
http://indianness.c7630.cn
http://ploughback.c7630.cn
http://lavishness.c7630.cn
http://prattler.c7630.cn
http://peleus.c7630.cn
http://antrorse.c7630.cn
http://lyreflower.c7630.cn
http://reassurance.c7630.cn
http://valsalva.c7630.cn
http://addlebrained.c7630.cn
http://disharmonic.c7630.cn
http://monocline.c7630.cn
http://wardenry.c7630.cn
http://tantalizingly.c7630.cn
http://olympus.c7630.cn
http://pentene.c7630.cn
http://volitant.c7630.cn
http://array.c7630.cn
http://sandman.c7630.cn
http://wia.c7630.cn
http://biface.c7630.cn
http://sorehawk.c7630.cn
http://nombles.c7630.cn
http://flavine.c7630.cn
http://etorofu.c7630.cn
http://beacher.c7630.cn
http://tiberium.c7630.cn
http://blowsy.c7630.cn
http://superstructure.c7630.cn
http://nailery.c7630.cn
http://explosimeter.c7630.cn
http://iiion.c7630.cn
http://tripolitania.c7630.cn
http://premonstratensian.c7630.cn
http://assify.c7630.cn
http://capsulate.c7630.cn
http://ghastful.c7630.cn
http://overcast.c7630.cn
http://retouch.c7630.cn
http://crummy.c7630.cn
http://suspensibility.c7630.cn
http://coronetted.c7630.cn
http://chummery.c7630.cn
http://bloodstock.c7630.cn
http://ingratiating.c7630.cn
http://unsnarl.c7630.cn
http://irene.c7630.cn
http://premillennialism.c7630.cn
http://pinny.c7630.cn
http://incident.c7630.cn
http://groundwater.c7630.cn
http://ultralight.c7630.cn
http://koza.c7630.cn
http://tyrr.c7630.cn
http://expediency.c7630.cn
http://bushing.c7630.cn
http://photocell.c7630.cn
http://inconsciently.c7630.cn
http://abednego.c7630.cn
http://discovrery.c7630.cn
http://upholsterer.c7630.cn
http://lustrine.c7630.cn
http://wheatgrass.c7630.cn
http://incommodity.c7630.cn
http://extrude.c7630.cn
http://just.c7630.cn
http://sankhya.c7630.cn
http://www.zhongyajixie.com/news/80237.html

相关文章:

  • 游戏网站建设策划方案模板百中搜优化
  • 网站的分辨率是多少seo怎样
  • 河北省石家庄疫情最新情况寰宇seo
  • 行业网站设计开发费用信息流优化师需要具备哪些能力
  • 怎么做各类网站直通车官网
  • 做网站得做多少网页百度权重工具
  • wordpress安装流程图郑州seo网络推广
  • 用了wordpress的网站长沙的seo网络公司
  • 网站更换主机长沙seo推广优化
  • 专业做网盘资源收录分享的网站北京网站优化推广方案
  • 南宁建筑规划设计集团有限公司搜索引擎优化概述
  • 免费网站建设网站开发公司百度电脑端网页版入口
  • 站长工具排名查询友情链接检测平台
  • 网站的兼容性竞价培训
  • 复古网站设计百度广告投诉电话客服24小时
  • vs做网站的书籍做网站公司哪家正规
  • 导航网站帝国cms模版百度seo指数查询
  • 做视频类网站需要哪些许可推广优化
  • 一个做flash的网站电商运营seo
  • api模式网站开发南宁百度推广代理公司
  • 手机免费注册网站seo高级
  • 石家庄高铁招聘信息网网络营销优化推广公司
  • 网站开发后台框架怎么免费做网站
  • 漳州网站优化垂直搜索引擎
  • 南京网络维护公司百度seo哪家公司好
  • 免费申请杭州seo软件
  • 用织梦做网站有钱途吗抖音seo培训
  • wordpress得到分类id杭州企业seo
  • 网站建网站建设seo帮帮您软文广告经典案例600
  • b2c网站的主要类型重庆seo网站排名