Skip to content

Commit d11e3d2

Browse files
committed
Simplify autoloading of examples.
1 parent b81d048 commit d11e3d2

File tree

5 files changed

+21
-48
lines changed

5 files changed

+21
-48
lines changed

Examples/Cache.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,7 @@
1818
use Cmfcmf\OpenWeatherMap;
1919
use Cmfcmf\OpenWeatherMap\AbstractCache;
2020

21-
if (file_exists('../vendor/autoload.php')) {
22-
// Library is not part of a project. "composer install" was executed directly on this library's composer file.
23-
require('../vendor/autoload.php');
24-
} else {
25-
// Library is part of a project.
26-
/** @noinspection PhpIncludeInspection */
27-
require('../../../autoload.php');
28-
}
21+
require_once __DIR__ . '/bootstrap.php';
2922

3023
/**
3124
* Example cache implementation.
@@ -81,10 +74,6 @@ public function setCached($url, $content)
8174
}
8275
}
8376

84-
// Load the api key.
85-
$ini = parse_ini_file('ApiKey.ini');
86-
$myApiKey = $ini['api_key'];
87-
8877
// Language of data (try your own language here!):
8978
$lang = 'de';
9079

Examples/CurrentWeather.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,7 @@
1717
use Cmfcmf\OpenWeatherMap;
1818
use Cmfcmf\OpenWeatherMap\Exception as OWMException;
1919

20-
if (file_exists('../vendor/autoload.php')) {
21-
// Library is not part of a project. "composer install" was executed directly on this library's composer file.
22-
require '../vendor/autoload.php';
23-
} else {
24-
// Library is part of a project.
25-
/** @noinspection PhpIncludeInspection */
26-
require '../../../autoload.php';
27-
}
28-
29-
// Load the api key.
30-
$ini = parse_ini_file('ApiKey.ini');
31-
$myApiKey = $ini['api_key'];
20+
require_once __DIR__ . '/bootstrap.php';
3221

3322
// Language of data (try your own language here!):
3423
$lang = 'de';

Examples/WeatherForecast.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,7 @@
1717

1818
use Cmfcmf\OpenWeatherMap;
1919

20-
if (file_exists('../vendor/autoload.php')) {
21-
// Library is not part of a project. "composer install" was executed directly on this library's composer file.
22-
require('../vendor/autoload.php');
23-
} else {
24-
// Library is part of a project.
25-
/** @noinspection PhpIncludeInspection */
26-
require('../../../autoload.php');
27-
}
28-
29-
// Load the api key.
30-
$ini = parse_ini_file('ApiKey.ini');
31-
$myApiKey = $ini['api_key'];
20+
require_once __DIR__ . '/bootstrap.php';
3221

3322
// Language of data (try your own language here!):
3423
$lang = 'de';

Examples/WeatherHistory.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,7 @@
1616
*/
1717
use Cmfcmf\OpenWeatherMap;
1818

19-
if (file_exists('../vendor/autoload.php')) {
20-
// Library is not part of a project. "composer install" was executed directly on this library's composer file.
21-
require '../vendor/autoload.php';
22-
} else {
23-
// Library is part of a project.
24-
/** @noinspection PhpIncludeInspection */
25-
require '../../../autoload.php';
26-
}
27-
28-
// Load the api key.
29-
$ini = parse_ini_file('ApiKey.ini');
30-
$myApiKey = $ini['api_key'];
19+
require_once __DIR__ . '/bootstrap.php';
3120

3221
// Language of data (try your own language here!):
3322
$lang = 'en';

Examples/bootstrap.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
call_user_func(function () {
4+
if (!is_file($autoloadFile = __DIR__ . '/../vendor/autoload.php')) {
5+
throw new \RuntimeException('Did not find vendor/autoload.php. Did you run "composer install --dev"?');
6+
}
7+
8+
/** @noinspection PhpIncludeInspection */
9+
require_once $autoloadFile;
10+
11+
ini_set('date.timezone', 'Europe/Berlin');
12+
});
13+
14+
15+
// Load the api key.
16+
$ini = parse_ini_file('ApiKey.ini');
17+
$myApiKey = $ini['api_key'];

0 commit comments

Comments
 (0)