diff --git a/composer.json b/composer.json index 0df8540..2f64151 100644 --- a/composer.json +++ b/composer.json @@ -1,4 +1,5 @@ { +<<<<<<< Updated upstream "name": "danharrin/squire", "description": "A library of static Eloquent models for common fixture data.", "keywords": [ @@ -11,6 +12,9 @@ "homepage": "https://github.com/squirephp/squire", "type": "library", "license": "MIT", +======= + "name": "squirephp/squire", +>>>>>>> Stashed changes "authors": [ { "name": "Dan Harrin", @@ -24,16 +28,40 @@ }, "require-dev": { "orchestra/testbench": "^6.2", - "phpunit/phpunit": "^9.4" + "phpunit/phpunit": "^9.4", + "symplify/monorepo-builder": "^9.0" }, "autoload": { "psr-4": { - "Squire\\": "src" + "Squire\\": [ + "packages/countries-en/src", + "packages/countries/src", + "packages/model/src", + "packages/repository/src" + ] } }, - "config": { - "sort-packages": true + "autoload-dev": { + "psr-4": { + "Squire\\Tests\\": "tests" + } + }, + "extra": { + "laravel": { + "providers": [ + "Squire\\CountriesEnServiceProvider", + "Squire\\RepositoryServiceProvider" + ], + "aliases": { + "RepositoryManager": "Squire\\Repository\\Facades\\Repository", + "Repository": "Squire\\Repository\\Facades\\Repository" + } + } }, - "minimum-stability": "dev", - "prefer-stable": true + "replace": { + "squirephp/countries": "self.version", + "squirephp/countries-en": "self.version", + "squirephp/model": "self.version", + "squirephp/repository": "self.version" + } } diff --git a/monorepo-builder.php b/monorepo-builder.php new file mode 100644 index 0000000..cac9751 --- /dev/null +++ b/monorepo-builder.php @@ -0,0 +1,25 @@ +parameters(); + + $parameters->set(Option::DATA_TO_APPEND, [ + 'autoload-dev' => [ + 'psr-4' => [ + 'Squire\Tests\\' => 'tests', + ], + ], + 'require-dev' => [ + 'orchestra/testbench' => '^6.2', + 'phpunit/phpunit' => '^9.4', + 'symplify/monorepo-builder' => '^9.0', + ], + ]); + + $parameters->set(Option::DATA_TO_REMOVE, [ + 'minimum-stability' => '*', + ]); +}; \ No newline at end of file diff --git a/packages/countries-en/composer.json b/packages/countries-en/composer.json new file mode 100644 index 0000000..8eb732c --- /dev/null +++ b/packages/countries-en/composer.json @@ -0,0 +1,39 @@ +{ + "name": "squirephp/countries-en", + "description": "A library containing the English translation of Squire's Country model.", + "keywords": ["squire"], + "license": "MIT", + "homepage": "https://github.com/squirephp", + "support": { + "issues": "https://github.com/squirephp/squire/issues", + "source": "https://github.com/squirephp/squire" + }, + "authors": [ + { + "name": "Dan Harrin", + "email": "dan@danharrin.com" + } + ], + "require": { + "php": "^7.2|^8.0", + "illuminate/support": "^6.0 || ^7.0 || ^8.0", + "squirephp/countries": "^2.0", + "squirephp/repository": "^2.0" + }, + "autoload": { + "psr-4": { + "Squire\\": "src" + } + }, + "extra": { + "laravel": { + "providers": [ + "Squire\\CountriesEnServiceProvider" + ] + } + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev" +} diff --git a/packages/countries-en/data.csv b/packages/countries-en/data.csv new file mode 100644 index 0000000..fbbdf7c --- /dev/null +++ b/packages/countries-en/data.csv @@ -0,0 +1,250 @@ +id,calling_code,capital_city,code_2,code_3,continent_id,currency_id,flag,name +ad,376,Andorra la Vella,ad,and,eu,eur,🇦🇩,Andorra +ae,971,Abu Dhabi,ae,are,as,aed,🇦🇪,United Arab Emirates +af,93,Kabul,af,afg,as,afn,🇦🇫,Afghanistan +ag,1268,St. John's,ag,atg,na,xcd,🇦🇬,Antigua and Barbuda +ai,1264,The Valley,ai,aia,na,xcd,🇦🇮,Anguilla +al,355,Tirana,al,alb,eu,all,🇦🇱,Albania +am,374,Yerevan,am,arm,as,amd,🇦🇲,Armenia +ao,244,Luanda,ao,ago,af,aoa,🇦🇴,Angola +aq,672,,aq,ata,an,,🇦🇶,Antarctica +ar,54,Buenos Aires,ar,arg,sa,ars,🇦🇷,Argentina +as,1684,Pago Pago,as,asm,oc,usd,🇦🇸,American Samoa +at,43,Vienna,at,aut,eu,eur,🇦🇹,Austria +au,61,Canberra,au,aus,oc,aud,🇦🇺,Australia +aw,297,Oranjestad,aw,abw,na,awg,🇦🇼,Aruba +ax,358,Mariehamn,ax,ala,eu,eur,🇦🇽,Aland Islands +az,994,Baku,az,aze,as,azn,🇦🇿,Azerbaijan +ba,387,Sarajevo,ba,bih,eu,bam,🇧🇦,Bosnia and Herzegovina +bb,1246,Bridgetown,bb,brb,na,bbd,🇧🇧,Barbados +bd,880,Dhaka,bd,bgd,as,bdt,🇧🇩,Bangladesh +be,32,Brussels,be,bel,eu,eur,🇧🇪,Belgium +bf,226,Ouagadougou,bf,bfa,af,xof,🇧🇫,Burkina Faso +bg,359,Sofia,bg,bgr,eu,bgn,🇧🇬,Bulgaria +bh,973,Manama,bh,bhr,as,bhd,🇧🇭,Bahrain +bi,257,Bujumbura,bi,bdi,af,bif,🇧🇮,Burundi +bj,229,Porto-Novo,bj,ben,af,xof,🇧🇯,Benin +bl,590,Gustavia,bl,blm,na,eur,🇧🇱,Saint Barthelemy +bm,1441,Hamilton,bm,bmu,na,bmd,🇧🇲,Bermuda +bn,673,Bandar Seri Begawan,bn,brn,as,bnd,🇧🇳,Brunei +bo,591,Sucre,bo,bol,sa,bob,🇧🇴,Bolivia +bq,599,,bq,bes,na,usd,🇧🇶,"Bonaire, Saint Eustatius and Saba " +br,55,Brasilia,br,bra,sa,brl,🇧🇷,Brazil +bs,1242,Nassau,bs,bhs,na,bsd,🇧🇸,Bahamas +bt,975,Thimphu,bt,btn,as,btn,🇧🇹,Bhutan +bv,55,,bv,bvt,an,nok,🇧🇻,Bouvet Island +bw,267,Gaborone,bw,bwa,af,bwp,🇧🇼,Botswana +by,375,Minsk,by,blr,eu,byr,🇧🇾,Belarus +bz,501,Belmopan,bz,blz,na,bzd,🇧🇿,Belize +ca,1,Ottawa,ca,can,na,cad,🇨🇦,Canada +cc,61,West Island,cc,cck,as,aud,🇨🇨,Cocos Islands +cd,243,Kinshasa,cd,cod,af,cdf,🇨🇩,Democratic Republic of the Congo +cf,236,Bangui,cf,caf,af,xaf,🇨🇫,Central African Republic +cg,242,Brazzaville,cg,cog,af,xaf,🇨🇬,Republic of the Congo +ch,41,Berne,ch,che,eu,chf,🇨🇭,Switzerland +ci,225,Yamoussoukro,ci,civ,af,xof,🇨🇮,Ivory Coast +ck,682,Avarua,ck,cok,oc,nzd,🇨🇰,Cook Islands +cl,56,Santiago,cl,chl,sa,clp,🇨🇱,Chile +cm,237,Yaounde,cm,cmr,af,xaf,🇨🇲,Cameroon +cn,86,Beijing,cn,chn,as,cny,🇨🇳,China +co,57,Bogota,co,col,sa,cop,🇨🇴,Colombia +cr,506,San Jose,cr,cri,na,crc,🇨🇷,Costa Rica +cu,53,Havana,cu,cub,na,cup,🇨🇺,Cuba +cv,238,Praia,cv,cpv,af,cve,🇨🇻,Cape Verde +cw,599, Willemstad,cw,cuw,na,ang,🇨🇼,Curacao +cx,61,Flying Fish Cove,cx,cxr,as,aud,🇨🇽,Christmas Island +cy,357,Nicosia,cy,cyp,eu,eur,🇨🇾,Cyprus +cz,420,Prague,cz,cze,eu,czk,🇨🇿,Czech Republic +de,49,Berlin,de,deu,eu,eur,🇩🇪,Germany +dj,253,Djibouti,dj,dji,af,djf,🇩🇯,Djibouti +dk,45,Copenhagen,dk,dnk,eu,dkk,🇩🇰,Denmark +dm,1767,Roseau,dm,dma,na,xcd,🇩🇲,Dominica +do,1809,Santo Domingo,do,dom,na,dop,🇩🇴,Dominican Republic +dz,213,Algiers,dz,dza,af,dzd,🇩🇿,Algeria +ec,593,Quito,ec,ecu,sa,usd,🇪🇨,Ecuador +ee,372,Tallinn,ee,est,eu,eur,🇪🇪,Estonia +eg,20,Cairo,eg,egy,af,egp,🇪🇬,Egypt +eh,212,El-Aaiun,eh,esh,af,mad,🇪🇭,Western Sahara +er,291,Asmara,er,eri,af,ern,🇪🇷,Eritrea +es,34,Madrid,es,esp,eu,eur,🇪🇸,Spain +et,251,Addis Ababa,et,eth,af,etb,🇪🇹,Ethiopia +fi,358,Helsinki,fi,fin,eu,eur,🇫🇮,Finland +fj,679,Suva,fj,fji,oc,fjd,🇫🇯,Fiji +fk,500,Stanley,fk,flk,sa,fkp,🇫🇰,Falkland Islands +fm,691,Palikir,fm,fsm,oc,usd,🇫🇲,Micronesia +fo,298,Torshavn,fo,fro,eu,dkk,🇫🇴,Faroe Islands +fr,33,Paris,fr,fra,eu,eur,🇫🇷,France +ga,241,Libreville,ga,gab,af,xaf,🇬🇦,Gabon +gb,44,London,gb,gbr,eu,gbp,🇬🇧,United Kingdom +gd,1473,St. George's,gd,grd,na,xcd,🇬🇩,Grenada +ge,995,Tbilisi,ge,geo,as,gel,🇬🇪,Georgia +gf,594,Cayenne,gf,guf,sa,eur,🇬🇫,French Guiana +gg,44,St Peter Port,gg,ggy,eu,gbp,🇬🇬,Guernsey +gh,233,Accra,gh,gha,af,ghs,🇬🇭,Ghana +gi,350,Gibraltar,gi,gib,eu,gip,🇬🇮,Gibraltar +gl,299,Nuuk,gl,grl,na,dkk,🇬🇱,Greenland +gm,220,Banjul,gm,gmb,af,gmd,🇬🇲,Gambia +gn,224,Conakry,gn,gin,af,gnf,🇬🇳,Guinea +gp,590,Basse-Terre,gp,glp,na,eur,🇬🇵,Guadeloupe +gq,240,Malabo,gq,gnq,af,xaf,🇬🇶,Equatorial Guinea +gr,30,Athens,gr,grc,eu,eur,🇬🇷,Greece +gs,500,Grytviken,gs,sgs,an,gbp,🇬🇸,South Georgia and the South Sandwich Islands +gt,502,Guatemala City,gt,gtm,na,gtq,🇬🇹,Guatemala +gu,1671,Hagatna,gu,gum,oc,usd,🇬🇺,Guam +gw,245,Bissau,gw,gnb,af,xof,🇬🇼,Guinea-Bissau +gy,592,Georgetown,gy,guy,sa,gyd,🇬🇾,Guyana +hk,852,Hong Kong,hk,hkg,as,hkd,🇭🇰,Hong Kong +hn,504,Tegucigalpa,hn,hnd,na,hnl,🇭🇳,Honduras +hr,385,Zagreb,hr,hrv,eu,hrk,🇭🇷,Croatia +ht,509,Port-au-Prince,ht,hti,na,htg,🇭🇹,Haiti +hu,36,Budapest,hu,hun,eu,huf,🇭🇺,Hungary +id,62,Jakarta,id,idn,as,idr,🇮🇩,Indonesia +ie,353,Dublin,ie,irl,eu,eur,🇮🇪,Ireland +il,972,Jerusalem,il,isr,as,ils,🇮🇱,Israel +im,44,"Douglas, Isle of Man",im,imn,eu,gbp,🇮🇲,Isle of Man +in,91,New Delhi,in,ind,as,inr,🇮🇳,India +io,246,Diego Garcia,io,iot,as,usd,🇮🇴,British Indian Ocean Territory +iq,964,Baghdad,iq,irq,as,iqd,🇮🇶,Iraq +ir,98,Tehran,ir,irn,as,irr,🇮🇷,Iran +is,354,Reykjavik,is,isl,eu,isk,🇮🇸,Iceland +it,39,Rome,it,ita,eu,eur,🇮🇹,Italy +je,44,Saint Helier,je,jey,eu,gbp,🇯🇪,Jersey +jm,1876,Kingston,jm,jam,na,jmd,🇯🇲,Jamaica +jo,962,Amman,jo,jor,as,jod,🇯🇴,Jordan +jp,81,Tokyo,jp,jpn,as,jpy,🇯🇵,Japan +ke,254,Nairobi,ke,ken,af,kes,🇰🇪,Kenya +kg,996,Bishkek,kg,kgz,as,kgs,🇰🇬,Kyrgyzstan +kh,855,Phnom Penh,kh,khm,as,khr,🇰🇭,Cambodia +ki,686,Tarawa,ki,kir,oc,aud,🇰🇮,Kiribati +km,269,Moroni,km,com,af,kmf,🇰🇲,Comoros +kn,1869,Basseterre,kn,kna,na,xcd,🇰🇳,Saint Kitts and Nevis +kp,850,Pyongyang,kp,prk,as,kpw,🇰🇵,North Korea +kr,82,Seoul,kr,kor,as,krw,🇰🇷,South Korea +kw,965,Kuwait City,kw,kwt,as,kwd,🇰🇼,Kuwait +ky,1345,George Town,ky,cym,na,kyd,🇰🇾,Cayman Islands +kz,7,Astana,kz,kaz,as,kzt,🇰🇿,Kazakhstan +la,856,Vientiane,la,lao,as,lak,🇱🇦,Laos +lb,961,Beirut,lb,lbn,as,lbp,🇱🇧,Lebanon +lc,1758,Castries,lc,lca,na,xcd,🇱🇨,Saint Lucia +li,423,Vaduz,li,lie,eu,chf,🇱🇮,Liechtenstein +lk,94,Colombo,lk,lka,as,lkr,🇱🇰,Sri Lanka +lr,231,Monrovia,lr,lbr,af,lrd,🇱🇷,Liberia +ls,266,Maseru,ls,lso,af,lsl,🇱🇸,Lesotho +lt,370,Vilnius,lt,ltu,eu,ltl,🇱🇹,Lithuania +lu,352,Luxembourg,lu,lux,eu,eur,🇱🇺,Luxembourg +lv,371,Riga,lv,lva,eu,eur,🇱🇻,Latvia +ly,218,Tripolis,ly,lby,af,lyd,🇱🇾,Libya +ma,212,Rabat,ma,mar,af,mad,🇲🇦,Morocco +mc,377,Monaco,mc,mco,eu,eur,🇲🇨,Monaco +md,373,Chisinau,md,mda,eu,mdl,🇲🇩,Moldova +me,382,Podgorica,me,mne,eu,eur,🇲🇪,Montenegro +mf,590,Marigot,mf,maf,na,eur,🇲🇫,Saint Martin +mg,261,Antananarivo,mg,mdg,af,mga,🇲🇬,Madagascar +mh,692,Majuro,mh,mhl,oc,usd,🇲🇭,Marshall Islands +mk,389,Skopje,mk,mkd,eu,mkd,🇲🇰,Macedonia +ml,223,Bamako,ml,mli,af,xof,🇲🇱,Mali +mm,95,Nay Pyi Taw,mm,mmr,as,mmk,🇲🇲,Myanmar +mn,976,Ulan Bator,mn,mng,as,mnt,🇲🇳,Mongolia +mo,853,Macao,mo,mac,as,mop,🇲🇴,Macao +mp,1670,Saipan,mp,mnp,oc,usd,🇲🇵,Northern Mariana Islands +mq,596,Fort-de-France,mq,mtq,na,eur,🇲🇶,Martinique +mr,222,Nouakchott,mr,mrt,af,mro,🇲🇷,Mauritania +ms,1664,Plymouth,ms,msr,na,xcd,🇲🇸,Montserrat +mt,356,Valletta,mt,mlt,eu,eur,🇲🇹,Malta +mu,230,Port Louis,mu,mus,af,mur,🇲🇺,Mauritius +mv,960,Male,mv,mdv,as,mvr,🇲🇻,Maldives +mw,265,Lilongwe,mw,mwi,af,mwk,🇲🇼,Malawi +mx,52,Mexico City,mx,mex,na,mxn,🇲🇽,Mexico +my,60,Kuala Lumpur,my,mys,as,myr,🇲🇾,Malaysia +mz,258,Maputo,mz,moz,af,mzn,🇲🇿,Mozambique +na,264,Windhoek,na,nam,af,nad,🇳🇦,Namibia +nc,687,Noumea,nc,ncl,oc,xpf,🇳🇨,New Caledonia +ne,227,Niamey,ne,ner,af,xof,🇳🇪,Niger +nf,672,Kingston,nf,nfk,oc,aud,🇳🇫,Norfolk Island +ng,234,Abuja,ng,nga,af,ngn,🇳🇬,Nigeria +ni,505,Managua,ni,nic,na,nio,🇳🇮,Nicaragua +nl,31,Amsterdam,nl,nld,eu,eur,🇳🇱,Netherlands +no,47,Oslo,no,nor,eu,nok,🇳🇴,Norway +np,977,Kathmandu,np,npl,as,npr,🇳🇵,Nepal +nr,674,Yaren,nr,nru,oc,aud,🇳🇷,Nauru +nu,683,Alofi,nu,niu,oc,nzd,🇳🇺,Niue +nz,64,Wellington,nz,nzl,oc,nzd,🇳🇿,New Zealand +om,968,Muscat,om,omn,as,omr,🇴🇲,Oman +pa,507,Panama City,pa,pan,na,pab,🇵🇦,Panama +pe,51,Lima,pe,per,sa,pen,🇵🇪,Peru +pf,689,Papeete,pf,pyf,oc,xpf,🇵🇫,French Polynesia +pg,675,Port Moresby,pg,png,oc,pgk,🇵🇬,Papua New Guinea +ph,63,Manila,ph,phl,as,php,🇵🇭,Philippines +pk,92,Islamabad,pk,pak,as,pkr,🇵🇰,Pakistan +pl,48,Warsaw,pl,pol,eu,pln,🇵🇱,Poland +pm,508,Saint-Pierre,pm,spm,na,eur,🇵🇲,Saint Pierre and Miquelon +pn,870,Adamstown,pn,pcn,oc,nzd,🇵🇳,Pitcairn +pr,1787,San Juan,pr,pri,na,usd,🇵🇷,Puerto Rico +ps,970,East Jerusalem,ps,pse,as,ils,🇵🇸,Palestinian Territory +pt,351,Lisbon,pt,prt,eu,eur,🇵🇹,Portugal +pw,680,Melekeok,pw,plw,oc,usd,🇵🇼,Palau +py,595,Asuncion,py,pry,sa,pyg,🇵🇾,Paraguay +qa,974,Doha,qa,qat,as,qar,🇶🇦,Qatar +re,262,Saint-Denis,re,reu,af,eur,🇷🇪,Reunion +ro,40,Bucharest,ro,rou,eu,ron,🇷🇴,Romania +rs,381,Belgrade,rs,srb,eu,rsd,🇷🇸,Serbia +ru,7,Moscow,ru,rus,eu,rub,🇷🇺,Russia +rw,250,Kigali,rw,rwa,af,rwf,🇷🇼,Rwanda +sa,966,Riyadh,sa,sau,as,sar,🇸🇦,Saudi Arabia +sb,677,Honiara,sb,slb,oc,sbd,🇸🇧,Solomon Islands +sc,248,Victoria,sc,syc,af,scr,🇸🇨,Seychelles +sd,249,Khartoum,sd,sdn,af,sdg,🇸🇩,Sudan +se,46,Stockholm,se,swe,eu,sek,🇸🇪,Sweden +sg,65,Singapur,sg,sgp,as,sgd,🇸🇬,Singapore +sh,290,Jamestown,sh,shn,af,shp,🇸🇭,Saint Helena +si,386,Ljubljana,si,svn,eu,eur,🇸🇮,Slovenia +sj,47,Longyearbyen,sj,sjm,eu,nok,🇸🇯,Svalbard and Jan Mayen +sk,421,Bratislava,sk,svk,eu,eur,🇸🇰,Slovakia +sl,232,Freetown,sl,sle,af,sll,🇸🇱,Sierra Leone +sm,378,San Marino,sm,smr,eu,eur,🇸🇲,San Marino +sn,221,Dakar,sn,sen,af,xof,🇸🇳,Senegal +so,252,Mogadishu,so,som,af,sos,🇸🇴,Somalia +sr,597,Paramaribo,sr,sur,sa,srd,🇸🇷,Suriname +ss,211,Juba,ss,ssd,af,ssp,🇸🇸,South Sudan +st,239,Sao Tome,st,stp,af,std,🇸🇹,Sao Tome and Principe +sv,503,San Salvador,sv,slv,na,usd,🇸🇻,El Salvador +sx,599,Philipsburg,sx,sxm,na,ang,🇸🇽,Sint Maarten +sy,963,Damascus,sy,syr,as,syp,🇸🇾,Syria +sz,268,Mbabane,sz,swz,af,szl,🇸🇿,Swaziland +tc,1649,Cockburn Town,tc,tca,na,usd,🇹🇨,Turks and Caicos Islands +td,235,N'Djamena,td,tcd,af,xaf,🇹🇩,Chad +tf,,Port-aux-Francais,tf,atf,an,eur,🇹🇫,French Southern Territories +tg,228,Lome,tg,tgo,af,xof,🇹🇬,Togo +th,66,Bangkok,th,tha,as,thb,🇹🇭,Thailand +tj,992,Dushanbe,tj,tjk,as,tjs,🇹🇯,Tajikistan +tk,690,,tk,tkl,oc,nzd,🇹🇰,Tokelau +tl,670,Dili,tl,tls,oc,usd,🇹🇱,East Timor +tm,993,Ashgabat,tm,tkm,as,tmt,🇹🇲,Turkmenistan +tn,216,Tunis,tn,tun,af,tnd,🇹🇳,Tunisia +to,676,Nuku'alofa,to,ton,oc,top,🇹🇴,Tonga +tr,90,Ankara,tr,tur,as,try,🇹🇷,Turkey +tt,1868,Port of Spain,tt,tto,na,ttd,🇹🇹,Trinidad and Tobago +tv,688,Funafuti,tv,tuv,oc,aud,🇹🇻,Tuvalu +tw,886,Taipei,tw,twn,as,twd,🇹🇼,Taiwan +tz,255,Dodoma,tz,tza,af,tzs,🇹🇿,Tanzania +ua,380,Kiev,ua,ukr,eu,uah,🇺🇦,Ukraine +ug,256,Kampala,ug,uga,af,ugx,🇺🇬,Uganda +um,246,,um,umi,oc,usd,🇺🇲,United States Minor Outlying Islands +us,1,Washington,us,usa,na,usd,🇺🇸,United States +uy,598,Montevideo,uy,ury,sa,uyu,🇺🇾,Uruguay +uz,998,Tashkent,uz,uzb,as,uzs,🇺🇿,Uzbekistan +va,379,Vatican City,va,vat,eu,eur,🇻🇦,Vatican +vc,1784,Kingstown,vc,vct,na,xcd,🇻🇨,Saint Vincent and the Grenadines +ve,58,Caracas,ve,ven,sa,vef,🇻🇪,Venezuela +vg,1284,Road Town,vg,vgb,na,usd,🇻🇬,British Virgin Islands +vi,1340,Charlotte Amalie,vi,vir,na,usd,🇻🇮,U.S. Virgin Islands +vn,84,Hanoi,vn,vnm,as,vnd,🇻🇳,Vietnam +vu,678,Port Vila,vu,vut,oc,vuv,🇻🇺,Vanuatu +wf,681,Mata Utu,wf,wlf,oc,xpf,🇼🇫,Wallis and Futuna +ws,685,Apia,ws,wsm,oc,wst,🇼🇸,Samoa +xk,383,Pristina,xk,xkx,eu,eur,🇽🇰,Kosovo +ye,967,Sanaa,ye,yem,as,yer,🇾🇪,Yemen +yt,262,Mamoudzou,yt,myt,af,eur,🇾🇹,Mayotte +za,27,Pretoria,za,zaf,af,zar,🇿🇦,South Africa +zm,260,Lusaka,zm,zmb,af,zmk,🇿🇲,Zambia +zw,263,Harare,zw,zwe,af,zwl,🇿🇼,Zimbabwe \ No newline at end of file diff --git a/packages/countries-en/src/CountriesEnServiceProvider.php b/packages/countries-en/src/CountriesEnServiceProvider.php new file mode 100644 index 0000000..d5663a3 --- /dev/null +++ b/packages/countries-en/src/CountriesEnServiceProvider.php @@ -0,0 +1,15 @@ + 'string', ]; - protected $source = 'countries'; - public function airlines() { return $this->hasMany(Airline::class); diff --git a/packages/model/composer.json b/packages/model/composer.json new file mode 100644 index 0000000..3e7de34 --- /dev/null +++ b/packages/model/composer.json @@ -0,0 +1,31 @@ +{ + "name": "squirephp/model", + "description": "A library containing the base Squire model class.", + "keywords": ["squire"], + "license": "MIT", + "homepage": "https://github.com/squirephp", + "support": { + "issues": "https://github.com/squirephp/squire/issues", + "source": "https://github.com/squirephp/squire" + }, + "authors": [ + { + "name": "Dan Harrin", + "email": "dan@danharrin.com" + } + ], + "require": { + "php": "^7.2|^8.0", + "calebporzio/sushi": "^2.1", + "illuminate/database": "^6.0 || ^7.0 || ^8.0" + }, + "autoload": { + "psr-4": { + "Squire\\": "src" + } + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev" +} diff --git a/packages/model/src/Model.php b/packages/model/src/Model.php new file mode 100644 index 0000000..a0da325 --- /dev/null +++ b/packages/model/src/Model.php @@ -0,0 +1,102 @@ + function () use ($cachePath) { + static::setSqliteConnection($cachePath); + }, + 'cache-file-not-found-or-stale' => function () use ($cachePath, $sourcePath, $instance) { + file_put_contents($cachePath, ''); + + static::setSqliteConnection($cachePath); + + $instance->migrate(); + + touch($cachePath, filemtime($sourcePath)); + } + ]; + + switch (true) { + case file_exists($cachePath) && filemtime($sourcePath) <= filemtime($cachePath): + $states['cache-file-found-and-up-to-date'](); + break; + + case file_exists($cacheDirectory) && is_writable($cacheDirectory): + $states['cache-file-not-found-or-stale'](); + dd('bad'); + break; + + default: + $states['cache-file-not-found-or-stale'](); + break; + } + } + + public function getMap() + { + $map = collect($this->map); + + if ($map->count()) return $map; + + return collect($this->rawData->first())->mapWithKeys(function ($value, $columnName) { + return [$columnName => $columnName]; + }); + } + + public function getRows() + { + $this->rawData = collect(Repository::fetchData(static::class)); + + $map = $this->getMap(); + + return $this->rawData->map(function ($row) use ($map) { + $record = []; + + foreach ($map as $columnName => $sourceColumnName) { + $record[$columnName] = $row[$sourceColumnName]; + } + + return $record; + })->toArray(); + } + + public function getSchema() + { + $schema = collect($this->schema ?? []); + + return $this->getMap() + ->filter(function ($sourceColumnName, $columnName) use ($schema) { + return $schema->get($sourceColumnName, false); + }) + ->mapWithKeys(function ($sourceColumnName, $columnName) use ($schema) { + return [$columnName => $schema->get($sourceColumnName)]; + })->toArray(); + } +} \ No newline at end of file diff --git a/packages/repository/composer.json b/packages/repository/composer.json new file mode 100644 index 0000000..021a3db --- /dev/null +++ b/packages/repository/composer.json @@ -0,0 +1,40 @@ +{ + "name": "squirephp/repository", + "description": "A library containing the Squire repository.", + "keywords": ["squire"], + "license": "MIT", + "homepage": "https://github.com/squirephp", + "support": { + "issues": "https://github.com/squirephp/squire/issues", + "source": "https://github.com/squirephp/squire" + }, + "authors": [ + { + "name": "Dan Harrin", + "email": "dan@danharrin.com" + } + ], + "require": { + "php": "^7.2|^8.0", + "illuminate/support": "^6.0 || ^7.0 || ^8.0" + }, + "autoload": { + "psr-4": { + "Squire\\": "src" + } + }, + "extra": { + "laravel": { + "providers": [ + "Squire\\RepositoryServiceProvider" + ], + "aliases": { + "RepositoryManager": "Squire\\Repository\\Facades\\Repository" + } + } + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev" +} diff --git a/packages/repository/src/Exceptions/SourceNotFoundException.php b/packages/repository/src/Exceptions/SourceNotFoundException.php new file mode 100644 index 0000000..c2dd8ca --- /dev/null +++ b/packages/repository/src/Exceptions/SourceNotFoundException.php @@ -0,0 +1,15 @@ +getSource($name, $locale); + + return $this->fetchDataFromSource($source); + } + + public function fetchDataFromSource($source) + { + $data = collect(file($source)) + ->map(function ($line) { + return collect(str_getcsv($line)); + }); + + $data = $data->map(function ($line) use ($data) { + return $data->first()->combine($line); + }); + + $data->shift(); + + return $data; + } + + public function getLocale($name) + { + $appLocale = App::getLocale(); + if ($this->sourceIsRegistered($name, $appLocale)) return $appLocale; + + $appFallbackLocale = App::getFallbackLocale(); + if ($this->sourceIsRegistered($name, $appFallbackLocale)) return $appFallbackLocale; + + return array_key_first($this->getSources($name)); + } + + public function getSource($name, $locale = null) + { + if ($locale && ! $this->sourceIsRegistered($name, $locale)) + throw new TranslationNotFoundException($name, $locale); + + if (! $locale) $locale = $this->getLocale($name); + + return $this->getSources($name)[$locale]; + } + + public function getSources($name = null) + { + if (! $name) return $this->sources; + + if (! $this->sourceIsRegistered($name) || ! count($this->sources[$name])) + throw new SourceNotFoundException($name); + + return $this->sources[$name]; + } + + public function registerSource($name, $locale, $path) + { + if (! $this->sourceIsRegistered($name)) $this->sources[$name] = []; + + $this->sources[$name][$locale] = $path; + } + + public function sourceIsRegistered($name, $locale = null) + { + if (! $locale) return array_key_exists($name, $this->sources); + + return array_key_exists($name, $this->sources) && array_key_exists($locale, $this->sources[$name]); + } +} \ No newline at end of file diff --git a/packages/repository/src/RepositoryServiceProvider.php b/packages/repository/src/RepositoryServiceProvider.php new file mode 100644 index 0000000..545727b --- /dev/null +++ b/packages/repository/src/RepositoryServiceProvider.php @@ -0,0 +1,12 @@ + RepositoryManager::class, + ]; +} \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index 290242a..f5ce85d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,10 +1,12 @@ + - src + packages + tests diff --git a/src/Model.php b/src/Model.php deleted file mode 100644 index e69484a..0000000 --- a/src/Model.php +++ /dev/null @@ -1,75 +0,0 @@ -map); - - if ($map->count()) return $map; - - return collect($this->rawData->first())->mapWithKeys(function ($value, $columnName) { - return [$columnName => $columnName]; - }); - } - - public function getRows() - { - if (! $this->rawData) { - $this->rawData = collect(file(__DIR__."/../data/{$this->source}.csv")) - ->map(function ($line) { - return collect(str_getcsv($line)); - }); - - $this->rawData = $this->rawData->map(function ($line) { - return $this->rawData->first()->combine($line); - }); - - $this->rawData->shift(); - } - - $this->rawData = collect($this->rawData); - - $map = $this->getMap(); - - return $this->rawData->map(function ($row) use ($map) { - $record = []; - - foreach ($map as $columnName => $sourceColumnName) { - $record[$columnName] = $row[$sourceColumnName]; - } - - return $record; - })->toArray(); - } - - public function getSchema() - { - $schema = collect($this->schema ?? []); - - return $this->getMap() - ->filter(function ($sourceColumnName, $columnName) use ($schema) { - return $schema->get($sourceColumnName, false); - }) - ->mapWithKeys(function ($sourceColumnName, $columnName) use ($schema) { - return [$columnName => $schema->get($sourceColumnName)]; - })->toArray(); - } -} diff --git a/src/Models/Airline.php b/src/Models/Airline.php deleted file mode 100644 index 1c6d019..0000000 --- a/src/Models/Airline.php +++ /dev/null @@ -1,20 +0,0 @@ -belongsTo(Country::class); - } - - public function continent() - { - return $this->hasOneThrough(Continent::class, Country::class); - } -} \ No newline at end of file diff --git a/src/Models/Airport.php b/src/Models/Airport.php deleted file mode 100644 index 7579e06..0000000 --- a/src/Models/Airport.php +++ /dev/null @@ -1,20 +0,0 @@ -hasOneThrough(Country::class, Region::class); - } - - public function region() - { - return $this->belongsTo(Region::class); - } -} \ No newline at end of file diff --git a/src/Models/Continent.php b/src/Models/Continent.php deleted file mode 100644 index ca3118f..0000000 --- a/src/Models/Continent.php +++ /dev/null @@ -1,20 +0,0 @@ -hasMany(Country::class); - } - - public function regions() - { - return $this->hasManyThrough(Region::class, Country::class); - } -} \ No newline at end of file diff --git a/src/Models/Counties/GbCounty.php b/src/Models/Counties/GbCounty.php deleted file mode 100644 index 66dd61d..0000000 --- a/src/Models/Counties/GbCounty.php +++ /dev/null @@ -1,16 +0,0 @@ -belongsTo(Region::class); - } -} \ No newline at end of file diff --git a/src/Models/Currency.php b/src/Models/Currency.php deleted file mode 100644 index 1709f36..0000000 --- a/src/Models/Currency.php +++ /dev/null @@ -1,15 +0,0 @@ -hasMany(Country::class); - } -} \ No newline at end of file diff --git a/src/Models/Region.php b/src/Models/Region.php deleted file mode 100644 index c98c323..0000000 --- a/src/Models/Region.php +++ /dev/null @@ -1,31 +0,0 @@ -hasMany(Airport::class); - } - - public function continent() - { - return $this->hasOneThrough(Continent::class, Country::class); - } - - public function country() - { - return $this->belongsTo(Country::class); - } - - public function gbCounties() - { - return $this->hasMany(GbCounty::class); - } -} \ No newline at end of file diff --git a/tests/SquireTest.php b/tests/SquireTest.php index 99e5e58..c6eca6e 100644 --- a/tests/SquireTest.php +++ b/tests/SquireTest.php @@ -2,29 +2,37 @@ namespace Tests; +use Illuminate\Support\Facades\App; use Orchestra\Testbench\TestCase; +use Squire\Facades\Repository; use Squire\Model; class SquireTest extends TestCase { /** @test */ - function basic_usage() + public function basic_usage() { + Repository::registerSource(Foo::class, App::getLocale(), __DIR__.'/data/foo.csv'); + $this->assertEquals(Foo::count(), 2); $this->assertEquals(Foo::first()->foo, 'bar'); $this->assertEquals(Foo::where('bob', 'law')->first()->foo, 'baz'); } /** @test */ - function custom_column_map() + public function custom_column_map() { + Repository::registerSource(Bar::class, App::getLocale(), __DIR__.'/data/bar.csv'); + $this->assertEquals(Bar::first()->new_foo, 'bar'); $this->assertEquals(Bar::where('new_bob', 'law')->first()->new_foo, 'baz'); } /** @test */ - function custom_column_map_and_schema() + public function custom_column_map_and_schema() { + Repository::registerSource(Baz::class, App::getLocale(), __DIR__.'/data/baz.csv'); + $this->assertEquals(Baz::first()->new_foo, '1.0'); $this->assertEquals(Baz::first()->new_bob, '1'); } diff --git a/tests/data/bar.csv b/tests/data/bar.csv new file mode 100644 index 0000000..8240f8a --- /dev/null +++ b/tests/data/bar.csv @@ -0,0 +1,3 @@ +foo,bob +bar,lob +baz,law \ No newline at end of file diff --git a/tests/data/baz.csv b/tests/data/baz.csv new file mode 100644 index 0000000..9d2260d --- /dev/null +++ b/tests/data/baz.csv @@ -0,0 +1,2 @@ +foo,bob +1.0,1.0 \ No newline at end of file diff --git a/tests/data/foo.csv b/tests/data/foo.csv new file mode 100644 index 0000000..8240f8a --- /dev/null +++ b/tests/data/foo.csv @@ -0,0 +1,3 @@ +foo,bob +bar,lob +baz,law \ No newline at end of file