Skip to content

Commit 37544f6

Browse files
author
Edwin Westerhoud
committed
Replaces php ini file with settings class as some environments have parse_ini_file disabled.
1 parent c9d879e commit 37544f6

9 files changed

Lines changed: 19 additions & 18 deletions

src/class-tiny-compress-curl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class Tiny_Compress_Curl extends Tiny_Compress {
2222
protected function shrink_options($input) {
2323
return array(
24-
CURLOPT_URL => $this->config['api']['url'],
24+
CURLOPT_URL => Tiny_Config::URL,
2525
CURLOPT_USERPWD => 'api:' . $this->api_key,
2626
CURLOPT_POSTFIELDS => $input,
2727
CURLOPT_BINARYTRANSFER => true,

src/class-tiny-compress-fopen.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function shrink_options($input) {
3939

4040
protected function shrink($input) {
4141
$context = stream_context_create($this->shrink_options($input));
42-
$request = @fopen($this->config['api']['url'], 'r', false, $context);
42+
$request = @fopen(Tiny_Config::URL, 'r', false, $context);
4343

4444
if (!$request) {
4545
return array(array(

src/class-tiny-compress.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,23 @@
2121
abstract class Tiny_Compress {
2222
protected $api_key;
2323
protected $count_callback;
24-
protected $config;
2524

2625
public static function get_ca_file() {
2726
return dirname(__FILE__) . '/cacert.pem';
2827
}
2928

30-
public static function get_config() {
31-
return parse_ini_file(dirname(__FILE__) . '/config/tinypng-api.ini', true);
32-
}
33-
3429
public static function get_compressor($api_key, $count_callback=null) {
3530
if (Tiny_PHP::is_curl_available()) {
36-
return new Tiny_Compress_Curl($api_key, $count_callback, self::get_config());
31+
return new Tiny_Compress_Curl($api_key, $count_callback);
3732
} elseif (Tiny_PHP::is_fopen_available()) {
38-
return new Tiny_Compress_Fopen($api_key, $count_callback, self::get_config());
33+
return new Tiny_Compress_Fopen($api_key, $count_callback);
3934
}
4035
throw new Tiny_Exception('No HTTP client is available (cURL or fopen)', 'NoHttpClient');
4136
}
4237

43-
protected function __construct($api_key, $count_callback, $config) {
38+
protected function __construct($api_key, $count_callback) {
4439
$this->api_key = $api_key;
4540
$this->count_callback = $count_callback;
46-
$this->config = $config;
4741
}
4842

4943
abstract protected function shrink($input);

src/config/tiny-config.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
class Tiny_Config {
4+
const URL = 'https://api.tinypng.com/shrink';
5+
}

src/config/tinypng-api.ini

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/fixtures/tiny-config.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
class Tiny_Config {
4+
const URL = 'http://webservice/shrink';
5+
}

test/fixtures/tinypng-api.ini

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/helpers/setup.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ function backup_wordpress_site() {
5050

5151
function set_test_webservice_url() {
5252
$config_dir = dirname(__FILE__) . '/../../src/config';
53-
shell_exec('mv ' . $config_dir . '/tinypng-api.ini ' . $config_dir . '/tinypng-api.ini.bak');
54-
shell_exec('cp ' . dirname(__FILE__) . '/../fixtures/tinypng-api.ini ' . $config_dir . '/tinypng-api.ini');
53+
shell_exec('mv ' . $config_dir . '/tiny-config.php ' . $config_dir . '/tiny-config.php.bak');
54+
shell_exec('cp ' . dirname(__FILE__) . '/../fixtures/tiny-config.php ' . $config_dir . '/tiny-config.php');
5555
}
5656

5757
function restore_webservice_url() {
5858
$config_dir = dirname(__FILE__) . '/../../src/config';
59-
shell_exec('test -f ' . $config_dir . '/tinypng-api.ini.bak && mv ' . $config_dir . '/tinypng-api.ini.bak ' . $config_dir . '/tinypng-api.ini');
59+
shell_exec('test -f ' . $config_dir . '/tiny-config.php.bak && mv ' . $config_dir . '/tiny-config.php.bak ' . $config_dir . '/tiny-config.php');
6060
}
6161

6262
function set_siteurl($site_url) {

tiny-compress-images.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111

12+
require (dirname(__FILE__) . '/src/config/tiny-config.php');
1213
require (dirname(__FILE__) . '/src/class-tiny-php.php');
1314
require (dirname(__FILE__) . '/src/class-tiny-wp-base.php');
1415
require (dirname(__FILE__) . '/src/class-tiny-exception.php');

0 commit comments

Comments
 (0)