From 23d90e3da059e66fa2d25030dc3c39fe0aaf1d65 Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Mon, 19 Dec 2016 21:43:17 +1100 Subject: [PATCH 01/23] Tidy Country model --- app/Models/Country.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/app/Models/Country.php b/app/Models/Country.php index 09bbdd2..a1b13ae 100644 --- a/app/Models/Country.php +++ b/app/Models/Country.php @@ -2,12 +2,14 @@ namespace App\Models; +use App\Exceptions\InvalidParamException; + class Country { /** * Raw country data * - * @todo move this into persistant data store + * @todo move this into persistent data store * @todo provide full list of countries * @var array */ @@ -20,6 +22,11 @@ class Country private $attributes = []; + /** + * Country constructor. + * + * @param null|array $attributes + */ public function __construct($attributes = null) { if (is_array($attributes)) { @@ -28,18 +35,23 @@ public function __construct($attributes = null) } /** - * [__get description] - * @param [type] $key [description] - * @return [type] [description] + * Access attributes as properties + * + * @param string $key + * @return mixed + * @throws InvalidParamException */ public function __get($key) { if (array_key_exists($key, $this->attributes)) { return $this->attributes[$key]; } - throw new \App\Exceptions\InvalidParamException(sprintf("Unknown property %s", $key)); + throw new InvalidParamException(sprintf("Unknown property %s", $key)); } + /** + * @return Country[] + */ public static function all() { $result = []; @@ -50,7 +62,8 @@ public static function all() } /** - * [findById description] + * Find a specific country by its ISO id + * * @param string $ref country identifier * @return Country|null */ From 9bbe2c7bf089833d786c16ee1119b8ff00a93cc9 Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 10:33:14 +1100 Subject: [PATCH 02/23] Add list of countries as data file --- resources/data/countries.json | 998 ++++++++++++++++++++++++++++++++++ 1 file changed, 998 insertions(+) create mode 100644 resources/data/countries.json diff --git a/resources/data/countries.json b/resources/data/countries.json new file mode 100644 index 0000000..6a272df --- /dev/null +++ b/resources/data/countries.json @@ -0,0 +1,998 @@ +{ + "AF": { + "name": "Afghanistan", + "id": "AF" + }, + "AX": { + "name": "Åland Islands", + "id": "AX" + }, + "AL": { + "name": "Albania", + "id": "AL" + }, + "DZ": { + "name": "Algeria", + "id": "DZ" + }, + "AS": { + "name": "American Samoa", + "id": "AS" + }, + "AD": { + "name": "Andorra", + "id": "AD" + }, + "AO": { + "name": "Angola", + "id": "AO" + }, + "AI": { + "name": "Anguilla", + "id": "AI" + }, + "AQ": { + "name": "Antarctica", + "id": "AQ" + }, + "AG": { + "name": "Antigua and Barbuda", + "id": "AG" + }, + "AR": { + "name": "Argentina", + "id": "AR" + }, + "AM": { + "name": "Armenia", + "id": "AM" + }, + "AW": { + "name": "Aruba", + "id": "AW" + }, + "AU": { + "name": "Australia", + "id": "AU" + }, + "AT": { + "name": "Austria", + "id": "AT" + }, + "AZ": { + "name": "Azerbaijan", + "id": "AZ" + }, + "BS": { + "name": "Bahamas", + "id": "BS" + }, + "BH": { + "name": "Bahrain", + "id": "BH" + }, + "BD": { + "name": "Bangladesh", + "id": "BD" + }, + "BB": { + "name": "Barbados", + "id": "BB" + }, + "BY": { + "name": "Belarus", + "id": "BY" + }, + "BE": { + "name": "Belgium", + "id": "BE" + }, + "BZ": { + "name": "Belize", + "id": "BZ" + }, + "BJ": { + "name": "Benin", + "id": "BJ" + }, + "BM": { + "name": "Bermuda", + "id": "BM" + }, + "BT": { + "name": "Bhutan", + "id": "BT" + }, + "BO": { + "name": "Bolivia, Plurinational State of", + "id": "BO" + }, + "BQ": { + "name": "Bonaire, Sint Eustatius and Saba", + "id": "BQ" + }, + "BA": { + "name": "Bosnia and Herzegovina", + "id": "BA" + }, + "BW": { + "name": "Botswana", + "id": "BW" + }, + "BV": { + "name": "Bouvet Island", + "id": "BV" + }, + "BR": { + "name": "Brazil", + "id": "BR" + }, + "IO": { + "name": "British Indian Ocean Territory", + "id": "IO" + }, + "BN": { + "name": "Brunei Darussalam", + "id": "BN" + }, + "BG": { + "name": "Bulgaria", + "id": "BG" + }, + "BF": { + "name": "Burkina Faso", + "id": "BF" + }, + "BI": { + "name": "Burundi", + "id": "BI" + }, + "KH": { + "name": "Cambodia", + "id": "KH" + }, + "CM": { + "name": "Cameroon", + "id": "CM" + }, + "CA": { + "name": "Canada", + "id": "CA" + }, + "CV": { + "name": "Cape Verde", + "id": "CV" + }, + "KY": { + "name": "Cayman Islands", + "id": "KY" + }, + "CF": { + "name": "Central African Republic", + "id": "CF" + }, + "TD": { + "name": "Chad", + "id": "TD" + }, + "CL": { + "name": "Chile", + "id": "CL" + }, + "CN": { + "name": "China", + "id": "CN" + }, + "CX": { + "name": "Christmas Island", + "id": "CX" + }, + "CC": { + "name": "Cocos (Keeling) Islands", + "id": "CC" + }, + "CO": { + "name": "Colombia", + "id": "CO" + }, + "KM": { + "name": "Comoros", + "id": "KM" + }, + "CG": { + "name": "Congo", + "id": "CG" + }, + "CD": { + "name": "Congo, the Democratic Republic of the", + "id": "CD" + }, + "CK": { + "name": "Cook Islands", + "id": "CK" + }, + "CR": { + "name": "Costa Rica", + "id": "CR" + }, + "CI": { + "name": "Côte d'Ivoire", + "id": "CI" + }, + "HR": { + "name": "Croatia", + "id": "HR" + }, + "CU": { + "name": "Cuba", + "id": "CU" + }, + "CW": { + "name": "Curaçao", + "id": "CW" + }, + "CY": { + "name": "Cyprus", + "id": "CY" + }, + "CZ": { + "name": "Czech Republic", + "id": "CZ" + }, + "DK": { + "name": "Denmark", + "id": "DK" + }, + "DJ": { + "name": "Djibouti", + "id": "DJ" + }, + "DM": { + "name": "Dominica", + "id": "DM" + }, + "DO": { + "name": "Dominican Republic", + "id": "DO" + }, + "EC": { + "name": "Ecuador", + "id": "EC" + }, + "EG": { + "name": "Egypt", + "id": "EG" + }, + "SV": { + "name": "El Salvador", + "id": "SV" + }, + "GQ": { + "name": "Equatorial Guinea", + "id": "GQ" + }, + "ER": { + "name": "Eritrea", + "id": "ER" + }, + "EE": { + "name": "Estonia", + "id": "EE" + }, + "ET": { + "name": "Ethiopia", + "id": "ET" + }, + "FK": { + "name": "Falkland Islands (Malvinas)", + "id": "FK" + }, + "FO": { + "name": "Faroe Islands", + "id": "FO" + }, + "FJ": { + "name": "Fiji", + "id": "FJ" + }, + "FI": { + "name": "Finland", + "id": "FI" + }, + "FR": { + "name": "France", + "id": "FR" + }, + "GF": { + "name": "French Guiana", + "id": "GF" + }, + "PF": { + "name": "French Polynesia", + "id": "PF" + }, + "TF": { + "name": "French Southern Territories", + "id": "TF" + }, + "GA": { + "name": "Gabon", + "id": "GA" + }, + "GM": { + "name": "Gambia", + "id": "GM" + }, + "GE": { + "name": "Georgia", + "id": "GE" + }, + "DE": { + "name": "Germany", + "id": "DE" + }, + "GH": { + "name": "Ghana", + "id": "GH" + }, + "GI": { + "name": "Gibraltar", + "id": "GI" + }, + "GR": { + "name": "Greece", + "id": "GR" + }, + "GL": { + "name": "Greenland", + "id": "GL" + }, + "GD": { + "name": "Grenada", + "id": "GD" + }, + "GP": { + "name": "Guadeloupe", + "id": "GP" + }, + "GU": { + "name": "Guam", + "id": "GU" + }, + "GT": { + "name": "Guatemala", + "id": "GT" + }, + "GG": { + "name": "Guernsey", + "id": "GG" + }, + "GN": { + "name": "Guinea", + "id": "GN" + }, + "GW": { + "name": "Guinea-Bissau", + "id": "GW" + }, + "GY": { + "name": "Guyana", + "id": "GY" + }, + "HT": { + "name": "Haiti", + "id": "HT" + }, + "HM": { + "name": "Heard Island and McDonald Islands", + "id": "HM" + }, + "VA": { + "name": "Holy See (Vatican City State)", + "id": "VA" + }, + "HN": { + "name": "Honduras", + "id": "HN" + }, + "HK": { + "name": "Hong Kong", + "id": "HK" + }, + "HU": { + "name": "Hungary", + "id": "HU" + }, + "IS": { + "name": "Iceland", + "id": "IS" + }, + "IN": { + "name": "India", + "id": "IN" + }, + "ID": { + "name": "Indonesia", + "id": "ID" + }, + "IR": { + "name": "Iran, Islamic Republic of", + "id": "IR" + }, + "IQ": { + "name": "Iraq", + "id": "IQ" + }, + "IE": { + "name": "Ireland", + "id": "IE" + }, + "IM": { + "name": "Isle of Man", + "id": "IM" + }, + "IL": { + "name": "Israel", + "id": "IL" + }, + "IT": { + "name": "Italy", + "id": "IT" + }, + "JM": { + "name": "Jamaica", + "id": "JM" + }, + "JP": { + "name": "Japan", + "id": "JP" + }, + "JE": { + "name": "Jersey", + "id": "JE" + }, + "JO": { + "name": "Jordan", + "id": "JO" + }, + "KZ": { + "name": "Kazakhstan", + "id": "KZ" + }, + "KE": { + "name": "Kenya", + "id": "KE" + }, + "KI": { + "name": "Kiribati", + "id": "KI" + }, + "KP": { + "name": "Korea, Democratic People's Republic of", + "id": "KP" + }, + "KR": { + "name": "Korea, Republic of", + "id": "KR" + }, + "KW": { + "name": "Kuwait", + "id": "KW" + }, + "KG": { + "name": "Kyrgyzstan", + "id": "KG" + }, + "LA": { + "name": "Lao People's Democratic Republic", + "id": "LA" + }, + "LV": { + "name": "Latvia", + "id": "LV" + }, + "LB": { + "name": "Lebanon", + "id": "LB" + }, + "LS": { + "name": "Lesotho", + "id": "LS" + }, + "LR": { + "name": "Liberia", + "id": "LR" + }, + "LY": { + "name": "Libya", + "id": "LY" + }, + "LI": { + "name": "Liechtenstein", + "id": "LI" + }, + "LT": { + "name": "Lithuania", + "id": "LT" + }, + "LU": { + "name": "Luxembourg", + "id": "LU" + }, + "MO": { + "name": "Macao", + "id": "MO" + }, + "MK": { + "name": "Macedonia, the Former Yugoslav Republic of", + "id": "MK" + }, + "MG": { + "name": "Madagascar", + "id": "MG" + }, + "MW": { + "name": "Malawi", + "id": "MW" + }, + "MY": { + "name": "Malaysia", + "id": "MY" + }, + "MV": { + "name": "Maldives", + "id": "MV" + }, + "ML": { + "name": "Mali", + "id": "ML" + }, + "MT": { + "name": "Malta", + "id": "MT" + }, + "MH": { + "name": "Marshall Islands", + "id": "MH" + }, + "MQ": { + "name": "Martinique", + "id": "MQ" + }, + "MR": { + "name": "Mauritania", + "id": "MR" + }, + "MU": { + "name": "Mauritius", + "id": "MU" + }, + "YT": { + "name": "Mayotte", + "id": "YT" + }, + "MX": { + "name": "Mexico", + "id": "MX" + }, + "FM": { + "name": "Micronesia, Federated States of", + "id": "FM" + }, + "MD": { + "name": "Moldova, Republic of", + "id": "MD" + }, + "MC": { + "name": "Monaco", + "id": "MC" + }, + "MN": { + "name": "Mongolia", + "id": "MN" + }, + "ME": { + "name": "Montenegro", + "id": "ME" + }, + "MS": { + "name": "Montserrat", + "id": "MS" + }, + "MA": { + "name": "Morocco", + "id": "MA" + }, + "MZ": { + "name": "Mozambique", + "id": "MZ" + }, + "MM": { + "name": "Myanmar", + "id": "MM" + }, + "NA": { + "name": "Namibia", + "id": "NA" + }, + "NR": { + "name": "Nauru", + "id": "NR" + }, + "NP": { + "name": "Nepal", + "id": "NP" + }, + "NL": { + "name": "Netherlands", + "id": "NL" + }, + "NC": { + "name": "New Caledonia", + "id": "NC" + }, + "NZ": { + "name": "New Zealand", + "id": "NZ" + }, + "NI": { + "name": "Nicaragua", + "id": "NI" + }, + "NE": { + "name": "Niger", + "id": "NE" + }, + "NG": { + "name": "Nigeria", + "id": "NG" + }, + "NU": { + "name": "Niue", + "id": "NU" + }, + "NF": { + "name": "Norfolk Island", + "id": "NF" + }, + "MP": { + "name": "Northern Mariana Islands", + "id": "MP" + }, + "NO": { + "name": "Norway", + "id": "NO" + }, + "OM": { + "name": "Oman", + "id": "OM" + }, + "PK": { + "name": "Pakistan", + "id": "PK" + }, + "PW": { + "name": "Palau", + "id": "PW" + }, + "PS": { + "name": "Palestine, State of", + "id": "PS" + }, + "PA": { + "name": "Panama", + "id": "PA" + }, + "PG": { + "name": "Papua New Guinea", + "id": "PG" + }, + "PY": { + "name": "Paraguay", + "id": "PY" + }, + "PE": { + "name": "Peru", + "id": "PE" + }, + "PH": { + "name": "Philippines", + "id": "PH" + }, + "PN": { + "name": "Pitcairn", + "id": "PN" + }, + "PL": { + "name": "Poland", + "id": "PL" + }, + "PT": { + "name": "Portugal", + "id": "PT" + }, + "PR": { + "name": "Puerto Rico", + "id": "PR" + }, + "QA": { + "name": "Qatar", + "id": "QA" + }, + "RE": { + "name": "Réunion", + "id": "RE" + }, + "RO": { + "name": "Romania", + "id": "RO" + }, + "RU": { + "name": "Russian Federation", + "id": "RU" + }, + "RW": { + "name": "Rwanda", + "id": "RW" + }, + "BL": { + "name": "Saint Barthélemy", + "id": "BL" + }, + "SH": { + "name": "Saint Helena, Ascension and Tristan da Cunha", + "id": "SH" + }, + "KN": { + "name": "Saint Kitts and Nevis", + "id": "KN" + }, + "LC": { + "name": "Saint Lucia", + "id": "LC" + }, + "MF": { + "name": "Saint Martin (French part)", + "id": "MF" + }, + "PM": { + "name": "Saint Pierre and Miquelon", + "id": "PM" + }, + "VC": { + "name": "Saint Vincent and the Grenadines", + "id": "VC" + }, + "WS": { + "name": "Samoa", + "id": "WS" + }, + "SM": { + "name": "San Marino", + "id": "SM" + }, + "ST": { + "name": "Sao Tome and Principe", + "id": "ST" + }, + "SA": { + "name": "Saudi Arabia", + "id": "SA" + }, + "SN": { + "name": "Senegal", + "id": "SN" + }, + "RS": { + "name": "Serbia", + "id": "RS" + }, + "SC": { + "name": "Seychelles", + "id": "SC" + }, + "SL": { + "name": "Sierra Leone", + "id": "SL" + }, + "SG": { + "name": "Singapore", + "id": "SG" + }, + "SX": { + "name": "Sint Maarten (Dutch part)", + "id": "SX" + }, + "SK": { + "name": "Slovakia", + "id": "SK" + }, + "SI": { + "name": "Slovenia", + "id": "SI" + }, + "SB": { + "name": "Solomon Islands", + "id": "SB" + }, + "SO": { + "name": "Somalia", + "id": "SO" + }, + "ZA": { + "name": "South Africa", + "id": "ZA" + }, + "GS": { + "name": "South Georgia and the South Sandwich Islands", + "id": "GS" + }, + "SS": { + "name": "South Sudan", + "id": "SS" + }, + "ES": { + "name": "Spain", + "id": "ES" + }, + "LK": { + "name": "Sri Lanka", + "id": "LK" + }, + "SD": { + "name": "Sudan", + "id": "SD" + }, + "SR": { + "name": "Suriname", + "id": "SR" + }, + "SJ": { + "name": "Svalbard and Jan Mayen", + "id": "SJ" + }, + "SZ": { + "name": "Swaziland", + "id": "SZ" + }, + "SE": { + "name": "Sweden", + "id": "SE" + }, + "CH": { + "name": "Switzerland", + "id": "CH" + }, + "SY": { + "name": "Syrian Arab Republic", + "id": "SY" + }, + "TW": { + "name": "Taiwan, Province of China", + "id": "TW" + }, + "TJ": { + "name": "Tajikistan", + "id": "TJ" + }, + "TZ": { + "name": "Tanzania, United Republic of", + "id": "TZ" + }, + "TH": { + "name": "Thailand", + "id": "TH" + }, + "TL": { + "name": "Timor-Leste", + "id": "TL" + }, + "TG": { + "name": "Togo", + "id": "TG" + }, + "TK": { + "name": "Tokelau", + "id": "TK" + }, + "TO": { + "name": "Tonga", + "id": "TO" + }, + "TT": { + "name": "Trinidad and Tobago", + "id": "TT" + }, + "TN": { + "name": "Tunisia", + "id": "TN" + }, + "TR": { + "name": "Turkey", + "id": "TR" + }, + "TM": { + "name": "Turkmenistan", + "id": "TM" + }, + "TC": { + "name": "Turks and Caicos Islands", + "id": "TC" + }, + "TV": { + "name": "Tuvalu", + "id": "TV" + }, + "UG": { + "name": "Uganda", + "id": "UG" + }, + "UA": { + "name": "Ukraine", + "id": "UA" + }, + "AE": { + "name": "United Arab Emirates", + "id": "AE" + }, + "GB": { + "name": "United Kingdom", + "id": "GB" + }, + "US": { + "name": "United States", + "id": "US" + }, + "UM": { + "name": "United States Minor Outlying Islands", + "id": "UM" + }, + "UY": { + "name": "Uruguay", + "id": "UY" + }, + "UZ": { + "name": "Uzbekistan", + "id": "UZ" + }, + "VU": { + "name": "Vanuatu", + "id": "VU" + }, + "VE": { + "name": "Venezuela, Bolivarian Republic of", + "id": "VE" + }, + "VN": { + "name": "Viet Nam", + "id": "VN" + }, + "VG": { + "name": "Virgin Islands, British", + "id": "VG" + }, + "VI": { + "name": "Virgin Islands, U.S.", + "id": "VI" + }, + "WF": { + "name": "Wallis and Futuna", + "id": "WF" + }, + "EH": { + "name": "Western Sahara", + "id": "EH" + }, + "YE": { + "name": "Yemen", + "id": "YE" + }, + "ZM": { + "name": "Zambia", + "id": "ZM" + }, + "ZW": { + "name": "Zimbabwe", + "id": "ZW" + } +} \ No newline at end of file From 366e8bc4fc783d91827daad3503332b8d725e541 Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 10:36:57 +1100 Subject: [PATCH 03/23] Update country code to upper case in unit test --- tests/CountryTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/CountryTest.php b/tests/CountryTest.php index f728c8b..34e4404 100644 --- a/tests/CountryTest.php +++ b/tests/CountryTest.php @@ -10,8 +10,8 @@ public function testAll() { $result = Country::all(); $this->assertTrue(count($result) > 0); - $this->assertInstanceOf(Country::class, $result['au']); - $this->assertSame('Australia', $result['au']->name); + $this->assertInstanceOf(Country::class, $result['AU']); + $this->assertSame('Australia', $result['AU']->name); } From 9ee95e3b553bef18d970504c2fdffb1f22ce9c0c Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 10:37:53 +1100 Subject: [PATCH 04/23] Add Country::loadRawData() Load raw country data from json file --- app/Models/Country.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/Models/Country.php b/app/Models/Country.php index 09bbdd2..66def48 100644 --- a/app/Models/Country.php +++ b/app/Models/Country.php @@ -11,12 +11,7 @@ class Country * @todo provide full list of countries * @var array */ - private static $data = [ - 'au' => [ - 'id' => 'au', - 'name' => 'Australia' - ] - ]; + private static $data; private $attributes = []; @@ -61,4 +56,17 @@ public static function findById($ref) } return null; } + + /** + * Load and return the raw country data + */ + private static function loadRawData() + { + if (!is_array(self::$data)) { + $path = \App\path('resources/data/countries.json'); + $content = file_get_contents($path); + self::$data = json_decode($content, true); + } + return self::$data; + } } From 47928ad5526a178b2a6c58200bdc1711d0df230f Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 10:38:33 +1100 Subject: [PATCH 05/23] Update country path to constant --- app/Models/Country.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Models/Country.php b/app/Models/Country.php index 66def48..3888609 100644 --- a/app/Models/Country.php +++ b/app/Models/Country.php @@ -4,6 +4,7 @@ class Country { + const DATA_FILE = 'resources/data/countries.json'; /** * Raw country data * @@ -63,7 +64,7 @@ public static function findById($ref) private static function loadRawData() { if (!is_array(self::$data)) { - $path = \App\path('resources/data/countries.json'); + $path = \App\path(self::DATA_FILE); $content = file_get_contents($path); self::$data = json_decode($content, true); } From ba2786e852858b802ad40a2451eda3ff68155778 Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 10:39:00 +1100 Subject: [PATCH 06/23] Update static country methods to use loadRawData --- app/Models/Country.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Models/Country.php b/app/Models/Country.php index 3888609..7ff308a 100644 --- a/app/Models/Country.php +++ b/app/Models/Country.php @@ -39,7 +39,7 @@ public function __get($key) public static function all() { $result = []; - foreach (self::$data as $key => $country) { + foreach (self::loadRawData() as $key => $country) { $result[$key] = new self($country); } return $result; @@ -52,8 +52,10 @@ public static function all() */ public static function findById($ref) { - if (isset(self::$data[$ref])) { - return new self(self::$data[$ref]); + $data = self::loadRawData(); + $ref = strtoupper($ref); + if (isset($data[$ref])) { + return new self($data[$ref]); } return null; } From 446629aecf8f8c5fb8e65dba7c193aa439ea99c0 Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 10:43:28 +1100 Subject: [PATCH 07/23] Add app & path helper functions --- app/helpers.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/app/helpers.php b/app/helpers.php index eb97d00..3b9ce6d 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -2,8 +2,12 @@ namespace App; +use App\Support\Container; + /** * Contains quick global helper methods + * These are simple wrappers to more complex objects that need to be accessed + * frequently within the application */ /** @@ -24,4 +28,29 @@ function array_get(&$data, $path) } return $data; -} \ No newline at end of file +} + +/** + * Retrieve an instance of the application Container + * + * @return Container + */ +function app() +{ + return Container::instance(); +} + +/** + * Get the absolute path to the resource, based on the root of the application + * + * @param string $relPath + * @return string + */ +function path($relPath = null) +{ + $path = app()->root(); + if ($relPath) { + $path .= trim($relPath, ' /'); + } + return $path; +} From d694f01ff46ec22ea710b222c5ec0948728b107a Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 10:50:14 +1100 Subject: [PATCH 08/23] Add container::instance & ::root() --- app/Support/Container.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/app/Support/Container.php b/app/Support/Container.php index cdc304c..2028a0e 100644 --- a/app/Support/Container.php +++ b/app/Support/Container.php @@ -20,6 +20,11 @@ */ class Container { + /** + * @var Container + */ + private static $instance; + /** * @var DiContainer */ @@ -40,12 +45,34 @@ class Container */ public function __construct(DiContainer $di, $path) { - // auto wire our calls + // auto wire our DI calls $di->delegate( new ReflectionContainer ); $this->dependency = $di; $this->pathRoot = rtrim($path, '/').'/'; + + self::$instance = $this; + } + + /** + * Get the instance of the container + * + * @return Container + */ + public static function instance() + { + return self::$instance; + } + + /** + * The root directory for the application + * + * @return string + */ + public function root() + { + return $this->pathRoot; } /** From f882770364b02c83ea260a6a9eb7dc50d2a66247 Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 10:51:14 +1100 Subject: [PATCH 09/23] Remove redundant --dev flag from travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a69f606..3a410f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ cache: before_script: - composer self-update - - composer install --prefer-source --no-interaction --dev + - composer install --prefer-source --no-interaction script: - vendor/bin/phpunit From 965a425895b974020cc30ae72508741751bfdf9b Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 10:52:21 +1100 Subject: [PATCH 10/23] Update travis composer install. Prefer dist --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3a410f0..a22fd88 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ cache: before_script: - composer self-update - - composer install --prefer-source --no-interaction + - composer install --prefer-dist --no-interaction script: - vendor/bin/phpunit From bb452f0dc6d9b409c52d2ef35c162a21a1119c72 Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 10:58:02 +1100 Subject: [PATCH 11/23] Add blade as dependency --- composer.json | 3 +- composer.lock | 598 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 598 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 9eae145..5505998 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "symfony/http-foundation": "^3.2", "symfony/psr-http-message-bridge": "^1.0", "zendframework/zend-diactoros": "^1.3", - "guzzlehttp/guzzle": "^6.2" + "guzzlehttp/guzzle": "^6.2", + "philo/laravel-blade": "^3.1" }, "require-dev": { "phpunit/phpunit": "^5.7", diff --git a/composer.lock b/composer.lock index ced0aa8..1d4316d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "e1d25b97da917dcda19199196028772d", - "content-hash": "39c6c8921d67b5056e756a3f05804559", + "hash": "98cef4fec8eff7e038b5428c5b531ef3", + "content-hash": "a45e0c9aff2bbd30f4c64e7ceb9aaeb1", "packages": [ { "name": "container-interop/container-interop", @@ -34,6 +34,73 @@ "description": "Promoting the interoperability of container objects (DIC, SL, etc.)", "time": "2014-12-30 15:22:37" }, + { + "name": "doctrine/inflector", + "version": "v1.1.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/inflector.git", + "reference": "90b2128806bfde671b6952ab8bea493942c1fdae" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/inflector/zipball/90b2128806bfde671b6952ab8bea493942c1fdae", + "reference": "90b2128806bfde671b6952ab8bea493942c1fdae", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "4.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Inflector\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Common String Manipulations with regard to casing and singular/plural rules.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "inflection", + "pluralize", + "singularize", + "string" + ], + "time": "2015-11-06 14:35:42" + }, { "name": "guzzlehttp/guzzle", "version": "6.2.2", @@ -205,6 +272,291 @@ ], "time": "2016-06-24 23:00:38" }, + { + "name": "illuminate/container", + "version": "v5.3.23", + "source": { + "type": "git", + "url": "https://github.com/illuminate/container.git", + "reference": "8047b47e1f731c975d9aa0fe0b269064d3f1346d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/container/zipball/8047b47e1f731c975d9aa0fe0b269064d3f1346d", + "reference": "8047b47e1f731c975d9aa0fe0b269064d3f1346d", + "shasum": "" + }, + "require": { + "illuminate/contracts": "5.3.*", + "php": ">=5.6.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.3-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Container\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Container package.", + "homepage": "https://laravel.com", + "time": "2016-10-02 01:14:30" + }, + { + "name": "illuminate/contracts", + "version": "v5.3.23", + "source": { + "type": "git", + "url": "https://github.com/illuminate/contracts.git", + "reference": "ce5d73c6015b2054d32f3f8530767847b358ae4e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/contracts/zipball/ce5d73c6015b2054d32f3f8530767847b358ae4e", + "reference": "ce5d73c6015b2054d32f3f8530767847b358ae4e", + "shasum": "" + }, + "require": { + "php": ">=5.6.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.3-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Contracts\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Contracts package.", + "homepage": "https://laravel.com", + "time": "2016-09-26 20:36:27" + }, + { + "name": "illuminate/events", + "version": "v5.3.23", + "source": { + "type": "git", + "url": "https://github.com/illuminate/events.git", + "reference": "cb29124d4eaba8a60bad40e95e3d8b199d040d77" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/events/zipball/cb29124d4eaba8a60bad40e95e3d8b199d040d77", + "reference": "cb29124d4eaba8a60bad40e95e3d8b199d040d77", + "shasum": "" + }, + "require": { + "illuminate/container": "5.3.*", + "illuminate/contracts": "5.3.*", + "illuminate/support": "5.3.*", + "php": ">=5.6.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.3-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Events\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Events package.", + "homepage": "https://laravel.com", + "time": "2016-08-12 14:24:30" + }, + { + "name": "illuminate/filesystem", + "version": "v5.3.23", + "source": { + "type": "git", + "url": "https://github.com/illuminate/filesystem.git", + "reference": "82576e0a6193e76929c929c8a2d3e1552ab64e76" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/filesystem/zipball/82576e0a6193e76929c929c8a2d3e1552ab64e76", + "reference": "82576e0a6193e76929c929c8a2d3e1552ab64e76", + "shasum": "" + }, + "require": { + "illuminate/contracts": "5.3.*", + "illuminate/support": "5.3.*", + "php": ">=5.6.4", + "symfony/finder": "3.1.*" + }, + "suggest": { + "league/flysystem": "Required to use the Flysystem local and FTP drivers (~1.0).", + "league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (~1.0).", + "league/flysystem-rackspace": "Required to use the Flysystem Rackspace driver (~1.0)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.3-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Filesystem\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Filesystem package.", + "homepage": "https://laravel.com", + "time": "2016-11-07 22:09:46" + }, + { + "name": "illuminate/support", + "version": "v5.3.23", + "source": { + "type": "git", + "url": "https://github.com/illuminate/support.git", + "reference": "050d0ed3e1c0e1d129d73b2eaa14044e46a66f77" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/support/zipball/050d0ed3e1c0e1d129d73b2eaa14044e46a66f77", + "reference": "050d0ed3e1c0e1d129d73b2eaa14044e46a66f77", + "shasum": "" + }, + "require": { + "doctrine/inflector": "~1.0", + "ext-mbstring": "*", + "illuminate/contracts": "5.3.*", + "paragonie/random_compat": "~1.4|~2.0", + "php": ">=5.6.4" + }, + "replace": { + "tightenco/collect": "self.version" + }, + "suggest": { + "illuminate/filesystem": "Required to use the composer class (5.2.*).", + "symfony/process": "Required to use the composer class (3.1.*).", + "symfony/var-dumper": "Required to use the dd function (3.1.*)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.3-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Support\\": "" + }, + "files": [ + "helpers.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Support package.", + "homepage": "https://laravel.com", + "time": "2016-11-03 15:25:28" + }, + { + "name": "illuminate/view", + "version": "v5.3.23", + "source": { + "type": "git", + "url": "https://github.com/illuminate/view.git", + "reference": "f840676c98e3cb1224267786f35eb420de55d41c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/view/zipball/f840676c98e3cb1224267786f35eb420de55d41c", + "reference": "f840676c98e3cb1224267786f35eb420de55d41c", + "shasum": "" + }, + "require": { + "illuminate/container": "5.3.*", + "illuminate/contracts": "5.3.*", + "illuminate/events": "5.3.*", + "illuminate/filesystem": "5.3.*", + "illuminate/support": "5.3.*", + "php": ">=5.6.4", + "symfony/debug": "3.1.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.3-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\View\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate View package.", + "homepage": "https://laravel.com", + "time": "2016-10-24 18:18:15" + }, { "name": "league/container", "version": "2.2.0", @@ -404,6 +756,95 @@ ], "time": "2015-12-20 19:50:12" }, + { + "name": "paragonie/random_compat", + "version": "v2.0.4", + "source": { + "type": "git", + "url": "https://github.com/paragonie/random_compat.git", + "reference": "a9b97968bcde1c4de2a5ec6cbd06a0f6c919b46e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/a9b97968bcde1c4de2a5ec6cbd06a0f6c919b46e", + "reference": "a9b97968bcde1c4de2a5ec6cbd06a0f6c919b46e", + "shasum": "" + }, + "require": { + "php": ">=5.2.0" + }, + "require-dev": { + "phpunit/phpunit": "4.*|5.*" + }, + "suggest": { + "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." + }, + "type": "library", + "autoload": { + "files": [ + "lib/random.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paragon Initiative Enterprises", + "email": "security@paragonie.com", + "homepage": "https://paragonie.com" + } + ], + "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", + "keywords": [ + "csprng", + "pseudorandom", + "random" + ], + "time": "2016-11-07 23:38:38" + }, + { + "name": "philo/laravel-blade", + "version": "v3.1", + "source": { + "type": "git", + "url": "https://github.com/PhiloNL/Laravel-Blade.git", + "reference": "3f0ce2ee198604c53c25188110e6d7b5e887527a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PhiloNL/Laravel-Blade/zipball/3f0ce2ee198604c53c25188110e6d7b5e887527a", + "reference": "3f0ce2ee198604c53c25188110e6d7b5e887527a", + "shasum": "" + }, + "require": { + "illuminate/events": "~5", + "illuminate/view": "~5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Philo\\Blade\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Philo Hermans", + "email": "me@philohermans.com" + } + ], + "description": "Use the simple and yet powerful Laravel Blade templating engine as a standalone component.", + "keywords": [ + "blade", + "laravel" + ], + "time": "2015-12-04 09:42:42" + }, { "name": "psr/http-message", "version": "1.0.1", @@ -454,6 +895,159 @@ ], "time": "2016-08-06 14:39:51" }, + { + "name": "psr/log", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2016-10-10 12:19:37" + }, + { + "name": "symfony/debug", + "version": "v3.1.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/debug.git", + "reference": "c058661c32f5b462722e36d120905940089cbd9a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/debug/zipball/c058661c32f5b462722e36d120905940089cbd9a", + "reference": "c058661c32f5b462722e36d120905940089cbd9a", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "psr/log": "~1.0" + }, + "conflict": { + "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2" + }, + "require-dev": { + "symfony/class-loader": "~2.8|~3.0", + "symfony/http-kernel": "~2.8|~3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Debug\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Debug Component", + "homepage": "https://symfony.com", + "time": "2016-11-15 12:55:20" + }, + { + "name": "symfony/finder", + "version": "v3.1.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/finder.git", + "reference": "74dcd370c8d057882575e535616fde935e411b19" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/finder/zipball/74dcd370c8d057882575e535616fde935e411b19", + "reference": "74dcd370c8d057882575e535616fde935e411b19", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Finder\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Finder Component", + "homepage": "https://symfony.com", + "time": "2016-12-13 09:38:21" + }, { "name": "symfony/http-foundation", "version": "v3.2.1", From 7cc255d287022d02d0bb2d8788e2f62d68646056 Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 11:02:39 +1100 Subject: [PATCH 12/23] Register blade into app bootstrap --- bootstrap/app.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bootstrap/app.php b/bootstrap/app.php index 3d09fb2..f650c7d 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -2,6 +2,7 @@ use App\Support\Container; use League\Container\Container as DiContainer; +use Philo\Blade\Blade; require_once __DIR__.'/../vendor/autoload.php'; @@ -23,6 +24,10 @@ $app->share('config', function() use ($app) { +$app->share('view', function () use ($app) { + return new Blade($app->get('config')->get('view.path'), $app->get('config')->get('view.cache')); +}); + return new \Config\Repository(new \Config\Loader\FileLoader(__DIR__.'/config'), getenv('APP_ENV')); }); //endregion From eb70e1b26c8bcf1127f72f3b8b7781f86d46134c Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 11:03:16 +1100 Subject: [PATCH 13/23] Add region comment to bootstrap/app for organisation --- bootstrap/app.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bootstrap/app.php b/bootstrap/app.php index f650c7d..108cc9f 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -15,7 +15,7 @@ $app = new Container(new DiContainer(), realpath(__DIR__.'/../')); -//region application services +//region low level application services $app->add('request', function () { return Symfony\Component\HttpFoundation\Request::createFromGlobals(); }); @@ -27,6 +27,7 @@ $app->share('view', function () use ($app) { return new Blade($app->get('config')->get('view.path'), $app->get('config')->get('view.cache')); }); +//endregion return new \Config\Repository(new \Config\Loader\FileLoader(__DIR__.'/config'), getenv('APP_ENV')); }); From 6c98e3d6e195d318f898e0a0dd995ab0457d0f4a Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 11:04:18 +1100 Subject: [PATCH 14/23] Update config service to use App\path --- bootstrap/app.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bootstrap/app.php b/bootstrap/app.php index 108cc9f..09f77c3 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -22,7 +22,9 @@ $app->share('response', \Symfony\Component\HttpFoundation\Response::class);; $app->share('emitter', Zend\Diactoros\Response\SapiEmitter::class); -$app->share('config', function() use ($app) { +$app->share('config', function () use ($app) { + return new \Config\Repository(new \Config\Loader\FileLoader(\App\path('config')), getenv('APP_ENV')); +}); $app->share('view', function () use ($app) { return new Blade($app->get('config')->get('view.path'), $app->get('config')->get('view.cache')); From 9878e9df970dd3d385dfa36348b5eedaf352a2ba Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 11:04:45 +1100 Subject: [PATCH 15/23] Remove old config service code --- bootstrap/app.php | 1 - 1 file changed, 1 deletion(-) diff --git a/bootstrap/app.php b/bootstrap/app.php index 09f77c3..c9584e5 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -31,7 +31,6 @@ }); //endregion - return new \Config\Repository(new \Config\Loader\FileLoader(__DIR__.'/config'), getenv('APP_ENV')); }); //endregion From 8b1adea4647f700e5b95ca1a4682cf796b066766 Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 11:05:05 +1100 Subject: [PATCH 16/23] Add view config file for location of files & cache --- config/view.php | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 config/view.php diff --git a/config/view.php b/config/view.php new file mode 100644 index 0000000..fb04018 --- /dev/null +++ b/config/view.php @@ -0,0 +1,6 @@ + \App\path('resources/views'), + 'cache' => \App\path('storage/views') +]; From a40a9caef345a0ce43a7979e31011b085aa2a953 Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 11:07:30 +1100 Subject: [PATCH 17/23] Add base abstract controller --- app/Http/Controllers/AbstractController.php | 94 +++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 app/Http/Controllers/AbstractController.php diff --git a/app/Http/Controllers/AbstractController.php b/app/Http/Controllers/AbstractController.php new file mode 100644 index 0000000..77a961b --- /dev/null +++ b/app/Http/Controllers/AbstractController.php @@ -0,0 +1,94 @@ +request = $request; + $this->response = $response; + } + + /** + * Get the request (get/post) param from the request handler + * + * @param string $key + * @param mixed $default + * @return mixed + */ + protected function getRequestParam($key, $default = null) + { + $params = $this->request->getQueryParams(); + if (array_key_exists($key, $params)) { + return $params[$key]; + } + + return $default; + } + + /** + * Verify the existence of a request param + * + * @param string $key + * @return bool + */ + protected function hasRequestParam($key) + { + $params = $this->request->getQueryParams(); + + return array_key_exists($key, $params); + } + + /** + * Allow a controllers actions to be called statically be invoking a new instance of the controller + * + * @param string $method + * @param array $params + * @return string|array|ResponseInterface + */ + public static function __callStatic($method, $params) + { + $methodName = 'action'.ucfirst($method); + + if (method_exists(static::class, $methodName)) { + $callback = [new static(array_shift($params), array_shift($params)), $methodName]; + + return call_user_func_array($callback, $params[0] ?: []); + } + throw new RuntimeException(sprintf("Unknown static method %s::%s()", static::class, $method)); + } + + /** + * Load the requested view add write it to the body + * + * @param string $path + * @param array $params + * @return \Psr\Http\Message\StreamInterface + */ + protected function view($path, array $params = []) + { + $view = \App\app()->get('view')->view(); + $rendered = $view->make($path, $params)->render(); + $this->response->getBody()->write($rendered); + return $this->response; + } +} From cae1adf5a58a57737aa54f42fd034793d92d750c Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 11:09:08 +1100 Subject: [PATCH 18/23] Add HttpException class. Allows components to output standard http responses via an Exception --- app/Exceptions/HttpException.php | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 app/Exceptions/HttpException.php diff --git a/app/Exceptions/HttpException.php b/app/Exceptions/HttpException.php new file mode 100644 index 0000000..0a0b636 --- /dev/null +++ b/app/Exceptions/HttpException.php @@ -0,0 +1,9 @@ + Date: Tue, 27 Dec 2016 11:10:02 +1100 Subject: [PATCH 19/23] Fix PSR-2 error in bootstrap/app.php --- bootstrap/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/app.php b/bootstrap/app.php index c9584e5..fc35bac 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -19,7 +19,7 @@ $app->add('request', function () { return Symfony\Component\HttpFoundation\Request::createFromGlobals(); }); -$app->share('response', \Symfony\Component\HttpFoundation\Response::class);; +$app->share('response', \Symfony\Component\HttpFoundation\Response::class); $app->share('emitter', Zend\Diactoros\Response\SapiEmitter::class); $app->share('config', function () use ($app) { From 1f868b6cfa548c15f54bc74f98a1b3b35f66b7bc Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 11:10:48 +1100 Subject: [PATCH 20/23] Add basic blade layout files --- resources/views/layouts/artist.blade.php | 14 ++++++++++++++ resources/views/layouts/default.blade.php | 15 +++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 resources/views/layouts/artist.blade.php create mode 100644 resources/views/layouts/default.blade.php diff --git a/resources/views/layouts/artist.blade.php b/resources/views/layouts/artist.blade.php new file mode 100644 index 0000000..a9961e9 --- /dev/null +++ b/resources/views/layouts/artist.blade.php @@ -0,0 +1,14 @@ + + + + + @yield('title') + + + +
+ @yield('content') +
+ + + diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php new file mode 100644 index 0000000..d518885 --- /dev/null +++ b/resources/views/layouts/default.blade.php @@ -0,0 +1,15 @@ + + + + + @yield('title') + + + +
+ @include('partials.form', ['model' => $model]) + @yield('content') +
+ + + From c57680db84d7d5204e05f718e5ab2935d5c561f3 Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 11:12:10 +1100 Subject: [PATCH 21/23] Add default controller --- app/Http/Controllers/DefaultController.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 app/Http/Controllers/DefaultController.php diff --git a/app/Http/Controllers/DefaultController.php b/app/Http/Controllers/DefaultController.php new file mode 100644 index 0000000..a6dcc30 --- /dev/null +++ b/app/Http/Controllers/DefaultController.php @@ -0,0 +1,19 @@ + Date: Tue, 27 Dec 2016 11:21:08 +1100 Subject: [PATCH 22/23] Update routes to use DefaultController --- app/Http/routes.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/Http/routes.php b/app/Http/routes.php index 3181329..f2422dd 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -1,12 +1,12 @@ addRoute('GET', '/', function() { - return 'asdf'; -}); -$route->addRoute('GET', '/ajax', function() { - return ['foo' => 'bar']; -}); \ No newline at end of file + + +$route->addRoute('GET', '/', DefaultController::class.'::index'); From 575a3b9af0476914f3ad359fa3a83b711df20fa5 Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Tue, 27 Dec 2016 11:21:26 +1100 Subject: [PATCH 23/23] Remove whitespace from routes.php --- app/Http/routes.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/Http/routes.php b/app/Http/routes.php index f2422dd..7b2e75b 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -6,7 +6,4 @@ /** * @var \League\Route\RouteCollection $route */ - - - $route->addRoute('GET', '/', DefaultController::class.'::index');