diff --git a/.gitignore b/.gitignore
index 4046c1b..804a659 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
.env
.idea
+.idea/*
coverage.xml
vendor
\ No newline at end of file
diff --git a/.idea/MalaysiaHoliday.iml b/.idea/MalaysiaHoliday.iml
deleted file mode 100644
index 81080d8..0000000
--- a/.idea/MalaysiaHoliday.iml
+++ /dev/null
@@ -1,49 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
- { - "status": true, - "regional": "Selangor", - "year": "2018", - "data": [ +{ + "status":true, + "data":[ + { + "regional":"Selangor", + "collection":[ { - "day": "Monday", - "date": "2018-01-01", - "date_formatted": "01 January 2018", - "month": "January", - "name": "New Year's Day", - "description": "All regions except Johor, Kedah, Kelantan, Perlis, Terengganu", - "is_holiday": true, - "type": "Regional Holiday" - }, + "year":2019, + "data":[ + { + "day":"Tuesday", + "date":"2019-01-01", + "date_formatted":"01 January 2019", + "month":"January", + "name":"New Year's Day", + "description":"Regional Holiday", + "is_holiday":true, + "type":"Regional Holiday", + "type_id":4 + }, + { + "day":"Monday", + "date":"2019-01-21", + "date_formatted":"21 January 2019", + "month":"January", + "name":"Thaipusam", + "description":"Regional Holiday", + "is_holiday":true, + "type":"Regional Holiday", + "type_id":4 + } + ] + } + ] + }, + { + "regional":"Johor", + "collection":[ { - "day": "Wednesday", - "date": "2018-01-31", - "date_formatted": "31 January 2018", - "month": "January", - "name": "Thaipusam", - "description": "Hindu festival", - "is_holiday": true, - "type": "Regional Holiday" + "year":2019, + "data":[ + { + "day":"Monday", + "date":"2019-01-21", + "date_formatted":"21 January 2019", + "month":"January", + "name":"Thaipusam", + "description":"Regional Holiday", + "is_holiday":true, + "type":"Regional Holiday", + "type_id":4 + } + ] } - ], - "sources": null, - "developer": { - "name": "Hafiq", - "email": "hafiqiqmal93@gmail.com", - "github": "https://github.com/afiqiqmal" - } - } + ] + } + ], + "developer":{ + "name":"Hafiq", + "email":"hafiqiqmal93@gmail.com", + "github":"https://github.com/afiqiqmal" + } +}### Source diff --git a/composer.json b/composer.json index ed0f62b..b6ae801 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": ">=5.6", + "php": ">=7.0", "fabpot/goutte": "^3.2" }, "require-dev": { diff --git a/composer.lock b/composer.lock index f1f474c..fcda838 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "098ce911470990d96174d9b171323955", + "content-hash": "71fe02fd36135937be768c35d4a152ca", "packages": [ { "name": "fabpot/goutte", @@ -179,32 +179,37 @@ }, { "name": "guzzlehttp/psr7", - "version": "1.4.2", + "version": "1.6.1", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c" + "reference": "239400de7a173fe9901b9ac7c06497751f00727a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c", - "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/239400de7a173fe9901b9ac7c06497751f00727a", + "reference": "239400de7a173fe9901b9ac7c06497751f00727a", "shasum": "" }, "require": { "php": ">=5.4.0", - "psr/http-message": "~1.0" + "psr/http-message": "~1.0", + "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" }, "provide": { "psr/http-message-implementation": "1.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "ext-zlib": "*", + "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" + }, + "suggest": { + "zendframework/zend-httphandlerrunner": "Emit PSR-7 responses" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "1.6-dev" } }, "autoload": { @@ -234,13 +239,14 @@ "keywords": [ "http", "message", + "psr-7", "request", "response", "stream", "uri", "url" ], - "time": "2017-03-20T17:10:46+00:00" + "time": "2019-07-01T23:21:34+00:00" }, { "name": "psr/http-message", @@ -292,18 +298,58 @@ ], "time": "2016-08-06T14:39:51+00:00" }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "time": "2019-03-08T08:55:37+00:00" + }, { "name": "symfony/browser-kit", - "version": "v4.1.3", + "version": "v4.3.4", "source": { "type": "git", "url": "https://github.com/symfony/browser-kit.git", - "reference": "c55fe9257003b2d95c0211b3f6941e8dfd26dffd" + "reference": "9e5dddb637b13db82e35695a8603fe6e118cc119" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/browser-kit/zipball/c55fe9257003b2d95c0211b3f6941e8dfd26dffd", - "reference": "c55fe9257003b2d95c0211b3f6941e8dfd26dffd", + "url": "https://api.github.com/repos/symfony/browser-kit/zipball/9e5dddb637b13db82e35695a8603fe6e118cc119", + "reference": "9e5dddb637b13db82e35695a8603fe6e118cc119", "shasum": "" }, "require": { @@ -312,6 +358,8 @@ }, "require-dev": { "symfony/css-selector": "~3.4|~4.0", + "symfony/http-client": "^4.3", + "symfony/mime": "^4.3", "symfony/process": "~3.4|~4.0" }, "suggest": { @@ -320,7 +368,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.1-dev" + "dev-master": "4.3-dev" } }, "autoload": { @@ -347,20 +395,20 @@ ], "description": "Symfony BrowserKit Component", "homepage": "https://symfony.com", - "time": "2018-07-26T09:10:45+00:00" + "time": "2019-08-26T08:26:39+00:00" }, { "name": "symfony/css-selector", - "version": "v4.1.3", + "version": "v4.3.4", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", - "reference": "2a4df7618f869b456f9096781e78c57b509d76c7" + "reference": "c6e5e2a00db768c92c3ae131532af4e1acc7bd03" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/css-selector/zipball/2a4df7618f869b456f9096781e78c57b509d76c7", - "reference": "2a4df7618f869b456f9096781e78c57b509d76c7", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/c6e5e2a00db768c92c3ae131532af4e1acc7bd03", + "reference": "c6e5e2a00db768c92c3ae131532af4e1acc7bd03", "shasum": "" }, "require": { @@ -369,7 +417,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.1-dev" + "dev-master": "4.3-dev" } }, "autoload": { @@ -385,14 +433,14 @@ "MIT" ], "authors": [ - { - "name": "Jean-François Simon", - "email": "jeanfrancois.simon@sensiolabs.com" - }, { "name": "Fabien Potencier", "email": "fabien@symfony.com" }, + { + "name": "Jean-François Simon", + "email": "jeanfrancois.simon@sensiolabs.com" + }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" @@ -400,20 +448,20 @@ ], "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", - "time": "2018-07-26T09:10:45+00:00" + "time": "2019-08-20T14:07:54+00:00" }, { "name": "symfony/dom-crawler", - "version": "v4.1.3", + "version": "v4.3.4", "source": { "type": "git", "url": "https://github.com/symfony/dom-crawler.git", - "reference": "1c4519d257e652404c3aa550207ccd8ada66b38e" + "reference": "cc686552948d627528c0e2e759186dff67c2610e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/1c4519d257e652404c3aa550207ccd8ada66b38e", - "reference": "1c4519d257e652404c3aa550207ccd8ada66b38e", + "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/cc686552948d627528c0e2e759186dff67c2610e", + "reference": "cc686552948d627528c0e2e759186dff67c2610e", "shasum": "" }, "require": { @@ -421,7 +469,11 @@ "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-mbstring": "~1.0" }, + "conflict": { + "masterminds/html5": "<2.6" + }, "require-dev": { + "masterminds/html5": "^2.6", "symfony/css-selector": "~3.4|~4.0" }, "suggest": { @@ -430,7 +482,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.1-dev" + "dev-master": "4.3-dev" } }, "autoload": { @@ -457,20 +509,20 @@ ], "description": "Symfony DomCrawler Component", "homepage": "https://symfony.com", - "time": "2018-07-26T11:00:49+00:00" + "time": "2019-08-26T08:26:39+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.9.0", + "version": "v1.12.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "e3d826245268269cd66f8326bd8bc066687b4a19" + "reference": "550ebaac289296ce228a706d0867afc34687e3f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19", - "reference": "e3d826245268269cd66f8326bd8bc066687b4a19", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/550ebaac289296ce228a706d0867afc34687e3f4", + "reference": "550ebaac289296ce228a706d0867afc34687e3f4", "shasum": "" }, "require": { @@ -482,7 +534,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.9-dev" + "dev-master": "1.12-dev" } }, "autoload": { @@ -498,13 +550,13 @@ "MIT" ], "authors": [ - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - }, { "name": "Gert de Pagter", "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], "description": "Symfony polyfill for ctype functions", @@ -515,20 +567,20 @@ "polyfill", "portable" ], - "time": "2018-08-06T14:22:27+00:00" + "time": "2019-08-06T08:03:45+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.11.0", + "version": "v1.12.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "fe5e94c604826c35a32fa832f35bd036b6799609" + "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fe5e94c604826c35a32fa832f35bd036b6799609", - "reference": "fe5e94c604826c35a32fa832f35bd036b6799609", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/b42a2f66e8f1b15ccf25652c3424265923eb4f17", + "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17", "shasum": "" }, "require": { @@ -540,7 +592,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.11-dev" + "dev-master": "1.12-dev" } }, "autoload": { @@ -574,33 +626,35 @@ "portable", "shim" ], - "time": "2019-02-06T07:57:58+00:00" + "time": "2019-08-06T08:03:45+00:00" } ], "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.1.0", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda" + "reference": "a2c590166b2133a4633738648b6b064edae0814a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", - "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/a2c590166b2133a4633738648b6b064edae0814a", + "reference": "a2c590166b2133a4633738648b6b064edae0814a", "shasum": "" }, "require": { "php": "^7.1" }, "require-dev": { - "athletic/athletic": "~0.1.8", + "doctrine/coding-standard": "^6.0", "ext-pdo": "*", "ext-phar": "*", - "phpunit/phpunit": "^6.2.3", - "squizlabs/php_codesniffer": "^3.0.2" + "phpbench/phpbench": "^0.13", + "phpstan/phpstan-phpunit": "^0.11", + "phpstan/phpstan-shim": "^0.11", + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { @@ -625,25 +679,25 @@ } ], "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", - "homepage": "https://github.com/doctrine/instantiator", + "homepage": "https://www.doctrine-project.org/projects/instantiator.html", "keywords": [ "constructor", "instantiate" ], - "time": "2017-07-22T11:58:36+00:00" + "time": "2019-03-17T17:37:11+00:00" }, { "name": "myclabs/deep-copy", - "version": "1.8.1", + "version": "1.9.3", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8" + "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", - "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/007c053ae6f31bba39dfa19a7726f56e9763bbea", + "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea", "shasum": "" }, "require": { @@ -678,39 +732,37 @@ "object", "object graph" ], - "time": "2018-06-11T23:09:50+00:00" + "time": "2019-08-09T12:45:53+00:00" }, { "name": "phpdocumentor/reflection-common", - "version": "1.0.1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6" + "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", - "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/63a995caa1ca9e5590304cd845c15ad6d482a62a", + "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a", "shasum": "" }, "require": { - "php": ">=5.5" + "php": ">=7.1" }, "require-dev": { - "phpunit/phpunit": "^4.6" + "phpunit/phpunit": "~6" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src" - ] + "phpDocumentor\\Reflection\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -732,30 +784,30 @@ "reflection", "static analysis" ], - "time": "2017-09-11T18:02:19+00:00" + "time": "2018-08-07T13:53:10+00:00" }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.3.0", + "version": "4.3.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "94fd0001232e47129dd3504189fa1c7225010d08" + "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08", - "reference": "94fd0001232e47129dd3504189fa1c7225010d08", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/b83ff7cfcfee7827e1e78b637a5904fe6a96698e", + "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e", "shasum": "" }, "require": { "php": "^7.0", - "phpdocumentor/reflection-common": "^1.0.0", - "phpdocumentor/type-resolver": "^0.4.0", + "phpdocumentor/reflection-common": "^1.0.0 || ^2.0.0", + "phpdocumentor/type-resolver": "~0.4 || ^1.0.0", "webmozart/assert": "^1.0" }, "require-dev": { - "doctrine/instantiator": "~1.0.5", + "doctrine/instantiator": "^1.0.5", "mockery/mockery": "^1.0", "phpunit/phpunit": "^6.4" }, @@ -783,41 +835,40 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-11-30T07:14:17+00:00" + "time": "2019-09-12T14:27:41+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "0.4.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" + "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", + "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", "shasum": "" }, "require": { - "php": "^5.5 || ^7.0", - "phpdocumentor/reflection-common": "^1.0" + "php": "^7.1", + "phpdocumentor/reflection-common": "^2.0" }, "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^5.2||^4.8.24" + "ext-tokenizer": "^7.1", + "mockery/mockery": "~1", + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] + "phpDocumentor\\Reflection\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -830,20 +881,21 @@ "email": "me@mikevanriel.com" } ], - "time": "2017-07-14T14:27:02+00:00" + "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", + "time": "2019-08-22T18:11:29+00:00" }, { "name": "phpspec/prophecy", - "version": "1.8.0", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" + "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/1927e75f4ed19131ec9bcc3b002e07fb1173ee76", + "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76", "shasum": "" }, "require": { @@ -864,8 +916,8 @@ } }, "autoload": { - "psr-0": { - "Prophecy\\": "src/" + "psr-4": { + "Prophecy\\": "src/Prophecy" } }, "notification-url": "https://packagist.org/downloads/", @@ -893,7 +945,7 @@ "spy", "stub" ], - "time": "2018-08-05T17:53:17+00:00" + "time": "2019-06-13T12:50:23+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1801,16 +1853,16 @@ }, { "name": "symfony/yaml", - "version": "v4.1.3", + "version": "v4.3.4", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "46bc69aa91fc4ab78a96ce67873a6b0c148fd48c" + "reference": "5a0b7c32dc3ec56fd4abae8a4a71b0cf05013686" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/46bc69aa91fc4ab78a96ce67873a6b0c148fd48c", - "reference": "46bc69aa91fc4ab78a96ce67873a6b0c148fd48c", + "url": "https://api.github.com/repos/symfony/yaml/zipball/5a0b7c32dc3ec56fd4abae8a4a71b0cf05013686", + "reference": "5a0b7c32dc3ec56fd4abae8a4a71b0cf05013686", "shasum": "" }, "require": { @@ -1829,7 +1881,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.1-dev" + "dev-master": "4.3-dev" } }, "autoload": { @@ -1856,24 +1908,25 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2018-07-26T11:24:31+00:00" + "time": "2019-08-20T14:27:59+00:00" }, { "name": "vlucas/phpdotenv", - "version": "v2.5.1", + "version": "v2.6.1", "source": { "type": "git", "url": "https://github.com/vlucas/phpdotenv.git", - "reference": "8abb4f9aa89ddea9d52112c65bbe8d0125e2fa8e" + "reference": "2a7dcf7e3e02dc5e701004e51a6f304b713107d5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/8abb4f9aa89ddea9d52112c65bbe8d0125e2fa8e", - "reference": "8abb4f9aa89ddea9d52112c65bbe8d0125e2fa8e", + "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/2a7dcf7e3e02dc5e701004e51a6f304b713107d5", + "reference": "2a7dcf7e3e02dc5e701004e51a6f304b713107d5", "shasum": "" }, "require": { - "php": ">=5.3.9" + "php": ">=5.3.9", + "symfony/polyfill-ctype": "^1.9" }, "require-dev": { "phpunit/phpunit": "^4.8.35 || ^5.0" @@ -1881,7 +1934,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.5-dev" + "dev-master": "2.6-dev" } }, "autoload": { @@ -1906,28 +1959,28 @@ "env", "environment" ], - "time": "2018-07-29T20:33:41+00:00" + "time": "2019-01-29T11:11:52+00:00" }, { "name": "webmozart/assert", - "version": "1.3.0", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "0df1908962e7a3071564e857d86874dad1ef204a" + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a", - "reference": "0df1908962e7a3071564e857d86874dad1ef204a", + "url": "https://api.github.com/repos/webmozart/assert/zipball/88e6d84706d09a236046d686bbea96f07b3a34f4", + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": "^5.3.3 || ^7.0", + "symfony/polyfill-ctype": "^1.8" }, "require-dev": { - "phpunit/phpunit": "^4.6", - "sebastian/version": "^1.0.1" + "phpunit/phpunit": "^4.8.36 || ^7.5.13" }, "type": "library", "extra": { @@ -1956,7 +2009,7 @@ "check", "validate" ], - "time": "2018-01-29T19:49:41+00:00" + "time": "2019-08-24T08:43:50+00:00" } ], "aliases": [], @@ -1965,7 +2018,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.6" + "php": ">=7.0" }, "platform-dev": [] } diff --git a/example/index.php b/example/index.php index d391425..9380b66 100644 --- a/example/index.php +++ b/example/index.php @@ -12,8 +12,8 @@ $holiday = new Holiday; -$result = $holiday->getRegionHoliday(['Selangor', 'Malacca'])->get(); +$result = $holiday->getRegionHoliday(['Selangor', 'Johore'])->filterByMonth(1)->get(); //print_r($result); header('Content-Type: application/json'); -echo json_encode($result['data']['Selangor']); +echo json_encode($result); diff --git a/src/Holiday.php b/src/Holiday.php index 4755448..974b3b4 100644 --- a/src/Holiday.php +++ b/src/Holiday.php @@ -2,26 +2,57 @@ namespace afiqiqmal\MalaysiaHoliday; -use Carbon\Carbon; -use DateTime; +use afiqiqmal\MalaysiaHoliday\exception\RegionException; use Goutte\Client; use GuzzleHttp\Client as GuzzleClient; class Holiday { - private $base_url; - private $regional_path; + private $months_array = [ + 1 => 'January', + 2 => 'February', + 3 => 'March', + 4 => 'April', + 5 => 'May', + 6 => 'June', + 7 => 'July', + 8 => 'August', + 9 => 'September', + 10 => 'October', + 11 => 'November', + 12 => 'December' + ]; + + private $region_array = [ + 'Johor', + 'Kedah', + 'Kelantan', + 'Kuala Lumpur', + 'Labuan', + 'Malacca', + 'Negeri Sembilan', + 'Pahang', + 'Penang', + 'Perak', + 'Perlis', + 'Putrajaya', + 'Sarawak', + 'Selangor', + 'Terengganu' + ]; + private $base_url; private $client; - private $result; + + private $year; + private $region; private $month; private $groupByMonth = false; public function __construct() { - $this->base_url = "http://www.officeholidays.com/countries/malaysia"; - $this->regional_path = "/regional.php"; + $this->base_url = "https://www.officeholidays.com/countries/malaysia"; $this->client = new Client(); $guzzleClient = new GuzzleClient( @@ -42,15 +73,15 @@ public static function init() public function getAllRegionHoliday($year = null) { - $year = $year ? $year : date('Y'); - $this->result = $this->baseRequest(null, $year); + $this->region = null; + $this->year = $year; return $this; } public function getRegionHoliday($region, $year = null) { - $year = $year ? $year : date('Y'); - $this->result = $this->baseRequest($region, $year); + $this->region = $region; + $this->year = $year; return $this; } @@ -68,28 +99,49 @@ public function filterByMonth($month) public function get() { - if ($this->result['status']) { - $temp = []; + $result = $this->queryWeb($this->region, $this->year); + + if ($result['status']) { if ($this->month != null && $this->checkMonth($this->month)) { - foreach ($this->result['data'] as $key => $holiday) { - if (date('F', strtotime($holiday['date'])) == $this->month) { - $temp[] = $holiday; + foreach ($result['data'] as $key => $data) { //regional + foreach ($data['collection'] as $index => $collection) { //year + $temp = []; + foreach ($collection['data'] as $key2 => $holiday) { // holidays + $month = date('F', strtotime($holiday['date'])); + if (strtolower($month) == $this->getMonth($this->month)) { + $temp[] = $holiday; + } + } + + $result['data'][$key]['collection'][$index]['data'] = $temp; } } - $this->result['data'] = $temp; - - return $this->result; + return $result; } elseif ($this->groupByMonth) { - foreach ($this->result['data'] as $key => $holiday) { - $temp[date('F', strtotime($holiday['date']))][] = $holiday; + foreach ($result['data'] as $key => $data) { //regional + foreach ($data['collection'] as $index => $collection) { //year + $temp = []; + foreach ($collection['data'] as $key2 => $holiday) { // holidays + $month = date('F', strtotime($holiday['date'])); + $entry = array_search($month, array_column($temp, 'month')); + if ($entry === false) { + $temp[] = [ + 'month' => $month, + 'data' => [$holiday], + ]; + } else { + $temp[$entry]['data'][] = $holiday; + } + } + + $result['data'][$key]['collection'][$index]['data'] = $temp; + } } - $this->result['data'] = $temp; - - return $this->result; + return $result; } else { - return $this->result; + return $result; } } else { return [ @@ -99,62 +151,71 @@ public function get() } } - private function baseRequest($region, $year) - { - return $this->queryWeb($region, $year); - } - private function queryWeb($regional, $year) { - try { - $arrays = []; - $request_url = null; - $currentYear = ($year==null) ? date('Y') : $year; - if ($regional == null) { - $request_url = $this->base_url."/".$year.".php"; - $arrays = $this->trigger($regional, $currentYear); - } else { - if (is_array($regional)) { - foreach ($regional as $region) { - $arrays[$region] = $this->trigger($region, $currentYear); - } - } else { - $arrays = $this->trigger($regional, $currentYear); - } - } + $years = ($year == null) ? [date('Y')] : $year; + if (!is_array($years)) { + $years = [$year]; + } - return [ - 'status' => true, - 'regional' => ($regional == null) ? "all" : (is_array($regional) ? explode(",", $regional) : $regional), - 'year'=> $currentYear, - 'data' => $arrays, - 'sources' => $request_url, - 'developer' => [ - "name"=> "Hafiq", - "email"=> "hafiqiqmal93@gmail.com", - "github"=> "https://github.com/afiqiqmal" - ] - ]; + if (!is_array($regional)) { + $regional = [$regional]; + } - } catch (\Exception $e) { - return [ - 'status' => false, - 'message' => "Something went wrong or not exist yet" - ]; + $final = []; + $error_messages = []; + foreach ($regional as $region) { + $data = []; + try { + foreach ($years as $selectedYear) { + $data[] = [ + 'year' => (int)$selectedYear, + 'data' => $this->trigger($region, $selectedYear), + ]; + } + + $final[] = [ + 'regional' => $region ?? "Malaysia", + 'collection' => $data + ]; + } catch (RegionException $regionException) { + $error_messages[] = $regionException->getMessage(); + $final[] = [ + 'regional' => $region ?? "Malaysia", + 'collection' => [] + ]; + } } + + return [ + 'status' => true, + 'data' => $final ?? [], + 'error_messages' => $error_messages, + 'developer' => [ + "name" => "Hafiq", + "email" => "hafiqiqmal93@gmail.com", + "github" => "https://github.com/afiqiqmal" + ] + ]; } - private function trigger($region, $currentYear) { - $request_url = $this->base_url; + /** + * + * @param $region + * @param $currentYear + * @return array + * @throws RegionException + */ + private function trigger($region, $currentYear) + { if ($region) { if ($this->checkRegional($region)) { - $request_url = $request_url . $this->regional_path . "?list_year=$currentYear&list_region=$region"; + $request_url = $this->base_url."/".$region."/".$currentYear; } else { - return [ - 'status' => false, - 'message' => $region . " is not include in the regional state" - ]; + throw new RegionException($region . " is not include in the regional state"); } + } else { + $request_url = $this->base_url."/".$currentYear; } $arrays = array_values(array_filter($this->crawl($request_url, $currentYear))); @@ -165,44 +226,53 @@ private function trigger($region, $currentYear) { private function crawl($request_url, $currentYear) { $crawler = $this->client->request('GET', $request_url); - $result = $crawler->filter('.list-table tr')->each( + $result = $crawler->filter('.country-table tr')->each( function ($node) use ($currentYear) { if ($node->children()->nodeName() == 'td') { $temp['day'] = trim($node->children()->eq(0)->text()); - $date_str = strtok(trim($node->children()->eq(1)->extract('_text', 'class')[0]), "\n")." ".$currentYear; + $date_str = strtok(trim($node->children() + ->eq(1) + ->extract('_text', 'class')[0]), "\n")." ".$currentYear; if ($date_str == null || empty($date_str)) { return null; } - $date = date_create_from_format('F d Y', preg_replace("/[\n\r]/","", $date_str)); + $date = date_create_from_format('F d Y', preg_replace("/[\n\r]/", "", $date_str)); if (!$date) { //check another format - $date = date_create_from_format('Y-m-d', $node->children()->eq(1)->children()->text()); + $date = date_create_from_format('Y-m-d', $node->children()->eq(1)->children()->text()); } - $temp['date'] = date_format($date, 'Y-m-d'); $temp['date_formatted'] = date_format($date, 'd F Y'); $temp['month'] = date('F', strtotime($temp['date'])); $temp['name'] = trim($node->children()->eq(2)->text()); $temp['description'] = trim($node->children()->eq(3)->text()); $temp['is_holiday'] = true; - switch ($node->extract('class')[0]) { + switch (trim($node->extract('class')[0])) { case 'govt_holiday': $temp['type'] = "Government/Public Sector Holiday"; + $temp['type_id'] = 1; break; - case 'publicholiday': + case 'nap-past': + case 'nap': $temp['type'] = "Not a Public Holiday"; $temp['is_holiday'] = false; + $temp['type_id'] = 2; break; - case 'holiday': + case 'country-past': + case 'country': $temp['type'] = "National Holiday"; + $temp['type_id'] = 3; break; - case 'regional': + case 'region-past': + case 'region': $temp['type'] = "Regional Holiday"; + $temp['type_id'] = 4; break; default: $temp['type'] = "Unknown"; + $temp['type_id'] = 5; break; } @@ -216,24 +286,7 @@ function ($node) use ($currentYear) { private function checkRegional($regional) { - $arrays = array( - 'Johor', - 'Kedah', - 'Kelantan', - 'Kuala Lumpur', - 'Labuan', - 'Malacca', - 'Negeri Sembilan', - 'Pahang', - 'Penang', - 'Perak', - 'Perlis', - 'Putrajaya', - 'Sarawak', - 'Selangor', - 'Terengganu' - ); - if (in_array(strtolower($regional), array_map('strtolower', $arrays))) { + if (in_array(strtolower($regional), array_map('strtolower', $this->region_array))) { return true; } return false; @@ -241,24 +294,16 @@ private function checkRegional($regional) private function checkMonth($month) { - $arrays = array( - 'January', - 'February', - 'March', - 'April', - 'May', - 'June', - 'July', - 'August', - 'September', - 'October', - 'November', - 'December' - ); - if (in_array(strtolower($month), array_map('strtolower', $arrays))) { + if (in_array(strtolower($month), array_map('strtolower', array_values($this->months_array)))) { return true; } - return false; + + return isset($this->months_array[$month]); + } + + private function getMonth($month) + { + return strtolower($this->months_array[$month]) ?? strtolower($month); } } diff --git a/src/exception/RegionException.php b/src/exception/RegionException.php new file mode 100644 index 0000000..fca0876 --- /dev/null +++ b/src/exception/RegionException.php @@ -0,0 +1,12 @@ +getAllRegionHoliday()->get(); $this->assertTrue($response['status']); + $this->assertTrue($response['data'][0]['regional'] == 'Malaysia'); } /** * To test getting specific region holiday */ - function testGetSpecificRegionHoliday() + public function testGetSpecificRegionHoliday() { $holiday = new Holiday; $response = $holiday->getRegionHoliday('Selangor')->get(); $this->assertTrue($response['status']); + $this->assertTrue($response['data'][0]['regional'] == 'Selangor'); } /** * To test getting multiple regions holiday */ - function testGetMultipleRegionsHoliday() + public function testGetMultipleRegionsHoliday() { $holiday = new Holiday; $response = $holiday->getRegionHoliday(['Selangor', 'Malacca'])->get(); - $this->assertTrue(isset($response['data']['Selangor'])); - $this->assertTrue(isset($response['data']['Malacca'])); + $this->assertTrue($response['status']); + $this->assertTrue($response['data'][0]['regional'] == 'Selangor'); + $this->assertTrue($response['data'][1]['regional'] == 'Malacca'); + } + + /** + * To test getting multiple regions holiday + */ + public function testErrorMessage() + { + $holiday = new Holiday; + $response = $holiday->getRegionHoliday(['Selangor', 'Malaccaa'])->get(); + + $this->assertTrue($response['status']); + $this->assertTrue($response['data'][0]['regional'] == 'Selangor'); + + + $this->assertFalse($response['data'][1]['regional'] == 'Malacca'); + $this->assertTrue($response['data'][1]['collection'] == []); + + $this->assertCount(1, $response['error_messages']); + $this->assertTrue($response['error_messages'][0] == 'Malaccaa is not include in the regional state'); } } \ No newline at end of file