Skip to content

Commit 2aba5f3

Browse files
authored
Next steps to version 1 (#176)
* Complete Redesign * Add examples. * Next step to stable version * Update README and composer. * Write tests, move autoloiad correct.
1 parent d22a828 commit 2aba5f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+285
-1382
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
index.php
2-
tools
3-
logs
42
config.json
5-
.idea
3+
.idea
4+
composer.lock
5+
vendor

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 0.4.0
2+
- Complete ReDesign.
3+
14
# 0.2.0 (15.08.2016)
25

36
## Enhancements
@@ -11,7 +14,7 @@
1114

1215
## Bugfixes
1316
- #122 Move InformationTrait file.
14-
- #143 Delete InputValidator::isRESTCommand function.
17+
- #143 Delete ::isRESTCommand function.
1518
- #156 Fix using other shop locale.
1619

1720
## Features

README.md

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,44 @@
22

33
This is the PHP REST SDK to easily connect to an ePages shop.
44
You can use it as a developer to develop apps for ePages.
5-
Just sign up for the [ePages Developer Program](http://www.epages.cloud/developer/) and create a free developer test shop.
5+
Just sign up for the [ePages Developer Program](https://developer.epages.com/) and create a free developer test shop.
66

77
## Requirements
88

99
To use this SDK, you'll need:
1010

11-
* at least **PHP 5.5**
11+
* at least **PHP 7.0**
1212

1313
All dependencies comes automatically with the client and could be updated via composer.
1414

15-
## Installation
15+
## Installation via composer
1616

17-
### Via composer
18-
Its recommended to get the client via **Composer**.
17+
Its easy to get the client via **Composer**.
1918
Just search for [epages/rest-sdk](https://packagist.org/packages/epages/rest-sdk) and put this to you composer.yml file:
2019

2120
```php
2221
{
2322
"require": {
24-
"php": ">=5.4.0",
2523
"epages/rest-sdk": ">=0.2"
2624
}
2725
}
2826
```
2927

30-
### Direct download
31-
To use the client directly without getting composer just download the **.phar** archive and include it.
32-
33-
```
34-
wget https://raw.githubusercontent.com/ePages-de/epages-rest-php/master/build/epages-rest-php.phar -O epages-rest-php.phar
35-
```
36-
37-
It is also possible to download the PHP file archive manually.
38-
Check for the latest **.phar** release in the [releases area](https://github.com/ePages-de/epages-rest-php/releases).
39-
40-
To use the SDK, you simply have to include it.
41-
**Warning:** It is not recommended to do this in live system!
42-
```php
43-
require_once("libraries/epages-rest-php.phar");
44-
```
45-
4628
## Configuration
4729
You can configure it with putting a **config.json** into you main directory.
4830
Just copy the **config.example.json** from GitHub or create a new one:
4931
```javascript
5032
{
51-
"logging":
52-
{
53-
"level": "NONE",
54-
"output": "SCREEN",
55-
"outputfile": null
33+
"Client": {
34+
"host": "www.some.host",
35+
"shop": "shopName",
36+
"isSSL": true,
37+
"userAgent": "UserAgent",
38+
"token": "TheTokenIfExists"
5639
},
57-
"formatting":
58-
{
59-
"format": "HTML"
40+
"Logger": {
41+
"level": "ERROR",
42+
"output": "SCREEN"
6043
}
6144
}
6245
```
@@ -115,24 +98,24 @@ $products = $productFilter->getProducts();
11598
// print the products
11699
foreach ($products as $product) {
117100

118-
echo "<h2>" . htmlentities($product->getName()) . "</h2>";
119-
echo "<p>";
120-
echo "<img style=\"float:left\" src=\"" . $product->getSmallImage()->getOriginURL() . "\"/>";
121-
echo "<strong>ProductID:</strong> " . $product->getID() . "<br/>";
122-
echo "<strong>Description:</strong> " . htmlentities($product->getDescription()) . "<br/><br/>";
123-
echo "<strong>This product is ";
124-
if (!$product->isForSale()) {
125-
echo "NOT ";
126-
}
127-
echo "for sale and is ";
128-
if ($product->isSpecialOffer()) {
129-
echo "<u>a</u> ";
130-
}
131-
else {
132-
echo "not a ";
133-
}
134-
echo "special offer.</strong>";
135-
echo "</p><hr style=\"clear:both\"/>";
101+
echo "<h2>" . htmlentities($product->getName()) . "</h2>";
102+
echo "<p>";
103+
echo "<img style=\"float:left\" src=\"" . $product->getSmallImage()->getOriginURL() . "\"/>";
104+
echo "<strong>ProductID:</strong> " . $product->getID() . "<br/>";
105+
echo "<strong>Description:</strong> " . htmlentities($product->getDescription()) . "<br/><br/>";
106+
echo "<strong>This product is ";
107+
if (!$product->isForSale()) {
108+
echo "NOT ";
109+
}
110+
echo "for sale and is ";
111+
if ($product->isSpecialOffer()) {
112+
echo "<u>a</u> ";
113+
}
114+
else {
115+
echo "not a ";
116+
}
117+
echo "special offer.</strong>";
118+
echo "</p><hr style=\"clear:both\"/>";
136119
}
137120
```
138121

circle.yml

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

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,11 @@
77
"license": "MIT",
88
"require": {
99
"php": ">=7.0"
10+
},
11+
"require-dev": {
12+
"phpunit/phpunit": "6.4.4"
13+
},
14+
"autoload": {
15+
"classmap": ["src/"]
1016
}
1117
}

config.example.json

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,13 @@
11
{
2-
"logging":
3-
{
4-
"level": "NOTIFICATION",
5-
"output": "SCREEN",
6-
"outputfile": null
2+
"Client": {
3+
"host": "www.some.host",
4+
"shop": "shopName",
5+
"isSSL": true,
6+
"userAgent": "UserAgent",
7+
"token": "TheTokenIfExists"
78
},
8-
"formatting":
9-
{
10-
"image":
11-
{
12-
"formatters": ["IMAGE", "NEWLINE"],
13-
"classes": ["testClass1", "testClass2"],
14-
"id": "testID",
15-
"attributes":
16-
{
17-
"testAttribute1": "testValue1",
18-
"testAttribute2": "testValue2"
19-
}
20-
},
21-
"bold":
22-
{
23-
"formatters": ["BOLD", "NEWLINE"],
24-
"classes": ["testClass1", "testClass2"],
25-
"id": "testID",
26-
"attributes":
27-
{
28-
"testAttribute1": "testValue1",
29-
"testAttribute2": "testValue2"
30-
}
31-
}
9+
"Logger": {
10+
"level": "ERROR",
11+
"output": "SCREEN"
3212
}
3313
}

examples/connectingSettings.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
*
1818
* This can throw a JSONDecodingException. If everything works correct this function will return the value true.
1919
*/
20-
Configuration::addConfigurationFromFile('/path/to/a/JSON/file');
20+
Configuration::addFromFile('/path/to/a/JSON/file');
2121

2222
/**
2323
* Solution 2.1: Define it via array.
2424
*
2525
* To connect to more different shops in one script call (e.g. having Crons) there is also the possibility to load
2626
* Configuration via array.
2727
*/
28-
Configuration::setConfiguration([
28+
Configuration::set([
2929
'Client' => [
3030
'host' => 'www.example.com',
3131
'shop' => 'MyCoolShop',
@@ -40,7 +40,7 @@
4040
*
4141
* There is also the possibility to only right a specific module with adding the Configuration with array.
4242
*/
43-
Configuration::setConfiguration(
43+
Configuration::set(
4444
[
4545
'host' => 'www.example.com',
4646
'shop' => 'MyCoolShop',
@@ -55,7 +55,7 @@
5555
* If you want to change some Client configuration, like host, but not change the other Client Configurations you can
5656
* extend the Configuration.
5757
*/
58-
Configuration::extendConfiguration(
58+
Configuration::extend(
5959
[
6060
'host' => 'www.example.org'
6161
],
@@ -67,5 +67,5 @@
6767
*
6868
* To delete the static Configuration settings just use the reset function.
6969
*/
70-
Configuration::resetConfiguration(); // Reset complete Configuration
71-
Configuration::resetConfiguration('Client'); // Only reset the Client configuration
70+
Configuration::reset(); // Reset complete Configuration
71+
Configuration::reset('Client'); // Only reset the Client configuration

examples/logMessages.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*
1717
* The Logger can be configured via JSON file or array.
1818
*/
19-
Configuration::addConfigurationFromFile('dir/and/filename.json'); // configure via JSON
20-
Configuration::setConfiguration(
19+
Configuration::addFromFile('dir/and/filename.json'); // configure via JSON
20+
Configuration::set(
2121
[
2222
'Logger' => [
2323
'level' => LogLevel::ERROR,

phpunit.xml

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,7 @@
1-
<phpunit bootstrap="src/Shop.class.php" colors="always">
2-
<testsuites>
3-
<testsuite name="RESTClient Test">
4-
<file>tests/util/RESTClientTest.php</file>
5-
</testsuite>
6-
<testsuite name="Shop Test">
7-
<file>tests/ShopTest.php</file>
8-
</testsuite>
9-
<testsuite name="InputValidator Test">
10-
<file>tests/util/InputValidatorTest.php</file>
11-
</testsuite>
12-
<testsuite name="Contact Information Test">
13-
<file>tests/shopobjects/information/ContactInformationTest.php</file>
14-
</testsuite>
15-
<testsuite name="Privacy Policy Information Test">
16-
<file>tests/shopobjects/information/PrivacyPolicyInformationTest.php</file>
17-
</testsuite>
18-
<testsuite name="Right Of Withdrawal Information Test">
19-
<file>tests/shopobjects/information/RightOfWithdrawalInformationTest.php</file>
20-
</testsuite>
21-
<testsuite name="Shipping Information Test">
22-
<file>tests/shopobjects/information/ShippingInformationTest.php</file>
23-
</testsuite>
24-
<testsuite name="Terms And Condition Information Test">
25-
<file>tests/shopobjects/information/TermsAndConditionInformationTest.php</file>
26-
</testsuite>
27-
<testsuite name="Address Test">
28-
<file>tests/shopobjects/address/AddressTest.php</file>
29-
</testsuite>
30-
<testsuite name="Date Test">
31-
<file>tests/shopobjects/date/DateTest.php</file>
32-
</testsuite>
33-
<testsuite name="Payment Method Test">
34-
<file>tests/shopobjects/method/PaymentMethodTest.php</file>
35-
</testsuite>
36-
<testsuite name="Shipping Method Test">
37-
<file>tests/shopobjects/method/ShippingMethodTest.php</file>
38-
</testsuite>
39-
<testsuite name="Shipping Method Test">
40-
<file>tests/shopobjects/order/OrderTest.php</file>
41-
</testsuite>
42-
</testsuites>
43-
<groups>
44-
<include>
45-
<group>utility</group>
46-
<group>shopobjects</group>
47-
</include>
48-
</groups>
1+
<phpunit bootstrap="vendor/autoload.php" colors="always">
2+
<testsuites>
3+
<testsuite name="Configuration Test">
4+
<file>tests/EpSDKTest/Configuration/ConfigurationTest.php</file>
5+
</testsuite>
6+
</testsuites>
497
</phpunit>

src/EpSDK/Configuration/Configuration.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace EpSDK\Configuration;
35

46
use EpSDK\Exception\JSONDecodingException;
@@ -28,7 +30,7 @@ class Configuration
2830
* @throws JSONDecodingException Thrown if the file cannot be found or is no valid JSON.
2931
* @since 0.4.0
3032
*/
31-
public static function addConfigurationFromFile(string $pathToFile): bool
33+
public static function addFromFile(string $pathToFile): bool
3234
{
3335
$configurationArray = \json_decode(\file_get_contents($pathToFile), true);
3436
if (null === $configurationArray) {
@@ -37,7 +39,7 @@ public static function addConfigurationFromFile(string $pathToFile): bool
3739
}
3840
/** @var array $configurationArray */
3941
foreach ($configurationArray as $module => $configuration) {
40-
self::extendConfiguration($configuration, $module);
42+
self::extend($configuration, $module);
4143
}
4244
return true;
4345
}
@@ -50,12 +52,12 @@ public static function addConfigurationFromFile(string $pathToFile): bool
5052
* @return bool
5153
* @since 0.4.0
5254
*/
53-
public static function extendConfiguration(array $configuration, string $module): bool
55+
public static function extend(array $configuration, string $module): bool
5456
{
5557
if (isset(self::$configuration[$module])) {
5658
self::$configuration[$module] = \array_merge(self::$configuration[$module], $configuration);
5759
} else {
58-
self::setConfiguration($configuration, $module);
60+
self::set($configuration, $module);
5961
}
6062
return true;
6163
}
@@ -67,12 +69,11 @@ public static function extendConfiguration(array $configuration, string $module)
6769
* @return array
6870
* @since 0.4.0
6971
*/
70-
public static function getConfiguration(string $module = null): array
72+
public static function get(string $module = null): array
7173
{
72-
if (null === $module) {
73-
return self::$configuration;
74-
}
75-
return self::$configuration[$module] ?? [];
74+
return null === $module
75+
? self::$configuration
76+
: self::$configuration[$module] ?? [];
7677
}
7778

7879
/**
@@ -102,7 +103,7 @@ public static function saveToFile(string $fileName, string $module = null): bool
102103
* @return bool
103104
* @since 0.4.0
104105
*/
105-
public static function setConfiguration(array $configuration, string $module = null): bool
106+
public static function set(array $configuration, string $module = null): bool
106107
{
107108
if (null === $module) {
108109
self::$configuration = $configuration;
@@ -115,10 +116,11 @@ public static function setConfiguration(array $configuration, string $module = n
115116
/**
116117
* Reset the configuration.
117118
*
119+
* @param string $module
118120
* @return bool
119121
* @since 0.4.0
120122
*/
121-
public static function resetConfiguration(string $module = null): bool
123+
public static function reset(string $module = null): bool
122124
{
123125
if (null !== $module) {
124126
unset(self::$configuration[$module]);

0 commit comments

Comments
 (0)