nieknijland/ista-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nieknijland/ista-php

最新稳定版本:v0.1.0

Composer 安装命令:

composer require nieknijland/ista-php

包简介

PHP client for the Ista energy consumption API

README 文档

README

Latest Version on Packagist Tests Total Downloads

PHP client for the Ista energy consumption API at mijn.ista.nl. Framework-agnostic.

Requires PHP 8.4+.

Installation

composer require nieknijland/ista-php

Quick start

use NiekNijland\Ista\Ista;

$ista = new Ista(
    username: 'your@email.com',
    password: 'your-password',
);

// Fetch all consumption data
$userValues = $ista->getUserValues();

$customer = $userValues->customers[0];

foreach ($customer->consumption->services as $service) {
    echo "Current usage: {$service->totalNow}\n";
    echo "Previous year: {$service->totalPrevious}\n";

    foreach ($service->currentMeters as $meter) {
        echo "  {$meter->position}: {$meter->value}\n";
    }
}

Constructor

$ista = new Ista(
    username: 'your@email.com',
    password: 'your-password',
    httpClient: $customGuzzleClient,  // ?ClientInterface, default: new Client()
    cache: $psr16Cache,               // ?CacheInterface (PSR-16), default: null (no caching)
    cacheTtl: 3600,                   // int, cache TTL in seconds, default: 3600
);
Parameter Type Default Description
$username string (required) Your mijn.ista.nl username
$password string (required) Your mijn.ista.nl password (marked #[SensitiveParameter])
$httpClient ?ClientInterface null Custom Guzzle HTTP client; null creates a default one
$cache ?CacheInterface null Any PSR-16 cache implementation; null disables caching
$cacheTtl int 3600 Cache time-to-live in seconds

API methods

The client provides four methods. All throw IstaException on failure.

Method Description
getUserValues() Fetch all customers, meters, and billing data
getConsumptionAverages() Fetch building average consumption
getMonthlyConsumption() Fetch month-by-month consumption history
getConsumptionValues() Fetch consumption for a specific billing period

See API Methods for full parameter documentation and examples.

Data objects

All API responses are returned as readonly DTOs with typed properties. Every DTO provides fromArray() and toArray() for serialization.

Class Description
UserValuesResult Top-level response with customers
Customer A customer with address and consumption data
ConsumptionPeriod A billing period with services, meters, and temperatures
ServiceComparison Current vs. previous year totals for a service type
Meter A single meter reading with all technical fields
BillingService Service type definition (e.g. Heating, Hot Water)
BillingPeriod A billing year with start/end dates
ConsumptionAverageResult Building average consumption
ConsumptionValuesResult Consumption data for a specific billing period
MonthlyConsumptionResult Monthly consumption history
MonthlyConsumption A single month's consumption
MonthlyServiceConsumption Per-service totals for a month
MonthlyDeviceConsumption Per-device readings for a month

See Data Objects for all properties and types.

Caching

Pass any PSR-16 CacheInterface to cache API responses and the JWT token:

$ista = new Ista(
    username: 'your@email.com',
    password: 'your-password',
    cache: new YourPsr16Cache(),
    cacheTtl: 86400, // 24 hours
);

Cache keys used:

Key pattern Data
ista:jwt Authentication token
ista:user-values getUserValues() response
ista:consumption-averages:{cuid}:{start}:{end} getConsumptionAverages() response
ista:monthly-consumption:{cuid} getMonthlyConsumption() response
ista:consumption-values:{cuid}:{year}:{start}:{end} getConsumptionValues() response

Cache failures are silently ignored -- the client will re-fetch from the API.

Error handling

All errors are wrapped in a single exception class:

use NiekNijland\Ista\Exception\IstaException;

try {
    $result = $ista->getUserValues();
} catch (IstaException $e) {
    // Authentication failures, HTTP errors, malformed responses
    // Original exception is available via $e->getPrevious()
}

Testing

The package ships testing utilities so you can mock the Ista client in your application tests without making real API calls.

use NiekNijland\Ista\Testing\FakeIsta;
use NiekNijland\Ista\Testing\UserValuesResultFactory;

$fake = new FakeIsta();
$fake->seedUserValuesResult(UserValuesResultFactory::make());

$result = $fake->getUserValues();

$fake->assertCalled('getUserValues');
$fake->assertCalledTimes('getUserValues', 1);

See Testing for full documentation of FakeIsta, all factories, and recorded call inspection.

Development

composer test              # Unit tests
composer test-integration  # Integration tests (requires ISTA_USERNAME and ISTA_PASSWORD)
composer test-all          # All test suites
composer analyse           # PHPStan level 8
composer format            # Laravel Pint
composer rector            # Rector automated refactoring
composer codestyle         # Full pipeline: Rector + Pint + PHPStan

Changelog

Please see CHANGELOG for more information on what has changed recently.

License

The MIT License (MIT). Please see License File for more information.

nieknijland/ista-php 适用场景与选型建议

nieknijland/ista-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「energy」 「consumption」 「heating」 「ista」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 nieknijland/ista-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nieknijland/ista-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 nieknijland/ista-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 23
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-14