PHPackages                             philwc/dark-sky - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. philwc/dark-sky

ActiveLibrary[API Development](/categories/api)

philwc/dark-sky
===============

A strongly typed simple client to talk to the Dark Sky API.

v2.0.2(7y ago)0894[1 issues](https://github.com/philwc/dark-sky/issues)MITPHPPHP &gt;=7.1

Since Aug 9Pushed 7y ago1 watchersCompare

[ Source](https://github.com/philwc/dark-sky)[ Packagist](https://packagist.org/packages/philwc/dark-sky)[ RSS](/packages/philwc-dark-sky/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (11)Versions (11)Used By (0)

Dark Sky API Client
===================

[](#dark-sky-api-client)

A strongly typed simple client to talk to the Dark Sky API.
-----------------------------------------------------------

[](#a-strongly-typed-simple-client-to-talk-to-the-dark-sky-api)

[![Build Status](https://camo.githubusercontent.com/cfdd6d1f8ad3bfb3531ae5bb3556e9444c0b7a305b1f1a2b9384540468aa9326/68747470733a2f2f7472617669732d63692e6f72672f7068696c77632f6461726b2d736b792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/philwc/dark-sky)

### Getting Started

[](#getting-started)

To get started, you will need to get a secret key from Dark Sky: .

### Client Adapters

[](#client-adapters)

This package makes use of HTTP adapters to connect to the API. Two are included out of the box, a Guzzle adapter and a Simple adapter (using `file_get_contents`). If you have specialised connection needs, simply implement the `ClientAdapterInterface` and pass to the client factory.

If a ClientAdapter is not specified, the package will make use of the `GuzzleAdapter` if [Guzzle](http://guzzlephp.org/) is available, falling back to the `SimpleAdapter` (using `file_get_contents`) if not.

If a guzzle adapter is provided (or the implemented `ClientAdapterInterface` supports it), multiple requests will be made concurrently.

Usage
-----

[](#usage)

Install the package using composer:

```
composer require philwc/dark-sky
```

### Simple Usage

[](#simple-usage)

#### Client

[](#client)

To use the `Client` use the `ClientFactory`:

```
require_once __DIR__ . '/vendor/autoload.php';

$client = philwc\DarkSky\ClientFactory::get(
    getenv('SECRET_KEY')
);

$request = \philwc\DarkSky\Entity\ForecastRequest::fromArray([
    'latitude' => 53.4084,
    'longitude' => 2.9916,
]);

$weather = $client->retrieve($request);

echo $weather->getCurrently()->getSummary() . PHP_EOL; // Mostly Cloudy
echo $weather->getCurrently()->getIcon()->toString() . PHP_EOL; // partly-cloudy-day
echo $weather->getCurrently()->getTemperature()->toFloat() . PHP_EOL; // 17.71
echo $weather->getCurrently()->getTemperature()->toString() . PHP_EOL; // 17.71 °F
```

### Advanced Usage

[](#advanced-usage)

It is possible to pass both a PSR-16 cache adapter, as well as a PSR-3 logger into the `ClientFactory`:

```
require_once __DIR__ . '/vendor/autoload.php';

$log = new Monolog\Logger('test');
$log->pushHandler(new Monolog\Handler\ErrorLogHandler());

philwc\DarkSky\ClientFactory::setLogger($log);

$client = philwc\DarkSky\ClientFactory::get(
    getenv('SECRET_KEY'),
    new Cache\Adapter\PHPArray\ArrayCachePool(),
    new philwc\DarkSky\ClientAdapter\GuzzleAdapter()
);
```

When creating your request, you can pass a `parameters` key to customise the values you get back from DarkSky.

```
$request = \philwc\DarkSky\Entity\ForecastRequest::fromArray([
    'latitude' => 53.4084,
    'longitude' => 2.9916,
    'parameters' => ['lang' => 'en', 'units' => 'si']
]);
$weather = $client->retrieve($request);

echo $weather->getCurrently()->getSummary() . PHP_EOL; // Mostly Cloudy
echo $weather->getCurrently()->getIcon()->toString() . PHP_EOL; // partly-cloudy-day
echo $weather->getCurrently()->getTemperature()->toFloat() . PHP_EOL; // 17.71
echo $weather->getCurrently()->getTemperature()->toString() . PHP_EOL; // 17.71 °C

// This second call will now be retrieved from the cache
$weather = $client->simpleRetrieve(53.4808, 2.2426, ['units'=>'si', 'lang' => 'en']);

echo $weather->getCurrently()->getSummary() . PHP_EOL; // Mostly Cloudy
echo $weather->getCurrently()->getIcon()->toString() . PHP_EOL; // partly-cloudy-day
echo $weather->getCurrently()->getTemperature()->toFloat() . PHP_EOL; // 17.71
echo $weather->getCurrently()->getTemperature()->toString() . PHP_EOL; // 17.71 °C
```

### Caching

[](#caching)

This package is also able to make use of a PSR-16 caching adapter to cache calls from the API. Simply pass a relevant cache service (see ) to the client factory to use. No caching is provided out of the box.

It is possible to set the TTL for the cache independently for each request type. On the client, use `setForecastTTL` or `setTimeMachineTTL` to specify. By default, the following TTLs are set:

- `ForecastClient` - 60s
- `TimeMachineClient` - 86400s (24 hours)

```
$client = philwc\DarkSky\ClientFactory::get(
    getenv('SECRET_KEY'),
    new Cache\Adapter\PHPArray\ArrayCachePool()
);

$client->setForecastTTL(120);

$request = \philwc\DarkSky\Entity\ForecastRequest::fromArray([
    'latitude' => 53.4084,
    'longitude' => 2.9916,
]);

$weather = $client->retrieve($request);

// This second call will now be cached for 120s
$weather = $client->retrieve($request);
```

### Concurrent Requests

[](#concurrent-requests)

It is possible to make concurrent requests to the DarkSky API. Simply create a `RequestCollection` and pass to `retrieve`

```
$client = philwc\DarkSky\ClientFactory::get(
    $secretKey,
    new Cache\Adapter\PHPArray\ArrayCachePool(),
    new philwc\DarkSky\ClientAdapter\SimpleAdapter()
);

$requestCollection = new \philwc\DarkSky\EntityCollection\RequestCollection();
$manchesterRequest = \philwc\DarkSky\Entity\ForecastRequest::fromArray([
    'latitude' => 53.4808,
    'longitude' => 2.2426,
    'parameters' => ['lang' => 'en', 'units' => 'si']
]);

$requestCollection->add($manchesterRequest);
$liverpoolRequest = \philwc\DarkSky\Entity\ForecastRequest::fromArray([
    'latitude' => 53.4084,
    'longitude' => 2.9916,
    'parameters' => ['lang' => 'en', 'units' => 'si']
]);
$requestCollection->add($liverpoolRequest);

$weatherCollection = $client->retrieve($requestCollection);

foreach ($weatherCollection as $weather) {
    echo $weather->getCurrently()->getSummary() . PHP_EOL;
    echo $weather->getCurrently()->getIcon()->toString() . PHP_EOL;
    echo $weather->getCurrently()->getTemperature()->toFloat() . PHP_EOL;
    echo $weather->getCurrently()->getTemperature()->toString() . PHP_EOL;
}
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

10

Last Release

2811d ago

Major Versions

v1.3.1 → v2.0.02018-08-15

### Community

Maintainers

![](https://www.gravatar.com/avatar/9b77176f6dc883b189a4045084aef3ed04171154f10830335622046022c103ee?d=identicon)[philwc](/maintainers/philwc)

---

Top Contributors

[![philwc](https://avatars.githubusercontent.com/u/617110?v=4)](https://github.com/philwc "philwc (23 commits)")

---

Tags

clientdark-skydark-sky-apidarkskydarksky-apistrongly-typed

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/philwc-dark-sky/health.svg)

```
[![Health](https://phpackages.com/badges/philwc-dark-sky/health.svg)](https://phpackages.com/packages/philwc-dark-sky)
```

###  Alternatives

[algolia/algoliasearch-client-php

API powering the features of Algolia.

69433.0M114](/packages/algolia-algoliasearch-client-php)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[commercetools/commercetools-sdk

The official PHP SDK for the commercetools Composable Commerce APIs

19281.5k](/packages/commercetools-commercetools-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
