此包已被废弃,不再维护。没有建议的替代包。

一个用于访问《EVE Online》CREST API的PHP库

2.0.0 2015-07-17 13:34 UTC

README

在我建立这个库之前,CCP还没有实施第三方许可证,因此你只能看到到那时可用的内容。由于我觉得我作为这个库的开发者没有得到适当的保护,并且所有试图与CCP讨论此事的尝试都无果而终,所以我自那以后就没有添加新功能。

这意味着:一些表示类的实现可能已过时(例如,如果它们有v2表示),CREST现在提供的一些东西从未实现,而且此外,没有对需要单点登录的功能的实现(因为这需要许可证)。

你可以自由地fork这个库并使用它,扩展它,重写它或做任何你想要的事情,代码在MIT许可证下,并将保持如此,但我可能不会回答错误报告,也不会接受pull请求或进行任何其他工作——如果你想要接管维护工作,请随时联系我。

直到找到维护者,我无法推荐使用此项目。

最好的祝愿,Peter "Peter Powers" Petermann

Latest Stable Version Total Downloads Scrutinizer Quality Score Code Coverage

Perry

一个用于访问《EVE Online》CREST API的PHP库

警告

这是一个原型/正在进行中的工作。由于CCP尚未发布大部分CREST API,其用途极为有限,此外,这个库不应被视为完整或稳定,很可能在进一步开发过程中会破坏向后兼容性。如果你不知道自己在做什么,不要使用此库。

完整性状态

实现

已删除

此外,你可能会找到一些用于访问Thora(旧API的代理)的文件,但它基本上还不工作,所以不要使用它。

此外,请查看此README的底部,它包含所有已知问题的列表。

许可证

此库在MIT风格许可证下发布。有关详细信息,请参阅LICENSE.txt。

需求

安装

假设

在开始之前,有一些假设

  1. 您正在Linux上,并且具有命令行访问权限。
  2. 您知道如何在Linux上自己处理
  3. 需求(请参阅README)已安装。

快速安装

Perry通过伟大的Composer依赖管理进行安装和更新,它可以通过Packagist获得,因此您的Composer安装器应该默认找到这些包。

如果您不熟悉Composer,从未使用过它,并需要示例,请访问https://getcomposer.org.cn/并阅读它。Composer是一个伟大的系统,如果您对PHP开发认真,您应该了解它。

添加以下之一(版本)

  • "3rdpartyeve/perry": "1.0.*" 或(dev-master,源代码更改)
  • "3rdpartyeve/perry": "dev-master" 到您的composer.json

使用

缓存

Perry带有内置的请求CREST页面缓存。Perry符合PSR-6(当前草案状态)。由于PSR-6尚未最终确定/发布,目前它还包含PSR-6定义的接口。一旦PSR-6可用,这些接口将从中移除。

默认情况下,Perry的缓存是禁用的,这意味着如果您想进行任何形式的缓存,您必须启用它。要在Perry中启用缓存,您只需给设置单例一个PSR-6兼容的缓存实例。

使用Perry,您将获得一个极其简单的文件缓存,它在构造函数中接受一个路径,然后将其填充为缓存文件。如果您使用它,请记住,这些文件不会自动删除。

缓存的TTL默认为5分钟,请参见下面的示例了解如何更改它。

<?php
// require composers autoload.php
require_once 'vendor/autoload.php';

// import the Setup class, alternatively you can always use the full qualified name)
use Perry\Setup;

// get the Instance of Setup and hand an instance of the PoolInterface implementation
// of the file cache
Setup::getInstance()->cacheImplementation = new FilePool("/path/to/cache/folder");

// change ttl to 10 minutes
Setup::$cacheTTL = 600;

示例

这里有一些示例,基于使用Composer安装Perry

击杀邮件

<?php
// lets set an url here for this example
$url = "http://public-crest.eveonline.com/killmails/34940735/32a1ed47430a4bf247d0544b399014067a734994/";

// require composers autoload.php
require_once 'vendor/autoload.php';

// import the Perry class, alternatively you can always use the full qualified name)
use Perry\Perry;


// since we have a use import on Perry\Perry, we can just use the classname here, otherwise
// it would be $killmail = \Perry\Perry::fromUrl($url);
/** @var \Perry\Representation\Eve\v1\Killmail */
$killmail = Perry::fromUrl($url);

// now there should be either an exception throw (in RL you want to catch those) or
// $killmail will contain a killmail. You can now access the values of the document
// quite easy.

// check if the victim has a character (not the cases for poses for example)
if (isset($killmail->victim->character)) {
    $killstring = sprintf(
        '%s of %s lost a %s to ',
        $killmail->victim->character->name,     // since we do have a character we can use its name
        $killmail->victim->corporation->name,   // victims allways have a corporation
        $killmail->victim->shipType->name       // the shiptype is what was actually lost
    );
} else {
    $killstring = sprintf(
        '%s lost by %s to ',
        $killmail->victim->shipType->name,
        $killmail->victim->corporation->name
    );
}

// attackers is a list of KillmailAttacker Objects.
$attackers = array();
foreach ($killmail->attackers as $attacker) {
    // like the victim there might not be a character with the attacker (sentry guns?)
    $attackers[] = isset($attacker->character) ? $attacker->character->name : $attacker->corporation->name;
}

$killstring .= join(',', $attackers);

echo $killstring;


// for more examples on what data is available in killmails, look at a killmail json string. If in doubt, there are some
// in tests/mock/kill*.json
// the references (character for example) which would be called like $killmail->victim->character(), do not work,
// since CCP has not opened those endpoints yet. :(
// except: the alliance endpoint work (at the moment on SISI only, but they will go live soon)

区域

<?php
// declare namespace of your script (optional, but recommended)
namespace MyScript;

// lets set an url here for this example
$url = "http://public-crest.eveonline.com/districts/";

// require composers autoload.php
require_once 'vendor/autoload.php';

// import the Perry class, alternatively you can always use the full qualified name
use Perry\Perry;

// we get the DistrictCollection Object, which will cause Perry to make a request to CCP's CREST API, and
// populate the DistrictCollection (and the Districts it holds)
/** @var \Perry\Representation\Eve\v1\DistrictCollection */
$districtCollection = Perry::fromUrl($url);


// districtCollection has a member called "items" which contains a list of districts
// we iterate over those items, and print a short info for every district.
// owner,system and infrastructure are references, which means they refer to further
// api representations, sadly, at the moment they refer to parts of the CREST API that
// CCP has not made public yet.
// If those reprenstations where public you could access them by doing $district->owner(), which would return a
// Corporation Representation. Again, this this is not working yet, hence we only use the name of the
// reference in this example.

foreach ($districtCollection->items as $district) {
    printf(
        "District: %s\n Owner: %s\n System: %s\n Clone Capacity: %s\n cloneRate: %s\n Infrastructure: %s\n\n",
        $district->name,
        $district->owner->name,
        $district->system->name,
        $district->cloneCapacity,
        $district->cloneRate,
        $district->infrastructure->name
    );
}

已知问题

有一些已知问题。如果您想帮助修复这些问题:欢迎PullRequests。

  • CREST有一个Uri类型,它链接到crest的其他部分。它与引用不完全相同,尚未实现 - 因此目前uri类型将返回一个包含uri的字符串,而不是可执行对象。这很快就会得到修复。
  • 从版本1.0.0开始,原始的便利方法如\Perry\Representation\Eve\v1\DistrictCollection::getInstance();不再工作,这是故意的
  • CREST字典具有如"32x32"之类的键,PHP会在$object->32x32上执行解析错误。您可以通过$object->{'32x32'};或使用它们作为数组来访问这些成员,而不是使用$object['32x32']。后者应该是首选变体。
  • CREST中引用的许多端点都不是公开可用的。对此无能为力,除非CCP打开这些端点。
  • 表示类中的缩进很糟糕。这是由于类是生成的,可能在未来的版本中得到修复
  • 目前Perry不支持对任何端点(POST)的写访问,但由于CCP尚未发布可写入的公开接口,这不应构成问题。
  • Perry附带的基础缓存非常简单。未来将会有更好的解决方案。
  • CREST有限制请求速率,防止你连续发送大量请求(我猜测是每秒15个)。这个速率限制不是由Perry强制的,所以你需要自己处理这个问题。
  • 是的,单元测试并不完整,Perry没有全面覆盖。
  • Perry在Psr命名空间中附带类,这是因为Perry正在实现一个尚未生效的Psr。