Skip to content
This repository was archived by the owner on Oct 26, 2024. It is now read-only.

Commit 3efe263

Browse files
committed
Merge branch 'master' of github.com:maschmann/php-utilities
2 parents 5564dfc + cfc3004 commit 3efe263

File tree

5 files changed

+70
-16
lines changed

5 files changed

+70
-16
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,31 @@ php-utilities
33
[![Build Status](https://travis-ci.org/maschmann/php-utilities.png?branch=master)](https://travis-ci.org/maschmann/php-utilities)
44
[![phpci build status](http://phpci.br0ken.de/build-status/image/9)](http://phpci.br0ken.de)
55

6-
php utilities like data container, collection object, timer, ...
6+
## About
7+
This library is all about helping with the common little problems like having a type of object to inherit from with an internal data storage to turn to a json or array, ...
8+
9+
## Usage
10+
A lot of examples on how to use the classes can be found in the UnitTests. The whole collection is extensively tested and therefore quite stable.
11+
Feel free to contribute, suggest changes or help make it better.
12+
13+
## Contents
14+
You'll get following groups of classes which are interdependent
15+
16+
### Data
17+
This part consists of two distinct classes:
18+
* Data is a data store where you can easily store and retrieve data.
19+
* DataCollection ist a container to house items like objects, iterable.
20+
21+
### Config
22+
Here you get a static factory which is able to produce three types of configuration objects, based on Data class. All config objects take yaml files as source and provide easy access via get/set methods. See UnitTests for examples.
23+
Available types are:
24+
* ConfigDefault - basic config object, stores the yaml content "as is", provides get/set.
25+
* ConfigEnv - provides the possibility to get an environment-merged config. Based on the currently provided env, you'll have e.g. prod -> dev merged, with prod node as a master.
26+
* ConfigTimer is a specialised for of config to provide pre-generated DateTime objects for the Timer class.
27+
28+
### Timer
29+
Provides functionality to check if there's a current holiday, has configurable "timers" to check uf e.g. your hotline should be available etc.
30+
Extensive examples can be found within both, the TestData and UnitTests :-)
31+
32+
### Test
33+
TestData is just a helper for providing configurations for either Config and Timer. Have a look for YAML config examples.

src/Asm/Config/ConfigTimer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function setConfig($file)
8989
foreach ($timers as $timerSubKey => $params) {
9090

9191
foreach ($params as $paramKey => $paramValue) {
92-
$config[$timerKey][$timerSubKey][$paramKey] = array(
92+
$config[$timerKey][$timerSubKey] = array(
9393
new \DateTime($paramValue),
9494
new \DateTime($paramValue . ' 23:59:59'),
9595
);

src/Asm/Test/TestData.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,19 @@ public static function getYamlTimerConfigFile()
6262
example_timer_config_3:
6363
day: [ monday, tuesday, wednesday, thursday ] # works weekdays 00:00:00 - 23:59:59
6464
65+
example_timer_config_3.1:
66+
day: [ monday, tuesday, wednesday, thursday, friday, saturday, sunday ]
67+
6568
example_timer_config_4:
6669
day: [ monday ] # works only mondays
6770
time:
6871
- [ "01:05:00", "17:00:00" ] # from 01:05:00 to 17:00:00
6972
73+
example_timer_config_4.1:
74+
day: [ monday, tuesday, wednesday, thursday, friday, saturday, sunday ]
75+
time:
76+
- [ "01:05:00", "17:00:00" ] # from 01:05:00 to 17:00:00
77+
7078
example_timer_config_5:
7179
time:
7280
- [ "01:05:00", "17:00:00" ] # from 01:05:00 to 17:00:00
@@ -75,15 +83,24 @@ public static function getYamlTimerConfigFile()
7583
holiday:
7684
use_gerneral: true # if false, uses separate holidays conf
7785
additional: [ sub, 1 ] # add or subract n days to holiday to create range
78-
interval:
79-
- [ "16:00:00", "16:00:00" ] # start and end time
86+
87+
example_timer_config_7:
88+
holiday:
89+
use_gerneral: true # if false, uses separate holidays conf
90+
additional: [ sub, 1 ] # add or subract n days to holiday to create range
91+
interval: [ "16:00:00", "16:00:00" ] # start and end time
92+
93+
example_timer_config_7.1:
94+
holiday:
95+
use_gerneral: true
96+
additional: [ add, 1 ]
97+
interval: [ "16:00:00", "16:00:00" ] # start and end time
8098
8199
general_shipping_promise:
82100
holiday:
83101
use_general: true
84102
additional: [ sub, 1 ] # add or subract n days to holiday to create range
85-
interval:
86-
- [ "16:00:00", "16:00:00" ] # start and end time
103+
interval: [ "16:00:00", "16:00:00" ] # start and end time
87104
day: [ monday, tuesday, wednesday, thursday, friday, sunday ]
88105
89106
shipping_promise_sunday:

src/Asm/Tests/Timer/TimerTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,22 @@ public function testConstruct()
5050
* @covers \Asm\Timer\Timer::checkDays
5151
* @covers \Asm\Timer\Timer::checkTime
5252
* @covers \Asm\Timer\Timer::checkHoliday
53+
* @covers \Asm\Timer\Timer::flush
5354
* @param Timer $timer
5455
*/
5556
public function testIsTimerActive(Timer $timer)
5657
{
5758
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_1')));
5859
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_2')));
5960
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_3')));
61+
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_3.1')));
6062
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_4')));
63+
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_4.1')));
6164
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_5')));
62-
//$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_6')));
63-
//$this->assertTrue(is_bool($timer->isTimerActive('general_shipping_promise')));
65+
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_6')));
66+
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_7')));
67+
$this->assertTrue(is_bool($timer->isTimerActive('example_timer_config_7.1')));
68+
$this->assertTrue(is_bool($timer->isTimerActive('general_shipping_promise')));
6469
}
6570

6671
/**
@@ -71,8 +76,8 @@ public function testIsTimerActive(Timer $timer)
7176
*/
7277
public function testIsHoliday(Timer $timer)
7378
{
74-
$this->assertFalse($timer->isHoliday('2014-03-03 00:00:00'));
75-
$this->assertTrue($timer->isHoliday('2014-12-24 12:30:01'));
76-
$this->assertTrue(is_bool($timer->isHoliday()));
79+
$this->assertFalse($timer->isHoliday('2014-03-03 00:00:00'), 'failed to check non-holiday date');
80+
$this->assertTrue($timer->isHoliday('2014-12-24 12:30:01'), 'failed to validate christmas');
81+
$this->assertTrue(is_bool($timer->isHoliday()), 'failed to validate bool return');
7782
}
7883
}

src/Asm/Timer/Timer.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public function isTimerActive($type)
8080
$return = $this->checkDate();
8181
}
8282

83+
$this->flush();
8384
return $return;
8485
}
8586

@@ -105,6 +106,15 @@ public function getHoliday()
105106
return $this->holiday;
106107
}
107108

109+
/**
110+
* clear current configuration
111+
*/
112+
public function flush()
113+
{
114+
$this->currentConf = array();
115+
$this->holiday = null;
116+
}
117+
108118
/**
109119
* date checks on config
110120
*
@@ -223,11 +233,6 @@ private function checkIntervals(array $intervals = array())
223233
}
224234

225235
foreach ($intervals as $interval) {
226-
// this means: just some time
227-
if (!is_a($interval[0], 'DateTime') || !is_a($interval[1], 'DateTime')) {
228-
$interval = $this->checkTime($intervals);
229-
}
230-
231236
$intervalStart = $today->diff($interval[0]);
232237
$intervalEnd = $today->diff($interval[1]);
233238

0 commit comments

Comments
 (0)