PHP性状的使用
<?php
trait Geocodable{
/** @var string */
protected $address; /** @var \Geocoder\Geocoder */
protected $geocoder; /** @var \Geocoder\Result\Geocoded */
protected $geocoderResult; public function setGeocoder(\GeoCoder\GeocoderInterface $gocoder)
{
$this->geocoder = $gocoder;
} public function setAddress($address)
{
$this->address = $address;
} public function getLatitude()
{
if (isset($this->geocoderResult) == false){
$this->geocodeAddress();
} return $this->geocoderResult->getLatitude();
} public function getLongitude()
{
if (isset($this->geocoderResult) === false){
$this->geocodeAddress();
} return $this->geocoderResult->getLongitude();
} protected function geocodeAddress()
{
$this->geocoderResult = $this->geocoder->geocode($this->address); return true;
}
} //使用性状
class RetailStore
{
use Geocodable; //这里是类的实现
} $geocoderAdapter = new \Geocoder\HttpAdapter\CurlHttpAdapter();
$geocoderProvider = new \Geocoder\Provider\GoogleMapsProvider($geocoderAdapter);
$geocoder = new \Geocoder\Geocoder($geocoderProvider); $store = new RetailStore();
$store->setAddress('420 9th Avenue, New York, NY 10001 USA');
$store->setGeocoder($gocoder); $latitude = $store->getLatitude();
$longitude = $store->getLongitude();
echo $latitude, ':', $longitude;
PHP性状的使用的更多相关文章
- php中trait(性状)与generator(生成器)
PHP中trait(性状)与generator(生成器) 一.trait (性状) 最近在看Josh Lockhat的<Modern PHP>,这本书很薄.但是其中给出了一个很重要的学习方 ...
- Genome-wide Complex Trait Analysis(GCTA)-全基因组复杂性状分析
GCTA(全基因组复杂性状分析)工具开发目的是针对复杂性状的全基因组关联分析,评估SNP解释的表型方差所占的比例(该网站地址:http://cnsgenomics.com/software/gcta/ ...
- 性状、生成器、闭包、OPcache【Modern PHP】
目录 性状 Trait 生成器 闭包 Zend OPcache PHP发展这么多年,技术.架构都已经革新,了解现代PHP很重要,最近在看Model PHP这本书,系统的了解下PHP相关的概念. 性状 ...
- modern php笔记---2.1、特性(命名空间、特性、性状)
modern php笔记---2.1.特性(命名空间.特性.性状) 一.总结 一句话总结: legend2是真的非常好用,资质起码提升5倍,也就是学习效率提升了起码5倍 1.命名空间实质? 从技术层面 ...
- modern php笔记---php (性状)
modern php笔记---php (性状) 一.总结 一句话总结: trait是和继承一个层次的东西 一个类use MyTrait;后,trait中的方法覆盖父类方法,当前类中的方法覆盖trait ...
- 【GS文献】测序时代植物复杂性状育种之基因组选择
综述:Genomic Selection in the Era of Next Generation Sequencing for Complex Traits in Plant Breeding 要 ...
- Atitit 软件工程概览attilax总结
Atitit 软件工程概览attilax总结 1.1. .2 软件工程的发展 进一步地,结合人类发展史和计算机世界演化史来考察软件工程的发展史. 表2 软件工程过程模型 表2将软件工程的主要过程模型做 ...
- R语言:常用统计检验
统计检验是将抽样结果和抽样分布相对照而作出判断的工作.主要分5个步骤: 建立假设 求抽样分布 选择显著性水平和否定域 计算检验统计量 判定 -- 百度百科 假设检验(hypothesis test)亦 ...
- react-echarts之折线图的显示
react中想要实现折线图和饼图的功能,需要引入react-echarts包,然后再实现折线图的功能.我这里引用的版本是:0.1.1.其他的写法参echarts官网即可.下面详细讲解的是我在react ...
随机推荐
- Integer.toBinaryString()的源代码解析
private static String toUnsignedString(int i, int shift) { char[] buf = new char[32];//i是要整形,这里得把它化成 ...
- java获取到机器IP地址及MAC码
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.net.InetAddress; import java.ne ...
- border-radius详解
语法: border-radius : none | <length>{1,4} [/ <length>{1,4} ]? 取值范围: <length>: 由浮点数字 ...
- wdcp安装
下载安装(ssh登录服务器,执行如下操作即可,需要用到root用户权限来安装)v3版本已经发布,更多可看论坛 wdCP v3版本讨论区更多安装请看 http://www.wdlinux.cn/bbs/ ...
- android 中获取当前焦点所在屏幕中的位置 view.getLocationOnScreen(location)
final int[] location = new int[2]; view.getLocationOnScreen(location); final int[] location = new in ...
- flume 配置
[root@dtpweb data]#tar -zxvf apache-flume-1.7.0-bin.tar.gz[root@dtpweb conf]# cp flume-env.sh.templa ...
- linux下设置固定IP
编辑网卡配置文件 vi /etc/sysconfig/network-script/ifcfg-eth0 进入编辑模式 按i键进行编辑修改 DEVICE=eth0 #物理设备名 IPADDR=192. ...
- 解决Windows下网络原因Composer安装失败问题
由于Composer镜像都在国外,所以直接在官网下载Windows Installer后安装很多情况下是无法成功安装的. 解决办法: 1,将php添加到系统环境变量,并开启openssl扩展. 2,点 ...
- sh脚本异常:/bin/sh^M:bad interpreter: No such file or directory
在Linux中执行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory. 分析:这是不同系统编码格式引起的:在windows系统中 ...
- IIS无法加载字体文件(*.woff,*.svg)的解决办法
在编写前端代码的过程中经常会遇到使用特定的字体(*.woff,*.svg),此时在加载字体时请求会被返回 Failed to load resource: the server responded w ...