abulia/tfl-unified

Laravel 包,用于访问伦敦交通局(TFL)的统一API

v0.1 2017-06-19 16:14 UTC

This package is not auto-updated.

Last update: 2024-09-24 17:29:14 UTC


README

TflUnified 是一个 Laravel 包,简化了与伦敦交通局(TfL)统一API的交互。

参见:TfL API

安装

步骤 1: Composer

composer require abulia/tfl-unified

步骤 2: 服务提供者

在 Laravel 应用中,打开 config/app.php,然后在 providers 数组中追加

Abulia\TflUnified\TflServiceProvider::class

可选 Facade 别名

aliases 数组中追加

'Tfl' => Abulia\TflUnified\ApiServiceFacade::class

步骤 3: 配置

默认配置无需修改即可使用。要自定义连接设置,运行

php artisan vendor:publish

这会将 tfl.php 复制到 config/ 目录。所有连接选项都可以在这个文件中设置 - 它还显示了可以在 .env 文件中设置的环境变量。

用法示例

(以 PsySH 会话显示)

获取行程规划路线

>>> {
...     $ambiguousResult = Tfl::journey()
...         ->withDisambiguation()
...         ->journeyResults('Paddington', 'Brixton');
... 
...     $fromIcsCode = $ambiguousResult->getFromLocationDisambiguation() 
...         ->getDisambiguationOptions()[0] 
...         ->getPlace() 
...         ->getIcsCode();
... 
...     $toIcsCode = $ambiguousResult->getToLocationDisambiguation() 
...         ->getDisambiguationOptions()[0] 
...         ->getPlace() 
...         ->getIcsCode();
... 
...     $exactResult = Tfl::journey()
...         ->withDisambiguation()
...         ->journeyResults($fromIcsCode, $toIcsCode);
... 
...     foreach ($exactResult->getJourneys()[0]->getLegs() as $leg) {
...         echo($leg->getInstruction()->getDetailed() . "\n");
...     }
... }
Bakerloo line towards Elephant & Castle
Victoria line towards Brixton
>>> 

获取线 #2 上车站的公交车到达时间

>>> {
...     $stopPoints = Tfl::cached(60)->line()->stopPoints(2);
... 
...     echo("StopPoint: " . $stopPoints[0]->getCommonName() . "\n");
... 
...     foreach (Tfl::stopPoint()->arrivals($stopPoints[0]->getId()) as $arrival) {
...         printf("Bus#: %3d\tDestination: %30s\tExpected: %s\n", $arrival->getLineName(), $arrival->getDestinationName(), $arrival->getExpectedArrival()->format('c'));
...     }
... }
StopPoint: Brixton Station
Bus#: 109	Destination:            Croydon Town Centre	Expected: 2017-06-16T15:22:46+00:00
Bus#: 109	Destination:            Croydon Town Centre	Expected: 2017-06-16T15:17:02+00:00
Bus#: 109	Destination:            Croydon Town Centre	Expected: 2017-06-16T15:11:10+00:00
Bus#: 109	Destination:            Croydon Town Centre	Expected: 2017-06-16T15:11:39+00:00
Bus#: 109	Destination:            Croydon Town Centre	Expected: 2017-06-16T15:06:06+00:00
Bus#: 109	Destination:            Croydon Town Centre	Expected: 2017-06-16T15:05:50+00:00
Bus#: 133	Destination:              Streatham Station	Expected: 2017-06-16T15:23:02+00:00
Bus#: 133	Destination:              Streatham Station	Expected: 2017-06-16T15:08:40+00:00
Bus#: 133	Destination:              Streatham Station	Expected: 2017-06-16T15:13:29+00:00
Bus#: 133	Destination:              Streatham Station	Expected: 2017-06-16T15:29:01+00:00
Bus#: 133	Destination:              Streatham Station	Expected: 2017-06-16T15:02:58+00:00
Bus#: 159	Destination:              Streatham Station	Expected: 2017-06-16T15:30:19+00:00
Bus#: 159	Destination:              Streatham Station	Expected: 2017-06-16T15:19:25+00:00
Bus#: 159	Destination:              Streatham Station	Expected: 2017-06-16T15:11:53+00:00
Bus#: 159	Destination:              Streatham Station	Expected: 2017-06-16T15:14:51+00:00
Bus#: 159	Destination:              Streatham Station	Expected: 2017-06-16T15:03:33+00:00
Bus#: 159	Destination:              Streatham Station	Expected: 2017-06-16T15:10:02+00:00
Bus#:   2	Destination:                   West Norwood	Expected: 2017-06-16T15:15:15+00:00
Bus#:   2	Destination:                   West Norwood	Expected: 2017-06-16T15:20:39+00:00
Bus#:   2	Destination:                   West Norwood	Expected: 2017-06-16T15:26:56+00:00
Bus#:   2	Destination:                   West Norwood	Expected: 2017-06-16T15:09:00+00:00
Bus#:   2	Destination:                   West Norwood	Expected: 2017-06-16T15:11:24+00:00
Bus#: 250	Destination:            Croydon Town Centre	Expected: 2017-06-16T15:14:59+00:00
Bus#: 250	Destination:            Croydon Town Centre	Expected: 2017-06-16T15:13:33+00:00
Bus#: 250	Destination:            Croydon Town Centre	Expected: 2017-06-16T15:28:45+00:00
Bus#: 250	Destination:            Croydon Town Centre	Expected: 2017-06-16T15:22:44+00:00
Bus#: 250	Destination:            Croydon Town Centre	Expected: 2017-06-16T15:06:04+00:00
Bus#: 333	Destination:               Tooting Broadway	Expected: 2017-06-16T15:26:11+00:00
Bus#: 333	Destination:               Tooting Broadway	Expected: 2017-06-16T15:03:34+00:00
Bus#: 333	Destination:               Tooting Broadway	Expected: 2017-06-16T15:17:07+00:00
Bus#:  45	Destination:                        Brixton	Expected: 2017-06-16T15:04:58+00:00
Bus#:  45	Destination:                   Clapham Park	Expected: 2017-06-16T15:09:48+00:00
Bus#:  45	Destination:                   Clapham Park	Expected: 2017-06-16T15:11:11+00:00
Bus#:  45	Destination:                   Clapham Park	Expected: 2017-06-16T15:31:57+00:00
Bus#:  45	Destination:                   Clapham Park	Expected: 2017-06-16T15:29:57+00:00
Bus#:  59	Destination: Streatham Hill, Telford Avenue	Expected: 2017-06-16T15:04:52+00:00
Bus#:  59	Destination: Streatham Hill, Telford Avenue	Expected: 2017-06-16T15:09:08+00:00
Bus#:  59	Destination: Streatham Hill, Telford Avenue	Expected: 2017-06-16T15:21:00+00:00
Bus#:  59	Destination: Streatham Hill, Telford Avenue	Expected: 2017-06-16T15:13:42+00:00
Bus#:  59	Destination: Streatham Hill, Telford Avenue	Expected: 2017-06-16T15:15:35+00:00
>>>

日志记录

Tfl::setLogger(Log $logger)  

为 API 调用异常设置日志记录实例。

缓存

默认不缓存结果。任何结果集都可以通过调用 Laravel 默认缓存轻松缓存,如下所示

Tfl::cached(5)->line()->arrivals('490000031T', '2')

这将缓存到达数据 5 分钟。

要使用不同的缓存实例

Tfl::setCache(Cache $cache)  

要清除所有缓存数据

Tfl::clearCache()  

如果缓存后端支持,将使用缓存标签。

API

AccidentStats

Tfl::accidentStats()->get($year)
获取指定年份发生的所有事故详情。

AirQuality

Tfl::airQuality()->get()
获取空气质量数据流。

BikePoint

Tfl::bikePoint()->get($id)
获取给定 ID 的自行车点。

Tfl::bikePoint()->getAll()
获取所有自行车点位置。地点对象有一个附加属性数组,其中包含 nbBikes、nbDocks 和 nbSpaces 数字,这些数字给出了 BikePoint 的状态。这些数字不匹配(即 nbDocks - (nbBikes + nbSpaces) != 0)表示码头损坏。

Tfl::bikePoint()->search($query)
通过名称搜索自行车站,例如,自行车点的名称通常包含街道名称或附近地标的信息。请注意,搜索结果不包含 PlaceProperties,即 BikePoint 的状态或占用情况,要获取该信息,您应通过其 ID 在 /BikePoint/id 上检索 BikePoint。

Cabwise

Tfl::cabwise()->get($lat, $lon, $optype = null, $wc = null, $radius = null, $name = null, $max_results = null, $legacy_format = null, $force_xml = null, $twenty_four_seven_only = null)
获取出租车和迷你出租车联系信息。

Journey

Tfl::journey()->meta()
获取所有可用的行程规划模式列表。

Tfl::journey()->journeyResults($from, $to, $via = null, $national_search = null, $date = null, $time = null, $time_is = null, $journey_preference = null, $mode = null, $accessibility_preference = null, $from_name = null, $to_name = null, $via_name = null, $max_transfer_minutes = null, $max_walking_minutes = null, $walking_speed = null, $cycle_preference = null, $adjustment = null, $bike_proficiency = null, $alternative_cycle = null, $alternative_walking = null, $apply_html_markup = null, $use_multi_modal_call = null, $walking_optimization = null)
根据简单类型参数执行行程规划搜索。

Tfl::journey()->withDisambiguation()->journeyResults($from, $to, $via = null, $national_search = null, $date = null, $time = null, $time_is = null, $journey_preference = null, $mode = null, $accessibility_preference = null, $from_name = null, $to_name = null, $via_name = null, $max_transfer_minutes = null, $max_walking_minutes = null, $walking_speed = null, $cycle_preference = null, $adjustment = null, $bike_proficiency = null, $alternative_cycle = null, $alternative_walking = null, $apply_html_markup = null, $use_multi_modal_call = null, $walking_optimization = null)
执行旅程规划搜索并处理歧义搜索。

线路

Tfl::line()->arrivals($stop_point_id, $ids)
根据给定的线路ID和站点获取到达预测列表。

Tfl::line()->arrivalsByStopPoint($stop_point_id, $ids, $direction)
根据给定的线路ID和站点,获取给定方向上的到达预测列表。

Tfl::line()->disruption($ids)
获取给定线路ID的干扰信息。

Tfl::line()->disruptionByMode($modes)
获取给定模式的所有线路的干扰信息。

Tfl::line()->get($ids)
获取指定线路ID的线路。

Tfl::line()->getByMode($modes)
获取指定模式的线路。

Tfl::line()->lineRoutesByIds($ids, $service_types = null)
获取给定线路ID的所有有效路线,包括每条路线的起点和终点站名称和ID。

Tfl::line()->metaDisruptionCategories()
获取用于过滤干扰的有效类别列表。

Tfl::line()->metaModes()
获取所有有效模式列表,用于过滤线路。

Tfl::line()->metaServiceTypes()
获取用于过滤的有效ServiceTypes列表。

Tfl::line()->metaSeverity()
获取有效严重程度代码列表。

Tfl::line()->routeByMode($modes, $service_types = null)
获取给定模式的所有线路及其有效路线,包括每条路线的起点和终点站名称和ID。

Tfl::line()->routeSequence($id, $direction, $service_types = null, $exclude_crowding = null)
获取给定线路ID的所有有效路线,包括每条路线上的站点序列。

Tfl::line()->search($query, $modes = null, $service_types = null)
搜索与查询字符串匹配的线路或路线。

Tfl::line()->status($ids, $start_date, $end_date, $detail = null, $date_range_start_date = null, $date_range_end_date = null)
获取给定线路ID在提供日期内的线路状态,例如轻微延误。

Tfl::line()->statusByIds($ids, $detail = null)
获取给定线路ID的状态,例如轻微延误。

Tfl::line()->statusByMode($modes, $detail = null)
获取给定模式的所有线路的状态。

Tfl::line()->statusBySeverity($severity)
获取具有给定严重程度的所有线路的状态。可以通过Line/Meta/Severity调用获取有效严重程度代码列表。

Tfl::line()->stopPoints($id)
获取服务给定线路ID的站点列表。

Tfl::line()->timetable($from_stop_point_id, $id)
获取给定线路上的指定站点的时刻表。

Tfl::line()->timetableTo($from_stop_point_id, $id, $to_stop_point_id)
获取给定线路和指定目的地的指定站点的时刻表。

模式

Tfl::mode()->arrivals($mode, $count = null)
获取给定模式下所有站点的下一到达预测。

Tfl::mode()->getActiveServiceTypes()
返回给定模式的活动服务类型。目前仅支持地铁。

占有率

Tfl::occupancy()->get()
获取所有有占有率数据的停车场的占有率。

Tfl::occupancy()->getById($id)
获取给定ID的停车场的占有率。

地点

Tfl::place()->get($id, $include_children = null)
获取给定ID的地点。

Tfl::place()->getAt($type, $lat, $lon, $location_lat, $location_lon)
获取与给定纬度和经度相交的给定类型的任何地点。在实践中,这意味着地点必须是多边形的,例如区域边界。

Tfl::place()->getByGeoBox($sw_lat, $sw_lon, $ne_lat, $ne_lon, $categories = null, $include_children = null, $type = null, $active_only = null)
获取位于由其西北角和东南角的纬度/经度定义的边界框内的地点。可按类型筛选,并可删除属性以减小数据包大小。

Tfl::place()->getByType($types, $active_only = null)
获取给定类型的所有地点。

Tfl::place()->getOverlay($z, $type, $width, $height, $lat, $lon, $location_lat, $location_lon)
获取给定一组坐标和给定宽/高处的地点覆盖。

Tfl::place()->getStreetsByPostCode($postcode, $postcode_input_postcode = null)
获取与邮编关联的一组街道。

Tfl::place()->metaCategories()
获取所有可用地点属性类别和键的列表。

Tfl::place()->metaPlaceTypes()
获取可用地点类型的列表。

Tfl::place()->search($name, $types = null)
获取与给定查询匹配的所有地点。

道路

Tfl::road()->disruptedStreets($start_date, $end_date)
获取中断道路的列表。如果没有提供日期筛选器,则返回当前中断。

Tfl::road()->disruption($ids, $strip_content = null, $severities = null, $categories = null, $closures = null)
获取按道路ID筛选的活动中断。

Tfl::road()->disruptionById($disruption_ids, $strip_content = null)
获取按中断ID筛选的活动中断列表。

Tfl::road()->get()
获取由TfL管理的所有道路。

Tfl::road()->getById($ids)
获取指定ID的道路(例如A1)。

Tfl::road()->metaCategories()
获取有效的RoadDisruption类别列表。

Tfl::road()->metaSeverities()
获取有效的RoadDisruption严重性代码列表。

Tfl::road()->status($ids, $date_range_nullable_start_date = null, $date_range_nullable_end_date = null)
获取指定日期范围内(或现在直到今天结束,如果没有提供日期)的状态汇总的指定道路。

搜索

Tfl::search()->busSchedules($query)
搜索S3上公交路线文件夹中的给定公交路线号。

Tfl::search()->get($query)
搜索网站中查询字符串的出现。返回的最大结果数等于最大页面大小100。要返回后续页面,请使用分页重载。

Tfl::search()->metaCategories()
获取可用搜索类别。

Tfl::search()->metaSearchProviders()
获取可用搜索Provider名称。

Tfl::search()->metaSorts()
获取可用排序选项。

停靠点

Tfl::stopPoint()->crowding($id, $line, $direction)
获取StopPointId的所有静态拥挤数据,以及给定路线和可选特定方向的拥挤数据。

Tfl::stopPoint()->arrivals($id)
获取给定停靠点ID的到达预测列表。

Tfl::stopPoint()->direction($id, $to_stop_point_id, $line_id = null)
返回给定一对停靠点ID的规范方向,“ inbound”或“ outbound”,从->到。

Tfl::stopPoint()->disruption($ids, $get_family = null, $include_route_blocked_stops = null, $flatten_response = null)
获取指定StopPointId的所有中断,以及任何子Naptan记录的中断。

Tfl::stopPoint()->disruptionByMode($modes, $include_route_blocked_stops = null)
获取给定模式的独特中断停靠点列表。

Tfl::stopPoint()->get($ids, $include_crowding_data = null)
获取与给定停靠点ID列表相对应的停靠点列表。

Tfl::stopPoint()->getByGeoPoint($stop_types, $lat, $lon, $radius = null, $use_stop_point_hierarchy = null, $modes = null, $categories = null, $return_lines = null)
按指定标准获取{radius}范围内的停靠点列表。

Tfl::stopPoint()->getByMode($modes, $page = null)
获取在停靠点可用模式下筛选的停靠点列表。

Tfl::stopPoint()->getBySms($id, $output = null)
获取给定短信代码的停靠点。

Tfl::stopPoint()->getByType($types)
获取给定类型的所有停靠点。

Tfl::stopPoint()->getCarParksById($stop_point_id)
获取与给定停靠点ID对应的停车场。

Tfl::stopPoint()->getServiceTypes($id, $line_ids = null, $modes = null)
获取指定停靠点的服务类型。

Tfl::stopPoint()->getTaxiRanksByIds($stop_point_id)
获取与指定停靠点ID对应的出租车排列表。

Tfl::stopPoint()->metaCategories()
获取可用的停靠点附加信息类别列表。

Tfl::stopPoint()->metaModes()
获取可用的停靠点模式列表。

Tfl::stopPoint()->metaStopTypes()
获取可用的停靠点类型列表。

Tfl::stopPoint()->reachableFrom($id, $line_id, $service_types = null)
获取可通过车站/线路组合到达的停靠点。

Tfl::stopPoint()->route($id, $service_types = null)
返回为给定停靠点ID提供服务的所有线路的路线段。

Tfl::stopPoint()->search($query, $modes = null, $fares_only = null, $max_results = null, $lines = null, $include_hubs = null)
通过停靠点的通用名称或5位数的Countdown公交车站代码搜索停靠点。

Tfl::stopPoint()->searchByQuery($query, $modes = null, $fares_only = null, $max_results = null, $lines = null, $include_hubs = null)
通过停靠点的通用名称或5位数的Countdown公交车站代码搜索停靠点。

旅行时间

Tfl::travelTime()->getCompareOverlay($z, $pin_lat, $pin_lon, $map_center_lat, $map_center_lon, $scenario_title, $time_of_day_id, $mode_id, $width, $height, $direction, $travel_time_interval, $compare_type, $compare_value)
获取旅行时间叠加层。

Tfl::travelTime()->getOverlay($z, $pin_lat, $pin_lon, $map_center_lat, $map_center_lon, $scenario_title, $time_of_day_id, $mode_id, $width, $height, $direction, $travel_time_interval)
获取旅行时间叠加层。

车辆

Tfl::vehicle()->get($ids)
获取给定车辆ID列表的预测。

Tfl::vehicle()->getVehicle($vrm)
获取车辆的排放附加费合规性。