composer.phar 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536515375153851539515405154151542515435154451545515465154751548515495155051551515525155351554515555155651557515585155951560515615156251563515645156551566515675156851569515705157151572515735157451575515765157751578515795158051581515825158351584515855158651587515885158951590515915159251593515945159551596515975159851599516005160151602516035160451605516065160751608516095161051611516125161351614516155161651617516185161951620516215162251623516245162551626516275162851629516305163151632516335163451635516365163751638516395164051641516425164351644516455164651647516485164951650516515165251653516545165551656516575165851659516605166151662516635166451665516665166751668516695167051671516725167351674516755167651677516785167951680516815168251683516845168551686516875168851689516905169151692516935169451695516965169751698516995170051701517025170351704517055170651707517085170951710517115171251713517145171551716517175171851719517205172151722517235172451725517265172751728517295173051731517325173351734517355173651737517385173951740517415174251743517445174551746517475174851749517505175151752517535175451755517565175751758517595176051761517625176351764517655176651767517685176951770517715177251773517745177551776517775177851779517805178151782517835178451785517865178751788517895179051791517925179351794517955179651797517985179951800518015180251803518045180551806518075180851809518105181151812518135181451815518165181751818518195182051821518225182351824518255182651827518285182951830518315183251833518345183551836518375183851839518405184151842518435184451845518465184751848518495185051851518525185351854518555185651857518585185951860518615186251863518645186551866518675186851869518705187151872518735187451875518765187751878518795188051881518825188351884518855188651887518885188951890518915189251893518945189551896518975189851899519005190151902519035190451905519065190751908519095191051911519125191351914519155191651917519185191951920519215192251923519245192551926519275192851929519305193151932519335193451935519365193751938519395194051941519425194351944519455194651947519485194951950519515195251953519545195551956519575195851959519605196151962519635196451965519665196751968519695197051971519725197351974519755197651977519785197951980519815198251983519845198551986519875198851989519905199151992519935199451995519965199751998519995200052001520025200352004520055200652007520085200952010520115201252013520145201552016520175201852019520205202152022520235202452025520265202752028520295203052031520325203352034520355203652037520385203952040520415204252043520445204552046520475204852049520505205152052520535205452055520565205752058520595206052061520625206352064520655206652067520685206952070520715207252073520745207552076520775207852079520805208152082520835208452085520865208752088520895209052091520925209352094520955209652097520985209952100521015210252103521045210552106521075210852109521105211152112521135211452115521165211752118521195212052121521225212352124521255212652127521285212952130521315213252133521345213552136521375213852139521405214152142521435214452145521465214752148521495215052151521525215352154521555215652157521585215952160521615216252163521645216552166521675216852169521705217152172521735217452175521765217752178521795218052181521825218352184521855218652187521885218952190521915219252193521945219552196521975219852199522005220152202522035220452205522065220752208522095221052211522125221352214522155221652217522185221952220522215222252223522245222552226522275222852229522305223152232522335223452235522365223752238522395224052241522425224352244522455224652247522485224952250522515225252253522545225552256522575225852259522605226152262522635226452265522665226752268522695227052271522725227352274522755227652277522785227952280522815228252283522845228552286522875228852289522905229152292522935229452295522965229752298522995230052301523025230352304523055230652307523085230952310523115231252313523145231552316523175231852319523205232152322523235232452325523265232752328523295233052331523325233352334523355233652337523385233952340523415234252343523445234552346523475234852349523505235152352523535235452355523565235752358523595236052361523625236352364523655236652367523685236952370523715237252373523745237552376523775237852379523805238152382523835238452385523865238752388523895239052391523925239352394523955239652397523985239952400524015240252403524045240552406524075240852409524105241152412524135241452415524165241752418524195242052421524225242352424524255242652427524285242952430524315243252433524345243552436524375243852439524405244152442524435244452445524465244752448524495245052451524525245352454524555245652457524585245952460524615246252463524645246552466524675246852469524705247152472524735247452475524765247752478524795248052481524825248352484524855248652487524885248952490524915249252493524945249552496524975249852499525005250152502525035250452505525065250752508525095251052511525125251352514525155251652517525185251952520525215252252523525245252552526525275252852529525305253152532525335253452535525365253752538525395254052541525425254352544525455254652547525485254952550525515255252553525545255552556525575255852559525605256152562525635256452565525665256752568525695257052571525725257352574525755257652577525785257952580525815258252583525845258552586525875258852589525905259152592525935259452595525965259752598525995260052601526025260352604526055260652607526085260952610526115261252613526145261552616526175261852619526205262152622526235262452625526265262752628526295263052631526325263352634526355263652637526385263952640526415264252643526445264552646526475264852649526505265152652526535265452655526565265752658526595266052661526625266352664526655266652667526685266952670526715267252673526745267552676526775267852679526805268152682526835268452685526865268752688526895269052691526925269352694526955269652697526985269952700527015270252703527045270552706527075270852709527105271152712527135271452715527165271752718527195272052721527225272352724527255272652727527285272952730527315273252733527345273552736527375273852739527405274152742527435274452745527465274752748527495275052751527525275352754527555275652757527585275952760527615276252763527645276552766527675276852769527705277152772527735277452775527765277752778527795278052781527825278352784527855278652787527885278952790527915279252793527945279552796527975279852799528005280152802528035280452805528065280752808528095281052811528125281352814528155281652817528185281952820528215282252823528245282552826528275282852829528305283152832528335283452835528365283752838528395284052841528425284352844528455284652847528485284952850528515285252853528545285552856528575285852859528605286152862528635286452865528665286752868528695287052871528725287352874528755287652877528785287952880528815288252883528845288552886528875288852889528905289152892528935289452895528965289752898528995290052901529025290352904529055290652907529085290952910529115291252913529145291552916529175291852919529205292152922529235292452925529265292752928529295293052931529325293352934529355293652937529385293952940529415294252943529445294552946529475294852949529505295152952529535295452955529565295752958529595296052961529625296352964529655296652967529685296952970529715297252973529745297552976529775297852979529805298152982529835298452985529865298752988529895299052991529925299352994529955299652997529985299953000530015300253003530045300553006530075300853009530105301153012530135301453015530165301753018530195302053021530225302353024530255302653027530285302953030530315303253033530345303553036530375303853039530405304153042530435304453045530465304753048530495305053051530525305353054530555305653057530585305953060530615306253063530645306553066530675306853069530705307153072530735307453075530765307753078530795308053081530825308353084530855308653087530885308953090530915309253093530945309553096530975309853099531005310153102531035310453105531065310753108531095311053111531125311353114531155311653117531185311953120531215312253123531245312553126531275312853129531305313153132531335313453135531365313753138531395314053141531425314353144531455314653147531485314953150531515315253153531545315553156531575315853159531605316153162531635316453165531665316753168531695317053171531725317353174531755317653177531785317953180531815318253183531845318553186531875318853189531905319153192531935319453195531965319753198531995320053201532025320353204532055320653207532085320953210532115321253213532145321553216532175321853219532205322153222532235322453225532265322753228532295323053231532325323353234532355323653237532385323953240532415324253243532445324553246532475324853249532505325153252532535325453255532565325753258532595326053261532625326353264532655326653267532685326953270532715327253273532745327553276532775327853279532805328153282532835328453285532865328753288532895329053291532925329353294532955329653297532985329953300533015330253303533045330553306533075330853309533105331153312533135331453315533165331753318533195332053321533225332353324533255332653327533285332953330533315333253333533345333553336533375333853339533405334153342533435334453345533465334753348533495335053351533525335353354533555335653357533585335953360533615336253363533645336553366533675336853369533705337153372533735337453375533765337753378533795338053381533825338353384533855338653387533885338953390533915339253393533945339553396533975339853399534005340153402534035340453405534065340753408534095341053411534125341353414534155341653417534185341953420534215342253423534245342553426534275342853429534305343153432534335343453435534365343753438534395344053441534425344353444534455344653447534485344953450534515345253453534545345553456534575345853459534605346153462534635346453465534665346753468534695347053471534725347353474534755347653477534785347953480534815348253483534845348553486534875348853489534905349153492534935349453495534965349753498534995350053501535025350353504535055350653507535085350953510535115351253513535145351553516535175351853519535205352153522535235352453525535265352753528535295353053531535325353353534535355353653537535385353953540535415354253543535445354553546535475354853549535505355153552535535355453555535565355753558535595356053561535625356353564535655356653567535685356953570535715357253573535745357553576535775357853579535805358153582535835358453585535865358753588535895359053591535925359353594535955359653597535985359953600536015360253603536045360553606536075360853609536105361153612536135361453615536165361753618536195362053621536225362353624536255362653627536285362953630536315363253633536345363553636536375363853639536405364153642536435364453645536465364753648536495365053651536525365353654536555365653657536585365953660536615366253663536645366553666536675366853669536705367153672536735367453675536765367753678536795368053681536825368353684536855368653687536885368953690536915369253693536945369553696536975369853699537005370153702537035370453705537065370753708537095371053711537125371353714537155371653717537185371953720537215372253723537245372553726537275372853729537305373153732537335373453735537365373753738537395374053741537425374353744537455374653747537485374953750537515375253753537545375553756537575375853759537605376153762537635376453765537665376753768537695377053771537725377353774537755377653777537785377953780537815378253783537845378553786537875378853789537905379153792537935379453795537965379753798537995380053801538025380353804538055380653807538085380953810538115381253813538145381553816538175381853819538205382153822538235382453825538265382753828538295383053831538325383353834538355383653837538385383953840538415384253843538445384553846538475384853849538505385153852538535385453855538565385753858538595386053861538625386353864538655386653867538685386953870538715387253873538745387553876538775387853879538805388153882538835388453885538865388753888538895389053891538925389353894538955389653897538985389953900539015390253903539045390553906539075390853909539105391153912539135391453915539165391753918539195392053921539225392353924539255392653927539285392953930539315393253933539345393553936539375393853939539405394153942539435394453945539465394753948539495395053951539525395353954539555395653957539585395953960539615396253963539645396553966539675396853969539705397153972539735397453975539765397753978539795398053981539825398353984539855398653987539885398953990539915399253993539945399553996539975399853999540005400154002540035400454005540065400754008540095401054011540125401354014540155401654017540185401954020540215402254023540245402554026540275402854029540305403154032540335403454035540365403754038540395404054041540425404354044540455404654047540485404954050540515405254053540545405554056540575405854059540605406154062540635406454065540665406754068540695407054071540725407354074540755407654077540785407954080540815408254083540845408554086540875408854089540905409154092540935409454095540965409754098540995410054101541025410354104541055410654107541085410954110541115411254113541145411554116541175411854119541205412154122541235412454125541265412754128541295413054131541325413354134541355413654137541385413954140541415414254143541445414554146541475414854149541505415154152541535415454155541565415754158541595416054161541625416354164541655416654167541685416954170541715417254173541745417554176541775417854179541805418154182541835418454185541865418754188541895419054191541925419354194541955419654197541985419954200542015420254203542045420554206542075420854209542105421154212542135421454215542165421754218542195422054221542225422354224542255422654227542285422954230542315423254233542345423554236542375423854239542405424154242542435424454245542465424754248542495425054251542525425354254542555425654257542585425954260542615426254263542645426554266542675426854269542705427154272542735427454275542765427754278542795428054281542825428354284542855428654287542885428954290542915429254293542945429554296542975429854299543005430154302543035430454305543065430754308543095431054311543125431354314543155431654317543185431954320543215432254323543245432554326543275432854329543305433154332543335433454335543365433754338543395434054341543425434354344543455434654347543485434954350543515435254353543545435554356543575435854359543605436154362543635436454365543665436754368543695437054371543725437354374543755437654377543785437954380543815438254383543845438554386543875438854389543905439154392543935439454395543965439754398543995440054401544025440354404544055440654407544085440954410544115441254413544145441554416544175441854419544205442154422544235442454425544265442754428544295443054431544325443354434544355443654437544385443954440544415444254443544445444554446544475444854449544505445154452544535445454455544565445754458544595446054461544625446354464544655446654467544685446954470544715447254473544745447554476544775447854479544805448154482544835448454485544865448754488544895449054491544925449354494544955449654497544985449954500545015450254503545045450554506545075450854509545105451154512545135451454515545165451754518545195452054521545225452354524545255452654527545285452954530545315453254533545345453554536545375453854539545405454154542545435454454545545465454754548545495455054551545525455354554545555455654557545585455954560545615456254563545645456554566545675456854569545705457154572545735457454575545765457754578545795458054581545825458354584545855458654587545885458954590545915459254593545945459554596545975459854599546005460154602546035460454605546065460754608546095461054611546125461354614546155461654617546185461954620546215462254623546245462554626546275462854629546305463154632546335463454635546365463754638546395464054641546425464354644546455464654647546485464954650546515465254653546545465554656546575465854659546605466154662546635466454665546665466754668546695467054671546725467354674546755467654677546785467954680546815468254683546845468554686546875468854689546905469154692546935469454695546965469754698546995470054701547025470354704547055470654707547085470954710547115471254713547145471554716547175471854719547205472154722547235472454725547265472754728547295473054731547325473354734547355473654737547385473954740547415474254743547445474554746547475474854749547505475154752547535475454755547565475754758547595476054761547625476354764547655476654767547685476954770547715477254773547745477554776547775477854779547805478154782547835478454785547865478754788547895479054791547925479354794547955479654797547985479954800548015480254803548045480554806548075480854809548105481154812548135481454815548165481754818548195482054821548225482354824548255482654827548285482954830548315483254833548345483554836548375483854839548405484154842548435484454845548465484754848548495485054851548525485354854548555485654857548585485954860548615486254863548645486554866548675486854869548705487154872548735487454875548765487754878548795488054881548825488354884548855488654887548885488954890548915489254893548945489554896548975489854899549005490154902549035490454905549065490754908549095491054911549125491354914549155491654917549185491954920549215492254923549245492554926549275492854929549305493154932549335493454935549365493754938549395494054941549425494354944549455494654947549485494954950549515495254953549545495554956549575495854959549605496154962549635496454965549665496754968549695497054971549725497354974549755497654977549785497954980549815498254983549845498554986549875498854989549905499154992549935499454995549965499754998549995500055001550025500355004550055500655007550085500955010550115501255013550145501555016550175501855019550205502155022550235502455025550265502755028550295503055031550325503355034550355503655037550385503955040550415504255043550445504555046550475504855049550505505155052550535505455055550565505755058550595506055061550625506355064550655506655067550685506955070550715507255073550745507555076550775507855079550805508155082550835508455085550865508755088550895509055091550925509355094550955509655097550985509955100551015510255103551045510555106551075510855109551105511155112551135511455115551165511755118551195512055121551225512355124551255512655127551285512955130551315513255133551345513555136551375513855139551405514155142551435514455145551465514755148551495515055151551525515355154551555515655157551585515955160551615516255163551645516555166551675516855169551705517155172551735517455175551765517755178551795518055181551825518355184551855518655187551885518955190551915519255193551945519555196551975519855199552005520155202552035520455205552065520755208552095521055211552125521355214552155521655217552185521955220552215522255223552245522555226552275522855229552305523155232552335523455235552365523755238552395524055241552425524355244552455524655247552485524955250552515525255253552545525555256552575525855259552605526155262552635526455265552665526755268552695527055271552725527355274552755527655277552785527955280552815528255283552845528555286552875528855289552905529155292552935529455295552965529755298552995530055301553025530355304553055530655307553085530955310553115531255313553145531555316553175531855319553205532155322553235532455325553265532755328553295533055331553325533355334553355533655337553385533955340553415534255343553445534555346553475534855349553505535155352553535535455355553565535755358553595536055361553625536355364553655536655367553685536955370553715537255373553745537555376553775537855379553805538155382553835538455385553865538755388553895539055391553925539355394553955539655397553985539955400554015540255403554045540555406554075540855409554105541155412554135541455415554165541755418554195542055421554225542355424554255542655427554285542955430554315543255433554345543555436554375543855439554405544155442554435544455445554465544755448554495545055451554525545355454554555545655457554585545955460554615546255463554645546555466554675546855469554705547155472554735547455475554765547755478554795548055481554825548355484554855548655487554885548955490554915549255493554945549555496554975549855499555005550155502555035550455505555065550755508555095551055511555125551355514555155551655517555185551955520555215552255523555245552555526555275552855529555305553155532555335553455535555365553755538555395554055541555425554355544555455554655547555485554955550555515555255553555545555555556555575555855559555605556155562555635556455565555665556755568555695557055571555725557355574555755557655577555785557955580555815558255583555845558555586555875558855589555905559155592555935559455595555965559755598555995560055601556025560355604556055560655607556085560955610556115561255613556145561555616556175561855619556205562155622556235562455625556265562755628556295563055631556325563355634556355563655637556385563955640556415564255643556445564555646556475564855649556505565155652556535565455655556565565755658556595566055661556625566355664556655566655667556685566955670556715567255673556745567555676556775567855679556805568155682556835568455685556865568755688556895569055691556925569355694556955569655697556985569955700557015570255703557045570555706557075570855709557105571155712557135571455715557165571755718557195572055721557225572355724557255572655727557285572955730557315573255733557345573555736557375573855739557405574155742557435574455745557465574755748557495575055751557525575355754557555575655757557585575955760557615576255763557645576555766557675576855769557705577155772557735577455775557765577755778557795578055781557825578355784557855578655787557885578955790557915579255793557945579555796557975579855799558005580155802558035580455805558065580755808558095581055811558125581355814558155581655817558185581955820558215582255823558245582555826558275582855829558305583155832558335583455835558365583755838558395584055841558425584355844558455584655847558485584955850558515585255853558545585555856558575585855859558605586155862558635586455865558665586755868558695587055871558725587355874558755587655877558785587955880558815588255883558845588555886558875588855889558905589155892558935589455895558965589755898558995590055901559025590355904559055590655907559085590955910559115591255913559145591555916559175591855919559205592155922559235592455925559265592755928559295593055931559325593355934559355593655937559385593955940559415594255943559445594555946559475594855949559505595155952559535595455955559565595755958559595596055961559625596355964559655596655967559685596955970559715597255973559745597555976559775597855979559805598155982559835598455985559865598755988559895599055991559925599355994559955599655997559985599956000560015600256003560045600556006560075600856009560105601156012560135601456015560165601756018560195602056021560225602356024560255602656027560285602956030560315603256033560345603556036560375603856039560405604156042560435604456045560465604756048560495605056051560525605356054560555605656057560585605956060560615606256063560645606556066560675606856069560705607156072560735607456075560765607756078560795608056081560825608356084560855608656087560885608956090560915609256093560945609556096560975609856099561005610156102561035610456105561065610756108561095611056111561125611356114561155611656117561185611956120561215612256123561245612556126561275612856129561305613156132561335613456135561365613756138561395614056141561425614356144561455614656147561485614956150561515615256153561545615556156561575615856159561605616156162561635616456165561665616756168561695617056171561725617356174561755617656177561785617956180561815618256183561845618556186561875618856189561905619156192561935619456195561965619756198561995620056201562025620356204562055620656207562085620956210562115621256213562145621556216562175621856219562205622156222562235622456225562265622756228562295623056231562325623356234562355623656237562385623956240562415624256243562445624556246562475624856249562505625156252562535625456255562565625756258562595626056261562625626356264562655626656267562685626956270562715627256273562745627556276562775627856279562805628156282562835628456285562865628756288562895629056291562925629356294562955629656297562985629956300563015630256303563045630556306563075630856309563105631156312563135631456315563165631756318563195632056321563225632356324563255632656327563285632956330563315633256333563345633556336563375633856339563405634156342563435634456345563465634756348563495635056351563525635356354563555635656357563585635956360563615636256363563645636556366563675636856369563705637156372563735637456375563765637756378563795638056381563825638356384563855638656387563885638956390563915639256393563945639556396563975639856399564005640156402564035640456405564065640756408564095641056411564125641356414564155641656417564185641956420564215642256423564245642556426564275642856429564305643156432564335643456435564365643756438564395644056441564425644356444564455644656447564485644956450564515645256453564545645556456564575645856459564605646156462564635646456465564665646756468564695647056471564725647356474564755647656477564785647956480564815648256483564845648556486564875648856489564905649156492564935649456495564965649756498564995650056501565025650356504565055650656507565085650956510565115651256513565145651556516565175651856519565205652156522565235652456525565265652756528565295653056531565325653356534565355653656537565385653956540565415654256543565445654556546565475654856549565505655156552565535655456555565565655756558565595656056561565625656356564565655656656567565685656956570565715657256573565745657556576565775657856579565805658156582565835658456585565865658756588565895659056591565925659356594565955659656597565985659956600566015660256603566045660556606566075660856609566105661156612566135661456615566165661756618566195662056621566225662356624566255662656627566285662956630566315663256633566345663556636566375663856639566405664156642566435664456645566465664756648566495665056651566525665356654566555665656657566585665956660566615666256663566645666556666566675666856669566705667156672566735667456675566765667756678566795668056681566825668356684566855668656687566885668956690566915669256693566945669556696566975669856699567005670156702567035670456705567065670756708567095671056711567125671356714567155671656717567185671956720567215672256723567245672556726567275672856729567305673156732567335673456735567365673756738567395674056741567425674356744567455674656747567485674956750567515675256753567545675556756567575675856759567605676156762567635676456765567665676756768567695677056771567725677356774567755677656777567785677956780567815678256783567845678556786567875678856789567905679156792567935679456795567965679756798567995680056801568025680356804568055680656807568085680956810568115681256813568145681556816568175681856819568205682156822568235682456825568265682756828568295683056831568325683356834568355683656837568385683956840568415684256843568445684556846568475684856849568505685156852568535685456855568565685756858568595686056861568625686356864568655686656867568685686956870568715687256873568745687556876568775687856879568805688156882568835688456885568865688756888568895689056891568925689356894568955689656897568985689956900569015690256903569045690556906569075690856909569105691156912569135691456915569165691756918569195692056921569225692356924569255692656927569285692956930569315693256933569345693556936569375693856939569405694156942569435694456945569465694756948569495695056951569525695356954569555695656957569585695956960569615696256963569645696556966569675696856969569705697156972569735697456975569765697756978569795698056981569825698356984569855698656987569885698956990569915699256993569945699556996569975699856999570005700157002570035700457005570065700757008570095701057011570125701357014570155701657017570185701957020570215702257023570245702557026570275702857029570305703157032570335703457035570365703757038570395704057041570425704357044570455704657047570485704957050570515705257053570545705557056570575705857059570605706157062570635706457065570665706757068570695707057071570725707357074570755707657077570785707957080570815708257083570845708557086570875708857089570905709157092570935709457095570965709757098570995710057101571025710357104571055710657107571085710957110571115711257113571145711557116571175711857119571205712157122571235712457125571265712757128571295713057131571325713357134571355713657137571385713957140571415714257143571445714557146571475714857149571505715157152571535715457155571565715757158571595716057161571625716357164571655716657167571685716957170571715717257173571745717557176571775717857179571805718157182571835718457185571865718757188571895719057191571925719357194571955719657197571985719957200572015720257203572045720557206572075720857209572105721157212572135721457215572165721757218572195722057221572225722357224572255722657227572285722957230572315723257233572345723557236572375723857239572405724157242572435724457245572465724757248572495725057251572525725357254572555725657257572585725957260572615726257263572645726557266572675726857269572705727157272572735727457275572765727757278572795728057281572825728357284572855728657287572885728957290572915729257293572945729557296572975729857299573005730157302573035730457305573065730757308573095731057311573125731357314573155731657317573185731957320573215732257323573245732557326573275732857329573305733157332573335733457335573365733757338573395734057341573425734357344573455734657347573485734957350573515735257353573545735557356573575735857359573605736157362573635736457365573665736757368573695737057371573725737357374573755737657377573785737957380573815738257383573845738557386573875738857389573905739157392573935739457395573965739757398573995740057401574025740357404574055740657407574085740957410574115741257413574145741557416574175741857419574205742157422574235742457425574265742757428574295743057431574325743357434574355743657437574385743957440574415744257443574445744557446574475744857449574505745157452574535745457455574565745757458574595746057461574625746357464574655746657467574685746957470574715747257473574745747557476574775747857479574805748157482574835748457485574865748757488574895749057491574925749357494574955749657497574985749957500575015750257503575045750557506575075750857509575105751157512575135751457515575165751757518575195752057521575225752357524575255752657527575285752957530575315753257533575345753557536575375753857539575405754157542575435754457545575465754757548575495755057551575525755357554575555755657557575585755957560575615756257563575645756557566575675756857569575705757157572575735757457575575765757757578575795758057581575825758357584575855758657587575885758957590575915759257593575945759557596575975759857599576005760157602576035760457605576065760757608576095761057611576125761357614576155761657617576185761957620576215762257623576245762557626576275762857629576305763157632576335763457635576365763757638576395764057641576425764357644576455764657647576485764957650576515765257653576545765557656576575765857659576605766157662576635766457665576665766757668576695767057671576725767357674576755767657677576785767957680576815768257683576845768557686576875768857689576905769157692576935769457695576965769757698576995770057701577025770357704577055770657707577085770957710577115771257713577145771557716577175771857719577205772157722577235772457725577265772757728577295773057731577325773357734577355773657737577385773957740577415774257743577445774557746577475774857749577505775157752577535775457755577565775757758577595776057761577625776357764577655776657767577685776957770577715777257773577745777557776577775777857779577805778157782577835778457785577865778757788577895779057791577925779357794577955779657797577985779957800578015780257803578045780557806578075780857809578105781157812578135781457815578165781757818578195782057821578225782357824578255782657827578285782957830578315783257833578345783557836578375783857839578405784157842578435784457845578465784757848578495785057851578525785357854578555785657857578585785957860578615786257863578645786557866578675786857869578705787157872578735787457875578765787757878578795788057881578825788357884578855788657887578885788957890578915789257893578945789557896578975789857899579005790157902579035790457905579065790757908579095791057911579125791357914579155791657917579185791957920579215792257923579245792557926579275792857929579305793157932579335793457935579365793757938579395794057941579425794357944579455794657947579485794957950579515795257953579545795557956579575795857959579605796157962579635796457965579665796757968579695797057971579725797357974579755797657977579785797957980579815798257983579845798557986579875798857989579905799157992579935799457995579965799757998579995800058001580025800358004580055800658007580085800958010580115801258013580145801558016580175801858019580205802158022580235802458025580265802758028580295803058031580325803358034580355803658037580385803958040580415804258043580445804558046580475804858049580505805158052580535805458055580565805758058580595806058061580625806358064580655806658067580685806958070580715807258073580745807558076580775807858079580805808158082580835808458085580865808758088580895809058091580925809358094580955809658097580985809958100581015810258103581045810558106581075810858109581105811158112581135811458115581165811758118581195812058121581225812358124581255812658127581285812958130581315813258133581345813558136581375813858139581405814158142581435814458145581465814758148581495815058151581525815358154581555815658157581585815958160581615816258163581645816558166581675816858169581705817158172581735817458175581765817758178581795818058181581825818358184581855818658187581885818958190581915819258193581945819558196581975819858199582005820158202582035820458205582065820758208582095821058211582125821358214582155821658217582185821958220582215822258223582245822558226582275822858229582305823158232582335823458235582365823758238582395824058241582425824358244582455824658247582485824958250582515825258253582545825558256582575825858259582605826158262582635826458265582665826758268582695827058271582725827358274582755827658277582785827958280582815828258283582845828558286582875828858289582905829158292582935829458295582965829758298582995830058301583025830358304583055830658307583085830958310583115831258313583145831558316583175831858319583205832158322583235832458325583265832758328583295833058331583325833358334583355833658337583385833958340583415834258343583445834558346583475834858349583505835158352583535835458355583565835758358583595836058361583625836358364583655836658367583685836958370583715837258373583745837558376583775837858379583805838158382583835838458385583865838758388583895839058391583925839358394583955839658397583985839958400584015840258403584045840558406584075840858409584105841158412584135841458415584165841758418584195842058421584225842358424584255842658427584285842958430584315843258433584345843558436584375843858439584405844158442584435844458445584465844758448584495845058451584525845358454584555845658457584585845958460584615846258463584645846558466584675846858469584705847158472584735847458475584765847758478584795848058481584825848358484584855848658487584885848958490584915849258493584945849558496584975849858499585005850158502585035850458505585065850758508585095851058511585125851358514585155851658517585185851958520585215852258523585245852558526585275852858529585305853158532585335853458535585365853758538585395854058541585425854358544585455854658547585485854958550585515855258553585545855558556585575855858559585605856158562585635856458565585665856758568585695857058571585725857358574585755857658577585785857958580585815858258583585845858558586585875858858589585905859158592585935859458595585965859758598585995860058601586025860358604586055860658607586085860958610586115861258613586145861558616586175861858619586205862158622586235862458625586265862758628586295863058631586325863358634586355863658637586385863958640586415864258643586445864558646586475864858649586505865158652586535865458655586565865758658586595866058661586625866358664586655866658667586685866958670586715867258673586745867558676586775867858679586805868158682586835868458685586865868758688586895869058691586925869358694586955869658697586985869958700587015870258703587045870558706587075870858709587105871158712587135871458715587165871758718587195872058721587225872358724587255872658727587285872958730587315873258733587345873558736587375873858739587405874158742587435874458745587465874758748587495875058751587525875358754587555875658757587585875958760587615876258763587645876558766587675876858769587705877158772587735877458775587765877758778587795878058781587825878358784587855878658787587885878958790587915879258793587945879558796587975879858799588005880158802588035880458805588065880758808588095881058811588125881358814588155881658817588185881958820588215882258823588245882558826588275882858829588305883158832588335883458835588365883758838588395884058841588425884358844588455884658847588485884958850588515885258853588545885558856588575885858859588605886158862588635886458865588665886758868588695887058871588725887358874588755887658877588785887958880588815888258883588845888558886588875888858889588905889158892588935889458895588965889758898588995890058901589025890358904589055890658907589085890958910589115891258913589145891558916589175891858919589205892158922589235892458925589265892758928589295893058931589325893358934589355893658937589385893958940589415894258943589445894558946589475894858949589505895158952589535895458955589565895758958589595896058961589625896358964589655896658967589685896958970589715897258973589745897558976589775897858979589805898158982589835898458985589865898758988589895899058991589925899358994589955899658997589985899959000590015900259003590045900559006590075900859009590105901159012590135901459015590165901759018590195902059021590225902359024590255902659027590285902959030590315903259033590345903559036590375903859039590405904159042590435904459045590465904759048590495905059051590525905359054590555905659057590585905959060590615906259063590645906559066590675906859069590705907159072590735907459075590765907759078590795908059081590825908359084590855908659087590885908959090590915909259093590945909559096590975909859099591005910159102591035910459105591065910759108591095911059111591125911359114591155911659117591185911959120591215912259123591245912559126591275912859129591305913159132591335913459135591365913759138591395914059141591425914359144591455914659147591485914959150591515915259153591545915559156591575915859159591605916159162591635916459165591665916759168591695917059171591725917359174591755917659177591785917959180591815918259183591845918559186591875918859189591905919159192591935919459195591965919759198591995920059201592025920359204592055920659207592085920959210592115921259213592145921559216592175921859219592205922159222592235922459225592265922759228592295923059231592325923359234592355923659237592385923959240592415924259243592445924559246592475924859249592505925159252592535925459255592565925759258592595926059261592625926359264592655926659267592685926959270592715927259273592745927559276592775927859279592805928159282592835928459285592865928759288592895929059291592925929359294592955929659297592985929959300593015930259303593045930559306593075930859309593105931159312593135931459315593165931759318593195932059321593225932359324593255932659327593285932959330593315933259333593345933559336593375933859339593405934159342593435934459345593465934759348593495935059351593525935359354593555935659357593585935959360593615936259363593645936559366593675936859369593705937159372593735937459375593765937759378593795938059381593825938359384593855938659387593885938959390593915939259393593945939559396593975939859399594005940159402594035940459405594065940759408594095941059411594125941359414594155941659417594185941959420594215942259423594245942559426594275942859429594305943159432594335943459435594365943759438594395944059441594425944359444594455944659447594485944959450594515945259453594545945559456594575945859459594605946159462594635946459465594665946759468594695947059471594725947359474594755947659477594785947959480594815948259483594845948559486594875948859489594905949159492594935949459495594965949759498594995950059501595025950359504595055950659507595085950959510595115951259513595145951559516595175951859519595205952159522595235952459525595265952759528595295953059531595325953359534595355953659537595385953959540595415954259543595445954559546595475954859549595505955159552595535955459555595565955759558595595956059561595625956359564595655956659567595685956959570595715957259573595745957559576595775957859579595805958159582595835958459585595865958759588595895959059591595925959359594595955959659597595985959959600596015960259603596045960559606596075960859609596105961159612596135961459615596165961759618596195962059621596225962359624596255962659627596285962959630596315963259633596345963559636596375963859639596405964159642596435964459645596465964759648596495965059651596525965359654596555965659657596585965959660596615966259663596645966559666596675966859669596705967159672596735967459675596765967759678596795968059681596825968359684596855968659687596885968959690596915969259693596945969559696596975969859699597005970159702597035970459705597065970759708597095971059711597125971359714597155971659717597185971959720597215972259723597245972559726597275972859729597305973159732597335973459735597365973759738597395974059741597425974359744597455974659747597485974959750597515975259753597545975559756597575975859759597605976159762597635976459765597665976759768597695977059771597725977359774597755977659777597785977959780597815978259783597845978559786597875978859789597905979159792597935979459795597965979759798597995980059801598025980359804598055980659807598085980959810598115981259813598145981559816598175981859819598205982159822598235982459825598265982759828598295983059831598325983359834598355983659837598385983959840598415984259843598445984559846598475984859849598505985159852598535985459855598565985759858598595986059861598625986359864598655986659867598685986959870598715987259873598745987559876598775987859879598805988159882598835988459885598865988759888598895989059891598925989359894598955989659897598985989959900599015990259903599045990559906599075990859909599105991159912599135991459915599165991759918599195992059921599225992359924599255992659927599285992959930599315993259933599345993559936599375993859939599405994159942599435994459945599465994759948599495995059951599525995359954599555995659957599585995959960599615996259963599645996559966599675996859969599705997159972599735997459975599765997759978599795998059981599825998359984599855998659987599885998959990599915999259993599945999559996599975999859999600006000160002600036000460005600066000760008600096001060011600126001360014600156001660017600186001960020600216002260023600246002560026600276002860029600306003160032600336003460035600366003760038600396004060041600426004360044600456004660047600486004960050600516005260053600546005560056600576005860059600606006160062600636006460065600666006760068600696007060071600726007360074600756007660077600786007960080600816008260083600846008560086600876008860089600906009160092600936009460095600966009760098600996010060101601026010360104601056010660107601086010960110601116011260113601146011560116601176011860119601206012160122601236012460125601266012760128601296013060131601326013360134601356013660137601386013960140601416014260143601446014560146601476014860149601506015160152601536015460155601566015760158601596016060161601626016360164601656016660167601686016960170601716017260173601746017560176601776017860179601806018160182601836018460185601866018760188601896019060191601926019360194601956019660197601986019960200602016020260203602046020560206602076020860209602106021160212602136021460215602166021760218602196022060221602226022360224602256022660227602286022960230602316023260233602346023560236602376023860239602406024160242602436024460245602466024760248602496025060251602526025360254602556025660257602586025960260602616026260263602646026560266602676026860269602706027160272602736027460275602766027760278602796028060281602826028360284602856028660287602886028960290602916029260293602946029560296602976029860299603006030160302603036030460305603066030760308603096031060311603126031360314603156031660317603186031960320603216032260323603246032560326603276032860329603306033160332603336033460335603366033760338603396034060341603426034360344603456034660347603486034960350603516035260353603546035560356603576035860359603606036160362603636036460365603666036760368603696037060371603726037360374603756037660377603786037960380603816038260383603846038560386603876038860389603906039160392603936039460395603966039760398603996040060401604026040360404604056040660407604086040960410604116041260413604146041560416604176041860419604206042160422604236042460425604266042760428604296043060431604326043360434604356043660437604386043960440604416044260443604446044560446604476044860449604506045160452604536045460455604566045760458604596046060461604626046360464604656046660467604686046960470604716047260473604746047560476604776047860479604806048160482604836048460485604866048760488604896049060491604926049360494604956049660497604986049960500605016050260503605046050560506605076050860509605106051160512605136051460515605166051760518605196052060521605226052360524605256052660527605286052960530605316053260533605346053560536605376053860539605406054160542605436054460545605466054760548605496055060551605526055360554605556055660557605586055960560605616056260563605646056560566605676056860569605706057160572605736057460575605766057760578605796058060581605826058360584605856058660587605886058960590605916059260593605946059560596605976059860599606006060160602606036060460605606066060760608606096061060611606126061360614606156061660617606186061960620606216062260623606246062560626606276062860629606306063160632606336063460635606366063760638606396064060641606426064360644606456064660647606486064960650606516065260653606546065560656606576065860659606606066160662606636066460665606666066760668606696067060671606726067360674606756067660677606786067960680606816068260683606846068560686606876068860689606906069160692606936069460695606966069760698606996070060701607026070360704607056070660707607086070960710607116071260713607146071560716607176071860719607206072160722607236072460725607266072760728607296073060731607326073360734607356073660737607386073960740607416074260743607446074560746607476074860749607506075160752607536075460755607566075760758607596076060761607626076360764607656076660767607686076960770607716077260773607746077560776607776077860779607806078160782607836078460785607866078760788607896079060791607926079360794607956079660797607986079960800608016080260803608046080560806608076080860809608106081160812608136081460815608166081760818608196082060821608226082360824608256082660827608286082960830608316083260833608346083560836608376083860839608406084160842608436084460845608466084760848608496085060851608526085360854608556085660857608586085960860608616086260863608646086560866608676086860869608706087160872608736087460875608766087760878608796088060881608826088360884608856088660887608886088960890608916089260893608946089560896608976089860899609006090160902609036090460905609066090760908609096091060911609126091360914609156091660917609186091960920609216092260923609246092560926609276092860929609306093160932609336093460935609366093760938609396094060941609426094360944609456094660947609486094960950609516095260953609546095560956609576095860959609606096160962609636096460965609666096760968609696097060971609726097360974609756097660977609786097960980609816098260983609846098560986609876098860989609906099160992609936099460995609966099760998609996100061001610026100361004610056100661007610086100961010610116101261013610146101561016610176101861019610206102161022610236102461025610266102761028610296103061031610326103361034610356103661037610386103961040610416104261043610446104561046610476104861049610506105161052610536105461055610566105761058610596106061061610626106361064610656106661067610686106961070610716107261073610746107561076610776107861079610806108161082610836108461085610866108761088610896109061091610926109361094610956109661097610986109961100611016110261103611046110561106611076110861109611106111161112611136111461115611166111761118611196112061121611226112361124611256112661127611286112961130611316113261133611346113561136611376113861139611406114161142611436114461145611466114761148611496115061151611526115361154611556115661157611586115961160611616116261163611646116561166611676116861169611706117161172611736117461175611766117761178611796118061181611826118361184611856118661187611886118961190611916119261193611946119561196611976119861199612006120161202612036120461205612066120761208612096121061211612126121361214612156121661217612186121961220612216122261223612246122561226612276122861229612306123161232612336123461235612366123761238612396124061241612426124361244612456124661247612486124961250612516125261253612546125561256612576125861259612606126161262612636126461265612666126761268612696127061271612726127361274612756127661277612786127961280612816128261283612846128561286612876128861289612906129161292612936129461295612966129761298612996130061301613026130361304613056130661307613086130961310613116131261313613146131561316613176131861319613206132161322613236132461325613266132761328613296133061331613326133361334613356133661337613386133961340613416134261343613446134561346613476134861349613506135161352613536135461355613566135761358613596136061361613626136361364613656136661367613686136961370613716137261373613746137561376613776137861379613806138161382613836138461385613866138761388613896139061391613926139361394613956139661397613986139961400614016140261403614046140561406614076140861409614106141161412614136141461415614166141761418614196142061421614226142361424614256142661427614286142961430614316143261433614346143561436614376143861439614406144161442614436144461445614466144761448614496145061451614526145361454614556145661457614586145961460614616146261463614646146561466614676146861469614706147161472614736147461475614766147761478614796148061481614826148361484614856148661487614886148961490614916149261493614946149561496614976149861499615006150161502615036150461505615066150761508615096151061511615126151361514615156151661517615186151961520615216152261523615246152561526615276152861529615306153161532615336153461535615366153761538615396154061541615426154361544615456154661547615486154961550615516155261553615546155561556615576155861559615606156161562615636156461565615666156761568615696157061571615726157361574615756157661577615786157961580615816158261583615846158561586615876158861589615906159161592615936159461595615966159761598615996160061601616026160361604616056160661607616086160961610616116161261613616146161561616616176161861619616206162161622616236162461625616266162761628616296163061631616326163361634616356163661637616386163961640616416164261643616446164561646616476164861649616506165161652616536165461655616566165761658616596166061661616626166361664616656166661667616686166961670616716167261673616746167561676616776167861679616806168161682616836168461685616866168761688616896169061691616926169361694616956169661697616986169961700617016170261703617046170561706617076170861709617106171161712617136171461715617166171761718617196172061721617226172361724617256172661727617286172961730617316173261733617346173561736617376173861739617406174161742617436174461745617466174761748617496175061751617526175361754617556175661757617586175961760617616176261763617646176561766617676176861769617706177161772617736177461775617766177761778617796178061781617826178361784617856178661787617886178961790617916179261793617946179561796617976179861799618006180161802618036180461805618066180761808618096181061811618126181361814618156181661817618186181961820618216182261823618246182561826618276182861829618306183161832618336183461835618366183761838618396184061841618426184361844618456184661847618486184961850618516185261853618546185561856618576185861859618606186161862618636186461865618666186761868618696187061871618726187361874618756187661877618786187961880618816188261883618846188561886618876188861889618906189161892618936189461895618966189761898618996190061901619026190361904619056190661907619086190961910619116191261913619146191561916619176191861919619206192161922619236192461925619266192761928619296193061931619326193361934619356193661937619386193961940619416194261943619446194561946619476194861949619506195161952619536195461955619566195761958619596196061961619626196361964619656196661967619686196961970619716197261973619746197561976619776197861979619806198161982619836198461985619866198761988619896199061991619926199361994619956199661997619986199962000620016200262003620046200562006620076200862009620106201162012
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. * This file is part of Composer.
  5. *
  6. * (c) Nils Adermann <naderman@naderman.de>
  7. * Jordi Boggiano <j.boggiano@seld.be>
  8. *
  9. * For the full copyright and license information, please view
  10. * the license that is located at the bottom of this file.
  11. */
  12. // Avoid APC causing random fatal errors per https://github.com/composer/composer/issues/264
  13. if (extension_loaded('apc') && ini_get('apc.enable_cli') && ini_get('apc.cache_by_default')) {
  14. if (version_compare(phpversion('apc'), '3.0.12', '>=')) {
  15. ini_set('apc.cache_by_default', 0);
  16. } else {
  17. fwrite(STDERR, 'Warning: APC <= 3.0.12 may cause fatal errors when running composer commands.'.PHP_EOL);
  18. fwrite(STDERR, 'Update APC, or set apc.enable_cli or apc.cache_by_default to 0 in your php.ini.'.PHP_EOL);
  19. }
  20. }
  21. Phar::mapPhar('composer.phar');
  22. define('COMPOSER_DEV_WARNING_TIME', 1451055666);
  23. require 'phar://composer.phar/bin/composer';
  24. __HALT_COMPILER(); ?>
  25. d|��}������ ���composer.phar����+���src/Composer/Autoload/AutoloadGenerator.php�L��2@.V�L��>V]¶������+���src/Composer/Autoload/ClassMapGenerator.php��2@.V��ᘨ*¶���������src/Composer/Cache.phpÇ��2@.VÇ�� ¹hà¶������%���src/Composer/Command/AboutCommand.php¼��2@.V¼��ZF�‡¶������'���src/Composer/Command/ArchiveCommand.phpß��2@.Vß��Ïã߶������*���src/Composer/Command/ClearCacheCommand.phpZ��2@.VZ��‰ì>¶������ ���src/Composer/Command/Command.php‰��2@.V‰��µ vJ¶������&���src/Composer/Command/ConfigCommand.phpÊ6��2@.VÊ6��"~¶������-���src/Composer/Command/CreateProjectCommand.php 3��2@.V 3��Ì?ù¶������'���src/Composer/Command/DependsCommand.php„
  26. ��2@.V„
  27. ��)¸Ó¶������(���src/Composer/Command/DiagnoseCommand.php/9��2@.V/9��[zÿ_¶������,���src/Composer/Command/DumpAutoloadCommand.php��2@.V��™Rù¶������&���src/Composer/Command/GlobalCommand.php��2@.V��©¨@•¶������$���src/Composer/Command/HomeCommand.php` ��2@.V` ��sgœ2¶������$���src/Composer/Command/InitCommand.php½7��2@.V½7��g$hG¶������'���src/Composer/Command/InstallCommand.php ��2@.V ��`Cí¶������(���src/Composer/Command/LicensesCommand.php��2@.V��Âv襶������&���src/Composer/Command/RemoveCommand.phpn��2@.Vn��€Ës¶������'���src/Composer/Command/RequireCommand.php½��2@.V½��Ĉ”Ķ������)���src/Composer/Command/RunScriptCommand.php� ��2@.V� ��âè2Ú¶������+���src/Composer/Command/ScriptAliasCommand.php²��2@.V²��ñÇ$½¶������&���src/Composer/Command/SearchCommand.phpa ��2@.Va ��ÐU}P¶������*���src/Composer/Command/SelfUpdateCommand.phpË��2@.VË��¾< à¶������$���src/Composer/Command/ShowCommand.php§0��2@.V§0��o
  28. î ¶������&���src/Composer/Command/StatusCommand.phpœ ��2@.Vœ ��#ƒ‡c¶������(���src/Composer/Command/SuggestsCommand.phpÿ��2@.Vÿ��¾?gж������&���src/Composer/Command/UpdateCommand.php��2@.V��Ït»a¶������(���src/Composer/Command/ValidateCommand.php½��2@.V½��pòL.¶���������src/Composer/Composer.php) ��2@.V) ��Û B¶���������src/Composer/Config.php2��2@.V2��§76q¶������-���src/Composer/Config/ConfigSourceInterface.php®��2@.V®��6J[ª¶������(���src/Composer/Config/JsonConfigSource.php“ ��2@.V“ ��*íÞT¶������$���src/Composer/Console/Application.php0!��2@.V0!��-LÒf¶������,���src/Composer/Console/HtmlOutputFormatter.php3��2@.V3��Ú�Eu¶������-���src/Composer/DependencyResolver/Decisions.phpQ��2@.VQ��?˜¬$¶������1���src/Composer/DependencyResolver/DefaultPolicy.phpÖ��2@.VÖ��9ÁÖõ¶������>���src/Composer/DependencyResolver/Operation/InstallOperation.phpC��2@.VC��´\õ*¶������I���src/Composer/DependencyResolver/Operation/MarkAliasInstalledOperation.php÷��2@.V÷��ïÎà÷¶������K���src/Composer/DependencyResolver/Operation/MarkAliasUninstalledOperation.phpý��2@.Vý��3#†¶������@���src/Composer/DependencyResolver/Operation/OperationInterface.phpÓ���2@.VÓ���Ùâ&ä¶������=���src/Composer/DependencyResolver/Operation/SolverOperation.php¹��2@.V¹��&¢e
  29. ¶������@���src/Composer/DependencyResolver/Operation/UninstallOperation.phpI��2@.VI��FûÂɶ������=���src/Composer/DependencyResolver/Operation/UpdateOperation.phph��2@.Vh��öSÕ]¶������3���src/Composer/DependencyResolver/PolicyInterface.php”��2@.V”��°�­¶������(���src/Composer/DependencyResolver/Pool.phpª!��2@.Vª!��Elü8¶������+���src/Composer/DependencyResolver/Problem.phpÀ��2@.VÀ��ØVìñ¶������+���src/Composer/DependencyResolver/Request.php€��2@.V€��Ðwƒ¶������(���src/Composer/DependencyResolver/Rule.phpç��2@.Vç��gì¬T¶������+���src/Composer/DependencyResolver/RuleSet.php
  30. ��2@.V
  31. ��:Z�E¶������4���src/Composer/DependencyResolver/RuleSetGenerator.php]��2@.V]��4“Ñ9¶������3���src/Composer/DependencyResolver/RuleSetIterator.php��2@.V��}õÇù¶������2���src/Composer/DependencyResolver/RuleWatchChain.phpi��2@.Vi��hïš,¶������2���src/Composer/DependencyResolver/RuleWatchGraph.phpÜ��2@.VÜ��‰8¶������1���src/Composer/DependencyResolver/RuleWatchNode.phpç��2@.Vç��—Þȶ������*���src/Composer/DependencyResolver/Solver.php7��2@.V7��@ÿ¶������6���src/Composer/DependencyResolver/SolverBugException.php˜��2@.V˜��"qN¶������;���src/Composer/DependencyResolver/SolverProblemsException.php(��2@.V(��S‹Ž¼¶������/���src/Composer/DependencyResolver/Transaction.phpÔ��2@.VÔ�� 3ô¶������-���src/Composer/Downloader/ArchiveDownloader.php‡��2@.V‡��¬¸£ ¶������1���src/Composer/Downloader/ChangeReportInterface.phpÌ���2@.VÌ���¯à¨¿¶������+���src/Composer/Downloader/DownloadManager.php���2@.V���F «ü¶������/���src/Composer/Downloader/DownloaderInterface.phpÊ��2@.VÊ��gs!l¶������*���src/Composer/Downloader/FileDownloader.phpn��2@.Vn�� „ò®¶������/���src/Composer/Downloader/FilesystemException.php��2@.V��]T½ˆ¶������)���src/Composer/Downloader/GitDownloader.phpÕ$��2@.VÕ$��²–�¶������*���src/Composer/Downloader/GzipDownloader.phpÈ��2@.VÈ��­äßж������(���src/Composer/Downloader/HgDownloader.phpd��2@.Vd��«.½¶������*���src/Composer/Downloader/PathDownloader.php8��2@.V8��se̶������0���src/Composer/Downloader/PearPackageExtractor.phpu��2@.Vu��z„‡¶������.���src/Composer/Downloader/PerforceDownloader.phpy��2@.Vy��(Ž)3¶������*���src/Composer/Downloader/PharDownloader.phpå���2@.Vå���ÞÉç¶������)���src/Composer/Downloader/RarDownloader.phpß��2@.Vß��¾¼¶������)���src/Composer/Downloader/SvnDownloader.php\��2@.V\��. [¶������)���src/Composer/Downloader/TarDownloader.phpã���2@.Vã���Í’X?¶������.���src/Composer/Downloader/TransportException.php–��2@.V–��h"Br¶������)���src/Composer/Downloader/VcsDownloader.php¹��2@.V¹��N+¶¶������)���src/Composer/Downloader/ZipDownloader.phpC ��2@.VC ��]^+¶������&���src/Composer/EventDispatcher/Event.php ��2@.V ��±™jï¶������0���src/Composer/EventDispatcher/EventDispatcher.php5��2@.V5��%¾Å¶������9���src/Composer/EventDispatcher/EventSubscriberInterface.php©���2@.V©���h·0¶���������src/Composer/Factory.php!.��2@.V!.��M-XT¶���������src/Composer/IO/BaseIO.phpp��2@.Vp��ÈNñZ¶���������src/Composer/IO/BufferIO.php��2@.V��hvá¶���������src/Composer/IO/ConsoleIO.php8��2@.V8��­Ãô¶���������src/Composer/IO/IOInterface.php„��2@.V„��´=Så¶���������src/Composer/IO/NullIO.php³��2@.V³��~1Ķ���������src/Composer/Installer.php„��2@.V„��ì™–¶������.���src/Composer/Installer/InstallationManager.php��2@.V��ÓýÇÛ¶������)���src/Composer/Installer/InstallerEvent.php��2@.V��lÔzi¶������*���src/Composer/Installer/InstallerEvents.phpÞ���2@.VÞ���ìŸ@G¶������-���src/Composer/Installer/InstallerInterface.phpã��2@.Vã��^ƒ“ʶ������+���src/Composer/Installer/LibraryInstaller.phpö��2@.Vö��›é7B¶������/���src/Composer/Installer/MetapackageInstaller.phpœ��2@.Vœ��ÆÅ!¶������(���src/Composer/Installer/NoopInstaller.php+��2@.V+��À·M}¶������'���src/Composer/Installer/PackageEvent.phpe��2@.Ve��;° ¶������(���src/Composer/Installer/PackageEvents.php¸��2@.V¸��dbØs¶������(���src/Composer/Installer/PearInstaller.phpV��2@.VV���zð¶������*���src/Composer/Installer/PluginInstaller.php
  32. ��2@.V
  33. ��6À¢�¶������+���src/Composer/Installer/ProjectInstaller.php��2@.V��*0@P¶���������src/Composer/Json/JsonFile.php���2@.V���’Üþ¶������#���src/Composer/Json/JsonFormatter.php��2@.V��Ðqu¶������%���src/Composer/Json/JsonManipulator.php*��2@.V*��r% ¶������-���src/Composer/Json/JsonValidationException.php\��2@.V\��.Xóܶ������%���src/Composer/Package/AliasPackage.php"��2@.V"��í©˜·¶������7���src/Composer/Package/Archiver/ArchivableFilesFinder.php¾��2@.V¾��„Œõɶ������0���src/Composer/Package/Archiver/ArchiveManager.phpz ��2@.Vz ��!sK™¶������3���src/Composer/Package/Archiver/ArchiverInterface.phpï���2@.Vï���<ʸ¶������3���src/Composer/Package/Archiver/BaseExcludeFilter.php‘��2@.V‘��[ÿ0=¶������7���src/Composer/Package/Archiver/ComposerExcludeFilter.php��2@.V��‹SZ0¶������2���src/Composer/Package/Archiver/GitExcludeFilter.phpw��2@.Vw��LgU»¶������1���src/Composer/Package/Archiver/HgExcludeFilter.php��2@.V��~”¸¶������.���src/Composer/Package/Archiver/PharArchiver.php[��2@.V[��Ê5Íø¶������$���src/Composer/Package/BasePackage.phpß ��2@.Vß ��鸞¶������(���src/Composer/Package/CompletePackage.phpÿ��2@.Vÿ��o+ã ¶������1���src/Composer/Package/CompletePackageInterface.phpõ��2@.Võ��¦Ê�ò¶������+���src/Composer/Package/Dumper/ArrayDumper.phpì ��2@.Vì ��ª–æ¶���������src/Composer/Package/Link.phpD��2@.VD��LО ¶������7���src/Composer/Package/LinkConstraint/EmptyConstraint.phpƒ��2@.Vƒ��¥,ED¶������?���src/Composer/Package/LinkConstraint/LinkConstraintInterface.phpe��2@.Ve���ÇþŸ¶������7���src/Composer/Package/LinkConstraint/MultiConstraint.phpƒ��2@.Vƒ��Ó6W¶������:���src/Composer/Package/LinkConstraint/SpecificConstraint.php…��2@.V…��û¾b¶������9���src/Composer/Package/LinkConstraint/VersionConstraint.phpY��2@.VY��"+\Q¶������+���src/Composer/Package/Loader/ArrayLoader.phpç��2@.Vç��MùØr¶������7���src/Composer/Package/Loader/InvalidPackageException.phpE��2@.VE��xb¾¶������*���src/Composer/Package/Loader/JsonLoader.phpù��2@.Vù��!~ˆ{¶������/���src/Composer/Package/Loader/LoaderInterface.php²���2@.V²���¦}úζ������1���src/Composer/Package/Loader/RootPackageLoader.php[��2@.V[��ñÊ&u¶������5���src/Composer/Package/Loader/ValidatingArrayLoader.phpÎ/��2@.VÎ/��‹Ú`L¶���������src/Composer/Package/Locker.phpŠ!��2@.VŠ!��†{¹€¶������ ���src/Composer/Package/Package.php»��2@.V»��¼Jâ¶������)���src/Composer/Package/PackageInterface.php ��2@.V ��ûÇ^ƶ������)���src/Composer/Package/RootAliasPackage.phpy��2@.Vy��ÀE'¶������$���src/Composer/Package/RootPackage.phpn��2@.Vn��áACO¶������-���src/Composer/Package/RootPackageInterface.php´��2@.V´��êqKж������/���src/Composer/Package/Version/VersionGuesser.phpû��2@.Vû��9¼Ò¶������.���src/Composer/Package/Version/VersionParser.phpò��2@.Vò��&Cf¶������0���src/Composer/Package/Version/VersionSelector.phpÃ��2@.VÃ��A‡¥6¶������$���src/Composer/Plugin/CommandEvent.phpâ��2@.Vâ��³ÆÇW¶������$���src/Composer/Plugin/PluginEvents.php¤���2@.V¤���0ïÞX¶������'���src/Composer/Plugin/PluginInterface.phpô���2@.Vô��� 1‰%¶������%���src/Composer/Plugin/PluginManager.php£��2@.V£��CßO¶������,���src/Composer/Plugin/PreFileDownloadEvent.php`��2@.V`���9-ζ������+���src/Composer/Repository/ArrayRepository.php| ��2@.V| ��õ{^f¶������.���src/Composer/Repository/ArtifactRepository.phpG ��2@.VG ��àÈ=À¶������.���src/Composer/Repository/ComposerRepository.phpä@��2@.Vä@��߈eÒ¶������/���src/Composer/Repository/CompositeRepository.php.��2@.V.��CÅx¶������0���src/Composer/Repository/FilesystemRepository.phpÀ��2@.VÀ��&xb£¶������4���src/Composer/Repository/InstalledArrayRepository.php£���2@.V£���/ö~>¶������9���src/Composer/Repository/InstalledFilesystemRepository.php£���2@.V£���V
  34. •_¶������8���src/Composer/Repository/InstalledRepositoryInterface.php‡���2@.V‡���£9p¶������6���src/Composer/Repository/InvalidRepositoryException.phpn���2@.Vn���à“똶������-���src/Composer/Repository/PackageRepository.phpG��2@.VG��í:k¶������*���src/Composer/Repository/PathRepository.php‰��2@.V‰��t¶±¶������2���src/Composer/Repository/Pear/BaseChannelReader.php6��2@.V6��.fi!¶������,���src/Composer/Repository/Pear/ChannelInfo.phpÄ��2@.VÄ��:T*ɶ������.���src/Composer/Repository/Pear/ChannelReader.phpn��2@.Vn��š8¶������4���src/Composer/Repository/Pear/ChannelRest10Reader.phpÁ ��2@.VÁ ��O€ë¶������4���src/Composer/Repository/Pear/ChannelRest11Reader.php& ��2@.V& ��òUb¶������5���src/Composer/Repository/Pear/DependencyConstraint.phpq��2@.Vq��9=¶������/���src/Composer/Repository/Pear/DependencyInfo.phpq��2@.Vq��fºTò¶������8���src/Composer/Repository/Pear/PackageDependencyParser.php%��2@.V%��j?“¶������,���src/Composer/Repository/Pear/PackageInfo.php°��2@.V°��Ÿ ¸ ¶������,���src/Composer/Repository/Pear/ReleaseInfo.php’��2@.V’��o“ŠÃ¶������*���src/Composer/Repository/PearRepository.php���2@.V���~ãs_¶������.���src/Composer/Repository/PlatformRepository.php{��2@.V{���™Úض������/���src/Composer/Repository/RepositoryInterface.phpÚ��2@.VÚ��7@€¶������-���src/Composer/Repository/RepositoryManager.phpæ��2@.Væ��¯YÙI¶������7���src/Composer/Repository/RepositorySecurityException.phpo���2@.Vo���pÕ«ª¶������2���src/Composer/Repository/Vcs/GitBitbucketDriver.phpì ��2@.Vì ��Fÿô¶������)���src/Composer/Repository/Vcs/GitDriver.php��2@.V��\îï¶������,���src/Composer/Repository/Vcs/GitHubDriver.phpá'��2@.Vá'��“ü@¶������1���src/Composer/Repository/Vcs/HgBitbucketDriver.phpô ��2@.Vô ��˜áWõ¶������(���src/Composer/Repository/Vcs/HgDriver.phpà��2@.Và��ñ‘綶������.���src/Composer/Repository/Vcs/PerforceDriver.php"
  35. ��2@.V"
  36. ��°`ìE¶������)���src/Composer/Repository/Vcs/SvnDriver.php²��2@.V²��Ë W¶������)���src/Composer/Repository/Vcs/VcsDriver.phpÑ��2@.VÑ��å%R¶������2���src/Composer/Repository/Vcs/VcsDriverInterface.phpˆ��2@.Vˆ��ŽP©Î¶������)���src/Composer/Repository/VcsRepository.php;��2@.V;��ayÉ£¶������3���src/Composer/Repository/WritableArrayRepository.php��2@.V��¾G*¶������7���src/Composer/Repository/WritableRepositoryInterface.php‰��2@.V‰��‘/sï¶������$���src/Composer/Script/CommandEvent.phpW���2@.VW���£VZt¶���������src/Composer/Script/Event.phpµ��2@.Vµ��lt¦M¶������$���src/Composer/Script/PackageEvent.phpœ���2@.Vœ���§ÿÉ ¶������$���src/Composer/Script/ScriptEvents.phpP��2@.VP��‡�¶¶������ ���src/Composer/Util/AuthHelper.phpË��2@.VË��>zx–¶������$���src/Composer/Util/ComposerMirror.php±��2@.V±��­½øض������%���src/Composer/Util/ConfigValidator.phpƒ��2@.Vƒ��YFQ!¶������"���src/Composer/Util/ErrorHandler.phpY��2@.VY��³vB¶������ ���src/Composer/Util/Filesystem.phpJ&��2@.VJ&��§�ßc¶���������src/Composer/Util/Git.php��2@.V��¥S|Ŷ���������src/Composer/Util/GitHub.php–
  37. ��2@.V–
  38. ��Êï'”¶������$���src/Composer/Util/NoProxyPattern.php¾��2@.V¾��Z+°m¶���������src/Composer/Util/Perforce.php3��2@.V3��¶-Ñȶ������%���src/Composer/Util/ProcessExecutor.phpí��2@.Ví��bF‘«¶������&���src/Composer/Util/RemoteFilesystem.php +��2@.V +��=$5¶������!���src/Composer/Util/SpdxLicense.php��2@.V��œ@›ƒ¶������*���src/Composer/Util/StreamContextFactory.phpÎ ��2@.VÎ ��ëä³Y¶���������src/Composer/Util/Svn.php†��2@.V†��e@î¶���������src/bootstrap.phpÅ��2@.VÅ��¨¯2�¶������%���src/Composer/Autoload/ClassLoader.php”0��2@.V”0��¸Lh¦¶���������res/composer-schema.json7U��2@.V7U��)Š¨>¶������6���vendor/composer/spdx-licenses/res/spdx-exceptions.json¹��2@.V¹��kw°¶������4���vendor/composer/spdx-licenses/res/spdx-licenses.json¿]��2@.V¿]��%z"�¶������*���vendor/seld/cli-prompt/res/hiddeninput.exe�$��2@.V�$��•�¥v¶������@���vendor/symfony/console/Symfony/Component/Console/Application.phpÎR��2@.VÎR��?sK¶������D���vendor/symfony/console/Symfony/Component/Console/Command/Command.phpð��2@.Vð��pŶ������H���vendor/symfony/console/Symfony/Component/Console/Command/HelpCommand.php6��2@.V6��#¯¾}¶������H���vendor/symfony/console/Symfony/Component/Console/Command/ListCommand.php³��2@.V³��VÓé¶������B���vendor/symfony/console/Symfony/Component/Console/ConsoleEvents.phpï���2@.Vï��� ÕH¸¶������V���vendor/symfony/console/Symfony/Component/Console/Descriptor/ApplicationDescription.php��2@.V��ù0Ðj¶������J���vendor/symfony/console/Symfony/Component/Console/Descriptor/Descriptor.php\��2@.V\��WJ[í¶������S���vendor/symfony/console/Symfony/Component/Console/Descriptor/DescriptorInterface.phpü���2@.Vü���±Qµ¶������N���vendor/symfony/console/Symfony/Component/Console/Descriptor/JsonDescriptor.php2 ��2@.V2 ��†ca¶������R���vendor/symfony/console/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php
  39. ��2@.V
  40. ���LÛ*¶������N���vendor/symfony/console/Symfony/Component/Console/Descriptor/TextDescriptor.php4��2@.V4��`âÐ8¶������M���vendor/symfony/console/Symfony/Component/Console/Descriptor/XmlDescriptor.php ��2@.V ��…{îm¶������N���vendor/symfony/console/Symfony/Component/Console/Event/ConsoleCommandEvent.php²��2@.V²��Zk‰2¶������G���vendor/symfony/console/Symfony/Component/Console/Event/ConsoleEvent.phpÅ��2@.VÅ��ÒxÛ\¶������P���vendor/symfony/console/Symfony/Component/Console/Event/ConsoleExceptionEvent.php��2@.V��á2é¶������P���vendor/symfony/console/Symfony/Component/Console/Event/ConsoleTerminateEvent.phpz��2@.Vz��³,îL¶������N���vendor/symfony/console/Symfony/Component/Console/Formatter/OutputFormatter.php� ��2@.V� ��%šÒ¬¶������W���vendor/symfony/console/Symfony/Component/Console/Formatter/OutputFormatterInterface.php˜��2@.V˜��3l~´¶������S���vendor/symfony/console/Symfony/Component/Console/Formatter/OutputFormatterStyle.php��2@.V��,{ZŠ¶������\���vendor/symfony/console/Symfony/Component/Console/Formatter/OutputFormatterStyleInterface.phpŽ��2@.VŽ��öëÄ=¶������X���vendor/symfony/console/Symfony/Component/Console/Formatter/OutputFormatterStyleStack.php
  41. ��2@.V
  42. ��,½-¶������P���vendor/symfony/console/Symfony/Component/Console/Helper/DebugFormatterHelper.phpx��2@.Vx��žH@¶������L���vendor/symfony/console/Symfony/Component/Console/Helper/DescriptorHelper.php9��2@.V9��ûùäð¶������H���vendor/symfony/console/Symfony/Component/Console/Helper/DialogHelper.php­��2@.V­��ø=ÜÓ¶������K���vendor/symfony/console/Symfony/Component/Console/Helper/FormatterHelper.phpc��2@.Vc��“ý«N¶������B���vendor/symfony/console/Symfony/Component/Console/Helper/Helper.phpß��2@.Vß��o¾ã¶������K���vendor/symfony/console/Symfony/Component/Console/Helper/HelperInterface.phpï���2@.Vï���=e ¶������E���vendor/symfony/console/Symfony/Component/Console/Helper/HelperSet.php/��2@.V/��âw�d¶������L���vendor/symfony/console/Symfony/Component/Console/Helper/InputAwareHelper.phpc��2@.Vc��ñø�|¶������I���vendor/symfony/console/Symfony/Component/Console/Helper/ProcessHelper.phpâ��2@.Vâ��|̼¶������G���vendor/symfony/console/Symfony/Component/Console/Helper/ProgressBar.php$��2@.V$��ô¶������J���vendor/symfony/console/Symfony/Component/Console/Helper/ProgressHelper.phpƒ��2@.Vƒ��“h™¶������J���vendor/symfony/console/Symfony/Component/Console/Helper/QuestionHelper.php��2@.V��R Š¶������A���vendor/symfony/console/Symfony/Component/Console/Helper/Table.php��2@.V��‚¸A)¶������G���vendor/symfony/console/Symfony/Component/Console/Helper/TableHelper.phpØ
  43. ��2@.VØ
  44. ��,  ¶������J���vendor/symfony/console/Symfony/Component/Console/Helper/TableSeparator.php[���2@.V[���LV¡¶������F���vendor/symfony/console/Symfony/Component/Console/Helper/TableStyle.phpÕ��2@.VÕ��æ"ðù¶������D���vendor/symfony/console/Symfony/Component/Console/Input/ArgvInput.phpÑ��2@.VÑ��íÐ�¶������E���vendor/symfony/console/Symfony/Component/Console/Input/ArrayInput.phpû ��2@.Vû ��âö¥p¶������@���vendor/symfony/console/Symfony/Component/Console/Input/Input.php
  45. ��2@.V
  46. ��ÇýT¶������H���vendor/symfony/console/Symfony/Component/Console/Input/InputArgument.phpž��2@.Vž��K]ìi¶������N���vendor/symfony/console/Symfony/Component/Console/Input/InputAwareInterface.phpš���2@.Vš���‡jTŸ¶������J���vendor/symfony/console/Symfony/Component/Console/Input/InputDefinition.php ��2@.V ��˜£JM¶������I���vendor/symfony/console/Symfony/Component/Console/Input/InputInterface.php ��2@.V ��9”øǶ������F���vendor/symfony/console/Symfony/Component/Console/Input/InputOption.php« ��2@.V« ��ꆮ½¶������F���vendor/symfony/console/Symfony/Component/Console/Input/StringInput.php‹��2@.V‹��†uný¶������8���vendor/symfony/console/Symfony/Component/Console/LICENSE)��2@.V)��ë&•¶������I���vendor/symfony/console/Symfony/Component/Console/Logger/ConsoleLogger.php; ��2@.V; ��#ØB~¶������J���vendor/symfony/console/Symfony/Component/Console/Output/BufferedOutput.php_��2@.V_��ûBÍ·¶������I���vendor/symfony/console/Symfony/Component/Console/Output/ConsoleOutput.php±��2@.V±��)m¶������R���vendor/symfony/console/Symfony/Component/Console/Output/ConsoleOutputInterface.phpå���2@.Vå���rNô�¶������F���vendor/symfony/console/Symfony/Component/Console/Output/NullOutput.php¿��2@.V¿��`5E˶������B���vendor/symfony/console/Symfony/Component/Console/Output/Output.php§��2@.V§��Ú _¶������K���vendor/symfony/console/Symfony/Component/Console/Output/OutputInterface.phpI��2@.VI��ÈâãB¶������H���vendor/symfony/console/Symfony/Component/Console/Output/StreamOutput.php£��2@.V£���_Õ¶������L���vendor/symfony/console/Symfony/Component/Console/Question/ChoiceQuestion.php^��2@.V^��C‚¦Û¶������R���vendor/symfony/console/Symfony/Component/Console/Question/ConfirmationQuestion.phpK��2@.VK��õÃTȶ������F���vendor/symfony/console/Symfony/Component/Console/Question/Question.php®��2@.V®��.e8Ö¶������:���vendor/symfony/console/Symfony/Component/Console/Shell.php1��2@.V1��U­È,¶������M���vendor/symfony/console/Symfony/Component/Console/Tester/ApplicationTester.phpÔ��2@.VÔ��¬ì¤d¶������I���vendor/symfony/console/Symfony/Component/Console/Tester/CommandTester.php®��2@.V®��EÙš|¶������W���vendor/symfony/filesystem/Symfony/Component/Filesystem/Exception/ExceptionInterface.phpk���2@.Vk���€Ûèà¶������Z���vendor/symfony/filesystem/Symfony/Component/Filesystem/Exception/FileNotFoundException.php¼��2@.V¼��pí\¶¶������P���vendor/symfony/filesystem/Symfony/Component/Filesystem/Exception/IOException.php‰��2@.V‰��Ö0ÿn¶������Y���vendor/symfony/filesystem/Symfony/Component/Filesystem/Exception/IOExceptionInterface.php¦���2@.V¦���jÙwM¶������E���vendor/symfony/filesystem/Symfony/Component/Filesystem/Filesystem.php¤&��2@.V¤&��Cäs¶������>���vendor/symfony/filesystem/Symfony/Component/Filesystem/LICENSE)��2@.V)��ë&•¶������F���vendor/symfony/filesystem/Symfony/Component/Filesystem/LockHandler.phpÊ��2@.VÊ��¤¸X¿¶������J���vendor/symfony/finder/Symfony/Component/Finder/Adapter/AbstractAdapter.php¤
  47. ��2@.V¤
  48. ��¢)z9¶������N���vendor/symfony/finder/Symfony/Component/Finder/Adapter/AbstractFindAdapter.phpÝ��2@.VÝ��Þ_“ø¶������K���vendor/symfony/finder/Symfony/Component/Finder/Adapter/AdapterInterface.php¯��2@.V¯��‹éȶ������I���vendor/symfony/finder/Symfony/Component/Finder/Adapter/BsdFindAdapter.php{��2@.V{��Q,D2¶������I���vendor/symfony/finder/Symfony/Component/Finder/Adapter/GnuFindAdapter.php^��2@.V^��ßz˜r¶������E���vendor/symfony/finder/Symfony/Component/Finder/Adapter/PhpAdapter.php+��2@.V+��&˜îÒ¶������H���vendor/symfony/finder/Symfony/Component/Finder/Comparator/Comparator.phpŒ��2@.VŒ��wþT¶������L���vendor/symfony/finder/Symfony/Component/Finder/Comparator/DateComparator.php%��2@.V%��L¿EǶ������N���vendor/symfony/finder/Symfony/Component/Finder/Comparator/NumberComparator.php~��2@.V~��”‡ x¶������R���vendor/symfony/finder/Symfony/Component/Finder/Exception/AccessDeniedException.php„���2@.V„���½¾sœ¶������T���vendor/symfony/finder/Symfony/Component/Finder/Exception/AdapterFailureException.php��2@.V��mŒ_,¶������O���vendor/symfony/finder/Symfony/Component/Finder/Exception/ExceptionInterface.php„���2@.V„���Gz-¶������Z���vendor/symfony/finder/Symfony/Component/Finder/Exception/OperationNotPermitedException.phpŠ���2@.VŠ���U88¶������Y���vendor/symfony/finder/Symfony/Component/Finder/Exception/ShellCommandFailureException.php$��2@.V$��C”sÓ¶������H���vendor/symfony/finder/Symfony/Component/Finder/Expression/Expression.php}��2@.V}��/·cð¶������B���vendor/symfony/finder/Symfony/Component/Finder/Expression/Glob.php¡��2@.V¡��3^äë¶������C���vendor/symfony/finder/Symfony/Component/Finder/Expression/Regex.php���2@.V���S7Pæ¶������L���vendor/symfony/finder/Symfony/Component/Finder/Expression/ValueInterface.php;��2@.V;�� îãÓ¶������9���vendor/symfony/finder/Symfony/Component/Finder/Finder.php#��2@.V#���Ó$ê¶������7���vendor/symfony/finder/Symfony/Component/Finder/Glob.php ��2@.V ��¥ M¶������P���vendor/symfony/finder/Symfony/Component/Finder/Iterator/CustomFilterIterator.php]��2@.V]��tà±µ¶������S���vendor/symfony/finder/Symfony/Component/Finder/Iterator/DateRangeFilterIterator.phpz��2@.Vz��}¢¶������T���vendor/symfony/finder/Symfony/Component/Finder/Iterator/DepthRangeFilterIterator.phpð��2@.Vð��ß0™¶������Z���vendor/symfony/finder/Symfony/Component/Finder/Iterator/ExcludeDirectoryFilterIterator.php”��2@.V”��"ÖóÁ¶������M���vendor/symfony/finder/Symfony/Component/Finder/Iterator/FilePathsIterator.php���2@.V���ýòäQ¶������R���vendor/symfony/finder/Symfony/Component/Finder/Iterator/FileTypeFilterIterator.php\��2@.V\��p‘'˜¶������U���vendor/symfony/finder/Symfony/Component/Finder/Iterator/FilecontentFilterIterator.php#��2@.V#��Ú_VǶ������R���vendor/symfony/finder/Symfony/Component/Finder/Iterator/FilenameFilterIterator.php‡��2@.V‡��F ’ ¶������J���vendor/symfony/finder/Symfony/Component/Finder/Iterator/FilterIterator.php†��2@.V†��0£¾Ô¶������V���vendor/symfony/finder/Symfony/Component/Finder/Iterator/MultiplePcreFilterIterator.phpØ��2@.VØ��Òù“¶������N���vendor/symfony/finder/Symfony/Component/Finder/Iterator/PathFilterIterator.php¸��2@.V¸��E*E¶������V���vendor/symfony/finder/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.phpY��2@.VY��êÓÊܶ������S���vendor/symfony/finder/Symfony/Component/Finder/Iterator/SizeRangeFilterIterator.phpg��2@.Vg��!Ô—é¶������L���vendor/symfony/finder/Symfony/Component/Finder/Iterator/SortableIterator.phpÞ��2@.VÞ��ö³%¶������6���vendor/symfony/finder/Symfony/Component/Finder/LICENSE)��2@.V)��ë&•¶������@���vendor/symfony/finder/Symfony/Component/Finder/Shell/Command.phpÊ
  49. ��2@.VÊ
  50. ��É_ï¶������>���vendor/symfony/finder/Symfony/Component/Finder/Shell/Shell.phpé��2@.Vé��¿ëÛ•¶������>���vendor/symfony/finder/Symfony/Component/Finder/SplFileInfo.phpû��2@.Vû��‘†6¶������Q���vendor/symfony/process/Symfony/Component/Process/Exception/ExceptionInterface.phpf���2@.Vf���]ö>T¶������W���vendor/symfony/process/Symfony/Component/Process/Exception/InvalidArgumentException.php¨���2@.V¨���ÐÀ+_¶������M���vendor/symfony/process/Symfony/Component/Process/Exception/LogicException.php”���2@.V”��� ³ãñ¶������U���vendor/symfony/process/Symfony/Component/Process/Exception/ProcessFailedException.php<��2@.V<��"wÛn¶������W���vendor/symfony/process/Symfony/Component/Process/Exception/ProcessTimedOutException.php��2@.V��. Ãá¶������O���vendor/symfony/process/Symfony/Component/Process/Exception/RuntimeException.php˜���2@.V˜���¢Ø:¶������E���vendor/symfony/process/Symfony/Component/Process/ExecutableFinder.php~��2@.V~��+…¶������8���vendor/symfony/process/Symfony/Component/Process/LICENSE)��2@.V)��ë&•¶������H���vendor/symfony/process/Symfony/Component/Process/PhpExecutableFinder.phpù��2@.Vù��}E᪶������?���vendor/symfony/process/Symfony/Component/Process/PhpProcess.php×��2@.V×��Š€«¶������H���vendor/symfony/process/Symfony/Component/Process/Pipes/AbstractPipes.php���2@.V���˜|¥¾¶������I���vendor/symfony/process/Symfony/Component/Process/Pipes/PipesInterface.phpD��2@.VD��vØ������D���vendor/symfony/process/Symfony/Component/Process/Pipes/UnixPipes.php¤ ��2@.V¤ ��øUt¶������G���vendor/symfony/process/Symfony/Component/Process/Pipes/WindowsPipes.php½��2@.V½���.X£¶������<���vendor/symfony/process/Symfony/Component/Process/Process.phpÚN��2@.VÚN��ZEkv¶������C���vendor/symfony/process/Symfony/Component/Process/ProcessBuilder.php ��2@.V ���ïy¶������A���vendor/symfony/process/Symfony/Component/Process/ProcessUtils.php‹��2@.V‹��
  51. c†¶���������vendor/seld/jsonlint/LICENSE"��2@.V"��aƒsy¶������5���vendor/seld/jsonlint/src/Seld/JsonLint/JsonParser.php)1��2@.V)1��?5R3¶������0���vendor/seld/jsonlint/src/Seld/JsonLint/Lexer.php��2@.V��‰„m!¶������;���vendor/seld/jsonlint/src/Seld/JsonLint/ParsingException.php��2@.V��‰²ñ¶������4���vendor/seld/jsonlint/src/Seld/JsonLint/Undefined.php>���2@.V>���ÿqŸŸ¶���������vendor/seld/cli-prompt/LICENSE"��2@.V"��ˆñ?e¶������&���vendor/seld/cli-prompt/res/example.php'��2@.V'��I£¶������(���vendor/seld/cli-prompt/src/CliPrompt.php��2@.V��­é™v¶������(���vendor/justinrainbow/json-schema/LICENSE÷��2@.V÷��xÞxt¶������T���vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/CollectionConstraint.php ��2@.V ��¨Ö
  52. ¨¶������J���vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php‰��2@.V‰��!Êf¹¶������S���vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/ConstraintInterface.phpN��2@.VN��øÆMy¶������N���vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/EnumConstraint.phpO��2@.VO�� Ú"¶������P���vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/FormatConstraint.php® ��2@.V® ���'®»¶������P���vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/NumberConstraint.phpµ��2@.Vµ��@ð¶������P���vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/ObjectConstraint.phpë
  53. ��2@.Vë
  54. ��Ì.#ä¶������P���vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/SchemaConstraint.php ��2@.V ��ÈÌÕâ¶������P���vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/StringConstraint.php©��2@.V©��^¯R¶������N���vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/TypeConstraint.php��2@.V��÷³¼¶������S���vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/UndefinedConstraint.php¢��2@.V¢��òí×®¶������V���vendor/justinrainbow/json-schema/src/JsonSchema/Exception/InvalidArgumentException.phpv���2@.Vv���¬ «"¶������]���vendor/justinrainbow/json-schema/src/JsonSchema/Exception/InvalidSchemaMediaTypeException.phpv���2@.Vv���ŠCÓ¶������W���vendor/justinrainbow/json-schema/src/JsonSchema/Exception/InvalidSourceUriException.phpw���2@.Vw���N-ò[¶������S���vendor/justinrainbow/json-schema/src/JsonSchema/Exception/JsonDecodingException.phpÞ��2@.VÞ��†¾©‘¶������W���vendor/justinrainbow/json-schema/src/JsonSchema/Exception/ResourceNotFoundException.phpo���2@.Vo���Æ$"Ŷ������R���vendor/justinrainbow/json-schema/src/JsonSchema/Exception/UriResolverException.phpj���2@.Vj���SÓdz¶������?���vendor/justinrainbow/json-schema/src/JsonSchema/RefResolver.phpÀ ��2@.VÀ ���c«¶������T���vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/AbstractRetriever.phpÜ���2@.VÜ���]j¶������G���vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/Curl.phpt��2@.Vt��I·ý�¶������R���vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/FileGetContents.phpb��2@.Vb��WýÁ¶������R���vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/PredefinedArray.php*��2@.V*��-3ÿ¶������X���vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/UriRetrieverInterface.php©���2@.V©���CO¶������C���vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriResolver.phpR ��2@.VR ��pÿi1¶������D���vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriRetriever.phpa��2@.Va��¾,Η¶������=���vendor/justinrainbow/json-schema/src/JsonSchema/Validator.phpæ��2@.Væ��,u¶������%���vendor/composer/spdx-licenses/LICENSE��2@.V��Bhí¶������2���vendor/composer/spdx-licenses/src/SpdxLicenses.phpå��2@.Vå��=Ø7¶���������vendor/composer/semver/LICENSE��2@.V��Bhí¶������)���vendor/composer/semver/src/Comparator.php��2@.V��wlƒï¶������<���vendor/composer/semver/src/Constraint/AbstractConstraint.phpk��2@.Vk��è§Àm¶������4���vendor/composer/semver/src/Constraint/Constraint.phpù
  55. ��2@.Vù
  56. ��­¸Èõ¶������=���vendor/composer/semver/src/Constraint/ConstraintInterface.php��2@.V��¾sX¶������9���vendor/composer/semver/src/Constraint/EmptyConstraint.phpé��2@.Vé��!-Ø™¶������9���vendor/composer/semver/src/Constraint/MultiConstraint.phpf��2@.Vf��Dðì>¶������%���vendor/composer/semver/src/Semver.phpv��2@.Vv��‹×È›¶������,���vendor/composer/semver/src/VersionParser.php (��2@.V (��´MPÿ¶���������vendor/autoload.php‡���2@.V‡���F*W~¶������'���vendor/composer/autoload_namespaces.php¼��2@.V¼���D­¶������!���vendor/composer/autoload_psr4.php��2@.V��šù‹®¶������%���vendor/composer/autoload_classmap.phpd���2@.Vd���Z¡¦H¶������!���vendor/composer/autoload_real.php7��2@.V7��›O‰¶���������vendor/composer/ClassLoader.phpB��2@.VB��é”í¶������ ���bin/composerl��2@.Vl��Ԛà ¶���������LICENSE3��2@.V3��fýÞX¶������<?php
  57. namespace Composer\Autoload;
  58. use Composer\Config;
  59. use Composer\EventDispatcher\EventDispatcher;
  60. use Composer\Installer\InstallationManager;
  61. use Composer\IO\IOInterface;
  62. use Composer\Package\AliasPackage;
  63. use Composer\Package\PackageInterface;
  64. use Composer\Repository\InstalledRepositoryInterface;
  65. use Composer\Util\Filesystem;
  66. use Composer\Script\ScriptEvents;
  67. class AutoloadGenerator
  68. {
  69. private $eventDispatcher;
  70. private $io;
  71. private $devMode = false;
  72. private $classMapAuthoritative = false;
  73. public function __construct(EventDispatcher $eventDispatcher, IOInterface $io = null)
  74. {
  75. $this->eventDispatcher = $eventDispatcher;
  76. $this->io = $io;
  77. }
  78. public function setDevMode($devMode = true)
  79. {
  80. $this->devMode = (boolean) $devMode;
  81. }
  82. public function setClassMapAuthoritative($classMapAuthoritative)
  83. {
  84. $this->classMapAuthoritative = (boolean) $classMapAuthoritative;
  85. }
  86. public function dump(Config $config, InstalledRepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $scanPsr0Packages = false, $suffix = '')
  87. {
  88. if ($this->classMapAuthoritative) {
  89. $scanPsr0Packages = true;
  90. }
  91. $this->eventDispatcher->dispatchScript(ScriptEvents::PRE_AUTOLOAD_DUMP, $this->devMode, array(), array(
  92. 'optimize' => (bool) $scanPsr0Packages,
  93. ));
  94. $filesystem = new Filesystem();
  95. $filesystem->ensureDirectoryExists($config->get('vendor-dir'));
  96. $basePath = $filesystem->normalizePath(realpath(getcwd()));
  97. $vendorPath = $filesystem->normalizePath(realpath($config->get('vendor-dir')));
  98. $useGlobalIncludePath = (bool) $config->get('use-include-path');
  99. $prependAutoloader = $config->get('prepend-autoloader') === false ? 'false' : 'true';
  100. $targetDir = $vendorPath.'/'.$targetDir;
  101. $filesystem->ensureDirectoryExists($targetDir);
  102. $vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
  103. $vendorPathCode52 = str_replace('__DIR__', 'dirname(__FILE__)', $vendorPathCode);
  104. $vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, realpath($targetDir), true);
  105. $appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, $basePath, true);
  106. $appBaseDirCode = str_replace('__DIR__', '$vendorDir', $appBaseDirCode);
  107. $namespacesFile = <<<EOF
  108. <?php
  109. // autoload_namespaces.php @generated by Composer
  110. \$vendorDir = $vendorPathCode52;
  111. \$baseDir = $appBaseDirCode;
  112. return array(
  113. EOF;
  114. $psr4File = <<<EOF
  115. <?php
  116. // autoload_psr4.php @generated by Composer
  117. \$vendorDir = $vendorPathCode52;
  118. \$baseDir = $appBaseDirCode;
  119. return array(
  120. EOF;
  121. $packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getCanonicalPackages());
  122. $autoloads = $this->parseAutoloads($packageMap, $mainPackage);
  123. foreach ($autoloads['psr-0'] as $namespace => $paths) {
  124. $exportedPaths = array();
  125. foreach ($paths as $path) {
  126. $exportedPaths[] = $this->getPathCode($filesystem, $basePath, $vendorPath, $path);
  127. }
  128. $exportedPrefix = var_export($namespace, true);
  129. $namespacesFile .= " $exportedPrefix => ";
  130. $namespacesFile .= "array(".implode(', ', $exportedPaths)."),\n";
  131. }
  132. $namespacesFile .= ");\n";
  133. foreach ($autoloads['psr-4'] as $namespace => $paths) {
  134. $exportedPaths = array();
  135. foreach ($paths as $path) {
  136. $exportedPaths[] = $this->getPathCode($filesystem, $basePath, $vendorPath, $path);
  137. }
  138. $exportedPrefix = var_export($namespace, true);
  139. $psr4File .= " $exportedPrefix => ";
  140. $psr4File .= "array(".implode(', ', $exportedPaths)."),\n";
  141. }
  142. $psr4File .= ");\n";
  143. $classmapFile = <<<EOF
  144. <?php
  145. // autoload_classmap.php @generated by Composer
  146. \$vendorDir = $vendorPathCode52;
  147. \$baseDir = $appBaseDirCode;
  148. return array(
  149. EOF;
  150. $targetDirLoader = null;
  151. $mainAutoload = $mainPackage->getAutoload();
  152. if ($mainPackage->getTargetDir() && !empty($mainAutoload['psr-0'])) {
  153. $levels = count(explode('/', $filesystem->normalizePath($mainPackage->getTargetDir())));
  154. $prefixes = implode(', ', array_map(function ($prefix) {
  155. return var_export($prefix, true);
  156. }, array_keys($mainAutoload['psr-0'])));
  157. $baseDirFromTargetDirCode = $filesystem->findShortestPathCode($targetDir, $basePath, true);
  158. $targetDirLoader = <<<EOF
  159. public static function autoload(\$class)
  160. {
  161. \$dir = $baseDirFromTargetDirCode . '/';
  162. \$prefixes = array($prefixes);
  163. foreach (\$prefixes as \$prefix) {
  164. if (0 !== strpos(\$class, \$prefix)) {
  165. continue;
  166. }
  167. \$path = \$dir . implode('/', array_slice(explode('\\\\', \$class), $levels)).'.php';
  168. if (!\$path = stream_resolve_include_path(\$path)) {
  169. return false;
  170. }
  171. require \$path;
  172. return true;
  173. }
  174. }
  175. EOF;
  176. }
  177. $classMap = array();
  178. if ($scanPsr0Packages) {
  179. $namespacesToScan = array();
  180. foreach (array('psr-0', 'psr-4') as $psrType) {
  181. foreach ($autoloads[$psrType] as $namespace => $paths) {
  182. $namespacesToScan[$namespace][] = array('paths' => $paths, 'type' => $psrType);
  183. }
  184. }
  185. krsort($namespacesToScan);
  186. foreach ($namespacesToScan as $namespace => $groups) {
  187. foreach ($groups as $group) {
  188. $psrType = $group['type'];
  189. foreach ($group['paths'] as $dir) {
  190. $dir = $filesystem->normalizePath($filesystem->isAbsolutePath($dir) ? $dir : $basePath.'/'.$dir);
  191. if (!is_dir($dir)) {
  192. continue;
  193. }
  194. $whitelist = sprintf(
  195. '{%s/%s.+$}',
  196. preg_quote($dir),
  197. ($psrType === 'psr-0' && strpos($namespace, '_') === false) ? preg_quote(strtr($namespace, '\\', '/')) : ''
  198. );
  199. $namespaceFilter = $namespace === '' ? null : $namespace;
  200. foreach (ClassMapGenerator::createMap($dir, $whitelist, $this->io, $namespaceFilter) as $class => $path) {
  201. $pathCode = $this->getPathCode($filesystem, $basePath, $vendorPath, $path).",\n";
  202. if (!isset($classMap[$class])) {
  203. $classMap[$class] = $pathCode;
  204. } elseif ($this->io && $classMap[$class] !== $pathCode && !preg_match('{/(test|fixture|example|stub)s?/}i', strtr($classMap[$class].' '.$path, '\\', '/'))) {
  205. $this->io->writeError(
  206. '<warning>Warning: Ambiguous class resolution, "'.$class.'"'.
  207. ' was found in both "'.str_replace(array('$vendorDir . \'', "',\n"), array($vendorPath, ''), $classMap[$class]).'" and "'.$path.'", the first will be used.</warning>'
  208. );
  209. }
  210. }
  211. }
  212. }
  213. }
  214. }
  215. foreach ($autoloads['classmap'] as $dir) {
  216. foreach (ClassMapGenerator::createMap($dir, null, $this->io) as $class => $path) {
  217. $pathCode = $this->getPathCode($filesystem, $basePath, $vendorPath, $path).",\n";
  218. if (!isset($classMap[$class])) {
  219. $classMap[$class] = $pathCode;
  220. } elseif ($this->io && $classMap[$class] !== $pathCode && !preg_match('{/(test|fixture|example|stub)s?/}i', strtr($classMap[$class].' '.$path, '\\', '/'))) {
  221. $this->io->writeError(
  222. '<warning>Warning: Ambiguous class resolution, "'.$class.'"'.
  223. ' was found in both "'.str_replace(array('$vendorDir . \'', "',\n"), array($vendorPath, ''), $classMap[$class]).'" and "'.$path.'", the first will be used.</warning>'
  224. );
  225. }
  226. }
  227. }
  228. ksort($classMap);
  229. foreach ($classMap as $class => $code) {
  230. $classmapFile .= ' '.var_export($class, true).' => '.$code;
  231. }
  232. $classmapFile .= ");\n";
  233. if (!$suffix) {
  234. if (!$config->get('autoloader-suffix') && is_readable($vendorPath.'/autoload.php')) {
  235. $content = file_get_contents($vendorPath.'/autoload.php');
  236. if (preg_match('{ComposerAutoloaderInit([^:\s]+)::}', $content, $match)) {
  237. $suffix = $match[1];
  238. }
  239. }
  240. if (!$suffix) {
  241. $suffix = $config->get('autoloader-suffix') ?: md5(uniqid('', true));
  242. }
  243. }
  244. file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile);
  245. file_put_contents($targetDir.'/autoload_psr4.php', $psr4File);
  246. file_put_contents($targetDir.'/autoload_classmap.php', $classmapFile);
  247. $includePathFilePath = $targetDir.'/include_paths.php';
  248. if ($includePathFileContents = $this->getIncludePathsFile($packageMap, $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) {
  249. file_put_contents($includePathFilePath, $includePathFileContents);
  250. } elseif (file_exists($includePathFilePath)) {
  251. unlink($includePathFilePath);
  252. }
  253. $includeFilesFilePath = $targetDir.'/autoload_files.php';
  254. if ($includeFilesFileContents = $this->getIncludeFilesFile($autoloads['files'], $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) {
  255. file_put_contents($includeFilesFilePath, $includeFilesFileContents);
  256. } elseif (file_exists($includeFilesFilePath)) {
  257. unlink($includeFilesFilePath);
  258. }
  259. file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix));
  260. file_put_contents($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, (bool) $includePathFileContents, $targetDirLoader, (bool) $includeFilesFileContents, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader));
  261. $this->safeCopy(__DIR__.'/ClassLoader.php', $targetDir.'/ClassLoader.php');
  262. $this->safeCopy(__DIR__.'/../../../LICENSE', $targetDir.'/LICENSE');
  263. $this->eventDispatcher->dispatchScript(ScriptEvents::POST_AUTOLOAD_DUMP, $this->devMode, array(), array(
  264. 'optimize' => (bool) $scanPsr0Packages,
  265. ));
  266. }
  267. public function buildPackageMap(InstallationManager $installationManager, PackageInterface $mainPackage, array $packages)
  268. {
  269. $packageMap = array(array($mainPackage, ''));
  270. foreach ($packages as $package) {
  271. if ($package instanceof AliasPackage) {
  272. continue;
  273. }
  274. $this->validatePackage($package);
  275. $packageMap[] = array(
  276. $package,
  277. $installationManager->getInstallPath($package),
  278. );
  279. }
  280. return $packageMap;
  281. }
  282. protected function validatePackage(PackageInterface $package)
  283. {
  284. $autoload = $package->getAutoload();
  285. if (!empty($autoload['psr-4']) && null !== $package->getTargetDir()) {
  286. $name = $package->getName();
  287. $package->getTargetDir();
  288. throw new \InvalidArgumentException("PSR-4 autoloading is incompatible with the target-dir property, remove the target-dir in package '$name'.");
  289. }
  290. if (!empty($autoload['psr-4'])) {
  291. foreach ($autoload['psr-4'] as $namespace => $dirs) {
  292. if ($namespace !== '' && '\\' !== substr($namespace, -1)) {
  293. throw new \InvalidArgumentException("psr-4 namespaces must end with a namespace separator, '$namespace' does not, use '$namespace\\'.");
  294. }
  295. }
  296. }
  297. }
  298. public function parseAutoloads(array $packageMap, PackageInterface $mainPackage)
  299. {
  300. $mainPackageMap = array_shift($packageMap);
  301. $sortedPackageMap = $this->sortPackageMap($packageMap);
  302. $sortedPackageMap[] = $mainPackageMap;
  303. array_unshift($packageMap, $mainPackageMap);
  304. $psr0 = $this->parseAutoloadsType($packageMap, 'psr-0', $mainPackage);
  305. $psr4 = $this->parseAutoloadsType($packageMap, 'psr-4', $mainPackage);
  306. $classmap = $this->parseAutoloadsType(array_reverse($sortedPackageMap), 'classmap', $mainPackage);
  307. $files = $this->parseAutoloadsType($sortedPackageMap, 'files', $mainPackage);
  308. krsort($psr0);
  309. krsort($psr4);
  310. return array('psr-0' => $psr0, 'psr-4' => $psr4, 'classmap' => $classmap, 'files' => $files);
  311. }
  312. public function createLoader(array $autoloads)
  313. {
  314. $loader = new ClassLoader();
  315. if (isset($autoloads['psr-0'])) {
  316. foreach ($autoloads['psr-0'] as $namespace => $path) {
  317. $loader->add($namespace, $path);
  318. }
  319. }
  320. if (isset($autoloads['psr-4'])) {
  321. foreach ($autoloads['psr-4'] as $namespace => $path) {
  322. $loader->addPsr4($namespace, $path);
  323. }
  324. }
  325. return $loader;
  326. }
  327. protected function getIncludePathsFile(array $packageMap, Filesystem $filesystem, $basePath, $vendorPath, $vendorPathCode, $appBaseDirCode)
  328. {
  329. $includePaths = array();
  330. foreach ($packageMap as $item) {
  331. list($package, $installPath) = $item;
  332. if (null !== $package->getTargetDir() && strlen($package->getTargetDir()) > 0) {
  333. $installPath = substr($installPath, 0, -strlen('/'.$package->getTargetDir()));
  334. }
  335. foreach ($package->getIncludePaths() as $includePath) {
  336. $includePath = trim($includePath, '/');
  337. $includePaths[] = empty($installPath) ? $includePath : $installPath.'/'.$includePath;
  338. }
  339. }
  340. if (!$includePaths) {
  341. return;
  342. }
  343. $includePathsCode = '';
  344. foreach ($includePaths as $path) {
  345. $includePathsCode .= " " . $this->getPathCode($filesystem, $basePath, $vendorPath, $path) . ",\n";
  346. }
  347. return <<<EOF
  348. <?php
  349. // include_paths.php @generated by Composer
  350. \$vendorDir = $vendorPathCode;
  351. \$baseDir = $appBaseDirCode;
  352. return array(
  353. $includePathsCode);
  354. EOF;
  355. }
  356. protected function getIncludeFilesFile(array $files, Filesystem $filesystem, $basePath, $vendorPath, $vendorPathCode, $appBaseDirCode)
  357. {
  358. $filesCode = '';
  359. foreach ($files as $functionFile) {
  360. $filesCode .= ' '.$this->getPathCode($filesystem, $basePath, $vendorPath, $functionFile).",\n";
  361. }
  362. if (!$filesCode) {
  363. return false;
  364. }
  365. return <<<EOF
  366. <?php
  367. // autoload_files.php @generated by Composer
  368. \$vendorDir = $vendorPathCode;
  369. \$baseDir = $appBaseDirCode;
  370. return array(
  371. $filesCode);
  372. EOF;
  373. }
  374. protected function getPathCode(Filesystem $filesystem, $basePath, $vendorPath, $path)
  375. {
  376. if (!$filesystem->isAbsolutePath($path)) {
  377. $path = $basePath . '/' . $path;
  378. }
  379. $path = $filesystem->normalizePath($path);
  380. $baseDir = '';
  381. if (strpos($path.'/', $vendorPath.'/') === 0) {
  382. $path = substr($path, strlen($vendorPath));
  383. $baseDir = '$vendorDir';
  384. if ($path !== false) {
  385. $baseDir .= " . ";
  386. }
  387. } else {
  388. $path = $filesystem->normalizePath($filesystem->findShortestPath($basePath, $path, true));
  389. if (!$filesystem->isAbsolutePath($path)) {
  390. $baseDir = '$baseDir . ';
  391. $path = '/' . $path;
  392. }
  393. }
  394. if (preg_match('/\.phar$/', $path)) {
  395. $baseDir = "'phar://' . " . $baseDir;
  396. }
  397. return $baseDir . (($path !== false) ? var_export($path, true) : "");
  398. }
  399. protected function getAutoloadFile($vendorPathToTargetDirCode, $suffix)
  400. {
  401. return <<<AUTOLOAD
  402. <?php
  403. // autoload.php @generated by Composer
  404. require_once $vendorPathToTargetDirCode . '/autoload_real.php';
  405. return ComposerAutoloaderInit$suffix::getLoader();
  406. AUTOLOAD;
  407. }
  408. protected function getAutoloadRealFile($useClassMap, $useIncludePath, $targetDirLoader, $useIncludeFiles, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader)
  409. {
  410. $file = <<<HEADER
  411. <?php
  412. // autoload_real.php @generated by Composer
  413. class ComposerAutoloaderInit$suffix
  414. {
  415. private static \$loader;
  416. public static function loadClassLoader(\$class)
  417. {
  418. if ('Composer\\Autoload\\ClassLoader' === \$class) {
  419. require __DIR__ . '/ClassLoader.php';
  420. }
  421. }
  422. public static function getLoader()
  423. {
  424. if (null !== self::\$loader) {
  425. return self::\$loader;
  426. }
  427. spl_autoload_register(array('ComposerAutoloaderInit$suffix', 'loadClassLoader'), true, $prependAutoloader);
  428. self::\$loader = \$loader = new \\Composer\\Autoload\\ClassLoader();
  429. spl_autoload_unregister(array('ComposerAutoloaderInit$suffix', 'loadClassLoader'));
  430. HEADER;
  431. if ($useIncludePath) {
  432. $file .= <<<'INCLUDE_PATH'
  433. $includePaths = require __DIR__ . '/include_paths.php';
  434. array_push($includePaths, get_include_path());
  435. set_include_path(join(PATH_SEPARATOR, $includePaths));
  436. INCLUDE_PATH;
  437. }
  438. $file .= <<<'PSR0'
  439. $map = require __DIR__ . '/autoload_namespaces.php';
  440. foreach ($map as $namespace => $path) {
  441. $loader->set($namespace, $path);
  442. }
  443. PSR0;
  444. $file .= <<<'PSR4'
  445. $map = require __DIR__ . '/autoload_psr4.php';
  446. foreach ($map as $namespace => $path) {
  447. $loader->setPsr4($namespace, $path);
  448. }
  449. PSR4;
  450. if ($useClassMap) {
  451. $file .= <<<'CLASSMAP'
  452. $classMap = require __DIR__ . '/autoload_classmap.php';
  453. if ($classMap) {
  454. $loader->addClassMap($classMap);
  455. }
  456. CLASSMAP;
  457. }
  458. if ($this->classMapAuthoritative) {
  459. $file .= <<<'CLASSMAPAUTHORITATIVE'
  460. $loader->setClassMapAuthoritative(true);
  461. CLASSMAPAUTHORITATIVE;
  462. }
  463. if ($useGlobalIncludePath) {
  464. $file .= <<<'INCLUDEPATH'
  465. $loader->setUseIncludePath(true);
  466. INCLUDEPATH;
  467. }
  468. if ($targetDirLoader) {
  469. $file .= <<<REGISTER_AUTOLOAD
  470. spl_autoload_register(array('ComposerAutoloaderInit$suffix', 'autoload'), true, true);
  471. REGISTER_AUTOLOAD;
  472. }
  473. $file .= <<<REGISTER_LOADER
  474. \$loader->register($prependAutoloader);
  475. REGISTER_LOADER;
  476. if ($useIncludeFiles) {
  477. $file .= <<<INCLUDE_FILES
  478. \$includeFiles = require __DIR__ . '/autoload_files.php';
  479. foreach (\$includeFiles as \$file) {
  480. composerRequire$suffix(\$file);
  481. }
  482. INCLUDE_FILES;
  483. }
  484. $file .= <<<METHOD_FOOTER
  485. return \$loader;
  486. }
  487. METHOD_FOOTER;
  488. $file .= $targetDirLoader;
  489. return $file . <<<FOOTER
  490. }
  491. function composerRequire$suffix(\$file)
  492. {
  493. require \$file;
  494. }
  495. FOOTER;
  496. }
  497. protected function parseAutoloadsType(array $packageMap, $type, PackageInterface $mainPackage)
  498. {
  499. $autoloads = array();
  500. foreach ($packageMap as $item) {
  501. list($package, $installPath) = $item;
  502. $autoload = $package->getAutoload();
  503. if ($this->devMode && $package === $mainPackage) {
  504. $autoload = array_merge_recursive($autoload, $package->getDevAutoload());
  505. }
  506. if (!isset($autoload[$type]) || !is_array($autoload[$type])) {
  507. continue;
  508. }
  509. if (null !== $package->getTargetDir() && $package !== $mainPackage) {
  510. $installPath = substr($installPath, 0, -strlen('/'.$package->getTargetDir()));
  511. }
  512. foreach ($autoload[$type] as $namespace => $paths) {
  513. foreach ((array) $paths as $path) {
  514. if (($type === 'files' || $type === 'classmap') && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) {
  515. if ($package === $mainPackage) {
  516. $targetDir = str_replace('\\<dirsep\\>', '[\\\\/]', preg_quote(str_replace(array('/', '\\'), '<dirsep>', $package->getTargetDir())));
  517. $path = ltrim(preg_replace('{^'.$targetDir.'}', '', ltrim($path, '\\/')), '\\/');
  518. } else {
  519. $path = $package->getTargetDir() . '/' . $path;
  520. }
  521. }
  522. $relativePath = empty($installPath) ? (empty($path) ? '.' : $path) : $installPath.'/'.$path;
  523. if ($type === 'files' || $type === 'classmap') {
  524. $autoloads[] = $relativePath;
  525. continue;
  526. }
  527. $autoloads[$namespace][] = $relativePath;
  528. }
  529. }
  530. }
  531. return $autoloads;
  532. }
  533. protected function sortPackageMap(array $packageMap)
  534. {
  535. $packages = array();
  536. $paths = array();
  537. $usageList = array();
  538. foreach ($packageMap as $item) {
  539. list($package, $path) = $item;
  540. $name = $package->getName();
  541. $packages[$name] = $package;
  542. $paths[$name] = $path;
  543. foreach (array_merge($package->getRequires(), $package->getDevRequires()) as $link) {
  544. $target = $link->getTarget();
  545. $usageList[$target][] = $name;
  546. }
  547. }
  548. $computing = array();
  549. $computed = array();
  550. $computeImportance = function ($name) use (&$computeImportance, &$computing, &$computed, $usageList) {
  551. if (isset($computed[$name])) {
  552. return $computed[$name];
  553. }
  554. if (isset($computing[$name])) {
  555. return 0;
  556. }
  557. $computing[$name] = true;
  558. $weight = 0;
  559. if (isset($usageList[$name])) {
  560. foreach ($usageList[$name] as $user) {
  561. $weight -= 1 - $computeImportance($user);
  562. }
  563. }
  564. unset($computing[$name]);
  565. $computed[$name] = $weight;
  566. return $weight;
  567. };
  568. $weightList = array();
  569. foreach ($packages as $name => $package) {
  570. $weight = $computeImportance($name);
  571. $weightList[$name] = $weight;
  572. }
  573. $stable_sort = function (&$array) {
  574. static $transform, $restore;
  575. $i = 0;
  576. if (!$transform) {
  577. $transform = function (&$v, $k) use (&$i) {
  578. $v = array($v, ++$i, $k, $v);
  579. };
  580. $restore = function (&$v, $k) {
  581. $v = $v[3];
  582. };
  583. }
  584. array_walk($array, $transform);
  585. asort($array);
  586. array_walk($array, $restore);
  587. };
  588. $stable_sort($weightList);
  589. $sortedPackageMap = array();
  590. foreach (array_keys($weightList) as $name) {
  591. $sortedPackageMap[] = array($packages[$name], $paths[$name]);
  592. }
  593. return $sortedPackageMap;
  594. }
  595. protected function safeCopy($source, $target)
  596. {
  597. $source = fopen($source, 'r');
  598. $target = fopen($target, 'w+');
  599. stream_copy_to_stream($source, $target);
  600. fclose($source);
  601. fclose($target);
  602. }
  603. }
  604. <?php
  605. namespace Composer\Autoload;
  606. use Symfony\Component\Finder\Finder;
  607. use Composer\IO\IOInterface;
  608. class ClassMapGenerator
  609. {
  610. public static function dump($dirs, $file)
  611. {
  612. $maps = array();
  613. foreach ($dirs as $dir) {
  614. $maps = array_merge($maps, static::createMap($dir));
  615. }
  616. file_put_contents($file, sprintf('<?php return %s;', var_export($maps, true)));
  617. }
  618. public static function createMap($path, $whitelist = null, IOInterface $io = null, $namespace = null)
  619. {
  620. if (is_string($path)) {
  621. if (is_file($path)) {
  622. $path = array(new \SplFileInfo($path));
  623. } elseif (is_dir($path)) {
  624. $path = Finder::create()->files()->followLinks()->name('/\.(php|inc|hh)$/')->in($path);
  625. } else {
  626. throw new \RuntimeException(
  627. 'Could not scan for classes inside "'.$path.
  628. '" which does not appear to be a file nor a folder'
  629. );
  630. }
  631. }
  632. $map = array();
  633. foreach ($path as $file) {
  634. $filePath = $file->getRealPath();
  635. if (!in_array(pathinfo($filePath, PATHINFO_EXTENSION), array('php', 'inc', 'hh'))) {
  636. continue;
  637. }
  638. if ($whitelist && !preg_match($whitelist, strtr($filePath, '\\', '/'))) {
  639. continue;
  640. }
  641. $classes = self::findClasses($filePath);
  642. foreach ($classes as $class) {
  643. if (null !== $namespace && 0 !== strpos($class, $namespace)) {
  644. continue;
  645. }
  646. if (!isset($map[$class])) {
  647. $map[$class] = $filePath;
  648. } elseif ($io && $map[$class] !== $filePath && !preg_match('{/(test|fixture|example|stub)s?/}i', strtr($map[$class].' '.$filePath, '\\', '/'))) {
  649. $io->writeError(
  650. '<warning>Warning: Ambiguous class resolution, "'.$class.'"'.
  651. ' was found in both "'.$map[$class].'" and "'.$filePath.'", the first will be used.</warning>'
  652. );
  653. }
  654. }
  655. }
  656. return $map;
  657. }
  658. private static function findClasses($path)
  659. {
  660. $extraTypes = PHP_VERSION_ID < 50400 ? '' : '|trait';
  661. if (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.3', '>=')) {
  662. $extraTypes .= '|enum';
  663. }
  664. try {
  665. $contents = @php_strip_whitespace($path);
  666. if (!$contents) {
  667. if (!file_exists($path)) {
  668. throw new \Exception('File does not exist');
  669. }
  670. if (!is_readable($path)) {
  671. throw new \Exception('File is not readable');
  672. }
  673. }
  674. } catch (\Exception $e) {
  675. throw new \RuntimeException('Could not scan for classes inside '.$path.": \n".$e->getMessage(), 0, $e);
  676. }
  677. if (!preg_match('{\b(?:class|interface'.$extraTypes.')\s}i', $contents)) {
  678. return array();
  679. }
  680. $contents = preg_replace('{<<<\s*(\'?)(\w+)\\1(?:\r\n|\n|\r)(?:.*?)(?:\r\n|\n|\r)\\2(?=\r\n|\n|\r|;)}s', 'null', $contents);
  681. $contents = preg_replace('{"[^"\\\\]*+(\\\\.[^"\\\\]*+)*+"|\'[^\'\\\\]*+(\\\\.[^\'\\\\]*+)*+\'}s', 'null', $contents);
  682. if (substr($contents, 0, 2) !== '<?') {
  683. $contents = preg_replace('{^.+?<\?}s', '<?', $contents, 1, $replacements);
  684. if ($replacements === 0) {
  685. return array();
  686. }
  687. }
  688. $contents = preg_replace('{\?>.+<\?}s', '?><?', $contents);
  689. $pos = strrpos($contents, '?>');
  690. if (false !== $pos && false === strpos(substr($contents, $pos), '<?')) {
  691. $contents = substr($contents, 0, $pos);
  692. }
  693. preg_match_all('{
  694. (?:
  695. \b(?<![\$:>])(?P<type>class|interface'.$extraTypes.') \s++ (?P<name>[a-zA-Z_\x7f-\xff:][a-zA-Z0-9_\x7f-\xff:\-]*+)
  696. | \b(?<![\$:>])(?P<ns>namespace) (?P<nsname>\s++[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\s*+\\\\\s*+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+)? \s*+ [\{;]
  697. )
  698. }ix', $contents, $matches);
  699. $classes = array();
  700. $namespace = '';
  701. for ($i = 0, $len = count($matches['type']); $i < $len; $i++) {
  702. if (!empty($matches['ns'][$i])) {
  703. $namespace = str_replace(array(' ', "\t", "\r", "\n"), '', $matches['nsname'][$i]) . '\\';
  704. } else {
  705. $name = $matches['name'][$i];
  706. if ($name[0] === ':') {
  707. $name = 'xhp'.substr(str_replace(array('-', ':'), array('_', '__'), $name), 1);
  708. } elseif ($matches['type'][$i] === 'enum') {
  709. $name = rtrim($name, ':');
  710. }
  711. $classes[] = ltrim($namespace . $name, '\\');
  712. }
  713. }
  714. return $classes;
  715. }
  716. }
  717. <?php
  718. namespace Composer;
  719. use Composer\IO\IOInterface;
  720. use Composer\Util\Filesystem;
  721. use Symfony\Component\Finder\Finder;
  722. class Cache
  723. {
  724. private static $cacheCollected = false;
  725. private $io;
  726. private $root;
  727. private $enabled = true;
  728. private $whitelist;
  729. private $filesystem;
  730. public function __construct(IOInterface $io, $cacheDir, $whitelist = 'a-z0-9.', Filesystem $filesystem = null)
  731. {
  732. $this->io = $io;
  733. $this->root = rtrim($cacheDir, '/\\') . '/';
  734. $this->whitelist = $whitelist;
  735. $this->filesystem = $filesystem ?: new Filesystem();
  736. if (
  737. (!is_dir($this->root) && !@mkdir($this->root, 0777, true))
  738. || !is_writable($this->root)
  739. ) {
  740. $this->io->writeError('<warning>Cannot create cache directory ' . $this->root . ', or directory is not writable. Proceeding without cache</warning>');
  741. $this->enabled = false;
  742. }
  743. }
  744. public function isEnabled()
  745. {
  746. return $this->enabled;
  747. }
  748. public function getRoot()
  749. {
  750. return $this->root;
  751. }
  752. public function read($file)
  753. {
  754. $file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file);
  755. if ($this->enabled && file_exists($this->root . $file)) {
  756. if ($this->io->isDebug()) {
  757. $this->io->writeError('Reading '.$this->root . $file.' from cache');
  758. }
  759. return file_get_contents($this->root . $file);
  760. }
  761. return false;
  762. }
  763. public function write($file, $contents)
  764. {
  765. if ($this->enabled) {
  766. $file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file);
  767. if ($this->io->isDebug()) {
  768. $this->io->writeError('Writing '.$this->root . $file.' into cache');
  769. }
  770. try {
  771. return file_put_contents($this->root . $file, $contents);
  772. } catch (\ErrorException $e) {
  773. if ($this->io->isDebug()) {
  774. $this->io->writeError('<warning>Failed to write into cache: '.$e->getMessage().'</warning>');
  775. }
  776. if (preg_match('{^file_put_contents\(\): Only ([0-9]+) of ([0-9]+) bytes written}', $e->getMessage(), $m)) {
  777. unlink($this->root . $file);
  778. $message = sprintf(
  779. '<warning>Writing %1$s into cache failed after %2$u of %3$u bytes written, only %4$u bytes of free space available</warning>',
  780. $this->root . $file,
  781. $m[1],
  782. $m[2],
  783. @disk_free_space($this->root . dirname($file))
  784. );
  785. $this->io->writeError($message);
  786. return false;
  787. }
  788. throw $e;
  789. }
  790. }
  791. return false;
  792. }
  793. public function copyFrom($file, $source)
  794. {
  795. if ($this->enabled) {
  796. $file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file);
  797. $this->filesystem->ensureDirectoryExists(dirname($this->root . $file));
  798. if ($this->io->isDebug()) {
  799. $this->io->writeError('Writing '.$this->root . $file.' into cache');
  800. }
  801. return copy($source, $this->root . $file);
  802. }
  803. return false;
  804. }
  805. public function copyTo($file, $target)
  806. {
  807. $file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file);
  808. if ($this->enabled && file_exists($this->root . $file)) {
  809. try {
  810. touch($this->root . $file, filemtime($this->root . $file), time());
  811. } catch (\ErrorException $e) {
  812. touch($this->root . $file);
  813. }
  814. if ($this->io->isDebug()) {
  815. $this->io->writeError('Reading '.$this->root . $file.' from cache');
  816. }
  817. return copy($this->root . $file, $target);
  818. }
  819. return false;
  820. }
  821. public function gcIsNecessary()
  822. {
  823. return (!self::$cacheCollected && !mt_rand(0, 50));
  824. }
  825. public function remove($file)
  826. {
  827. $file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file);
  828. if ($this->enabled && file_exists($this->root . $file)) {
  829. return $this->filesystem->unlink($this->root . $file);
  830. }
  831. return false;
  832. }
  833. public function gc($ttl, $maxSize)
  834. {
  835. if ($this->enabled) {
  836. $expire = new \DateTime();
  837. $expire->modify('-'.$ttl.' seconds');
  838. $finder = $this->getFinder()->date('until '.$expire->format('Y-m-d H:i:s'));
  839. foreach ($finder as $file) {
  840. $this->filesystem->unlink($file->getPathname());
  841. }
  842. $totalSize = $this->filesystem->size($this->root);
  843. if ($totalSize > $maxSize) {
  844. $iterator = $this->getFinder()->sortByAccessedTime()->getIterator();
  845. while ($totalSize > $maxSize && $iterator->valid()) {
  846. $filepath = $iterator->current()->getPathname();
  847. $totalSize -= $this->filesystem->size($filepath);
  848. $this->filesystem->unlink($filepath);
  849. $iterator->next();
  850. }
  851. }
  852. self::$cacheCollected = true;
  853. return true;
  854. }
  855. return false;
  856. }
  857. public function sha1($file)
  858. {
  859. $file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file);
  860. if ($this->enabled && file_exists($this->root . $file)) {
  861. return sha1_file($this->root . $file);
  862. }
  863. return false;
  864. }
  865. public function sha256($file)
  866. {
  867. $file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file);
  868. if ($this->enabled && file_exists($this->root . $file)) {
  869. return hash_file('sha256', $this->root . $file);
  870. }
  871. return false;
  872. }
  873. protected function getFinder()
  874. {
  875. return Finder::create()->in($this->root)->files();
  876. }
  877. }
  878. <?php
  879. namespace Composer\Command;
  880. use Symfony\Component\Console\Input\InputInterface;
  881. use Symfony\Component\Console\Output\OutputInterface;
  882. class AboutCommand extends Command
  883. {
  884. protected function configure()
  885. {
  886. $this
  887. ->setName('about')
  888. ->setDescription('Short information about Composer')
  889. ->setHelp(<<<EOT
  890. <info>php composer.phar about</info>
  891. EOT
  892. )
  893. ;
  894. }
  895. protected function execute(InputInterface $input, OutputInterface $output)
  896. {
  897. $this->getIO()->write(<<<EOT
  898. <info>Composer - Package Management for PHP</info>
  899. <comment>Composer is a dependency manager tracking local dependencies of your projects and libraries.
  900. See https://getcomposer.org/ for more information.</comment>
  901. EOT
  902. );
  903. }
  904. }
  905. <?php
  906. namespace Composer\Command;
  907. use Composer\Factory;
  908. use Composer\IO\IOInterface;
  909. use Composer\Config;
  910. use Composer\Repository\CompositeRepository;
  911. use Composer\Script\ScriptEvents;
  912. use Composer\Plugin\CommandEvent;
  913. use Composer\Plugin\PluginEvents;
  914. use Composer\Util\Filesystem;
  915. use Symfony\Component\Console\Input\InputArgument;
  916. use Symfony\Component\Console\Input\InputInterface;
  917. use Symfony\Component\Console\Input\InputOption;
  918. use Symfony\Component\Console\Output\OutputInterface;
  919. class ArchiveCommand extends Command
  920. {
  921. protected function configure()
  922. {
  923. $this
  924. ->setName('archive')
  925. ->setDescription('Create an archive of this composer package')
  926. ->setDefinition(array(
  927. new InputArgument('package', InputArgument::OPTIONAL, 'The package to archive instead of the current project'),
  928. new InputArgument('version', InputArgument::OPTIONAL, 'A version constraint to find the package to archive'),
  929. new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the resulting archive: tar or zip'),
  930. new InputOption('dir', false, InputOption::VALUE_REQUIRED, 'Write the archive to this directory'),
  931. new InputOption('file', false, InputOption::VALUE_REQUIRED, 'Write the archive with the given file name.'
  932. .' Note that the format will be appended.'),
  933. ))
  934. ->setHelp(<<<EOT
  935. The <info>archive</info> command creates an archive of the specified format
  936. containing the files and directories of the Composer project or the specified
  937. package in the specified version and writes it to the specified directory.
  938. <info>php composer.phar archive [--format=zip] [--dir=/foo] [package [version]]</info>
  939. EOT
  940. )
  941. ;
  942. }
  943. protected function execute(InputInterface $input, OutputInterface $output)
  944. {
  945. $config = Factory::createConfig();
  946. $composer = $this->getComposer(false);
  947. if ($composer) {
  948. $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'archive', $input, $output);
  949. $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
  950. $composer->getEventDispatcher()->dispatchScript(ScriptEvents::PRE_ARCHIVE_CMD);
  951. }
  952. if (null === $input->getOption('format')) {
  953. $input->setOption('format', $config->get('archive-format'));
  954. }
  955. if (null === $input->getOption('dir')) {
  956. $input->setOption('dir', $config->get('archive-dir'));
  957. }
  958. $returnCode = $this->archive(
  959. $this->getIO(),
  960. $config,
  961. $input->getArgument('package'),
  962. $input->getArgument('version'),
  963. $input->getOption('format'),
  964. $input->getOption('dir'),
  965. $input->getOption('file')
  966. );
  967. if (0 === $returnCode && $composer) {
  968. $composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_ARCHIVE_CMD);
  969. }
  970. return $returnCode;
  971. }
  972. protected function archive(IOInterface $io, Config $config, $packageName = null, $version = null, $format = 'tar', $dest = '.', $fileName = null)
  973. {
  974. $factory = new Factory;
  975. $downloadManager = $factory->createDownloadManager($io, $config);
  976. $archiveManager = $factory->createArchiveManager($config, $downloadManager);
  977. if ($packageName) {
  978. $package = $this->selectPackage($io, $packageName, $version);
  979. if (!$package) {
  980. return 1;
  981. }
  982. } else {
  983. $package = $this->getComposer()->getPackage();
  984. }
  985. $io->writeError('<info>Creating the archive into "'.$dest.'".</info>');
  986. $packagePath = $archiveManager->archive($package, $format, $dest, $fileName);
  987. $fs = new Filesystem;
  988. $shortPath = $fs->findShortestPath(getcwd(), $packagePath, true);
  989. $io->writeError('Created: ', false);
  990. $io->write(strlen($shortPath) < strlen($packagePath) ? $shortPath : $packagePath);
  991. return 0;
  992. }
  993. protected function selectPackage(IOInterface $io, $packageName, $version = null)
  994. {
  995. $io->writeError('<info>Searching for the specified package.</info>');
  996. if ($composer = $this->getComposer(false)) {
  997. $localRepo = $composer->getRepositoryManager()->getLocalRepository();
  998. $repo = new CompositeRepository(array_merge(array($localRepo), $composer->getRepositoryManager()->getRepositories()));
  999. } else {
  1000. $defaultRepos = Factory::createDefaultRepositories($this->getIO());
  1001. $io->writeError('No composer.json found in the current directory, searching packages from ' . implode(', ', array_keys($defaultRepos)));
  1002. $repo = new CompositeRepository($defaultRepos);
  1003. }
  1004. $packages = $repo->findPackages($packageName, $version);
  1005. if (count($packages) > 1) {
  1006. $package = reset($packages);
  1007. $io->writeError('<info>Found multiple matches, selected '.$package->getPrettyString().'.</info>');
  1008. $io->writeError('Alternatives were '.implode(', ', array_map(function ($p) { return $p->getPrettyString(); }, $packages)).'.');
  1009. $io->writeError('<comment>Please use a more specific constraint to pick a different package.</comment>');
  1010. } elseif ($packages) {
  1011. $package = reset($packages);
  1012. $io->writeError('<info>Found an exact match '.$package->getPrettyString().'.</info>');
  1013. } else {
  1014. $io->writeError('<error>Could not find a package matching '.$packageName.'.</error>');
  1015. return false;
  1016. }
  1017. return $package;
  1018. }
  1019. }
  1020. <?php
  1021. namespace Composer\Command;
  1022. use Composer\Cache;
  1023. use Composer\Factory;
  1024. use Symfony\Component\Console\Input\InputInterface;
  1025. use Symfony\Component\Console\Output\OutputInterface;
  1026. class ClearCacheCommand extends Command
  1027. {
  1028. protected function configure()
  1029. {
  1030. $this
  1031. ->setName('clear-cache')
  1032. ->setAliases(array('clearcache'))
  1033. ->setDescription('Clears composer\'s internal package cache.')
  1034. ->setHelp(<<<EOT
  1035. The <info>clear-cache</info> deletes all cached packages from composer's
  1036. cache directory.
  1037. EOT
  1038. )
  1039. ;
  1040. }
  1041. protected function execute(InputInterface $input, OutputInterface $output)
  1042. {
  1043. $config = Factory::createConfig();
  1044. $io = $this->getIO();
  1045. $cachePaths = array(
  1046. 'cache-dir' => $config->get('cache-dir'),
  1047. 'cache-files-dir' => $config->get('cache-files-dir'),
  1048. 'cache-repo-dir' => $config->get('cache-repo-dir'),
  1049. 'cache-vcs-dir' => $config->get('cache-vcs-dir'),
  1050. );
  1051. foreach ($cachePaths as $key => $cachePath) {
  1052. $cachePath = realpath($cachePath);
  1053. if (!$cachePath) {
  1054. $io->writeError("<info>Cache directory does not exist ($key): $cachePath</info>");
  1055. continue;
  1056. }
  1057. $cache = new Cache($io, $cachePath);
  1058. if (!$cache->isEnabled()) {
  1059. $io->writeError("<info>Cache is not enabled ($key): $cachePath</info>");
  1060. continue;
  1061. }
  1062. $io->writeError("<info>Clearing cache ($key): $cachePath</info>");
  1063. $cache->gc(0, 0);
  1064. }
  1065. $io->writeError('<info>All caches cleared.</info>');
  1066. }
  1067. }
  1068. <?php
  1069. namespace Composer\Command;
  1070. use Composer\Composer;
  1071. use Composer\Console\Application;
  1072. use Composer\IO\IOInterface;
  1073. use Composer\IO\NullIO;
  1074. use Symfony\Component\Console\Input\InputInterface;
  1075. use Symfony\Component\Console\Output\OutputInterface;
  1076. use Symfony\Component\Console\Command\Command as BaseCommand;
  1077. abstract class Command extends BaseCommand
  1078. {
  1079. private $composer;
  1080. private $io;
  1081. public function getComposer($required = true, $disablePlugins = false)
  1082. {
  1083. if (null === $this->composer) {
  1084. $application = $this->getApplication();
  1085. if ($application instanceof Application) {
  1086. $this->composer = $application->getComposer($required, $disablePlugins);
  1087. } elseif ($required) {
  1088. throw new \RuntimeException(
  1089. 'Could not create a Composer\Composer instance, you must inject '.
  1090. 'one if this command is not used with a Composer\Console\Application instance'
  1091. );
  1092. }
  1093. }
  1094. return $this->composer;
  1095. }
  1096. public function setComposer(Composer $composer)
  1097. {
  1098. $this->composer = $composer;
  1099. }
  1100. public function resetComposer()
  1101. {
  1102. $this->composer = null;
  1103. $this->getApplication()->resetComposer();
  1104. }
  1105. public function getIO()
  1106. {
  1107. if (null === $this->io) {
  1108. $application = $this->getApplication();
  1109. if ($application instanceof Application) {
  1110. $this->io = $application->getIO();
  1111. } else {
  1112. $this->io = new NullIO();
  1113. }
  1114. }
  1115. return $this->io;
  1116. }
  1117. public function setIO(IOInterface $io)
  1118. {
  1119. $this->io = $io;
  1120. }
  1121. protected function initialize(InputInterface $input, OutputInterface $output)
  1122. {
  1123. if (true === $input->hasParameterOption(array('--no-ansi')) && $input->hasOption('no-progress')) {
  1124. $input->setOption('no-progress', true);
  1125. }
  1126. parent::initialize($input, $output);
  1127. }
  1128. }
  1129. <?php
  1130. namespace Composer\Command;
  1131. use Symfony\Component\Console\Input\InputInterface;
  1132. use Symfony\Component\Console\Input\InputArgument;
  1133. use Symfony\Component\Console\Input\InputOption;
  1134. use Symfony\Component\Console\Output\OutputInterface;
  1135. use Composer\Config;
  1136. use Composer\Config\JsonConfigSource;
  1137. use Composer\Factory;
  1138. use Composer\Json\JsonFile;
  1139. class ConfigCommand extends Command
  1140. {
  1141. protected $config;
  1142. protected $configFile;
  1143. protected $configSource;
  1144. protected $authConfigFile;
  1145. protected $authConfigSource;
  1146. protected function configure()
  1147. {
  1148. $this
  1149. ->setName('config')
  1150. ->setDescription('Set config options')
  1151. ->setDefinition(array(
  1152. new InputOption('global', 'g', InputOption::VALUE_NONE, 'Apply command to the global config file'),
  1153. new InputOption('editor', 'e', InputOption::VALUE_NONE, 'Open editor'),
  1154. new InputOption('auth', 'a', InputOption::VALUE_NONE, 'Affect auth config file (only used for --editor)'),
  1155. new InputOption('unset', null, InputOption::VALUE_NONE, 'Unset the given setting-key'),
  1156. new InputOption('list', 'l', InputOption::VALUE_NONE, 'List configuration settings'),
  1157. new InputOption('file', 'f', InputOption::VALUE_REQUIRED, 'If you want to choose a different composer.json or config.json'),
  1158. new InputOption('absolute', null, InputOption::VALUE_NONE, 'Returns absolute paths when fetching *-dir config values instead of relative'),
  1159. new InputArgument('setting-key', null, 'Setting key'),
  1160. new InputArgument('setting-value', InputArgument::IS_ARRAY, 'Setting value'),
  1161. ))
  1162. ->setHelp(<<<EOT
  1163. This command allows you to edit some basic composer settings in either the
  1164. local composer.json file or the global config.json file.
  1165. To set a config setting:
  1166. <comment>%command.full_name% bin-dir bin/</comment>
  1167. To read a config setting:
  1168. <comment>%command.full_name% bin-dir</comment>
  1169. Outputs: <info>bin</info>
  1170. To edit the global config.json file:
  1171. <comment>%command.full_name% --global</comment>
  1172. To add a repository:
  1173. <comment>%command.full_name% repositories.foo vcs http://bar.com</comment>
  1174. To remove a repository (repo is a short alias for repositories):
  1175. <comment>%command.full_name% --unset repo.foo</comment>
  1176. To disable packagist:
  1177. <comment>%command.full_name% repo.packagist false</comment>
  1178. You can alter repositories in the global config.json file by passing in the
  1179. <info>--global</info> option.
  1180. To edit the file in an external editor:
  1181. <comment>%command.full_name% --editor</comment>
  1182. To choose your editor you can set the "EDITOR" env variable.
  1183. To get a list of configuration values in the file:
  1184. <comment>%command.full_name% --list</comment>
  1185. You can always pass more than one option. As an example, if you want to edit the
  1186. global config.json file.
  1187. <comment>%command.full_name% --editor --global</comment>
  1188. EOT
  1189. )
  1190. ;
  1191. }
  1192. protected function initialize(InputInterface $input, OutputInterface $output)
  1193. {
  1194. parent::initialize($input, $output);
  1195. if ($input->getOption('global') && null !== $input->getOption('file')) {
  1196. throw new \RuntimeException('--file and --global can not be combined');
  1197. }
  1198. $this->config = Factory::createConfig($this->getIO());
  1199. $configFile = $input->getOption('global')
  1200. ? ($this->config->get('home') . '/config.json')
  1201. : ($input->getOption('file') ?: trim(getenv('COMPOSER')) ?: 'composer.json');
  1202. if ($configFile === 'composer.json' && !file_exists($configFile) && realpath(getcwd()) === realpath($this->config->get('home'))) {
  1203. file_put_contents($configFile, "{\n}\n");
  1204. }
  1205. $this->configFile = new JsonFile($configFile);
  1206. $this->configSource = new JsonConfigSource($this->configFile);
  1207. $authConfigFile = $input->getOption('global')
  1208. ? ($this->config->get('home') . '/auth.json')
  1209. : dirname(realpath($configFile)) . '/auth.json';
  1210. $this->authConfigFile = new JsonFile($authConfigFile);
  1211. $this->authConfigSource = new JsonConfigSource($this->authConfigFile, true);
  1212. if ($input->getOption('global') && !$this->configFile->exists()) {
  1213. touch($this->configFile->getPath());
  1214. $this->configFile->write(array('config' => new \ArrayObject));
  1215. @chmod($this->configFile->getPath(), 0600);
  1216. }
  1217. if ($input->getOption('global') && !$this->authConfigFile->exists()) {
  1218. touch($this->authConfigFile->getPath());
  1219. $this->authConfigFile->write(array('http-basic' => new \ArrayObject, 'github-oauth' => new \ArrayObject));
  1220. @chmod($this->authConfigFile->getPath(), 0600);
  1221. }
  1222. if (!$this->configFile->exists()) {
  1223. throw new \RuntimeException(sprintf('File "%s" cannot be found in the current directory', $configFile));
  1224. }
  1225. }
  1226. protected function execute(InputInterface $input, OutputInterface $output)
  1227. {
  1228. if ($input->getOption('editor')) {
  1229. $editor = escapeshellcmd(getenv('EDITOR'));
  1230. if (!$editor) {
  1231. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  1232. $editor = 'notepad';
  1233. } else {
  1234. foreach (array('vim', 'vi', 'nano', 'pico', 'ed') as $candidate) {
  1235. if (exec('which '.$candidate)) {
  1236. $editor = $candidate;
  1237. break;
  1238. }
  1239. }
  1240. }
  1241. }
  1242. $file = $input->getOption('auth') ? $this->authConfigFile->getPath() : $this->configFile->getPath();
  1243. system($editor . ' ' . $file . (defined('PHP_WINDOWS_VERSION_BUILD') ? '' : ' > `tty`'));
  1244. return 0;
  1245. }
  1246. if (!$input->getOption('global')) {
  1247. $this->config->merge($this->configFile->read());
  1248. $this->config->merge(array('config' => $this->authConfigFile->exists() ? $this->authConfigFile->read() : array()));
  1249. }
  1250. if ($input->getOption('list')) {
  1251. $this->listConfiguration($this->config->all(), $this->config->raw(), $output);
  1252. return 0;
  1253. }
  1254. $settingKey = $input->getArgument('setting-key');
  1255. if (!$settingKey) {
  1256. return 0;
  1257. }
  1258. if (array() !== $input->getArgument('setting-value') && $input->getOption('unset')) {
  1259. throw new \RuntimeException('You can not combine a setting value with --unset');
  1260. }
  1261. if (array() === $input->getArgument('setting-value') && !$input->getOption('unset')) {
  1262. $data = $this->config->all();
  1263. if (preg_match('/^repos?(?:itories)?(?:\.(.+))?/', $settingKey, $matches)) {
  1264. if (empty($matches[1])) {
  1265. $value = isset($data['repositories']) ? $data['repositories'] : array();
  1266. } else {
  1267. if (!isset($data['repositories'][$matches[1]])) {
  1268. throw new \InvalidArgumentException('There is no '.$matches[1].' repository defined');
  1269. }
  1270. $value = $data['repositories'][$matches[1]];
  1271. }
  1272. } elseif (strpos($settingKey, '.')) {
  1273. $bits = explode('.', $settingKey);
  1274. $data = $data['config'];
  1275. $match = false;
  1276. foreach ($bits as $bit) {
  1277. $key = isset($key) ? $key.'.'.$bit : $bit;
  1278. $match = false;
  1279. if (isset($data[$key])) {
  1280. $match = true;
  1281. $data = $data[$key];
  1282. unset($key);
  1283. }
  1284. }
  1285. if (!$match) {
  1286. throw new \RuntimeException($settingKey.' is not defined.');
  1287. }
  1288. $value = $data;
  1289. } elseif (isset($data['config'][$settingKey])) {
  1290. $value = $this->config->get($settingKey, $input->getOption('absolute') ? 0 : Config::RELATIVE_PATHS);
  1291. } else {
  1292. throw new \RuntimeException($settingKey.' is not defined');
  1293. }
  1294. if (is_array($value)) {
  1295. $value = json_encode($value);
  1296. }
  1297. $this->getIO()->write($value);
  1298. return 0;
  1299. }
  1300. $values = $input->getArgument('setting-value');
  1301. $booleanValidator = function ($val) { return in_array($val, array('true', 'false', '1', '0'), true); };
  1302. $booleanNormalizer = function ($val) { return $val !== 'false' && (bool) $val; };
  1303. $uniqueConfigValues = array(
  1304. 'process-timeout' => array('is_numeric', 'intval'),
  1305. 'use-include-path' => array($booleanValidator, $booleanNormalizer),
  1306. 'preferred-install' => array(
  1307. function ($val) { return in_array($val, array('auto', 'source', 'dist'), true); },
  1308. function ($val) { return $val; },
  1309. ),
  1310. 'store-auths' => array(
  1311. function ($val) { return in_array($val, array('true', 'false', 'prompt'), true); },
  1312. function ($val) {
  1313. if ('prompt' === $val) {
  1314. return 'prompt';
  1315. }
  1316. return $val !== 'false' && (bool) $val;
  1317. },
  1318. ),
  1319. 'notify-on-install' => array($booleanValidator, $booleanNormalizer),
  1320. 'vendor-dir' => array('is_string', function ($val) { return $val; }),
  1321. 'bin-dir' => array('is_string', function ($val) { return $val; }),
  1322. 'archive-dir' => array('is_string', function ($val) { return $val; }),
  1323. 'archive-format' => array('is_string', function ($val) { return $val; }),
  1324. 'cache-dir' => array('is_string', function ($val) { return $val; }),
  1325. 'cache-files-dir' => array('is_string', function ($val) { return $val; }),
  1326. 'cache-repo-dir' => array('is_string', function ($val) { return $val; }),
  1327. 'cache-vcs-dir' => array('is_string', function ($val) { return $val; }),
  1328. 'cache-ttl' => array('is_numeric', 'intval'),
  1329. 'cache-files-ttl' => array('is_numeric', 'intval'),
  1330. 'cache-files-maxsize' => array(
  1331. function ($val) { return preg_match('/^\s*([0-9.]+)\s*(?:([kmg])(?:i?b)?)?\s*$/i', $val) > 0; },
  1332. function ($val) { return $val; },
  1333. ),
  1334. 'discard-changes' => array(
  1335. function ($val) { return in_array($val, array('stash', 'true', 'false', '1', '0'), true); },
  1336. function ($val) {
  1337. if ('stash' === $val) {
  1338. return 'stash';
  1339. }
  1340. return $val !== 'false' && (bool) $val;
  1341. },
  1342. ),
  1343. 'autoloader-suffix' => array('is_string', function ($val) { return $val === 'null' ? null : $val; }),
  1344. 'optimize-autoloader' => array($booleanValidator, $booleanNormalizer),
  1345. 'classmap-authoritative' => array($booleanValidator, $booleanNormalizer),
  1346. 'prepend-autoloader' => array($booleanValidator, $booleanNormalizer),
  1347. 'github-expose-hostname' => array($booleanValidator, $booleanNormalizer),
  1348. 'prefer-stable' => array($booleanValidator, $booleanNormalizer),
  1349. 'minimum-stability' => array(
  1350. function ($val) { return in_array($val, array('dev', 'alpha', 'beta', 'RC', 'stable'), true); },
  1351. function ($val) { return $val; },
  1352. ),
  1353. );
  1354. $multiConfigValues = array(
  1355. 'github-protocols' => array(
  1356. function ($vals) {
  1357. if (!is_array($vals)) {
  1358. return 'array expected';
  1359. }
  1360. foreach ($vals as $val) {
  1361. if (!in_array($val, array('git', 'https', 'ssh'))) {
  1362. return 'valid protocols include: git, https, ssh';
  1363. }
  1364. }
  1365. return true;
  1366. },
  1367. function ($vals) {
  1368. return $vals;
  1369. },
  1370. ),
  1371. 'github-domains' => array(
  1372. function ($vals) {
  1373. if (!is_array($vals)) {
  1374. return 'array expected';
  1375. }
  1376. return true;
  1377. },
  1378. function ($vals) {
  1379. return $vals;
  1380. },
  1381. ),
  1382. );
  1383. foreach ($uniqueConfigValues as $name => $callbacks) {
  1384. if ($settingKey === $name) {
  1385. if ($input->getOption('unset')) {
  1386. return $this->configSource->removeConfigSetting($settingKey);
  1387. }
  1388. list($validator, $normalizer) = $callbacks;
  1389. if (1 !== count($values)) {
  1390. throw new \RuntimeException('You can only pass one value. Example: php composer.phar config process-timeout 300');
  1391. }
  1392. if (true !== $validation = $validator($values[0])) {
  1393. throw new \RuntimeException(sprintf(
  1394. '"%s" is an invalid value'.($validation ? ' ('.$validation.')' : ''),
  1395. $values[0]
  1396. ));
  1397. }
  1398. return $this->configSource->addConfigSetting($settingKey, $normalizer($values[0]));
  1399. }
  1400. }
  1401. foreach ($multiConfigValues as $name => $callbacks) {
  1402. if ($settingKey === $name) {
  1403. if ($input->getOption('unset')) {
  1404. return $this->configSource->removeConfigSetting($settingKey);
  1405. }
  1406. list($validator, $normalizer) = $callbacks;
  1407. if (true !== $validation = $validator($values)) {
  1408. throw new \RuntimeException(sprintf(
  1409. '%s is an invalid value'.($validation ? ' ('.$validation.')' : ''),
  1410. json_encode($values)
  1411. ));
  1412. }
  1413. return $this->configSource->addConfigSetting($settingKey, $normalizer($values));
  1414. }
  1415. }
  1416. if (preg_match('/^repos?(?:itories)?\.(.+)/', $settingKey, $matches)) {
  1417. if ($input->getOption('unset')) {
  1418. return $this->configSource->removeRepository($matches[1]);
  1419. }
  1420. if (2 === count($values)) {
  1421. return $this->configSource->addRepository($matches[1], array(
  1422. 'type' => $values[0],
  1423. 'url' => $values[1],
  1424. ));
  1425. }
  1426. if (1 === count($values)) {
  1427. $bool = strtolower($values[0]);
  1428. if (true === $booleanValidator($bool) && false === $booleanNormalizer($bool)) {
  1429. return $this->configSource->addRepository($matches[1], false);
  1430. }
  1431. }
  1432. throw new \RuntimeException('You must pass the type and a url. Example: php composer.phar config repositories.foo vcs http://bar.com');
  1433. }
  1434. if (preg_match('/^platform\.(.+)/', $settingKey, $matches)) {
  1435. if ($input->getOption('unset')) {
  1436. return $this->configSource->removeConfigSetting($settingKey);
  1437. }
  1438. return $this->configSource->addConfigSetting($settingKey, $values[0]);
  1439. }
  1440. if (preg_match('/^(github-oauth|http-basic)\.(.+)/', $settingKey, $matches)) {
  1441. if ($input->getOption('unset')) {
  1442. $this->authConfigSource->removeConfigSetting($matches[1].'.'.$matches[2]);
  1443. $this->configSource->removeConfigSetting($matches[1].'.'.$matches[2]);
  1444. return;
  1445. }
  1446. if ($matches[1] === 'github-oauth') {
  1447. if (1 !== count($values)) {
  1448. throw new \RuntimeException('Too many arguments, expected only one token');
  1449. }
  1450. $this->configSource->removeConfigSetting($matches[1].'.'.$matches[2]);
  1451. $this->authConfigSource->addConfigSetting($matches[1].'.'.$matches[2], $values[0]);
  1452. } elseif ($matches[1] === 'http-basic') {
  1453. if (2 !== count($values)) {
  1454. throw new \RuntimeException('Expected two arguments (username, password), got '.count($values));
  1455. }
  1456. $this->configSource->removeConfigSetting($matches[1].'.'.$matches[2]);
  1457. $this->authConfigSource->addConfigSetting($matches[1].'.'.$matches[2], array('username' => $values[0], 'password' => $values[1]));
  1458. }
  1459. return;
  1460. }
  1461. throw new \InvalidArgumentException('Setting '.$settingKey.' does not exist or is not supported by this command');
  1462. }
  1463. protected function listConfiguration(array $contents, array $rawContents, OutputInterface $output, $k = null)
  1464. {
  1465. $origK = $k;
  1466. $io = $this->getIO();
  1467. foreach ($contents as $key => $value) {
  1468. if ($k === null && !in_array($key, array('config', 'repositories'))) {
  1469. continue;
  1470. }
  1471. $rawVal = isset($rawContents[$key]) ? $rawContents[$key] : null;
  1472. if (is_array($value) && (!is_numeric(key($value)) || ($key === 'repositories' && null === $k))) {
  1473. $k .= preg_replace('{^config\.}', '', $key . '.');
  1474. $this->listConfiguration($value, $rawVal, $output, $k);
  1475. $k = $origK;
  1476. continue;
  1477. }
  1478. if (is_array($value)) {
  1479. $value = array_map(function ($val) {
  1480. return is_array($val) ? json_encode($val) : $val;
  1481. }, $value);
  1482. $value = '['.implode(', ', $value).']';
  1483. }
  1484. if (is_bool($value)) {
  1485. $value = var_export($value, true);
  1486. }
  1487. if (is_string($rawVal) && $rawVal != $value) {
  1488. $io->write('[<comment>' . $k . $key . '</comment>] <info>' . $rawVal . ' (' . $value . ')</info>');
  1489. } else {
  1490. $io->write('[<comment>' . $k . $key . '</comment>] <info>' . $value . '</info>');
  1491. }
  1492. }
  1493. }
  1494. }
  1495. <?php
  1496. namespace Composer\Command;
  1497. use Composer\Config;
  1498. use Composer\Factory;
  1499. use Composer\Installer;
  1500. use Composer\Installer\ProjectInstaller;
  1501. use Composer\Installer\InstallationManager;
  1502. use Composer\IO\IOInterface;
  1503. use Composer\Package\BasePackage;
  1504. use Composer\DependencyResolver\Pool;
  1505. use Composer\DependencyResolver\Operation\InstallOperation;
  1506. use Composer\Package\Version\VersionSelector;
  1507. use Composer\Repository\ComposerRepository;
  1508. use Composer\Repository\CompositeRepository;
  1509. use Composer\Repository\FilesystemRepository;
  1510. use Composer\Repository\InstalledFilesystemRepository;
  1511. use Composer\Script\ScriptEvents;
  1512. use Symfony\Component\Console\Input\InputArgument;
  1513. use Symfony\Component\Console\Input\InputInterface;
  1514. use Symfony\Component\Console\Input\InputOption;
  1515. use Symfony\Component\Console\Output\OutputInterface;
  1516. use Symfony\Component\Finder\Finder;
  1517. use Composer\Json\JsonFile;
  1518. use Composer\Config\JsonConfigSource;
  1519. use Composer\Util\Filesystem;
  1520. use Composer\Util\RemoteFilesystem;
  1521. use Composer\Package\Version\VersionParser;
  1522. class CreateProjectCommand extends Command
  1523. {
  1524. protected function configure()
  1525. {
  1526. $this
  1527. ->setName('create-project')
  1528. ->setDescription('Create new project from a package into given directory.')
  1529. ->setDefinition(array(
  1530. new InputArgument('package', InputArgument::OPTIONAL, 'Package name to be installed'),
  1531. new InputArgument('directory', InputArgument::OPTIONAL, 'Directory where the files should be created'),
  1532. new InputArgument('version', InputArgument::OPTIONAL, 'Version, will default to latest'),
  1533. new InputOption('stability', 's', InputOption::VALUE_REQUIRED, 'Minimum-stability allowed (unless a version is specified).'),
  1534. new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'),
  1535. new InputOption('prefer-dist', null, InputOption::VALUE_NONE, 'Forces installation from package dist even for dev versions.'),
  1536. new InputOption('repository-url', null, InputOption::VALUE_REQUIRED, 'Pick a different repository url to look for the package.'),
  1537. new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables installation of require-dev packages (enabled by default, only present for BC).'),
  1538. new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables installation of require-dev packages.'),
  1539. new InputOption('no-plugins', null, InputOption::VALUE_NONE, 'Whether to disable plugins.'),
  1540. new InputOption('no-custom-installers', null, InputOption::VALUE_NONE, 'DEPRECATED: Use no-plugins instead.'),
  1541. new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Whether to prevent execution of all defined scripts in the root package.'),
  1542. new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'),
  1543. new InputOption('keep-vcs', null, InputOption::VALUE_NONE, 'Whether to prevent deletion vcs folder.'),
  1544. new InputOption('no-install', null, InputOption::VALUE_NONE, 'Whether to skip installation of the package dependencies.'),
  1545. new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore platform requirements (php & ext- packages).'),
  1546. ))
  1547. ->setHelp(<<<EOT
  1548. The <info>create-project</info> command creates a new project from a given
  1549. package into a new directory. If executed without params and in a directory
  1550. with a composer.json file it installs the packages for the current project.
  1551. You can use this command to bootstrap new projects or setup a clean
  1552. version-controlled installation for developers of your project.
  1553. <info>php composer.phar create-project vendor/project target-directory [version]</info>
  1554. You can also specify the version with the package name using = or : as separator.
  1555. To install unstable packages, either specify the version you want, or use the
  1556. --stability=dev (where dev can be one of RC, beta, alpha or dev).
  1557. To setup a developer workable version you should create the project using the source
  1558. controlled code by appending the <info>'--prefer-source'</info> flag.
  1559. To install a package from another repository than the default one you
  1560. can pass the <info>'--repository-url=http://myrepository.org'</info> flag.
  1561. EOT
  1562. )
  1563. ;
  1564. }
  1565. protected function execute(InputInterface $input, OutputInterface $output)
  1566. {
  1567. $config = Factory::createConfig();
  1568. $io = $this->getIO();
  1569. $this->updatePreferredOptions($config, $input, $preferSource, $preferDist, true);
  1570. if ($input->getOption('no-custom-installers')) {
  1571. $io->writeError('<warning>You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.</warning>');
  1572. $input->setOption('no-plugins', true);
  1573. }
  1574. return $this->installProject(
  1575. $io,
  1576. $config,
  1577. $input->getArgument('package'),
  1578. $input->getArgument('directory'),
  1579. $input->getArgument('version'),
  1580. $input->getOption('stability'),
  1581. $preferSource,
  1582. $preferDist,
  1583. !$input->getOption('no-dev'),
  1584. $input->getOption('repository-url'),
  1585. $input->getOption('no-plugins'),
  1586. $input->getOption('no-scripts'),
  1587. $input->getOption('keep-vcs'),
  1588. $input->getOption('no-progress'),
  1589. $input->getOption('no-install'),
  1590. $input->getOption('ignore-platform-reqs'),
  1591. $input
  1592. );
  1593. }
  1594. public function installProject(IOInterface $io, Config $config, $packageName, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, $repositoryUrl = null, $disablePlugins = false, $noScripts = false, $keepVcs = false, $noProgress = false, $noInstall = false, $ignorePlatformReqs = false, InputInterface $input)
  1595. {
  1596. $oldCwd = getcwd();
  1597. $io->loadConfiguration($config);
  1598. if ($packageName !== null) {
  1599. $installedFromVcs = $this->installRootPackage($io, $config, $packageName, $directory, $packageVersion, $stability, $preferSource, $preferDist, $installDevPackages, $repositoryUrl, $disablePlugins, $noScripts, $keepVcs, $noProgress);
  1600. } else {
  1601. $installedFromVcs = false;
  1602. }
  1603. $composer = Factory::create($io, null, $disablePlugins);
  1604. $composer->getDownloadManager()->setOutputProgress(!$noProgress);
  1605. $fs = new Filesystem();
  1606. if ($noScripts === false) {
  1607. $composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_ROOT_PACKAGE_INSTALL, $installDevPackages);
  1608. }
  1609. $rootPackageConfig = $composer->getConfig();
  1610. $this->updatePreferredOptions($rootPackageConfig, $input, $preferSource, $preferDist);
  1611. if ($noInstall === false) {
  1612. $installer = Installer::create($io, $composer);
  1613. $installer->setPreferSource($preferSource)
  1614. ->setPreferDist($preferDist)
  1615. ->setDevMode($installDevPackages)
  1616. ->setRunScripts(!$noScripts)
  1617. ->setIgnorePlatformRequirements($ignorePlatformReqs);
  1618. if ($disablePlugins) {
  1619. $installer->disablePlugins();
  1620. }
  1621. $status = $installer->run();
  1622. if (0 !== $status) {
  1623. return $status;
  1624. }
  1625. }
  1626. $hasVcs = $installedFromVcs;
  1627. if (!$keepVcs && $installedFromVcs
  1628. && (
  1629. !$io->isInteractive()
  1630. || $io->askConfirmation('<info>Do you want to remove the existing VCS (.git, .svn..) history?</info> [<comment>Y,n</comment>]? ', true)
  1631. )
  1632. ) {
  1633. $finder = new Finder();
  1634. $finder->depth(0)->directories()->in(getcwd())->ignoreVCS(false)->ignoreDotFiles(false);
  1635. foreach (array('.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg') as $vcsName) {
  1636. $finder->name($vcsName);
  1637. }
  1638. try {
  1639. $dirs = iterator_to_array($finder);
  1640. unset($finder);
  1641. foreach ($dirs as $dir) {
  1642. if (!$fs->removeDirectory($dir)) {
  1643. throw new \RuntimeException('Could not remove '.$dir);
  1644. }
  1645. }
  1646. } catch (\Exception $e) {
  1647. $io->writeError('<error>An error occurred while removing the VCS metadata: '.$e->getMessage().'</error>');
  1648. }
  1649. $hasVcs = false;
  1650. }
  1651. if (!$hasVcs) {
  1652. $package = $composer->getPackage();
  1653. $configSource = new JsonConfigSource(new JsonFile('composer.json'));
  1654. foreach (BasePackage::$supportedLinkTypes as $type => $meta) {
  1655. foreach ($package->{'get'.$meta['method']}() as $link) {
  1656. if ($link->getPrettyConstraint() === 'self.version') {
  1657. $configSource->addLink($type, $link->getTarget(), $package->getPrettyVersion());
  1658. }
  1659. }
  1660. }
  1661. }
  1662. if ($noScripts === false) {
  1663. $composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_CREATE_PROJECT_CMD, $installDevPackages);
  1664. }
  1665. chdir($oldCwd);
  1666. $vendorComposerDir = $composer->getConfig()->get('vendor-dir').'/composer';
  1667. if (is_dir($vendorComposerDir) && $fs->isDirEmpty($vendorComposerDir)) {
  1668. @rmdir($vendorComposerDir);
  1669. $vendorDir = $composer->getConfig()->get('vendor-dir');
  1670. if (is_dir($vendorDir) && $fs->isDirEmpty($vendorDir)) {
  1671. @rmdir($vendorDir);
  1672. }
  1673. }
  1674. return 0;
  1675. }
  1676. protected function installRootPackage(IOInterface $io, Config $config, $packageName, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, $repositoryUrl = null, $disablePlugins = false, $noScripts = false, $keepVcs = false, $noProgress = false)
  1677. {
  1678. if (null === $repositoryUrl) {
  1679. $sourceRepo = new CompositeRepository(Factory::createDefaultRepositories($io, $config));
  1680. } elseif ("json" === pathinfo($repositoryUrl, PATHINFO_EXTENSION) && file_exists($repositoryUrl)) {
  1681. $json = new JsonFile($repositoryUrl, new RemoteFilesystem($io, $config));
  1682. $data = $json->read();
  1683. if (!empty($data['packages']) || !empty($data['includes']) || !empty($data['provider-includes'])) {
  1684. $sourceRepo = new ComposerRepository(array('url' => 'file://' . strtr(realpath($repositoryUrl), '\\', '/')), $io, $config);
  1685. } else {
  1686. $sourceRepo = new FilesystemRepository($json);
  1687. }
  1688. } elseif (0 === strpos($repositoryUrl, 'http')) {
  1689. $sourceRepo = new ComposerRepository(array('url' => $repositoryUrl), $io, $config);
  1690. } else {
  1691. throw new \InvalidArgumentException("Invalid repository url given. Has to be a .json file or an http url.");
  1692. }
  1693. $parser = new VersionParser();
  1694. $requirements = $parser->parseNameVersionPairs(array($packageName));
  1695. $name = strtolower($requirements[0]['name']);
  1696. if (!$packageVersion && isset($requirements[0]['version'])) {
  1697. $packageVersion = $requirements[0]['version'];
  1698. }
  1699. if (null === $stability) {
  1700. if (preg_match('{^[^,\s]*?@('.implode('|', array_keys(BasePackage::$stabilities)).')$}i', $packageVersion, $match)) {
  1701. $stability = $match[1];
  1702. } else {
  1703. $stability = VersionParser::parseStability($packageVersion);
  1704. }
  1705. }
  1706. $stability = VersionParser::normalizeStability($stability);
  1707. if (!isset(BasePackage::$stabilities[$stability])) {
  1708. throw new \InvalidArgumentException('Invalid stability provided ('.$stability.'), must be one of: '.implode(', ', array_keys(BasePackage::$stabilities)));
  1709. }
  1710. $pool = new Pool($stability);
  1711. $pool->addRepository($sourceRepo);
  1712. $versionSelector = new VersionSelector($pool);
  1713. $package = $versionSelector->findBestCandidate($name, $packageVersion);
  1714. if (!$package) {
  1715. throw new \InvalidArgumentException("Could not find package $name" . ($packageVersion ? " with version $packageVersion." : " with stability $stability."));
  1716. }
  1717. if (null === $directory) {
  1718. $parts = explode("/", $name, 2);
  1719. $directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts);
  1720. }
  1721. if (function_exists('pcntl_signal')) {
  1722. declare (ticks = 100);
  1723. pcntl_signal(SIGINT, function () use ($directory) {
  1724. $fs = new Filesystem();
  1725. $fs->removeDirectory($directory);
  1726. exit(130);
  1727. });
  1728. }
  1729. $io->writeError('<info>Installing ' . $package->getName() . ' (' . $package->getFullPrettyVersion(false) . ')</info>');
  1730. if ($disablePlugins) {
  1731. $io->writeError('<info>Plugins have been disabled.</info>');
  1732. }
  1733. if (0 === strpos($package->getPrettyVersion(), 'dev-') && in_array($package->getSourceType(), array('git', 'hg'))) {
  1734. $package->setSourceReference(substr($package->getPrettyVersion(), 4));
  1735. }
  1736. $dm = $this->createDownloadManager($io, $config);
  1737. $dm->setPreferSource($preferSource)
  1738. ->setPreferDist($preferDist)
  1739. ->setOutputProgress(!$noProgress);
  1740. $projectInstaller = new ProjectInstaller($directory, $dm);
  1741. $im = $this->createInstallationManager();
  1742. $im->addInstaller($projectInstaller);
  1743. $im->install(new InstalledFilesystemRepository(new JsonFile('php://memory')), new InstallOperation($package));
  1744. $im->notifyInstalls($io);
  1745. $installedFromVcs = 'source' === $package->getInstallationSource();
  1746. $io->writeError('<info>Created project in ' . $directory . '</info>');
  1747. chdir($directory);
  1748. $_SERVER['COMPOSER_ROOT_VERSION'] = $package->getPrettyVersion();
  1749. putenv('COMPOSER_ROOT_VERSION='.$_SERVER['COMPOSER_ROOT_VERSION']);
  1750. return $installedFromVcs;
  1751. }
  1752. protected function createDownloadManager(IOInterface $io, Config $config)
  1753. {
  1754. $factory = new Factory();
  1755. return $factory->createDownloadManager($io, $config);
  1756. }
  1757. protected function createInstallationManager()
  1758. {
  1759. return new InstallationManager();
  1760. }
  1761. protected function updatePreferredOptions(Config $config, InputInterface $input, &$preferSource, &$preferDist, $keepVcsRequiresPreferSource = false)
  1762. {
  1763. $preferSource = false;
  1764. $preferDist = false;
  1765. switch ($config->get('preferred-install')) {
  1766. case 'source':
  1767. $preferSource = true;
  1768. break;
  1769. case 'dist':
  1770. $preferDist = true;
  1771. break;
  1772. case 'auto':
  1773. default:
  1774. break;
  1775. }
  1776. if ($input->getOption('prefer-source') || $input->getOption('prefer-dist') || ($keepVcsRequiresPreferSource && $input->getOption('keep-vcs'))) {
  1777. $preferSource = $input->getOption('prefer-source') || ($keepVcsRequiresPreferSource && $input->getOption('keep-vcs'));
  1778. $preferDist = $input->getOption('prefer-dist');
  1779. }
  1780. }
  1781. }
  1782. <?php
  1783. namespace Composer\Command;
  1784. use Composer\DependencyResolver\Pool;
  1785. use Composer\Plugin\CommandEvent;
  1786. use Composer\Plugin\PluginEvents;
  1787. use Symfony\Component\Console\Input\InputInterface;
  1788. use Symfony\Component\Console\Input\InputArgument;
  1789. use Symfony\Component\Console\Input\InputOption;
  1790. use Symfony\Component\Console\Output\OutputInterface;
  1791. class DependsCommand extends Command
  1792. {
  1793. protected $linkTypes = array(
  1794. 'require' => array('requires', 'requires'),
  1795. 'require-dev' => array('devRequires', 'requires (dev)'),
  1796. );
  1797. protected function configure()
  1798. {
  1799. $this
  1800. ->setName('depends')
  1801. ->setDescription('Shows which packages depend on the given package')
  1802. ->setDefinition(array(
  1803. new InputArgument('package', InputArgument::REQUIRED, 'Package to inspect'),
  1804. new InputOption('link-type', '', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Link types to show (require, require-dev)', array_keys($this->linkTypes)),
  1805. ))
  1806. ->setHelp(<<<EOT
  1807. Displays detailed information about where a package is referenced.
  1808. <info>php composer.phar depends composer/composer</info>
  1809. EOT
  1810. )
  1811. ;
  1812. }
  1813. protected function execute(InputInterface $input, OutputInterface $output)
  1814. {
  1815. $composer = $this->getComposer();
  1816. $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'depends', $input, $output);
  1817. $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
  1818. $repo = $composer->getRepositoryManager()->getLocalRepository();
  1819. $needle = $input->getArgument('package');
  1820. $pool = new Pool();
  1821. $pool->addRepository($repo);
  1822. $packages = $pool->whatProvides($needle);
  1823. if (empty($packages)) {
  1824. throw new \InvalidArgumentException('Could not find package "'.$needle.'" in your project.');
  1825. }
  1826. $linkTypes = $this->linkTypes;
  1827. $types = array_map(function ($type) use ($linkTypes) {
  1828. $type = rtrim($type, 's');
  1829. if (!isset($linkTypes[$type])) {
  1830. throw new \InvalidArgumentException('Unexpected link type: '.$type.', valid types: '.implode(', ', array_keys($linkTypes)));
  1831. }
  1832. return $type;
  1833. }, $input->getOption('link-type'));
  1834. $messages = array();
  1835. $outputPackages = array();
  1836. $io = $this->getIO();
  1837. foreach ($repo->getPackages() as $package) {
  1838. foreach ($types as $type) {
  1839. foreach ($package->{'get'.$linkTypes[$type][0]}() as $link) {
  1840. if ($link->getTarget() === $needle) {
  1841. if (!isset($outputPackages[$package->getName()])) {
  1842. $messages[] = '<info>'.$package->getPrettyName() . '</info> ' . $linkTypes[$type][1] . ' ' . $needle .' (<info>' . $link->getPrettyConstraint() . '</info>)';
  1843. $outputPackages[$package->getName()] = true;
  1844. }
  1845. }
  1846. }
  1847. }
  1848. }
  1849. if ($messages) {
  1850. sort($messages);
  1851. $io->write($messages);
  1852. } else {
  1853. $io->writeError('<info>There is no installed package depending on "'.$needle.'".</info>');
  1854. }
  1855. }
  1856. }
  1857. <?php
  1858. namespace Composer\Command;
  1859. use Composer\Composer;
  1860. use Composer\Factory;
  1861. use Composer\Downloader\TransportException;
  1862. use Composer\Plugin\CommandEvent;
  1863. use Composer\Plugin\PluginEvents;
  1864. use Composer\Util\ConfigValidator;
  1865. use Composer\Util\ProcessExecutor;
  1866. use Composer\Util\RemoteFilesystem;
  1867. use Composer\Util\StreamContextFactory;
  1868. use Symfony\Component\Console\Input\InputInterface;
  1869. use Symfony\Component\Console\Output\OutputInterface;
  1870. class DiagnoseCommand extends Command
  1871. {
  1872. protected $rfs;
  1873. protected $process;
  1874. protected $failures = 0;
  1875. protected function configure()
  1876. {
  1877. $this
  1878. ->setName('diagnose')
  1879. ->setDescription('Diagnoses the system to identify common errors.')
  1880. ->setHelp(<<<EOT
  1881. The <info>diagnose</info> command checks common errors to help debugging problems.
  1882. EOT
  1883. )
  1884. ;
  1885. }
  1886. protected function execute(InputInterface $input, OutputInterface $output)
  1887. {
  1888. $composer = $this->getComposer(false);
  1889. $io = $this->getIO();
  1890. if ($composer) {
  1891. $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'diagnose', $input, $output);
  1892. $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
  1893. $io->write('Checking composer.json: ', false);
  1894. $this->outputResult($this->checkComposerSchema());
  1895. }
  1896. if ($composer) {
  1897. $config = $composer->getConfig();
  1898. } else {
  1899. $config = Factory::createConfig();
  1900. }
  1901. $this->rfs = new RemoteFilesystem($io, $config);
  1902. $this->process = new ProcessExecutor($io);
  1903. $io->write('Checking platform settings: ', false);
  1904. $this->outputResult($this->checkPlatform());
  1905. $io->write('Checking git settings: ', false);
  1906. $this->outputResult($this->checkGit());
  1907. $io->write('Checking http connectivity to packagist: ', false);
  1908. $this->outputResult($this->checkHttp('http'));
  1909. $io->write('Checking https connectivity to packagist: ', false);
  1910. $this->outputResult($this->checkHttp('https'));
  1911. $opts = stream_context_get_options(StreamContextFactory::getContext('http://example.org'));
  1912. if (!empty($opts['http']['proxy'])) {
  1913. $io->write('Checking HTTP proxy: ', false);
  1914. $this->outputResult($this->checkHttpProxy());
  1915. $io->write('Checking HTTP proxy support for request_fulluri: ', false);
  1916. $this->outputResult($this->checkHttpProxyFullUriRequestParam());
  1917. $io->write('Checking HTTPS proxy support for request_fulluri: ', false);
  1918. $this->outputResult($this->checkHttpsProxyFullUriRequestParam());
  1919. }
  1920. if ($oauth = $config->get('github-oauth')) {
  1921. foreach ($oauth as $domain => $token) {
  1922. $io->write('Checking '.$domain.' oauth access: ', false);
  1923. $this->outputResult($this->checkGithubOauth($domain, $token));
  1924. }
  1925. } else {
  1926. $io->write('Checking github.com rate limit: ', false);
  1927. try {
  1928. $rate = $this->getGithubRateLimit('github.com');
  1929. $this->outputResult(true);
  1930. if (10 > $rate['remaining']) {
  1931. $io->write('<warning>WARNING</warning>');
  1932. $io->write(sprintf(
  1933. '<comment>Github has a rate limit on their API. '
  1934. . 'You currently have <options=bold>%u</options=bold> '
  1935. . 'out of <options=bold>%u</options=bold> requests left.' . PHP_EOL
  1936. . 'See https://developer.github.com/v3/#rate-limiting and also' . PHP_EOL
  1937. . ' https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens</comment>',
  1938. $rate['remaining'],
  1939. $rate['limit']
  1940. ));
  1941. }
  1942. } catch (\Exception $e) {
  1943. if ($e instanceof TransportException && $e->getCode() === 401) {
  1944. $this->outputResult('<comment>The oauth token for github.com seems invalid, run "composer config --global --unset github-oauth.github.com" to remove it</comment>');
  1945. } else {
  1946. $this->outputResult($e);
  1947. }
  1948. }
  1949. }
  1950. $io->write('Checking disk free space: ', false);
  1951. $this->outputResult($this->checkDiskSpace($config));
  1952. $io->write('Checking composer version: ', false);
  1953. $this->outputResult($this->checkVersion());
  1954. return $this->failures;
  1955. }
  1956. private function checkComposerSchema()
  1957. {
  1958. $validator = new ConfigValidator($this->getIO());
  1959. list($errors, $publishErrors, $warnings) = $validator->validate(Factory::getComposerFile());
  1960. if ($errors || $publishErrors || $warnings) {
  1961. $messages = array(
  1962. 'error' => array_merge($errors, $publishErrors),
  1963. 'warning' => $warnings,
  1964. );
  1965. $output = '';
  1966. foreach ($messages as $style => $msgs) {
  1967. foreach ($msgs as $msg) {
  1968. $output .= '<' . $style . '>' . $msg . '</' . $style . '>' . PHP_EOL;
  1969. }
  1970. }
  1971. return rtrim($output);
  1972. }
  1973. return true;
  1974. }
  1975. private function checkGit()
  1976. {
  1977. $this->process->execute('git config color.ui', $output);
  1978. if (strtolower(trim($output)) === 'always') {
  1979. return '<comment>Your git color.ui setting is set to always, this is known to create issues. Use "git config --global color.ui true" to set it correctly.</comment>';
  1980. }
  1981. return true;
  1982. }
  1983. private function checkHttp($proto)
  1984. {
  1985. try {
  1986. $this->rfs->getContents('packagist.org', $proto . '://packagist.org/packages.json', false);
  1987. } catch (\Exception $e) {
  1988. return $e;
  1989. }
  1990. return true;
  1991. }
  1992. private function checkHttpProxy()
  1993. {
  1994. $protocol = extension_loaded('openssl') ? 'https' : 'http';
  1995. try {
  1996. $json = json_decode($this->rfs->getContents('packagist.org', $protocol . '://packagist.org/packages.json', false), true);
  1997. $hash = reset($json['provider-includes']);
  1998. $hash = $hash['sha256'];
  1999. $path = str_replace('%hash%', $hash, key($json['provider-includes']));
  2000. $provider = $this->rfs->getContents('packagist.org', $protocol . '://packagist.org/'.$path, false);
  2001. if (hash('sha256', $provider) !== $hash) {
  2002. return 'It seems that your proxy is modifying http traffic on the fly';
  2003. }
  2004. } catch (\Exception $e) {
  2005. return $e;
  2006. }
  2007. return true;
  2008. }
  2009. private function checkHttpProxyFullUriRequestParam()
  2010. {
  2011. $url = 'http://packagist.org/packages.json';
  2012. try {
  2013. $this->rfs->getContents('packagist.org', $url, false);
  2014. } catch (TransportException $e) {
  2015. try {
  2016. $this->rfs->getContents('packagist.org', $url, false, array('http' => array('request_fulluri' => false)));
  2017. } catch (TransportException $e) {
  2018. return 'Unable to assess the situation, maybe packagist.org is down ('.$e->getMessage().')';
  2019. }
  2020. return 'It seems there is a problem with your proxy server, try setting the "HTTP_PROXY_REQUEST_FULLURI" and "HTTPS_PROXY_REQUEST_FULLURI" environment variables to "false"';
  2021. }
  2022. return true;
  2023. }
  2024. private function checkHttpsProxyFullUriRequestParam()
  2025. {
  2026. if (!extension_loaded('openssl')) {
  2027. return 'You need the openssl extension installed for this check';
  2028. }
  2029. $url = 'https://api.github.com/repos/Seldaek/jsonlint/zipball/1.0.0';
  2030. try {
  2031. $this->rfs->getContents('github.com', $url, false);
  2032. } catch (TransportException $e) {
  2033. try {
  2034. $this->rfs->getContents('github.com', $url, false, array('http' => array('request_fulluri' => false)));
  2035. } catch (TransportException $e) {
  2036. return 'Unable to assess the situation, maybe github is down ('.$e->getMessage().')';
  2037. }
  2038. return 'It seems there is a problem with your proxy server, try setting the "HTTPS_PROXY_REQUEST_FULLURI" environment variable to "false"';
  2039. }
  2040. return true;
  2041. }
  2042. private function checkGithubOauth($domain, $token)
  2043. {
  2044. $this->getIO()->setAuthentication($domain, $token, 'x-oauth-basic');
  2045. try {
  2046. $url = $domain === 'github.com' ? 'https://api.'.$domain.'/user/repos' : 'https://'.$domain.'/api/v3/user/repos';
  2047. return $this->rfs->getContents($domain, $url, false, array(
  2048. 'retry-auth-failure' => false,
  2049. )) ? true : 'Unexpected error';
  2050. } catch (\Exception $e) {
  2051. if ($e instanceof TransportException && $e->getCode() === 401) {
  2052. return '<comment>The oauth token for '.$domain.' seems invalid, run "composer config --global --unset github-oauth.'.$domain.'" to remove it</comment>';
  2053. }
  2054. return $e;
  2055. }
  2056. }
  2057. private function getGithubRateLimit($domain, $token = null)
  2058. {
  2059. if ($token) {
  2060. $this->getIO()->setAuthentication($domain, $token, 'x-oauth-basic');
  2061. }
  2062. $url = $domain === 'github.com' ? 'https://api.'.$domain.'/rate_limit' : 'https://'.$domain.'/api/rate_limit';
  2063. $json = $this->rfs->getContents($domain, $url, false, array('retry-auth-failure' => false));
  2064. $data = json_decode($json, true);
  2065. return $data['resources']['core'];
  2066. }
  2067. private function checkDiskSpace($config)
  2068. {
  2069. $minSpaceFree = 1024 * 1024;
  2070. if ((($df = @disk_free_space($dir = $config->get('home'))) !== false && $df < $minSpaceFree)
  2071. || (($df = @disk_free_space($dir = $config->get('vendor-dir'))) !== false && $df < $minSpaceFree)
  2072. ) {
  2073. return '<error>The disk hosting '.$dir.' is full</error>';
  2074. }
  2075. return true;
  2076. }
  2077. private function checkVersion()
  2078. {
  2079. $protocol = extension_loaded('openssl') ? 'https' : 'http';
  2080. $latest = trim($this->rfs->getContents('getcomposer.org', $protocol . '://getcomposer.org/version', false));
  2081. if (Composer::VERSION !== $latest && Composer::VERSION !== '@package_version@') {
  2082. return '<comment>You are not running the latest version</comment>';
  2083. }
  2084. return true;
  2085. }
  2086. private function outputResult($result)
  2087. {
  2088. $io = $this->getIO();
  2089. if (true === $result) {
  2090. $io->write('<info>OK</info>');
  2091. } else {
  2092. $this->failures++;
  2093. $io->write('<error>FAIL</error>');
  2094. if ($result instanceof \Exception) {
  2095. $io->write('['.get_class($result).'] '.$result->getMessage());
  2096. } elseif ($result) {
  2097. $io->write(trim($result));
  2098. }
  2099. }
  2100. }
  2101. private function checkPlatform()
  2102. {
  2103. $output = '';
  2104. $out = function ($msg, $style) use (&$output) {
  2105. $output .= '<'.$style.'>'.$msg.'</'.$style.'>'.PHP_EOL;
  2106. };
  2107. $errors = array();
  2108. $warnings = array();
  2109. $iniPath = php_ini_loaded_file();
  2110. $displayIniMessage = false;
  2111. if ($iniPath) {
  2112. $iniMessage = PHP_EOL.PHP_EOL.'The php.ini used by your command-line PHP is: ' . $iniPath;
  2113. } else {
  2114. $iniMessage = PHP_EOL.PHP_EOL.'A php.ini file does not exist. You will have to create one.';
  2115. }
  2116. $iniMessage .= PHP_EOL.'If you can not modify the ini file, you can also run `php -d option=value` to modify ini values on the fly. You can use -d multiple times.';
  2117. if (!function_exists('json_decode')) {
  2118. $errors['json'] = true;
  2119. }
  2120. if (!extension_loaded('Phar')) {
  2121. $errors['phar'] = true;
  2122. }
  2123. if (!extension_loaded('filter')) {
  2124. $errors['filter'] = true;
  2125. }
  2126. if (!extension_loaded('hash')) {
  2127. $errors['hash'] = true;
  2128. }
  2129. if (!ini_get('allow_url_fopen')) {
  2130. $errors['allow_url_fopen'] = true;
  2131. }
  2132. if (extension_loaded('ionCube Loader') && ioncube_loader_iversion() < 40009) {
  2133. $errors['ioncube'] = ioncube_loader_version();
  2134. }
  2135. if (PHP_VERSION_ID < 50302) {
  2136. $errors['php'] = PHP_VERSION;
  2137. }
  2138. if (!isset($errors['php']) && PHP_VERSION_ID < 50304) {
  2139. $warnings['php'] = PHP_VERSION;
  2140. }
  2141. if (!extension_loaded('openssl')) {
  2142. $errors['openssl'] = true;
  2143. }
  2144. if (!defined('HHVM_VERSION') && !extension_loaded('apcu') && ini_get('apc.enable_cli')) {
  2145. $warnings['apc_cli'] = true;
  2146. }
  2147. ob_start();
  2148. phpinfo(INFO_GENERAL);
  2149. $phpinfo = ob_get_clean();
  2150. if (preg_match('{Configure Command(?: *</td><td class="v">| *=> *)(.*?)(?:</td>|$)}m', $phpinfo, $match)) {
  2151. $configure = $match[1];
  2152. if (false !== strpos($configure, '--enable-sigchild')) {
  2153. $warnings['sigchild'] = true;
  2154. }
  2155. if (false !== strpos($configure, '--with-curlwrappers')) {
  2156. $warnings['curlwrappers'] = true;
  2157. }
  2158. }
  2159. if (ini_get('xdebug.profiler_enabled')) {
  2160. $warnings['xdebug_profile'] = true;
  2161. } elseif (extension_loaded('xdebug')) {
  2162. $warnings['xdebug_loaded'] = true;
  2163. }
  2164. if (!empty($errors)) {
  2165. foreach ($errors as $error => $current) {
  2166. switch ($error) {
  2167. case 'json':
  2168. $text = PHP_EOL."The json extension is missing.".PHP_EOL;
  2169. $text .= "Install it or recompile php without --disable-json";
  2170. break;
  2171. case 'phar':
  2172. $text = PHP_EOL."The phar extension is missing.".PHP_EOL;
  2173. $text .= "Install it or recompile php without --disable-phar";
  2174. break;
  2175. case 'filter':
  2176. $text = PHP_EOL."The filter extension is missing.".PHP_EOL;
  2177. $text .= "Install it or recompile php without --disable-filter";
  2178. break;
  2179. case 'hash':
  2180. $text = PHP_EOL."The hash extension is missing.".PHP_EOL;
  2181. $text .= "Install it or recompile php without --disable-hash";
  2182. break;
  2183. case 'unicode':
  2184. $text = PHP_EOL."The detect_unicode setting must be disabled.".PHP_EOL;
  2185. $text .= "Add the following to the end of your `php.ini`:".PHP_EOL;
  2186. $text .= " detect_unicode = Off";
  2187. $displayIniMessage = true;
  2188. break;
  2189. case 'suhosin':
  2190. $text = PHP_EOL."The suhosin.executor.include.whitelist setting is incorrect.".PHP_EOL;
  2191. $text .= "Add the following to the end of your `php.ini` or suhosin.ini (Example path [for Debian]: /etc/php5/cli/conf.d/suhosin.ini):".PHP_EOL;
  2192. $text .= " suhosin.executor.include.whitelist = phar ".$current;
  2193. $displayIniMessage = true;
  2194. break;
  2195. case 'php':
  2196. $text = PHP_EOL."Your PHP ({$current}) is too old, you must upgrade to PHP 5.3.2 or higher.";
  2197. break;
  2198. case 'allow_url_fopen':
  2199. $text = PHP_EOL."The allow_url_fopen setting is incorrect.".PHP_EOL;
  2200. $text .= "Add the following to the end of your `php.ini`:".PHP_EOL;
  2201. $text .= " allow_url_fopen = On";
  2202. $displayIniMessage = true;
  2203. break;
  2204. case 'ioncube':
  2205. $text = PHP_EOL."Your ionCube Loader extension ($current) is incompatible with Phar files.".PHP_EOL;
  2206. $text .= "Upgrade to ionCube 4.0.9 or higher or remove this line (path may be different) from your `php.ini` to disable it:".PHP_EOL;
  2207. $text .= " zend_extension = /usr/lib/php5/20090626+lfs/ioncube_loader_lin_5.3.so";
  2208. $displayIniMessage = true;
  2209. break;
  2210. case 'openssl':
  2211. $text = PHP_EOL."The openssl extension is missing, which means that secure HTTPS transfers are impossible.".PHP_EOL;
  2212. $text .= "If possible you should enable it or recompile php with --with-openssl";
  2213. break;
  2214. }
  2215. $out($text, 'error');
  2216. }
  2217. $output .= PHP_EOL;
  2218. }
  2219. if (!empty($warnings)) {
  2220. foreach ($warnings as $warning => $current) {
  2221. switch ($warning) {
  2222. case 'apc_cli':
  2223. $text = "The apc.enable_cli setting is incorrect.".PHP_EOL;
  2224. $text .= "Add the following to the end of your `php.ini`:".PHP_EOL;
  2225. $text .= " apc.enable_cli = Off";
  2226. $displayIniMessage = true;
  2227. break;
  2228. case 'sigchild':
  2229. $text = "PHP was compiled with --enable-sigchild which can cause issues on some platforms.".PHP_EOL;
  2230. $text .= "Recompile it without this flag if possible, see also:".PHP_EOL;
  2231. $text .= " https://bugs.php.net/bug.php?id=22999";
  2232. break;
  2233. case 'curlwrappers':
  2234. $text = "PHP was compiled with --with-curlwrappers which will cause issues with HTTP authentication and GitHub.".PHP_EOL;
  2235. $text .= " Recompile it without this flag if possible";
  2236. break;
  2237. case 'php':
  2238. $text = "Your PHP ({$current}) is quite old, upgrading to PHP 5.3.4 or higher is recommended.".PHP_EOL;
  2239. $text .= " Composer works with 5.3.2+ for most people, but there might be edge case issues.";
  2240. break;
  2241. case 'xdebug_loaded':
  2242. $text = "The xdebug extension is loaded, this can slow down Composer a little.".PHP_EOL;
  2243. $text .= " Disabling it when using Composer is recommended.";
  2244. break;
  2245. case 'xdebug_profile':
  2246. $text = "The xdebug.profiler_enabled setting is enabled, this can slow down Composer a lot.".PHP_EOL;
  2247. $text .= "Add the following to the end of your `php.ini` to disable it:".PHP_EOL;
  2248. $text .= " xdebug.profiler_enabled = 0";
  2249. $displayIniMessage = true;
  2250. break;
  2251. }
  2252. $out($text, 'comment');
  2253. }
  2254. }
  2255. if ($displayIniMessage) {
  2256. $out($iniMessage, 'comment');
  2257. }
  2258. return !$warnings && !$errors ? true : $output;
  2259. }
  2260. }
  2261. <?php
  2262. namespace Composer\Command;
  2263. use Composer\Plugin\CommandEvent;
  2264. use Composer\Plugin\PluginEvents;
  2265. use Symfony\Component\Console\Input\InputInterface;
  2266. use Symfony\Component\Console\Input\InputOption;
  2267. use Symfony\Component\Console\Output\OutputInterface;
  2268. class DumpAutoloadCommand extends Command
  2269. {
  2270. protected function configure()
  2271. {
  2272. $this
  2273. ->setName('dump-autoload')
  2274. ->setAliases(array('dumpautoload'))
  2275. ->setDescription('Dumps the autoloader')
  2276. ->setDefinition(array(
  2277. new InputOption('optimize', 'o', InputOption::VALUE_NONE, 'Optimizes PSR0 and PSR4 packages to be loaded with classmaps too, good for production.'),
  2278. new InputOption('classmap-authoritative', 'a', InputOption::VALUE_NONE, 'Autoload classes from the classmap only. Implicitly enables `--optimize`.'),
  2279. new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables autoload-dev rules.'),
  2280. ))
  2281. ->setHelp(<<<EOT
  2282. <info>php composer.phar dump-autoload</info>
  2283. EOT
  2284. )
  2285. ;
  2286. }
  2287. protected function execute(InputInterface $input, OutputInterface $output)
  2288. {
  2289. $composer = $this->getComposer();
  2290. $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'dump-autoload', $input, $output);
  2291. $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
  2292. $installationManager = $composer->getInstallationManager();
  2293. $localRepo = $composer->getRepositoryManager()->getLocalRepository();
  2294. $package = $composer->getPackage();
  2295. $config = $composer->getConfig();
  2296. $optimize = $input->getOption('optimize') || $config->get('optimize-autoloader');
  2297. $authoritative = $input->getOption('classmap-authoritative') || $config->get('classmap-authoritative');
  2298. if ($optimize || $authoritative) {
  2299. $this->getIO()->writeError('<info>Generating optimized autoload files</info>');
  2300. } else {
  2301. $this->getIO()->writeError('<info>Generating autoload files</info>');
  2302. }
  2303. $generator = $composer->getAutoloadGenerator();
  2304. $generator->setDevMode(!$input->getOption('no-dev'));
  2305. $generator->setClassMapAuthoritative($authoritative);
  2306. $generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize);
  2307. }
  2308. }
  2309. <?php
  2310. namespace Composer\Command;
  2311. use Composer\Factory;
  2312. use Symfony\Component\Console\Input\InputInterface;
  2313. use Symfony\Component\Console\Input\InputArgument;
  2314. use Symfony\Component\Console\Input\StringInput;
  2315. use Symfony\Component\Console\Output\OutputInterface;
  2316. class GlobalCommand extends Command
  2317. {
  2318. protected function configure()
  2319. {
  2320. $this
  2321. ->setName('global')
  2322. ->setDescription('Allows running commands in the global composer dir ($COMPOSER_HOME).')
  2323. ->setDefinition(array(
  2324. new InputArgument('command-name', InputArgument::REQUIRED, ''),
  2325. new InputArgument('args', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, ''),
  2326. ))
  2327. ->setHelp(<<<EOT
  2328. Use this command as a wrapper to run other Composer commands
  2329. within the global context of COMPOSER_HOME.
  2330. You can use this to install CLI utilities globally, all you need
  2331. is to add the COMPOSER_HOME/vendor/bin dir to your PATH env var.
  2332. COMPOSER_HOME is c:\Users\<user>\AppData\Roaming\Composer on Windows
  2333. and /home/<user>/.composer on unix systems.
  2334. Note: This path may vary depending on customizations to bin-dir in
  2335. composer.json or the environmental variable COMPOSER_BIN_DIR.
  2336. EOT
  2337. )
  2338. ;
  2339. }
  2340. public function run(InputInterface $input, OutputInterface $output)
  2341. {
  2342. $tokens = preg_split('{\s+}', $input->__toString());
  2343. $args = array();
  2344. foreach ($tokens as $token) {
  2345. if ($token && $token[0] !== '-') {
  2346. $args[] = $token;
  2347. if (count($args) >= 2) {
  2348. break;
  2349. }
  2350. }
  2351. }
  2352. if (count($args) < 2) {
  2353. return parent::run($input, $output);
  2354. }
  2355. $config = Factory::createConfig();
  2356. chdir($config->get('home'));
  2357. $this->getIO()->writeError('<info>Changed current directory to '.$config->get('home').'</info>');
  2358. $input = new StringInput(preg_replace('{\bg(?:l(?:o(?:b(?:a(?:l)?)?)?)?)?\b}', '', $input->__toString(), 1));
  2359. return $this->getApplication()->run($input, $output);
  2360. }
  2361. }
  2362. <?php
  2363. namespace Composer\Command;
  2364. use Composer\Factory;
  2365. use Composer\Package\CompletePackageInterface;
  2366. use Composer\Repository\RepositoryInterface;
  2367. use Composer\Repository\ArrayRepository;
  2368. use Composer\Util\ProcessExecutor;
  2369. use Symfony\Component\Console\Input\InputArgument;
  2370. use Symfony\Component\Console\Input\InputOption;
  2371. use Symfony\Component\Console\Input\InputInterface;
  2372. use Symfony\Component\Console\Output\OutputInterface;
  2373. class HomeCommand extends Command
  2374. {
  2375. protected function configure()
  2376. {
  2377. $this
  2378. ->setName('browse')
  2379. ->setAliases(array('home'))
  2380. ->setDescription('Opens the package\'s repository URL or homepage in your browser.')
  2381. ->setDefinition(array(
  2382. new InputArgument('packages', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'Package(s) to browse to.'),
  2383. new InputOption('homepage', 'H', InputOption::VALUE_NONE, 'Open the homepage instead of the repository URL.'),
  2384. new InputOption('show', 's', InputOption::VALUE_NONE, 'Only show the homepage or repository URL.'),
  2385. ))
  2386. ->setHelp(<<<EOT
  2387. The home command opens or shows a package's repository URL or
  2388. homepage in your default browser.
  2389. To open the homepage by default, use -H or --homepage.
  2390. To show instead of open the repository or homepage URL, use -s or --show.
  2391. EOT
  2392. );
  2393. }
  2394. protected function execute(InputInterface $input, OutputInterface $output)
  2395. {
  2396. $repos = $this->initializeRepos();
  2397. $io = $this->getIO();
  2398. $return = 0;
  2399. foreach ($input->getArgument('packages') as $packageName) {
  2400. $handled = false;
  2401. $packageExists = false;
  2402. foreach ($repos as $repo) {
  2403. foreach ($repo->findPackages($packageName) as $package) {
  2404. $packageExists = true;
  2405. if ($this->handlePackage($package, $input->getOption('homepage'), $input->getOption('show'))) {
  2406. $handled = true;
  2407. break 2;
  2408. }
  2409. }
  2410. }
  2411. if (!$packageExists) {
  2412. $return = 1;
  2413. $io->writeError('<warning>Package '.$packageName.' not found</warning>');
  2414. }
  2415. if (!$handled) {
  2416. $return = 1;
  2417. $io->writeError('<warning>'.($input->getOption('homepage') ? 'Invalid or missing homepage' : 'Invalid or missing repository URL').' for '.$packageName.'</warning>');
  2418. }
  2419. }
  2420. return $return;
  2421. }
  2422. private function handlePackage(CompletePackageInterface $package, $showHomepage, $showOnly)
  2423. {
  2424. $support = $package->getSupport();
  2425. $url = isset($support['source']) ? $support['source'] : $package->getSourceUrl();
  2426. if (!$url || $showHomepage) {
  2427. $url = $package->getHomepage();
  2428. }
  2429. if (!$url || !filter_var($url, FILTER_VALIDATE_URL)) {
  2430. return false;
  2431. }
  2432. if ($showOnly) {
  2433. $this->getIO()->write(sprintf('<info>%s</info>', $url));
  2434. } else {
  2435. $this->openBrowser($url);
  2436. }
  2437. return true;
  2438. }
  2439. private function openBrowser($url)
  2440. {
  2441. $url = ProcessExecutor::escape($url);
  2442. if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
  2443. return passthru('start "web" explorer "' . $url . '"');
  2444. }
  2445. passthru('which xdg-open', $linux);
  2446. passthru('which open', $osx);
  2447. if (0 === $linux) {
  2448. passthru('xdg-open ' . $url);
  2449. } elseif (0 === $osx) {
  2450. passthru('open ' . $url);
  2451. } else {
  2452. $this->getIO()->writeError('no suitable browser opening command found, open yourself: ' . $url);
  2453. }
  2454. }
  2455. private function initializeRepos()
  2456. {
  2457. $composer = $this->getComposer(false);
  2458. if ($composer) {
  2459. return array_merge(
  2460. array(new ArrayRepository(array($composer->getPackage()))),
  2461. array($composer->getRepositoryManager()->getLocalRepository()),
  2462. $composer->getRepositoryManager()->getRepositories()
  2463. );
  2464. }
  2465. $defaultRepos = Factory::createDefaultRepositories($this->getIO());
  2466. return $defaultRepos;
  2467. }
  2468. }
  2469. <?php
  2470. namespace Composer\Command;
  2471. use Composer\DependencyResolver\Pool;
  2472. use Composer\Json\JsonFile;
  2473. use Composer\Factory;
  2474. use Composer\Package\BasePackage;
  2475. use Composer\Package\Version\VersionParser;
  2476. use Composer\Package\Version\VersionSelector;
  2477. use Composer\Repository\CompositeRepository;
  2478. use Composer\Repository\PlatformRepository;
  2479. use Composer\Util\ProcessExecutor;
  2480. use Symfony\Component\Console\Input\InputInterface;
  2481. use Symfony\Component\Console\Input\InputOption;
  2482. use Symfony\Component\Console\Output\OutputInterface;
  2483. use Symfony\Component\Process\Process;
  2484. use Symfony\Component\Process\ExecutableFinder;
  2485. class InitCommand extends Command
  2486. {
  2487. protected $repos;
  2488. private $gitConfig;
  2489. private $pool;
  2490. protected function configure()
  2491. {
  2492. $this
  2493. ->setName('init')
  2494. ->setDescription('Creates a basic composer.json file in current directory.')
  2495. ->setDefinition(array(
  2496. new InputOption('name', null, InputOption::VALUE_REQUIRED, 'Name of the package'),
  2497. new InputOption('description', null, InputOption::VALUE_REQUIRED, 'Description of package'),
  2498. new InputOption('author', null, InputOption::VALUE_REQUIRED, 'Author name of package'),
  2499. new InputOption('type', null, InputOption::VALUE_OPTIONAL, 'Type of package'),
  2500. new InputOption('homepage', null, InputOption::VALUE_REQUIRED, 'Homepage of package'),
  2501. new InputOption('require', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Package to require with a version constraint, e.g. foo/bar:1.0.0 or foo/bar=1.0.0 or "foo/bar 1.0.0"'),
  2502. new InputOption('require-dev', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Package to require for development with a version constraint, e.g. foo/bar:1.0.0 or foo/bar=1.0.0 or "foo/bar 1.0.0"'),
  2503. new InputOption('stability', 's', InputOption::VALUE_REQUIRED, 'Minimum stability (empty or one of: '.implode(', ', array_keys(BasePackage::$stabilities)).')'),
  2504. new InputOption('license', 'l', InputOption::VALUE_REQUIRED, 'License of package'),
  2505. ))
  2506. ->setHelp(<<<EOT
  2507. The <info>init</info> command creates a basic composer.json file
  2508. in the current directory.
  2509. <info>php composer.phar init</info>
  2510. EOT
  2511. )
  2512. ;
  2513. }
  2514. protected function execute(InputInterface $input, OutputInterface $output)
  2515. {
  2516. $whitelist = array('name', 'description', 'author', 'type', 'homepage', 'require', 'require-dev', 'stability', 'license');
  2517. $options = array_filter(array_intersect_key($input->getOptions(), array_flip($whitelist)));
  2518. if (isset($options['author'])) {
  2519. $options['authors'] = $this->formatAuthors($options['author']);
  2520. unset($options['author']);
  2521. }
  2522. if (isset($options['stability'])) {
  2523. $options['minimum-stability'] = $options['stability'];
  2524. unset($options['stability']);
  2525. }
  2526. $options['require'] = isset($options['require']) ? $this->formatRequirements($options['require']) : new \stdClass;
  2527. if (array() === $options['require']) {
  2528. $options['require'] = new \stdClass;
  2529. }
  2530. if (isset($options['require-dev'])) {
  2531. $options['require-dev'] = $this->formatRequirements($options['require-dev']);
  2532. if (array() === $options['require-dev']) {
  2533. $options['require-dev'] = new \stdClass;
  2534. }
  2535. }
  2536. $file = new JsonFile('composer.json');
  2537. $json = $file->encode($options);
  2538. $io = $this->getIO();
  2539. if ($input->isInteractive()) {
  2540. $io->writeError(array('', $json, ''));
  2541. if (!$io->askConfirmation('Do you confirm generation [<comment>yes</comment>]? ', true)) {
  2542. $io->writeError('<error>Command aborted</error>');
  2543. return 1;
  2544. }
  2545. }
  2546. $file->write($options);
  2547. if ($input->isInteractive() && is_dir('.git')) {
  2548. $ignoreFile = realpath('.gitignore');
  2549. if (false === $ignoreFile) {
  2550. $ignoreFile = realpath('.') . '/.gitignore';
  2551. }
  2552. if (!$this->hasVendorIgnore($ignoreFile)) {
  2553. $question = 'Would you like the <info>vendor</info> directory added to your <info>.gitignore</info> [<comment>yes</comment>]? ';
  2554. if ($io->askConfirmation($question, true)) {
  2555. $this->addVendorIgnore($ignoreFile);
  2556. }
  2557. }
  2558. }
  2559. }
  2560. protected function interact(InputInterface $input, OutputInterface $output)
  2561. {
  2562. $git = $this->getGitConfig();
  2563. $io = $this->getIO();
  2564. $formatter = $this->getHelperSet()->get('formatter');
  2565. $io->writeError(array(
  2566. '',
  2567. $formatter->formatBlock('Welcome to the Composer config generator', 'bg=blue;fg=white', true),
  2568. '',
  2569. ));
  2570. $io->writeError(array(
  2571. '',
  2572. 'This command will guide you through creating your composer.json config.',
  2573. '',
  2574. ));
  2575. $cwd = realpath(".");
  2576. if (!$name = $input->getOption('name')) {
  2577. $name = basename($cwd);
  2578. $name = preg_replace('{(?:([a-z])([A-Z])|([A-Z])([A-Z][a-z]))}', '\\1\\3-\\2\\4', $name);
  2579. $name = strtolower($name);
  2580. if (isset($git['github.user'])) {
  2581. $name = $git['github.user'] . '/' . $name;
  2582. } elseif (!empty($_SERVER['USERNAME'])) {
  2583. $name = $_SERVER['USERNAME'] . '/' . $name;
  2584. } elseif (get_current_user()) {
  2585. $name = get_current_user() . '/' . $name;
  2586. } else {
  2587. $name = $name . '/' . $name;
  2588. }
  2589. } else {
  2590. if (!preg_match('{^[a-z0-9_.-]+/[a-z0-9_.-]+$}', $name)) {
  2591. throw new \InvalidArgumentException(
  2592. 'The package name '.$name.' is invalid, it should be lowercase and have a vendor name, a forward slash, and a package name, matching: [a-z0-9_.-]+/[a-z0-9_.-]+'
  2593. );
  2594. }
  2595. }
  2596. $name = $io->askAndValidate(
  2597. 'Package name (<vendor>/<name>) [<comment>'.$name.'</comment>]: ',
  2598. function ($value) use ($name) {
  2599. if (null === $value) {
  2600. return $name;
  2601. }
  2602. if (!preg_match('{^[a-z0-9_.-]+/[a-z0-9_.-]+$}', $value)) {
  2603. throw new \InvalidArgumentException(
  2604. 'The package name '.$value.' is invalid, it should be lowercase and have a vendor name, a forward slash, and a package name, matching: [a-z0-9_.-]+/[a-z0-9_.-]+'
  2605. );
  2606. }
  2607. return $value;
  2608. },
  2609. null,
  2610. $name
  2611. );
  2612. $input->setOption('name', $name);
  2613. $description = $input->getOption('description') ?: false;
  2614. $description = $io->ask(
  2615. 'Description [<comment>'.$description.'</comment>]: ',
  2616. $description
  2617. );
  2618. $input->setOption('description', $description);
  2619. if (null === $author = $input->getOption('author')) {
  2620. if (isset($git['user.name']) && isset($git['user.email'])) {
  2621. $author = sprintf('%s <%s>', $git['user.name'], $git['user.email']);
  2622. }
  2623. }
  2624. $self = $this;
  2625. $author = $io->askAndValidate(
  2626. 'Author [<comment>'.$author.'</comment>]: ',
  2627. function ($value) use ($self, $author) {
  2628. $value = $value ?: $author;
  2629. $author = $self->parseAuthorString($value);
  2630. return sprintf('%s <%s>', $author['name'], $author['email']);
  2631. },
  2632. null,
  2633. $author
  2634. );
  2635. $input->setOption('author', $author);
  2636. $minimumStability = $input->getOption('stability') ?: null;
  2637. $minimumStability = $io->askAndValidate(
  2638. 'Minimum Stability [<comment>'.$minimumStability.'</comment>]: ',
  2639. function ($value) use ($self, $minimumStability) {
  2640. if (null === $value) {
  2641. return $minimumStability;
  2642. }
  2643. if (!isset(BasePackage::$stabilities[$value])) {
  2644. throw new \InvalidArgumentException(
  2645. 'Invalid minimum stability "'.$value.'". Must be empty or one of: '.
  2646. implode(', ', array_keys(BasePackage::$stabilities))
  2647. );
  2648. }
  2649. return $value;
  2650. },
  2651. null,
  2652. $minimumStability
  2653. );
  2654. $input->setOption('stability', $minimumStability);
  2655. $type = $input->getOption('type') ?: false;
  2656. $type = $io->ask(
  2657. 'Package Type [<comment>'.$type.'</comment>]: ',
  2658. $type
  2659. );
  2660. $input->setOption('type', $type);
  2661. $license = $input->getOption('license') ?: false;
  2662. $license = $io->ask(
  2663. 'License [<comment>'.$license.'</comment>]: ',
  2664. $license
  2665. );
  2666. $input->setOption('license', $license);
  2667. $io->writeError(array('', 'Define your dependencies.', ''));
  2668. $question = 'Would you like to define your dependencies (require) interactively [<comment>yes</comment>]? ';
  2669. $requirements = array();
  2670. if ($io->askConfirmation($question, true)) {
  2671. $requirements = $this->determineRequirements($input, $output, $input->getOption('require'));
  2672. }
  2673. $input->setOption('require', $requirements);
  2674. $question = 'Would you like to define your dev dependencies (require-dev) interactively [<comment>yes</comment>]? ';
  2675. $devRequirements = array();
  2676. if ($io->askConfirmation($question, true)) {
  2677. $devRequirements = $this->determineRequirements($input, $output, $input->getOption('require-dev'));
  2678. }
  2679. $input->setOption('require-dev', $devRequirements);
  2680. }
  2681. public function parseAuthorString($author)
  2682. {
  2683. if (preg_match('/^(?P<name>[- \.,\p{L}\p{N}\'’]+) <(?P<email>.+?)>$/u', $author, $match)) {
  2684. if ($this->isValidEmail($match['email'])) {
  2685. return array(
  2686. 'name' => trim($match['name']),
  2687. 'email' => $match['email'],
  2688. );
  2689. }
  2690. }
  2691. throw new \InvalidArgumentException(
  2692. 'Invalid author string. Must be in the format: '.
  2693. 'John Smith <john@example.com>'
  2694. );
  2695. }
  2696. protected function findPackages($name)
  2697. {
  2698. return $this->getRepos()->search($name);
  2699. }
  2700. protected function getRepos()
  2701. {
  2702. if (!$this->repos) {
  2703. $this->repos = new CompositeRepository(array_merge(
  2704. array(new PlatformRepository),
  2705. Factory::createDefaultRepositories($this->getIO())
  2706. ));
  2707. }
  2708. return $this->repos;
  2709. }
  2710. protected function determineRequirements(InputInterface $input, OutputInterface $output, $requires = array())
  2711. {
  2712. if ($requires) {
  2713. $requires = $this->normalizeRequirements($requires);
  2714. $result = array();
  2715. $io = $this->getIO();
  2716. foreach ($requires as $requirement) {
  2717. if (!isset($requirement['version'])) {
  2718. $version = $this->findBestVersionForPackage($input, $requirement['name']);
  2719. $requirement['version'] = $version;
  2720. $io->writeError(sprintf(
  2721. 'Using version <info>%s</info> for <info>%s</info>',
  2722. $requirement['version'],
  2723. $requirement['name']
  2724. ));
  2725. }
  2726. $result[] = $requirement['name'] . ' ' . $requirement['version'];
  2727. }
  2728. return $result;
  2729. }
  2730. $versionParser = new VersionParser();
  2731. $io = $this->getIO();
  2732. while (null !== $package = $io->ask('Search for a package: ')) {
  2733. $matches = $this->findPackages($package);
  2734. if (count($matches)) {
  2735. $exactMatch = null;
  2736. $choices = array();
  2737. foreach ($matches as $position => $foundPackage) {
  2738. $choices[] = sprintf(' <info>%5s</info> %s', "[$position]", $foundPackage['name']);
  2739. if ($foundPackage['name'] === $package) {
  2740. $exactMatch = true;
  2741. break;
  2742. }
  2743. }
  2744. if (!$exactMatch) {
  2745. $io->writeError(array(
  2746. '',
  2747. sprintf('Found <info>%s</info> packages matching <info>%s</info>', count($matches), $package),
  2748. '',
  2749. ));
  2750. $io->writeError($choices);
  2751. $io->writeError('');
  2752. $validator = function ($selection) use ($matches, $versionParser) {
  2753. if ('' === $selection) {
  2754. return false;
  2755. }
  2756. if (is_numeric($selection) && isset($matches[(int) $selection])) {
  2757. $package = $matches[(int) $selection];
  2758. return $package['name'];
  2759. }
  2760. if (preg_match('{^\s*(?P<name>[\S/]+)(?:\s+(?P<version>\S+))?\s*$}', $selection, $packageMatches)) {
  2761. if (isset($packageMatches['version'])) {
  2762. $versionParser->parseConstraints($packageMatches['version']);
  2763. return $packageMatches['name'].' '.$packageMatches['version'];
  2764. }
  2765. return $packageMatches['name'];
  2766. }
  2767. throw new \Exception('Not a valid selection');
  2768. };
  2769. $package = $io->askAndValidate(
  2770. 'Enter package # to add, or the complete package name if it is not listed: ',
  2771. $validator,
  2772. 3,
  2773. false
  2774. );
  2775. }
  2776. if (false !== $package && false === strpos($package, ' ')) {
  2777. $validator = function ($input) {
  2778. $input = trim($input);
  2779. return $input ?: false;
  2780. };
  2781. $constraint = $io->askAndValidate(
  2782. 'Enter the version constraint to require (or leave blank to use the latest version): ',
  2783. $validator,
  2784. 3,
  2785. false
  2786. );
  2787. if (false === $constraint) {
  2788. $constraint = $this->findBestVersionForPackage($input, $package);
  2789. $io->writeError(sprintf(
  2790. 'Using version <info>%s</info> for <info>%s</info>',
  2791. $constraint,
  2792. $package
  2793. ));
  2794. }
  2795. $package .= ' '.$constraint;
  2796. }
  2797. if (false !== $package) {
  2798. $requires[] = $package;
  2799. }
  2800. }
  2801. }
  2802. return $requires;
  2803. }
  2804. protected function formatAuthors($author)
  2805. {
  2806. return array($this->parseAuthorString($author));
  2807. }
  2808. protected function formatRequirements(array $requirements)
  2809. {
  2810. $requires = array();
  2811. $requirements = $this->normalizeRequirements($requirements);
  2812. foreach ($requirements as $requirement) {
  2813. $requires[$requirement['name']] = $requirement['version'];
  2814. }
  2815. return $requires;
  2816. }
  2817. protected function getGitConfig()
  2818. {
  2819. if (null !== $this->gitConfig) {
  2820. return $this->gitConfig;
  2821. }
  2822. $finder = new ExecutableFinder();
  2823. $gitBin = $finder->find('git');
  2824. $cmd = new Process(sprintf('%s config -l', ProcessExecutor::escape($gitBin)));
  2825. $cmd->run();
  2826. if ($cmd->isSuccessful()) {
  2827. $this->gitConfig = array();
  2828. preg_match_all('{^([^=]+)=(.*)$}m', $cmd->getOutput(), $matches, PREG_SET_ORDER);
  2829. foreach ($matches as $match) {
  2830. $this->gitConfig[$match[1]] = $match[2];
  2831. }
  2832. return $this->gitConfig;
  2833. }
  2834. return $this->gitConfig = array();
  2835. }
  2836. protected function hasVendorIgnore($ignoreFile, $vendor = 'vendor')
  2837. {
  2838. if (!file_exists($ignoreFile)) {
  2839. return false;
  2840. }
  2841. $pattern = sprintf('{^/?%s(/\*?)?$}', preg_quote($vendor));
  2842. $lines = file($ignoreFile, FILE_IGNORE_NEW_LINES);
  2843. foreach ($lines as $line) {
  2844. if (preg_match($pattern, $line)) {
  2845. return true;
  2846. }
  2847. }
  2848. return false;
  2849. }
  2850. protected function normalizeRequirements(array $requirements)
  2851. {
  2852. $parser = new VersionParser();
  2853. return $parser->parseNameVersionPairs($requirements);
  2854. }
  2855. protected function addVendorIgnore($ignoreFile, $vendor = '/vendor/')
  2856. {
  2857. $contents = "";
  2858. if (file_exists($ignoreFile)) {
  2859. $contents = file_get_contents($ignoreFile);
  2860. if ("\n" !== substr($contents, 0, -1)) {
  2861. $contents .= "\n";
  2862. }
  2863. }
  2864. file_put_contents($ignoreFile, $contents . $vendor. "\n");
  2865. }
  2866. protected function isValidEmail($email)
  2867. {
  2868. if (!function_exists('filter_var')) {
  2869. return true;
  2870. }
  2871. if (PHP_VERSION_ID < 50303) {
  2872. return true;
  2873. }
  2874. return false !== filter_var($email, FILTER_VALIDATE_EMAIL);
  2875. }
  2876. private function getPool(InputInterface $input)
  2877. {
  2878. if (!$this->pool) {
  2879. $this->pool = new Pool($this->getMinimumStability($input));
  2880. $this->pool->addRepository($this->getRepos());
  2881. }
  2882. return $this->pool;
  2883. }
  2884. private function getMinimumStability(InputInterface $input)
  2885. {
  2886. if ($input->hasOption('stability')) {
  2887. return $input->getOption('stability') ?: 'stable';
  2888. }
  2889. $file = Factory::getComposerFile();
  2890. if (is_file($file) && is_readable($file) && is_array($composer = json_decode(file_get_contents($file), true))) {
  2891. if (!empty($composer['minimum-stability'])) {
  2892. return $composer['minimum-stability'];
  2893. }
  2894. }
  2895. return 'stable';
  2896. }
  2897. private function findBestVersionForPackage(InputInterface $input, $name)
  2898. {
  2899. $versionSelector = new VersionSelector($this->getPool($input));
  2900. $package = $versionSelector->findBestCandidate($name);
  2901. if (!$package) {
  2902. throw new \InvalidArgumentException(sprintf(
  2903. 'Could not find package %s at any version for your minimum-stability (%s). Check the package spelling or your minimum-stability',
  2904. $name,
  2905. $this->getMinimumStability($input)
  2906. ));
  2907. }
  2908. return $versionSelector->findRecommendedRequireVersion($package);
  2909. }
  2910. }
  2911. <?php
  2912. namespace Composer\Command;
  2913. use Composer\Installer;
  2914. use Composer\Plugin\CommandEvent;
  2915. use Composer\Plugin\PluginEvents;
  2916. use Symfony\Component\Console\Input\InputInterface;
  2917. use Symfony\Component\Console\Input\InputOption;
  2918. use Symfony\Component\Console\Input\InputArgument;
  2919. use Symfony\Component\Console\Output\OutputInterface;
  2920. class InstallCommand extends Command
  2921. {
  2922. protected function configure()
  2923. {
  2924. $this
  2925. ->setName('install')
  2926. ->setDescription('Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.')
  2927. ->setDefinition(array(
  2928. new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'),
  2929. new InputOption('prefer-dist', null, InputOption::VALUE_NONE, 'Forces installation from package dist even for dev versions.'),
  2930. new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'),
  2931. new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables installation of require-dev packages (enabled by default, only present for BC).'),
  2932. new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables installation of require-dev packages.'),
  2933. new InputOption('no-plugins', null, InputOption::VALUE_NONE, 'Disables all plugins.'),
  2934. new InputOption('no-custom-installers', null, InputOption::VALUE_NONE, 'DEPRECATED: Use no-plugins instead.'),
  2935. new InputOption('no-autoloader', null, InputOption::VALUE_NONE, 'Skips autoloader generation'),
  2936. new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'),
  2937. new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'),
  2938. new InputOption('verbose', 'v|vv|vvv', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'),
  2939. new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump'),
  2940. new InputOption('classmap-authoritative', 'a', InputOption::VALUE_NONE, 'Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.'),
  2941. new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore platform requirements (php & ext- packages).'),
  2942. new InputArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Should not be provided, use composer require instead to add a given package to composer.json.'),
  2943. ))
  2944. ->setHelp(<<<EOT
  2945. The <info>install</info> command reads the composer.lock file from
  2946. the current directory, processes it, and downloads and installs all the
  2947. libraries and dependencies outlined in that file. If the file does not
  2948. exist it will look for composer.json and do the same.
  2949. <info>php composer.phar install</info>
  2950. EOT
  2951. )
  2952. ;
  2953. }
  2954. protected function execute(InputInterface $input, OutputInterface $output)
  2955. {
  2956. $io = $this->getIO();
  2957. if ($args = $input->getArgument('packages')) {
  2958. $io->writeError('<error>Invalid argument '.implode(' ', $args).'. Use "composer require '.implode(' ', $args).'" instead to add packages to your composer.json.</error>');
  2959. return 1;
  2960. }
  2961. if ($input->getOption('no-custom-installers')) {
  2962. $io->writeError('<warning>You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.</warning>');
  2963. $input->setOption('no-plugins', true);
  2964. }
  2965. if ($input->getOption('dev')) {
  2966. $io->writeError('<warning>You are using the deprecated option "dev". Dev packages are installed by default now.</warning>');
  2967. }
  2968. $composer = $this->getComposer(true, $input->getOption('no-plugins'));
  2969. $composer->getDownloadManager()->setOutputProgress(!$input->getOption('no-progress'));
  2970. $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'install', $input, $output);
  2971. $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
  2972. $install = Installer::create($io, $composer);
  2973. $preferSource = false;
  2974. $preferDist = false;
  2975. $config = $composer->getConfig();
  2976. switch ($config->get('preferred-install')) {
  2977. case 'source':
  2978. $preferSource = true;
  2979. break;
  2980. case 'dist':
  2981. $preferDist = true;
  2982. break;
  2983. case 'auto':
  2984. default:
  2985. break;
  2986. }
  2987. if ($input->getOption('prefer-source') || $input->getOption('prefer-dist')) {
  2988. $preferSource = $input->getOption('prefer-source');
  2989. $preferDist = $input->getOption('prefer-dist');
  2990. }
  2991. $optimize = $input->getOption('optimize-autoloader') || $config->get('optimize-autoloader');
  2992. $authoritative = $input->getOption('classmap-authoritative') || $config->get('classmap-authoritative');
  2993. $install
  2994. ->setDryRun($input->getOption('dry-run'))
  2995. ->setVerbose($input->getOption('verbose'))
  2996. ->setPreferSource($preferSource)
  2997. ->setPreferDist($preferDist)
  2998. ->setDevMode(!$input->getOption('no-dev'))
  2999. ->setDumpAutoloader(!$input->getOption('no-autoloader'))
  3000. ->setRunScripts(!$input->getOption('no-scripts'))
  3001. ->setOptimizeAutoloader($optimize)
  3002. ->setClassMapAuthoritative($authoritative)
  3003. ->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs'))
  3004. ;
  3005. if ($input->getOption('no-plugins')) {
  3006. $install->disablePlugins();
  3007. }
  3008. return $install->run();
  3009. }
  3010. }
  3011. <?php
  3012. namespace Composer\Command;
  3013. use Composer\Json\JsonFile;
  3014. use Composer\Plugin\CommandEvent;
  3015. use Composer\Plugin\PluginEvents;
  3016. use Composer\Package\PackageInterface;
  3017. use Composer\Repository\RepositoryInterface;
  3018. use Symfony\Component\Console\Helper\Table;
  3019. use Symfony\Component\Console\Input\InputInterface;
  3020. use Symfony\Component\Console\Input\InputOption;
  3021. use Symfony\Component\Console\Output\OutputInterface;
  3022. class LicensesCommand extends Command
  3023. {
  3024. protected function configure()
  3025. {
  3026. $this
  3027. ->setName('licenses')
  3028. ->setDescription('Show information about licenses of dependencies')
  3029. ->setDefinition(array(
  3030. new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the output: text or json', 'text'),
  3031. new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables search in require-dev packages.'),
  3032. ))
  3033. ->setHelp(<<<EOT
  3034. The license command displays detailed information about the licenses of
  3035. the installed dependencies.
  3036. EOT
  3037. )
  3038. ;
  3039. }
  3040. protected function execute(InputInterface $input, OutputInterface $output)
  3041. {
  3042. $composer = $this->getComposer();
  3043. $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'licenses', $input, $output);
  3044. $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
  3045. $root = $composer->getPackage();
  3046. $repo = $composer->getRepositoryManager()->getLocalRepository();
  3047. if ($input->getOption('no-dev')) {
  3048. $packages = $this->filterRequiredPackages($repo, $root);
  3049. } else {
  3050. $packages = $this->appendPackages($repo->getPackages(), array());
  3051. }
  3052. ksort($packages);
  3053. $io = $this->getIO();
  3054. switch ($format = $input->getOption('format')) {
  3055. case 'text':
  3056. $io->write('Name: <comment>'.$root->getPrettyName().'</comment>');
  3057. $io->write('Version: <comment>'.$root->getFullPrettyVersion().'</comment>');
  3058. $io->write('Licenses: <comment>'.(implode(', ', $root->getLicense()) ?: 'none').'</comment>');
  3059. $io->write('Dependencies:');
  3060. $io->write('');
  3061. $table = new Table($output);
  3062. $table->setStyle('compact');
  3063. $table->getStyle()->setVerticalBorderChar('');
  3064. $table->getStyle()->setCellRowContentFormat('%s ');
  3065. $table->setHeaders(array('Name', 'Version', 'License'));
  3066. foreach ($packages as $package) {
  3067. $table->addRow(array(
  3068. $package->getPrettyName(),
  3069. $package->getFullPrettyVersion(),
  3070. implode(', ', $package->getLicense()) ?: 'none',
  3071. ));
  3072. }
  3073. $table->render();
  3074. break;
  3075. case 'json':
  3076. foreach ($packages as $package) {
  3077. $dependencies[$package->getPrettyName()] = array(
  3078. 'version' => $package->getFullPrettyVersion(),
  3079. 'license' => $package->getLicense(),
  3080. );
  3081. }
  3082. $io->write(JsonFile::encode(array(
  3083. 'name' => $root->getPrettyName(),
  3084. 'version' => $root->getFullPrettyVersion(),
  3085. 'license' => $root->getLicense(),
  3086. 'dependencies' => $dependencies,
  3087. )));
  3088. break;
  3089. default:
  3090. throw new \RuntimeException(sprintf('Unsupported format "%s". See help for supported formats.', $format));
  3091. }
  3092. }
  3093. private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, $bucket = array())
  3094. {
  3095. $requires = array_keys($package->getRequires());
  3096. $packageListNames = array_keys($bucket);
  3097. $packages = array_filter(
  3098. $repo->getPackages(),
  3099. function ($package) use ($requires, $packageListNames) {
  3100. return in_array($package->getName(), $requires) && !in_array($package->getName(), $packageListNames);
  3101. }
  3102. );
  3103. $bucket = $this->appendPackages($packages, $bucket);
  3104. foreach ($packages as $package) {
  3105. $bucket = $this->filterRequiredPackages($repo, $package, $bucket);
  3106. }
  3107. return $bucket;
  3108. }
  3109. public function appendPackages(array $packages, array $bucket)
  3110. {
  3111. foreach ($packages as $package) {
  3112. $bucket[$package->getName()] = $package;
  3113. }
  3114. return $bucket;
  3115. }
  3116. }
  3117. <?php
  3118. namespace Composer\Command;
  3119. use Composer\Config\JsonConfigSource;
  3120. use Composer\Installer;
  3121. use Composer\Plugin\CommandEvent;
  3122. use Composer\Plugin\PluginEvents;
  3123. use Composer\Json\JsonFile;
  3124. use Composer\Factory;
  3125. use Symfony\Component\Console\Input\InputInterface;
  3126. use Symfony\Component\Console\Input\InputOption;
  3127. use Symfony\Component\Console\Input\InputArgument;
  3128. use Symfony\Component\Console\Output\OutputInterface;
  3129. class RemoveCommand extends Command
  3130. {
  3131. protected function configure()
  3132. {
  3133. $this
  3134. ->setName('remove')
  3135. ->setDescription('Removes a package from the require or require-dev')
  3136. ->setDefinition(array(
  3137. new InputArgument('packages', InputArgument::IS_ARRAY, 'Packages that should be removed.'),
  3138. new InputOption('dev', null, InputOption::VALUE_NONE, 'Removes a package from the require-dev section.'),
  3139. new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'),
  3140. new InputOption('no-update', null, InputOption::VALUE_NONE, 'Disables the automatic update of the dependencies.'),
  3141. new InputOption('update-no-dev', null, InputOption::VALUE_NONE, 'Run the dependency update with the --no-dev option.'),
  3142. new InputOption('update-with-dependencies', null, InputOption::VALUE_NONE, 'Allows inherited dependencies to be updated with explicit dependencies.'),
  3143. new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore platform requirements (php & ext- packages).'),
  3144. new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump'),
  3145. new InputOption('classmap-authoritative', 'a', InputOption::VALUE_NONE, 'Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.'),
  3146. ))
  3147. ->setHelp(<<<EOT
  3148. The <info>remove</info> command removes a package from the current
  3149. list of installed packages
  3150. <info>php composer.phar remove</info>
  3151. EOT
  3152. )
  3153. ;
  3154. }
  3155. protected function execute(InputInterface $input, OutputInterface $output)
  3156. {
  3157. $packages = $input->getArgument('packages');
  3158. $file = Factory::getComposerFile();
  3159. $jsonFile = new JsonFile($file);
  3160. $composer = $jsonFile->read();
  3161. $composerBackup = file_get_contents($jsonFile->getPath());
  3162. $json = new JsonConfigSource($jsonFile);
  3163. $type = $input->getOption('dev') ? 'require-dev' : 'require';
  3164. $altType = !$input->getOption('dev') ? 'require-dev' : 'require';
  3165. $io = $this->getIO();
  3166. foreach ($packages as $package) {
  3167. if (isset($composer[$type][$package])) {
  3168. $json->removeLink($type, $package);
  3169. } elseif (isset($composer[$altType][$package])) {
  3170. $io->writeError('<warning>'.$package.' could not be found in '.$type.' but it is present in '.$altType.'</warning>');
  3171. if ($io->isInteractive()) {
  3172. if ($io->askConfirmation('Do you want to remove it from '.$altType.' [<comment>yes</comment>]? ', true)) {
  3173. $json->removeLink($altType, $package);
  3174. }
  3175. }
  3176. } else {
  3177. $io->writeError('<warning>'.$package.' is not required in your composer.json and has not been removed</warning>');
  3178. }
  3179. }
  3180. if ($input->getOption('no-update')) {
  3181. return 0;
  3182. }
  3183. $composer = $this->getComposer();
  3184. $composer->getDownloadManager()->setOutputProgress(!$input->getOption('no-progress'));
  3185. $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'remove', $input, $output);
  3186. $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
  3187. $install = Installer::create($io, $composer);
  3188. $updateDevMode = !$input->getOption('update-no-dev');
  3189. $optimize = $input->getOption('optimize-autoloader') || $composer->getConfig()->get('optimize-autoloader');
  3190. $authoritative = $input->getOption('classmap-authoritative') || $composer->getConfig()->get('classmap-authoritative');
  3191. $install
  3192. ->setVerbose($input->getOption('verbose'))
  3193. ->setDevMode($updateDevMode)
  3194. ->setOptimizeAutoloader($optimize)
  3195. ->setClassMapAuthoritative($authoritative)
  3196. ->setUpdate(true)
  3197. ->setUpdateWhitelist($packages)
  3198. ->setWhitelistDependencies($input->getOption('update-with-dependencies'))
  3199. ->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs'))
  3200. ;
  3201. $status = $install->run();
  3202. if ($status !== 0) {
  3203. $io->writeError("\n".'<error>Removal failed, reverting '.$file.' to its original content.</error>');
  3204. file_put_contents($jsonFile->getPath(), $composerBackup);
  3205. }
  3206. return $status;
  3207. }
  3208. }
  3209. <?php
  3210. namespace Composer\Command;
  3211. use Symfony\Component\Console\Input\InputInterface;
  3212. use Symfony\Component\Console\Input\InputArgument;
  3213. use Symfony\Component\Console\Input\InputOption;
  3214. use Symfony\Component\Console\Output\OutputInterface;
  3215. use Composer\Factory;
  3216. use Composer\Installer;
  3217. use Composer\Json\JsonFile;
  3218. use Composer\Json\JsonManipulator;
  3219. use Composer\Semver\VersionParser;
  3220. use Composer\Plugin\CommandEvent;
  3221. use Composer\Plugin\PluginEvents;
  3222. use Composer\Repository\CompositeRepository;
  3223. use Composer\Repository\PlatformRepository;
  3224. class RequireCommand extends InitCommand
  3225. {
  3226. protected function configure()
  3227. {
  3228. $this
  3229. ->setName('require')
  3230. ->setDescription('Adds required packages to your composer.json and installs them')
  3231. ->setDefinition(array(
  3232. new InputArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Required package name optionally including a version constraint, e.g. foo/bar or foo/bar:1.0.0 or foo/bar=1.0.0 or "foo/bar 1.0.0"'),
  3233. new InputOption('dev', null, InputOption::VALUE_NONE, 'Add requirement to require-dev.'),
  3234. new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'),
  3235. new InputOption('prefer-dist', null, InputOption::VALUE_NONE, 'Forces installation from package dist even for dev versions.'),
  3236. new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'),
  3237. new InputOption('no-update', null, InputOption::VALUE_NONE, 'Disables the automatic update of the dependencies.'),
  3238. new InputOption('update-no-dev', null, InputOption::VALUE_NONE, 'Run the dependency update with the --no-dev option.'),
  3239. new InputOption('update-with-dependencies', null, InputOption::VALUE_NONE, 'Allows inherited dependencies to be updated with explicit dependencies.'),
  3240. new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore platform requirements (php & ext- packages).'),
  3241. new InputOption('sort-packages', null, InputOption::VALUE_NONE, 'Sorts packages when adding/updating a new dependency'),
  3242. new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump'),
  3243. new InputOption('classmap-authoritative', 'a', InputOption::VALUE_NONE, 'Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.'),
  3244. ))
  3245. ->setHelp(<<<EOT
  3246. The require command adds required packages to your composer.json and installs them.
  3247. If you do not specify a version constraint, composer will choose a suitable one based on the available package versions.
  3248. If you do not want to install the new dependencies immediately you can call it with --no-update
  3249. EOT
  3250. )
  3251. ;
  3252. }
  3253. protected function execute(InputInterface $input, OutputInterface $output)
  3254. {
  3255. $file = Factory::getComposerFile();
  3256. $io = $this->getIO();
  3257. $newlyCreated = !file_exists($file);
  3258. if (!file_exists($file) && !file_put_contents($file, "{\n}\n")) {
  3259. $io->writeError('<error>'.$file.' could not be created.</error>');
  3260. return 1;
  3261. }
  3262. if (!is_readable($file)) {
  3263. $io->writeError('<error>'.$file.' is not readable.</error>');
  3264. return 1;
  3265. }
  3266. if (!is_writable($file)) {
  3267. $io->writeError('<error>'.$file.' is not writable.</error>');
  3268. return 1;
  3269. }
  3270. if (filesize($file) === 0) {
  3271. file_put_contents($file, "{\n}\n");
  3272. }
  3273. $json = new JsonFile($file);
  3274. $composerDefinition = $json->read();
  3275. $composerBackup = file_get_contents($json->getPath());
  3276. $composer = $this->getComposer();
  3277. $repos = $composer->getRepositoryManager()->getRepositories();
  3278. $this->repos = new CompositeRepository(array_merge(
  3279. array(new PlatformRepository),
  3280. $repos
  3281. ));
  3282. $requirements = $this->determineRequirements($input, $output, $input->getArgument('packages'));
  3283. $requireKey = $input->getOption('dev') ? 'require-dev' : 'require';
  3284. $removeKey = $input->getOption('dev') ? 'require' : 'require-dev';
  3285. $baseRequirements = array_key_exists($requireKey, $composerDefinition) ? $composerDefinition[$requireKey] : array();
  3286. $requirements = $this->formatRequirements($requirements);
  3287. $versionParser = new VersionParser();
  3288. foreach ($requirements as $constraint) {
  3289. $versionParser->parseConstraints($constraint);
  3290. }
  3291. $sortPackages = $input->getOption('sort-packages');
  3292. if (!$this->updateFileCleanly($json, $baseRequirements, $requirements, $requireKey, $removeKey, $sortPackages)) {
  3293. foreach ($requirements as $package => $version) {
  3294. $baseRequirements[$package] = $version;
  3295. if (isset($composerDefinition[$removeKey][$package])) {
  3296. unset($composerDefinition[$removeKey][$package]);
  3297. }
  3298. }
  3299. $composerDefinition[$requireKey] = $baseRequirements;
  3300. $json->write($composerDefinition);
  3301. }
  3302. $io->writeError('<info>'.$file.' has been '.($newlyCreated ? 'created' : 'updated').'</info>');
  3303. if ($input->getOption('no-update')) {
  3304. return 0;
  3305. }
  3306. $updateDevMode = !$input->getOption('update-no-dev');
  3307. $optimize = $input->getOption('optimize-autoloader') || $composer->getConfig()->get('optimize-autoloader');
  3308. $authoritative = $input->getOption('classmap-authoritative') || $composer->getConfig()->get('classmap-authoritative');
  3309. $this->resetComposer();
  3310. $composer = $this->getComposer();
  3311. $composer->getDownloadManager()->setOutputProgress(!$input->getOption('no-progress'));
  3312. $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'require', $input, $output);
  3313. $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
  3314. $install = Installer::create($io, $composer);
  3315. $install
  3316. ->setVerbose($input->getOption('verbose'))
  3317. ->setPreferSource($input->getOption('prefer-source'))
  3318. ->setPreferDist($input->getOption('prefer-dist'))
  3319. ->setDevMode($updateDevMode)
  3320. ->setOptimizeAutoloader($optimize)
  3321. ->setClassMapAuthoritative($authoritative)
  3322. ->setUpdate(true)
  3323. ->setUpdateWhitelist(array_keys($requirements))
  3324. ->setWhitelistDependencies($input->getOption('update-with-dependencies'))
  3325. ->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs'))
  3326. ;
  3327. $status = $install->run();
  3328. if ($status !== 0) {
  3329. if ($newlyCreated) {
  3330. $io->writeError("\n".'<error>Installation failed, deleting '.$file.'.</error>');
  3331. unlink($json->getPath());
  3332. } else {
  3333. $io->writeError("\n".'<error>Installation failed, reverting '.$file.' to its original content.</error>');
  3334. file_put_contents($json->getPath(), $composerBackup);
  3335. }
  3336. }
  3337. return $status;
  3338. }
  3339. private function updateFileCleanly($json, array $base, array $new, $requireKey, $removeKey, $sortPackages)
  3340. {
  3341. $contents = file_get_contents($json->getPath());
  3342. $manipulator = new JsonManipulator($contents);
  3343. foreach ($new as $package => $constraint) {
  3344. if (!$manipulator->addLink($requireKey, $package, $constraint, $sortPackages)) {
  3345. return false;
  3346. }
  3347. if (!$manipulator->removeSubNode($removeKey, $package)) {
  3348. return false;
  3349. }
  3350. }
  3351. file_put_contents($json->getPath(), $manipulator->getContents());
  3352. return true;
  3353. }
  3354. protected function interact(InputInterface $input, OutputInterface $output)
  3355. {
  3356. return;
  3357. }
  3358. }
  3359. <?php
  3360. namespace Composer\Command;
  3361. use Composer\Script\CommandEvent;
  3362. use Composer\Script\ScriptEvents;
  3363. use Symfony\Component\Console\Input\InputInterface;
  3364. use Symfony\Component\Console\Input\InputOption;
  3365. use Symfony\Component\Console\Input\InputArgument;
  3366. use Symfony\Component\Console\Output\OutputInterface;
  3367. class RunScriptCommand extends Command
  3368. {
  3369. protected $scriptEvents = array(
  3370. ScriptEvents::PRE_INSTALL_CMD,
  3371. ScriptEvents::POST_INSTALL_CMD,
  3372. ScriptEvents::PRE_UPDATE_CMD,
  3373. ScriptEvents::POST_UPDATE_CMD,
  3374. ScriptEvents::PRE_STATUS_CMD,
  3375. ScriptEvents::POST_STATUS_CMD,
  3376. ScriptEvents::POST_ROOT_PACKAGE_INSTALL,
  3377. ScriptEvents::POST_CREATE_PROJECT_CMD,
  3378. ScriptEvents::PRE_ARCHIVE_CMD,
  3379. ScriptEvents::POST_ARCHIVE_CMD,
  3380. ScriptEvents::PRE_AUTOLOAD_DUMP,
  3381. ScriptEvents::POST_AUTOLOAD_DUMP,
  3382. );
  3383. protected function configure()
  3384. {
  3385. $this
  3386. ->setName('run-script')
  3387. ->setDescription('Run the scripts defined in composer.json.')
  3388. ->setDefinition(array(
  3389. new InputArgument('script', InputArgument::OPTIONAL, 'Script name to run.'),
  3390. new InputArgument('args', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, ''),
  3391. new InputOption('dev', null, InputOption::VALUE_NONE, 'Sets the dev mode.'),
  3392. new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables the dev mode.'),
  3393. new InputOption('list', 'l', InputOption::VALUE_NONE, 'List scripts.'),
  3394. ))
  3395. ->setHelp(<<<EOT
  3396. The <info>run-script</info> command runs scripts defined in composer.json:
  3397. <info>php composer.phar run-script post-update-cmd</info>
  3398. EOT
  3399. )
  3400. ;
  3401. }
  3402. protected function execute(InputInterface $input, OutputInterface $output)
  3403. {
  3404. if ($input->getOption('list')) {
  3405. return $this->listScripts();
  3406. } elseif (!$input->getArgument('script')) {
  3407. throw new \RunTimeException('Missing required argument "script"');
  3408. }
  3409. $script = $input->getArgument('script');
  3410. if (!in_array($script, $this->scriptEvents)) {
  3411. if (defined('Composer\Script\ScriptEvents::'.str_replace('-', '_', strtoupper($script)))) {
  3412. throw new \InvalidArgumentException(sprintf('Script "%s" cannot be run with this command', $script));
  3413. }
  3414. }
  3415. $composer = $this->getComposer();
  3416. $hasListeners = $composer->getEventDispatcher()->hasEventListeners(new CommandEvent($script, $composer, $this->getIO()));
  3417. if (!$hasListeners) {
  3418. throw new \InvalidArgumentException(sprintf('Script "%s" is not defined in this package', $script));
  3419. }
  3420. $binDir = $composer->getConfig()->get('bin-dir');
  3421. if (is_dir($binDir)) {
  3422. $_SERVER['PATH'] = realpath($binDir).PATH_SEPARATOR.getenv('PATH');
  3423. putenv('PATH='.$_SERVER['PATH']);
  3424. }
  3425. $args = $input->getArgument('args');
  3426. return $composer->getEventDispatcher()->dispatchScript($script, $input->getOption('dev') || !$input->getOption('no-dev'), $args);
  3427. }
  3428. protected function listScripts()
  3429. {
  3430. $scripts = $this->getComposer()->getPackage()->getScripts();
  3431. if (!count($scripts)) {
  3432. return 0;
  3433. }
  3434. $io = $this->getIO();
  3435. $io->writeError('<info>scripts:</info>');
  3436. foreach ($scripts as $name => $script) {
  3437. $io->write(' ' . $name);
  3438. }
  3439. return 0;
  3440. }
  3441. }
  3442. <?php
  3443. namespace Composer\Command;
  3444. use Symfony\Component\Console\Input\InputInterface;
  3445. use Symfony\Component\Console\Input\InputOption;
  3446. use Symfony\Component\Console\Input\InputArgument;
  3447. use Symfony\Component\Console\Output\OutputInterface;
  3448. class ScriptAliasCommand extends Command
  3449. {
  3450. private $script;
  3451. public function __construct($script)
  3452. {
  3453. $this->script = $script;
  3454. parent::__construct();
  3455. }
  3456. protected function configure()
  3457. {
  3458. $this
  3459. ->setName($this->script)
  3460. ->setDescription('Run the '.$this->script.' script as defined in composer.json.')
  3461. ->setDefinition(array(
  3462. new InputOption('dev', null, InputOption::VALUE_NONE, 'Sets the dev mode.'),
  3463. new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables the dev mode.'),
  3464. new InputArgument('args', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, ''),
  3465. ))
  3466. ->setHelp(<<<EOT
  3467. The <info>run-script</info> command runs scripts defined in composer.json:
  3468. <info>php composer.phar run-script post-update-cmd</info>
  3469. EOT
  3470. )
  3471. ;
  3472. }
  3473. protected function execute(InputInterface $input, OutputInterface $output)
  3474. {
  3475. $composer = $this->getComposer();
  3476. $binDir = $composer->getConfig()->get('bin-dir');
  3477. if (is_dir($binDir)) {
  3478. $_SERVER['PATH'] = realpath($binDir).PATH_SEPARATOR.getenv('PATH');
  3479. putenv('PATH='.$_SERVER['PATH']);
  3480. }
  3481. $args = $input->getArguments();
  3482. return $composer->getEventDispatcher()->dispatchScript($this->script, $input->getOption('dev') || !$input->getOption('no-dev'), $args['args']);
  3483. }
  3484. }
  3485. <?php
  3486. namespace Composer\Command;
  3487. use Symfony\Component\Console\Input\InputInterface;
  3488. use Symfony\Component\Console\Input\InputArgument;
  3489. use Symfony\Component\Console\Input\InputOption;
  3490. use Symfony\Component\Console\Output\OutputInterface;
  3491. use Composer\Repository\CompositeRepository;
  3492. use Composer\Repository\PlatformRepository;
  3493. use Composer\Repository\RepositoryInterface;
  3494. use Composer\Factory;
  3495. use Composer\Plugin\CommandEvent;
  3496. use Composer\Plugin\PluginEvents;
  3497. class SearchCommand extends Command
  3498. {
  3499. protected $matches;
  3500. protected $lowMatches = array();
  3501. protected $tokens;
  3502. protected $output;
  3503. protected $onlyName;
  3504. protected function configure()
  3505. {
  3506. $this
  3507. ->setName('search')
  3508. ->setDescription('Search for packages')
  3509. ->setDefinition(array(
  3510. new InputOption('only-name', 'N', InputOption::VALUE_NONE, 'Search only in name'),
  3511. new InputArgument('tokens', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'tokens to search for'),
  3512. ))
  3513. ->setHelp(<<<EOT
  3514. The search command searches for packages by its name
  3515. <info>php composer.phar search symfony composer</info>
  3516. EOT
  3517. )
  3518. ;
  3519. }
  3520. protected function execute(InputInterface $input, OutputInterface $output)
  3521. {
  3522. $platformRepo = new PlatformRepository;
  3523. $io = $this->getIO();
  3524. if ($composer = $this->getComposer(false)) {
  3525. $localRepo = $composer->getRepositoryManager()->getLocalRepository();
  3526. $installedRepo = new CompositeRepository(array($localRepo, $platformRepo));
  3527. $repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
  3528. } else {
  3529. $defaultRepos = Factory::createDefaultRepositories($io);
  3530. $io->writeError('No composer.json found in the current directory, showing packages from ' . implode(', ', array_keys($defaultRepos)));
  3531. $installedRepo = $platformRepo;
  3532. $repos = new CompositeRepository(array_merge(array($installedRepo), $defaultRepos));
  3533. }
  3534. if ($composer) {
  3535. $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'search', $input, $output);
  3536. $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
  3537. }
  3538. $onlyName = $input->getOption('only-name');
  3539. $flags = $onlyName ? RepositoryInterface::SEARCH_NAME : RepositoryInterface::SEARCH_FULLTEXT;
  3540. $results = $repos->search(implode(' ', $input->getArgument('tokens')), $flags);
  3541. foreach ($results as $result) {
  3542. $io->write($result['name'] . (isset($result['description']) ? ' '. $result['description'] : ''));
  3543. }
  3544. }
  3545. }
  3546. <?php
  3547. namespace Composer\Command;
  3548. use Composer\Composer;
  3549. use Composer\Factory;
  3550. use Composer\Util\Filesystem;
  3551. use Composer\Util\RemoteFilesystem;
  3552. use Composer\Downloader\FilesystemException;
  3553. use Symfony\Component\Console\Input\InputInterface;
  3554. use Symfony\Component\Console\Input\InputOption;
  3555. use Symfony\Component\Console\Input\InputArgument;
  3556. use Symfony\Component\Console\Output\OutputInterface;
  3557. use Symfony\Component\Finder\Finder;
  3558. class SelfUpdateCommand extends Command
  3559. {
  3560. const HOMEPAGE = 'getcomposer.org';
  3561. const OLD_INSTALL_EXT = '-old.phar';
  3562. protected function configure()
  3563. {
  3564. $this
  3565. ->setName('self-update')
  3566. ->setAliases(array('selfupdate'))
  3567. ->setDescription('Updates composer.phar to the latest version.')
  3568. ->setDefinition(array(
  3569. new InputOption('rollback', 'r', InputOption::VALUE_NONE, 'Revert to an older installation of composer'),
  3570. new InputOption('clean-backups', null, InputOption::VALUE_NONE, 'Delete old backups during an update. This makes the current version of composer the only backup available after the update'),
  3571. new InputArgument('version', InputArgument::OPTIONAL, 'The version to update to'),
  3572. new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'),
  3573. ))
  3574. ->setHelp(<<<EOT
  3575. The <info>self-update</info> command checks getcomposer.org for newer
  3576. versions of composer and if found, installs the latest.
  3577. <info>php composer.phar self-update</info>
  3578. EOT
  3579. )
  3580. ;
  3581. }
  3582. protected function execute(InputInterface $input, OutputInterface $output)
  3583. {
  3584. $baseUrl = (extension_loaded('openssl') ? 'https' : 'http') . '://' . self::HOMEPAGE;
  3585. $config = Factory::createConfig();
  3586. $io = $this->getIO();
  3587. $remoteFilesystem = new RemoteFilesystem($io, $config);
  3588. $cacheDir = $config->get('cache-dir');
  3589. $rollbackDir = $config->get('home');
  3590. $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
  3591. $tmpDir = is_writable(dirname($localFilename)) ? dirname($localFilename) : $cacheDir;
  3592. if (!is_writable($tmpDir)) {
  3593. throw new FilesystemException('Composer update failed: the "'.$tmpDir.'" directory used to download the temp file could not be written');
  3594. }
  3595. if (!is_writable($localFilename)) {
  3596. throw new FilesystemException('Composer update failed: the "'.$localFilename.'" file could not be written');
  3597. }
  3598. if ($input->getOption('rollback')) {
  3599. return $this->rollback($output, $rollbackDir, $localFilename);
  3600. }
  3601. $latestVersion = trim($remoteFilesystem->getContents(self::HOMEPAGE, $baseUrl. '/version', false));
  3602. $updateVersion = $input->getArgument('version') ?: $latestVersion;
  3603. if (preg_match('{^[0-9a-f]{40}$}', $updateVersion) && $updateVersion !== $latestVersion) {
  3604. $io->writeError('<error>You can not update to a specific SHA-1 as those phars are not available for download</error>');
  3605. return 1;
  3606. }
  3607. if (Composer::VERSION === $updateVersion) {
  3608. $io->writeError('<info>You are already using composer version '.$updateVersion.'.</info>');
  3609. return 0;
  3610. }
  3611. $tempFilename = $tmpDir . '/' . basename($localFilename, '.phar').'-temp.phar';
  3612. $backupFile = sprintf(
  3613. '%s/%s-%s%s',
  3614. $rollbackDir,
  3615. strtr(Composer::RELEASE_DATE, ' :', '_-'),
  3616. preg_replace('{^([0-9a-f]{7})[0-9a-f]{33}$}', '$1', Composer::VERSION),
  3617. self::OLD_INSTALL_EXT
  3618. );
  3619. $io->writeError(sprintf("Updating to version <info>%s</info>.", $updateVersion));
  3620. $remoteFilename = $baseUrl . (preg_match('{^[0-9a-f]{40}$}', $updateVersion) ? '/composer.phar' : "/download/{$updateVersion}/composer.phar");
  3621. $remoteFilesystem->copy(self::HOMEPAGE, $remoteFilename, $tempFilename, !$input->getOption('no-progress'));
  3622. if (!file_exists($tempFilename)) {
  3623. $io->writeError('<error>The download of the new composer version failed for an unexpected reason</error>');
  3624. return 1;
  3625. }
  3626. if ($input->getOption('clean-backups')) {
  3627. $finder = $this->getOldInstallationFinder($rollbackDir);
  3628. $fs = new Filesystem;
  3629. foreach ($finder as $file) {
  3630. $file = (string) $file;
  3631. $io->writeError('<info>Removing: '.$file.'</info>');
  3632. $fs->remove($file);
  3633. }
  3634. }
  3635. if ($err = $this->setLocalPhar($localFilename, $tempFilename, $backupFile)) {
  3636. $io->writeError('<error>The file is corrupted ('.$err->getMessage().').</error>');
  3637. $io->writeError('<error>Please re-run the self-update command to try again.</error>');
  3638. return 1;
  3639. }
  3640. if (file_exists($backupFile)) {
  3641. $io->writeError('Use <info>composer self-update --rollback</info> to return to version '.Composer::VERSION);
  3642. } else {
  3643. $io->writeError('<warning>A backup of the current version could not be written to '.$backupFile.', no rollback possible</warning>');
  3644. }
  3645. }
  3646. protected function rollback(OutputInterface $output, $rollbackDir, $localFilename)
  3647. {
  3648. $rollbackVersion = $this->getLastBackupVersion($rollbackDir);
  3649. if (!$rollbackVersion) {
  3650. throw new \UnexpectedValueException('Composer rollback failed: no installation to roll back to in "'.$rollbackDir.'"');
  3651. }
  3652. if (!is_writable($rollbackDir)) {
  3653. throw new FilesystemException('Composer rollback failed: the "'.$rollbackDir.'" dir could not be written to');
  3654. }
  3655. $old = $rollbackDir . '/' . $rollbackVersion . self::OLD_INSTALL_EXT;
  3656. if (!is_file($old)) {
  3657. throw new FilesystemException('Composer rollback failed: "'.$old.'" could not be found');
  3658. }
  3659. if (!is_readable($old)) {
  3660. throw new FilesystemException('Composer rollback failed: "'.$old.'" could not be read');
  3661. }
  3662. $oldFile = $rollbackDir . "/{$rollbackVersion}" . self::OLD_INSTALL_EXT;
  3663. $io = $this->getIO();
  3664. $io->writeError(sprintf("Rolling back to version <info>%s</info>.", $rollbackVersion));
  3665. if ($err = $this->setLocalPhar($localFilename, $oldFile)) {
  3666. $io->writeError('<error>The backup file was corrupted ('.$err->getMessage().') and has been removed.</error>');
  3667. return 1;
  3668. }
  3669. return 0;
  3670. }
  3671. protected function setLocalPhar($localFilename, $newFilename, $backupTarget = null)
  3672. {
  3673. try {
  3674. @chmod($newFilename, fileperms($localFilename));
  3675. if (!ini_get('phar.readonly')) {
  3676. $phar = new \Phar($newFilename);
  3677. unset($phar);
  3678. }
  3679. if ($backupTarget && file_exists($localFilename)) {
  3680. @copy($localFilename, $backupTarget);
  3681. }
  3682. rename($newFilename, $localFilename);
  3683. } catch (\Exception $e) {
  3684. if ($backupTarget) {
  3685. @unlink($newFilename);
  3686. }
  3687. if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) {
  3688. throw $e;
  3689. }
  3690. return $e;
  3691. }
  3692. }
  3693. protected function getLastBackupVersion($rollbackDir)
  3694. {
  3695. $finder = $this->getOldInstallationFinder($rollbackDir);
  3696. $finder->sortByName();
  3697. $files = iterator_to_array($finder);
  3698. if (count($files)) {
  3699. return basename(end($files), self::OLD_INSTALL_EXT);
  3700. }
  3701. return false;
  3702. }
  3703. protected function getOldInstallationFinder($rollbackDir)
  3704. {
  3705. $finder = Finder::create()
  3706. ->depth(0)
  3707. ->files()
  3708. ->name('*' . self::OLD_INSTALL_EXT)
  3709. ->in($rollbackDir);
  3710. return $finder;
  3711. }
  3712. }
  3713. <?php
  3714. namespace Composer\Command;
  3715. use Composer\DependencyResolver\Pool;
  3716. use Composer\DependencyResolver\DefaultPolicy;
  3717. use Composer\Factory;
  3718. use Composer\Package\CompletePackageInterface;
  3719. use Composer\Semver\VersionParser;
  3720. use Composer\Plugin\CommandEvent;
  3721. use Composer\Plugin\PluginEvents;
  3722. use Symfony\Component\Console\Input\InputInterface;
  3723. use Symfony\Component\Console\Input\InputArgument;
  3724. use Symfony\Component\Console\Input\InputOption;
  3725. use Symfony\Component\Console\Output\OutputInterface;
  3726. use Composer\Repository\ArrayRepository;
  3727. use Composer\Repository\CompositeRepository;
  3728. use Composer\Repository\ComposerRepository;
  3729. use Composer\Repository\PlatformRepository;
  3730. use Composer\Repository\RepositoryInterface;
  3731. use Composer\Spdx\SpdxLicenses;
  3732. class ShowCommand extends Command
  3733. {
  3734. protected $versionParser;
  3735. protected function configure()
  3736. {
  3737. $this
  3738. ->setName('show')
  3739. ->setAliases(array('info'))
  3740. ->setDescription('Show information about packages')
  3741. ->setDefinition(array(
  3742. new InputArgument('package', InputArgument::OPTIONAL, 'Package to inspect'),
  3743. new InputArgument('version', InputArgument::OPTIONAL, 'Version or version constraint to inspect'),
  3744. new InputOption('installed', 'i', InputOption::VALUE_NONE, 'List installed packages only'),
  3745. new InputOption('platform', 'p', InputOption::VALUE_NONE, 'List platform packages only'),
  3746. new InputOption('available', 'a', InputOption::VALUE_NONE, 'List available packages only'),
  3747. new InputOption('self', 's', InputOption::VALUE_NONE, 'Show the root package information'),
  3748. new InputOption('name-only', 'N', InputOption::VALUE_NONE, 'List package names only'),
  3749. new InputOption('path', 'P', InputOption::VALUE_NONE, 'Show package paths'),
  3750. ))
  3751. ->setHelp(<<<EOT
  3752. The show command displays detailed information about a package, or
  3753. lists all packages available.
  3754. EOT
  3755. )
  3756. ;
  3757. }
  3758. protected function execute(InputInterface $input, OutputInterface $output)
  3759. {
  3760. $this->versionParser = new VersionParser;
  3761. $platformRepo = new PlatformRepository;
  3762. $composer = $this->getComposer(false);
  3763. $io = $this->getIO();
  3764. if ($input->getOption('self')) {
  3765. $package = $this->getComposer()->getPackage();
  3766. $repos = $installedRepo = new ArrayRepository(array($package));
  3767. } elseif ($input->getOption('platform')) {
  3768. $repos = $installedRepo = $platformRepo;
  3769. } elseif ($input->getOption('installed')) {
  3770. $repos = $installedRepo = $this->getComposer()->getRepositoryManager()->getLocalRepository();
  3771. } elseif ($input->getOption('available')) {
  3772. $installedRepo = $platformRepo;
  3773. if ($composer) {
  3774. $repos = new CompositeRepository($composer->getRepositoryManager()->getRepositories());
  3775. } else {
  3776. $defaultRepos = Factory::createDefaultRepositories($io);
  3777. $repos = new CompositeRepository($defaultRepos);
  3778. $io->writeError('No composer.json found in the current directory, showing available packages from ' . implode(', ', array_keys($defaultRepos)));
  3779. }
  3780. } elseif ($composer) {
  3781. $localRepo = $composer->getRepositoryManager()->getLocalRepository();
  3782. $installedRepo = new CompositeRepository(array($localRepo, $platformRepo));
  3783. $repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
  3784. } else {
  3785. $defaultRepos = Factory::createDefaultRepositories($io);
  3786. $io->writeError('No composer.json found in the current directory, showing available packages from ' . implode(', ', array_keys($defaultRepos)));
  3787. $installedRepo = $platformRepo;
  3788. $repos = new CompositeRepository(array_merge(array($installedRepo), $defaultRepos));
  3789. }
  3790. if ($composer) {
  3791. $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'show', $input, $output);
  3792. $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
  3793. }
  3794. if ($input->getArgument('package') || !empty($package)) {
  3795. $versions = array();
  3796. if (empty($package)) {
  3797. list($package, $versions) = $this->getPackage($installedRepo, $repos, $input->getArgument('package'), $input->getArgument('version'));
  3798. if (!$package) {
  3799. throw new \InvalidArgumentException('Package '.$input->getArgument('package').' not found');
  3800. }
  3801. } else {
  3802. $versions = array($package->getPrettyVersion() => $package->getVersion());
  3803. }
  3804. $this->printMeta($package, $versions, $installedRepo);
  3805. $this->printLinks($package, 'requires');
  3806. $this->printLinks($package, 'devRequires', 'requires (dev)');
  3807. if ($package->getSuggests()) {
  3808. $io->write("\n<info>suggests</info>");
  3809. foreach ($package->getSuggests() as $suggested => $reason) {
  3810. $io->write($suggested . ' <comment>' . $reason . '</comment>');
  3811. }
  3812. }
  3813. $this->printLinks($package, 'provides');
  3814. $this->printLinks($package, 'conflicts');
  3815. $this->printLinks($package, 'replaces');
  3816. return;
  3817. }
  3818. $packages = array();
  3819. if ($repos instanceof CompositeRepository) {
  3820. $repos = $repos->getRepositories();
  3821. } elseif (!is_array($repos)) {
  3822. $repos = array($repos);
  3823. }
  3824. foreach ($repos as $repo) {
  3825. if ($repo === $platformRepo) {
  3826. $type = '<info>platform</info>:';
  3827. } elseif (
  3828. $repo === $installedRepo
  3829. || ($installedRepo instanceof CompositeRepository && in_array($repo, $installedRepo->getRepositories(), true))
  3830. ) {
  3831. $type = '<info>installed</info>:';
  3832. } else {
  3833. $type = '<comment>available</comment>:';
  3834. }
  3835. if ($repo instanceof ComposerRepository && $repo->hasProviders()) {
  3836. foreach ($repo->getProviderNames() as $name) {
  3837. $packages[$type][$name] = $name;
  3838. }
  3839. } else {
  3840. foreach ($repo->getPackages() as $package) {
  3841. if (!isset($packages[$type][$package->getName()])
  3842. || !is_object($packages[$type][$package->getName()])
  3843. || version_compare($packages[$type][$package->getName()]->getVersion(), $package->getVersion(), '<')
  3844. ) {
  3845. $packages[$type][$package->getName()] = $package;
  3846. }
  3847. }
  3848. }
  3849. }
  3850. $tree = !$input->getOption('platform') && !$input->getOption('installed') && !$input->getOption('available');
  3851. $indent = $tree ? ' ' : '';
  3852. foreach (array('<info>platform</info>:' => true, '<comment>available</comment>:' => false, '<info>installed</info>:' => true) as $type => $showVersion) {
  3853. if (isset($packages[$type])) {
  3854. if ($tree) {
  3855. $io->write($type);
  3856. }
  3857. ksort($packages[$type]);
  3858. $nameLength = $versionLength = 0;
  3859. foreach ($packages[$type] as $package) {
  3860. if (is_object($package)) {
  3861. $nameLength = max($nameLength, strlen($package->getPrettyName()));
  3862. $versionLength = max($versionLength, strlen($package->getFullPrettyVersion()));
  3863. } else {
  3864. $nameLength = max($nameLength, $package);
  3865. }
  3866. }
  3867. list($width) = $this->getApplication()->getTerminalDimensions();
  3868. if (null === $width) {
  3869. $width = PHP_INT_MAX;
  3870. }
  3871. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  3872. $width--;
  3873. }
  3874. if ($input->getOption('path') && null === $composer) {
  3875. $io->writeError('No composer.json found in the current directory, disabling "path" option');
  3876. $input->setOption('path', false);
  3877. }
  3878. $writePath = !$input->getOption('name-only') && $input->getOption('path');
  3879. $writeVersion = !$input->getOption('name-only') && !$input->getOption('path') && $showVersion && ($nameLength + $versionLength + 3 <= $width);
  3880. $writeDescription = !$input->getOption('name-only') && !$input->getOption('path') && ($nameLength + ($showVersion ? $versionLength : 0) + 24 <= $width);
  3881. foreach ($packages[$type] as $package) {
  3882. if (is_object($package)) {
  3883. $output->write($indent . str_pad($package->getPrettyName(), $nameLength, ' '), false);
  3884. if ($writeVersion) {
  3885. $output->write(' ' . str_pad($package->getFullPrettyVersion(), $versionLength, ' '), false);
  3886. }
  3887. if ($writeDescription) {
  3888. $description = strtok($package->getDescription(), "\r\n");
  3889. $remaining = $width - $nameLength - $versionLength - 4;
  3890. if (strlen($description) > $remaining) {
  3891. $description = substr($description, 0, $remaining - 3) . '...';
  3892. }
  3893. $output->write(' ' . $description);
  3894. }
  3895. if ($writePath) {
  3896. $path = strtok(realpath($composer->getInstallationManager()->getInstallPath($package)), "\r\n");
  3897. $output->write(' ' . $path);
  3898. }
  3899. } else {
  3900. $output->write($indent . $package);
  3901. }
  3902. $io->write('');
  3903. }
  3904. if ($tree) {
  3905. $io->write('');
  3906. }
  3907. }
  3908. }
  3909. }
  3910. protected function getPackage(RepositoryInterface $installedRepo, RepositoryInterface $repos, $name, $version = null)
  3911. {
  3912. $name = strtolower($name);
  3913. $constraint = null;
  3914. if ($version) {
  3915. $constraint = $this->versionParser->parseConstraints($version);
  3916. }
  3917. $policy = new DefaultPolicy();
  3918. $pool = new Pool('dev');
  3919. $pool->addRepository($repos);
  3920. $matchedPackage = null;
  3921. $versions = array();
  3922. $matches = $pool->whatProvides($name, $constraint);
  3923. foreach ($matches as $index => $package) {
  3924. if ($package->getName() !== $name) {
  3925. unset($matches[$index]);
  3926. continue;
  3927. }
  3928. if (null === $version && $installedRepo->hasPackage($package)) {
  3929. $matchedPackage = $package;
  3930. }
  3931. $versions[$package->getPrettyVersion()] = $package->getVersion();
  3932. $matches[$index] = $package->getId();
  3933. }
  3934. if (!$matchedPackage && $matches && $preferred = $policy->selectPreferredPackages($pool, array(), $matches)) {
  3935. $matchedPackage = $pool->literalToPackage($preferred[0]);
  3936. }
  3937. return array($matchedPackage, $versions);
  3938. }
  3939. protected function printMeta(CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo)
  3940. {
  3941. $io = $this->getIO();
  3942. $io->write('<info>name</info> : ' . $package->getPrettyName());
  3943. $io->write('<info>descrip.</info> : ' . $package->getDescription());
  3944. $io->write('<info>keywords</info> : ' . join(', ', $package->getKeywords() ?: array()));
  3945. $this->printVersions($package, $versions, $installedRepo);
  3946. $io->write('<info>type</info> : ' . $package->getType());
  3947. $this->printLicenses($package);
  3948. $io->write('<info>source</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference()));
  3949. $io->write('<info>dist</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getDistType(), $package->getDistUrl(), $package->getDistReference()));
  3950. $io->write('<info>names</info> : ' . implode(', ', $package->getNames()));
  3951. if ($package->isAbandoned()) {
  3952. $replacement = ($package->getReplacementPackage() !== null)
  3953. ? ' The author suggests using the ' . $package->getReplacementPackage(). ' package instead.'
  3954. : null;
  3955. $io->writeError(
  3956. sprintf('<warning>Attention: This package is abandoned and no longer maintained.%s</warning>', $replacement)
  3957. );
  3958. }
  3959. if ($package->getSupport()) {
  3960. $io->write("\n<info>support</info>");
  3961. foreach ($package->getSupport() as $type => $value) {
  3962. $io->write('<comment>' . $type . '</comment> : '.$value);
  3963. }
  3964. }
  3965. if ($package->getAutoload()) {
  3966. $io->write("\n<info>autoload</info>");
  3967. foreach ($package->getAutoload() as $type => $autoloads) {
  3968. $io->write('<comment>' . $type . '</comment>');
  3969. if ($type === 'psr-0') {
  3970. foreach ($autoloads as $name => $path) {
  3971. $io->write(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.')));
  3972. }
  3973. } elseif ($type === 'psr-4') {
  3974. foreach ($autoloads as $name => $path) {
  3975. $io->write(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.')));
  3976. }
  3977. } elseif ($type === 'classmap') {
  3978. $io->write(implode(', ', $autoloads));
  3979. }
  3980. }
  3981. if ($package->getIncludePaths()) {
  3982. $io->write('<comment>include-path</comment>');
  3983. $io->write(implode(', ', $package->getIncludePaths()));
  3984. }
  3985. }
  3986. }
  3987. protected function printVersions(CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo)
  3988. {
  3989. uasort($versions, 'version_compare');
  3990. $versions = array_keys(array_reverse($versions));
  3991. if ($installedRepo->hasPackage($package)) {
  3992. $installedVersion = $package->getPrettyVersion();
  3993. $key = array_search($installedVersion, $versions);
  3994. if (false !== $key) {
  3995. $versions[$key] = '<info>* ' . $installedVersion . '</info>';
  3996. }
  3997. }
  3998. $versions = implode(', ', $versions);
  3999. $this->getIO()->write('<info>versions</info> : ' . $versions);
  4000. }
  4001. protected function printLinks(CompletePackageInterface $package, $linkType, $title = null)
  4002. {
  4003. $title = $title ?: $linkType;
  4004. $io = $this->getIO();
  4005. if ($links = $package->{'get'.ucfirst($linkType)}()) {
  4006. $io->write("\n<info>" . $title . "</info>");
  4007. foreach ($links as $link) {
  4008. $io->write($link->getTarget() . ' <comment>' . $link->getPrettyConstraint() . '</comment>');
  4009. }
  4010. }
  4011. }
  4012. protected function printLicenses(CompletePackageInterface $package)
  4013. {
  4014. $spdxLicenses = new SpdxLicenses();
  4015. $licenses = $package->getLicense();
  4016. $io = $this->getIO();
  4017. foreach ($licenses as $licenseId) {
  4018. $license = $spdxLicenses->getLicenseByIdentifier($licenseId);
  4019. if (!$license) {
  4020. $out = $licenseId;
  4021. } else {
  4022. if ($license[1] === true) {
  4023. $out = sprintf('%s (%s) (OSI approved) %s', $license[0], $licenseId, $license[2]);
  4024. } else {
  4025. $out = sprintf('%s (%s) %s', $license[0], $licenseId, $license[2]);
  4026. }
  4027. }
  4028. $io->write('<info>license</info> : ' . $out);
  4029. }
  4030. }
  4031. }
  4032. <?php
  4033. namespace Composer\Command;
  4034. use Symfony\Component\Console\Input\InputInterface;
  4035. use Symfony\Component\Console\Input\InputOption;
  4036. use Symfony\Component\Console\Output\OutputInterface;
  4037. use Composer\Downloader\ChangeReportInterface;
  4038. use Composer\Plugin\CommandEvent;
  4039. use Composer\Plugin\PluginEvents;
  4040. use Composer\Script\ScriptEvents;
  4041. class StatusCommand extends Command
  4042. {
  4043. protected function configure()
  4044. {
  4045. $this
  4046. ->setName('status')
  4047. ->setDescription('Show a list of locally modified packages')
  4048. ->setDefinition(array(
  4049. new InputOption('verbose', 'v|vv|vvv', InputOption::VALUE_NONE, 'Show modified files for each directory that contains changes.'),
  4050. ))
  4051. ->setHelp(<<<EOT
  4052. The status command displays a list of dependencies that have
  4053. been modified locally.
  4054. EOT
  4055. )
  4056. ;
  4057. }
  4058. protected function execute(InputInterface $input, OutputInterface $output)
  4059. {
  4060. $composer = $this->getComposer();
  4061. $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'status', $input, $output);
  4062. $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
  4063. $installedRepo = $composer->getRepositoryManager()->getLocalRepository();
  4064. $dm = $composer->getDownloadManager();
  4065. $im = $composer->getInstallationManager();
  4066. $composer->getEventDispatcher()->dispatchScript(ScriptEvents::PRE_STATUS_CMD, true);
  4067. $errors = array();
  4068. $io = $this->getIO();
  4069. foreach ($installedRepo->getPackages() as $package) {
  4070. $downloader = $dm->getDownloaderForInstalledPackage($package);
  4071. if ($downloader instanceof ChangeReportInterface) {
  4072. $targetDir = $im->getInstallPath($package);
  4073. if (is_link($targetDir)) {
  4074. $errors[$targetDir] = $targetDir . ' is a symbolic link.';
  4075. }
  4076. if ($changes = $downloader->getLocalChanges($package, $targetDir)) {
  4077. $errors[$targetDir] = $changes;
  4078. }
  4079. }
  4080. }
  4081. if (!$errors) {
  4082. $io->writeError('<info>No local changes</info>');
  4083. } else {
  4084. $io->writeError('<error>You have changes in the following dependencies:</error>');
  4085. }
  4086. foreach ($errors as $path => $changes) {
  4087. if ($input->getOption('verbose')) {
  4088. $indentedChanges = implode("\n", array_map(function ($line) {
  4089. return ' ' . ltrim($line);
  4090. }, explode("\n", $changes)));
  4091. $io->write('<info>'.$path.'</info>:');
  4092. $io->write($indentedChanges);
  4093. } else {
  4094. $io->write($path);
  4095. }
  4096. }
  4097. if ($errors && !$input->getOption('verbose')) {
  4098. $io->writeError('Use --verbose (-v) to see modified files');
  4099. }
  4100. $composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_STATUS_CMD, true);
  4101. return $errors ? 1 : 0;
  4102. }
  4103. }
  4104. <?php
  4105. namespace Composer\Command;
  4106. use Symfony\Component\Console\Input\InputArgument;
  4107. use Symfony\Component\Console\Input\InputInterface;
  4108. use Symfony\Component\Console\Input\InputOption;
  4109. use Symfony\Component\Console\Output\OutputInterface;
  4110. class SuggestsCommand extends Command
  4111. {
  4112. protected function configure()
  4113. {
  4114. $this
  4115. ->setName('suggests')
  4116. ->setDescription('Show package suggestions')
  4117. ->setDefinition(array(
  4118. new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Exclude suggestions from require-dev packages'),
  4119. new InputArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Packages that you want to list suggestions from.'),
  4120. ))
  4121. ->setHelp(<<<EOT
  4122. The <info>%command.name%</info> command shows suggested packages.
  4123. With <info>-v</info> you also see which package suggested it and why.
  4124. EOT
  4125. )
  4126. ;
  4127. }
  4128. protected function execute(InputInterface $input, OutputInterface $output)
  4129. {
  4130. $lock = $this->getComposer()->getLocker()->getLockData();
  4131. if (empty($lock)) {
  4132. throw new \RuntimeException('Lockfile seems to be empty?');
  4133. }
  4134. $packages = $lock['packages'];
  4135. if (!$input->getOption('no-dev')) {
  4136. $packages += $lock['packages-dev'];
  4137. }
  4138. $filter = $input->getArgument('packages');
  4139. foreach ($packages as $package) {
  4140. if (empty($package['suggest'])) {
  4141. continue;
  4142. }
  4143. if (!empty($filter) && !in_array($package['name'], $filter)) {
  4144. continue;
  4145. }
  4146. $this->printSuggestions($packages, $package['name'], $package['suggest']);
  4147. }
  4148. }
  4149. protected function printSuggestions($installed, $source, $suggestions)
  4150. {
  4151. foreach ($suggestions as $suggestion => $reason) {
  4152. foreach ($installed as $package) {
  4153. if ($package['name'] === $suggestion) {
  4154. continue 2;
  4155. }
  4156. }
  4157. if (empty($reason)) {
  4158. $reason = '*';
  4159. }
  4160. $this->printSuggestion($source, $suggestion, $reason);
  4161. }
  4162. }
  4163. protected function printSuggestion($package, $suggestion, $reason)
  4164. {
  4165. $io = $this->getIO();
  4166. if ($io->isVerbose()) {
  4167. $io->write(sprintf('<comment>%s</comment> suggests <info>%s</info>: %s', $package, $suggestion, $reason));
  4168. } else {
  4169. $io->write(sprintf('<info>%s</info>', $suggestion));
  4170. }
  4171. }
  4172. }
  4173. <?php
  4174. namespace Composer\Command;
  4175. use Composer\Installer;
  4176. use Composer\Plugin\CommandEvent;
  4177. use Composer\Plugin\PluginEvents;
  4178. use Symfony\Component\Console\Input\InputInterface;
  4179. use Symfony\Component\Console\Input\InputOption;
  4180. use Symfony\Component\Console\Input\InputArgument;
  4181. use Symfony\Component\Console\Output\OutputInterface;
  4182. class UpdateCommand extends Command
  4183. {
  4184. protected function configure()
  4185. {
  4186. $this
  4187. ->setName('update')
  4188. ->setDescription('Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file.')
  4189. ->setDefinition(array(
  4190. new InputArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Packages that should be updated, if not provided all packages are.'),
  4191. new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'),
  4192. new InputOption('prefer-dist', null, InputOption::VALUE_NONE, 'Forces installation from package dist even for dev versions.'),
  4193. new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'),
  4194. new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables installation of require-dev packages (enabled by default, only present for BC).'),
  4195. new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables installation of require-dev packages.'),
  4196. new InputOption('lock', null, InputOption::VALUE_NONE, 'Only updates the lock file hash to suppress warning about the lock file being out of date.'),
  4197. new InputOption('no-plugins', null, InputOption::VALUE_NONE, 'Disables all plugins.'),
  4198. new InputOption('no-custom-installers', null, InputOption::VALUE_NONE, 'DEPRECATED: Use no-plugins instead.'),
  4199. new InputOption('no-autoloader', null, InputOption::VALUE_NONE, 'Skips autoloader generation'),
  4200. new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'),
  4201. new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'),
  4202. new InputOption('with-dependencies', null, InputOption::VALUE_NONE, 'Add also all dependencies of whitelisted packages to the whitelist.'),
  4203. new InputOption('verbose', 'v|vv|vvv', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'),
  4204. new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump.'),
  4205. new InputOption('classmap-authoritative', 'a', InputOption::VALUE_NONE, 'Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.'),
  4206. new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore platform requirements (php & ext- packages).'),
  4207. new InputOption('prefer-stable', null, InputOption::VALUE_NONE, 'Prefer stable versions of dependencies.'),
  4208. new InputOption('prefer-lowest', null, InputOption::VALUE_NONE, 'Prefer lowest versions of dependencies.'),
  4209. ))
  4210. ->setHelp(<<<EOT
  4211. The <info>update</info> command reads the composer.json file from the
  4212. current directory, processes it, and updates, removes or installs all the
  4213. dependencies.
  4214. <info>php composer.phar update</info>
  4215. To limit the update operation to a few packages, you can list the package(s)
  4216. you want to update as such:
  4217. <info>php composer.phar update vendor/package1 foo/mypackage [...]</info>
  4218. You may also use an asterisk (*) pattern to limit the update operation to package(s)
  4219. from a specific vendor:
  4220. <info>php composer.phar update vendor/package1 foo/* [...]</info>
  4221. EOT
  4222. )
  4223. ;
  4224. }
  4225. protected function execute(InputInterface $input, OutputInterface $output)
  4226. {
  4227. $io = $this->getIO();
  4228. if ($input->getOption('no-custom-installers')) {
  4229. $io->writeError('<warning>You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.</warning>');
  4230. $input->setOption('no-plugins', true);
  4231. }
  4232. if ($input->getOption('dev')) {
  4233. $io->writeError('<warning>You are using the deprecated option "dev". Dev packages are installed by default now.</warning>');
  4234. }
  4235. $composer = $this->getComposer(true, $input->getOption('no-plugins'));
  4236. $composer->getDownloadManager()->setOutputProgress(!$input->getOption('no-progress'));
  4237. $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'update', $input, $output);
  4238. $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
  4239. $install = Installer::create($io, $composer);
  4240. $preferSource = false;
  4241. $preferDist = false;
  4242. $config = $composer->getConfig();
  4243. switch ($config->get('preferred-install')) {
  4244. case 'source':
  4245. $preferSource = true;
  4246. break;
  4247. case 'dist':
  4248. $preferDist = true;
  4249. break;
  4250. case 'auto':
  4251. default:
  4252. break;
  4253. }
  4254. if ($input->getOption('prefer-source') || $input->getOption('prefer-dist')) {
  4255. $preferSource = $input->getOption('prefer-source');
  4256. $preferDist = $input->getOption('prefer-dist');
  4257. }
  4258. $optimize = $input->getOption('optimize-autoloader') || $config->get('optimize-autoloader');
  4259. $authoritative = $input->getOption('classmap-authoritative') || $config->get('classmap-authoritative');
  4260. $install
  4261. ->setDryRun($input->getOption('dry-run'))
  4262. ->setVerbose($input->getOption('verbose'))
  4263. ->setPreferSource($preferSource)
  4264. ->setPreferDist($preferDist)
  4265. ->setDevMode(!$input->getOption('no-dev'))
  4266. ->setDumpAutoloader(!$input->getOption('no-autoloader'))
  4267. ->setRunScripts(!$input->getOption('no-scripts'))
  4268. ->setOptimizeAutoloader($optimize)
  4269. ->setClassMapAuthoritative($authoritative)
  4270. ->setUpdate(true)
  4271. ->setUpdateWhitelist($input->getOption('lock') ? array('lock') : $input->getArgument('packages'))
  4272. ->setWhitelistDependencies($input->getOption('with-dependencies'))
  4273. ->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs'))
  4274. ->setPreferStable($input->getOption('prefer-stable'))
  4275. ->setPreferLowest($input->getOption('prefer-lowest'))
  4276. ;
  4277. if ($input->getOption('no-plugins')) {
  4278. $install->disablePlugins();
  4279. }
  4280. return $install->run();
  4281. }
  4282. }
  4283. <?php
  4284. namespace Composer\Command;
  4285. use Composer\Factory;
  4286. use Composer\Package\Loader\ValidatingArrayLoader;
  4287. use Composer\Util\ConfigValidator;
  4288. use Symfony\Component\Console\Input\InputArgument;
  4289. use Symfony\Component\Console\Input\InputInterface;
  4290. use Symfony\Component\Console\Input\InputOption;
  4291. use Symfony\Component\Console\Output\OutputInterface;
  4292. class ValidateCommand extends Command
  4293. {
  4294. protected function configure()
  4295. {
  4296. $this
  4297. ->setName('validate')
  4298. ->setDescription('Validates a composer.json and composer.lock')
  4299. ->setDefinition(array(
  4300. new InputOption('no-check-all', null, InputOption::VALUE_NONE, 'Do not make a complete validation'),
  4301. new InputOption('no-check-lock', null, InputOption::VALUE_NONE, 'Do not check if lock file is up to date'),
  4302. new InputOption('no-check-publish', null, InputOption::VALUE_NONE, 'Do not check for publish errors'),
  4303. new InputOption('with-dependencies', 'A', InputOption::VALUE_NONE, 'Also validate the composer.json of all installed dependencies'),
  4304. new InputOption('strict', null, InputOption::VALUE_NONE, 'Return a non-zero exit code for warnings as well as errors'),
  4305. new InputArgument('file', InputArgument::OPTIONAL, 'path to composer.json file', './composer.json'),
  4306. ))
  4307. ->setHelp(<<<EOT
  4308. The validate command validates a given composer.json and composer.lock
  4309. Exit codes in case of errors are:
  4310. 1 validation warning(s), only when --strict is given
  4311. 2 validation error(s)
  4312. 3 file unreadable or missing
  4313. EOT
  4314. );
  4315. }
  4316. protected function execute(InputInterface $input, OutputInterface $output)
  4317. {
  4318. $file = $input->getArgument('file');
  4319. $io = $this->getIO();
  4320. if (!file_exists($file)) {
  4321. $io->writeError('<error>' . $file . ' not found.</error>');
  4322. return 3;
  4323. }
  4324. if (!is_readable($file)) {
  4325. $io->writeError('<error>' . $file . ' is not readable.</error>');
  4326. return 3;
  4327. }
  4328. $validator = new ConfigValidator($io);
  4329. $checkAll = $input->getOption('no-check-all') ? 0 : ValidatingArrayLoader::CHECK_ALL;
  4330. $checkPublish = !$input->getOption('no-check-publish');
  4331. $checkLock = !$input->getOption('no-check-lock');
  4332. $isStrict = $input->getOption('strict');
  4333. list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll);
  4334. $lockErrors = array();
  4335. $composer = Factory::create($io, $file);
  4336. $locker = $composer->getLocker();
  4337. if ($locker->isLocked() && !$locker->isFresh()) {
  4338. $lockErrors[] = 'The lock file is not up to date with the latest changes in composer.json.';
  4339. }
  4340. $this->outputResult($io, $file, $errors, $warnings, $checkPublish, $publishErrors, $checkLock, $lockErrors, true);
  4341. $exitCode = $errors || ($publishErrors && $checkPublish) || ($lockErrors && $checkLock) ? 2 : ($isStrict && $warnings ? 1 : 0);
  4342. if ($input->getOption('with-dependencies')) {
  4343. $localRepo = $composer->getRepositoryManager()->getLocalRepository();
  4344. foreach ($localRepo->getPackages() as $package) {
  4345. $path = $composer->getInstallationManager()->getInstallPath($package);
  4346. $file = $path . '/composer.json';
  4347. if (is_dir($path) && file_exists($file)) {
  4348. list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll);
  4349. $this->outputResult($io, $package->getPrettyName(), $errors, $warnings, $checkPublish, $publishErrors);
  4350. $depCode = $errors || ($publishErrors && $checkPublish) ? 2 : ($isStrict && $warnings ? 1 : 0);
  4351. $exitCode = max($depCode, $exitCode);
  4352. }
  4353. }
  4354. }
  4355. return $exitCode;
  4356. }
  4357. private function outputResult($io, $name, &$errors, &$warnings, $checkPublish = false, $publishErrors = array(), $checkLock = false, $lockErrors = array(), $printSchemaUrl = false)
  4358. {
  4359. if (!$errors && !$publishErrors && !$warnings) {
  4360. $io->write('<info>' . $name . ' is valid</info>');
  4361. } elseif (!$errors && !$publishErrors) {
  4362. $io->writeError('<info>' . $name . ' is valid, but with a few warnings</info>');
  4363. if ($printSchemaUrl) {
  4364. $io->writeError('<warning>See https://getcomposer.org/doc/04-schema.md for details on the schema</warning>');
  4365. }
  4366. } elseif (!$errors) {
  4367. $io->writeError('<info>' . $name . ' is valid for simple usage with composer but has</info>');
  4368. $io->writeError('<info>strict errors that make it unable to be published as a package:</info>');
  4369. if ($printSchemaUrl) {
  4370. $io->writeError('<warning>See https://getcomposer.org/doc/04-schema.md for details on the schema</warning>');
  4371. }
  4372. } else {
  4373. $io->writeError('<error>' . $name . ' is invalid, the following errors/warnings were found:</error>');
  4374. }
  4375. if ($checkPublish) {
  4376. $errors = array_merge($errors, $publishErrors);
  4377. } else {
  4378. $warnings = array_merge($warnings, $publishErrors);
  4379. }
  4380. if ($checkLock) {
  4381. $errors = array_merge($errors, $lockErrors);
  4382. } else {
  4383. $warnings = array_merge($warnings, $lockErrors);
  4384. }
  4385. $messages = array(
  4386. 'error' => $errors,
  4387. 'warning' => $warnings,
  4388. );
  4389. foreach ($messages as $style => $msgs) {
  4390. foreach ($msgs as $msg) {
  4391. $io->writeError('<' . $style . '>' . $msg . '</' . $style . '>');
  4392. }
  4393. }
  4394. }
  4395. }
  4396. <?php
  4397. namespace Composer;
  4398. use Composer\Package\RootPackageInterface;
  4399. use Composer\Package\Locker;
  4400. use Composer\Repository\RepositoryManager;
  4401. use Composer\Installer\InstallationManager;
  4402. use Composer\Plugin\PluginManager;
  4403. use Composer\Downloader\DownloadManager;
  4404. use Composer\EventDispatcher\EventDispatcher;
  4405. use Composer\Autoload\AutoloadGenerator;
  4406. class Composer
  4407. {
  4408. const VERSION = '4f934d928260e126b5d06392e12ee20fae258232';
  4409. const BRANCH_ALIAS_VERSION = '1.0-dev';
  4410. const RELEASE_DATE = '2015-10-26 15:01:06';
  4411. private $package;
  4412. private $locker;
  4413. private $repositoryManager;
  4414. private $downloadManager;
  4415. private $installationManager;
  4416. private $pluginManager;
  4417. private $config;
  4418. private $eventDispatcher;
  4419. private $autoloadGenerator;
  4420. public function setPackage(RootPackageInterface $package)
  4421. {
  4422. $this->package = $package;
  4423. }
  4424. public function getPackage()
  4425. {
  4426. return $this->package;
  4427. }
  4428. public function setConfig(Config $config)
  4429. {
  4430. $this->config = $config;
  4431. }
  4432. public function getConfig()
  4433. {
  4434. return $this->config;
  4435. }
  4436. public function setLocker(Locker $locker)
  4437. {
  4438. $this->locker = $locker;
  4439. }
  4440. public function getLocker()
  4441. {
  4442. return $this->locker;
  4443. }
  4444. public function setRepositoryManager(RepositoryManager $manager)
  4445. {
  4446. $this->repositoryManager = $manager;
  4447. }
  4448. public function getRepositoryManager()
  4449. {
  4450. return $this->repositoryManager;
  4451. }
  4452. public function setDownloadManager(DownloadManager $manager)
  4453. {
  4454. $this->downloadManager = $manager;
  4455. }
  4456. public function getDownloadManager()
  4457. {
  4458. return $this->downloadManager;
  4459. }
  4460. public function setInstallationManager(InstallationManager $manager)
  4461. {
  4462. $this->installationManager = $manager;
  4463. }
  4464. public function getInstallationManager()
  4465. {
  4466. return $this->installationManager;
  4467. }
  4468. public function setPluginManager(PluginManager $manager)
  4469. {
  4470. $this->pluginManager = $manager;
  4471. }
  4472. public function getPluginManager()
  4473. {
  4474. return $this->pluginManager;
  4475. }
  4476. public function setEventDispatcher(EventDispatcher $eventDispatcher)
  4477. {
  4478. $this->eventDispatcher = $eventDispatcher;
  4479. }
  4480. public function getEventDispatcher()
  4481. {
  4482. return $this->eventDispatcher;
  4483. }
  4484. public function setAutoloadGenerator(AutoloadGenerator $autoloadGenerator)
  4485. {
  4486. $this->autoloadGenerator = $autoloadGenerator;
  4487. }
  4488. public function getAutoloadGenerator()
  4489. {
  4490. return $this->autoloadGenerator;
  4491. }
  4492. }
  4493. <?php
  4494. namespace Composer;
  4495. use Composer\Config\ConfigSourceInterface;
  4496. class Config
  4497. {
  4498. const RELATIVE_PATHS = 1;
  4499. public static $defaultConfig = array(
  4500. 'process-timeout' => 300,
  4501. 'use-include-path' => false,
  4502. 'preferred-install' => 'auto',
  4503. 'notify-on-install' => true,
  4504. 'github-protocols' => array('git', 'https', 'ssh'),
  4505. 'vendor-dir' => 'vendor',
  4506. 'bin-dir' => '{$vendor-dir}/bin',
  4507. 'cache-dir' => '{$home}/cache',
  4508. 'cache-files-dir' => '{$cache-dir}/files',
  4509. 'cache-repo-dir' => '{$cache-dir}/repo',
  4510. 'cache-vcs-dir' => '{$cache-dir}/vcs',
  4511. 'cache-ttl' => 15552000,
  4512. 'cache-files-ttl' => null,
  4513. 'cache-files-maxsize' => '300MiB',
  4514. 'discard-changes' => false,
  4515. 'autoloader-suffix' => null,
  4516. 'optimize-autoloader' => false,
  4517. 'classmap-authoritative' => false,
  4518. 'prepend-autoloader' => true,
  4519. 'github-domains' => array('github.com'),
  4520. 'github-expose-hostname' => true,
  4521. 'store-auths' => 'prompt',
  4522. 'platform' => array(),
  4523. 'archive-format' => 'tar',
  4524. 'archive-dir' => '.',
  4525. );
  4526. public static $defaultRepositories = array(
  4527. 'packagist' => array(
  4528. 'type' => 'composer',
  4529. 'url' => 'https?://packagist.org',
  4530. 'allow_ssl_downgrade' => true,
  4531. ),
  4532. );
  4533. private $config;
  4534. private $baseDir;
  4535. private $repositories;
  4536. private $configSource;
  4537. private $authConfigSource;
  4538. private $useEnvironment;
  4539. public function __construct($useEnvironment = true, $baseDir = null)
  4540. {
  4541. $this->config = static::$defaultConfig;
  4542. $this->repositories = static::$defaultRepositories;
  4543. $this->useEnvironment = (bool) $useEnvironment;
  4544. $this->baseDir = $baseDir;
  4545. }
  4546. public function setConfigSource(ConfigSourceInterface $source)
  4547. {
  4548. $this->configSource = $source;
  4549. }
  4550. public function getConfigSource()
  4551. {
  4552. return $this->configSource;
  4553. }
  4554. public function setAuthConfigSource(ConfigSourceInterface $source)
  4555. {
  4556. $this->authConfigSource = $source;
  4557. }
  4558. public function getAuthConfigSource()
  4559. {
  4560. return $this->authConfigSource;
  4561. }
  4562. public function merge($config)
  4563. {
  4564. if (!empty($config['config']) && is_array($config['config'])) {
  4565. foreach ($config['config'] as $key => $val) {
  4566. if (in_array($key, array('github-oauth', 'http-basic')) && isset($this->config[$key])) {
  4567. $this->config[$key] = array_merge($this->config[$key], $val);
  4568. } else {
  4569. $this->config[$key] = $val;
  4570. }
  4571. }
  4572. }
  4573. if (!empty($config['repositories']) && is_array($config['repositories'])) {
  4574. $this->repositories = array_reverse($this->repositories, true);
  4575. $newRepos = array_reverse($config['repositories'], true);
  4576. foreach ($newRepos as $name => $repository) {
  4577. if (false === $repository) {
  4578. unset($this->repositories[$name]);
  4579. continue;
  4580. }
  4581. if (is_array($repository) && 1 === count($repository) && false === current($repository)) {
  4582. unset($this->repositories[key($repository)]);
  4583. continue;
  4584. }
  4585. if (is_int($name)) {
  4586. $this->repositories[] = $repository;
  4587. } else {
  4588. $this->repositories[$name] = $repository;
  4589. }
  4590. }
  4591. $this->repositories = array_reverse($this->repositories, true);
  4592. }
  4593. }
  4594. public function getRepositories()
  4595. {
  4596. return $this->repositories;
  4597. }
  4598. public function get($key, $flags = 0)
  4599. {
  4600. switch ($key) {
  4601. case 'vendor-dir':
  4602. case 'bin-dir':
  4603. case 'process-timeout':
  4604. case 'cache-dir':
  4605. case 'cache-files-dir':
  4606. case 'cache-repo-dir':
  4607. case 'cache-vcs-dir':
  4608. $env = 'COMPOSER_' . strtoupper(strtr($key, '-', '_'));
  4609. $val = rtrim($this->process($this->getComposerEnv($env) ?: $this->config[$key], $flags), '/\\');
  4610. $val = preg_replace('#^(\$HOME|~)(/|$)#', rtrim(getenv('HOME') ?: getenv('USERPROFILE'), '/\\') . '/', $val);
  4611. if (substr($key, -4) !== '-dir') {
  4612. return $val;
  4613. }
  4614. return ($flags & self::RELATIVE_PATHS == self::RELATIVE_PATHS) ? $val : $this->realpath($val);
  4615. case 'cache-ttl':
  4616. return (int) $this->config[$key];
  4617. case 'cache-files-maxsize':
  4618. if (!preg_match('/^\s*([0-9.]+)\s*(?:([kmg])(?:i?b)?)?\s*$/i', $this->config[$key], $matches)) {
  4619. throw new \RuntimeException(
  4620. "Could not parse the value of 'cache-files-maxsize': {$this->config[$key]}"
  4621. );
  4622. }
  4623. $size = $matches[1];
  4624. if (isset($matches[2])) {
  4625. switch (strtolower($matches[2])) {
  4626. case 'g':
  4627. $size *= 1024;
  4628. case 'm':
  4629. $size *= 1024;
  4630. case 'k':
  4631. $size *= 1024;
  4632. break;
  4633. }
  4634. }
  4635. return $size;
  4636. case 'cache-files-ttl':
  4637. if (isset($this->config[$key])) {
  4638. return (int) $this->config[$key];
  4639. }
  4640. return (int) $this->config['cache-ttl'];
  4641. case 'home':
  4642. return rtrim($this->process($this->config[$key], $flags), '/\\');
  4643. case 'discard-changes':
  4644. if ($env = $this->getComposerEnv('COMPOSER_DISCARD_CHANGES')) {
  4645. if (!in_array($env, array('stash', 'true', 'false', '1', '0'), true)) {
  4646. throw new \RuntimeException(
  4647. "Invalid value for COMPOSER_DISCARD_CHANGES: {$env}. Expected 1, 0, true, false or stash"
  4648. );
  4649. }
  4650. if ('stash' === $env) {
  4651. return 'stash';
  4652. }
  4653. return $env !== 'false' && (bool) $env;
  4654. }
  4655. if (!in_array($this->config[$key], array(true, false, 'stash'), true)) {
  4656. throw new \RuntimeException(
  4657. "Invalid value for 'discard-changes': {$this->config[$key]}. Expected true, false or stash"
  4658. );
  4659. }
  4660. return $this->config[$key];
  4661. case 'github-protocols':
  4662. if (reset($this->config['github-protocols']) === 'http') {
  4663. throw new \RuntimeException('The http protocol for github is not available anymore, update your config\'s github-protocols to use "https", "git" or "ssh"');
  4664. }
  4665. return $this->config[$key];
  4666. default:
  4667. if (!isset($this->config[$key])) {
  4668. return null;
  4669. }
  4670. return $this->process($this->config[$key], $flags);
  4671. }
  4672. }
  4673. public function all($flags = 0)
  4674. {
  4675. $all = array(
  4676. 'repositories' => $this->getRepositories(),
  4677. );
  4678. foreach (array_keys($this->config) as $key) {
  4679. $all['config'][$key] = $this->get($key, $flags);
  4680. }
  4681. return $all;
  4682. }
  4683. public function raw()
  4684. {
  4685. return array(
  4686. 'repositories' => $this->getRepositories(),
  4687. 'config' => $this->config,
  4688. );
  4689. }
  4690. public function has($key)
  4691. {
  4692. return array_key_exists($key, $this->config);
  4693. }
  4694. private function process($value, $flags)
  4695. {
  4696. $config = $this;
  4697. if (!is_string($value)) {
  4698. return $value;
  4699. }
  4700. return preg_replace_callback('#\{\$(.+)\}#', function ($match) use ($config, $flags) {
  4701. return $config->get($match[1], $flags);
  4702. }, $value);
  4703. }
  4704. private function realpath($path)
  4705. {
  4706. if (substr($path, 0, 1) === '/' || substr($path, 1, 1) === ':') {
  4707. return $path;
  4708. }
  4709. return $this->baseDir . '/' . $path;
  4710. }
  4711. private function getComposerEnv($var)
  4712. {
  4713. if ($this->useEnvironment) {
  4714. return getenv($var);
  4715. }
  4716. return false;
  4717. }
  4718. }
  4719. <?php
  4720. namespace Composer\Config;
  4721. interface ConfigSourceInterface
  4722. {
  4723. public function addRepository($name, $config);
  4724. public function removeRepository($name);
  4725. public function addConfigSetting($name, $value);
  4726. public function removeConfigSetting($name);
  4727. public function addLink($type, $name, $value);
  4728. public function removeLink($type, $name);
  4729. public function getName();
  4730. }
  4731. <?php
  4732. namespace Composer\Config;
  4733. use Composer\Json\JsonFile;
  4734. use Composer\Json\JsonManipulator;
  4735. class JsonConfigSource implements ConfigSourceInterface
  4736. {
  4737. private $file;
  4738. private $authConfig;
  4739. public function __construct(JsonFile $file, $authConfig = false)
  4740. {
  4741. $this->file = $file;
  4742. $this->authConfig = $authConfig;
  4743. }
  4744. public function getName()
  4745. {
  4746. return $this->file->getPath();
  4747. }
  4748. public function addRepository($name, $config)
  4749. {
  4750. $this->manipulateJson('addRepository', $name, $config, function (&$config, $repo, $repoConfig) {
  4751. $config['repositories'][$repo] = $repoConfig;
  4752. });
  4753. }
  4754. public function removeRepository($name)
  4755. {
  4756. $this->manipulateJson('removeRepository', $name, function (&$config, $repo) {
  4757. unset($config['repositories'][$repo]);
  4758. });
  4759. }
  4760. public function addConfigSetting($name, $value)
  4761. {
  4762. $this->manipulateJson('addConfigSetting', $name, $value, function (&$config, $key, $val) {
  4763. if (preg_match('{^(github-oauth|http-basic|platform)\.}', $key)) {
  4764. list($key, $host) = explode('.', $key, 2);
  4765. if ($this->authConfig) {
  4766. $config[$key][$host] = $val;
  4767. } else {
  4768. $config['config'][$key][$host] = $val;
  4769. }
  4770. } else {
  4771. $config['config'][$key] = $val;
  4772. }
  4773. });
  4774. }
  4775. public function removeConfigSetting($name)
  4776. {
  4777. $this->manipulateJson('removeConfigSetting', $name, function (&$config, $key) {
  4778. if (preg_match('{^(github-oauth|http-basic|platform)\.}', $key)) {
  4779. list($key, $host) = explode('.', $key, 2);
  4780. if ($this->authConfig) {
  4781. unset($config[$key][$host]);
  4782. } else {
  4783. unset($config['config'][$key][$host]);
  4784. }
  4785. } else {
  4786. unset($config['config'][$key]);
  4787. }
  4788. });
  4789. }
  4790. public function addLink($type, $name, $value)
  4791. {
  4792. $this->manipulateJson('addLink', $type, $name, $value, function (&$config, $type, $name, $value) {
  4793. $config[$type][$name] = $value;
  4794. });
  4795. }
  4796. public function removeLink($type, $name)
  4797. {
  4798. $this->manipulateJson('removeSubNode', $type, $name, function (&$config, $type, $name) {
  4799. unset($config[$type][$name]);
  4800. });
  4801. }
  4802. protected function manipulateJson($method, $args, $fallback)
  4803. {
  4804. $args = func_get_args();
  4805. array_shift($args);
  4806. $fallback = array_pop($args);
  4807. if ($this->file->exists()) {
  4808. $contents = file_get_contents($this->file->getPath());
  4809. } elseif ($this->authConfig) {
  4810. $contents = "{\n}\n";
  4811. } else {
  4812. $contents = "{\n \"config\": {\n }\n}\n";
  4813. }
  4814. $manipulator = new JsonManipulator($contents);
  4815. $newFile = !$this->file->exists();
  4816. if ($this->authConfig && $method === 'addConfigSetting') {
  4817. $method = 'addSubNode';
  4818. list($mainNode, $name) = explode('.', $args[0], 2);
  4819. $args = array($mainNode, $name, $args[1]);
  4820. } elseif ($this->authConfig && $method === 'removeConfigSetting') {
  4821. $method = 'removeSubNode';
  4822. list($mainNode, $name) = explode('.', $args[0], 2);
  4823. $args = array($mainNode, $name);
  4824. }
  4825. if (call_user_func_array(array($manipulator, $method), $args)) {
  4826. file_put_contents($this->file->getPath(), $manipulator->getContents());
  4827. } else {
  4828. $config = $this->file->read();
  4829. $this->arrayUnshiftRef($args, $config);
  4830. call_user_func_array($fallback, $args);
  4831. $this->file->write($config);
  4832. }
  4833. if ($newFile) {
  4834. @chmod($this->file->getPath(), 0600);
  4835. }
  4836. }
  4837. private function arrayUnshiftRef(&$array, &$value)
  4838. {
  4839. $return = array_unshift($array, '');
  4840. $array[0] = &$value;
  4841. return $return;
  4842. }
  4843. }
  4844. <?php
  4845. namespace Composer\Console;
  4846. use Symfony\Component\Console\Application as BaseApplication;
  4847. use Symfony\Component\Console\Input\InputInterface;
  4848. use Symfony\Component\Console\Input\InputOption;
  4849. use Symfony\Component\Console\Output\ConsoleOutputInterface;
  4850. use Symfony\Component\Console\Output\OutputInterface;
  4851. use Symfony\Component\Console\Output\ConsoleOutput;
  4852. use Symfony\Component\Console\Formatter\OutputFormatter;
  4853. use Composer\Command;
  4854. use Composer\Composer;
  4855. use Composer\Factory;
  4856. use Composer\IO\IOInterface;
  4857. use Composer\IO\ConsoleIO;
  4858. use Composer\Json\JsonValidationException;
  4859. use Composer\Util\ErrorHandler;
  4860. class Application extends BaseApplication
  4861. {
  4862. protected $composer;
  4863. protected $io;
  4864. private static $logo = ' ______
  4865. / ____/___ ____ ___ ____ ____ ________ _____
  4866. / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
  4867. / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
  4868. \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
  4869. /_/
  4870. ';
  4871. public function __construct()
  4872. {
  4873. if (function_exists('ini_set') && extension_loaded('xdebug')) {
  4874. ini_set('xdebug.show_exception_trace', false);
  4875. ini_set('xdebug.scream', false);
  4876. }
  4877. if (function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get')) {
  4878. date_default_timezone_set(@date_default_timezone_get());
  4879. }
  4880. parent::__construct('Composer', Composer::VERSION);
  4881. }
  4882. public function run(InputInterface $input = null, OutputInterface $output = null)
  4883. {
  4884. if (null === $output) {
  4885. $styles = Factory::createAdditionalStyles();
  4886. $formatter = new OutputFormatter(null, $styles);
  4887. $output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, null, $formatter);
  4888. }
  4889. return parent::run($input, $output);
  4890. }
  4891. public function doRun(InputInterface $input, OutputInterface $output)
  4892. {
  4893. $this->io = new ConsoleIO($input, $output, $this->getHelperSet());
  4894. ErrorHandler::register($this->io);
  4895. $io = $this->getIO();
  4896. if (PHP_VERSION_ID < 50302) {
  4897. $io->writeError('<warning>Composer only officially supports PHP 5.3.2 and above, you will most likely encounter problems with your PHP '.PHP_VERSION.', upgrading is strongly recommended.</warning>');
  4898. }
  4899. if (defined('COMPOSER_DEV_WARNING_TIME')) {
  4900. $commandName = '';
  4901. if ($name = $this->getCommandName($input)) {
  4902. try {
  4903. $commandName = $this->find($name)->getName();
  4904. } catch (\InvalidArgumentException $e) {
  4905. }
  4906. }
  4907. if ($commandName !== 'self-update' && $commandName !== 'selfupdate') {
  4908. if (time() > COMPOSER_DEV_WARNING_TIME) {
  4909. $io->writeError(sprintf('<warning>Warning: This development build of composer is over 60 days old. It is recommended to update it by running "%s self-update" to get the latest version.</warning>', $_SERVER['PHP_SELF']));
  4910. }
  4911. }
  4912. }
  4913. if (getenv('COMPOSER_NO_INTERACTION')) {
  4914. $input->setInteractive(false);
  4915. }
  4916. if ($newWorkDir = $this->getNewWorkingDir($input)) {
  4917. $oldWorkingDir = getcwd();
  4918. chdir($newWorkDir);
  4919. if ($io->isDebug() >= 4) {
  4920. $io->writeError('Changed CWD to ' . getcwd());
  4921. }
  4922. }
  4923. $file = Factory::getComposerFile();
  4924. if (is_file($file) && is_readable($file) && is_array($composer = json_decode(file_get_contents($file), true))) {
  4925. if (isset($composer['scripts']) && is_array($composer['scripts'])) {
  4926. foreach ($composer['scripts'] as $script => $dummy) {
  4927. if (!defined('Composer\Script\ScriptEvents::'.str_replace('-', '_', strtoupper($script)))) {
  4928. if ($this->has($script)) {
  4929. $io->writeError('<warning>A script named '.$script.' would override a native Composer function and has been skipped</warning>');
  4930. } else {
  4931. $this->add(new Command\ScriptAliasCommand($script));
  4932. }
  4933. }
  4934. }
  4935. }
  4936. }
  4937. if ($input->hasParameterOption('--profile')) {
  4938. $startTime = microtime(true);
  4939. $this->io->enableDebugging($startTime);
  4940. }
  4941. $result = parent::doRun($input, $output);
  4942. if (isset($oldWorkingDir)) {
  4943. chdir($oldWorkingDir);
  4944. }
  4945. if (isset($startTime)) {
  4946. $io->writeError('<info>Memory usage: '.round(memory_get_usage() / 1024 / 1024, 2).'MB (peak: '.round(memory_get_peak_usage() / 1024 / 1024, 2).'MB), time: '.round(microtime(true) - $startTime, 2).'s');
  4947. }
  4948. return $result;
  4949. }
  4950. private function getNewWorkingDir(InputInterface $input)
  4951. {
  4952. $workingDir = $input->getParameterOption(array('--working-dir', '-d'));
  4953. if (false !== $workingDir && !is_dir($workingDir)) {
  4954. throw new \RuntimeException('Invalid working directory specified.');
  4955. }
  4956. return $workingDir;
  4957. }
  4958. public function renderException($exception, $output)
  4959. {
  4960. $io = $this->getIO();
  4961. try {
  4962. $composer = $this->getComposer(false, true);
  4963. if ($composer) {
  4964. $config = $composer->getConfig();
  4965. $minSpaceFree = 1024 * 1024;
  4966. if ((($df = @disk_free_space($dir = $config->get('home'))) !== false && $df < $minSpaceFree)
  4967. || (($df = @disk_free_space($dir = $config->get('vendor-dir'))) !== false && $df < $minSpaceFree)
  4968. || (($df = @disk_free_space($dir = sys_get_temp_dir())) !== false && $df < $minSpaceFree)
  4969. ) {
  4970. $io->writeError('<error>The disk hosting '.$dir.' is full, this may be the cause of the following exception</error>');
  4971. }
  4972. }
  4973. } catch (\Exception $e) {
  4974. }
  4975. if (defined('PHP_WINDOWS_VERSION_BUILD') && false !== strpos($exception->getMessage(), 'The system cannot find the path specified')) {
  4976. $io->writeError('<error>The following exception may be caused by a stale entry in your cmd.exe AutoRun</error>');
  4977. $io->writeError('<error>Check https://getcomposer.org/doc/articles/troubleshooting.md#-the-system-cannot-find-the-path-specified-windows- for details</error>');
  4978. }
  4979. if (false !== strpos($exception->getMessage(), 'fork failed - Cannot allocate memory')) {
  4980. $io->writeError('<error>The following exception is caused by a lack of memory and not having swap configured</error>');
  4981. $io->writeError('<error>Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details</error>');
  4982. }
  4983. if ($output instanceof ConsoleOutputInterface) {
  4984. parent::renderException($exception, $output->getErrorOutput());
  4985. } else {
  4986. parent::renderException($exception, $output);
  4987. }
  4988. }
  4989. public function getComposer($required = true, $disablePlugins = false)
  4990. {
  4991. if (null === $this->composer) {
  4992. try {
  4993. $this->composer = Factory::create($this->io, null, $disablePlugins);
  4994. } catch (\InvalidArgumentException $e) {
  4995. if ($required) {
  4996. $this->io->writeError($e->getMessage());
  4997. exit(1);
  4998. }
  4999. } catch (JsonValidationException $e) {
  5000. $errors = ' - ' . implode(PHP_EOL . ' - ', $e->getErrors());
  5001. $message = $e->getMessage() . ':' . PHP_EOL . $errors;
  5002. throw new JsonValidationException($message);
  5003. }
  5004. }
  5005. return $this->composer;
  5006. }
  5007. public function resetComposer()
  5008. {
  5009. $this->composer = null;
  5010. }
  5011. public function getIO()
  5012. {
  5013. return $this->io;
  5014. }
  5015. public function getHelp()
  5016. {
  5017. return self::$logo . parent::getHelp();
  5018. }
  5019. protected function getDefaultCommands()
  5020. {
  5021. $commands = parent::getDefaultCommands();
  5022. $commands[] = new Command\AboutCommand();
  5023. $commands[] = new Command\ConfigCommand();
  5024. $commands[] = new Command\DependsCommand();
  5025. $commands[] = new Command\InitCommand();
  5026. $commands[] = new Command\InstallCommand();
  5027. $commands[] = new Command\CreateProjectCommand();
  5028. $commands[] = new Command\UpdateCommand();
  5029. $commands[] = new Command\SearchCommand();
  5030. $commands[] = new Command\ValidateCommand();
  5031. $commands[] = new Command\ShowCommand();
  5032. $commands[] = new Command\SuggestsCommand();
  5033. $commands[] = new Command\RequireCommand();
  5034. $commands[] = new Command\DumpAutoloadCommand();
  5035. $commands[] = new Command\StatusCommand();
  5036. $commands[] = new Command\ArchiveCommand();
  5037. $commands[] = new Command\DiagnoseCommand();
  5038. $commands[] = new Command\RunScriptCommand();
  5039. $commands[] = new Command\LicensesCommand();
  5040. $commands[] = new Command\GlobalCommand();
  5041. $commands[] = new Command\ClearCacheCommand();
  5042. $commands[] = new Command\RemoveCommand();
  5043. $commands[] = new Command\HomeCommand();
  5044. if ('phar:' === substr(__FILE__, 0, 5)) {
  5045. $commands[] = new Command\SelfUpdateCommand();
  5046. }
  5047. return $commands;
  5048. }
  5049. public function getLongVersion()
  5050. {
  5051. if (Composer::BRANCH_ALIAS_VERSION) {
  5052. return sprintf(
  5053. '<info>%s</info> version <comment>%s (%s)</comment> %s',
  5054. $this->getName(),
  5055. Composer::BRANCH_ALIAS_VERSION,
  5056. $this->getVersion(),
  5057. Composer::RELEASE_DATE
  5058. );
  5059. }
  5060. return parent::getLongVersion() . ' ' . Composer::RELEASE_DATE;
  5061. }
  5062. protected function getDefaultInputDefinition()
  5063. {
  5064. $definition = parent::getDefaultInputDefinition();
  5065. $definition->addOption(new InputOption('--profile', null, InputOption::VALUE_NONE, 'Display timing and memory usage information'));
  5066. $definition->addOption(new InputOption('--working-dir', '-d', InputOption::VALUE_REQUIRED, 'If specified, use the given directory as working directory.'));
  5067. return $definition;
  5068. }
  5069. }
  5070. <?php
  5071. namespace Composer\Console;
  5072. use Symfony\Component\Console\Formatter\OutputFormatter;
  5073. class HtmlOutputFormatter extends OutputFormatter
  5074. {
  5075. private static $availableForegroundColors = array(
  5076. 30 => 'black',
  5077. 31 => 'red',
  5078. 32 => 'green',
  5079. 33 => 'yellow',
  5080. 34 => 'blue',
  5081. 35 => 'magenta',
  5082. 36 => 'cyan',
  5083. 37 => 'white',
  5084. );
  5085. private static $availableBackgroundColors = array(
  5086. 40 => 'black',
  5087. 41 => 'red',
  5088. 42 => 'green',
  5089. 43 => 'yellow',
  5090. 44 => 'blue',
  5091. 45 => 'magenta',
  5092. 46 => 'cyan',
  5093. 47 => 'white',
  5094. );
  5095. private static $availableOptions = array(
  5096. 1 => 'bold',
  5097. 4 => 'underscore',
  5098. );
  5099. public function __construct(array $styles = array())
  5100. {
  5101. parent::__construct(true, $styles);
  5102. }
  5103. public function format($message)
  5104. {
  5105. $formatted = parent::format($message);
  5106. $clearEscapeCodes = '(?:39|49|0|22|24|25|27|28)';
  5107. return preg_replace_callback("{\033\[([0-9;]+)m(.*?)\033\[(?:".$clearEscapeCodes.";)*?".$clearEscapeCodes."m}s", array($this, 'formatHtml'), $formatted);
  5108. }
  5109. private function formatHtml($matches)
  5110. {
  5111. $out = '<span style="';
  5112. foreach (explode(';', $matches[1]) as $code) {
  5113. if (isset(self::$availableForegroundColors[$code])) {
  5114. $out .= 'color:'.self::$availableForegroundColors[$code].';';
  5115. } elseif (isset(self::$availableBackgroundColors[$code])) {
  5116. $out .= 'background-color:'.self::$availableBackgroundColors[$code].';';
  5117. } elseif (isset(self::$availableOptions[$code])) {
  5118. switch (self::$availableOptions[$code]) {
  5119. case 'bold':
  5120. $out .= 'font-weight:bold;';
  5121. break;
  5122. case 'underscore':
  5123. $out .= 'text-decoration:underline;';
  5124. break;
  5125. }
  5126. }
  5127. }
  5128. return $out.'">'.$matches[2].'</span>';
  5129. }
  5130. }
  5131. <?php
  5132. namespace Composer\DependencyResolver;
  5133. class Decisions implements \Iterator, \Countable
  5134. {
  5135. const DECISION_LITERAL = 0;
  5136. const DECISION_REASON = 1;
  5137. protected $pool;
  5138. protected $decisionMap;
  5139. protected $decisionQueue = array();
  5140. public function __construct($pool)
  5141. {
  5142. $this->pool = $pool;
  5143. $this->decisionMap = array();
  5144. }
  5145. public function decide($literal, $level, $why)
  5146. {
  5147. $this->addDecision($literal, $level);
  5148. $this->decisionQueue[] = array(
  5149. self::DECISION_LITERAL => $literal,
  5150. self::DECISION_REASON => $why,
  5151. );
  5152. }
  5153. public function satisfy($literal)
  5154. {
  5155. $packageId = abs($literal);
  5156. return (
  5157. $literal > 0 && isset($this->decisionMap[$packageId]) && $this->decisionMap[$packageId] > 0 ||
  5158. $literal < 0 && isset($this->decisionMap[$packageId]) && $this->decisionMap[$packageId] < 0
  5159. );
  5160. }
  5161. public function conflict($literal)
  5162. {
  5163. $packageId = abs($literal);
  5164. return (
  5165. (isset($this->decisionMap[$packageId]) && $this->decisionMap[$packageId] > 0 && $literal < 0) ||
  5166. (isset($this->decisionMap[$packageId]) && $this->decisionMap[$packageId] < 0 && $literal > 0)
  5167. );
  5168. }
  5169. public function decided($literalOrPackageId)
  5170. {
  5171. return !empty($this->decisionMap[abs($literalOrPackageId)]);
  5172. }
  5173. public function undecided($literalOrPackageId)
  5174. {
  5175. return empty($this->decisionMap[abs($literalOrPackageId)]);
  5176. }
  5177. public function decidedInstall($literalOrPackageId)
  5178. {
  5179. $packageId = abs($literalOrPackageId);
  5180. return isset($this->decisionMap[$packageId]) && $this->decisionMap[$packageId] > 0;
  5181. }
  5182. public function decisionLevel($literalOrPackageId)
  5183. {
  5184. $packageId = abs($literalOrPackageId);
  5185. if (isset($this->decisionMap[$packageId])) {
  5186. return abs($this->decisionMap[$packageId]);
  5187. }
  5188. return 0;
  5189. }
  5190. public function decisionRule($literalOrPackageId)
  5191. {
  5192. $packageId = abs($literalOrPackageId);
  5193. foreach ($this->decisionQueue as $i => $decision) {
  5194. if ($packageId === abs($decision[self::DECISION_LITERAL])) {
  5195. return $decision[self::DECISION_REASON];
  5196. }
  5197. }
  5198. return null;
  5199. }
  5200. public function atOffset($queueOffset)
  5201. {
  5202. return $this->decisionQueue[$queueOffset];
  5203. }
  5204. public function validOffset($queueOffset)
  5205. {
  5206. return $queueOffset >= 0 && $queueOffset < count($this->decisionQueue);
  5207. }
  5208. public function lastReason()
  5209. {
  5210. return $this->decisionQueue[count($this->decisionQueue) - 1][self::DECISION_REASON];
  5211. }
  5212. public function lastLiteral()
  5213. {
  5214. return $this->decisionQueue[count($this->decisionQueue) - 1][self::DECISION_LITERAL];
  5215. }
  5216. public function reset()
  5217. {
  5218. while ($decision = array_pop($this->decisionQueue)) {
  5219. $this->decisionMap[abs($decision[self::DECISION_LITERAL])] = 0;
  5220. }
  5221. }
  5222. public function resetToOffset($offset)
  5223. {
  5224. while (count($this->decisionQueue) > $offset + 1) {
  5225. $decision = array_pop($this->decisionQueue);
  5226. $this->decisionMap[abs($decision[self::DECISION_LITERAL])] = 0;
  5227. }
  5228. }
  5229. public function revertLast()
  5230. {
  5231. $this->decisionMap[abs($this->lastLiteral())] = 0;
  5232. array_pop($this->decisionQueue);
  5233. }
  5234. public function count()
  5235. {
  5236. return count($this->decisionQueue);
  5237. }
  5238. public function rewind()
  5239. {
  5240. end($this->decisionQueue);
  5241. }
  5242. public function current()
  5243. {
  5244. return current($this->decisionQueue);
  5245. }
  5246. public function key()
  5247. {
  5248. return key($this->decisionQueue);
  5249. }
  5250. public function next()
  5251. {
  5252. return prev($this->decisionQueue);
  5253. }
  5254. public function valid()
  5255. {
  5256. return false !== current($this->decisionQueue);
  5257. }
  5258. public function isEmpty()
  5259. {
  5260. return count($this->decisionQueue) === 0;
  5261. }
  5262. protected function addDecision($literal, $level)
  5263. {
  5264. $packageId = abs($literal);
  5265. $previousDecision = isset($this->decisionMap[$packageId]) ? $this->decisionMap[$packageId] : null;
  5266. if ($previousDecision != 0) {
  5267. $literalString = $this->pool->literalToString($literal);
  5268. $package = $this->pool->literalToPackage($literal);
  5269. throw new SolverBugException(
  5270. "Trying to decide $literalString on level $level, even though $package was previously decided as ".(int) $previousDecision."."
  5271. );
  5272. }
  5273. if ($literal > 0) {
  5274. $this->decisionMap[$packageId] = $level;
  5275. } else {
  5276. $this->decisionMap[$packageId] = -$level;
  5277. }
  5278. }
  5279. }
  5280. <?php
  5281. namespace Composer\DependencyResolver;
  5282. use Composer\Package\PackageInterface;
  5283. use Composer\Package\AliasPackage;
  5284. use Composer\Package\BasePackage;
  5285. use Composer\Semver\Constraint\Constraint;
  5286. class DefaultPolicy implements PolicyInterface
  5287. {
  5288. private $preferStable;
  5289. private $preferLowest;
  5290. public function __construct($preferStable = false, $preferLowest = false)
  5291. {
  5292. $this->preferStable = $preferStable;
  5293. $this->preferLowest = $preferLowest;
  5294. }
  5295. public function versionCompare(PackageInterface $a, PackageInterface $b, $operator)
  5296. {
  5297. if ($this->preferStable && ($stabA = $a->getStability()) !== ($stabB = $b->getStability())) {
  5298. return BasePackage::$stabilities[$stabA] < BasePackage::$stabilities[$stabB];
  5299. }
  5300. $constraint = new Constraint($operator, $b->getVersion());
  5301. $version = new Constraint('==', $a->getVersion());
  5302. return $constraint->matchSpecific($version, true);
  5303. }
  5304. public function findUpdatePackages(Pool $pool, array $installedMap, PackageInterface $package, $mustMatchName = false)
  5305. {
  5306. $packages = array();
  5307. foreach ($pool->whatProvides($package->getName(), null, $mustMatchName) as $candidate) {
  5308. if ($candidate !== $package) {
  5309. $packages[] = $candidate;
  5310. }
  5311. }
  5312. return $packages;
  5313. }
  5314. public function getPriority(Pool $pool, PackageInterface $package)
  5315. {
  5316. return $pool->getPriority($package->getRepository());
  5317. }
  5318. public function selectPreferedPackages(Pool $pool, array $installedMap, array $literals, $requiredPackage = null)
  5319. {
  5320. return $this->selectPreferredPackages($pool, $installedMap, $literals, $requiredPackage);
  5321. }
  5322. public function selectPreferredPackages(Pool $pool, array $installedMap, array $literals, $requiredPackage = null)
  5323. {
  5324. $packages = $this->groupLiteralsByNamePreferInstalled($pool, $installedMap, $literals);
  5325. foreach ($packages as &$literals) {
  5326. $policy = $this;
  5327. usort($literals, function ($a, $b) use ($policy, $pool, $installedMap, $requiredPackage) {
  5328. return $policy->compareByPriorityPreferInstalled($pool, $installedMap, $pool->literalToPackage($a), $pool->literalToPackage($b), $requiredPackage, true);
  5329. });
  5330. }
  5331. foreach ($packages as &$literals) {
  5332. $literals = $this->pruneToHighestPriorityOrInstalled($pool, $installedMap, $literals);
  5333. $literals = $this->pruneToBestVersion($pool, $literals);
  5334. $literals = $this->pruneRemoteAliases($pool, $literals);
  5335. }
  5336. $selected = call_user_func_array('array_merge', $packages);
  5337. usort($selected, function ($a, $b) use ($policy, $pool, $installedMap, $requiredPackage) {
  5338. return $policy->compareByPriorityPreferInstalled($pool, $installedMap, $pool->literalToPackage($a), $pool->literalToPackage($b), $requiredPackage);
  5339. });
  5340. return $selected;
  5341. }
  5342. protected function groupLiteralsByNamePreferInstalled(Pool $pool, array $installedMap, $literals)
  5343. {
  5344. $packages = array();
  5345. foreach ($literals as $literal) {
  5346. $packageName = $pool->literalToPackage($literal)->getName();
  5347. if (!isset($packages[$packageName])) {
  5348. $packages[$packageName] = array();
  5349. }
  5350. if (isset($installedMap[abs($literal)])) {
  5351. array_unshift($packages[$packageName], $literal);
  5352. } else {
  5353. $packages[$packageName][] = $literal;
  5354. }
  5355. }
  5356. return $packages;
  5357. }
  5358. public function compareByPriorityPreferInstalled(Pool $pool, array $installedMap, PackageInterface $a, PackageInterface $b, $requiredPackage = null, $ignoreReplace = false)
  5359. {
  5360. if ($a->getRepository() === $b->getRepository()) {
  5361. if ($a->getName() === $b->getName()) {
  5362. $aAliased = $a instanceof AliasPackage;
  5363. $bAliased = $b instanceof AliasPackage;
  5364. if ($aAliased && !$bAliased) {
  5365. return -1;
  5366. }
  5367. if (!$aAliased && $bAliased) {
  5368. return 1;
  5369. }
  5370. }
  5371. if (!$ignoreReplace) {
  5372. if ($this->replaces($a, $b)) {
  5373. return 1;
  5374. }
  5375. if ($this->replaces($b, $a)) {
  5376. return -1;
  5377. }
  5378. if ($requiredPackage && false !== ($pos = strpos($requiredPackage, '/'))) {
  5379. $requiredVendor = substr($requiredPackage, 0, $pos);
  5380. $aIsSameVendor = substr($a->getName(), 0, $pos) === $requiredVendor;
  5381. $bIsSameVendor = substr($b->getName(), 0, $pos) === $requiredVendor;
  5382. if ($bIsSameVendor !== $aIsSameVendor) {
  5383. return $aIsSameVendor ? -1 : 1;
  5384. }
  5385. }
  5386. }
  5387. if ($a->id === $b->id) {
  5388. return 0;
  5389. }
  5390. return ($a->id < $b->id) ? -1 : 1;
  5391. }
  5392. if (isset($installedMap[$a->id])) {
  5393. return -1;
  5394. }
  5395. if (isset($installedMap[$b->id])) {
  5396. return 1;
  5397. }
  5398. return ($this->getPriority($pool, $a) > $this->getPriority($pool, $b)) ? -1 : 1;
  5399. }
  5400. protected function replaces(PackageInterface $source, PackageInterface $target)
  5401. {
  5402. foreach ($source->getReplaces() as $link) {
  5403. if ($link->getTarget() === $target->getName()
  5404. ) {
  5405. return true;
  5406. }
  5407. }
  5408. return false;
  5409. }
  5410. protected function pruneToBestVersion(Pool $pool, $literals)
  5411. {
  5412. $operator = $this->preferLowest ? '<' : '>';
  5413. $bestLiterals = array($literals[0]);
  5414. $bestPackage = $pool->literalToPackage($literals[0]);
  5415. foreach ($literals as $i => $literal) {
  5416. if (0 === $i) {
  5417. continue;
  5418. }
  5419. $package = $pool->literalToPackage($literal);
  5420. if ($this->versionCompare($package, $bestPackage, $operator)) {
  5421. $bestPackage = $package;
  5422. $bestLiterals = array($literal);
  5423. } elseif ($this->versionCompare($package, $bestPackage, '==')) {
  5424. $bestLiterals[] = $literal;
  5425. }
  5426. }
  5427. return $bestLiterals;
  5428. }
  5429. protected function pruneToHighestPriorityOrInstalled(Pool $pool, array $installedMap, array $literals)
  5430. {
  5431. $selected = array();
  5432. $priority = null;
  5433. foreach ($literals as $literal) {
  5434. $package = $pool->literalToPackage($literal);
  5435. if (isset($installedMap[$package->id])) {
  5436. $selected[] = $literal;
  5437. continue;
  5438. }
  5439. if (null === $priority) {
  5440. $priority = $this->getPriority($pool, $package);
  5441. }
  5442. if ($this->getPriority($pool, $package) != $priority) {
  5443. break;
  5444. }
  5445. $selected[] = $literal;
  5446. }
  5447. return $selected;
  5448. }
  5449. protected function pruneRemoteAliases(Pool $pool, array $literals)
  5450. {
  5451. $hasLocalAlias = false;
  5452. foreach ($literals as $literal) {
  5453. $package = $pool->literalToPackage($literal);
  5454. if ($package instanceof AliasPackage && $package->isRootPackageAlias()) {
  5455. $hasLocalAlias = true;
  5456. break;
  5457. }
  5458. }
  5459. if (!$hasLocalAlias) {
  5460. return $literals;
  5461. }
  5462. $selected = array();
  5463. foreach ($literals as $literal) {
  5464. $package = $pool->literalToPackage($literal);
  5465. if ($package instanceof AliasPackage && $package->isRootPackageAlias()) {
  5466. $selected[] = $literal;
  5467. }
  5468. }
  5469. return $selected;
  5470. }
  5471. }
  5472. <?php
  5473. namespace Composer\DependencyResolver\Operation;
  5474. use Composer\Package\PackageInterface;
  5475. class InstallOperation extends SolverOperation
  5476. {
  5477. protected $package;
  5478. public function __construct(PackageInterface $package, $reason = null)
  5479. {
  5480. parent::__construct($reason);
  5481. $this->package = $package;
  5482. }
  5483. public function getPackage()
  5484. {
  5485. return $this->package;
  5486. }
  5487. public function getJobType()
  5488. {
  5489. return 'install';
  5490. }
  5491. public function __toString()
  5492. {
  5493. return 'Installing '.$this->package->getPrettyName().' ('.$this->formatVersion($this->package).')';
  5494. }
  5495. }
  5496. <?php
  5497. namespace Composer\DependencyResolver\Operation;
  5498. use Composer\Package\AliasPackage;
  5499. use Composer\Package\PackageInterface;
  5500. class MarkAliasInstalledOperation extends SolverOperation
  5501. {
  5502. protected $package;
  5503. public function __construct(AliasPackage $package, $reason = null)
  5504. {
  5505. parent::__construct($reason);
  5506. $this->package = $package;
  5507. }
  5508. public function getPackage()
  5509. {
  5510. return $this->package;
  5511. }
  5512. public function getJobType()
  5513. {
  5514. return 'markAliasInstalled';
  5515. }
  5516. public function __toString()
  5517. {
  5518. return 'Marking '.$this->package->getPrettyName().' ('.$this->formatVersion($this->package).') as installed, alias of '.$this->package->getAliasOf()->getPrettyName().' ('.$this->formatVersion($this->package->getAliasOf()).')';
  5519. }
  5520. }
  5521. <?php
  5522. namespace Composer\DependencyResolver\Operation;
  5523. use Composer\Package\AliasPackage;
  5524. use Composer\Package\PackageInterface;
  5525. class MarkAliasUninstalledOperation extends SolverOperation
  5526. {
  5527. protected $package;
  5528. public function __construct(AliasPackage $package, $reason = null)
  5529. {
  5530. parent::__construct($reason);
  5531. $this->package = $package;
  5532. }
  5533. public function getPackage()
  5534. {
  5535. return $this->package;
  5536. }
  5537. public function getJobType()
  5538. {
  5539. return 'markAliasUninstalled';
  5540. }
  5541. public function __toString()
  5542. {
  5543. return 'Marking '.$this->package->getPrettyName().' ('.$this->formatVersion($this->package).') as uninstalled, alias of '.$this->package->getAliasOf()->getPrettyName().' ('.$this->formatVersion($this->package->getAliasOf()).')';
  5544. }
  5545. }
  5546. <?php
  5547. namespace Composer\DependencyResolver\Operation;
  5548. interface OperationInterface
  5549. {
  5550. public function getJobType();
  5551. public function getReason();
  5552. public function __toString();
  5553. }
  5554. <?php
  5555. namespace Composer\DependencyResolver\Operation;
  5556. use Composer\Package\PackageInterface;
  5557. abstract class SolverOperation implements OperationInterface
  5558. {
  5559. protected $reason;
  5560. public function __construct($reason = null)
  5561. {
  5562. $this->reason = $reason;
  5563. }
  5564. public function getReason()
  5565. {
  5566. return $this->reason;
  5567. }
  5568. protected function formatVersion(PackageInterface $package)
  5569. {
  5570. return $package->getFullPrettyVersion();
  5571. }
  5572. }
  5573. <?php
  5574. namespace Composer\DependencyResolver\Operation;
  5575. use Composer\Package\PackageInterface;
  5576. class UninstallOperation extends SolverOperation
  5577. {
  5578. protected $package;
  5579. public function __construct(PackageInterface $package, $reason = null)
  5580. {
  5581. parent::__construct($reason);
  5582. $this->package = $package;
  5583. }
  5584. public function getPackage()
  5585. {
  5586. return $this->package;
  5587. }
  5588. public function getJobType()
  5589. {
  5590. return 'uninstall';
  5591. }
  5592. public function __toString()
  5593. {
  5594. return 'Uninstalling '.$this->package->getPrettyName().' ('.$this->formatVersion($this->package).')';
  5595. }
  5596. }
  5597. <?php
  5598. namespace Composer\DependencyResolver\Operation;
  5599. use Composer\Package\PackageInterface;
  5600. class UpdateOperation extends SolverOperation
  5601. {
  5602. protected $initialPackage;
  5603. protected $targetPackage;
  5604. public function __construct(PackageInterface $initial, PackageInterface $target, $reason = null)
  5605. {
  5606. parent::__construct($reason);
  5607. $this->initialPackage = $initial;
  5608. $this->targetPackage = $target;
  5609. }
  5610. public function getInitialPackage()
  5611. {
  5612. return $this->initialPackage;
  5613. }
  5614. public function getTargetPackage()
  5615. {
  5616. return $this->targetPackage;
  5617. }
  5618. public function getJobType()
  5619. {
  5620. return 'update';
  5621. }
  5622. public function __toString()
  5623. {
  5624. return 'Updating '.$this->initialPackage->getPrettyName().' ('.$this->formatVersion($this->initialPackage).') to '.
  5625. $this->targetPackage->getPrettyName(). ' ('.$this->formatVersion($this->targetPackage).')';
  5626. }
  5627. }
  5628. <?php
  5629. namespace Composer\DependencyResolver;
  5630. use Composer\Package\PackageInterface;
  5631. interface PolicyInterface
  5632. {
  5633. public function versionCompare(PackageInterface $a, PackageInterface $b, $operator);
  5634. public function findUpdatePackages(Pool $pool, array $installedMap, PackageInterface $package);
  5635. public function selectPreferredPackages(Pool $pool, array $installedMap, array $literals);
  5636. }
  5637. <?php
  5638. namespace Composer\DependencyResolver;
  5639. use Composer\Package\BasePackage;
  5640. use Composer\Package\AliasPackage;
  5641. use Composer\Semver\VersionParser;
  5642. use Composer\Semver\Constraint\ConstraintInterface;
  5643. use Composer\Semver\Constraint\Constraint;
  5644. use Composer\Semver\Constraint\EmptyConstraint;
  5645. use Composer\Repository\RepositoryInterface;
  5646. use Composer\Repository\CompositeRepository;
  5647. use Composer\Repository\ComposerRepository;
  5648. use Composer\Repository\InstalledRepositoryInterface;
  5649. use Composer\Repository\PlatformRepository;
  5650. use Composer\Package\PackageInterface;
  5651. class Pool implements \Countable
  5652. {
  5653. const MATCH_NAME = -1;
  5654. const MATCH_NONE = 0;
  5655. const MATCH = 1;
  5656. const MATCH_PROVIDE = 2;
  5657. const MATCH_REPLACE = 3;
  5658. const MATCH_FILTERED = 4;
  5659. protected $repositories = array();
  5660. protected $providerRepos = array();
  5661. protected $packages = array();
  5662. protected $packageByName = array();
  5663. protected $packageByExactName = array();
  5664. protected $acceptableStabilities;
  5665. protected $stabilityFlags;
  5666. protected $versionParser;
  5667. protected $providerCache = array();
  5668. protected $filterRequires;
  5669. protected $whitelist = null;
  5670. protected $id = 1;
  5671. public function __construct($minimumStability = 'stable', array $stabilityFlags = array(), array $filterRequires = array())
  5672. {
  5673. $this->versionParser = new VersionParser;
  5674. $this->acceptableStabilities = array();
  5675. foreach (BasePackage::$stabilities as $stability => $value) {
  5676. if ($value <= BasePackage::$stabilities[$minimumStability]) {
  5677. $this->acceptableStabilities[$stability] = $value;
  5678. }
  5679. }
  5680. $this->stabilityFlags = $stabilityFlags;
  5681. $this->filterRequires = $filterRequires;
  5682. foreach ($filterRequires as $name => $constraint) {
  5683. if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $name)) {
  5684. unset($this->filterRequires[$name]);
  5685. }
  5686. }
  5687. }
  5688. public function setWhitelist($whitelist)
  5689. {
  5690. $this->whitelist = $whitelist;
  5691. $this->providerCache = array();
  5692. }
  5693. public function addRepository(RepositoryInterface $repo, $rootAliases = array())
  5694. {
  5695. if ($repo instanceof CompositeRepository) {
  5696. $repos = $repo->getRepositories();
  5697. } else {
  5698. $repos = array($repo);
  5699. }
  5700. foreach ($repos as $repo) {
  5701. $this->repositories[] = $repo;
  5702. $exempt = $repo instanceof PlatformRepository || $repo instanceof InstalledRepositoryInterface;
  5703. if ($repo instanceof ComposerRepository && $repo->hasProviders()) {
  5704. $this->providerRepos[] = $repo;
  5705. $repo->setRootAliases($rootAliases);
  5706. $repo->resetPackageIds();
  5707. } else {
  5708. foreach ($repo->getPackages() as $package) {
  5709. $names = $package->getNames();
  5710. $stability = $package->getStability();
  5711. if ($exempt || $this->isPackageAcceptable($names, $stability)) {
  5712. $package->setId($this->id++);
  5713. $this->packages[] = $package;
  5714. $this->packageByExactName[$package->getName()][$package->id] = $package;
  5715. foreach ($names as $provided) {
  5716. $this->packageByName[$provided][] = $package;
  5717. }
  5718. $name = $package->getName();
  5719. if (isset($rootAliases[$name][$package->getVersion()])) {
  5720. $alias = $rootAliases[$name][$package->getVersion()];
  5721. if ($package instanceof AliasPackage) {
  5722. $package = $package->getAliasOf();
  5723. }
  5724. $aliasPackage = new AliasPackage($package, $alias['alias_normalized'], $alias['alias']);
  5725. $aliasPackage->setRootPackageAlias(true);
  5726. $aliasPackage->setId($this->id++);
  5727. $package->getRepository()->addPackage($aliasPackage);
  5728. $this->packages[] = $aliasPackage;
  5729. $this->packageByExactName[$aliasPackage->getName()][$aliasPackage->id] = $aliasPackage;
  5730. foreach ($aliasPackage->getNames() as $name) {
  5731. $this->packageByName[$name][] = $aliasPackage;
  5732. }
  5733. }
  5734. }
  5735. }
  5736. }
  5737. }
  5738. }
  5739. public function getPriority(RepositoryInterface $repo)
  5740. {
  5741. $priority = array_search($repo, $this->repositories, true);
  5742. if (false === $priority) {
  5743. throw new \RuntimeException("Could not determine repository priority. The repository was not registered in the pool.");
  5744. }
  5745. return -$priority;
  5746. }
  5747. public function packageById($id)
  5748. {
  5749. return $this->packages[$id - 1];
  5750. }
  5751. public function count()
  5752. {
  5753. return count($this->packages);
  5754. }
  5755. public function whatProvides($name, ConstraintInterface $constraint = null, $mustMatchName = false)
  5756. {
  5757. $key = ((int) $mustMatchName).$constraint;
  5758. if (isset($this->providerCache[$name][$key])) {
  5759. return $this->providerCache[$name][$key];
  5760. }
  5761. return $this->providerCache[$name][$key] = $this->computeWhatProvides($name, $constraint, $mustMatchName);
  5762. }
  5763. private function computeWhatProvides($name, $constraint, $mustMatchName = false)
  5764. {
  5765. $candidates = array();
  5766. foreach ($this->providerRepos as $repo) {
  5767. foreach ($repo->whatProvides($this, $name) as $candidate) {
  5768. $candidates[] = $candidate;
  5769. if ($candidate->id < 1) {
  5770. $candidate->setId($this->id++);
  5771. $this->packages[$this->id - 2] = $candidate;
  5772. }
  5773. }
  5774. }
  5775. if ($mustMatchName) {
  5776. $candidates = array_filter($candidates, function ($candidate) use ($name) {
  5777. return $candidate->getName() == $name;
  5778. });
  5779. if (isset($this->packageByExactName[$name])) {
  5780. $candidates = array_merge($candidates, $this->packageByExactName[$name]);
  5781. }
  5782. } elseif (isset($this->packageByName[$name])) {
  5783. $candidates = array_merge($candidates, $this->packageByName[$name]);
  5784. }
  5785. $matches = $provideMatches = array();
  5786. $nameMatch = false;
  5787. foreach ($candidates as $candidate) {
  5788. $aliasOfCandidate = null;
  5789. if ($candidate instanceof AliasPackage) {
  5790. $aliasOfCandidate = $candidate->getAliasOf();
  5791. }
  5792. if ($this->whitelist !== null && (
  5793. (!($candidate instanceof AliasPackage) && !isset($this->whitelist[$candidate->id])) ||
  5794. ($candidate instanceof AliasPackage && !isset($this->whitelist[$aliasOfCandidate->id]))
  5795. )) {
  5796. continue;
  5797. }
  5798. switch ($this->match($candidate, $name, $constraint)) {
  5799. case self::MATCH_NONE:
  5800. break;
  5801. case self::MATCH_NAME:
  5802. $nameMatch = true;
  5803. break;
  5804. case self::MATCH:
  5805. $nameMatch = true;
  5806. $matches[] = $candidate;
  5807. break;
  5808. case self::MATCH_PROVIDE:
  5809. $provideMatches[] = $candidate;
  5810. break;
  5811. case self::MATCH_REPLACE:
  5812. $matches[] = $candidate;
  5813. break;
  5814. case self::MATCH_FILTERED:
  5815. break;
  5816. default:
  5817. throw new \UnexpectedValueException('Unexpected match type');
  5818. }
  5819. }
  5820. if ($nameMatch) {
  5821. return $matches;
  5822. }
  5823. return array_merge($matches, $provideMatches);
  5824. }
  5825. public function literalToPackage($literal)
  5826. {
  5827. $packageId = abs($literal);
  5828. return $this->packageById($packageId);
  5829. }
  5830. public function literalToPrettyString($literal, $installedMap)
  5831. {
  5832. $package = $this->literalToPackage($literal);
  5833. if (isset($installedMap[$package->id])) {
  5834. $prefix = ($literal > 0 ? 'keep' : 'remove');
  5835. } else {
  5836. $prefix = ($literal > 0 ? 'install' : 'don\'t install');
  5837. }
  5838. return $prefix.' '.$package->getPrettyString();
  5839. }
  5840. public function isPackageAcceptable($name, $stability)
  5841. {
  5842. foreach ((array) $name as $n) {
  5843. if (!isset($this->stabilityFlags[$n]) && isset($this->acceptableStabilities[$stability])) {
  5844. return true;
  5845. }
  5846. if (isset($this->stabilityFlags[$n]) && BasePackage::$stabilities[$stability] <= $this->stabilityFlags[$n]) {
  5847. return true;
  5848. }
  5849. }
  5850. return false;
  5851. }
  5852. private function match($candidate, $name, ConstraintInterface $constraint = null)
  5853. {
  5854. $candidateName = $candidate->getName();
  5855. $candidateVersion = $candidate->getVersion();
  5856. $isDev = $candidate->getStability() === 'dev';
  5857. $isAlias = $candidate instanceof AliasPackage;
  5858. if (!$isDev && !$isAlias && isset($this->filterRequires[$name])) {
  5859. $requireFilter = $this->filterRequires[$name];
  5860. } else {
  5861. $requireFilter = new EmptyConstraint;
  5862. }
  5863. if ($candidateName === $name) {
  5864. $pkgConstraint = new Constraint('==', $candidateVersion);
  5865. if ($constraint === null || $constraint->matches($pkgConstraint)) {
  5866. return $requireFilter->matches($pkgConstraint) ? self::MATCH : self::MATCH_FILTERED;
  5867. }
  5868. return self::MATCH_NAME;
  5869. }
  5870. $provides = $candidate->getProvides();
  5871. $replaces = $candidate->getReplaces();
  5872. if (isset($replaces[0]) || isset($provides[0])) {
  5873. foreach ($provides as $link) {
  5874. if ($link->getTarget() === $name && ($constraint === null || $constraint->matches($link->getConstraint()))) {
  5875. return $requireFilter->matches($link->getConstraint()) ? self::MATCH_PROVIDE : self::MATCH_FILTERED;
  5876. }
  5877. }
  5878. foreach ($replaces as $link) {
  5879. if ($link->getTarget() === $name && ($constraint === null || $constraint->matches($link->getConstraint()))) {
  5880. return $requireFilter->matches($link->getConstraint()) ? self::MATCH_REPLACE : self::MATCH_FILTERED;
  5881. }
  5882. }
  5883. return self::MATCH_NONE;
  5884. }
  5885. if (isset($provides[$name]) && ($constraint === null || $constraint->matches($provides[$name]->getConstraint()))) {
  5886. return $requireFilter->matches($provides[$name]->getConstraint()) ? self::MATCH_PROVIDE : self::MATCH_FILTERED;
  5887. }
  5888. if (isset($replaces[$name]) && ($constraint === null || $constraint->matches($replaces[$name]->getConstraint()))) {
  5889. return $requireFilter->matches($replaces[$name]->getConstraint()) ? self::MATCH_REPLACE : self::MATCH_FILTERED;
  5890. }
  5891. return self::MATCH_NONE;
  5892. }
  5893. }
  5894. <?php
  5895. namespace Composer\DependencyResolver;
  5896. class Problem
  5897. {
  5898. protected $reasonSeen;
  5899. protected $reasons = array();
  5900. protected $section = 0;
  5901. protected $pool;
  5902. public function __construct(Pool $pool)
  5903. {
  5904. $this->pool = $pool;
  5905. }
  5906. public function addRule(Rule $rule)
  5907. {
  5908. $this->addReason(spl_object_hash($rule), array(
  5909. 'rule' => $rule,
  5910. 'job' => $rule->getJob(),
  5911. ));
  5912. }
  5913. public function getReasons()
  5914. {
  5915. return $this->reasons;
  5916. }
  5917. public function getPrettyString(array $installedMap = array())
  5918. {
  5919. $reasons = call_user_func_array('array_merge', array_reverse($this->reasons));
  5920. if (count($reasons) === 1) {
  5921. reset($reasons);
  5922. $reason = current($reasons);
  5923. $rule = $reason['rule'];
  5924. $job = $reason['job'];
  5925. if (isset($job['constraint'])) {
  5926. $packages = $this->pool->whatProvides($job['packageName'], $job['constraint']);
  5927. } else {
  5928. $packages = array();
  5929. }
  5930. if ($job && $job['cmd'] === 'install' && empty($packages)) {
  5931. if ($job['packageName'] === 'php' || $job['packageName'] === 'php-64bit' || $job['packageName'] === 'hhvm') {
  5932. $available = $this->pool->whatProvides($job['packageName']);
  5933. $version = count($available) ? $available[0]->getPrettyVersion() : phpversion();
  5934. $msg = "\n - This package requires ".$job['packageName'].$this->constraintToText($job['constraint']).' but ';
  5935. if (defined('HHVM_VERSION')) {
  5936. return $msg . 'your HHVM version does not satisfy that requirement.';
  5937. } elseif ($job['packageName'] === 'hhvm') {
  5938. return $msg . 'you are running this with PHP and not HHVM.';
  5939. }
  5940. return $msg . 'your PHP version ('. $version .') does not satisfy that requirement.';
  5941. }
  5942. if (0 === stripos($job['packageName'], 'ext-')) {
  5943. $ext = substr($job['packageName'], 4);
  5944. $error = extension_loaded($ext) ? 'has the wrong version ('.(phpversion($ext) ?: '0').') installed' : 'is missing from your system';
  5945. return "\n - The requested PHP extension ".$job['packageName'].$this->constraintToText($job['constraint']).' '.$error.'.';
  5946. }
  5947. if (0 === stripos($job['packageName'], 'lib-')) {
  5948. if (strtolower($job['packageName']) === 'lib-icu') {
  5949. $error = extension_loaded('intl') ? 'has the wrong version installed, try upgrading the intl extension.' : 'is missing from your system, make sure the intl extension is loaded.';
  5950. return "\n - The requested linked library ".$job['packageName'].$this->constraintToText($job['constraint']).' '.$error;
  5951. }
  5952. return "\n - The requested linked library ".$job['packageName'].$this->constraintToText($job['constraint']).' has the wrong version installed or is missing from your system, make sure to load the extension providing it.';
  5953. }
  5954. if (!preg_match('{^[A-Za-z0-9_./-]+$}', $job['packageName'])) {
  5955. $illegalChars = preg_replace('{[A-Za-z0-9_./-]+}', '', $job['packageName']);
  5956. return "\n - The requested package ".$job['packageName'].' could not be found, it looks like its name is invalid, "'.$illegalChars.'" is not allowed in package names.';
  5957. }
  5958. if (!$this->pool->whatProvides($job['packageName'])) {
  5959. return "\n - The requested package ".$job['packageName'].' could not be found in any version, there may be a typo in the package name.';
  5960. }
  5961. return "\n - The requested package ".$job['packageName'].$this->constraintToText($job['constraint']).' could not be found.';
  5962. }
  5963. }
  5964. $messages = array();
  5965. foreach ($reasons as $reason) {
  5966. $rule = $reason['rule'];
  5967. $job = $reason['job'];
  5968. if ($job) {
  5969. $messages[] = $this->jobToText($job);
  5970. } elseif ($rule) {
  5971. if ($rule instanceof Rule) {
  5972. $messages[] = $rule->getPrettyString($this->pool, $installedMap);
  5973. }
  5974. }
  5975. }
  5976. return "\n - ".implode("\n - ", $messages);
  5977. }
  5978. protected function addReason($id, $reason)
  5979. {
  5980. if (!isset($this->reasonSeen[$id])) {
  5981. $this->reasonSeen[$id] = true;
  5982. $this->reasons[$this->section][] = $reason;
  5983. }
  5984. }
  5985. public function nextSection()
  5986. {
  5987. $this->section++;
  5988. }
  5989. protected function jobToText($job)
  5990. {
  5991. switch ($job['cmd']) {
  5992. case 'install':
  5993. $packages = $this->pool->whatProvides($job['packageName'], $job['constraint']);
  5994. if (!$packages) {
  5995. return 'No package found to satisfy install request for '.$job['packageName'].$this->constraintToText($job['constraint']);
  5996. }
  5997. return 'Installation request for '.$job['packageName'].$this->constraintToText($job['constraint']).' -> satisfiable by '.$this->getPackageList($packages).'.';
  5998. case 'update':
  5999. return 'Update request for '.$job['packageName'].$this->constraintToText($job['constraint']).'.';
  6000. case 'remove':
  6001. return 'Removal request for '.$job['packageName'].$this->constraintToText($job['constraint']).'';
  6002. }
  6003. if (isset($job['constraint'])) {
  6004. $packages = $this->pool->whatProvides($job['packageName'], $job['constraint']);
  6005. } else {
  6006. $packages = array();
  6007. }
  6008. return 'Job(cmd='.$job['cmd'].', target='.$job['packageName'].', packages=['.$this->getPackageList($packages).'])';
  6009. }
  6010. protected function getPackageList($packages)
  6011. {
  6012. $prepared = array();
  6013. foreach ($packages as $package) {
  6014. $prepared[$package->getName()]['name'] = $package->getPrettyName();
  6015. $prepared[$package->getName()]['versions'][$package->getVersion()] = $package->getPrettyVersion();
  6016. }
  6017. foreach ($prepared as $name => $package) {
  6018. $prepared[$name] = $package['name'].'['.implode(', ', $package['versions']).']';
  6019. }
  6020. return implode(', ', $prepared);
  6021. }
  6022. protected function constraintToText($constraint)
  6023. {
  6024. return ($constraint) ? ' '.$constraint->getPrettyString() : '';
  6025. }
  6026. }
  6027. <?php
  6028. namespace Composer\DependencyResolver;
  6029. use Composer\Semver\Constraint\ConstraintInterface;
  6030. class Request
  6031. {
  6032. protected $jobs;
  6033. public function __construct()
  6034. {
  6035. $this->jobs = array();
  6036. }
  6037. public function install($packageName, ConstraintInterface $constraint = null)
  6038. {
  6039. $this->addJob($packageName, 'install', $constraint);
  6040. }
  6041. public function update($packageName, ConstraintInterface $constraint = null)
  6042. {
  6043. $this->addJob($packageName, 'update', $constraint);
  6044. }
  6045. public function remove($packageName, ConstraintInterface $constraint = null)
  6046. {
  6047. $this->addJob($packageName, 'remove', $constraint);
  6048. }
  6049. public function fix($packageName, ConstraintInterface $constraint = null)
  6050. {
  6051. $this->addJob($packageName, 'install', $constraint, true);
  6052. }
  6053. protected function addJob($packageName, $cmd, ConstraintInterface $constraint = null, $fixed = false)
  6054. {
  6055. $packageName = strtolower($packageName);
  6056. $this->jobs[] = array(
  6057. 'cmd' => $cmd,
  6058. 'packageName' => $packageName,
  6059. 'constraint' => $constraint,
  6060. 'fixed' => $fixed,
  6061. );
  6062. }
  6063. public function updateAll()
  6064. {
  6065. $this->jobs[] = array('cmd' => 'update-all');
  6066. }
  6067. public function getJobs()
  6068. {
  6069. return $this->jobs;
  6070. }
  6071. }
  6072. <?php
  6073. namespace Composer\DependencyResolver;
  6074. class Rule
  6075. {
  6076. const RULE_INTERNAL_ALLOW_UPDATE = 1;
  6077. const RULE_JOB_INSTALL = 2;
  6078. const RULE_JOB_REMOVE = 3;
  6079. const RULE_PACKAGE_CONFLICT = 6;
  6080. const RULE_PACKAGE_REQUIRES = 7;
  6081. const RULE_PACKAGE_OBSOLETES = 8;
  6082. const RULE_INSTALLED_PACKAGE_OBSOLETES = 9;
  6083. const RULE_PACKAGE_SAME_NAME = 10;
  6084. const RULE_PACKAGE_IMPLICIT_OBSOLETES = 11;
  6085. const RULE_LEARNED = 12;
  6086. const RULE_PACKAGE_ALIAS = 13;
  6087. const BITFIELD_TYPE = 0;
  6088. const BITFIELD_REASON = 8;
  6089. const BITFIELD_DISABLED = 16;
  6090. public $literals;
  6091. protected $bitfield;
  6092. protected $reasonData;
  6093. public function __construct(array $literals, $reason, $reasonData, $job = null)
  6094. {
  6095. sort($literals);
  6096. $this->literals = $literals;
  6097. $this->reasonData = $reasonData;
  6098. if ($job) {
  6099. $this->job = $job;
  6100. }
  6101. $this->bitfield = (0 << self::BITFIELD_DISABLED) |
  6102. ($reason << self::BITFIELD_REASON) |
  6103. (255 << self::BITFIELD_TYPE);
  6104. }
  6105. public function getHash()
  6106. {
  6107. $data = unpack('ihash', md5(implode(',', $this->literals), true));
  6108. return $data['hash'];
  6109. }
  6110. public function getJob()
  6111. {
  6112. return isset($this->job) ? $this->job : null;
  6113. }
  6114. public function getReason()
  6115. {
  6116. return ($this->bitfield & (255 << self::BITFIELD_REASON)) >> self::BITFIELD_REASON;
  6117. }
  6118. public function getReasonData()
  6119. {
  6120. return $this->reasonData;
  6121. }
  6122. public function getRequiredPackage()
  6123. {
  6124. if ($this->getReason() === self::RULE_JOB_INSTALL) {
  6125. return $this->reasonData;
  6126. }
  6127. if ($this->getReason() === self::RULE_PACKAGE_REQUIRES) {
  6128. return $this->reasonData->getTarget();
  6129. }
  6130. }
  6131. public function equals(Rule $rule)
  6132. {
  6133. if (count($this->literals) != count($rule->literals)) {
  6134. return false;
  6135. }
  6136. for ($i = 0, $n = count($this->literals); $i < $n; $i++) {
  6137. if ($this->literals[$i] !== $rule->literals[$i]) {
  6138. return false;
  6139. }
  6140. }
  6141. return true;
  6142. }
  6143. public function setType($type)
  6144. {
  6145. $this->bitfield = ($this->bitfield & ~(255 << self::BITFIELD_TYPE)) | ((255 & $type) << self::BITFIELD_TYPE);
  6146. }
  6147. public function getType()
  6148. {
  6149. return ($this->bitfield & (255 << self::BITFIELD_TYPE)) >> self::BITFIELD_TYPE;
  6150. }
  6151. public function disable()
  6152. {
  6153. $this->bitfield = ($this->bitfield & ~(255 << self::BITFIELD_DISABLED)) | (1 << self::BITFIELD_DISABLED);
  6154. }
  6155. public function enable()
  6156. {
  6157. $this->bitfield = $this->bitfield & ~(255 << self::BITFIELD_DISABLED);
  6158. }
  6159. public function isDisabled()
  6160. {
  6161. return (bool) (($this->bitfield & (255 << self::BITFIELD_DISABLED)) >> self::BITFIELD_DISABLED);
  6162. }
  6163. public function isEnabled()
  6164. {
  6165. return !(($this->bitfield & (255 << self::BITFIELD_DISABLED)) >> self::BITFIELD_DISABLED);
  6166. }
  6167. public function getLiterals()
  6168. {
  6169. return $this->literals;
  6170. }
  6171. public function isAssertion()
  6172. {
  6173. return 1 === count($this->literals);
  6174. }
  6175. public function getPrettyString(Pool $pool, array $installedMap = array())
  6176. {
  6177. $ruleText = '';
  6178. foreach ($this->literals as $i => $literal) {
  6179. if ($i != 0) {
  6180. $ruleText .= '|';
  6181. }
  6182. $ruleText .= $pool->literalToPrettyString($literal, $installedMap);
  6183. }
  6184. switch ($this->getReason()) {
  6185. case self::RULE_INTERNAL_ALLOW_UPDATE:
  6186. return $ruleText;
  6187. case self::RULE_JOB_INSTALL:
  6188. return "Install command rule ($ruleText)";
  6189. case self::RULE_JOB_REMOVE:
  6190. return "Remove command rule ($ruleText)";
  6191. case self::RULE_PACKAGE_CONFLICT:
  6192. $package1 = $pool->literalToPackage($this->literals[0]);
  6193. $package2 = $pool->literalToPackage($this->literals[1]);
  6194. return $package1->getPrettyString().' conflicts with '.$this->formatPackagesUnique($pool, array($package2)).'.';
  6195. case self::RULE_PACKAGE_REQUIRES:
  6196. $literals = $this->literals;
  6197. $sourceLiteral = array_shift($literals);
  6198. $sourcePackage = $pool->literalToPackage($sourceLiteral);
  6199. $requires = array();
  6200. foreach ($literals as $literal) {
  6201. $requires[] = $pool->literalToPackage($literal);
  6202. }
  6203. $text = $this->reasonData->getPrettyString($sourcePackage);
  6204. if ($requires) {
  6205. $text .= ' -> satisfiable by ' . $this->formatPackagesUnique($pool, $requires) . '.';
  6206. } else {
  6207. $targetName = $this->reasonData->getTarget();
  6208. if ($targetName === 'php' || $targetName === 'php-64bit' || $targetName === 'hhvm') {
  6209. if (defined('HHVM_VERSION')) {
  6210. $text .= ' -> your HHVM version does not satisfy that requirement.';
  6211. } elseif ($targetName === 'hhvm') {
  6212. $text .= ' -> you are running this with PHP and not HHVM.';
  6213. } else {
  6214. $text .= ' -> your PHP version ('. phpversion() .') or "config.platform.php" value does not satisfy that requirement.';
  6215. }
  6216. } elseif (0 === strpos($targetName, 'ext-')) {
  6217. $ext = substr($targetName, 4);
  6218. $error = extension_loaded($ext) ? 'has the wrong version ('.(phpversion($ext) ?: '0').') installed' : 'is missing from your system';
  6219. $text .= ' -> the requested PHP extension '.$ext.' '.$error.'.';
  6220. } elseif (0 === strpos($targetName, 'lib-')) {
  6221. $lib = substr($targetName, 4);
  6222. $text .= ' -> the requested linked library '.$lib.' has the wrong version installed or is missing from your system, make sure to have the extension providing it.';
  6223. } else {
  6224. $text .= ' -> no matching package found.';
  6225. }
  6226. }
  6227. return $text;
  6228. case self::RULE_PACKAGE_OBSOLETES:
  6229. return $ruleText;
  6230. case self::RULE_INSTALLED_PACKAGE_OBSOLETES:
  6231. return $ruleText;
  6232. case self::RULE_PACKAGE_SAME_NAME:
  6233. return 'Can only install one of: ' . $this->formatPackagesUnique($pool, $this->literals) . '.';
  6234. case self::RULE_PACKAGE_IMPLICIT_OBSOLETES:
  6235. return $ruleText;
  6236. case self::RULE_LEARNED:
  6237. return 'Conclusion: '.$ruleText;
  6238. case self::RULE_PACKAGE_ALIAS:
  6239. return $ruleText;
  6240. default:
  6241. return '('.$ruleText.')';
  6242. }
  6243. }
  6244. protected function formatPackagesUnique($pool, array $packages)
  6245. {
  6246. $prepared = array();
  6247. foreach ($packages as $package) {
  6248. if (!is_object($package)) {
  6249. $package = $pool->literalToPackage($package);
  6250. }
  6251. $prepared[$package->getName()]['name'] = $package->getPrettyName();
  6252. $prepared[$package->getName()]['versions'][$package->getVersion()] = $package->getPrettyVersion();
  6253. }
  6254. foreach ($prepared as $name => $package) {
  6255. $prepared[$name] = $package['name'].'['.implode(', ', $package['versions']).']';
  6256. }
  6257. return implode(', ', $prepared);
  6258. }
  6259. public function __toString()
  6260. {
  6261. $result = ($this->isDisabled()) ? 'disabled(' : '(';
  6262. foreach ($this->literals as $i => $literal) {
  6263. if ($i != 0) {
  6264. $result .= '|';
  6265. }
  6266. $result .= $literal;
  6267. }
  6268. $result .= ')';
  6269. return $result;
  6270. }
  6271. }
  6272. <?php
  6273. namespace Composer\DependencyResolver;
  6274. class RuleSet implements \IteratorAggregate, \Countable
  6275. {
  6276. const TYPE_PACKAGE = 0;
  6277. const TYPE_JOB = 1;
  6278. const TYPE_LEARNED = 4;
  6279. public $ruleById;
  6280. protected static $types = array(
  6281. 255 => 'UNKNOWN',
  6282. self::TYPE_PACKAGE => 'PACKAGE',
  6283. self::TYPE_JOB => 'JOB',
  6284. self::TYPE_LEARNED => 'LEARNED',
  6285. );
  6286. protected $rules;
  6287. protected $nextRuleId;
  6288. protected $rulesByHash;
  6289. public function __construct()
  6290. {
  6291. $this->nextRuleId = 0;
  6292. foreach ($this->getTypes() as $type) {
  6293. $this->rules[$type] = array();
  6294. }
  6295. $this->rulesByHash = array();
  6296. }
  6297. public function add(Rule $rule, $type)
  6298. {
  6299. if (!isset(self::$types[$type])) {
  6300. throw new \OutOfBoundsException('Unknown rule type: ' . $type);
  6301. }
  6302. if (!isset($this->rules[$type])) {
  6303. $this->rules[$type] = array();
  6304. }
  6305. $this->rules[$type][] = $rule;
  6306. $this->ruleById[$this->nextRuleId] = $rule;
  6307. $rule->setType($type);
  6308. $this->nextRuleId++;
  6309. $hash = $rule->getHash();
  6310. if (!isset($this->rulesByHash[$hash])) {
  6311. $this->rulesByHash[$hash] = array($rule);
  6312. } else {
  6313. $this->rulesByHash[$hash][] = $rule;
  6314. }
  6315. }
  6316. public function count()
  6317. {
  6318. return $this->nextRuleId;
  6319. }
  6320. public function ruleById($id)
  6321. {
  6322. return $this->ruleById[$id];
  6323. }
  6324. public function getRules()
  6325. {
  6326. return $this->rules;
  6327. }
  6328. public function getIterator()
  6329. {
  6330. return new RuleSetIterator($this->getRules());
  6331. }
  6332. public function getIteratorFor($types)
  6333. {
  6334. if (!is_array($types)) {
  6335. $types = array($types);
  6336. }
  6337. $allRules = $this->getRules();
  6338. $rules = array();
  6339. foreach ($types as $type) {
  6340. $rules[$type] = $allRules[$type];
  6341. }
  6342. return new RuleSetIterator($rules);
  6343. }
  6344. public function getIteratorWithout($types)
  6345. {
  6346. if (!is_array($types)) {
  6347. $types = array($types);
  6348. }
  6349. $rules = $this->getRules();
  6350. foreach ($types as $type) {
  6351. unset($rules[$type]);
  6352. }
  6353. return new RuleSetIterator($rules);
  6354. }
  6355. public function getTypes()
  6356. {
  6357. $types = self::$types;
  6358. unset($types[255]);
  6359. return array_keys($types);
  6360. }
  6361. public function containsEqual($rule)
  6362. {
  6363. if (isset($this->rulesByHash[$rule->getHash()])) {
  6364. $potentialDuplicates = $this->rulesByHash[$rule->getHash()];
  6365. foreach ($potentialDuplicates as $potentialDuplicate) {
  6366. if ($rule->equals($potentialDuplicate)) {
  6367. return true;
  6368. }
  6369. }
  6370. }
  6371. return false;
  6372. }
  6373. public function getPrettyString(Pool $pool = null)
  6374. {
  6375. $string = "\n";
  6376. foreach ($this->rules as $type => $rules) {
  6377. $string .= str_pad(self::$types[$type], 8, ' ') . ": ";
  6378. foreach ($rules as $rule) {
  6379. $string .= ($pool ? $rule->getPrettyString($pool) : $rule)."\n";
  6380. }
  6381. $string .= "\n\n";
  6382. }
  6383. return $string;
  6384. }
  6385. public function __toString()
  6386. {
  6387. return $this->getPrettyString(null);
  6388. }
  6389. }
  6390. <?php
  6391. namespace Composer\DependencyResolver;
  6392. use Composer\Package\PackageInterface;
  6393. use Composer\Package\AliasPackage;
  6394. use Composer\Repository\PlatformRepository;
  6395. class RuleSetGenerator
  6396. {
  6397. protected $policy;
  6398. protected $pool;
  6399. protected $rules;
  6400. protected $jobs;
  6401. protected $installedMap;
  6402. protected $whitelistedMap;
  6403. protected $addedMap;
  6404. public function __construct(PolicyInterface $policy, Pool $pool)
  6405. {
  6406. $this->policy = $policy;
  6407. $this->pool = $pool;
  6408. }
  6409. protected function createRequireRule(PackageInterface $package, array $providers, $reason, $reasonData = null)
  6410. {
  6411. $literals = array(-$package->id);
  6412. foreach ($providers as $provider) {
  6413. if ($provider === $package) {
  6414. return null;
  6415. }
  6416. $literals[] = $provider->id;
  6417. }
  6418. return new Rule($literals, $reason, $reasonData);
  6419. }
  6420. protected function createInstallOneOfRule(array $packages, $reason, $job)
  6421. {
  6422. $literals = array();
  6423. foreach ($packages as $package) {
  6424. $literals[] = $package->id;
  6425. }
  6426. return new Rule($literals, $reason, $job['packageName'], $job);
  6427. }
  6428. protected function createRemoveRule(PackageInterface $package, $reason, $job)
  6429. {
  6430. return new Rule(array(-$package->id), $reason, $job['packageName'], $job);
  6431. }
  6432. protected function createConflictRule(PackageInterface $issuer, PackageInterface $provider, $reason, $reasonData = null)
  6433. {
  6434. if ($issuer === $provider) {
  6435. return null;
  6436. }
  6437. return new Rule(array(-$issuer->id, -$provider->id), $reason, $reasonData);
  6438. }
  6439. private function addRule($type, Rule $newRule = null)
  6440. {
  6441. if (!$newRule || $this->rules->containsEqual($newRule)) {
  6442. return;
  6443. }
  6444. $this->rules->add($newRule, $type);
  6445. }
  6446. protected function whitelistFromPackage(PackageInterface $package)
  6447. {
  6448. $workQueue = new \SplQueue;
  6449. $workQueue->enqueue($package);
  6450. while (!$workQueue->isEmpty()) {
  6451. $package = $workQueue->dequeue();
  6452. if (isset($this->whitelistedMap[$package->id])) {
  6453. continue;
  6454. }
  6455. $this->whitelistedMap[$package->id] = true;
  6456. foreach ($package->getRequires() as $link) {
  6457. $possibleRequires = $this->pool->whatProvides($link->getTarget(), $link->getConstraint(), true);
  6458. foreach ($possibleRequires as $require) {
  6459. $workQueue->enqueue($require);
  6460. }
  6461. }
  6462. $obsoleteProviders = $this->pool->whatProvides($package->getName(), null, true);
  6463. foreach ($obsoleteProviders as $provider) {
  6464. if ($provider === $package) {
  6465. continue;
  6466. }
  6467. if (($package instanceof AliasPackage) && $package->getAliasOf() === $provider) {
  6468. $workQueue->enqueue($provider);
  6469. }
  6470. }
  6471. }
  6472. }
  6473. protected function addRulesForPackage(PackageInterface $package, $ignorePlatformReqs)
  6474. {
  6475. $workQueue = new \SplQueue;
  6476. $workQueue->enqueue($package);
  6477. while (!$workQueue->isEmpty()) {
  6478. $package = $workQueue->dequeue();
  6479. if (isset($this->addedMap[$package->id])) {
  6480. continue;
  6481. }
  6482. $this->addedMap[$package->id] = true;
  6483. foreach ($package->getRequires() as $link) {
  6484. if ($ignorePlatformReqs && preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $link->getTarget())) {
  6485. continue;
  6486. }
  6487. $possibleRequires = $this->pool->whatProvides($link->getTarget(), $link->getConstraint());
  6488. $this->addRule(RuleSet::TYPE_PACKAGE, $rule = $this->createRequireRule($package, $possibleRequires, Rule::RULE_PACKAGE_REQUIRES, $link));
  6489. foreach ($possibleRequires as $require) {
  6490. $workQueue->enqueue($require);
  6491. }
  6492. }
  6493. foreach ($package->getConflicts() as $link) {
  6494. $possibleConflicts = $this->pool->whatProvides($link->getTarget(), $link->getConstraint());
  6495. foreach ($possibleConflicts as $conflict) {
  6496. $this->addRule(RuleSet::TYPE_PACKAGE, $this->createConflictRule($package, $conflict, Rule::RULE_PACKAGE_CONFLICT, $link));
  6497. }
  6498. }
  6499. $isInstalled = (isset($this->installedMap[$package->id]));
  6500. foreach ($package->getReplaces() as $link) {
  6501. $obsoleteProviders = $this->pool->whatProvides($link->getTarget(), $link->getConstraint());
  6502. foreach ($obsoleteProviders as $provider) {
  6503. if ($provider === $package) {
  6504. continue;
  6505. }
  6506. if (!$this->obsoleteImpossibleForAlias($package, $provider)) {
  6507. $reason = ($isInstalled) ? Rule::RULE_INSTALLED_PACKAGE_OBSOLETES : Rule::RULE_PACKAGE_OBSOLETES;
  6508. $this->addRule(RuleSet::TYPE_PACKAGE, $this->createConflictRule($package, $provider, $reason, $link));
  6509. }
  6510. }
  6511. }
  6512. $obsoleteProviders = $this->pool->whatProvides($package->getName(), null);
  6513. foreach ($obsoleteProviders as $provider) {
  6514. if ($provider === $package) {
  6515. continue;
  6516. }
  6517. if (($package instanceof AliasPackage) && $package->getAliasOf() === $provider) {
  6518. $this->addRule(RuleSet::TYPE_PACKAGE, $rule = $this->createRequireRule($package, array($provider), Rule::RULE_PACKAGE_ALIAS, $package));
  6519. } elseif (!$this->obsoleteImpossibleForAlias($package, $provider)) {
  6520. $reason = ($package->getName() == $provider->getName()) ? Rule::RULE_PACKAGE_SAME_NAME : Rule::RULE_PACKAGE_IMPLICIT_OBSOLETES;
  6521. $this->addRule(RuleSet::TYPE_PACKAGE, $rule = $this->createConflictRule($package, $provider, $reason, $package));
  6522. }
  6523. }
  6524. }
  6525. }
  6526. protected function obsoleteImpossibleForAlias($package, $provider)
  6527. {
  6528. $packageIsAlias = $package instanceof AliasPackage;
  6529. $providerIsAlias = $provider instanceof AliasPackage;
  6530. $impossible = (
  6531. ($packageIsAlias && $package->getAliasOf() === $provider) ||
  6532. ($providerIsAlias && $provider->getAliasOf() === $package) ||
  6533. ($packageIsAlias && $providerIsAlias && $provider->getAliasOf() === $package->getAliasOf())
  6534. );
  6535. return $impossible;
  6536. }
  6537. protected function whitelistFromJobs()
  6538. {
  6539. foreach ($this->jobs as $job) {
  6540. switch ($job['cmd']) {
  6541. case 'install':
  6542. $packages = $this->pool->whatProvides($job['packageName'], $job['constraint'], true);
  6543. foreach ($packages as $package) {
  6544. $this->whitelistFromPackage($package);
  6545. }
  6546. break;
  6547. }
  6548. }
  6549. }
  6550. protected function addRulesForJobs($ignorePlatformReqs)
  6551. {
  6552. foreach ($this->jobs as $job) {
  6553. switch ($job['cmd']) {
  6554. case 'install':
  6555. if (!$job['fixed'] && $ignorePlatformReqs && preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $job['packageName'])) {
  6556. continue;
  6557. }
  6558. $packages = $this->pool->whatProvides($job['packageName'], $job['constraint']);
  6559. if ($packages) {
  6560. foreach ($packages as $package) {
  6561. if (!isset($this->installedMap[$package->id])) {
  6562. $this->addRulesForPackage($package, $ignorePlatformReqs);
  6563. }
  6564. }
  6565. $rule = $this->createInstallOneOfRule($packages, Rule::RULE_JOB_INSTALL, $job);
  6566. $this->addRule(RuleSet::TYPE_JOB, $rule);
  6567. }
  6568. break;
  6569. case 'remove':
  6570. $packages = $this->pool->whatProvides($job['packageName'], $job['constraint']);
  6571. foreach ($packages as $package) {
  6572. $rule = $this->createRemoveRule($package, Rule::RULE_JOB_REMOVE, $job);
  6573. $this->addRule(RuleSet::TYPE_JOB, $rule);
  6574. }
  6575. break;
  6576. }
  6577. }
  6578. }
  6579. public function getRulesFor($jobs, $installedMap, $ignorePlatformReqs = false)
  6580. {
  6581. $this->jobs = $jobs;
  6582. $this->rules = new RuleSet;
  6583. $this->installedMap = $installedMap;
  6584. $this->whitelistedMap = array();
  6585. foreach ($this->installedMap as $package) {
  6586. $this->whitelistFromPackage($package);
  6587. }
  6588. $this->whitelistFromJobs();
  6589. $this->pool->setWhitelist($this->whitelistedMap);
  6590. $this->addedMap = array();
  6591. foreach ($this->installedMap as $package) {
  6592. $this->addRulesForPackage($package, $ignorePlatformReqs);
  6593. }
  6594. $this->addRulesForJobs($ignorePlatformReqs);
  6595. return $this->rules;
  6596. }
  6597. }
  6598. <?php
  6599. namespace Composer\DependencyResolver;
  6600. class RuleSetIterator implements \Iterator
  6601. {
  6602. protected $rules;
  6603. protected $types;
  6604. protected $currentOffset;
  6605. protected $currentType;
  6606. protected $currentTypeOffset;
  6607. public function __construct(array $rules)
  6608. {
  6609. $this->rules = $rules;
  6610. $this->types = array_keys($rules);
  6611. sort($this->types);
  6612. $this->rewind();
  6613. }
  6614. public function current()
  6615. {
  6616. return $this->rules[$this->currentType][$this->currentOffset];
  6617. }
  6618. public function key()
  6619. {
  6620. return $this->currentType;
  6621. }
  6622. public function next()
  6623. {
  6624. $this->currentOffset++;
  6625. if (!isset($this->rules[$this->currentType])) {
  6626. return;
  6627. }
  6628. if ($this->currentOffset >= sizeof($this->rules[$this->currentType])) {
  6629. $this->currentOffset = 0;
  6630. do {
  6631. $this->currentTypeOffset++;
  6632. if (!isset($this->types[$this->currentTypeOffset])) {
  6633. $this->currentType = -1;
  6634. break;
  6635. }
  6636. $this->currentType = $this->types[$this->currentTypeOffset];
  6637. } while (isset($this->types[$this->currentTypeOffset]) && !sizeof($this->rules[$this->currentType]));
  6638. }
  6639. }
  6640. public function rewind()
  6641. {
  6642. $this->currentOffset = 0;
  6643. $this->currentTypeOffset = -1;
  6644. $this->currentType = -1;
  6645. do {
  6646. $this->currentTypeOffset++;
  6647. if (!isset($this->types[$this->currentTypeOffset])) {
  6648. $this->currentType = -1;
  6649. break;
  6650. }
  6651. $this->currentType = $this->types[$this->currentTypeOffset];
  6652. } while (isset($this->types[$this->currentTypeOffset]) && !sizeof($this->rules[$this->currentType]));
  6653. }
  6654. public function valid()
  6655. {
  6656. return isset($this->rules[$this->currentType])
  6657. && isset($this->rules[$this->currentType][$this->currentOffset]);
  6658. }
  6659. }
  6660. <?php
  6661. namespace Composer\DependencyResolver;
  6662. class RuleWatchChain extends \SplDoublyLinkedList
  6663. {
  6664. protected $offset = 0;
  6665. public function seek($offset)
  6666. {
  6667. $this->rewind();
  6668. for ($i = 0; $i < $offset; $i++, $this->next());
  6669. }
  6670. public function remove()
  6671. {
  6672. $offset = $this->key();
  6673. $this->offsetUnset($offset);
  6674. $this->seek($offset);
  6675. }
  6676. }
  6677. <?php
  6678. namespace Composer\DependencyResolver;
  6679. class RuleWatchGraph
  6680. {
  6681. protected $watchChains = array();
  6682. public function insert(RuleWatchNode $node)
  6683. {
  6684. if ($node->getRule()->isAssertion()) {
  6685. return;
  6686. }
  6687. foreach (array($node->watch1, $node->watch2) as $literal) {
  6688. if (!isset($this->watchChains[$literal])) {
  6689. $this->watchChains[$literal] = new RuleWatchChain;
  6690. }
  6691. $this->watchChains[$literal]->unshift($node);
  6692. }
  6693. }
  6694. public function propagateLiteral($decidedLiteral, $level, $decisions)
  6695. {
  6696. $literal = -$decidedLiteral;
  6697. if (!isset($this->watchChains[$literal])) {
  6698. return null;
  6699. }
  6700. $chain = $this->watchChains[$literal];
  6701. $chain->rewind();
  6702. while ($chain->valid()) {
  6703. $node = $chain->current();
  6704. $otherWatch = $node->getOtherWatch($literal);
  6705. if (!$node->getRule()->isDisabled() && !$decisions->satisfy($otherWatch)) {
  6706. $ruleLiterals = $node->getRule()->literals;
  6707. $alternativeLiterals = array_filter($ruleLiterals, function ($ruleLiteral) use ($literal, $otherWatch, $decisions) {
  6708. return $literal !== $ruleLiteral &&
  6709. $otherWatch !== $ruleLiteral &&
  6710. !$decisions->conflict($ruleLiteral);
  6711. });
  6712. if ($alternativeLiterals) {
  6713. reset($alternativeLiterals);
  6714. $this->moveWatch($literal, current($alternativeLiterals), $node);
  6715. continue;
  6716. }
  6717. if ($decisions->conflict($otherWatch)) {
  6718. return $node->getRule();
  6719. }
  6720. $decisions->decide($otherWatch, $level, $node->getRule());
  6721. }
  6722. $chain->next();
  6723. }
  6724. return null;
  6725. }
  6726. protected function moveWatch($fromLiteral, $toLiteral, $node)
  6727. {
  6728. if (!isset($this->watchChains[$toLiteral])) {
  6729. $this->watchChains[$toLiteral] = new RuleWatchChain;
  6730. }
  6731. $node->moveWatch($fromLiteral, $toLiteral);
  6732. $this->watchChains[$fromLiteral]->remove();
  6733. $this->watchChains[$toLiteral]->unshift($node);
  6734. }
  6735. }
  6736. <?php
  6737. namespace Composer\DependencyResolver;
  6738. class RuleWatchNode
  6739. {
  6740. public $watch1;
  6741. public $watch2;
  6742. protected $rule;
  6743. public function __construct($rule)
  6744. {
  6745. $this->rule = $rule;
  6746. $literals = $rule->literals;
  6747. $this->watch1 = count($literals) > 0 ? $literals[0] : 0;
  6748. $this->watch2 = count($literals) > 1 ? $literals[1] : 0;
  6749. }
  6750. public function watch2OnHighest(Decisions $decisions)
  6751. {
  6752. $literals = $this->rule->literals;
  6753. if (count($literals) < 3) {
  6754. return;
  6755. }
  6756. $watchLevel = 0;
  6757. foreach ($literals as $literal) {
  6758. $level = $decisions->decisionLevel($literal);
  6759. if ($level > $watchLevel) {
  6760. $this->watch2 = $literal;
  6761. $watchLevel = $level;
  6762. }
  6763. }
  6764. }
  6765. public function getRule()
  6766. {
  6767. return $this->rule;
  6768. }
  6769. public function getOtherWatch($literal)
  6770. {
  6771. if ($this->watch1 == $literal) {
  6772. return $this->watch2;
  6773. } else {
  6774. return $this->watch1;
  6775. }
  6776. }
  6777. public function moveWatch($from, $to)
  6778. {
  6779. if ($this->watch1 == $from) {
  6780. $this->watch1 = $to;
  6781. } else {
  6782. $this->watch2 = $to;
  6783. }
  6784. }
  6785. }
  6786. <?php
  6787. namespace Composer\DependencyResolver;
  6788. use Composer\Repository\RepositoryInterface;
  6789. use Composer\Repository\PlatformRepository;
  6790. class Solver
  6791. {
  6792. const BRANCH_LITERALS = 0;
  6793. const BRANCH_LEVEL = 1;
  6794. protected $policy;
  6795. protected $pool;
  6796. protected $installed;
  6797. protected $rules;
  6798. protected $ruleSetGenerator;
  6799. protected $jobs;
  6800. protected $updateMap = array();
  6801. protected $watchGraph;
  6802. protected $decisions;
  6803. protected $installedMap;
  6804. protected $propagateIndex;
  6805. protected $branches = array();
  6806. protected $problems = array();
  6807. protected $learnedPool = array();
  6808. protected $learnedWhy = array();
  6809. public function __construct(PolicyInterface $policy, Pool $pool, RepositoryInterface $installed)
  6810. {
  6811. $this->policy = $policy;
  6812. $this->pool = $pool;
  6813. $this->installed = $installed;
  6814. $this->ruleSetGenerator = new RuleSetGenerator($policy, $pool);
  6815. }
  6816. public function getRuleSetSize()
  6817. {
  6818. return count($this->rules);
  6819. }
  6820. private function makeAssertionRuleDecisions()
  6821. {
  6822. $decisionStart = count($this->decisions) - 1;
  6823. $rulesCount = count($this->rules);
  6824. for ($ruleIndex = 0; $ruleIndex < $rulesCount; $ruleIndex++) {
  6825. $rule = $this->rules->ruleById[$ruleIndex];
  6826. if (!$rule->isAssertion() || $rule->isDisabled()) {
  6827. continue;
  6828. }
  6829. $literals = $rule->literals;
  6830. $literal = $literals[0];
  6831. if (!$this->decisions->decided(abs($literal))) {
  6832. $this->decisions->decide($literal, 1, $rule);
  6833. continue;
  6834. }
  6835. if ($this->decisions->satisfy($literal)) {
  6836. continue;
  6837. }
  6838. if (RuleSet::TYPE_LEARNED === $rule->getType()) {
  6839. $rule->disable();
  6840. continue;
  6841. }
  6842. $conflict = $this->decisions->decisionRule($literal);
  6843. if ($conflict && RuleSet::TYPE_PACKAGE === $conflict->getType()) {
  6844. $problem = new Problem($this->pool);
  6845. $problem->addRule($rule);
  6846. $problem->addRule($conflict);
  6847. $this->disableProblem($rule);
  6848. $this->problems[] = $problem;
  6849. continue;
  6850. }
  6851. $problem = new Problem($this->pool);
  6852. $problem->addRule($rule);
  6853. $problem->addRule($conflict);
  6854. foreach ($this->rules->getIteratorFor(RuleSet::TYPE_JOB) as $assertRule) {
  6855. if ($assertRule->isDisabled() || !$assertRule->isAssertion()) {
  6856. continue;
  6857. }
  6858. $assertRuleLiterals = $assertRule->literals;
  6859. $assertRuleLiteral = $assertRuleLiterals[0];
  6860. if (abs($literal) !== abs($assertRuleLiteral)) {
  6861. continue;
  6862. }
  6863. $problem->addRule($assertRule);
  6864. $this->disableProblem($assertRule);
  6865. }
  6866. $this->problems[] = $problem;
  6867. $this->decisions->resetToOffset($decisionStart);
  6868. $ruleIndex = -1;
  6869. }
  6870. }
  6871. protected function setupInstalledMap()
  6872. {
  6873. $this->installedMap = array();
  6874. foreach ($this->installed->getPackages() as $package) {
  6875. $this->installedMap[$package->id] = $package;
  6876. }
  6877. }
  6878. protected function checkForRootRequireProblems($ignorePlatformReqs)
  6879. {
  6880. foreach ($this->jobs as $job) {
  6881. switch ($job['cmd']) {
  6882. case 'update':
  6883. $packages = $this->pool->whatProvides($job['packageName'], $job['constraint']);
  6884. foreach ($packages as $package) {
  6885. if (isset($this->installedMap[$package->id])) {
  6886. $this->updateMap[$package->id] = true;
  6887. }
  6888. }
  6889. break;
  6890. case 'update-all':
  6891. foreach ($this->installedMap as $package) {
  6892. $this->updateMap[$package->id] = true;
  6893. }
  6894. break;
  6895. case 'install':
  6896. if ($ignorePlatformReqs && preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $job['packageName'])) {
  6897. break;
  6898. }
  6899. if (!$this->pool->whatProvides($job['packageName'], $job['constraint'])) {
  6900. $problem = new Problem($this->pool);
  6901. $problem->addRule(new Rule(array(), null, null, $job));
  6902. $this->problems[] = $problem;
  6903. }
  6904. break;
  6905. }
  6906. }
  6907. }
  6908. public function solve(Request $request, $ignorePlatformReqs = false)
  6909. {
  6910. $this->jobs = $request->getJobs();
  6911. $this->setupInstalledMap();
  6912. $this->rules = $this->ruleSetGenerator->getRulesFor($this->jobs, $this->installedMap, $ignorePlatformReqs);
  6913. $this->checkForRootRequireProblems($ignorePlatformReqs);
  6914. $this->decisions = new Decisions($this->pool);
  6915. $this->watchGraph = new RuleWatchGraph;
  6916. foreach ($this->rules as $rule) {
  6917. $this->watchGraph->insert(new RuleWatchNode($rule));
  6918. }
  6919. $this->makeAssertionRuleDecisions();
  6920. $this->runSat(true);
  6921. foreach ($this->installedMap as $packageId => $void) {
  6922. if ($this->decisions->undecided($packageId)) {
  6923. $this->decisions->decide(-$packageId, 1, null);
  6924. }
  6925. }
  6926. if ($this->problems) {
  6927. throw new SolverProblemsException($this->problems, $this->installedMap);
  6928. }
  6929. $transaction = new Transaction($this->policy, $this->pool, $this->installedMap, $this->decisions);
  6930. return $transaction->getOperations();
  6931. }
  6932. protected function propagate($level)
  6933. {
  6934. while ($this->decisions->validOffset($this->propagateIndex)) {
  6935. $decision = $this->decisions->atOffset($this->propagateIndex);
  6936. $conflict = $this->watchGraph->propagateLiteral(
  6937. $decision[Decisions::DECISION_LITERAL],
  6938. $level,
  6939. $this->decisions
  6940. );
  6941. $this->propagateIndex++;
  6942. if ($conflict) {
  6943. return $conflict;
  6944. }
  6945. }
  6946. return null;
  6947. }
  6948. private function revert($level)
  6949. {
  6950. while (!$this->decisions->isEmpty()) {
  6951. $literal = $this->decisions->lastLiteral();
  6952. if ($this->decisions->undecided($literal)) {
  6953. break;
  6954. }
  6955. $decisionLevel = $this->decisions->decisionLevel($literal);
  6956. if ($decisionLevel <= $level) {
  6957. break;
  6958. }
  6959. $this->decisions->revertLast();
  6960. $this->propagateIndex = count($this->decisions);
  6961. }
  6962. while (!empty($this->branches) && $this->branches[count($this->branches) - 1][self::BRANCH_LEVEL] >= $level) {
  6963. array_pop($this->branches);
  6964. }
  6965. }
  6966. private function setPropagateLearn($level, $literal, $disableRules, Rule $rule)
  6967. {
  6968. $level++;
  6969. $this->decisions->decide($literal, $level, $rule);
  6970. while (true) {
  6971. $rule = $this->propagate($level);
  6972. if (!$rule) {
  6973. break;
  6974. }
  6975. if ($level == 1) {
  6976. return $this->analyzeUnsolvable($rule, $disableRules);
  6977. }
  6978. list($learnLiteral, $newLevel, $newRule, $why) = $this->analyze($level, $rule);
  6979. if ($newLevel <= 0 || $newLevel >= $level) {
  6980. throw new SolverBugException(
  6981. "Trying to revert to invalid level ".(int) $newLevel." from level ".(int) $level."."
  6982. );
  6983. } elseif (!$newRule) {
  6984. throw new SolverBugException(
  6985. "No rule was learned from analyzing $rule at level $level."
  6986. );
  6987. }
  6988. $level = $newLevel;
  6989. $this->revert($level);
  6990. $this->rules->add($newRule, RuleSet::TYPE_LEARNED);
  6991. $this->learnedWhy[spl_object_hash($newRule)] = $why;
  6992. $ruleNode = new RuleWatchNode($newRule);
  6993. $ruleNode->watch2OnHighest($this->decisions);
  6994. $this->watchGraph->insert($ruleNode);
  6995. $this->decisions->decide($learnLiteral, $level, $newRule);
  6996. }
  6997. return $level;
  6998. }
  6999. private function selectAndInstall($level, array $decisionQueue, $disableRules, Rule $rule)
  7000. {
  7001. $literals = $this->policy->selectPreferredPackages($this->pool, $this->installedMap, $decisionQueue, $rule->getRequiredPackage());
  7002. $selectedLiteral = array_shift($literals);
  7003. if (count($literals)) {
  7004. $this->branches[] = array($literals, $level);
  7005. }
  7006. return $this->setPropagateLearn($level, $selectedLiteral, $disableRules, $rule);
  7007. }
  7008. protected function analyze($level, Rule $rule)
  7009. {
  7010. $analyzedRule = $rule;
  7011. $ruleLevel = 1;
  7012. $num = 0;
  7013. $l1num = 0;
  7014. $seen = array();
  7015. $learnedLiterals = array(null);
  7016. $decisionId = count($this->decisions);
  7017. $this->learnedPool[] = array();
  7018. while (true) {
  7019. $this->learnedPool[count($this->learnedPool) - 1][] = $rule;
  7020. foreach ($rule->literals as $literal) {
  7021. if ($this->decisions->satisfy($literal)) {
  7022. continue;
  7023. }
  7024. if (isset($seen[abs($literal)])) {
  7025. continue;
  7026. }
  7027. $seen[abs($literal)] = true;
  7028. $l = $this->decisions->decisionLevel($literal);
  7029. if (1 === $l) {
  7030. $l1num++;
  7031. } elseif ($level === $l) {
  7032. $num++;
  7033. } else {
  7034. $learnedLiterals[] = $literal;
  7035. if ($l > $ruleLevel) {
  7036. $ruleLevel = $l;
  7037. }
  7038. }
  7039. }
  7040. $l1retry = true;
  7041. while ($l1retry) {
  7042. $l1retry = false;
  7043. if (!$num && !--$l1num) {
  7044. break 2;
  7045. }
  7046. while (true) {
  7047. if ($decisionId <= 0) {
  7048. throw new SolverBugException(
  7049. "Reached invalid decision id $decisionId while looking through $rule for a literal present in the analyzed rule $analyzedRule."
  7050. );
  7051. }
  7052. $decisionId--;
  7053. $decision = $this->decisions->atOffset($decisionId);
  7054. $literal = $decision[Decisions::DECISION_LITERAL];
  7055. if (isset($seen[abs($literal)])) {
  7056. break;
  7057. }
  7058. }
  7059. unset($seen[abs($literal)]);
  7060. if ($num && 0 === --$num) {
  7061. $learnedLiterals[0] = -abs($literal);
  7062. if (!$l1num) {
  7063. break 2;
  7064. }
  7065. foreach ($learnedLiterals as $i => $learnedLiteral) {
  7066. if ($i !== 0) {
  7067. unset($seen[abs($learnedLiteral)]);
  7068. }
  7069. }
  7070. $l1num++;
  7071. $l1retry = true;
  7072. }
  7073. }
  7074. $decision = $this->decisions->atOffset($decisionId);
  7075. $rule = $decision[Decisions::DECISION_REASON];
  7076. }
  7077. $why = count($this->learnedPool) - 1;
  7078. if (!$learnedLiterals[0]) {
  7079. throw new SolverBugException(
  7080. "Did not find a learnable literal in analyzed rule $analyzedRule."
  7081. );
  7082. }
  7083. $newRule = new Rule($learnedLiterals, Rule::RULE_LEARNED, $why);
  7084. return array($learnedLiterals[0], $ruleLevel, $newRule, $why);
  7085. }
  7086. private function analyzeUnsolvableRule(Problem $problem, Rule $conflictRule)
  7087. {
  7088. $why = spl_object_hash($conflictRule);
  7089. if ($conflictRule->getType() == RuleSet::TYPE_LEARNED) {
  7090. $learnedWhy = $this->learnedWhy[$why];
  7091. $problemRules = $this->learnedPool[$learnedWhy];
  7092. foreach ($problemRules as $problemRule) {
  7093. $this->analyzeUnsolvableRule($problem, $problemRule);
  7094. }
  7095. return;
  7096. }
  7097. if ($conflictRule->getType() == RuleSet::TYPE_PACKAGE) {
  7098. return;
  7099. }
  7100. $problem->nextSection();
  7101. $problem->addRule($conflictRule);
  7102. }
  7103. private function analyzeUnsolvable(Rule $conflictRule, $disableRules)
  7104. {
  7105. $problem = new Problem($this->pool);
  7106. $problem->addRule($conflictRule);
  7107. $this->analyzeUnsolvableRule($problem, $conflictRule);
  7108. $this->problems[] = $problem;
  7109. $seen = array();
  7110. $literals = $conflictRule->literals;
  7111. foreach ($literals as $literal) {
  7112. if ($this->decisions->satisfy($literal)) {
  7113. continue;
  7114. }
  7115. $seen[abs($literal)] = true;
  7116. }
  7117. foreach ($this->decisions as $decision) {
  7118. $literal = $decision[Decisions::DECISION_LITERAL];
  7119. if (!isset($seen[abs($literal)])) {
  7120. continue;
  7121. }
  7122. $why = $decision[Decisions::DECISION_REASON];
  7123. $problem->addRule($why);
  7124. $this->analyzeUnsolvableRule($problem, $why);
  7125. $literals = $why->literals;
  7126. foreach ($literals as $literal) {
  7127. if ($this->decisions->satisfy($literal)) {
  7128. continue;
  7129. }
  7130. $seen[abs($literal)] = true;
  7131. }
  7132. }
  7133. if ($disableRules) {
  7134. foreach ($this->problems[count($this->problems) - 1] as $reason) {
  7135. $this->disableProblem($reason['rule']);
  7136. }
  7137. $this->resetSolver();
  7138. return 1;
  7139. }
  7140. return 0;
  7141. }
  7142. private function disableProblem(Rule $why)
  7143. {
  7144. $job = $why->getJob();
  7145. if (!$job) {
  7146. $why->disable();
  7147. return;
  7148. }
  7149. foreach ($this->rules as $rule) {
  7150. if ($job === $rule->getJob()) {
  7151. $rule->disable();
  7152. }
  7153. }
  7154. }
  7155. private function resetSolver()
  7156. {
  7157. $this->decisions->reset();
  7158. $this->propagateIndex = 0;
  7159. $this->branches = array();
  7160. $this->enableDisableLearnedRules();
  7161. $this->makeAssertionRuleDecisions();
  7162. }
  7163. private function enableDisableLearnedRules()
  7164. {
  7165. foreach ($this->rules->getIteratorFor(RuleSet::TYPE_LEARNED) as $rule) {
  7166. $why = $this->learnedWhy[spl_object_hash($rule)];
  7167. $problemRules = $this->learnedPool[$why];
  7168. $foundDisabled = false;
  7169. foreach ($problemRules as $problemRule) {
  7170. if ($problemRule->isDisabled()) {
  7171. $foundDisabled = true;
  7172. break;
  7173. }
  7174. }
  7175. if ($foundDisabled && $rule->isEnabled()) {
  7176. $rule->disable();
  7177. } elseif (!$foundDisabled && $rule->isDisabled()) {
  7178. $rule->enable();
  7179. }
  7180. }
  7181. }
  7182. private function runSat($disableRules = true)
  7183. {
  7184. $this->propagateIndex = 0;
  7185. $decisionQueue = array();
  7186. $decisionSupplementQueue = array();
  7187. $disableRules = array();
  7188. $level = 1;
  7189. $systemLevel = $level + 1;
  7190. $installedPos = 0;
  7191. while (true) {
  7192. if (1 === $level) {
  7193. $conflictRule = $this->propagate($level);
  7194. if (null !== $conflictRule) {
  7195. if ($this->analyzeUnsolvable($conflictRule, $disableRules)) {
  7196. continue;
  7197. }
  7198. return;
  7199. }
  7200. }
  7201. if ($level < $systemLevel) {
  7202. $iterator = $this->rules->getIteratorFor(RuleSet::TYPE_JOB);
  7203. foreach ($iterator as $rule) {
  7204. if ($rule->isEnabled()) {
  7205. $decisionQueue = array();
  7206. $noneSatisfied = true;
  7207. foreach ($rule->literals as $literal) {
  7208. if ($this->decisions->satisfy($literal)) {
  7209. $noneSatisfied = false;
  7210. break;
  7211. }
  7212. if ($literal > 0 && $this->decisions->undecided($literal)) {
  7213. $decisionQueue[] = $literal;
  7214. }
  7215. }
  7216. if ($noneSatisfied && count($decisionQueue)) {
  7217. if (count($this->installed) != count($this->updateMap)) {
  7218. $prunedQueue = array();
  7219. foreach ($decisionQueue as $literal) {
  7220. if (isset($this->installedMap[abs($literal)])) {
  7221. $prunedQueue[] = $literal;
  7222. if (isset($this->updateMap[abs($literal)])) {
  7223. $prunedQueue = $decisionQueue;
  7224. break;
  7225. }
  7226. }
  7227. }
  7228. $decisionQueue = $prunedQueue;
  7229. }
  7230. }
  7231. if ($noneSatisfied && count($decisionQueue)) {
  7232. $oLevel = $level;
  7233. $level = $this->selectAndInstall($level, $decisionQueue, $disableRules, $rule);
  7234. if (0 === $level) {
  7235. return;
  7236. }
  7237. if ($level <= $oLevel) {
  7238. break;
  7239. }
  7240. }
  7241. }
  7242. }
  7243. $systemLevel = $level + 1;
  7244. $iterator->next();
  7245. if ($iterator->valid()) {
  7246. continue;
  7247. }
  7248. }
  7249. if ($level < $systemLevel) {
  7250. $systemLevel = $level;
  7251. }
  7252. for ($i = 0, $n = 0; $n < count($this->rules); $i++, $n++) {
  7253. if ($i == count($this->rules)) {
  7254. $i = 0;
  7255. }
  7256. $rule = $this->rules->ruleById[$i];
  7257. $literals = $rule->literals;
  7258. if ($rule->isDisabled()) {
  7259. continue;
  7260. }
  7261. $decisionQueue = array();
  7262. foreach ($literals as $literal) {
  7263. if ($literal <= 0) {
  7264. if (!$this->decisions->decidedInstall(abs($literal))) {
  7265. continue 2;
  7266. }
  7267. } else {
  7268. if ($this->decisions->decidedInstall(abs($literal))) {
  7269. continue 2;
  7270. }
  7271. if ($this->decisions->undecided(abs($literal))) {
  7272. $decisionQueue[] = $literal;
  7273. }
  7274. }
  7275. }
  7276. if (count($decisionQueue) < 2) {
  7277. continue;
  7278. }
  7279. $oLevel = $level;
  7280. $level = $this->selectAndInstall($level, $decisionQueue, $disableRules, $rule);
  7281. if (0 === $level) {
  7282. return;
  7283. }
  7284. $n = -1;
  7285. }
  7286. if ($level < $systemLevel) {
  7287. continue;
  7288. }
  7289. if (count($this->branches)) {
  7290. $lastLiteral = null;
  7291. $lastLevel = null;
  7292. $lastBranchIndex = 0;
  7293. $lastBranchOffset = 0;
  7294. $l = 0;
  7295. for ($i = count($this->branches) - 1; $i >= 0; $i--) {
  7296. list($literals, $l) = $this->branches[$i];
  7297. foreach ($literals as $offset => $literal) {
  7298. if ($literal && $literal > 0 && $this->decisions->decisionLevel($literal) > $l + 1) {
  7299. $lastLiteral = $literal;
  7300. $lastBranchIndex = $i;
  7301. $lastBranchOffset = $offset;
  7302. $lastLevel = $l;
  7303. }
  7304. }
  7305. }
  7306. if ($lastLiteral) {
  7307. unset($this->branches[$lastBranchIndex][self::BRANCH_LITERALS][$lastBranchOffset]);
  7308. $level = $lastLevel;
  7309. $this->revert($level);
  7310. $why = $this->decisions->lastReason();
  7311. $oLevel = $level;
  7312. $level = $this->setPropagateLearn($level, $lastLiteral, $disableRules, $why);
  7313. if ($level == 0) {
  7314. return;
  7315. }
  7316. continue;
  7317. }
  7318. }
  7319. break;
  7320. }
  7321. }
  7322. }
  7323. <?php
  7324. namespace Composer\DependencyResolver;
  7325. class SolverBugException extends \RuntimeException
  7326. {
  7327. public function __construct($message)
  7328. {
  7329. parent::__construct(
  7330. $message."\nThis exception was most likely caused by a bug in Composer.\n".
  7331. "Please report the command you ran, the exact error you received, and your composer.json on https://github.com/composer/composer/issues - thank you!\n");
  7332. }
  7333. }
  7334. <?php
  7335. namespace Composer\DependencyResolver;
  7336. class SolverProblemsException extends \RuntimeException
  7337. {
  7338. protected $problems;
  7339. protected $installedMap;
  7340. public function __construct(array $problems, array $installedMap)
  7341. {
  7342. $this->problems = $problems;
  7343. $this->installedMap = $installedMap;
  7344. parent::__construct($this->createMessage(), 2);
  7345. }
  7346. protected function createMessage()
  7347. {
  7348. $text = "\n";
  7349. foreach ($this->problems as $i => $problem) {
  7350. $text .= " Problem ".($i + 1).$problem->getPrettyString($this->installedMap)."\n";
  7351. }
  7352. if (strpos($text, 'could not be found') || strpos($text, 'no matching package found')) {
  7353. $text .= "\nPotential causes:\n - A typo in the package name\n - The package is not available in a stable-enough version according to your minimum-stability setting\n see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.\n\nRead <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.";
  7354. }
  7355. return $text;
  7356. }
  7357. public function getProblems()
  7358. {
  7359. return $this->problems;
  7360. }
  7361. }
  7362. <?php
  7363. namespace Composer\DependencyResolver;
  7364. use Composer\Package\AliasPackage;
  7365. class Transaction
  7366. {
  7367. protected $policy;
  7368. protected $pool;
  7369. protected $installedMap;
  7370. protected $decisions;
  7371. protected $transaction;
  7372. public function __construct($policy, $pool, $installedMap, $decisions)
  7373. {
  7374. $this->policy = $policy;
  7375. $this->pool = $pool;
  7376. $this->installedMap = $installedMap;
  7377. $this->decisions = $decisions;
  7378. $this->transaction = array();
  7379. }
  7380. public function getOperations()
  7381. {
  7382. $installMeansUpdateMap = $this->findUpdates();
  7383. $updateMap = array();
  7384. $installMap = array();
  7385. $uninstallMap = array();
  7386. foreach ($this->decisions as $i => $decision) {
  7387. $literal = $decision[Decisions::DECISION_LITERAL];
  7388. $reason = $decision[Decisions::DECISION_REASON];
  7389. $package = $this->pool->literalToPackage($literal);
  7390. if (($literal > 0) == (isset($this->installedMap[$package->id]))) {
  7391. continue;
  7392. }
  7393. if ($literal > 0) {
  7394. if (isset($installMeansUpdateMap[abs($literal)]) && !$package instanceof AliasPackage) {
  7395. $source = $installMeansUpdateMap[abs($literal)];
  7396. $updateMap[$package->id] = array(
  7397. 'package' => $package,
  7398. 'source' => $source,
  7399. 'reason' => $reason,
  7400. );
  7401. unset($installMeansUpdateMap[abs($literal)]);
  7402. $ignoreRemove[$source->id] = true;
  7403. } else {
  7404. $installMap[$package->id] = array(
  7405. 'package' => $package,
  7406. 'reason' => $reason,
  7407. );
  7408. }
  7409. }
  7410. }
  7411. foreach ($this->decisions as $i => $decision) {
  7412. $literal = $decision[Decisions::DECISION_LITERAL];
  7413. $reason = $decision[Decisions::DECISION_REASON];
  7414. $package = $this->pool->literalToPackage($literal);
  7415. if ($literal <= 0 &&
  7416. isset($this->installedMap[$package->id]) &&
  7417. !isset($ignoreRemove[$package->id])) {
  7418. $uninstallMap[$package->id] = array(
  7419. 'package' => $package,
  7420. 'reason' => $reason,
  7421. );
  7422. }
  7423. }
  7424. $this->transactionFromMaps($installMap, $updateMap, $uninstallMap);
  7425. return $this->transaction;
  7426. }
  7427. protected function transactionFromMaps($installMap, $updateMap, $uninstallMap)
  7428. {
  7429. $queue = array_map(function ($operation) {
  7430. return $operation['package'];
  7431. },
  7432. $this->findRootPackages($installMap, $updateMap)
  7433. );
  7434. $visited = array();
  7435. while (!empty($queue)) {
  7436. $package = array_pop($queue);
  7437. $packageId = $package->id;
  7438. if (!isset($visited[$packageId])) {
  7439. array_push($queue, $package);
  7440. if ($package instanceof AliasPackage) {
  7441. array_push($queue, $package->getAliasOf());
  7442. } else {
  7443. foreach ($package->getRequires() as $link) {
  7444. $possibleRequires = $this->pool->whatProvides($link->getTarget(), $link->getConstraint());
  7445. foreach ($possibleRequires as $require) {
  7446. array_push($queue, $require);
  7447. }
  7448. }
  7449. }
  7450. $visited[$package->id] = true;
  7451. } else {
  7452. if (isset($installMap[$packageId])) {
  7453. $this->install(
  7454. $installMap[$packageId]['package'],
  7455. $installMap[$packageId]['reason']
  7456. );
  7457. unset($installMap[$packageId]);
  7458. }
  7459. if (isset($updateMap[$packageId])) {
  7460. $this->update(
  7461. $updateMap[$packageId]['source'],
  7462. $updateMap[$packageId]['package'],
  7463. $updateMap[$packageId]['reason']
  7464. );
  7465. unset($updateMap[$packageId]);
  7466. }
  7467. }
  7468. }
  7469. foreach ($uninstallMap as $uninstall) {
  7470. $this->uninstall($uninstall['package'], $uninstall['reason']);
  7471. }
  7472. }
  7473. protected function findRootPackages($installMap, $updateMap)
  7474. {
  7475. $packages = $installMap + $updateMap;
  7476. $roots = $packages;
  7477. foreach ($packages as $packageId => $operation) {
  7478. $package = $operation['package'];
  7479. if (!isset($roots[$packageId])) {
  7480. continue;
  7481. }
  7482. foreach ($package->getRequires() as $link) {
  7483. $possibleRequires = $this->pool->whatProvides($link->getTarget(), $link->getConstraint());
  7484. foreach ($possibleRequires as $require) {
  7485. unset($roots[$require->id]);
  7486. }
  7487. }
  7488. }
  7489. return $roots;
  7490. }
  7491. protected function findUpdates()
  7492. {
  7493. $installMeansUpdateMap = array();
  7494. foreach ($this->decisions as $i => $decision) {
  7495. $literal = $decision[Decisions::DECISION_LITERAL];
  7496. $package = $this->pool->literalToPackage($literal);
  7497. if ($package instanceof AliasPackage) {
  7498. continue;
  7499. }
  7500. if ($literal <= 0 && isset($this->installedMap[$package->id])) {
  7501. $updates = $this->policy->findUpdatePackages($this->pool, $this->installedMap, $package);
  7502. $literals = array($package->id);
  7503. foreach ($updates as $update) {
  7504. $literals[] = $update->id;
  7505. }
  7506. foreach ($literals as $updateLiteral) {
  7507. if ($updateLiteral !== $literal) {
  7508. $installMeansUpdateMap[abs($updateLiteral)] = $package;
  7509. }
  7510. }
  7511. }
  7512. }
  7513. return $installMeansUpdateMap;
  7514. }
  7515. protected function install($package, $reason)
  7516. {
  7517. if ($package instanceof AliasPackage) {
  7518. return $this->markAliasInstalled($package, $reason);
  7519. }
  7520. $this->transaction[] = new Operation\InstallOperation($package, $reason);
  7521. }
  7522. protected function update($from, $to, $reason)
  7523. {
  7524. $this->transaction[] = new Operation\UpdateOperation($from, $to, $reason);
  7525. }
  7526. protected function uninstall($package, $reason)
  7527. {
  7528. if ($package instanceof AliasPackage) {
  7529. return $this->markAliasUninstalled($package, $reason);
  7530. }
  7531. $this->transaction[] = new Operation\UninstallOperation($package, $reason);
  7532. }
  7533. protected function markAliasInstalled($package, $reason)
  7534. {
  7535. $this->transaction[] = new Operation\MarkAliasInstalledOperation($package, $reason);
  7536. }
  7537. protected function markAliasUninstalled($package, $reason)
  7538. {
  7539. $this->transaction[] = new Operation\MarkAliasUninstalledOperation($package, $reason);
  7540. }
  7541. }
  7542. <?php
  7543. namespace Composer\Downloader;
  7544. use Composer\Package\PackageInterface;
  7545. use Symfony\Component\Finder\Finder;
  7546. abstract class ArchiveDownloader extends FileDownloader
  7547. {
  7548. public function download(PackageInterface $package, $path)
  7549. {
  7550. $temporaryDir = $this->config->get('vendor-dir').'/composer/'.substr(md5(uniqid('', true)), 0, 8);
  7551. $retries = 3;
  7552. while ($retries--) {
  7553. $fileName = parent::download($package, $path);
  7554. if ($this->io->isVerbose()) {
  7555. $this->io->writeError(' Extracting archive');
  7556. }
  7557. try {
  7558. $this->filesystem->ensureDirectoryExists($temporaryDir);
  7559. try {
  7560. $this->extract($fileName, $temporaryDir);
  7561. } catch (\Exception $e) {
  7562. parent::clearCache($package, $path);
  7563. throw $e;
  7564. }
  7565. $this->filesystem->unlink($fileName);
  7566. $contentDir = $this->getFolderContent($temporaryDir);
  7567. if (1 === count($contentDir) && is_dir(reset($contentDir))) {
  7568. $contentDir = $this->getFolderContent((string) reset($contentDir));
  7569. }
  7570. foreach ($contentDir as $file) {
  7571. $file = (string) $file;
  7572. $this->filesystem->rename($file, $path . '/' . basename($file));
  7573. }
  7574. $this->filesystem->removeDirectory($temporaryDir);
  7575. if ($this->filesystem->isDirEmpty($this->config->get('vendor-dir').'/composer/')) {
  7576. $this->filesystem->removeDirectory($this->config->get('vendor-dir').'/composer/');
  7577. }
  7578. if ($this->filesystem->isDirEmpty($this->config->get('vendor-dir'))) {
  7579. $this->filesystem->removeDirectory($this->config->get('vendor-dir'));
  7580. }
  7581. } catch (\Exception $e) {
  7582. $this->filesystem->removeDirectory($path);
  7583. $this->filesystem->removeDirectory($temporaryDir);
  7584. if ($retries && $e instanceof \UnexpectedValueException && class_exists('ZipArchive') && $e->getCode() === \ZipArchive::ER_NOZIP) {
  7585. if ($this->io->isDebug()) {
  7586. $this->io->writeError(' Invalid zip file ('.$e->getMessage().'), retrying...');
  7587. } else {
  7588. $this->io->writeError(' Invalid zip file, retrying...');
  7589. }
  7590. usleep(500000);
  7591. continue;
  7592. }
  7593. throw $e;
  7594. }
  7595. break;
  7596. }
  7597. $this->io->writeError('');
  7598. }
  7599. protected function getFileName(PackageInterface $package, $path)
  7600. {
  7601. return rtrim($path.'/'.md5($path.spl_object_hash($package)).'.'.pathinfo(parse_url($package->getDistUrl(), PHP_URL_PATH), PATHINFO_EXTENSION), '.');
  7602. }
  7603. protected function processUrl(PackageInterface $package, $url)
  7604. {
  7605. if ($package->getDistReference() && strpos($url, 'github.com')) {
  7606. if (preg_match('{^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.+)$}i', $url, $match)) {
  7607. $url = 'https://api.github.com/repos/' . $match[1] . '/'. $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference();
  7608. } elseif ($package->getDistReference() && preg_match('{^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/archive/.+\.(zip|tar)(?:\.gz)?$}i', $url, $match)) {
  7609. $url = 'https://api.github.com/repos/' . $match[1] . '/'. $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference();
  7610. } elseif ($package->getDistReference() && preg_match('{^https?://api\.github\.com/repos/([^/]+)/([^/]+)/(zip|tar)ball(?:/.+)?$}i', $url, $match)) {
  7611. $url = 'https://api.github.com/repos/' . $match[1] . '/'. $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference();
  7612. }
  7613. } elseif ($package->getDistReference() && strpos($url, 'bitbucket.org')) {
  7614. if (preg_match('{^https?://(?:www\.)?bitbucket\.org/([^/]+)/([^/]+)/get/(.+)\.(zip|tar\.gz|tar\.bz2)$}i', $url, $match)) {
  7615. $url = 'https://bitbucket.org/' . $match[1] . '/'. $match[2] . '/get/' . $package->getDistReference() . '.' . $match[4];
  7616. }
  7617. }
  7618. return parent::processUrl($package, $url);
  7619. }
  7620. abstract protected function extract($file, $path);
  7621. private function getFolderContent($dir)
  7622. {
  7623. $finder = Finder::create()
  7624. ->ignoreVCS(false)
  7625. ->ignoreDotFiles(false)
  7626. ->depth(0)
  7627. ->in($dir);
  7628. return iterator_to_array($finder);
  7629. }
  7630. }
  7631. <?php
  7632. namespace Composer\Downloader;
  7633. use Composer\Package\PackageInterface;
  7634. interface ChangeReportInterface
  7635. {
  7636. public function getLocalChanges(PackageInterface $package, $path);
  7637. }
  7638. <?php
  7639. namespace Composer\Downloader;
  7640. use Composer\Package\PackageInterface;
  7641. use Composer\IO\IOInterface;
  7642. use Composer\Util\Filesystem;
  7643. class DownloadManager
  7644. {
  7645. private $io;
  7646. private $preferDist = false;
  7647. private $preferSource = false;
  7648. private $filesystem;
  7649. private $downloaders = array();
  7650. public function __construct(IOInterface $io, $preferSource = false, Filesystem $filesystem = null)
  7651. {
  7652. $this->io = $io;
  7653. $this->preferSource = $preferSource;
  7654. $this->filesystem = $filesystem ?: new Filesystem();
  7655. }
  7656. public function setPreferSource($preferSource)
  7657. {
  7658. $this->preferSource = $preferSource;
  7659. return $this;
  7660. }
  7661. public function setPreferDist($preferDist)
  7662. {
  7663. $this->preferDist = $preferDist;
  7664. return $this;
  7665. }
  7666. public function setOutputProgress($outputProgress)
  7667. {
  7668. foreach ($this->downloaders as $downloader) {
  7669. $downloader->setOutputProgress($outputProgress);
  7670. }
  7671. return $this;
  7672. }
  7673. public function setDownloader($type, DownloaderInterface $downloader)
  7674. {
  7675. $type = strtolower($type);
  7676. $this->downloaders[$type] = $downloader;
  7677. return $this;
  7678. }
  7679. public function getDownloader($type)
  7680. {
  7681. $type = strtolower($type);
  7682. if (!isset($this->downloaders[$type])) {
  7683. throw new \InvalidArgumentException(sprintf('Unknown downloader type: %s. Available types: %s.', $type, implode(', ', array_keys($this->downloaders))));
  7684. }
  7685. return $this->downloaders[$type];
  7686. }
  7687. public function getDownloaderForInstalledPackage(PackageInterface $package)
  7688. {
  7689. $installationSource = $package->getInstallationSource();
  7690. if ('metapackage' === $package->getType()) {
  7691. return;
  7692. }
  7693. if ('dist' === $installationSource) {
  7694. $downloader = $this->getDownloader($package->getDistType());
  7695. } elseif ('source' === $installationSource) {
  7696. $downloader = $this->getDownloader($package->getSourceType());
  7697. } else {
  7698. throw new \InvalidArgumentException(
  7699. 'Package '.$package.' seems not been installed properly'
  7700. );
  7701. }
  7702. if ($installationSource !== $downloader->getInstallationSource()) {
  7703. throw new \LogicException(sprintf(
  7704. 'Downloader "%s" is a %s type downloader and can not be used to download %s',
  7705. get_class($downloader), $downloader->getInstallationSource(), $installationSource
  7706. ));
  7707. }
  7708. return $downloader;
  7709. }
  7710. public function download(PackageInterface $package, $targetDir, $preferSource = null)
  7711. {
  7712. $preferSource = null !== $preferSource ? $preferSource : $this->preferSource;
  7713. $sourceType = $package->getSourceType();
  7714. $distType = $package->getDistType();
  7715. $sources = array();
  7716. if ($sourceType) {
  7717. $sources[] = 'source';
  7718. }
  7719. if ($distType) {
  7720. $sources[] = 'dist';
  7721. }
  7722. if (empty($sources)) {
  7723. throw new \InvalidArgumentException('Package '.$package.' must have a source or dist specified');
  7724. }
  7725. if ((!$package->isDev() || $this->preferDist) && !$preferSource) {
  7726. $sources = array_reverse($sources);
  7727. }
  7728. $this->filesystem->ensureDirectoryExists($targetDir);
  7729. foreach ($sources as $i => $source) {
  7730. if (isset($e)) {
  7731. $this->io->writeError(' <warning>Now trying to download from ' . $source . '</warning>');
  7732. }
  7733. $package->setInstallationSource($source);
  7734. try {
  7735. $downloader = $this->getDownloaderForInstalledPackage($package);
  7736. if ($downloader) {
  7737. $downloader->download($package, $targetDir);
  7738. }
  7739. break;
  7740. } catch (\RuntimeException $e) {
  7741. if ($i === count($sources) - 1) {
  7742. throw $e;
  7743. }
  7744. $this->io->writeError(
  7745. ' <warning>Failed to download '.
  7746. $package->getPrettyName().
  7747. ' from ' . $source . ': '.
  7748. $e->getMessage().'</warning>'
  7749. );
  7750. }
  7751. }
  7752. }
  7753. public function update(PackageInterface $initial, PackageInterface $target, $targetDir)
  7754. {
  7755. $downloader = $this->getDownloaderForInstalledPackage($initial);
  7756. if (!$downloader) {
  7757. return;
  7758. }
  7759. $installationSource = $initial->getInstallationSource();
  7760. if ('dist' === $installationSource) {
  7761. $initialType = $initial->getDistType();
  7762. $targetType = $target->getDistType();
  7763. } else {
  7764. $initialType = $initial->getSourceType();
  7765. $targetType = $target->getSourceType();
  7766. }
  7767. if ($target->isDev() && 'dist' === $installationSource) {
  7768. $downloader->remove($initial, $targetDir);
  7769. $this->download($target, $targetDir);
  7770. return;
  7771. }
  7772. if ($initialType === $targetType) {
  7773. $target->setInstallationSource($installationSource);
  7774. $downloader->update($initial, $target, $targetDir);
  7775. } else {
  7776. $downloader->remove($initial, $targetDir);
  7777. $this->download($target, $targetDir, 'source' === $installationSource);
  7778. }
  7779. }
  7780. public function remove(PackageInterface $package, $targetDir)
  7781. {
  7782. $downloader = $this->getDownloaderForInstalledPackage($package);
  7783. if ($downloader) {
  7784. $downloader->remove($package, $targetDir);
  7785. }
  7786. }
  7787. }
  7788. <?php
  7789. namespace Composer\Downloader;
  7790. use Composer\Package\PackageInterface;
  7791. interface DownloaderInterface
  7792. {
  7793. public function getInstallationSource();
  7794. public function download(PackageInterface $package, $path);
  7795. public function update(PackageInterface $initial, PackageInterface $target, $path);
  7796. public function remove(PackageInterface $package, $path);
  7797. public function setOutputProgress($outputProgress);
  7798. }
  7799. <?php
  7800. namespace Composer\Downloader;
  7801. use Composer\Config;
  7802. use Composer\Cache;
  7803. use Composer\IO\IOInterface;
  7804. use Composer\Package\PackageInterface;
  7805. use Composer\Plugin\PluginEvents;
  7806. use Composer\Plugin\PreFileDownloadEvent;
  7807. use Composer\EventDispatcher\EventDispatcher;
  7808. use Composer\Util\Filesystem;
  7809. use Composer\Util\RemoteFilesystem;
  7810. class FileDownloader implements DownloaderInterface
  7811. {
  7812. protected $io;
  7813. protected $config;
  7814. protected $rfs;
  7815. protected $filesystem;
  7816. protected $cache;
  7817. protected $outputProgress = true;
  7818. public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, RemoteFilesystem $rfs = null, Filesystem $filesystem = null)
  7819. {
  7820. $this->io = $io;
  7821. $this->config = $config;
  7822. $this->eventDispatcher = $eventDispatcher;
  7823. $this->rfs = $rfs ?: new RemoteFilesystem($io, $config);
  7824. $this->filesystem = $filesystem ?: new Filesystem();
  7825. $this->cache = $cache;
  7826. if ($this->cache && $this->cache->gcIsNecessary()) {
  7827. $this->cache->gc($config->get('cache-files-ttl'), $config->get('cache-files-maxsize'));
  7828. }
  7829. }
  7830. public function getInstallationSource()
  7831. {
  7832. return 'dist';
  7833. }
  7834. public function download(PackageInterface $package, $path)
  7835. {
  7836. if (!$package->getDistUrl()) {
  7837. throw new \InvalidArgumentException('The given package is missing url information');
  7838. }
  7839. $this->io->writeError(" - Installing <info>" . $package->getName() . "</info> (<comment>" . $package->getFullPrettyVersion() . "</comment>)");
  7840. $urls = $package->getDistUrls();
  7841. while ($url = array_shift($urls)) {
  7842. try {
  7843. return $this->doDownload($package, $path, $url);
  7844. } catch (\Exception $e) {
  7845. if ($this->io->isDebug()) {
  7846. $this->io->writeError('');
  7847. $this->io->writeError('Failed: ['.get_class($e).'] '.$e->getCode().': '.$e->getMessage());
  7848. } elseif (count($urls)) {
  7849. $this->io->writeError('');
  7850. $this->io->writeError(' Failed, trying the next URL ('.$e->getCode().': '.$e->getMessage().')');
  7851. }
  7852. if (!count($urls)) {
  7853. throw $e;
  7854. }
  7855. }
  7856. }
  7857. $this->io->writeError('');
  7858. }
  7859. protected function doDownload(PackageInterface $package, $path, $url)
  7860. {
  7861. $this->filesystem->emptyDirectory($path);
  7862. $fileName = $this->getFileName($package, $path);
  7863. $processedUrl = $this->processUrl($package, $url);
  7864. $hostname = parse_url($processedUrl, PHP_URL_HOST);
  7865. $preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->rfs, $processedUrl);
  7866. if ($this->eventDispatcher) {
  7867. $this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
  7868. }
  7869. $rfs = $preFileDownloadEvent->getRemoteFilesystem();
  7870. try {
  7871. $checksum = $package->getDistSha1Checksum();
  7872. $cacheKey = $this->getCacheKey($package);
  7873. if (!$this->cache || ($checksum && $checksum !== $this->cache->sha1($cacheKey)) || !$this->cache->copyTo($cacheKey, $fileName)) {
  7874. if (!$this->outputProgress) {
  7875. $this->io->writeError(' Downloading');
  7876. }
  7877. $retries = 3;
  7878. while ($retries--) {
  7879. try {
  7880. $rfs->copy($hostname, $processedUrl, $fileName, $this->outputProgress, $package->getTransportOptions());
  7881. break;
  7882. } catch (TransportException $e) {
  7883. if ((0 !== $e->getCode() && !in_array($e->getCode(), array(500, 502, 503, 504))) || !$retries) {
  7884. throw $e;
  7885. }
  7886. if ($this->io->isVerbose()) {
  7887. $this->io->writeError(' Download failed, retrying...');
  7888. }
  7889. usleep(500000);
  7890. }
  7891. }
  7892. if ($this->cache) {
  7893. $this->cache->copyFrom($cacheKey, $fileName);
  7894. }
  7895. } else {
  7896. $this->io->writeError(' Loading from cache');
  7897. }
  7898. if (!file_exists($fileName)) {
  7899. throw new \UnexpectedValueException($url.' could not be saved to '.$fileName.', make sure the'
  7900. .' directory is writable and you have internet connectivity');
  7901. }
  7902. if ($checksum && hash_file('sha1', $fileName) !== $checksum) {
  7903. throw new \UnexpectedValueException('The checksum verification of the file failed (downloaded from '.$url.')');
  7904. }
  7905. } catch (\Exception $e) {
  7906. $this->filesystem->removeDirectory($path);
  7907. $this->clearCache($package, $path);
  7908. throw $e;
  7909. }
  7910. return $fileName;
  7911. }
  7912. public function setOutputProgress($outputProgress)
  7913. {
  7914. $this->outputProgress = $outputProgress;
  7915. return $this;
  7916. }
  7917. protected function clearCache(PackageInterface $package, $path)
  7918. {
  7919. if ($this->cache) {
  7920. $fileName = $this->getFileName($package, $path);
  7921. $this->cache->remove($this->getCacheKey($package));
  7922. }
  7923. }
  7924. public function update(PackageInterface $initial, PackageInterface $target, $path)
  7925. {
  7926. $this->remove($initial, $path);
  7927. $this->download($target, $path);
  7928. }
  7929. public function remove(PackageInterface $package, $path)
  7930. {
  7931. $this->io->writeError(" - Removing <info>" . $package->getName() . "</info> (<comment>" . $package->getFullPrettyVersion() . "</comment>)");
  7932. if (!$this->filesystem->removeDirectory($path)) {
  7933. throw new \RuntimeException('Could not completely delete '.$path.', aborting.');
  7934. }
  7935. }
  7936. protected function getFileName(PackageInterface $package, $path)
  7937. {
  7938. return $path.'/'.pathinfo(parse_url($package->getDistUrl(), PHP_URL_PATH), PATHINFO_BASENAME);
  7939. }
  7940. protected function processUrl(PackageInterface $package, $url)
  7941. {
  7942. if (!extension_loaded('openssl') && 0 === strpos($url, 'https:')) {
  7943. throw new \RuntimeException('You must enable the openssl extension to download files via https');
  7944. }
  7945. return $url;
  7946. }
  7947. private function getCacheKey(PackageInterface $package)
  7948. {
  7949. if (preg_match('{^[a-f0-9]{40}$}', $package->getDistReference())) {
  7950. return $package->getName().'/'.$package->getDistReference().'.'.$package->getDistType();
  7951. }
  7952. return $package->getName().'/'.$package->getVersion().'-'.$package->getDistReference().'.'.$package->getDistType();
  7953. }
  7954. }
  7955. <?php
  7956. namespace Composer\Downloader;
  7957. class FilesystemException extends \Exception
  7958. {
  7959. public function __construct($message = null, $code = null, \Exception $previous = null)
  7960. {
  7961. parent::__construct("Filesystem exception: \n".$message, $code, $previous);
  7962. }
  7963. }
  7964. <?php
  7965. namespace Composer\Downloader;
  7966. use Composer\Package\PackageInterface;
  7967. use Composer\Util\Git as GitUtil;
  7968. use Composer\Util\ProcessExecutor;
  7969. use Composer\IO\IOInterface;
  7970. use Composer\Util\Filesystem;
  7971. use Composer\Config;
  7972. class GitDownloader extends VcsDownloader
  7973. {
  7974. private $hasStashedChanges = false;
  7975. private $gitUtil;
  7976. public function __construct(IOInterface $io, Config $config, ProcessExecutor $process = null, Filesystem $fs = null)
  7977. {
  7978. parent::__construct($io, $config, $process, $fs);
  7979. $this->gitUtil = new GitUtil($this->io, $this->config, $this->process, $this->filesystem);
  7980. }
  7981. public function doDownload(PackageInterface $package, $path, $url)
  7982. {
  7983. GitUtil::cleanEnv();
  7984. $path = $this->normalizePath($path);
  7985. $ref = $package->getSourceReference();
  7986. $flag = defined('PHP_WINDOWS_VERSION_MAJOR') ? '/D ' : '';
  7987. $command = 'git clone --no-checkout %s %s && cd '.$flag.'%2$s && git remote add composer %1$s && git fetch composer';
  7988. $this->io->writeError(" Cloning ".$ref);
  7989. $commandCallable = function ($url) use ($ref, $path, $command) {
  7990. return sprintf($command, ProcessExecutor::escape($url), ProcessExecutor::escape($path), ProcessExecutor::escape($ref));
  7991. };
  7992. $this->gitUtil->runCommand($commandCallable, $url, $path, true);
  7993. if ($url !== $package->getSourceUrl()) {
  7994. $url = $package->getSourceUrl();
  7995. $this->process->execute(sprintf('git remote set-url origin %s', ProcessExecutor::escape($url)), $output, $path);
  7996. }
  7997. $this->setPushUrl($path, $url);
  7998. if ($newRef = $this->updateToCommit($path, $ref, $package->getPrettyVersion(), $package->getReleaseDate())) {
  7999. if ($package->getDistReference() === $package->getSourceReference()) {
  8000. $package->setDistReference($newRef);
  8001. }
  8002. $package->setSourceReference($newRef);
  8003. }
  8004. }
  8005. public function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url)
  8006. {
  8007. GitUtil::cleanEnv();
  8008. $path = $this->normalizePath($path);
  8009. if (!is_dir($path.'/.git')) {
  8010. throw new \RuntimeException('The .git directory is missing from '.$path.', see https://getcomposer.org/commit-deps for more information');
  8011. }
  8012. $ref = $target->getSourceReference();
  8013. $this->io->writeError(" Checking out ".$ref);
  8014. $command = 'git remote set-url composer %s && git fetch composer && git fetch --tags composer';
  8015. $commandCallable = function ($url) use ($command) {
  8016. return sprintf($command, ProcessExecutor::escape($url));
  8017. };
  8018. $this->gitUtil->runCommand($commandCallable, $url, $path);
  8019. if ($newRef = $this->updateToCommit($path, $ref, $target->getPrettyVersion(), $target->getReleaseDate())) {
  8020. if ($target->getDistReference() === $target->getSourceReference()) {
  8021. $target->setDistReference($newRef);
  8022. }
  8023. $target->setSourceReference($newRef);
  8024. }
  8025. }
  8026. public function getLocalChanges(PackageInterface $package, $path)
  8027. {
  8028. GitUtil::cleanEnv();
  8029. $path = $this->normalizePath($path);
  8030. if (!is_dir($path.'/.git')) {
  8031. return;
  8032. }
  8033. $command = 'git status --porcelain --untracked-files=no';
  8034. if (0 !== $this->process->execute($command, $output, $path)) {
  8035. throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
  8036. }
  8037. return trim($output) ?: null;
  8038. }
  8039. protected function cleanChanges(PackageInterface $package, $path, $update)
  8040. {
  8041. GitUtil::cleanEnv();
  8042. $path = $this->normalizePath($path);
  8043. if (!$changes = $this->getLocalChanges($package, $path)) {
  8044. return;
  8045. }
  8046. if (!$this->io->isInteractive()) {
  8047. $discardChanges = $this->config->get('discard-changes');
  8048. if (true === $discardChanges) {
  8049. return $this->discardChanges($path);
  8050. }
  8051. if ('stash' === $discardChanges) {
  8052. if (!$update) {
  8053. return parent::cleanChanges($package, $path, $update);
  8054. }
  8055. return $this->stashChanges($path);
  8056. }
  8057. return parent::cleanChanges($package, $path, $update);
  8058. }
  8059. $changes = array_map(function ($elem) {
  8060. return ' '.$elem;
  8061. }, preg_split('{\s*\r?\n\s*}', $changes));
  8062. $this->io->writeError(' <error>The package has modified files:</error>');
  8063. $this->io->writeError(array_slice($changes, 0, 10));
  8064. if (count($changes) > 10) {
  8065. $this->io->writeError(' <info>'.count($changes) - 10 . ' more files modified, choose "v" to view the full list</info>');
  8066. }
  8067. while (true) {
  8068. switch ($this->io->ask(' <info>Discard changes [y,n,v,d,'.($update ? 's,' : '').'?]?</info> ', '?')) {
  8069. case 'y':
  8070. $this->discardChanges($path);
  8071. break 2;
  8072. case 's':
  8073. if (!$update) {
  8074. goto help;
  8075. }
  8076. $this->stashChanges($path);
  8077. break 2;
  8078. case 'n':
  8079. throw new \RuntimeException('Update aborted');
  8080. case 'v':
  8081. $this->io->writeError($changes);
  8082. break;
  8083. case 'd':
  8084. $this->viewDiff($path);
  8085. break;
  8086. case '?':
  8087. default:
  8088. help:
  8089. $this->io->writeError(array(
  8090. ' y - discard changes and apply the '.($update ? 'update' : 'uninstall'),
  8091. ' n - abort the '.($update ? 'update' : 'uninstall').' and let you manually clean things up',
  8092. ' v - view modified files',
  8093. ' d - view local modifications (diff)',
  8094. ));
  8095. if ($update) {
  8096. $this->io->writeError(' s - stash changes and try to reapply them after the update');
  8097. }
  8098. $this->io->writeError(' ? - print help');
  8099. break;
  8100. }
  8101. }
  8102. }
  8103. protected function reapplyChanges($path)
  8104. {
  8105. $path = $this->normalizePath($path);
  8106. if ($this->hasStashedChanges) {
  8107. $this->hasStashedChanges = false;
  8108. $this->io->writeError(' <info>Re-applying stashed changes</info>');
  8109. if (0 !== $this->process->execute('git stash pop', $output, $path)) {
  8110. throw new \RuntimeException("Failed to apply stashed changes:\n\n".$this->process->getErrorOutput());
  8111. }
  8112. }
  8113. }
  8114. protected function updateToCommit($path, $reference, $branch, $date)
  8115. {
  8116. $template = 'git checkout %s -- && git reset --hard %1$s --';
  8117. $branch = preg_replace('{(?:^dev-|(?:\.x)?-dev$)}i', '', $branch);
  8118. $branches = null;
  8119. if (0 === $this->process->execute('git branch -r', $output, $path)) {
  8120. $branches = $output;
  8121. }
  8122. $gitRef = $reference;
  8123. if (!preg_match('{^[a-f0-9]{40}$}', $reference)
  8124. && $branches
  8125. && preg_match('{^\s+composer/'.preg_quote($reference).'$}m', $branches)
  8126. ) {
  8127. $command = sprintf('git checkout -B %s %s -- && git reset --hard %2$s --', ProcessExecutor::escape($branch), ProcessExecutor::escape('composer/'.$reference));
  8128. if (0 === $this->process->execute($command, $output, $path)) {
  8129. return;
  8130. }
  8131. }
  8132. if (preg_match('{^[a-f0-9]{40}$}', $reference)) {
  8133. if (!preg_match('{^\s+composer/'.preg_quote($branch).'$}m', $branches) && preg_match('{^\s+composer/v'.preg_quote($branch).'$}m', $branches)) {
  8134. $branch = 'v' . $branch;
  8135. }
  8136. $command = sprintf('git checkout %s --', ProcessExecutor::escape($branch));
  8137. $fallbackCommand = sprintf('git checkout -B %s %s --', ProcessExecutor::escape($branch), ProcessExecutor::escape('composer/'.$branch));
  8138. if (0 === $this->process->execute($command, $output, $path)
  8139. || 0 === $this->process->execute($fallbackCommand, $output, $path)
  8140. ) {
  8141. $command = sprintf('git reset --hard %s --', ProcessExecutor::escape($reference));
  8142. if (0 === $this->process->execute($command, $output, $path)) {
  8143. return;
  8144. }
  8145. }
  8146. }
  8147. $command = sprintf($template, ProcessExecutor::escape($gitRef));
  8148. if (0 === $this->process->execute($command, $output, $path)) {
  8149. return;
  8150. }
  8151. if (false !== strpos($this->process->getErrorOutput(), $reference)) {
  8152. $this->io->writeError(' <warning>'.$reference.' is gone (history was rewritten?)</warning>');
  8153. }
  8154. throw new \RuntimeException('Failed to execute ' . GitUtil::sanitizeUrl($command) . "\n\n" . $this->process->getErrorOutput());
  8155. }
  8156. protected function setPushUrl($path, $url)
  8157. {
  8158. if (preg_match('{^(?:https?|git)://'.GitUtil::getGitHubDomainsRegex($this->config).'/([^/]+)/([^/]+?)(?:\.git)?$}', $url, $match)) {
  8159. $protocols = $this->config->get('github-protocols');
  8160. $pushUrl = 'git@'.$match[1].':'.$match[2].'/'.$match[3].'.git';
  8161. if ($protocols[0] !== 'git') {
  8162. $pushUrl = 'https://' . $match[1] . '/'.$match[2].'/'.$match[3].'.git';
  8163. }
  8164. $cmd = sprintf('git remote set-url --push origin %s', ProcessExecutor::escape($pushUrl));
  8165. $this->process->execute($cmd, $ignoredOutput, $path);
  8166. }
  8167. }
  8168. protected function getCommitLogs($fromReference, $toReference, $path)
  8169. {
  8170. $path = $this->normalizePath($path);
  8171. $command = sprintf('git log %s..%s --pretty=format:"%%h - %%an: %%s"', $fromReference, $toReference);
  8172. if (0 !== $this->process->execute($command, $output, $path)) {
  8173. throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
  8174. }
  8175. return $output;
  8176. }
  8177. protected function discardChanges($path)
  8178. {
  8179. $path = $this->normalizePath($path);
  8180. if (0 !== $this->process->execute('git reset --hard', $output, $path)) {
  8181. throw new \RuntimeException("Could not reset changes\n\n:".$this->process->getErrorOutput());
  8182. }
  8183. }
  8184. protected function stashChanges($path)
  8185. {
  8186. $path = $this->normalizePath($path);
  8187. if (0 !== $this->process->execute('git stash', $output, $path)) {
  8188. throw new \RuntimeException("Could not stash changes\n\n:".$this->process->getErrorOutput());
  8189. }
  8190. $this->hasStashedChanges = true;
  8191. }
  8192. protected function viewDiff($path)
  8193. {
  8194. $path = $this->normalizePath($path);
  8195. if (0 !== $this->process->execute('git diff HEAD', $output, $path)) {
  8196. throw new \RuntimeException("Could not view diff\n\n:".$this->process->getErrorOutput());
  8197. }
  8198. $this->io->writeError($output);
  8199. }
  8200. protected function normalizePath($path)
  8201. {
  8202. if (defined('PHP_WINDOWS_VERSION_MAJOR') && strlen($path) > 0) {
  8203. $basePath = $path;
  8204. $removed = array();
  8205. while (!is_dir($basePath) && $basePath !== '\\') {
  8206. array_unshift($removed, basename($basePath));
  8207. $basePath = dirname($basePath);
  8208. }
  8209. if ($basePath === '\\') {
  8210. return $path;
  8211. }
  8212. $path = rtrim(realpath($basePath) . '/' . implode('/', $removed), '/');
  8213. }
  8214. return $path;
  8215. }
  8216. }
  8217. <?php
  8218. namespace Composer\Downloader;
  8219. use Composer\Config;
  8220. use Composer\Cache;
  8221. use Composer\EventDispatcher\EventDispatcher;
  8222. use Composer\Package\PackageInterface;
  8223. use Composer\Util\ProcessExecutor;
  8224. use Composer\IO\IOInterface;
  8225. class GzipDownloader extends ArchiveDownloader
  8226. {
  8227. protected $process;
  8228. public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null)
  8229. {
  8230. $this->process = $process ?: new ProcessExecutor($io);
  8231. parent::__construct($io, $config, $eventDispatcher, $cache);
  8232. }
  8233. protected function extract($file, $path)
  8234. {
  8235. $targetFilepath = $path . DIRECTORY_SEPARATOR . basename(substr($file, 0, -3));
  8236. if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
  8237. $command = 'gzip -cd ' . ProcessExecutor::escape($file) . ' > ' . ProcessExecutor::escape($targetFilepath);
  8238. if (0 === $this->process->execute($command, $ignoredOutput)) {
  8239. return;
  8240. }
  8241. $processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput();
  8242. throw new \RuntimeException($processError);
  8243. }
  8244. $archiveFile = gzopen($file, 'rb');
  8245. $targetFile = fopen($targetFilepath, 'wb');
  8246. while ($string = gzread($archiveFile, 4096)) {
  8247. fwrite($targetFile, $string, strlen($string));
  8248. }
  8249. gzclose($archiveFile);
  8250. fclose($targetFile);
  8251. }
  8252. protected function getFileName(PackageInterface $package, $path)
  8253. {
  8254. return $path.'/'.pathinfo(parse_url($package->getDistUrl(), PHP_URL_PATH), PATHINFO_BASENAME);
  8255. }
  8256. }
  8257. <?php
  8258. namespace Composer\Downloader;
  8259. use Composer\Package\PackageInterface;
  8260. use Composer\Util\ProcessExecutor;
  8261. class HgDownloader extends VcsDownloader
  8262. {
  8263. public function doDownload(PackageInterface $package, $path, $url)
  8264. {
  8265. $url = ProcessExecutor::escape($url);
  8266. $ref = ProcessExecutor::escape($package->getSourceReference());
  8267. $this->io->writeError(" Cloning ".$package->getSourceReference());
  8268. $command = sprintf('hg clone %s %s', $url, ProcessExecutor::escape($path));
  8269. if (0 !== $this->process->execute($command, $ignoredOutput)) {
  8270. throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
  8271. }
  8272. $command = sprintf('hg up %s', $ref);
  8273. if (0 !== $this->process->execute($command, $ignoredOutput, realpath($path))) {
  8274. throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
  8275. }
  8276. }
  8277. public function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url)
  8278. {
  8279. $url = ProcessExecutor::escape($url);
  8280. $ref = ProcessExecutor::escape($target->getSourceReference());
  8281. $this->io->writeError(" Updating to ".$target->getSourceReference());
  8282. if (!is_dir($path.'/.hg')) {
  8283. throw new \RuntimeException('The .hg directory is missing from '.$path.', see https://getcomposer.org/commit-deps for more information');
  8284. }
  8285. $command = sprintf('hg pull %s && hg up %s', $url, $ref);
  8286. if (0 !== $this->process->execute($command, $ignoredOutput, realpath($path))) {
  8287. throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
  8288. }
  8289. }
  8290. public function getLocalChanges(PackageInterface $package, $path)
  8291. {
  8292. if (!is_dir($path.'/.hg')) {
  8293. return;
  8294. }
  8295. $this->process->execute('hg st', $output, realpath($path));
  8296. return trim($output) ?: null;
  8297. }
  8298. protected function getCommitLogs($fromReference, $toReference, $path)
  8299. {
  8300. $command = sprintf('hg log -r %s:%s --style compact', $fromReference, $toReference);
  8301. if (0 !== $this->process->execute($command, $output, realpath($path))) {
  8302. throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
  8303. }
  8304. return $output;
  8305. }
  8306. }
  8307. <?php
  8308. namespace Composer\Downloader;
  8309. use Composer\Package\PackageInterface;
  8310. use Symfony\Component\Filesystem\Exception\IOException;
  8311. use Symfony\Component\Filesystem\Filesystem;
  8312. class PathDownloader extends FileDownloader
  8313. {
  8314. public function download(PackageInterface $package, $path)
  8315. {
  8316. $fileSystem = new Filesystem();
  8317. $this->filesystem->removeDirectory($path);
  8318. $this->io->writeError(sprintf(
  8319. ' - Installing <info>%s</info> (<comment>%s</comment>)',
  8320. $package->getName(),
  8321. $package->getFullPrettyVersion()
  8322. ));
  8323. $url = $package->getDistUrl();
  8324. $realUrl = realpath($url);
  8325. if (false === $realUrl || !file_exists($realUrl) || !is_dir($realUrl)) {
  8326. throw new \RuntimeException(sprintf(
  8327. 'Path "%s" is not found',
  8328. $url
  8329. ));
  8330. }
  8331. try {
  8332. $shortestPath = $this->filesystem->findShortestPath($path, $realUrl);
  8333. $fileSystem->symlink($shortestPath, $path);
  8334. $this->io->writeError(sprintf(' Symlinked from %s', $url));
  8335. } catch (IOException $e) {
  8336. $fileSystem->mirror($realUrl, $path);
  8337. $this->io->writeError(sprintf(' Mirrored from %s', $url));
  8338. }
  8339. $this->io->writeError('');
  8340. }
  8341. }
  8342. <?php
  8343. namespace Composer\Downloader;
  8344. use Composer\Util\Filesystem;
  8345. class PearPackageExtractor
  8346. {
  8347. private static $rolesWithoutPackageNamePrefix = array('php', 'script', 'www');
  8348. private $filesystem;
  8349. private $file;
  8350. public function __construct($file)
  8351. {
  8352. if (!is_file($file)) {
  8353. throw new \UnexpectedValueException('PEAR package file is not found at '.$file);
  8354. }
  8355. $this->filesystem = new Filesystem();
  8356. $this->file = $file;
  8357. }
  8358. public function extractTo($target, array $roles = array('php' => '/', 'script' => '/bin'), $vars = array())
  8359. {
  8360. $extractionPath = $target.'/tarball';
  8361. try {
  8362. $archive = new \PharData($this->file);
  8363. $archive->extractTo($extractionPath, null, true);
  8364. if (!is_file($this->combine($extractionPath, '/package.xml'))) {
  8365. throw new \RuntimeException('Invalid PEAR package. It must contain package.xml file.');
  8366. }
  8367. $fileCopyActions = $this->buildCopyActions($extractionPath, $roles, $vars);
  8368. $this->copyFiles($fileCopyActions, $extractionPath, $target, $roles, $vars);
  8369. $this->filesystem->removeDirectory($extractionPath);
  8370. } catch (\Exception $exception) {
  8371. throw new \UnexpectedValueException(sprintf('Failed to extract PEAR package %s to %s. Reason: %s', $this->file, $target, $exception->getMessage()), 0, $exception);
  8372. }
  8373. }
  8374. private function copyFiles($files, $source, $target, $roles, $vars)
  8375. {
  8376. foreach ($files as $file) {
  8377. $from = $this->combine($source, $file['from']);
  8378. $to = $this->combine($target, $roles[$file['role']]);
  8379. $to = $this->combine($to, $file['to']);
  8380. $tasks = $file['tasks'];
  8381. $this->copyFile($from, $to, $tasks, $vars);
  8382. }
  8383. }
  8384. private function copyFile($from, $to, $tasks, $vars)
  8385. {
  8386. if (!is_file($from)) {
  8387. throw new \RuntimeException('Invalid PEAR package. package.xml defines file that is not located inside tarball.');
  8388. }
  8389. $this->filesystem->ensureDirectoryExists(dirname($to));
  8390. if (0 == count($tasks)) {
  8391. $copied = copy($from, $to);
  8392. } else {
  8393. $content = file_get_contents($from);
  8394. $replacements = array();
  8395. foreach ($tasks as $task) {
  8396. $pattern = $task['from'];
  8397. $varName = $task['to'];
  8398. if (isset($vars[$varName])) {
  8399. if ($varName === 'php_bin' && false === strpos($to, '.bat')) {
  8400. $replacements[$pattern] = preg_replace('{\.bat$}', '', $vars[$varName]);
  8401. } else {
  8402. $replacements[$pattern] = $vars[$varName];
  8403. }
  8404. }
  8405. }
  8406. $content = strtr($content, $replacements);
  8407. $copied = file_put_contents($to, $content);
  8408. }
  8409. if (false === $copied) {
  8410. throw new \RuntimeException(sprintf('Failed to copy %s to %s', $from, $to));
  8411. }
  8412. }
  8413. private function buildCopyActions($source, array $roles, $vars)
  8414. {
  8415. $package = simplexml_load_string(file_get_contents($this->combine($source, 'package.xml')));
  8416. if (false === $package) {
  8417. throw new \RuntimeException('Package definition file is not valid.');
  8418. }
  8419. $packageSchemaVersion = $package['version'];
  8420. if ('1.0' == $packageSchemaVersion) {
  8421. $children = $package->release->filelist->children();
  8422. $packageName = (string) $package->name;
  8423. $packageVersion = (string) $package->release->version;
  8424. $sourceDir = $packageName . '-' . $packageVersion;
  8425. $result = $this->buildSourceList10($children, $roles, $sourceDir, '', null, $packageName);
  8426. } elseif ('2.0' == $packageSchemaVersion || '2.1' == $packageSchemaVersion) {
  8427. $children = $package->contents->children();
  8428. $packageName = (string) $package->name;
  8429. $packageVersion = (string) $package->version->release;
  8430. $sourceDir = $packageName . '-' . $packageVersion;
  8431. $result = $this->buildSourceList20($children, $roles, $sourceDir, '', null, $packageName);
  8432. $namespaces = $package->getNamespaces();
  8433. $package->registerXPathNamespace('ns', $namespaces['']);
  8434. $releaseNodes = $package->xpath('ns:phprelease');
  8435. $this->applyRelease($result, $releaseNodes, $vars);
  8436. } else {
  8437. throw new \RuntimeException('Unsupported schema version of package definition file.');
  8438. }
  8439. return $result;
  8440. }
  8441. private function applyRelease(&$actions, $releaseNodes, $vars)
  8442. {
  8443. foreach ($releaseNodes as $releaseNode) {
  8444. $requiredOs = $releaseNode->installconditions && $releaseNode->installconditions->os && $releaseNode->installconditions->os->name ? (string) $releaseNode->installconditions->os->name : '';
  8445. if ($requiredOs && $vars['os'] != $requiredOs) {
  8446. continue;
  8447. }
  8448. if ($releaseNode->filelist) {
  8449. foreach ($releaseNode->filelist->children() as $action) {
  8450. if ('install' == $action->getName()) {
  8451. $name = (string) $action['name'];
  8452. $as = (string) $action['as'];
  8453. if (isset($actions[$name])) {
  8454. $actions[$name]['to'] = $as;
  8455. }
  8456. } elseif ('ignore' == $action->getName()) {
  8457. $name = (string) $action['name'];
  8458. unset($actions[$name]);
  8459. } else {
  8460. }
  8461. }
  8462. }
  8463. break;
  8464. }
  8465. }
  8466. private function buildSourceList10($children, $targetRoles, $source, $target, $role, $packageName)
  8467. {
  8468. $result = array();
  8469. foreach ($children as $child) {
  8470. if ($child->getName() == 'dir') {
  8471. $dirSource = $this->combine($source, (string) $child['name']);
  8472. $dirTarget = $child['baseinstalldir'] ?: $target;
  8473. $dirRole = $child['role'] ?: $role;
  8474. $dirFiles = $this->buildSourceList10($child->children(), $targetRoles, $dirSource, $dirTarget, $dirRole, $packageName);
  8475. $result = array_merge($result, $dirFiles);
  8476. } elseif ($child->getName() == 'file') {
  8477. $fileRole = (string) $child['role'] ?: $role;
  8478. if (isset($targetRoles[$fileRole])) {
  8479. $fileName = (string) ($child['name'] ?: $child[0]);
  8480. $fileSource = $this->combine($source, $fileName);
  8481. $fileTarget = $this->combine((string) $child['baseinstalldir'] ?: $target, $fileName);
  8482. if (!in_array($fileRole, self::$rolesWithoutPackageNamePrefix)) {
  8483. $fileTarget = $packageName . '/' . $fileTarget;
  8484. }
  8485. $result[(string) $child['name']] = array('from' => $fileSource, 'to' => $fileTarget, 'role' => $fileRole, 'tasks' => array());
  8486. }
  8487. }
  8488. }
  8489. return $result;
  8490. }
  8491. private function buildSourceList20($children, $targetRoles, $source, $target, $role, $packageName)
  8492. {
  8493. $result = array();
  8494. foreach ($children as $child) {
  8495. if ('dir' == $child->getName()) {
  8496. $dirSource = $this->combine($source, $child['name']);
  8497. $dirTarget = $child['baseinstalldir'] ?: $target;
  8498. $dirRole = $child['role'] ?: $role;
  8499. $dirFiles = $this->buildSourceList20($child->children(), $targetRoles, $dirSource, $dirTarget, $dirRole, $packageName);
  8500. $result = array_merge($result, $dirFiles);
  8501. } elseif ('file' == $child->getName()) {
  8502. $fileRole = (string) $child['role'] ?: $role;
  8503. if (isset($targetRoles[$fileRole])) {
  8504. $fileSource = $this->combine($source, (string) $child['name']);
  8505. $fileTarget = $this->combine((string) ($child['baseinstalldir'] ?: $target), (string) $child['name']);
  8506. $fileTasks = array();
  8507. foreach ($child->children('http://pear.php.net/dtd/tasks-1.0') as $taskNode) {
  8508. if ('replace' == $taskNode->getName()) {
  8509. $fileTasks[] = array('from' => (string) $taskNode->attributes()->from, 'to' => (string) $taskNode->attributes()->to);
  8510. }
  8511. }
  8512. if (!in_array($fileRole, self::$rolesWithoutPackageNamePrefix)) {
  8513. $fileTarget = $packageName . '/' . $fileTarget;
  8514. }
  8515. $result[(string) $child['name']] = array('from' => $fileSource, 'to' => $fileTarget, 'role' => $fileRole, 'tasks' => $fileTasks);
  8516. }
  8517. }
  8518. }
  8519. return $result;
  8520. }
  8521. private function combine($left, $right)
  8522. {
  8523. return rtrim($left, '/') . '/' . ltrim($right, '/');
  8524. }
  8525. }
  8526. <?php
  8527. namespace Composer\Downloader;
  8528. use Composer\Package\PackageInterface;
  8529. use Composer\Repository\VcsRepository;
  8530. use Composer\Util\Perforce;
  8531. class PerforceDownloader extends VcsDownloader
  8532. {
  8533. protected $perforce;
  8534. public function doDownload(PackageInterface $package, $path, $url)
  8535. {
  8536. $ref = $package->getSourceReference();
  8537. $label = $this->getLabelFromSourceReference($ref);
  8538. $this->io->writeError(' Cloning ' . $ref);
  8539. $this->initPerforce($package, $path, $url);
  8540. $this->perforce->setStream($ref);
  8541. $this->perforce->p4Login($this->io);
  8542. $this->perforce->writeP4ClientSpec();
  8543. $this->perforce->connectClient();
  8544. $this->perforce->syncCodeBase($label);
  8545. $this->perforce->cleanupClientSpec();
  8546. }
  8547. private function getLabelFromSourceReference($ref)
  8548. {
  8549. $pos = strpos($ref, '@');
  8550. if (false !== $pos) {
  8551. return substr($ref, $pos + 1);
  8552. }
  8553. return null;
  8554. }
  8555. public function initPerforce($package, $path, $url)
  8556. {
  8557. if (!empty($this->perforce)) {
  8558. $this->perforce->initializePath($path);
  8559. return;
  8560. }
  8561. $repository = $package->getRepository();
  8562. $repoConfig = null;
  8563. if ($repository instanceof VcsRepository) {
  8564. $repoConfig = $this->getRepoConfig($repository);
  8565. }
  8566. $this->perforce = Perforce::create($repoConfig, $url, $path, $this->process, $this->io);
  8567. }
  8568. private function getRepoConfig(VcsRepository $repository)
  8569. {
  8570. return $repository->getRepoConfig();
  8571. }
  8572. public function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url)
  8573. {
  8574. $this->doDownload($target, $path, $url);
  8575. }
  8576. public function getLocalChanges(PackageInterface $package, $path)
  8577. {
  8578. $this->io->writeError('Perforce driver does not check for local changes before overriding', true);
  8579. return;
  8580. }
  8581. protected function getCommitLogs($fromReference, $toReference, $path)
  8582. {
  8583. $commitLogs = $this->perforce->getCommitLogs($fromReference, $toReference);
  8584. return $commitLogs;
  8585. }
  8586. public function setPerforce($perforce)
  8587. {
  8588. $this->perforce = $perforce;
  8589. }
  8590. }
  8591. <?php
  8592. namespace Composer\Downloader;
  8593. class PharDownloader extends ArchiveDownloader
  8594. {
  8595. protected function extract($file, $path)
  8596. {
  8597. $archive = new \Phar($file);
  8598. $archive->extractTo($path, null, true);
  8599. }
  8600. }
  8601. <?php
  8602. namespace Composer\Downloader;
  8603. use Composer\Config;
  8604. use Composer\Cache;
  8605. use Composer\EventDispatcher\EventDispatcher;
  8606. use Composer\Util\ProcessExecutor;
  8607. use Composer\IO\IOInterface;
  8608. use RarArchive;
  8609. class RarDownloader extends ArchiveDownloader
  8610. {
  8611. protected $process;
  8612. public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null)
  8613. {
  8614. $this->process = $process ?: new ProcessExecutor($io);
  8615. parent::__construct($io, $config, $eventDispatcher, $cache);
  8616. }
  8617. protected function extract($file, $path)
  8618. {
  8619. $processError = null;
  8620. if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
  8621. $command = 'unrar x ' . ProcessExecutor::escape($file) . ' ' . ProcessExecutor::escape($path) . ' && chmod -R u+w ' . ProcessExecutor::escape($path);
  8622. if (0 === $this->process->execute($command, $ignoredOutput)) {
  8623. return;
  8624. }
  8625. $processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput();
  8626. }
  8627. if (!class_exists('RarArchive')) {
  8628. $iniPath = php_ini_loaded_file();
  8629. if ($iniPath) {
  8630. $iniMessage = 'The php.ini used by your command-line PHP is: ' . $iniPath;
  8631. } else {
  8632. $iniMessage = 'A php.ini file does not exist. You will have to create one.';
  8633. }
  8634. $error = "Could not decompress the archive, enable the PHP rar extension or install unrar.\n"
  8635. . $iniMessage . "\n" . $processError;
  8636. if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
  8637. $error = "Could not decompress the archive, enable the PHP rar extension.\n" . $iniMessage;
  8638. }
  8639. throw new \RuntimeException($error);
  8640. }
  8641. $rarArchive = RarArchive::open($file);
  8642. if (false === $rarArchive) {
  8643. throw new \UnexpectedValueException('Could not open RAR archive: ' . $file);
  8644. }
  8645. $entries = $rarArchive->getEntries();
  8646. if (false === $entries) {
  8647. throw new \RuntimeException('Could not retrieve RAR archive entries');
  8648. }
  8649. foreach ($entries as $entry) {
  8650. if (false === $entry->extract($path)) {
  8651. throw new \RuntimeException('Could not extract entry');
  8652. }
  8653. }
  8654. $rarArchive->close();
  8655. }
  8656. }
  8657. <?php
  8658. namespace Composer\Downloader;
  8659. use Composer\Package\PackageInterface;
  8660. use Composer\Util\Svn as SvnUtil;
  8661. class SvnDownloader extends VcsDownloader
  8662. {
  8663. public function doDownload(PackageInterface $package, $path, $url)
  8664. {
  8665. SvnUtil::cleanEnv();
  8666. $ref = $package->getSourceReference();
  8667. $this->io->writeError(" Checking out ".$package->getSourceReference());
  8668. $this->execute($url, "svn co", sprintf("%s/%s", $url, $ref), null, $path);
  8669. }
  8670. public function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url)
  8671. {
  8672. SvnUtil::cleanEnv();
  8673. $ref = $target->getSourceReference();
  8674. if (!is_dir($path.'/.svn')) {
  8675. throw new \RuntimeException('The .svn directory is missing from '.$path.', see https://getcomposer.org/commit-deps for more information');
  8676. }
  8677. $flags = "";
  8678. if (0 === $this->process->execute('svn --version', $output)) {
  8679. if (preg_match('{(\d+(?:\.\d+)+)}', $output, $match) && version_compare($match[1], '1.7.0', '>=')) {
  8680. $flags .= ' --ignore-ancestry';
  8681. }
  8682. }
  8683. $this->io->writeError(" Checking out " . $ref);
  8684. $this->execute($url, "svn switch" . $flags, sprintf("%s/%s", $url, $ref), $path);
  8685. }
  8686. public function getLocalChanges(PackageInterface $package, $path)
  8687. {
  8688. if (!is_dir($path.'/.svn')) {
  8689. return;
  8690. }
  8691. $this->process->execute('svn status --ignore-externals', $output, $path);
  8692. return preg_match('{^ *[^X ] +}m', $output) ? $output : null;
  8693. }
  8694. protected function execute($baseUrl, $command, $url, $cwd = null, $path = null)
  8695. {
  8696. $util = new SvnUtil($baseUrl, $this->io, $this->config);
  8697. try {
  8698. return $util->execute($command, $url, $cwd, $path, $this->io->isVerbose());
  8699. } catch (\RuntimeException $e) {
  8700. throw new \RuntimeException(
  8701. 'Package could not be downloaded, '.$e->getMessage()
  8702. );
  8703. }
  8704. }
  8705. protected function cleanChanges(PackageInterface $package, $path, $update)
  8706. {
  8707. if (!$changes = $this->getLocalChanges($package, $path)) {
  8708. return;
  8709. }
  8710. if (!$this->io->isInteractive()) {
  8711. if (true === $this->config->get('discard-changes')) {
  8712. return $this->discardChanges($path);
  8713. }
  8714. return parent::cleanChanges($package, $path, $update);
  8715. }
  8716. $changes = array_map(function ($elem) {
  8717. return ' '.$elem;
  8718. }, preg_split('{\s*\r?\n\s*}', $changes));
  8719. $this->io->writeError(' <error>The package has modified files:</error>');
  8720. $this->io->writeError(array_slice($changes, 0, 10));
  8721. if (count($changes) > 10) {
  8722. $this->io->writeError(' <info>'.count($changes) - 10 . ' more files modified, choose "v" to view the full list</info>');
  8723. }
  8724. while (true) {
  8725. switch ($this->io->ask(' <info>Discard changes [y,n,v,?]?</info> ', '?')) {
  8726. case 'y':
  8727. $this->discardChanges($path);
  8728. break 2;
  8729. case 'n':
  8730. throw new \RuntimeException('Update aborted');
  8731. case 'v':
  8732. $this->io->writeError($changes);
  8733. break;
  8734. case '?':
  8735. default:
  8736. $this->io->writeError(array(
  8737. ' y - discard changes and apply the '.($update ? 'update' : 'uninstall'),
  8738. ' n - abort the '.($update ? 'update' : 'uninstall').' and let you manually clean things up',
  8739. ' v - view modified files',
  8740. ' ? - print help',
  8741. ));
  8742. break;
  8743. }
  8744. }
  8745. }
  8746. protected function getCommitLogs($fromReference, $toReference, $path)
  8747. {
  8748. if (preg_match('{.*@(\d+)$}', $fromReference) && preg_match('{.*@(\d+)$}', $toReference)) {
  8749. $fromRevision = preg_replace('{.*@(\d+)$}', '$1', $fromReference);
  8750. $toRevision = preg_replace('{.*@(\d+)$}', '$1', $toReference);
  8751. $command = sprintf('svn log -r%s:%s --incremental', $fromRevision, $toRevision);
  8752. if (0 !== $this->process->execute($command, $output, $path)) {
  8753. throw new \RuntimeException(
  8754. 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()
  8755. );
  8756. }
  8757. } else {
  8758. $output = "Could not retrieve changes between $fromReference and $toReference due to missing revision information";
  8759. }
  8760. return $output;
  8761. }
  8762. protected function discardChanges($path)
  8763. {
  8764. if (0 !== $this->process->execute('svn revert -R .', $output, $path)) {
  8765. throw new \RuntimeException("Could not reset changes\n\n:".$this->process->getErrorOutput());
  8766. }
  8767. }
  8768. }
  8769. <?php
  8770. namespace Composer\Downloader;
  8771. class TarDownloader extends ArchiveDownloader
  8772. {
  8773. protected function extract($file, $path)
  8774. {
  8775. $archive = new \PharData($file);
  8776. $archive->extractTo($path, null, true);
  8777. }
  8778. }
  8779. <?php
  8780. namespace Composer\Downloader;
  8781. class TransportException extends \RuntimeException
  8782. {
  8783. protected $headers;
  8784. protected $response;
  8785. public function setHeaders($headers)
  8786. {
  8787. $this->headers = $headers;
  8788. }
  8789. public function getHeaders()
  8790. {
  8791. return $this->headers;
  8792. }
  8793. public function setResponse($response)
  8794. {
  8795. $this->response = $response;
  8796. }
  8797. public function getResponse()
  8798. {
  8799. return $this->response;
  8800. }
  8801. }
  8802. <?php
  8803. namespace Composer\Downloader;
  8804. use Composer\Config;
  8805. use Composer\Package\PackageInterface;
  8806. use Composer\Util\ProcessExecutor;
  8807. use Composer\IO\IOInterface;
  8808. use Composer\Util\Filesystem;
  8809. abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterface
  8810. {
  8811. protected $io;
  8812. protected $config;
  8813. protected $process;
  8814. protected $filesystem;
  8815. public function __construct(IOInterface $io, Config $config, ProcessExecutor $process = null, Filesystem $fs = null)
  8816. {
  8817. $this->io = $io;
  8818. $this->config = $config;
  8819. $this->process = $process ?: new ProcessExecutor($io);
  8820. $this->filesystem = $fs ?: new Filesystem;
  8821. }
  8822. public function getInstallationSource()
  8823. {
  8824. return 'source';
  8825. }
  8826. public function download(PackageInterface $package, $path)
  8827. {
  8828. if (!$package->getSourceReference()) {
  8829. throw new \InvalidArgumentException('Package '.$package->getPrettyName().' is missing reference information');
  8830. }
  8831. $this->io->writeError(" - Installing <info>" . $package->getName() . "</info> (<comment>" . $package->getFullPrettyVersion() . "</comment>)");
  8832. $this->filesystem->emptyDirectory($path);
  8833. $urls = $package->getSourceUrls();
  8834. while ($url = array_shift($urls)) {
  8835. try {
  8836. if (Filesystem::isLocalPath($url)) {
  8837. $url = realpath($url);
  8838. }
  8839. $this->doDownload($package, $path, $url);
  8840. break;
  8841. } catch (\Exception $e) {
  8842. if ($this->io->isDebug()) {
  8843. $this->io->writeError('Failed: ['.get_class($e).'] '.$e->getMessage());
  8844. } elseif (count($urls)) {
  8845. $this->io->writeError(' Failed, trying the next URL');
  8846. }
  8847. if (!count($urls)) {
  8848. throw $e;
  8849. }
  8850. }
  8851. }
  8852. $this->io->writeError('');
  8853. }
  8854. public function update(PackageInterface $initial, PackageInterface $target, $path)
  8855. {
  8856. if (!$target->getSourceReference()) {
  8857. throw new \InvalidArgumentException('Package '.$target->getPrettyName().' is missing reference information');
  8858. }
  8859. $name = $target->getName();
  8860. if ($initial->getPrettyVersion() == $target->getPrettyVersion()) {
  8861. if ($target->getSourceType() === 'svn') {
  8862. $from = $initial->getSourceReference();
  8863. $to = $target->getSourceReference();
  8864. } else {
  8865. $from = substr($initial->getSourceReference(), 0, 7);
  8866. $to = substr($target->getSourceReference(), 0, 7);
  8867. }
  8868. $name .= ' '.$initial->getPrettyVersion();
  8869. } else {
  8870. $from = $initial->getFullPrettyVersion();
  8871. $to = $target->getFullPrettyVersion();
  8872. }
  8873. $this->io->writeError(" - Updating <info>" . $name . "</info> (<comment>" . $from . "</comment> => <comment>" . $to . "</comment>)");
  8874. $this->cleanChanges($initial, $path, true);
  8875. $urls = $target->getSourceUrls();
  8876. while ($url = array_shift($urls)) {
  8877. try {
  8878. if (Filesystem::isLocalPath($url)) {
  8879. $url = realpath($url);
  8880. }
  8881. $this->doUpdate($initial, $target, $path, $url);
  8882. break;
  8883. } catch (\Exception $e) {
  8884. if ($this->io->isDebug()) {
  8885. $this->io->writeError('Failed: ['.get_class($e).'] '.$e->getMessage());
  8886. } elseif (count($urls)) {
  8887. $this->io->writeError(' Failed, trying the next URL');
  8888. } else {
  8889. $this->reapplyChanges($path);
  8890. throw $e;
  8891. }
  8892. }
  8893. }
  8894. $this->reapplyChanges($path);
  8895. if ($this->io->isVerbose()) {
  8896. $message = 'Pulling in changes:';
  8897. $logs = $this->getCommitLogs($initial->getSourceReference(), $target->getSourceReference(), $path);
  8898. if (!trim($logs)) {
  8899. $message = 'Rolling back changes:';
  8900. $logs = $this->getCommitLogs($target->getSourceReference(), $initial->getSourceReference(), $path);
  8901. }
  8902. if (trim($logs)) {
  8903. $logs = implode("\n", array_map(function ($line) {
  8904. return ' ' . $line;
  8905. }, explode("\n", $logs)));
  8906. $this->io->writeError(' '.$message);
  8907. $this->io->writeError($logs);
  8908. }
  8909. }
  8910. $this->io->writeError('');
  8911. }
  8912. public function remove(PackageInterface $package, $path)
  8913. {
  8914. $this->io->writeError(" - Removing <info>" . $package->getName() . "</info> (<comment>" . $package->getPrettyVersion() . "</comment>)");
  8915. $this->cleanChanges($package, $path, false);
  8916. if (!$this->filesystem->removeDirectory($path)) {
  8917. throw new \RuntimeException('Could not completely delete '.$path.', aborting.');
  8918. }
  8919. }
  8920. public function setOutputProgress($outputProgress)
  8921. {
  8922. return $this;
  8923. }
  8924. protected function cleanChanges(PackageInterface $package, $path, $update)
  8925. {
  8926. if (null !== $this->getLocalChanges($package, $path)) {
  8927. throw new \RuntimeException('Source directory ' . $path . ' has uncommitted changes.');
  8928. }
  8929. }
  8930. protected function reapplyChanges($path)
  8931. {
  8932. }
  8933. abstract protected function doDownload(PackageInterface $package, $path, $url);
  8934. abstract protected function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url);
  8935. abstract protected function getCommitLogs($fromReference, $toReference, $path);
  8936. }
  8937. <?php
  8938. namespace Composer\Downloader;
  8939. use Composer\Config;
  8940. use Composer\Cache;
  8941. use Composer\EventDispatcher\EventDispatcher;
  8942. use Composer\Util\ProcessExecutor;
  8943. use Composer\IO\IOInterface;
  8944. use ZipArchive;
  8945. class ZipDownloader extends ArchiveDownloader
  8946. {
  8947. protected $process;
  8948. public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null)
  8949. {
  8950. $this->process = $process ?: new ProcessExecutor($io);
  8951. parent::__construct($io, $config, $eventDispatcher, $cache);
  8952. }
  8953. protected function extract($file, $path)
  8954. {
  8955. $processError = null;
  8956. if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
  8957. $command = 'unzip '.ProcessExecutor::escape($file).' -d '.ProcessExecutor::escape($path) . ' && chmod -R u+w ' . ProcessExecutor::escape($path);
  8958. try {
  8959. if (0 === $this->process->execute($command, $ignoredOutput)) {
  8960. return;
  8961. }
  8962. $processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput();
  8963. } catch (\Exception $e) {
  8964. $processError = 'Failed to execute ' . $command . "\n\n" . $e->getMessage();
  8965. }
  8966. }
  8967. if (!class_exists('ZipArchive')) {
  8968. $iniPath = php_ini_loaded_file();
  8969. if ($iniPath) {
  8970. $iniMessage = 'The php.ini used by your command-line PHP is: ' . $iniPath;
  8971. } else {
  8972. $iniMessage = 'A php.ini file does not exist. You will have to create one.';
  8973. }
  8974. $error = "Could not decompress the archive, enable the PHP zip extension or install unzip.\n"
  8975. . $iniMessage . "\n" . $processError;
  8976. if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
  8977. $error = "Could not decompress the archive, enable the PHP zip extension.\n" . $iniMessage;
  8978. }
  8979. throw new \RuntimeException($error);
  8980. }
  8981. $zipArchive = new ZipArchive();
  8982. if (true !== ($retval = $zipArchive->open($file))) {
  8983. throw new \UnexpectedValueException($this->getErrorMessage($retval, $file), $retval);
  8984. }
  8985. if (true !== $zipArchive->extractTo($path)) {
  8986. throw new \RuntimeException("There was an error extracting the ZIP file. Corrupt file?");
  8987. }
  8988. $zipArchive->close();
  8989. }
  8990. protected function getErrorMessage($retval, $file)
  8991. {
  8992. switch ($retval) {
  8993. case ZipArchive::ER_EXISTS:
  8994. return sprintf("File '%s' already exists.", $file);
  8995. case ZipArchive::ER_INCONS:
  8996. return sprintf("Zip archive '%s' is inconsistent.", $file);
  8997. case ZipArchive::ER_INVAL:
  8998. return sprintf("Invalid argument (%s)", $file);
  8999. case ZipArchive::ER_MEMORY:
  9000. return sprintf("Malloc failure (%s)", $file);
  9001. case ZipArchive::ER_NOENT:
  9002. return sprintf("No such zip file: '%s'", $file);
  9003. case ZipArchive::ER_NOZIP:
  9004. return sprintf("'%s' is not a zip archive.", $file);
  9005. case ZipArchive::ER_OPEN:
  9006. return sprintf("Can't open zip file: %s", $file);
  9007. case ZipArchive::ER_READ:
  9008. return sprintf("Zip read error (%s)", $file);
  9009. case ZipArchive::ER_SEEK:
  9010. return sprintf("Zip seek error (%s)", $file);
  9011. default:
  9012. return sprintf("'%s' is not a valid zip archive, got error code: %s", $file, $retval);
  9013. }
  9014. }
  9015. }
  9016. <?php
  9017. namespace Composer\EventDispatcher;
  9018. class Event
  9019. {
  9020. protected $name;
  9021. protected $args;
  9022. protected $flags;
  9023. private $propagationStopped = false;
  9024. public function __construct($name, array $args = array(), array $flags = array())
  9025. {
  9026. $this->name = $name;
  9027. $this->args = $args;
  9028. $this->flags = $flags;
  9029. }
  9030. public function getName()
  9031. {
  9032. return $this->name;
  9033. }
  9034. public function getArguments()
  9035. {
  9036. return $this->args;
  9037. }
  9038. public function getFlags()
  9039. {
  9040. return $this->flags;
  9041. }
  9042. public function isPropagationStopped()
  9043. {
  9044. return $this->propagationStopped;
  9045. }
  9046. public function stopPropagation()
  9047. {
  9048. $this->propagationStopped = true;
  9049. }
  9050. }
  9051. <?php
  9052. namespace Composer\EventDispatcher;
  9053. use Composer\DependencyResolver\PolicyInterface;
  9054. use Composer\DependencyResolver\Pool;
  9055. use Composer\DependencyResolver\Request;
  9056. use Composer\Installer\InstallerEvent;
  9057. use Composer\IO\IOInterface;
  9058. use Composer\Composer;
  9059. use Composer\DependencyResolver\Operation\OperationInterface;
  9060. use Composer\Repository\CompositeRepository;
  9061. use Composer\Script;
  9062. use Composer\Script\CommandEvent;
  9063. use Composer\Script\PackageEvent;
  9064. use Composer\Util\ProcessExecutor;
  9065. class EventDispatcher
  9066. {
  9067. protected $composer;
  9068. protected $io;
  9069. protected $loader;
  9070. protected $process;
  9071. protected $listeners;
  9072. public function __construct(Composer $composer, IOInterface $io, ProcessExecutor $process = null)
  9073. {
  9074. $this->composer = $composer;
  9075. $this->io = $io;
  9076. $this->process = $process ?: new ProcessExecutor($io);
  9077. }
  9078. public function dispatch($eventName, Event $event = null)
  9079. {
  9080. if (null == $event) {
  9081. $event = new Event($eventName);
  9082. }
  9083. return $this->doDispatch($event);
  9084. }
  9085. public function dispatchScript($eventName, $devMode = false, $additionalArgs = array(), $flags = array())
  9086. {
  9087. return $this->doDispatch(new Script\Event($eventName, $this->composer, $this->io, $devMode, $additionalArgs, $flags));
  9088. }
  9089. public function dispatchPackageEvent($eventName, $devMode, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request, array $operations, OperationInterface $operation)
  9090. {
  9091. return $this->doDispatch(new PackageEvent($eventName, $this->composer, $this->io, $devMode, $policy, $pool, $installedRepo, $request, $operations, $operation));
  9092. }
  9093. public function dispatchInstallerEvent($eventName, $devMode, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request, array $operations = array())
  9094. {
  9095. return $this->doDispatch(new InstallerEvent($eventName, $this->composer, $this->io, $devMode, $policy, $pool, $installedRepo, $request, $operations));
  9096. }
  9097. protected function doDispatch(Event $event)
  9098. {
  9099. $listeners = $this->getListeners($event);
  9100. $return = 0;
  9101. foreach ($listeners as $callable) {
  9102. if (!is_string($callable) && is_callable($callable)) {
  9103. $event = $this->checkListenerExpectedEvent($callable, $event);
  9104. $return = false === call_user_func($callable, $event) ? 1 : 0;
  9105. } elseif ($this->isPhpScript($callable)) {
  9106. $className = substr($callable, 0, strpos($callable, '::'));
  9107. $methodName = substr($callable, strpos($callable, '::') + 2);
  9108. if (!class_exists($className)) {
  9109. $this->io->writeError('<warning>Class '.$className.' is not autoloadable, can not call '.$event->getName().' script</warning>');
  9110. continue;
  9111. }
  9112. if (!is_callable($callable)) {
  9113. $this->io->writeError('<warning>Method '.$callable.' is not callable, can not call '.$event->getName().' script</warning>');
  9114. continue;
  9115. }
  9116. try {
  9117. $return = false === $this->executeEventPhpScript($className, $methodName, $event) ? 1 : 0;
  9118. } catch (\Exception $e) {
  9119. $message = "Script %s handling the %s event terminated with an exception";
  9120. $this->io->writeError('<error>'.sprintf($message, $callable, $event->getName()).'</error>');
  9121. throw $e;
  9122. }
  9123. } else {
  9124. $args = implode(' ', array_map(array('Composer\Util\ProcessExecutor', 'escape'), $event->getArguments()));
  9125. $exec = $callable . ($args === '' ? '' : ' '.$args);
  9126. if ($this->io->isVerbose()) {
  9127. $this->io->writeError(sprintf('> %s: %s', $event->getName(), $exec));
  9128. } else {
  9129. $this->io->writeError(sprintf('> %s', $exec));
  9130. }
  9131. if (0 !== ($exitCode = $this->process->execute($exec))) {
  9132. $this->io->writeError(sprintf('<error>Script %s handling the %s event returned with an error</error>', $callable, $event->getName()));
  9133. throw new \RuntimeException('Error Output: '.$this->process->getErrorOutput(), $exitCode);
  9134. }
  9135. }
  9136. if ($event->isPropagationStopped()) {
  9137. break;
  9138. }
  9139. }
  9140. return $return;
  9141. }
  9142. protected function executeEventPhpScript($className, $methodName, Event $event)
  9143. {
  9144. $event = $this->checkListenerExpectedEvent(array($className, $methodName), $event);
  9145. if ($this->io->isVerbose()) {
  9146. $this->io->writeError(sprintf('> %s: %s::%s', $event->getName(), $className, $methodName));
  9147. } else {
  9148. $this->io->writeError(sprintf('> %s::%s', $className, $methodName));
  9149. }
  9150. return $className::$methodName($event);
  9151. }
  9152. protected function checkListenerExpectedEvent($target, Event $event)
  9153. {
  9154. try {
  9155. $reflected = new \ReflectionParameter($target, 0);
  9156. } catch (\Exception $e) {
  9157. return $event;
  9158. }
  9159. $typehint = $reflected->getClass();
  9160. if (!$typehint instanceof \ReflectionClass) {
  9161. return $event;
  9162. }
  9163. $expected = $typehint->getName();
  9164. if (!$event instanceof $expected && $expected === 'Composer\Script\CommandEvent') {
  9165. $event = new \Composer\Script\CommandEvent(
  9166. $event->getName(), $event->getComposer(), $event->getIO(), $event->isDevMode(), $event->getArguments()
  9167. );
  9168. }
  9169. if (!$event instanceof $expected && $expected === 'Composer\Script\PackageEvent') {
  9170. $event = new \Composer\Script\PackageEvent(
  9171. $event->getName(), $event->getComposer(), $event->getIO(), $event->isDevMode(),
  9172. $event->getPolicy(), $event->getPool(), $event->getInstalledRepo(), $event->getRequest(),
  9173. $event->getOperations(), $event->getOperation()
  9174. );
  9175. }
  9176. if (!$event instanceof $expected && $expected === 'Composer\Script\Event') {
  9177. $event = new \Composer\Script\Event(
  9178. $event->getName(), $event->getComposer(), $event->getIO(), $event->isDevMode(),
  9179. $event->getArguments(), $event->getFlags()
  9180. );
  9181. }
  9182. return $event;
  9183. }
  9184. protected function addListener($eventName, $listener, $priority = 0)
  9185. {
  9186. $this->listeners[$eventName][$priority][] = $listener;
  9187. }
  9188. public function addSubscriber(EventSubscriberInterface $subscriber)
  9189. {
  9190. foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
  9191. if (is_string($params)) {
  9192. $this->addListener($eventName, array($subscriber, $params));
  9193. } elseif (is_string($params[0])) {
  9194. $this->addListener($eventName, array($subscriber, $params[0]), isset($params[1]) ? $params[1] : 0);
  9195. } else {
  9196. foreach ($params as $listener) {
  9197. $this->addListener($eventName, array($subscriber, $listener[0]), isset($listener[1]) ? $listener[1] : 0);
  9198. }
  9199. }
  9200. }
  9201. }
  9202. protected function getListeners(Event $event)
  9203. {
  9204. $scriptListeners = $this->getScriptListeners($event);
  9205. if (!isset($this->listeners[$event->getName()][0])) {
  9206. $this->listeners[$event->getName()][0] = array();
  9207. }
  9208. krsort($this->listeners[$event->getName()]);
  9209. $listeners = $this->listeners;
  9210. $listeners[$event->getName()][0] = array_merge($listeners[$event->getName()][0], $scriptListeners);
  9211. return call_user_func_array('array_merge', $listeners[$event->getName()]);
  9212. }
  9213. public function hasEventListeners(Event $event)
  9214. {
  9215. $listeners = $this->getListeners($event);
  9216. return count($listeners) > 0;
  9217. }
  9218. protected function getScriptListeners(Event $event)
  9219. {
  9220. $package = $this->composer->getPackage();
  9221. $scripts = $package->getScripts();
  9222. if (empty($scripts[$event->getName()])) {
  9223. return array();
  9224. }
  9225. if ($this->loader) {
  9226. $this->loader->unregister();
  9227. }
  9228. $generator = $this->composer->getAutoloadGenerator();
  9229. $packages = $this->composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages();
  9230. $packageMap = $generator->buildPackageMap($this->composer->getInstallationManager(), $package, $packages);
  9231. $map = $generator->parseAutoloads($packageMap, $package);
  9232. $this->loader = $generator->createLoader($map);
  9233. $this->loader->register();
  9234. return $scripts[$event->getName()];
  9235. }
  9236. protected function isPhpScript($callable)
  9237. {
  9238. return false === strpos($callable, ' ') && false !== strpos($callable, '::');
  9239. }
  9240. }
  9241. <?php
  9242. namespace Composer\EventDispatcher;
  9243. interface EventSubscriberInterface
  9244. {
  9245. public static function getSubscribedEvents();
  9246. }
  9247. <?php
  9248. namespace Composer;
  9249. use Composer\Config\JsonConfigSource;
  9250. use Composer\Json\JsonFile;
  9251. use Composer\IO\IOInterface;
  9252. use Composer\Package\Archiver;
  9253. use Composer\Package\Version\VersionGuesser;
  9254. use Composer\Repository\RepositoryManager;
  9255. use Composer\Repository\WritableRepositoryInterface;
  9256. use Composer\Util\ProcessExecutor;
  9257. use Composer\Util\RemoteFilesystem;
  9258. use Symfony\Component\Console\Formatter\OutputFormatterStyle;
  9259. use Composer\EventDispatcher\EventDispatcher;
  9260. use Composer\Autoload\AutoloadGenerator;
  9261. use Composer\Semver\VersionParser;
  9262. class Factory
  9263. {
  9264. protected static function getHomeDir()
  9265. {
  9266. $home = getenv('COMPOSER_HOME');
  9267. if (!$home) {
  9268. if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
  9269. if (!getenv('APPDATA')) {
  9270. throw new \RuntimeException('The APPDATA or COMPOSER_HOME environment variable must be set for composer to run correctly');
  9271. }
  9272. $home = strtr(getenv('APPDATA'), '\\', '/') . '/Composer';
  9273. } else {
  9274. if (!getenv('HOME')) {
  9275. throw new \RuntimeException('The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly');
  9276. }
  9277. $home = rtrim(getenv('HOME'), '/') . '/.composer';
  9278. }
  9279. }
  9280. return $home;
  9281. }
  9282. protected static function getCacheDir($home)
  9283. {
  9284. $cacheDir = getenv('COMPOSER_CACHE_DIR');
  9285. if (!$cacheDir) {
  9286. if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
  9287. if ($cacheDir = getenv('LOCALAPPDATA')) {
  9288. $cacheDir .= '/Composer';
  9289. } else {
  9290. $cacheDir = $home . '/cache';
  9291. }
  9292. $cacheDir = strtr($cacheDir, '\\', '/');
  9293. } else {
  9294. $cacheDir = $home.'/cache';
  9295. }
  9296. }
  9297. return $cacheDir;
  9298. }
  9299. public static function createConfig(IOInterface $io = null, $cwd = null)
  9300. {
  9301. $cwd = $cwd ?: getcwd();
  9302. $home = self::getHomeDir();
  9303. $cacheDir = self::getCacheDir($home);
  9304. foreach (array($home, $cacheDir) as $dir) {
  9305. if (!file_exists($dir . '/.htaccess')) {
  9306. if (!is_dir($dir)) {
  9307. @mkdir($dir, 0777, true);
  9308. }
  9309. @file_put_contents($dir . '/.htaccess', 'Deny from all');
  9310. }
  9311. }
  9312. $config = new Config(true, $cwd);
  9313. $config->merge(array('config' => array('home' => $home, 'cache-dir' => $cacheDir)));
  9314. $file = new JsonFile($config->get('home').'/config.json');
  9315. if ($file->exists()) {
  9316. if ($io && $io->isDebug()) {
  9317. $io->writeError('Loading config file ' . $file->getPath());
  9318. }
  9319. $config->merge($file->read());
  9320. }
  9321. $config->setConfigSource(new JsonConfigSource($file));
  9322. $file = new JsonFile($config->get('home').'/auth.json');
  9323. if ($file->exists()) {
  9324. if ($io && $io->isDebug()) {
  9325. $io->writeError('Loading config file ' . $file->getPath());
  9326. }
  9327. $config->merge(array('config' => $file->read()));
  9328. }
  9329. $config->setAuthConfigSource(new JsonConfigSource($file, true));
  9330. return $config;
  9331. }
  9332. public static function getComposerFile()
  9333. {
  9334. return trim(getenv('COMPOSER')) ?: './composer.json';
  9335. }
  9336. public static function createAdditionalStyles()
  9337. {
  9338. return array(
  9339. 'highlight' => new OutputFormatterStyle('red'),
  9340. 'warning' => new OutputFormatterStyle('black', 'yellow'),
  9341. );
  9342. }
  9343. public static function createDefaultRepositories(IOInterface $io = null, Config $config = null, RepositoryManager $rm = null)
  9344. {
  9345. $repos = array();
  9346. if (!$config) {
  9347. $config = static::createConfig($io);
  9348. }
  9349. if (!$rm) {
  9350. if (!$io) {
  9351. throw new \InvalidArgumentException('This function requires either an IOInterface or a RepositoryManager');
  9352. }
  9353. $factory = new static;
  9354. $rm = $factory->createRepositoryManager($io, $config);
  9355. }
  9356. foreach ($config->getRepositories() as $index => $repo) {
  9357. if (is_string($repo)) {
  9358. throw new \UnexpectedValueException('"repositories" should be an array of repository definitions, only a single repository was given');
  9359. }
  9360. if (!is_array($repo)) {
  9361. throw new \UnexpectedValueException('Repository "'.$index.'" ('.json_encode($repo).') should be an array, '.gettype($repo).' given');
  9362. }
  9363. if (!isset($repo['type'])) {
  9364. throw new \UnexpectedValueException('Repository "'.$index.'" ('.json_encode($repo).') must have a type defined');
  9365. }
  9366. $name = is_int($index) && isset($repo['url']) ? preg_replace('{^https?://}i', '', $repo['url']) : $index;
  9367. while (isset($repos[$name])) {
  9368. $name .= '2';
  9369. }
  9370. $repos[$name] = $rm->createRepository($repo['type'], $repo);
  9371. }
  9372. return $repos;
  9373. }
  9374. public function createComposer(IOInterface $io, $localConfig = null, $disablePlugins = false, $cwd = null, $fullLoad = true)
  9375. {
  9376. $cwd = $cwd ?: getcwd();
  9377. if (null === $localConfig) {
  9378. $localConfig = static::getComposerFile();
  9379. }
  9380. if (is_string($localConfig)) {
  9381. $composerFile = $localConfig;
  9382. $file = new JsonFile($localConfig, new RemoteFilesystem($io));
  9383. if (!$file->exists()) {
  9384. if ($localConfig === './composer.json' || $localConfig === 'composer.json') {
  9385. $message = 'Composer could not find a composer.json file in '.$cwd;
  9386. } else {
  9387. $message = 'Composer could not find the config file: '.$localConfig;
  9388. }
  9389. $instructions = 'To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section';
  9390. throw new \InvalidArgumentException($message.PHP_EOL.$instructions);
  9391. }
  9392. $file->validateSchema(JsonFile::LAX_SCHEMA);
  9393. $localConfig = $file->read();
  9394. }
  9395. $config = static::createConfig($io, $cwd);
  9396. $config->merge($localConfig);
  9397. if (isset($composerFile)) {
  9398. if ($io && $io->isDebug()) {
  9399. $io->writeError('Loading config file ' . $composerFile);
  9400. }
  9401. $localAuthFile = new JsonFile(dirname(realpath($composerFile)) . '/auth.json');
  9402. if ($localAuthFile->exists()) {
  9403. if ($io && $io->isDebug()) {
  9404. $io->writeError('Loading config file ' . $localAuthFile->getPath());
  9405. }
  9406. $config->merge(array('config' => $localAuthFile->read()));
  9407. $config->setAuthConfigSource(new JsonConfigSource($localAuthFile, true));
  9408. }
  9409. }
  9410. $vendorDir = $config->get('vendor-dir');
  9411. $binDir = $config->get('bin-dir');
  9412. $composer = new Composer();
  9413. $composer->setConfig($config);
  9414. if ($fullLoad) {
  9415. $io->loadConfiguration($config);
  9416. }
  9417. $dispatcher = new EventDispatcher($composer, $io);
  9418. $composer->setEventDispatcher($dispatcher);
  9419. $rm = $this->createRepositoryManager($io, $config, $dispatcher);
  9420. $composer->setRepositoryManager($rm);
  9421. $this->addLocalRepository($rm, $vendorDir);
  9422. $parser = new VersionParser;
  9423. $guesser = new VersionGuesser($config, new ProcessExecutor($io), $parser);
  9424. $loader = new Package\Loader\RootPackageLoader($rm, $config, $parser, $guesser);
  9425. $package = $loader->load($localConfig);
  9426. $composer->setPackage($package);
  9427. $im = $this->createInstallationManager();
  9428. $composer->setInstallationManager($im);
  9429. if ($fullLoad) {
  9430. $dm = $this->createDownloadManager($io, $config, $dispatcher);
  9431. $composer->setDownloadManager($dm);
  9432. $generator = new AutoloadGenerator($dispatcher, $io);
  9433. $composer->setAutoloadGenerator($generator);
  9434. }
  9435. $this->createDefaultInstallers($im, $composer, $io);
  9436. if ($fullLoad) {
  9437. $globalComposer = $this->createGlobalComposer($io, $config, $disablePlugins);
  9438. $pm = $this->createPluginManager($io, $composer, $globalComposer);
  9439. $composer->setPluginManager($pm);
  9440. if (!$disablePlugins) {
  9441. $pm->loadInstalledPlugins();
  9442. }
  9443. if ($rm->getLocalRepository()) {
  9444. $this->purgePackages($rm->getLocalRepository(), $im);
  9445. }
  9446. }
  9447. if ($fullLoad && isset($composerFile)) {
  9448. $lockFile = "json" === pathinfo($composerFile, PATHINFO_EXTENSION)
  9449. ? substr($composerFile, 0, -4).'lock'
  9450. : $composerFile . '.lock';
  9451. $locker = new Package\Locker($io, new JsonFile($lockFile, new RemoteFilesystem($io, $config)), $rm, $im, file_get_contents($composerFile));
  9452. $composer->setLocker($locker);
  9453. }
  9454. return $composer;
  9455. }
  9456. protected function createRepositoryManager(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null)
  9457. {
  9458. $rm = new RepositoryManager($io, $config, $eventDispatcher);
  9459. $rm->setRepositoryClass('composer', 'Composer\Repository\ComposerRepository');
  9460. $rm->setRepositoryClass('vcs', 'Composer\Repository\VcsRepository');
  9461. $rm->setRepositoryClass('package', 'Composer\Repository\PackageRepository');
  9462. $rm->setRepositoryClass('pear', 'Composer\Repository\PearRepository');
  9463. $rm->setRepositoryClass('git', 'Composer\Repository\VcsRepository');
  9464. $rm->setRepositoryClass('svn', 'Composer\Repository\VcsRepository');
  9465. $rm->setRepositoryClass('perforce', 'Composer\Repository\VcsRepository');
  9466. $rm->setRepositoryClass('hg', 'Composer\Repository\VcsRepository');
  9467. $rm->setRepositoryClass('artifact', 'Composer\Repository\ArtifactRepository');
  9468. $rm->setRepositoryClass('path', 'Composer\Repository\PathRepository');
  9469. return $rm;
  9470. }
  9471. protected function addLocalRepository(RepositoryManager $rm, $vendorDir)
  9472. {
  9473. $rm->setLocalRepository(new Repository\InstalledFilesystemRepository(new JsonFile($vendorDir.'/composer/installed.json')));
  9474. }
  9475. protected function createGlobalComposer(IOInterface $io, Config $config, $disablePlugins)
  9476. {
  9477. if (realpath($config->get('home')) === getcwd()) {
  9478. return;
  9479. }
  9480. $composer = null;
  9481. try {
  9482. $composer = self::createComposer($io, $config->get('home') . '/composer.json', $disablePlugins, $config->get('home'), false);
  9483. } catch (\Exception $e) {
  9484. if ($io->isDebug()) {
  9485. $io->writeError('Failed to initialize global composer: '.$e->getMessage());
  9486. }
  9487. }
  9488. return $composer;
  9489. }
  9490. public function createDownloadManager(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null)
  9491. {
  9492. $cache = null;
  9493. if ($config->get('cache-files-ttl') > 0) {
  9494. $cache = new Cache($io, $config->get('cache-files-dir'), 'a-z0-9_./');
  9495. }
  9496. $dm = new Downloader\DownloadManager($io);
  9497. switch ($config->get('preferred-install')) {
  9498. case 'dist':
  9499. $dm->setPreferDist(true);
  9500. break;
  9501. case 'source':
  9502. $dm->setPreferSource(true);
  9503. break;
  9504. case 'auto':
  9505. default:
  9506. break;
  9507. }
  9508. $dm->setDownloader('git', new Downloader\GitDownloader($io, $config));
  9509. $dm->setDownloader('svn', new Downloader\SvnDownloader($io, $config));
  9510. $dm->setDownloader('hg', new Downloader\HgDownloader($io, $config));
  9511. $dm->setDownloader('perforce', new Downloader\PerforceDownloader($io, $config));
  9512. $dm->setDownloader('zip', new Downloader\ZipDownloader($io, $config, $eventDispatcher, $cache));
  9513. $dm->setDownloader('rar', new Downloader\RarDownloader($io, $config, $eventDispatcher, $cache));
  9514. $dm->setDownloader('tar', new Downloader\TarDownloader($io, $config, $eventDispatcher, $cache));
  9515. $dm->setDownloader('gzip', new Downloader\GzipDownloader($io, $config, $eventDispatcher, $cache));
  9516. $dm->setDownloader('phar', new Downloader\PharDownloader($io, $config, $eventDispatcher, $cache));
  9517. $dm->setDownloader('file', new Downloader\FileDownloader($io, $config, $eventDispatcher, $cache));
  9518. $dm->setDownloader('path', new Downloader\PathDownloader($io, $config, $eventDispatcher, $cache));
  9519. return $dm;
  9520. }
  9521. public function createArchiveManager(Config $config, Downloader\DownloadManager $dm = null)
  9522. {
  9523. if (null === $dm) {
  9524. $io = new IO\NullIO();
  9525. $io->loadConfiguration($config);
  9526. $dm = $this->createDownloadManager($io, $config);
  9527. }
  9528. $am = new Archiver\ArchiveManager($dm);
  9529. $am->addArchiver(new Archiver\PharArchiver);
  9530. return $am;
  9531. }
  9532. protected function createPluginManager(IOInterface $io, Composer $composer, Composer $globalComposer = null)
  9533. {
  9534. return new Plugin\PluginManager($io, $composer, $globalComposer);
  9535. }
  9536. protected function createInstallationManager()
  9537. {
  9538. return new Installer\InstallationManager();
  9539. }
  9540. protected function createDefaultInstallers(Installer\InstallationManager $im, Composer $composer, IOInterface $io)
  9541. {
  9542. $im->addInstaller(new Installer\LibraryInstaller($io, $composer, null));
  9543. $im->addInstaller(new Installer\PearInstaller($io, $composer, 'pear-library'));
  9544. $im->addInstaller(new Installer\PluginInstaller($io, $composer));
  9545. $im->addInstaller(new Installer\MetapackageInstaller($io));
  9546. }
  9547. protected function purgePackages(WritableRepositoryInterface $repo, Installer\InstallationManager $im)
  9548. {
  9549. foreach ($repo->getPackages() as $package) {
  9550. if (!$im->isPackageInstalled($repo, $package)) {
  9551. $repo->removePackage($package);
  9552. }
  9553. }
  9554. }
  9555. public static function create(IOInterface $io, $config = null, $disablePlugins = false)
  9556. {
  9557. $factory = new static();
  9558. return $factory->createComposer($io, $config, $disablePlugins);
  9559. }
  9560. }
  9561. <?php
  9562. namespace Composer\IO;
  9563. use Composer\Config;
  9564. use Composer\Util\ProcessExecutor;
  9565. abstract class BaseIO implements IOInterface
  9566. {
  9567. protected $authentications = array();
  9568. public function getAuthentications()
  9569. {
  9570. return $this->authentications;
  9571. }
  9572. public function hasAuthentication($repositoryName)
  9573. {
  9574. return isset($this->authentications[$repositoryName]);
  9575. }
  9576. public function getAuthentication($repositoryName)
  9577. {
  9578. if (isset($this->authentications[$repositoryName])) {
  9579. return $this->authentications[$repositoryName];
  9580. }
  9581. return array('username' => null, 'password' => null);
  9582. }
  9583. public function setAuthentication($repositoryName, $username, $password = null)
  9584. {
  9585. $this->authentications[$repositoryName] = array('username' => $username, 'password' => $password);
  9586. }
  9587. public function loadConfiguration(Config $config)
  9588. {
  9589. if ($tokens = $config->get('github-oauth')) {
  9590. foreach ($tokens as $domain => $token) {
  9591. if (!preg_match('{^[a-z0-9]+$}', $token)) {
  9592. throw new \UnexpectedValueException('Your github oauth token for '.$domain.' contains invalid characters: "'.$token.'"');
  9593. }
  9594. $this->setAuthentication($domain, $token, 'x-oauth-basic');
  9595. }
  9596. }
  9597. if ($creds = $config->get('http-basic')) {
  9598. foreach ($creds as $domain => $cred) {
  9599. $this->setAuthentication($domain, $cred['username'], $cred['password']);
  9600. }
  9601. }
  9602. ProcessExecutor::setTimeout((int) $config->get('process-timeout'));
  9603. }
  9604. }
  9605. <?php
  9606. namespace Composer\IO;
  9607. use Symfony\Component\Console\Output\StreamOutput;
  9608. use Symfony\Component\Console\Formatter\OutputFormatterInterface;
  9609. use Symfony\Component\Console\Input\StringInput;
  9610. use Symfony\Component\Console\Helper\HelperSet;
  9611. class BufferIO extends ConsoleIO
  9612. {
  9613. public function __construct(
  9614. $input = '',
  9615. $verbosity = StreamOutput::VERBOSITY_NORMAL,
  9616. OutputFormatterInterface $formatter = null
  9617. ) {
  9618. $input = new StringInput($input);
  9619. $input->setInteractive(false);
  9620. $output = new StreamOutput(fopen('php://memory', 'rw'), $verbosity, !empty($formatter), $formatter);
  9621. parent::__construct($input, $output, new HelperSet(array()));
  9622. }
  9623. public function getOutput()
  9624. {
  9625. fseek($this->output->getStream(), 0);
  9626. $output = stream_get_contents($this->output->getStream());
  9627. $output = preg_replace_callback("{(?<=^|\n|\x08)(.+?)(\x08+)}", function ($matches) {
  9628. $pre = strip_tags($matches[1]);
  9629. if (strlen($pre) === strlen($matches[2])) {
  9630. return '';
  9631. }
  9632. return rtrim($matches[1])."\n";
  9633. }, $output);
  9634. return $output;
  9635. }
  9636. }
  9637. <?php
  9638. namespace Composer\IO;
  9639. use Symfony\Component\Console\Input\InputInterface;
  9640. use Symfony\Component\Console\Output\ConsoleOutputInterface;
  9641. use Symfony\Component\Console\Output\OutputInterface;
  9642. use Symfony\Component\Console\Helper\HelperSet;
  9643. use Symfony\Component\Console\Question\ConfirmationQuestion;
  9644. use Symfony\Component\Console\Question\Question;
  9645. class ConsoleIO extends BaseIO
  9646. {
  9647. protected $input;
  9648. protected $output;
  9649. protected $helperSet;
  9650. protected $lastMessage;
  9651. protected $lastMessageErr;
  9652. private $startTime;
  9653. public function __construct(InputInterface $input, OutputInterface $output, HelperSet $helperSet)
  9654. {
  9655. $this->input = $input;
  9656. $this->output = $output;
  9657. $this->helperSet = $helperSet;
  9658. }
  9659. public function enableDebugging($startTime)
  9660. {
  9661. $this->startTime = $startTime;
  9662. }
  9663. public function isInteractive()
  9664. {
  9665. return $this->input->isInteractive();
  9666. }
  9667. public function isDecorated()
  9668. {
  9669. return $this->output->isDecorated();
  9670. }
  9671. public function isVerbose()
  9672. {
  9673. return $this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE;
  9674. }
  9675. public function isVeryVerbose()
  9676. {
  9677. return $this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE;
  9678. }
  9679. public function isDebug()
  9680. {
  9681. return $this->output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG;
  9682. }
  9683. public function write($messages, $newline = true)
  9684. {
  9685. $this->doWrite($messages, $newline, false);
  9686. }
  9687. public function writeError($messages, $newline = true)
  9688. {
  9689. $this->doWrite($messages, $newline, true);
  9690. }
  9691. private function doWrite($messages, $newline, $stderr)
  9692. {
  9693. if (null !== $this->startTime) {
  9694. $memoryUsage = memory_get_usage() / 1024 / 1024;
  9695. $timeSpent = microtime(true) - $this->startTime;
  9696. $messages = array_map(function ($message) use ($memoryUsage, $timeSpent) {
  9697. return sprintf('[%.1fMB/%.2fs] %s', $memoryUsage, $timeSpent, $message);
  9698. }, (array) $messages);
  9699. }
  9700. if (true === $stderr && $this->output instanceof ConsoleOutputInterface) {
  9701. $this->output->getErrorOutput()->write($messages, $newline);
  9702. $this->lastMessageErr = join($newline ? "\n" : '', (array) $messages);
  9703. return;
  9704. }
  9705. $this->output->write($messages, $newline);
  9706. $this->lastMessage = join($newline ? "\n" : '', (array) $messages);
  9707. }
  9708. public function overwrite($messages, $newline = true, $size = null)
  9709. {
  9710. $this->doOverwrite($messages, $newline, $size, false);
  9711. }
  9712. public function overwriteError($messages, $newline = true, $size = null)
  9713. {
  9714. $this->doOverwrite($messages, $newline, $size, true);
  9715. }
  9716. private function doOverwrite($messages, $newline, $size, $stderr)
  9717. {
  9718. $messages = join($newline ? "\n" : '', (array) $messages);
  9719. if (!isset($size)) {
  9720. $size = strlen(strip_tags($stderr ? $this->lastMessageErr : $this->lastMessage));
  9721. }
  9722. $this->doWrite(str_repeat("\x08", $size), false, $stderr);
  9723. $this->doWrite($messages, false, $stderr);
  9724. $fill = $size - strlen(strip_tags($messages));
  9725. if ($fill > 0) {
  9726. $this->doWrite(str_repeat(' ', $fill), false, $stderr);
  9727. $this->doWrite(str_repeat("\x08", $fill), false, $stderr);
  9728. }
  9729. if ($newline) {
  9730. $this->doWrite('', true, $stderr);
  9731. }
  9732. if ($stderr) {
  9733. $this->lastMessageErr = $messages;
  9734. } else {
  9735. $this->lastMessage = $messages;
  9736. }
  9737. }
  9738. public function ask($question, $default = null)
  9739. {
  9740. $output = $this->output;
  9741. if ($output instanceof ConsoleOutputInterface) {
  9742. $output = $output->getErrorOutput();
  9743. }
  9744. $helper = $this->helperSet->get('question');
  9745. $question = new Question($question, $default);
  9746. return $helper->ask($this->input, $output, $question);
  9747. }
  9748. public function askConfirmation($question, $default = true)
  9749. {
  9750. $output = $this->output;
  9751. if ($output instanceof ConsoleOutputInterface) {
  9752. $output = $output->getErrorOutput();
  9753. }
  9754. $helper = $this->helperSet->get('question');
  9755. $question = new ConfirmationQuestion($question, $default);
  9756. return $helper->ask($this->input, $output, $question);
  9757. }
  9758. public function askAndValidate($question, $validator, $attempts = null, $default = null)
  9759. {
  9760. $output = $this->output;
  9761. if ($output instanceof ConsoleOutputInterface) {
  9762. $output = $output->getErrorOutput();
  9763. }
  9764. $helper = $this->helperSet->get('question');
  9765. $question = new Question($question, $default);
  9766. $question->setValidator($validator);
  9767. $question->setMaxAttempts($attempts);
  9768. return $helper->ask($this->input, $output, $question);
  9769. }
  9770. public function askAndHideAnswer($question)
  9771. {
  9772. $this->writeError($question, false);
  9773. return \Seld\CliPrompt\CliPrompt::hiddenPrompt(true);
  9774. }
  9775. }
  9776. <?php
  9777. namespace Composer\IO;
  9778. use Composer\Config;
  9779. interface IOInterface
  9780. {
  9781. public function isInteractive();
  9782. public function isVerbose();
  9783. public function isVeryVerbose();
  9784. public function isDebug();
  9785. public function isDecorated();
  9786. public function write($messages, $newline = true);
  9787. public function writeError($messages, $newline = true);
  9788. public function overwrite($messages, $newline = true, $size = null);
  9789. public function overwriteError($messages, $newline = true, $size = null);
  9790. public function ask($question, $default = null);
  9791. public function askConfirmation($question, $default = true);
  9792. public function askAndValidate($question, $validator, $attempts = null, $default = null);
  9793. public function askAndHideAnswer($question);
  9794. public function getAuthentications();
  9795. public function hasAuthentication($repositoryName);
  9796. public function getAuthentication($repositoryName);
  9797. public function setAuthentication($repositoryName, $username, $password = null);
  9798. public function loadConfiguration(Config $config);
  9799. }
  9800. <?php
  9801. namespace Composer\IO;
  9802. class NullIO extends BaseIO
  9803. {
  9804. public function isInteractive()
  9805. {
  9806. return false;
  9807. }
  9808. public function isVerbose()
  9809. {
  9810. return false;
  9811. }
  9812. public function isVeryVerbose()
  9813. {
  9814. return false;
  9815. }
  9816. public function isDebug()
  9817. {
  9818. return false;
  9819. }
  9820. public function isDecorated()
  9821. {
  9822. return false;
  9823. }
  9824. public function write($messages, $newline = true)
  9825. {
  9826. }
  9827. public function writeError($messages, $newline = true)
  9828. {
  9829. }
  9830. public function overwrite($messages, $newline = true, $size = 80)
  9831. {
  9832. }
  9833. public function overwriteError($messages, $newline = true, $size = 80)
  9834. {
  9835. }
  9836. public function ask($question, $default = null)
  9837. {
  9838. return $default;
  9839. }
  9840. public function askConfirmation($question, $default = true)
  9841. {
  9842. return $default;
  9843. }
  9844. public function askAndValidate($question, $validator, $attempts = false, $default = null)
  9845. {
  9846. return $default;
  9847. }
  9848. public function askAndHideAnswer($question)
  9849. {
  9850. return null;
  9851. }
  9852. }
  9853. <?php
  9854. namespace Composer;
  9855. use Composer\Autoload\AutoloadGenerator;
  9856. use Composer\DependencyResolver\DefaultPolicy;
  9857. use Composer\DependencyResolver\Operation\UpdateOperation;
  9858. use Composer\DependencyResolver\Operation\InstallOperation;
  9859. use Composer\DependencyResolver\Operation\UninstallOperation;
  9860. use Composer\DependencyResolver\Operation\OperationInterface;
  9861. use Composer\DependencyResolver\PolicyInterface;
  9862. use Composer\DependencyResolver\Pool;
  9863. use Composer\DependencyResolver\Request;
  9864. use Composer\DependencyResolver\Rule;
  9865. use Composer\DependencyResolver\Solver;
  9866. use Composer\DependencyResolver\SolverProblemsException;
  9867. use Composer\Downloader\DownloadManager;
  9868. use Composer\EventDispatcher\EventDispatcher;
  9869. use Composer\Installer\InstallationManager;
  9870. use Composer\Installer\InstallerEvents;
  9871. use Composer\Installer\NoopInstaller;
  9872. use Composer\IO\IOInterface;
  9873. use Composer\Json\JsonFile;
  9874. use Composer\Package\AliasPackage;
  9875. use Composer\Package\CompletePackage;
  9876. use Composer\Package\Link;
  9877. use Composer\Semver\Constraint\Constraint;
  9878. use Composer\Package\Locker;
  9879. use Composer\Package\PackageInterface;
  9880. use Composer\Package\RootPackageInterface;
  9881. use Composer\Repository\CompositeRepository;
  9882. use Composer\Repository\InstalledArrayRepository;
  9883. use Composer\Repository\InstalledFilesystemRepository;
  9884. use Composer\Repository\PlatformRepository;
  9885. use Composer\Repository\RepositoryInterface;
  9886. use Composer\Repository\RepositoryManager;
  9887. use Composer\Repository\WritableRepositoryInterface;
  9888. use Composer\Script\ScriptEvents;
  9889. class Installer
  9890. {
  9891. protected $io;
  9892. protected $config;
  9893. protected $package;
  9894. protected $downloadManager;
  9895. protected $repositoryManager;
  9896. protected $locker;
  9897. protected $installationManager;
  9898. protected $eventDispatcher;
  9899. protected $autoloadGenerator;
  9900. protected $preferSource = false;
  9901. protected $preferDist = false;
  9902. protected $optimizeAutoloader = false;
  9903. protected $classMapAuthoritative = false;
  9904. protected $devMode = false;
  9905. protected $dryRun = false;
  9906. protected $verbose = false;
  9907. protected $update = false;
  9908. protected $dumpAutoloader = true;
  9909. protected $runScripts = true;
  9910. protected $ignorePlatformReqs = false;
  9911. protected $preferStable = false;
  9912. protected $preferLowest = false;
  9913. protected $updateWhitelist = null;
  9914. protected $whitelistDependencies = false;
  9915. protected $suggestedPackages;
  9916. protected $additionalInstalledRepository;
  9917. public function __construct(IOInterface $io, Config $config, RootPackageInterface $package, DownloadManager $downloadManager, RepositoryManager $repositoryManager, Locker $locker, InstallationManager $installationManager, EventDispatcher $eventDispatcher, AutoloadGenerator $autoloadGenerator)
  9918. {
  9919. $this->io = $io;
  9920. $this->config = $config;
  9921. $this->package = $package;
  9922. $this->downloadManager = $downloadManager;
  9923. $this->repositoryManager = $repositoryManager;
  9924. $this->locker = $locker;
  9925. $this->installationManager = $installationManager;
  9926. $this->eventDispatcher = $eventDispatcher;
  9927. $this->autoloadGenerator = $autoloadGenerator;
  9928. }
  9929. public function run()
  9930. {
  9931. gc_collect_cycles();
  9932. gc_disable();
  9933. if ($this->dryRun) {
  9934. $this->verbose = true;
  9935. $this->runScripts = false;
  9936. $this->installationManager->addInstaller(new NoopInstaller);
  9937. $this->mockLocalRepositories($this->repositoryManager);
  9938. }
  9939. $devRepo = new InstalledFilesystemRepository(new JsonFile($this->config->get('vendor-dir').'/composer/installed_dev.json'));
  9940. if ($devRepo->getPackages()) {
  9941. $this->io->writeError('<warning>BC Notice: Removing old dev packages to migrate to the new require-dev handling.</warning>');
  9942. foreach ($devRepo->getPackages() as $package) {
  9943. if ($this->installationManager->isPackageInstalled($devRepo, $package)) {
  9944. $this->installationManager->uninstall($devRepo, new UninstallOperation($package));
  9945. }
  9946. }
  9947. unlink($this->config->get('vendor-dir').'/composer/installed_dev.json');
  9948. }
  9949. unset($devRepo, $package);
  9950. if ($this->runScripts) {
  9951. $eventName = $this->update ? ScriptEvents::PRE_UPDATE_CMD : ScriptEvents::PRE_INSTALL_CMD;
  9952. $this->eventDispatcher->dispatchScript($eventName, $this->devMode);
  9953. }
  9954. $this->downloadManager->setPreferSource($this->preferSource);
  9955. $this->downloadManager->setPreferDist($this->preferDist);
  9956. $installedRootPackage = clone $this->package;
  9957. $installedRootPackage->setRequires(array());
  9958. $installedRootPackage->setDevRequires(array());
  9959. $localRepo = $this->repositoryManager->getLocalRepository();
  9960. if (!$this->update && $this->locker->isLocked()) {
  9961. $platformOverrides = $this->locker->getPlatformOverrides();
  9962. } else {
  9963. $platformOverrides = $this->config->get('platform') ?: array();
  9964. }
  9965. $platformRepo = new PlatformRepository(array(), $platformOverrides);
  9966. $repos = array(
  9967. $localRepo,
  9968. new InstalledArrayRepository(array($installedRootPackage)),
  9969. $platformRepo,
  9970. );
  9971. $installedRepo = new CompositeRepository($repos);
  9972. if ($this->additionalInstalledRepository) {
  9973. $installedRepo->addRepository($this->additionalInstalledRepository);
  9974. }
  9975. $aliases = $this->getRootAliases();
  9976. $this->aliasPlatformPackages($platformRepo, $aliases);
  9977. try {
  9978. $this->suggestedPackages = array();
  9979. $res = $this->doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $this->devMode);
  9980. if ($res !== 0) {
  9981. return $res;
  9982. }
  9983. } catch (\Exception $e) {
  9984. if (!$this->dryRun) {
  9985. $this->installationManager->notifyInstalls($this->io);
  9986. }
  9987. throw $e;
  9988. }
  9989. if (!$this->dryRun) {
  9990. $this->installationManager->notifyInstalls($this->io);
  9991. }
  9992. if ($this->devMode) {
  9993. foreach ($this->suggestedPackages as $suggestion) {
  9994. $target = $suggestion['target'];
  9995. foreach ($installedRepo->getPackages() as $package) {
  9996. if (in_array($target, $package->getNames())) {
  9997. continue 2;
  9998. }
  9999. }
  10000. $this->io->writeError($suggestion['source'].' suggests installing '.$suggestion['target'].' ('.$suggestion['reason'].')');
  10001. }
  10002. }
  10003. foreach ($localRepo->getPackages() as $package) {
  10004. if (!$package instanceof CompletePackage || !$package->isAbandoned()) {
  10005. continue;
  10006. }
  10007. $replacement = (is_string($package->getReplacementPackage()))
  10008. ? 'Use ' . $package->getReplacementPackage() . ' instead'
  10009. : 'No replacement was suggested';
  10010. $this->io->writeError(
  10011. sprintf(
  10012. "<warning>Package %s is abandoned, you should avoid using it. %s.</warning>",
  10013. $package->getPrettyName(),
  10014. $replacement
  10015. )
  10016. );
  10017. }
  10018. if (!$this->dryRun) {
  10019. if ($this->update || !$this->locker->isLocked()) {
  10020. $localRepo->reload();
  10021. $devPackages = ($this->devMode || !$this->package->getDevRequires()) ? array() : null;
  10022. if ($this->devMode && $this->package->getDevRequires()) {
  10023. $policy = $this->createPolicy();
  10024. $pool = $this->createPool(true);
  10025. $pool->addRepository($installedRepo, $aliases);
  10026. $request = $this->createRequest($this->package, $platformRepo);
  10027. $request->updateAll();
  10028. foreach ($this->package->getRequires() as $link) {
  10029. $request->install($link->getTarget(), $link->getConstraint());
  10030. }
  10031. $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request);
  10032. $solver = new Solver($policy, $pool, $installedRepo);
  10033. $ops = $solver->solve($request, $this->ignorePlatformReqs);
  10034. $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request, $ops);
  10035. foreach ($ops as $op) {
  10036. if ($op->getJobType() === 'uninstall') {
  10037. $devPackages[] = $op->getPackage();
  10038. }
  10039. }
  10040. }
  10041. $platformReqs = $this->extractPlatformRequirements($this->package->getRequires());
  10042. $platformDevReqs = $this->devMode ? $this->extractPlatformRequirements($this->package->getDevRequires()) : array();
  10043. $updatedLock = $this->locker->setLockData(
  10044. array_diff($localRepo->getCanonicalPackages(), (array) $devPackages),
  10045. $devPackages,
  10046. $platformReqs,
  10047. $platformDevReqs,
  10048. $aliases,
  10049. $this->package->getMinimumStability(),
  10050. $this->package->getStabilityFlags(),
  10051. $this->preferStable || $this->package->getPreferStable(),
  10052. $this->preferLowest,
  10053. $this->config->get('platform') ?: array()
  10054. );
  10055. if ($updatedLock) {
  10056. $this->io->writeError('<info>Writing lock file</info>');
  10057. }
  10058. }
  10059. if ($this->dumpAutoloader) {
  10060. if ($this->optimizeAutoloader) {
  10061. $this->io->writeError('<info>Generating optimized autoload files</info>');
  10062. } else {
  10063. $this->io->writeError('<info>Generating autoload files</info>');
  10064. }
  10065. $this->autoloadGenerator->setDevMode($this->devMode);
  10066. $this->autoloadGenerator->setClassMapAuthoritative($this->classMapAuthoritative);
  10067. $this->autoloadGenerator->dump($this->config, $localRepo, $this->package, $this->installationManager, 'composer', $this->optimizeAutoloader);
  10068. }
  10069. if ($this->runScripts) {
  10070. $eventName = $this->update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD;
  10071. $this->eventDispatcher->dispatchScript($eventName, $this->devMode);
  10072. }
  10073. $vendorDir = $this->config->get('vendor-dir');
  10074. if (is_dir($vendorDir)) {
  10075. @touch($vendorDir);
  10076. }
  10077. }
  10078. return 0;
  10079. }
  10080. protected function doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $withDevReqs)
  10081. {
  10082. $lockedRepository = null;
  10083. $repositories = null;
  10084. $installFromLock = !$this->update && $this->locker->isLocked();
  10085. if ($installFromLock || (!empty($this->updateWhitelist) && $this->locker->isLocked())) {
  10086. try {
  10087. $lockedRepository = $this->locker->getLockedRepository($withDevReqs);
  10088. } catch (\RuntimeException $e) {
  10089. if ($this->package->getDevRequires()) {
  10090. throw $e;
  10091. }
  10092. $lockedRepository = $this->locker->getLockedRepository();
  10093. }
  10094. }
  10095. $this->whitelistUpdateDependencies(
  10096. $localRepo,
  10097. $withDevReqs,
  10098. $this->package->getRequires(),
  10099. $this->package->getDevRequires()
  10100. );
  10101. $this->io->writeError('<info>Loading composer repositories with package information</info>');
  10102. $policy = $this->createPolicy();
  10103. $pool = $this->createPool($withDevReqs, $installFromLock ? $lockedRepository : null);
  10104. $pool->addRepository($installedRepo, $aliases);
  10105. if (!$installFromLock) {
  10106. $repositories = $this->repositoryManager->getRepositories();
  10107. foreach ($repositories as $repository) {
  10108. $pool->addRepository($repository, $aliases);
  10109. }
  10110. }
  10111. if ($lockedRepository) {
  10112. $pool->addRepository($lockedRepository, $aliases);
  10113. }
  10114. $request = $this->createRequest($this->package, $platformRepo);
  10115. if (!$installFromLock) {
  10116. $removedUnstablePackages = array();
  10117. foreach ($localRepo->getPackages() as $package) {
  10118. if (
  10119. !$pool->isPackageAcceptable($package->getNames(), $package->getStability())
  10120. && $this->installationManager->isPackageInstalled($localRepo, $package)
  10121. ) {
  10122. $removedUnstablePackages[$package->getName()] = true;
  10123. $request->remove($package->getName(), new Constraint('=', $package->getVersion()));
  10124. }
  10125. }
  10126. }
  10127. if ($this->update) {
  10128. $this->io->writeError('<info>Updating dependencies'.($withDevReqs ? ' (including require-dev)' : '').'</info>');
  10129. $request->updateAll();
  10130. if ($withDevReqs) {
  10131. $links = array_merge($this->package->getRequires(), $this->package->getDevRequires());
  10132. } else {
  10133. $links = $this->package->getRequires();
  10134. }
  10135. foreach ($links as $link) {
  10136. $request->install($link->getTarget(), $link->getConstraint());
  10137. }
  10138. if ($this->updateWhitelist) {
  10139. $currentPackages = $this->getCurrentPackages($withDevReqs, $installedRepo);
  10140. $candidates = array();
  10141. foreach ($links as $link) {
  10142. $candidates[$link->getTarget()] = true;
  10143. }
  10144. foreach ($localRepo->getPackages() as $package) {
  10145. $candidates[$package->getName()] = true;
  10146. }
  10147. foreach ($candidates as $candidate => $dummy) {
  10148. foreach ($currentPackages as $curPackage) {
  10149. if ($curPackage->getName() === $candidate) {
  10150. if (!$this->isUpdateable($curPackage) && !isset($removedUnstablePackages[$curPackage->getName()])) {
  10151. $constraint = new Constraint('=', $curPackage->getVersion());
  10152. $request->install($curPackage->getName(), $constraint);
  10153. }
  10154. break;
  10155. }
  10156. }
  10157. }
  10158. }
  10159. } elseif ($installFromLock) {
  10160. $this->io->writeError('<info>Installing dependencies'.($withDevReqs ? ' (including require-dev)' : '').' from lock file</info>');
  10161. if (!$this->locker->isFresh()) {
  10162. $this->io->writeError('<warning>Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.</warning>');
  10163. }
  10164. foreach ($lockedRepository->getPackages() as $package) {
  10165. $version = $package->getVersion();
  10166. if (isset($aliases[$package->getName()][$version])) {
  10167. $version = $aliases[$package->getName()][$version]['alias_normalized'];
  10168. }
  10169. $constraint = new Constraint('=', $version);
  10170. $constraint->setPrettyString($package->getPrettyVersion());
  10171. $request->install($package->getName(), $constraint);
  10172. }
  10173. foreach ($this->locker->getPlatformRequirements($withDevReqs) as $link) {
  10174. $request->install($link->getTarget(), $link->getConstraint());
  10175. }
  10176. } else {
  10177. $this->io->writeError('<info>Installing dependencies'.($withDevReqs ? ' (including require-dev)' : '').'</info>');
  10178. if ($withDevReqs) {
  10179. $links = array_merge($this->package->getRequires(), $this->package->getDevRequires());
  10180. } else {
  10181. $links = $this->package->getRequires();
  10182. }
  10183. foreach ($links as $link) {
  10184. $request->install($link->getTarget(), $link->getConstraint());
  10185. }
  10186. }
  10187. $this->processDevPackages($localRepo, $pool, $policy, $repositories, $installedRepo, $lockedRepository, $installFromLock, $withDevReqs, 'force-links');
  10188. $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $this->devMode, $policy, $pool, $installedRepo, $request);
  10189. $solver = new Solver($policy, $pool, $installedRepo);
  10190. try {
  10191. $operations = $solver->solve($request, $this->ignorePlatformReqs);
  10192. $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $this->devMode, $policy, $pool, $installedRepo, $request, $operations);
  10193. } catch (SolverProblemsException $e) {
  10194. $this->io->writeError('<error>Your requirements could not be resolved to an installable set of packages.</error>');
  10195. $this->io->writeError($e->getMessage());
  10196. return max(1, $e->getCode());
  10197. }
  10198. if ($this->io->isVerbose()) {
  10199. $this->io->writeError("Analyzed ".count($pool)." packages to resolve dependencies");
  10200. $this->io->writeError("Analyzed ".$solver->getRuleSetSize()." rules to resolve dependencies");
  10201. }
  10202. $operations = $this->processDevPackages($localRepo, $pool, $policy, $repositories, $installedRepo, $lockedRepository, $installFromLock, $withDevReqs, 'force-updates', $operations);
  10203. if (!$operations) {
  10204. $this->io->writeError('Nothing to install or update');
  10205. }
  10206. $operations = $this->movePluginsToFront($operations);
  10207. $operations = $this->moveUninstallsToFront($operations);
  10208. foreach ($operations as $operation) {
  10209. if ('install' === $operation->getJobType()) {
  10210. foreach ($operation->getPackage()->getSuggests() as $target => $reason) {
  10211. $this->suggestedPackages[] = array(
  10212. 'source' => $operation->getPackage()->getPrettyName(),
  10213. 'target' => $target,
  10214. 'reason' => $reason,
  10215. );
  10216. }
  10217. }
  10218. if (!$installFromLock) {
  10219. $package = null;
  10220. if ('update' === $operation->getJobType()) {
  10221. $package = $operation->getTargetPackage();
  10222. } elseif ('install' === $operation->getJobType()) {
  10223. $package = $operation->getPackage();
  10224. }
  10225. if ($package && $package->isDev()) {
  10226. $references = $this->package->getReferences();
  10227. if (isset($references[$package->getName()])) {
  10228. $package->setSourceReference($references[$package->getName()]);
  10229. $package->setDistReference($references[$package->getName()]);
  10230. }
  10231. }
  10232. if ('update' === $operation->getJobType()
  10233. && $operation->getTargetPackage()->isDev()
  10234. && $operation->getTargetPackage()->getVersion() === $operation->getInitialPackage()->getVersion()
  10235. && (!$operation->getTargetPackage()->getSourceReference() || $operation->getTargetPackage()->getSourceReference() === $operation->getInitialPackage()->getSourceReference())
  10236. && (!$operation->getTargetPackage()->getDistReference() || $operation->getTargetPackage()->getDistReference() === $operation->getInitialPackage()->getDistReference())
  10237. ) {
  10238. if ($this->io->isDebug()) {
  10239. $this->io->writeError(' - Skipping update of '. $operation->getTargetPackage()->getPrettyName().' to the same reference-locked version');
  10240. $this->io->writeError('');
  10241. }
  10242. continue;
  10243. }
  10244. }
  10245. $event = 'Composer\Installer\PackageEvents::PRE_PACKAGE_'.strtoupper($operation->getJobType());
  10246. if (defined($event) && $this->runScripts) {
  10247. $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation);
  10248. }
  10249. if ($this->dryRun && false === strpos($operation->getJobType(), 'Alias')) {
  10250. $this->io->writeError(' - ' . $operation);
  10251. $this->io->writeError('');
  10252. } elseif ($this->io->isDebug() && false !== strpos($operation->getJobType(), 'Alias')) {
  10253. $this->io->writeError(' - ' . $operation);
  10254. $this->io->writeError('');
  10255. }
  10256. $this->installationManager->execute($localRepo, $operation);
  10257. if ($this->verbose && $this->io->isVeryVerbose() && in_array($operation->getJobType(), array('install', 'update'))) {
  10258. $reason = $operation->getReason();
  10259. if ($reason instanceof Rule) {
  10260. switch ($reason->getReason()) {
  10261. case Rule::RULE_JOB_INSTALL:
  10262. $this->io->writeError(' REASON: Required by root: '.$reason->getPrettyString($pool));
  10263. $this->io->writeError('');
  10264. break;
  10265. case Rule::RULE_PACKAGE_REQUIRES:
  10266. $this->io->writeError(' REASON: '.$reason->getPrettyString($pool));
  10267. $this->io->writeError('');
  10268. break;
  10269. }
  10270. }
  10271. }
  10272. $event = 'Composer\Installer\PackageEvents::POST_PACKAGE_'.strtoupper($operation->getJobType());
  10273. if (defined($event) && $this->runScripts) {
  10274. $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation);
  10275. }
  10276. if (!$this->dryRun) {
  10277. $localRepo->write();
  10278. }
  10279. }
  10280. if (!$this->dryRun) {
  10281. $this->processPackageUrls($pool, $policy, $localRepo, $repositories);
  10282. $localRepo->write();
  10283. }
  10284. return 0;
  10285. }
  10286. private function movePluginsToFront(array $operations)
  10287. {
  10288. $installerOps = array();
  10289. foreach ($operations as $idx => $op) {
  10290. if ($op instanceof InstallOperation) {
  10291. $package = $op->getPackage();
  10292. } elseif ($op instanceof UpdateOperation) {
  10293. $package = $op->getTargetPackage();
  10294. } else {
  10295. continue;
  10296. }
  10297. if ($package->getType() === 'composer-plugin' || $package->getType() === 'composer-installer') {
  10298. $requires = array_keys($package->getRequires());
  10299. foreach ($requires as $index => $req) {
  10300. if ($req === 'composer-plugin-api' || preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $req)) {
  10301. unset($requires[$index]);
  10302. }
  10303. }
  10304. if (!count($requires)) {
  10305. $installerOps[] = $op;
  10306. unset($operations[$idx]);
  10307. }
  10308. }
  10309. }
  10310. return array_merge($installerOps, $operations);
  10311. }
  10312. private function moveUninstallsToFront(array $operations)
  10313. {
  10314. $uninstOps = array();
  10315. foreach ($operations as $idx => $op) {
  10316. if ($op instanceof UninstallOperation) {
  10317. $uninstOps[] = $op;
  10318. unset($operations[$idx]);
  10319. }
  10320. }
  10321. return array_merge($uninstOps, $operations);
  10322. }
  10323. private function createPool($withDevReqs, RepositoryInterface $lockedRepository = null)
  10324. {
  10325. if (!$this->update && $this->locker->isLocked()) {
  10326. $minimumStability = $this->locker->getMinimumStability();
  10327. $stabilityFlags = $this->locker->getStabilityFlags();
  10328. $requires = array();
  10329. foreach ($lockedRepository->getPackages() as $package) {
  10330. $constraint = new Constraint('=', $package->getVersion());
  10331. $constraint->setPrettyString($package->getPrettyVersion());
  10332. $requires[$package->getName()] = $constraint;
  10333. }
  10334. } else {
  10335. $minimumStability = $this->package->getMinimumStability();
  10336. $stabilityFlags = $this->package->getStabilityFlags();
  10337. $requires = $this->package->getRequires();
  10338. if ($withDevReqs) {
  10339. $requires = array_merge($requires, $this->package->getDevRequires());
  10340. }
  10341. }
  10342. $rootConstraints = array();
  10343. foreach ($requires as $req => $constraint) {
  10344. if ($this->ignorePlatformReqs && preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $req)) {
  10345. continue;
  10346. }
  10347. if ($constraint instanceof Link) {
  10348. $rootConstraints[$req] = $constraint->getConstraint();
  10349. } else {
  10350. $rootConstraints[$req] = $constraint;
  10351. }
  10352. }
  10353. return new Pool($minimumStability, $stabilityFlags, $rootConstraints);
  10354. }
  10355. private function createPolicy()
  10356. {
  10357. $preferStable = null;
  10358. $preferLowest = null;
  10359. if (!$this->update && $this->locker->isLocked()) {
  10360. $preferStable = $this->locker->getPreferStable();
  10361. $preferLowest = $this->locker->getPreferLowest();
  10362. }
  10363. if (null === $preferStable) {
  10364. $preferStable = $this->preferStable || $this->package->getPreferStable();
  10365. }
  10366. if (null === $preferLowest) {
  10367. $preferLowest = $this->preferLowest;
  10368. }
  10369. return new DefaultPolicy($preferStable, $preferLowest);
  10370. }
  10371. private function createRequest(RootPackageInterface $rootPackage, PlatformRepository $platformRepo)
  10372. {
  10373. $request = new Request();
  10374. $constraint = new Constraint('=', $rootPackage->getVersion());
  10375. $constraint->setPrettyString($rootPackage->getPrettyVersion());
  10376. $request->install($rootPackage->getName(), $constraint);
  10377. $fixedPackages = $platformRepo->getPackages();
  10378. if ($this->additionalInstalledRepository) {
  10379. $additionalFixedPackages = $this->additionalInstalledRepository->getPackages();
  10380. $fixedPackages = array_merge($fixedPackages, $additionalFixedPackages);
  10381. }
  10382. $provided = $rootPackage->getProvides();
  10383. foreach ($fixedPackages as $package) {
  10384. $constraint = new Constraint('=', $package->getVersion());
  10385. $constraint->setPrettyString($package->getPrettyVersion());
  10386. if ($package->getRepository() !== $platformRepo
  10387. || !isset($provided[$package->getName()])
  10388. || !$provided[$package->getName()]->getConstraint()->matches($constraint)
  10389. ) {
  10390. $request->fix($package->getName(), $constraint);
  10391. }
  10392. }
  10393. return $request;
  10394. }
  10395. private function processDevPackages($localRepo, $pool, $policy, $repositories, $installedRepo, $lockedRepository, $installFromLock, $withDevReqs, $task, array $operations = null)
  10396. {
  10397. if ($task === 'force-updates' && null === $operations) {
  10398. throw new \InvalidArgumentException('Missing operations argument');
  10399. }
  10400. if ($task === 'force-links') {
  10401. $operations = array();
  10402. }
  10403. if (!$installFromLock && $this->updateWhitelist) {
  10404. $currentPackages = $this->getCurrentPackages($withDevReqs, $installedRepo);
  10405. }
  10406. foreach ($localRepo->getCanonicalPackages() as $package) {
  10407. if (!$package->isDev()) {
  10408. continue;
  10409. }
  10410. foreach ($operations as $operation) {
  10411. if (('update' === $operation->getJobType() && $operation->getInitialPackage()->equals($package))
  10412. || ('uninstall' === $operation->getJobType() && $operation->getPackage()->equals($package))
  10413. ) {
  10414. continue 2;
  10415. }
  10416. }
  10417. if ($installFromLock) {
  10418. foreach ($lockedRepository->findPackages($package->getName()) as $lockedPackage) {
  10419. if ($lockedPackage->isDev() && $lockedPackage->getVersion() === $package->getVersion()) {
  10420. if ($task === 'force-links') {
  10421. $package->setRequires($lockedPackage->getRequires());
  10422. $package->setConflicts($lockedPackage->getConflicts());
  10423. $package->setProvides($lockedPackage->getProvides());
  10424. $package->setReplaces($lockedPackage->getReplaces());
  10425. } elseif ($task === 'force-updates') {
  10426. if (($lockedPackage->getSourceReference() && $lockedPackage->getSourceReference() !== $package->getSourceReference())
  10427. || ($lockedPackage->getDistReference() && $lockedPackage->getDistReference() !== $package->getDistReference())
  10428. ) {
  10429. $operations[] = new UpdateOperation($package, $lockedPackage);
  10430. }
  10431. }
  10432. break;
  10433. }
  10434. }
  10435. } else {
  10436. if ($this->update) {
  10437. if ($this->updateWhitelist && !$this->isUpdateable($package)) {
  10438. foreach ($currentPackages as $curPackage) {
  10439. if ($curPackage->isDev() && $curPackage->getName() === $package->getName() && $curPackage->getVersion() === $package->getVersion()) {
  10440. if ($task === 'force-links') {
  10441. $package->setRequires($curPackage->getRequires());
  10442. $package->setConflicts($curPackage->getConflicts());
  10443. $package->setProvides($curPackage->getProvides());
  10444. $package->setReplaces($curPackage->getReplaces());
  10445. } elseif ($task === 'force-updates') {
  10446. if (($curPackage->getSourceReference() && $curPackage->getSourceReference() !== $package->getSourceReference())
  10447. || ($curPackage->getDistReference() && $curPackage->getDistReference() !== $package->getDistReference())
  10448. ) {
  10449. $operations[] = new UpdateOperation($package, $curPackage);
  10450. }
  10451. }
  10452. break;
  10453. }
  10454. }
  10455. continue;
  10456. }
  10457. $matches = $pool->whatProvides($package->getName(), new Constraint('=', $package->getVersion()));
  10458. foreach ($matches as $index => $match) {
  10459. if (!in_array($match->getRepository(), $repositories, true)) {
  10460. unset($matches[$index]);
  10461. continue;
  10462. }
  10463. if ($match->getName() !== $package->getName()) {
  10464. unset($matches[$index]);
  10465. continue;
  10466. }
  10467. $matches[$index] = $match->getId();
  10468. }
  10469. if ($matches && $matches = $policy->selectPreferredPackages($pool, array(), $matches)) {
  10470. $newPackage = $pool->literalToPackage($matches[0]);
  10471. if ($task === 'force-links' && $newPackage) {
  10472. $package->setRequires($newPackage->getRequires());
  10473. $package->setConflicts($newPackage->getConflicts());
  10474. $package->setProvides($newPackage->getProvides());
  10475. $package->setReplaces($newPackage->getReplaces());
  10476. }
  10477. if ($task === 'force-updates' && $newPackage && (
  10478. (($newPackage->getSourceReference() && $newPackage->getSourceReference() !== $package->getSourceReference())
  10479. || ($newPackage->getDistReference() && $newPackage->getDistReference() !== $package->getDistReference())
  10480. )
  10481. )) {
  10482. $operations[] = new UpdateOperation($package, $newPackage);
  10483. }
  10484. }
  10485. }
  10486. if ($task === 'force-updates') {
  10487. $references = $this->package->getReferences();
  10488. if (isset($references[$package->getName()]) && $references[$package->getName()] !== $package->getSourceReference()) {
  10489. $operations[] = new UpdateOperation($package, clone $package);
  10490. }
  10491. }
  10492. }
  10493. }
  10494. return $operations;
  10495. }
  10496. private function getCurrentPackages($withDevReqs, $installedRepo)
  10497. {
  10498. if ($this->locker->isLocked()) {
  10499. try {
  10500. return $this->locker->getLockedRepository($withDevReqs)->getPackages();
  10501. } catch (\RuntimeException $e) {
  10502. return $this->locker->getLockedRepository()->getPackages();
  10503. }
  10504. }
  10505. return $installedRepo->getPackages();
  10506. }
  10507. private function getRootAliases()
  10508. {
  10509. if (!$this->update && $this->locker->isLocked()) {
  10510. $aliases = $this->locker->getAliases();
  10511. } else {
  10512. $aliases = $this->package->getAliases();
  10513. }
  10514. $normalizedAliases = array();
  10515. foreach ($aliases as $alias) {
  10516. $normalizedAliases[$alias['package']][$alias['version']] = array(
  10517. 'alias' => $alias['alias'],
  10518. 'alias_normalized' => $alias['alias_normalized'],
  10519. );
  10520. }
  10521. return $normalizedAliases;
  10522. }
  10523. private function processPackageUrls($pool, $policy, $localRepo, $repositories)
  10524. {
  10525. if (!$this->update) {
  10526. return;
  10527. }
  10528. foreach ($localRepo->getCanonicalPackages() as $package) {
  10529. $matches = $pool->whatProvides($package->getName(), new Constraint('=', $package->getVersion()));
  10530. foreach ($matches as $index => $match) {
  10531. if (!in_array($match->getRepository(), $repositories, true)) {
  10532. unset($matches[$index]);
  10533. continue;
  10534. }
  10535. if ($match->getName() !== $package->getName()) {
  10536. unset($matches[$index]);
  10537. continue;
  10538. }
  10539. $matches[$index] = $match->getId();
  10540. }
  10541. if ($matches && $matches = $policy->selectPreferredPackages($pool, array(), $matches)) {
  10542. $newPackage = $pool->literalToPackage($matches[0]);
  10543. $sourceUrl = $package->getSourceUrl();
  10544. $newSourceUrl = $newPackage->getSourceUrl();
  10545. if ($sourceUrl !== $newSourceUrl) {
  10546. $package->setSourceType($newPackage->getSourceType());
  10547. $package->setSourceUrl($newSourceUrl);
  10548. $package->setSourceReference($newPackage->getSourceReference());
  10549. }
  10550. if (preg_match('{^https?://(?:(?:www\.)?bitbucket\.org|(api\.)?github\.com)/}', $newPackage->getDistUrl())) {
  10551. $package->setDistUrl($newPackage->getDistUrl());
  10552. }
  10553. }
  10554. }
  10555. }
  10556. private function aliasPlatformPackages(PlatformRepository $platformRepo, $aliases)
  10557. {
  10558. foreach ($aliases as $package => $versions) {
  10559. foreach ($versions as $version => $alias) {
  10560. $packages = $platformRepo->findPackages($package, $version);
  10561. foreach ($packages as $package) {
  10562. $aliasPackage = new AliasPackage($package, $alias['alias_normalized'], $alias['alias']);
  10563. $aliasPackage->setRootPackageAlias(true);
  10564. $platformRepo->addPackage($aliasPackage);
  10565. }
  10566. }
  10567. }
  10568. }
  10569. private function isUpdateable(PackageInterface $package)
  10570. {
  10571. if (!$this->updateWhitelist) {
  10572. throw new \LogicException('isUpdateable should only be called when a whitelist is present');
  10573. }
  10574. foreach ($this->updateWhitelist as $whiteListedPattern => $void) {
  10575. $patternRegexp = $this->packageNameToRegexp($whiteListedPattern);
  10576. if (preg_match($patternRegexp, $package->getName())) {
  10577. return true;
  10578. }
  10579. }
  10580. return false;
  10581. }
  10582. private function packageNameToRegexp($whiteListedPattern)
  10583. {
  10584. $cleanedWhiteListedPattern = str_replace('\\*', '.*', preg_quote($whiteListedPattern));
  10585. return "{^" . $cleanedWhiteListedPattern . "$}i";
  10586. }
  10587. private function extractPlatformRequirements($links)
  10588. {
  10589. $platformReqs = array();
  10590. foreach ($links as $link) {
  10591. if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $link->getTarget())) {
  10592. $platformReqs[$link->getTarget()] = $link->getPrettyConstraint();
  10593. }
  10594. }
  10595. return $platformReqs;
  10596. }
  10597. private function whitelistUpdateDependencies($localRepo, $devMode, array $rootRequires, array $rootDevRequires)
  10598. {
  10599. if (!$this->updateWhitelist) {
  10600. return;
  10601. }
  10602. $requiredPackageNames = array();
  10603. foreach (array_merge($rootRequires, $rootDevRequires) as $require) {
  10604. $requiredPackageNames[] = $require->getTarget();
  10605. }
  10606. if ($devMode) {
  10607. $rootRequires = array_merge($rootRequires, $rootDevRequires);
  10608. }
  10609. $skipPackages = array();
  10610. foreach ($rootRequires as $require) {
  10611. $skipPackages[$require->getTarget()] = true;
  10612. }
  10613. $pool = new Pool;
  10614. $pool->addRepository($localRepo);
  10615. $seen = array();
  10616. $rootRequiredPackageNames = array_keys($rootRequires);
  10617. foreach ($this->updateWhitelist as $packageName => $void) {
  10618. $packageQueue = new \SplQueue;
  10619. $depPackages = $pool->whatProvides($packageName);
  10620. $nameMatchesRequiredPackage = in_array($packageName, $requiredPackageNames, true);
  10621. if (!$nameMatchesRequiredPackage) {
  10622. $whitelistPatternRegexp = $this->packageNameToRegexp($packageName);
  10623. foreach ($rootRequiredPackageNames as $rootRequiredPackageName) {
  10624. if (preg_match($whitelistPatternRegexp, $rootRequiredPackageName)) {
  10625. $nameMatchesRequiredPackage = true;
  10626. break;
  10627. }
  10628. }
  10629. }
  10630. if (count($depPackages) == 0 && !$nameMatchesRequiredPackage && !in_array($packageName, array('nothing', 'lock'))) {
  10631. $this->io->writeError('<warning>Package "' . $packageName . '" listed for update is not installed. Ignoring.</warning>');
  10632. }
  10633. foreach ($depPackages as $depPackage) {
  10634. $packageQueue->enqueue($depPackage);
  10635. }
  10636. while (!$packageQueue->isEmpty()) {
  10637. $package = $packageQueue->dequeue();
  10638. if (isset($seen[$package->getId()])) {
  10639. continue;
  10640. }
  10641. $seen[$package->getId()] = true;
  10642. $this->updateWhitelist[$package->getName()] = true;
  10643. if (!$this->whitelistDependencies) {
  10644. continue;
  10645. }
  10646. $requires = $package->getRequires();
  10647. foreach ($requires as $require) {
  10648. $requirePackages = $pool->whatProvides($require->getTarget());
  10649. foreach ($requirePackages as $requirePackage) {
  10650. if (isset($skipPackages[$requirePackage->getName()])) {
  10651. continue;
  10652. }
  10653. $packageQueue->enqueue($requirePackage);
  10654. }
  10655. }
  10656. }
  10657. }
  10658. }
  10659. private function mockLocalRepositories(RepositoryManager $rm)
  10660. {
  10661. $packages = array();
  10662. foreach ($rm->getLocalRepository()->getPackages() as $package) {
  10663. $packages[(string) $package] = clone $package;
  10664. }
  10665. foreach ($packages as $key => $package) {
  10666. if ($package instanceof AliasPackage) {
  10667. $alias = (string) $package->getAliasOf();
  10668. $packages[$key] = new AliasPackage($packages[$alias], $package->getVersion(), $package->getPrettyVersion());
  10669. }
  10670. }
  10671. $rm->setLocalRepository(
  10672. new InstalledArrayRepository($packages)
  10673. );
  10674. }
  10675. public static function create(IOInterface $io, Composer $composer)
  10676. {
  10677. return new static(
  10678. $io,
  10679. $composer->getConfig(),
  10680. $composer->getPackage(),
  10681. $composer->getDownloadManager(),
  10682. $composer->getRepositoryManager(),
  10683. $composer->getLocker(),
  10684. $composer->getInstallationManager(),
  10685. $composer->getEventDispatcher(),
  10686. $composer->getAutoloadGenerator()
  10687. );
  10688. }
  10689. public function setAdditionalInstalledRepository(RepositoryInterface $additionalInstalledRepository)
  10690. {
  10691. $this->additionalInstalledRepository = $additionalInstalledRepository;
  10692. return $this;
  10693. }
  10694. public function setDryRun($dryRun = true)
  10695. {
  10696. $this->dryRun = (boolean) $dryRun;
  10697. return $this;
  10698. }
  10699. public function isDryRun()
  10700. {
  10701. return $this->dryRun;
  10702. }
  10703. public function setPreferSource($preferSource = true)
  10704. {
  10705. $this->preferSource = (boolean) $preferSource;
  10706. return $this;
  10707. }
  10708. public function setPreferDist($preferDist = true)
  10709. {
  10710. $this->preferDist = (boolean) $preferDist;
  10711. return $this;
  10712. }
  10713. public function setOptimizeAutoloader($optimizeAutoloader = false)
  10714. {
  10715. $this->optimizeAutoloader = (boolean) $optimizeAutoloader;
  10716. if (!$this->optimizeAutoloader) {
  10717. $this->setClassMapAuthoritative(false);
  10718. }
  10719. return $this;
  10720. }
  10721. public function setClassMapAuthoritative($classMapAuthoritative = false)
  10722. {
  10723. $this->classMapAuthoritative = (boolean) $classMapAuthoritative;
  10724. if ($this->classMapAuthoritative) {
  10725. $this->setOptimizeAutoloader(true);
  10726. }
  10727. return $this;
  10728. }
  10729. public function setUpdate($update = true)
  10730. {
  10731. $this->update = (boolean) $update;
  10732. return $this;
  10733. }
  10734. public function setDevMode($devMode = true)
  10735. {
  10736. $this->devMode = (boolean) $devMode;
  10737. return $this;
  10738. }
  10739. public function setDumpAutoloader($dumpAutoloader = true)
  10740. {
  10741. $this->dumpAutoloader = (boolean) $dumpAutoloader;
  10742. return $this;
  10743. }
  10744. public function setRunScripts($runScripts = true)
  10745. {
  10746. $this->runScripts = (boolean) $runScripts;
  10747. return $this;
  10748. }
  10749. public function setConfig(Config $config)
  10750. {
  10751. $this->config = $config;
  10752. return $this;
  10753. }
  10754. public function setVerbose($verbose = true)
  10755. {
  10756. $this->verbose = (boolean) $verbose;
  10757. return $this;
  10758. }
  10759. public function isVerbose()
  10760. {
  10761. return $this->verbose;
  10762. }
  10763. public function setIgnorePlatformRequirements($ignorePlatformReqs = false)
  10764. {
  10765. $this->ignorePlatformReqs = (boolean) $ignorePlatformReqs;
  10766. return $this;
  10767. }
  10768. public function setUpdateWhitelist(array $packages)
  10769. {
  10770. $this->updateWhitelist = array_flip(array_map('strtolower', $packages));
  10771. return $this;
  10772. }
  10773. public function setWhitelistDependencies($updateDependencies = true)
  10774. {
  10775. $this->whitelistDependencies = (boolean) $updateDependencies;
  10776. return $this;
  10777. }
  10778. public function setPreferStable($preferStable = true)
  10779. {
  10780. $this->preferStable = (boolean) $preferStable;
  10781. return $this;
  10782. }
  10783. public function setPreferLowest($preferLowest = true)
  10784. {
  10785. $this->preferLowest = (boolean) $preferLowest;
  10786. return $this;
  10787. }
  10788. public function disablePlugins()
  10789. {
  10790. $this->installationManager->disablePlugins();
  10791. return $this;
  10792. }
  10793. }
  10794. <?php
  10795. namespace Composer\Installer;
  10796. use Composer\IO\IOInterface;
  10797. use Composer\Package\PackageInterface;
  10798. use Composer\Package\AliasPackage;
  10799. use Composer\Repository\RepositoryInterface;
  10800. use Composer\Repository\InstalledRepositoryInterface;
  10801. use Composer\DependencyResolver\Operation\OperationInterface;
  10802. use Composer\DependencyResolver\Operation\InstallOperation;
  10803. use Composer\DependencyResolver\Operation\UpdateOperation;
  10804. use Composer\DependencyResolver\Operation\UninstallOperation;
  10805. use Composer\DependencyResolver\Operation\MarkAliasInstalledOperation;
  10806. use Composer\DependencyResolver\Operation\MarkAliasUninstalledOperation;
  10807. use Composer\Util\StreamContextFactory;
  10808. class InstallationManager
  10809. {
  10810. private $installers = array();
  10811. private $cache = array();
  10812. private $notifiablePackages = array();
  10813. public function reset()
  10814. {
  10815. $this->notifiablePackages = array();
  10816. }
  10817. public function addInstaller(InstallerInterface $installer)
  10818. {
  10819. array_unshift($this->installers, $installer);
  10820. $this->cache = array();
  10821. }
  10822. public function removeInstaller(InstallerInterface $installer)
  10823. {
  10824. if (false !== ($key = array_search($installer, $this->installers, true))) {
  10825. array_splice($this->installers, $key, 1);
  10826. $this->cache = array();
  10827. }
  10828. }
  10829. public function disablePlugins()
  10830. {
  10831. foreach ($this->installers as $i => $installer) {
  10832. if (!$installer instanceof PluginInstaller) {
  10833. continue;
  10834. }
  10835. unset($this->installers[$i]);
  10836. }
  10837. }
  10838. public function getInstaller($type)
  10839. {
  10840. $type = strtolower($type);
  10841. if (isset($this->cache[$type])) {
  10842. return $this->cache[$type];
  10843. }
  10844. foreach ($this->installers as $installer) {
  10845. if ($installer->supports($type)) {
  10846. return $this->cache[$type] = $installer;
  10847. }
  10848. }
  10849. throw new \InvalidArgumentException('Unknown installer type: '.$type);
  10850. }
  10851. public function isPackageInstalled(InstalledRepositoryInterface $repo, PackageInterface $package)
  10852. {
  10853. if ($package instanceof AliasPackage) {
  10854. return $repo->hasPackage($package) && $this->isPackageInstalled($repo, $package->getAliasOf());
  10855. }
  10856. return $this->getInstaller($package->getType())->isInstalled($repo, $package);
  10857. }
  10858. public function execute(RepositoryInterface $repo, OperationInterface $operation)
  10859. {
  10860. $method = $operation->getJobType();
  10861. $this->$method($repo, $operation);
  10862. }
  10863. public function install(RepositoryInterface $repo, InstallOperation $operation)
  10864. {
  10865. $package = $operation->getPackage();
  10866. $installer = $this->getInstaller($package->getType());
  10867. $installer->install($repo, $package);
  10868. $this->markForNotification($package);
  10869. }
  10870. public function update(RepositoryInterface $repo, UpdateOperation $operation)
  10871. {
  10872. $initial = $operation->getInitialPackage();
  10873. $target = $operation->getTargetPackage();
  10874. $initialType = $initial->getType();
  10875. $targetType = $target->getType();
  10876. if ($initialType === $targetType) {
  10877. $installer = $this->getInstaller($initialType);
  10878. $installer->update($repo, $initial, $target);
  10879. $this->markForNotification($target);
  10880. } else {
  10881. $this->getInstaller($initialType)->uninstall($repo, $initial);
  10882. $this->getInstaller($targetType)->install($repo, $target);
  10883. }
  10884. }
  10885. public function uninstall(RepositoryInterface $repo, UninstallOperation $operation)
  10886. {
  10887. $package = $operation->getPackage();
  10888. $installer = $this->getInstaller($package->getType());
  10889. $installer->uninstall($repo, $package);
  10890. }
  10891. public function markAliasInstalled(RepositoryInterface $repo, MarkAliasInstalledOperation $operation)
  10892. {
  10893. $package = $operation->getPackage();
  10894. if (!$repo->hasPackage($package)) {
  10895. $repo->addPackage(clone $package);
  10896. }
  10897. }
  10898. public function markAliasUninstalled(RepositoryInterface $repo, MarkAliasUninstalledOperation $operation)
  10899. {
  10900. $package = $operation->getPackage();
  10901. $repo->removePackage($package);
  10902. }
  10903. public function getInstallPath(PackageInterface $package)
  10904. {
  10905. $installer = $this->getInstaller($package->getType());
  10906. return $installer->getInstallPath($package);
  10907. }
  10908. public function notifyInstalls(IOInterface $io)
  10909. {
  10910. foreach ($this->notifiablePackages as $repoUrl => $packages) {
  10911. $repositoryName = parse_url($repoUrl, PHP_URL_HOST);
  10912. if ($io->hasAuthentication($repositoryName)) {
  10913. $auth = $io->getAuthentication($repositoryName);
  10914. $authStr = base64_encode($auth['username'] . ':' . $auth['password']);
  10915. $authHeader = 'Authorization: Basic '.$authStr;
  10916. }
  10917. if (strpos($repoUrl, '%package%')) {
  10918. foreach ($packages as $package) {
  10919. $url = str_replace('%package%', $package->getPrettyName(), $repoUrl);
  10920. $params = array(
  10921. 'version' => $package->getPrettyVersion(),
  10922. 'version_normalized' => $package->getVersion(),
  10923. );
  10924. $opts = array('http' =>
  10925. array(
  10926. 'method' => 'POST',
  10927. 'header' => array('Content-type: application/x-www-form-urlencoded'),
  10928. 'content' => http_build_query($params, '', '&'),
  10929. 'timeout' => 3,
  10930. ),
  10931. );
  10932. if (isset($authHeader)) {
  10933. $opts['http']['header'][] = $authHeader;
  10934. }
  10935. $context = StreamContextFactory::getContext($url, $opts);
  10936. @file_get_contents($url, false, $context);
  10937. }
  10938. continue;
  10939. }
  10940. $postData = array('downloads' => array());
  10941. foreach ($packages as $package) {
  10942. $postData['downloads'][] = array(
  10943. 'name' => $package->getPrettyName(),
  10944. 'version' => $package->getVersion(),
  10945. );
  10946. }
  10947. $opts = array('http' =>
  10948. array(
  10949. 'method' => 'POST',
  10950. 'header' => array('Content-Type: application/json'),
  10951. 'content' => json_encode($postData),
  10952. 'timeout' => 6,
  10953. ),
  10954. );
  10955. if (isset($authHeader)) {
  10956. $opts['http']['header'][] = $authHeader;
  10957. }
  10958. $context = StreamContextFactory::getContext($repoUrl, $opts);
  10959. @file_get_contents($repoUrl, false, $context);
  10960. }
  10961. $this->reset();
  10962. }
  10963. private function markForNotification(PackageInterface $package)
  10964. {
  10965. if ($package->getNotificationUrl()) {
  10966. $this->notifiablePackages[$package->getNotificationUrl()][$package->getName()] = $package;
  10967. }
  10968. }
  10969. }
  10970. <?php
  10971. namespace Composer\Installer;
  10972. use Composer\Composer;
  10973. use Composer\DependencyResolver\PolicyInterface;
  10974. use Composer\DependencyResolver\Operation\OperationInterface;
  10975. use Composer\DependencyResolver\Pool;
  10976. use Composer\DependencyResolver\Request;
  10977. use Composer\EventDispatcher\Event;
  10978. use Composer\IO\IOInterface;
  10979. use Composer\Repository\CompositeRepository;
  10980. class InstallerEvent extends Event
  10981. {
  10982. private $composer;
  10983. private $io;
  10984. private $devMode;
  10985. private $policy;
  10986. private $pool;
  10987. private $installedRepo;
  10988. private $request;
  10989. private $operations;
  10990. public function __construct($eventName, Composer $composer, IOInterface $io, $devMode, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request, array $operations = array())
  10991. {
  10992. parent::__construct($eventName);
  10993. $this->composer = $composer;
  10994. $this->io = $io;
  10995. $this->devMode = $devMode;
  10996. $this->policy = $policy;
  10997. $this->pool = $pool;
  10998. $this->installedRepo = $installedRepo;
  10999. $this->request = $request;
  11000. $this->operations = $operations;
  11001. }
  11002. public function getComposer()
  11003. {
  11004. return $this->composer;
  11005. }
  11006. public function getIO()
  11007. {
  11008. return $this->io;
  11009. }
  11010. public function isDevMode()
  11011. {
  11012. return $this->devMode;
  11013. }
  11014. public function getPolicy()
  11015. {
  11016. return $this->policy;
  11017. }
  11018. public function getPool()
  11019. {
  11020. return $this->pool;
  11021. }
  11022. public function getInstalledRepo()
  11023. {
  11024. return $this->installedRepo;
  11025. }
  11026. public function getRequest()
  11027. {
  11028. return $this->request;
  11029. }
  11030. public function getOperations()
  11031. {
  11032. return $this->operations;
  11033. }
  11034. }
  11035. <?php
  11036. namespace Composer\Installer;
  11037. class InstallerEvents
  11038. {
  11039. const PRE_DEPENDENCIES_SOLVING = 'pre-dependencies-solving';
  11040. const POST_DEPENDENCIES_SOLVING = 'post-dependencies-solving';
  11041. }
  11042. <?php
  11043. namespace Composer\Installer;
  11044. use Composer\Package\PackageInterface;
  11045. use Composer\Repository\InstalledRepositoryInterface;
  11046. use InvalidArgumentException;
  11047. interface InstallerInterface
  11048. {
  11049. public function supports($packageType);
  11050. public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package);
  11051. public function install(InstalledRepositoryInterface $repo, PackageInterface $package);
  11052. public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target);
  11053. public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package);
  11054. public function getInstallPath(PackageInterface $package);
  11055. }
  11056. <?php
  11057. namespace Composer\Installer;
  11058. use Composer\Composer;
  11059. use Composer\IO\IOInterface;
  11060. use Composer\Repository\InstalledRepositoryInterface;
  11061. use Composer\Package\PackageInterface;
  11062. use Composer\Util\Filesystem;
  11063. use Composer\Util\ProcessExecutor;
  11064. class LibraryInstaller implements InstallerInterface
  11065. {
  11066. protected $composer;
  11067. protected $vendorDir;
  11068. protected $binDir;
  11069. protected $downloadManager;
  11070. protected $io;
  11071. protected $type;
  11072. protected $filesystem;
  11073. public function __construct(IOInterface $io, Composer $composer, $type = 'library', Filesystem $filesystem = null)
  11074. {
  11075. $this->composer = $composer;
  11076. $this->downloadManager = $composer->getDownloadManager();
  11077. $this->io = $io;
  11078. $this->type = $type;
  11079. $this->filesystem = $filesystem ?: new Filesystem();
  11080. $this->vendorDir = rtrim($composer->getConfig()->get('vendor-dir'), '/');
  11081. $this->binDir = rtrim($composer->getConfig()->get('bin-dir'), '/');
  11082. }
  11083. public function supports($packageType)
  11084. {
  11085. return $packageType === $this->type || null === $this->type;
  11086. }
  11087. public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package)
  11088. {
  11089. return $repo->hasPackage($package) && is_readable($this->getInstallPath($package));
  11090. }
  11091. public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
  11092. {
  11093. $this->initializeVendorDir();
  11094. $downloadPath = $this->getInstallPath($package);
  11095. if (!is_readable($downloadPath) && $repo->hasPackage($package)) {
  11096. $this->removeBinaries($package);
  11097. }
  11098. $this->installCode($package);
  11099. $this->installBinaries($package);
  11100. if (!$repo->hasPackage($package)) {
  11101. $repo->addPackage(clone $package);
  11102. }
  11103. }
  11104. public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
  11105. {
  11106. if (!$repo->hasPackage($initial)) {
  11107. throw new \InvalidArgumentException('Package is not installed: '.$initial);
  11108. }
  11109. $this->initializeVendorDir();
  11110. $this->removeBinaries($initial);
  11111. $this->updateCode($initial, $target);
  11112. $this->installBinaries($target);
  11113. $repo->removePackage($initial);
  11114. if (!$repo->hasPackage($target)) {
  11115. $repo->addPackage(clone $target);
  11116. }
  11117. }
  11118. public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
  11119. {
  11120. if (!$repo->hasPackage($package)) {
  11121. throw new \InvalidArgumentException('Package is not installed: '.$package);
  11122. }
  11123. $this->removeCode($package);
  11124. $this->removeBinaries($package);
  11125. $repo->removePackage($package);
  11126. $downloadPath = $this->getPackageBasePath($package);
  11127. if (strpos($package->getName(), '/')) {
  11128. $packageVendorDir = dirname($downloadPath);
  11129. if (is_dir($packageVendorDir) && $this->filesystem->isDirEmpty($packageVendorDir)) {
  11130. @rmdir($packageVendorDir);
  11131. }
  11132. }
  11133. }
  11134. public function getInstallPath(PackageInterface $package)
  11135. {
  11136. $targetDir = $package->getTargetDir();
  11137. return $this->getPackageBasePath($package) . ($targetDir ? '/'.$targetDir : '');
  11138. }
  11139. protected function getPackageBasePath(PackageInterface $package)
  11140. {
  11141. $this->initializeVendorDir();
  11142. return ($this->vendorDir ? $this->vendorDir.'/' : '') . $package->getPrettyName();
  11143. }
  11144. protected function installCode(PackageInterface $package)
  11145. {
  11146. $downloadPath = $this->getInstallPath($package);
  11147. $this->downloadManager->download($package, $downloadPath);
  11148. }
  11149. protected function updateCode(PackageInterface $initial, PackageInterface $target)
  11150. {
  11151. $initialDownloadPath = $this->getInstallPath($initial);
  11152. $targetDownloadPath = $this->getInstallPath($target);
  11153. if ($targetDownloadPath !== $initialDownloadPath) {
  11154. if (substr($initialDownloadPath, 0, strlen($targetDownloadPath)) === $targetDownloadPath
  11155. || substr($targetDownloadPath, 0, strlen($initialDownloadPath)) === $initialDownloadPath
  11156. ) {
  11157. $this->removeCode($initial);
  11158. $this->installCode($target);
  11159. return;
  11160. }
  11161. $this->filesystem->rename($initialDownloadPath, $targetDownloadPath);
  11162. }
  11163. $this->downloadManager->update($initial, $target, $targetDownloadPath);
  11164. }
  11165. protected function removeCode(PackageInterface $package)
  11166. {
  11167. $downloadPath = $this->getPackageBasePath($package);
  11168. $this->downloadManager->remove($package, $downloadPath);
  11169. }
  11170. protected function getBinaries(PackageInterface $package)
  11171. {
  11172. return $package->getBinaries();
  11173. }
  11174. protected function installBinaries(PackageInterface $package)
  11175. {
  11176. $binaries = $this->getBinaries($package);
  11177. if (!$binaries) {
  11178. return;
  11179. }
  11180. foreach ($binaries as $bin) {
  11181. $binPath = $this->getInstallPath($package).'/'.$bin;
  11182. if (!file_exists($binPath)) {
  11183. $this->io->writeError(' <warning>Skipped installation of bin '.$bin.' for package '.$package->getName().': file not found in package</warning>');
  11184. continue;
  11185. }
  11186. $binPath = realpath($binPath);
  11187. $this->initializeBinDir();
  11188. $link = $this->binDir.'/'.basename($bin);
  11189. if (file_exists($link)) {
  11190. if (is_link($link)) {
  11191. @chmod($link, 0777 & ~umask());
  11192. }
  11193. $this->io->writeError(' Skipped installation of bin '.$bin.' for package '.$package->getName().': name conflicts with an existing file');
  11194. continue;
  11195. }
  11196. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  11197. if ('.bat' !== substr($binPath, -4)) {
  11198. file_put_contents($link, $this->generateUnixyProxyCode($binPath, $link));
  11199. @chmod($link, 0777 & ~umask());
  11200. $link .= '.bat';
  11201. if (file_exists($link)) {
  11202. $this->io->writeError(' Skipped installation of bin '.$bin.'.bat proxy for package '.$package->getName().': a .bat proxy was already installed');
  11203. }
  11204. }
  11205. if (!file_exists($link)) {
  11206. file_put_contents($link, $this->generateWindowsProxyCode($binPath, $link));
  11207. }
  11208. } else {
  11209. $cwd = getcwd();
  11210. try {
  11211. $relativeBin = $this->filesystem->findShortestPath($link, $binPath);
  11212. chdir(dirname($link));
  11213. if (false === @symlink($relativeBin, $link)) {
  11214. throw new \ErrorException();
  11215. }
  11216. } catch (\ErrorException $e) {
  11217. file_put_contents($link, $this->generateUnixyProxyCode($binPath, $link));
  11218. }
  11219. chdir($cwd);
  11220. }
  11221. @chmod($link, 0777 & ~umask());
  11222. }
  11223. }
  11224. protected function removeBinaries(PackageInterface $package)
  11225. {
  11226. $binaries = $this->getBinaries($package);
  11227. if (!$binaries) {
  11228. return;
  11229. }
  11230. foreach ($binaries as $bin) {
  11231. $link = $this->binDir.'/'.basename($bin);
  11232. if (is_link($link) || file_exists($link)) {
  11233. $this->filesystem->unlink($link);
  11234. }
  11235. if (file_exists($link.'.bat')) {
  11236. $this->filesystem->unlink($link.'.bat');
  11237. }
  11238. }
  11239. if ((is_dir($this->binDir)) && ($this->filesystem->isDirEmpty($this->binDir))) {
  11240. @rmdir($this->binDir);
  11241. }
  11242. }
  11243. protected function initializeVendorDir()
  11244. {
  11245. $this->filesystem->ensureDirectoryExists($this->vendorDir);
  11246. $this->vendorDir = realpath($this->vendorDir);
  11247. }
  11248. protected function initializeBinDir()
  11249. {
  11250. $this->filesystem->ensureDirectoryExists($this->binDir);
  11251. $this->binDir = realpath($this->binDir);
  11252. }
  11253. protected function generateWindowsProxyCode($bin, $link)
  11254. {
  11255. $binPath = $this->filesystem->findShortestPath($link, $bin);
  11256. if ('.bat' === substr($bin, -4) || '.exe' === substr($bin, -4)) {
  11257. $caller = 'call';
  11258. } else {
  11259. $handle = fopen($bin, 'r');
  11260. $line = fgets($handle);
  11261. fclose($handle);
  11262. if (preg_match('{^#!/(?:usr/bin/env )?(?:[^/]+/)*(.+)$}m', $line, $match)) {
  11263. $caller = trim($match[1]);
  11264. } else {
  11265. $caller = 'php';
  11266. }
  11267. }
  11268. return "@ECHO OFF\r\n".
  11269. "SET BIN_TARGET=%~dp0/".trim(ProcessExecutor::escape($binPath), '"')."\r\n".
  11270. "{$caller} \"%BIN_TARGET%\" %*\r\n";
  11271. }
  11272. protected function generateUnixyProxyCode($bin, $link)
  11273. {
  11274. $binPath = $this->filesystem->findShortestPath($link, $bin);
  11275. return "#!/usr/bin/env sh\n".
  11276. 'SRC_DIR="`pwd`"'."\n".
  11277. 'cd "`dirname "$0"`"'."\n".
  11278. 'cd '.ProcessExecutor::escape(dirname($binPath))."\n".
  11279. 'BIN_TARGET="`pwd`/'.basename($binPath)."\"\n".
  11280. 'cd "$SRC_DIR"'."\n".
  11281. '"$BIN_TARGET" "$@"'."\n";
  11282. }
  11283. }
  11284. <?php
  11285. namespace Composer\Installer;
  11286. use Composer\Repository\InstalledRepositoryInterface;
  11287. use Composer\Package\PackageInterface;
  11288. class MetapackageInstaller implements InstallerInterface
  11289. {
  11290. public function supports($packageType)
  11291. {
  11292. return $packageType === 'metapackage';
  11293. }
  11294. public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package)
  11295. {
  11296. return $repo->hasPackage($package);
  11297. }
  11298. public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
  11299. {
  11300. $repo->addPackage(clone $package);
  11301. }
  11302. public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
  11303. {
  11304. if (!$repo->hasPackage($initial)) {
  11305. throw new \InvalidArgumentException('Package is not installed: '.$initial);
  11306. }
  11307. $repo->removePackage($initial);
  11308. $repo->addPackage(clone $target);
  11309. }
  11310. public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
  11311. {
  11312. if (!$repo->hasPackage($package)) {
  11313. throw new \InvalidArgumentException('Package is not installed: '.$package);
  11314. }
  11315. $repo->removePackage($package);
  11316. }
  11317. public function getInstallPath(PackageInterface $package)
  11318. {
  11319. return '';
  11320. }
  11321. }
  11322. <?php
  11323. namespace Composer\Installer;
  11324. use Composer\Repository\InstalledRepositoryInterface;
  11325. use Composer\Package\PackageInterface;
  11326. class NoopInstaller implements InstallerInterface
  11327. {
  11328. public function supports($packageType)
  11329. {
  11330. return true;
  11331. }
  11332. public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package)
  11333. {
  11334. return $repo->hasPackage($package);
  11335. }
  11336. public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
  11337. {
  11338. if (!$repo->hasPackage($package)) {
  11339. $repo->addPackage(clone $package);
  11340. }
  11341. }
  11342. public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
  11343. {
  11344. if (!$repo->hasPackage($initial)) {
  11345. throw new \InvalidArgumentException('Package is not installed: '.$initial);
  11346. }
  11347. $repo->removePackage($initial);
  11348. if (!$repo->hasPackage($target)) {
  11349. $repo->addPackage(clone $target);
  11350. }
  11351. }
  11352. public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
  11353. {
  11354. if (!$repo->hasPackage($package)) {
  11355. throw new \InvalidArgumentException('Package is not installed: '.$package);
  11356. }
  11357. $repo->removePackage($package);
  11358. }
  11359. public function getInstallPath(PackageInterface $package)
  11360. {
  11361. $targetDir = $package->getTargetDir();
  11362. return $package->getPrettyName() . ($targetDir ? '/'.$targetDir : '');
  11363. }
  11364. }
  11365. <?php
  11366. namespace Composer\Installer;
  11367. use Composer\Composer;
  11368. use Composer\IO\IOInterface;
  11369. use Composer\DependencyResolver\Operation\OperationInterface;
  11370. use Composer\DependencyResolver\PolicyInterface;
  11371. use Composer\DependencyResolver\Pool;
  11372. use Composer\DependencyResolver\Request;
  11373. use Composer\Repository\CompositeRepository;
  11374. class PackageEvent extends InstallerEvent
  11375. {
  11376. private $operation;
  11377. public function __construct($eventName, Composer $composer, IOInterface $io, $devMode, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request, array $operations, OperationInterface $operation)
  11378. {
  11379. parent::__construct($eventName, $composer, $io, $devMode, $policy, $pool, $installedRepo, $request, $operations);
  11380. $this->operation = $operation;
  11381. }
  11382. public function getOperation()
  11383. {
  11384. return $this->operation;
  11385. }
  11386. }
  11387. <?php
  11388. namespace Composer\Installer;
  11389. class PackageEvents
  11390. {
  11391. const PRE_PACKAGE_INSTALL = 'pre-package-install';
  11392. const POST_PACKAGE_INSTALL = 'post-package-install';
  11393. const PRE_PACKAGE_UPDATE = 'pre-package-update';
  11394. const POST_PACKAGE_UPDATE = 'post-package-update';
  11395. const PRE_PACKAGE_UNINSTALL = 'pre-package-uninstall';
  11396. const POST_PACKAGE_UNINSTALL = 'post-package-uninstall';
  11397. }
  11398. <?php
  11399. namespace Composer\Installer;
  11400. use Composer\IO\IOInterface;
  11401. use Composer\Composer;
  11402. use Composer\Downloader\PearPackageExtractor;
  11403. use Composer\Repository\InstalledRepositoryInterface;
  11404. use Composer\Package\PackageInterface;
  11405. use Composer\Util\ProcessExecutor;
  11406. class PearInstaller extends LibraryInstaller
  11407. {
  11408. public function __construct(IOInterface $io, Composer $composer, $type = 'pear-library')
  11409. {
  11410. parent::__construct($io, $composer, $type);
  11411. }
  11412. public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
  11413. {
  11414. $this->uninstall($repo, $initial);
  11415. $this->install($repo, $target);
  11416. }
  11417. protected function installCode(PackageInterface $package)
  11418. {
  11419. parent::installCode($package);
  11420. parent::initializeBinDir();
  11421. $isWindows = defined('PHP_WINDOWS_VERSION_BUILD');
  11422. $php_bin = $this->binDir . ($isWindows ? '/composer-php.bat' : '/composer-php');
  11423. if (!$isWindows) {
  11424. $php_bin = '/usr/bin/env ' . $php_bin;
  11425. }
  11426. $installPath = $this->getInstallPath($package);
  11427. $vars = array(
  11428. 'os' => $isWindows ? 'windows' : 'linux',
  11429. 'php_bin' => $php_bin,
  11430. 'pear_php' => $installPath,
  11431. 'php_dir' => $installPath,
  11432. 'bin_dir' => $installPath . '/bin',
  11433. 'data_dir' => $installPath . '/data',
  11434. 'version' => $package->getPrettyVersion(),
  11435. );
  11436. $packageArchive = $this->getInstallPath($package).'/'.pathinfo($package->getDistUrl(), PATHINFO_BASENAME);
  11437. $pearExtractor = new PearPackageExtractor($packageArchive);
  11438. $pearExtractor->extractTo($this->getInstallPath($package), array('php' => '/', 'script' => '/bin', 'data' => '/data'), $vars);
  11439. if ($this->io->isVerbose()) {
  11440. $this->io->writeError(' Cleaning up');
  11441. }
  11442. $this->filesystem->unlink($packageArchive);
  11443. }
  11444. protected function getBinaries(PackageInterface $package)
  11445. {
  11446. $binariesPath = $this->getInstallPath($package) . '/bin/';
  11447. $binaries = array();
  11448. if (file_exists($binariesPath)) {
  11449. foreach (new \FilesystemIterator($binariesPath, \FilesystemIterator::KEY_AS_FILENAME | \FilesystemIterator::CURRENT_AS_FILEINFO) as $fileName => $value) {
  11450. if (!$value->isDir()) {
  11451. $binaries[] = 'bin/'.$fileName;
  11452. }
  11453. }
  11454. }
  11455. return $binaries;
  11456. }
  11457. protected function initializeBinDir()
  11458. {
  11459. parent::initializeBinDir();
  11460. file_put_contents($this->binDir.'/composer-php', $this->generateUnixyPhpProxyCode());
  11461. @chmod($this->binDir.'/composer-php', 0777);
  11462. file_put_contents($this->binDir.'/composer-php.bat', $this->generateWindowsPhpProxyCode());
  11463. @chmod($this->binDir.'/composer-php.bat', 0777);
  11464. }
  11465. protected function generateWindowsProxyCode($bin, $link)
  11466. {
  11467. $binPath = $this->filesystem->findShortestPath($link, $bin);
  11468. if ('.bat' === substr($bin, -4)) {
  11469. $caller = 'call';
  11470. } else {
  11471. $handle = fopen($bin, 'r');
  11472. $line = fgets($handle);
  11473. fclose($handle);
  11474. if (preg_match('{^#!/(?:usr/bin/env )?(?:[^/]+/)*(.+)$}m', $line, $match)) {
  11475. $caller = trim($match[1]);
  11476. } else {
  11477. $caller = 'php';
  11478. }
  11479. if ($caller === 'php') {
  11480. return "@echo off\r\n".
  11481. "pushd .\r\n".
  11482. "cd %~dp0\r\n".
  11483. "set PHP_PROXY=%CD%\\composer-php.bat\r\n".
  11484. "cd ".ProcessExecutor::escape(dirname($binPath))."\r\n".
  11485. "set BIN_TARGET=%CD%\\".basename($binPath)."\r\n".
  11486. "popd\r\n".
  11487. "%PHP_PROXY% \"%BIN_TARGET%\" %*\r\n";
  11488. }
  11489. }
  11490. return "@echo off\r\n".
  11491. "pushd .\r\n".
  11492. "cd %~dp0\r\n".
  11493. "cd ".ProcessExecutor::escape(dirname($binPath))."\r\n".
  11494. "set BIN_TARGET=%CD%\\".basename($binPath)."\r\n".
  11495. "popd\r\n".
  11496. $caller." \"%BIN_TARGET%\" %*\r\n";
  11497. }
  11498. private function generateWindowsPhpProxyCode()
  11499. {
  11500. $binToVendor = $this->filesystem->findShortestPath($this->binDir, $this->vendorDir, true);
  11501. return
  11502. "@echo off\r\n" .
  11503. "setlocal enabledelayedexpansion\r\n" .
  11504. "set BIN_DIR=%~dp0\r\n" .
  11505. "set VENDOR_DIR=%BIN_DIR%\\".$binToVendor."\r\n" .
  11506. "set DIRS=.\r\n" .
  11507. "FOR /D %%V IN (%VENDOR_DIR%\\*) DO (\r\n" .
  11508. " FOR /D %%P IN (%%V\\*) DO (\r\n" .
  11509. " set DIRS=!DIRS!;%%~fP\r\n" .
  11510. " )\r\n" .
  11511. ")\r\n" .
  11512. "php.exe -d include_path=!DIRS! %*\r\n";
  11513. }
  11514. private function generateUnixyPhpProxyCode()
  11515. {
  11516. $binToVendor = $this->filesystem->findShortestPath($this->binDir, $this->vendorDir, true);
  11517. return
  11518. "#!/usr/bin/env sh\n".
  11519. "SRC_DIR=`pwd`\n".
  11520. "BIN_DIR=`dirname $0`\n".
  11521. "VENDOR_DIR=\$BIN_DIR/".escapeshellarg($binToVendor)."\n".
  11522. "DIRS=\"\"\n".
  11523. "for vendor in \$VENDOR_DIR/*; do\n".
  11524. " if [ -d \"\$vendor\" ]; then\n".
  11525. " for package in \$vendor/*; do\n".
  11526. " if [ -d \"\$package\" ]; then\n".
  11527. " DIRS=\"\${DIRS}:\${package}\"\n".
  11528. " fi\n".
  11529. " done\n".
  11530. " fi\n".
  11531. "done\n".
  11532. "php -d include_path=\".\$DIRS\" $@\n";
  11533. }
  11534. }
  11535. <?php
  11536. namespace Composer\Installer;
  11537. use Composer\Composer;
  11538. use Composer\IO\IOInterface;
  11539. use Composer\Repository\InstalledRepositoryInterface;
  11540. use Composer\Package\PackageInterface;
  11541. class PluginInstaller extends LibraryInstaller
  11542. {
  11543. private $installationManager;
  11544. public function __construct(IOInterface $io, Composer $composer, $type = 'library')
  11545. {
  11546. parent::__construct($io, $composer, 'composer-plugin');
  11547. $this->installationManager = $composer->getInstallationManager();
  11548. }
  11549. public function supports($packageType)
  11550. {
  11551. return $packageType === 'composer-plugin' || $packageType === 'composer-installer';
  11552. }
  11553. public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
  11554. {
  11555. $extra = $package->getExtra();
  11556. if (empty($extra['class'])) {
  11557. throw new \UnexpectedValueException('Error while installing '.$package->getPrettyName().', composer-plugin packages should have a class defined in their extra key to be usable.');
  11558. }
  11559. parent::install($repo, $package);
  11560. $this->composer->getPluginManager()->registerPackage($package, true);
  11561. }
  11562. public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
  11563. {
  11564. $extra = $target->getExtra();
  11565. if (empty($extra['class'])) {
  11566. throw new \UnexpectedValueException('Error while installing '.$target->getPrettyName().', composer-plugin packages should have a class defined in their extra key to be usable.');
  11567. }
  11568. parent::update($repo, $initial, $target);
  11569. $this->composer->getPluginManager()->registerPackage($target, true);
  11570. }
  11571. }
  11572. <?php
  11573. namespace Composer\Installer;
  11574. use Composer\Package\PackageInterface;
  11575. use Composer\Downloader\DownloadManager;
  11576. use Composer\Repository\InstalledRepositoryInterface;
  11577. use Composer\Util\Filesystem;
  11578. class ProjectInstaller implements InstallerInterface
  11579. {
  11580. private $installPath;
  11581. private $downloadManager;
  11582. private $filesystem;
  11583. public function __construct($installPath, DownloadManager $dm)
  11584. {
  11585. $this->installPath = rtrim(strtr($installPath, '\\', '/'), '/').'/';
  11586. $this->downloadManager = $dm;
  11587. $this->filesystem = new Filesystem;
  11588. }
  11589. public function supports($packageType)
  11590. {
  11591. return true;
  11592. }
  11593. public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package)
  11594. {
  11595. return false;
  11596. }
  11597. public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
  11598. {
  11599. $installPath = $this->installPath;
  11600. if (file_exists($installPath) && !$this->filesystem->isDirEmpty($installPath)) {
  11601. throw new \InvalidArgumentException("Project directory $installPath is not empty.");
  11602. }
  11603. if (!is_dir($installPath)) {
  11604. mkdir($installPath, 0777, true);
  11605. }
  11606. $this->downloadManager->download($package, $installPath);
  11607. }
  11608. public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
  11609. {
  11610. throw new \InvalidArgumentException("not supported");
  11611. }
  11612. public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
  11613. {
  11614. throw new \InvalidArgumentException("not supported");
  11615. }
  11616. public function getInstallPath(PackageInterface $package)
  11617. {
  11618. return $this->installPath;
  11619. }
  11620. }
  11621. <?php
  11622. namespace Composer\Json;
  11623. use JsonSchema\Validator;
  11624. use Seld\JsonLint\JsonParser;
  11625. use Seld\JsonLint\ParsingException;
  11626. use Composer\Util\RemoteFilesystem;
  11627. use Composer\Downloader\TransportException;
  11628. class JsonFile
  11629. {
  11630. const LAX_SCHEMA = 1;
  11631. const STRICT_SCHEMA = 2;
  11632. const JSON_UNESCAPED_SLASHES = 64;
  11633. const JSON_PRETTY_PRINT = 128;
  11634. const JSON_UNESCAPED_UNICODE = 256;
  11635. private $path;
  11636. private $rfs;
  11637. public function __construct($path, RemoteFilesystem $rfs = null)
  11638. {
  11639. $this->path = $path;
  11640. if (null === $rfs && preg_match('{^https?://}i', $path)) {
  11641. throw new \InvalidArgumentException('http urls require a RemoteFilesystem instance to be passed');
  11642. }
  11643. $this->rfs = $rfs;
  11644. }
  11645. public function getPath()
  11646. {
  11647. return $this->path;
  11648. }
  11649. public function exists()
  11650. {
  11651. return is_file($this->path);
  11652. }
  11653. public function read()
  11654. {
  11655. try {
  11656. if ($this->rfs) {
  11657. $json = $this->rfs->getContents($this->path, $this->path, false);
  11658. } else {
  11659. $json = file_get_contents($this->path);
  11660. }
  11661. } catch (TransportException $e) {
  11662. throw new \RuntimeException($e->getMessage(), 0, $e);
  11663. } catch (\Exception $e) {
  11664. throw new \RuntimeException('Could not read '.$this->path."\n\n".$e->getMessage());
  11665. }
  11666. return static::parseJson($json, $this->path);
  11667. }
  11668. public function write(array $hash, $options = 448)
  11669. {
  11670. $dir = dirname($this->path);
  11671. if (!is_dir($dir)) {
  11672. if (file_exists($dir)) {
  11673. throw new \UnexpectedValueException(
  11674. $dir.' exists and is not a directory.'
  11675. );
  11676. }
  11677. if (!@mkdir($dir, 0777, true)) {
  11678. throw new \UnexpectedValueException(
  11679. $dir.' does not exist and could not be created.'
  11680. );
  11681. }
  11682. }
  11683. $retries = 3;
  11684. while ($retries--) {
  11685. try {
  11686. file_put_contents($this->path, static::encode($hash, $options). ($options & self::JSON_PRETTY_PRINT ? "\n" : ''));
  11687. break;
  11688. } catch (\Exception $e) {
  11689. if ($retries) {
  11690. usleep(500000);
  11691. continue;
  11692. }
  11693. throw $e;
  11694. }
  11695. }
  11696. }
  11697. public function validateSchema($schema = self::STRICT_SCHEMA)
  11698. {
  11699. $content = file_get_contents($this->path);
  11700. $data = json_decode($content);
  11701. if (null === $data && 'null' !== $content) {
  11702. self::validateSyntax($content, $this->path);
  11703. }
  11704. $schemaFile = __DIR__ . '/../../../res/composer-schema.json';
  11705. $schemaData = json_decode(file_get_contents($schemaFile));
  11706. if ($schema === self::LAX_SCHEMA) {
  11707. $schemaData->additionalProperties = true;
  11708. $schemaData->required = array();
  11709. }
  11710. $validator = new Validator();
  11711. $validator->check($data, $schemaData);
  11712. if (!$validator->isValid()) {
  11713. $errors = array();
  11714. foreach ((array) $validator->getErrors() as $error) {
  11715. $errors[] = ($error['property'] ? $error['property'].' : ' : '').$error['message'];
  11716. }
  11717. throw new JsonValidationException('"'.$this->path.'" does not match the expected JSON schema', $errors);
  11718. }
  11719. return true;
  11720. }
  11721. public static function encode($data, $options = 448)
  11722. {
  11723. if (PHP_VERSION_ID >= 50400) {
  11724. $json = json_encode($data, $options);
  11725. if (false === $json) {
  11726. self::throwEncodeError(json_last_error());
  11727. }
  11728. if (PHP_VERSION_ID < 50428 || (PHP_VERSION_ID >= 50500 && PHP_VERSION_ID < 50512) || (defined('JSON_C_VERSION') && version_compare(phpversion('json'), '1.3.6', '<'))) {
  11729. $json = preg_replace('/\[\s+\]/', '[]', $json);
  11730. $json = preg_replace('/\{\s+\}/', '{}', $json);
  11731. }
  11732. return $json;
  11733. }
  11734. $json = json_encode($data);
  11735. if (false === $json) {
  11736. self::throwEncodeError(json_last_error());
  11737. }
  11738. $prettyPrint = (bool) ($options & self::JSON_PRETTY_PRINT);
  11739. $unescapeUnicode = (bool) ($options & self::JSON_UNESCAPED_UNICODE);
  11740. $unescapeSlashes = (bool) ($options & self::JSON_UNESCAPED_SLASHES);
  11741. if (!$prettyPrint && !$unescapeUnicode && !$unescapeSlashes) {
  11742. return $json;
  11743. }
  11744. $result = JsonFormatter::format($json, $unescapeUnicode, $unescapeSlashes);
  11745. return $result;
  11746. }
  11747. private static function throwEncodeError($code)
  11748. {
  11749. switch ($code) {
  11750. case JSON_ERROR_DEPTH:
  11751. $msg = 'Maximum stack depth exceeded';
  11752. break;
  11753. case JSON_ERROR_STATE_MISMATCH:
  11754. $msg = 'Underflow or the modes mismatch';
  11755. break;
  11756. case JSON_ERROR_CTRL_CHAR:
  11757. $msg = 'Unexpected control character found';
  11758. break;
  11759. case JSON_ERROR_UTF8:
  11760. $msg = 'Malformed UTF-8 characters, possibly incorrectly encoded';
  11761. break;
  11762. default:
  11763. $msg = 'Unknown error';
  11764. }
  11765. throw new \RuntimeException('JSON encoding failed: '.$msg);
  11766. }
  11767. public static function parseJson($json, $file = null)
  11768. {
  11769. if (null === $json) {
  11770. return;
  11771. }
  11772. $data = json_decode($json, true);
  11773. if (null === $data && JSON_ERROR_NONE !== json_last_error()) {
  11774. self::validateSyntax($json, $file);
  11775. }
  11776. return $data;
  11777. }
  11778. protected static function validateSyntax($json, $file = null)
  11779. {
  11780. $parser = new JsonParser();
  11781. $result = $parser->lint($json);
  11782. if (null === $result) {
  11783. if (defined('JSON_ERROR_UTF8') && JSON_ERROR_UTF8 === json_last_error()) {
  11784. throw new \UnexpectedValueException('"'.$file.'" is not UTF-8, could not parse as JSON');
  11785. }
  11786. return true;
  11787. }
  11788. throw new ParsingException('"'.$file.'" does not contain valid JSON'."\n".$result->getMessage(), $result->getDetails());
  11789. }
  11790. }
  11791. <?php
  11792. namespace Composer\Json;
  11793. class JsonFormatter
  11794. {
  11795. public static function format($json, $unescapeUnicode, $unescapeSlashes)
  11796. {
  11797. $result = '';
  11798. $pos = 0;
  11799. $strLen = strlen($json);
  11800. $indentStr = ' ';
  11801. $newLine = "\n";
  11802. $outOfQuotes = true;
  11803. $buffer = '';
  11804. $noescape = true;
  11805. for ($i = 0; $i < $strLen; $i++) {
  11806. $char = substr($json, $i, 1);
  11807. if ('"' === $char && $noescape) {
  11808. $outOfQuotes = !$outOfQuotes;
  11809. }
  11810. if (!$outOfQuotes) {
  11811. $buffer .= $char;
  11812. $noescape = '\\' === $char ? !$noescape : true;
  11813. continue;
  11814. } elseif ('' !== $buffer) {
  11815. if ($unescapeSlashes) {
  11816. $buffer = str_replace('\\/', '/', $buffer);
  11817. }
  11818. if ($unescapeUnicode && function_exists('mb_convert_encoding')) {
  11819. $buffer = preg_replace_callback('/(\\\\+)u([0-9a-f]{4})/i', function ($match) {
  11820. $l = strlen($match[1]);
  11821. if ($l % 2) {
  11822. return str_repeat('\\', $l - 1) . mb_convert_encoding(
  11823. pack('H*', $match[2]),
  11824. 'UTF-8',
  11825. 'UCS-2BE'
  11826. );
  11827. }
  11828. return $match[0];
  11829. }, $buffer);
  11830. }
  11831. $result .= $buffer.$char;
  11832. $buffer = '';
  11833. continue;
  11834. }
  11835. if (':' === $char) {
  11836. $char .= ' ';
  11837. } elseif (('}' === $char || ']' === $char)) {
  11838. $pos--;
  11839. $prevChar = substr($json, $i - 1, 1);
  11840. if ('{' !== $prevChar && '[' !== $prevChar) {
  11841. $result .= $newLine;
  11842. for ($j = 0; $j < $pos; $j++) {
  11843. $result .= $indentStr;
  11844. }
  11845. } else {
  11846. $result = rtrim($result);
  11847. }
  11848. }
  11849. $result .= $char;
  11850. if (',' === $char || '{' === $char || '[' === $char) {
  11851. $result .= $newLine;
  11852. if ('{' === $char || '[' === $char) {
  11853. $pos++;
  11854. }
  11855. for ($j = 0; $j < $pos; $j++) {
  11856. $result .= $indentStr;
  11857. }
  11858. }
  11859. }
  11860. return $result;
  11861. }
  11862. }
  11863. <?php
  11864. namespace Composer\Json;
  11865. use Composer\Repository\PlatformRepository;
  11866. class JsonManipulator
  11867. {
  11868. private static $RECURSE_BLOCKS;
  11869. private static $RECURSE_ARRAYS;
  11870. private static $JSON_VALUE;
  11871. private static $JSON_STRING;
  11872. private $contents;
  11873. private $newline;
  11874. private $indent;
  11875. public function __construct($contents)
  11876. {
  11877. if (!self::$RECURSE_BLOCKS) {
  11878. self::$RECURSE_BLOCKS = '(?:[^{}]*|\{(?:[^{}]*|\{(?:[^{}]*|\{(?:[^{}]*|\{[^{}]*\})*\})*\})*\})*';
  11879. self::$RECURSE_ARRAYS = '(?:[^\]]*|\[(?:[^\]]*|\[(?:[^\]]*|\[(?:[^\]]*|\[[^\]]*\])*\])*\])*\]|'.self::$RECURSE_BLOCKS.')*';
  11880. self::$JSON_STRING = '"(?:[^\0-\x09\x0a-\x1f\\\\"]+|\\\\["bfnrt/\\\\]|\\\\u[a-fA-F0-9]{4})*"';
  11881. self::$JSON_VALUE = '(?:[0-9.]+|null|true|false|'.self::$JSON_STRING.'|\['.self::$RECURSE_ARRAYS.'\]|\{'.self::$RECURSE_BLOCKS.'\})';
  11882. }
  11883. $contents = trim($contents);
  11884. if ($contents === '') {
  11885. $contents = '{}';
  11886. }
  11887. if (!$this->pregMatch('#^\{(.*)\}$#s', $contents)) {
  11888. throw new \InvalidArgumentException('The json file must be an object ({})');
  11889. }
  11890. $this->newline = false !== strpos($contents, "\r\n") ? "\r\n" : "\n";
  11891. $this->contents = $contents === '{}' ? '{' . $this->newline . '}' : $contents;
  11892. $this->detectIndenting();
  11893. }
  11894. public function getContents()
  11895. {
  11896. return $this->contents . $this->newline;
  11897. }
  11898. public function addLink($type, $package, $constraint, $sortPackages = false)
  11899. {
  11900. $decoded = JsonFile::parseJson($this->contents);
  11901. if (!isset($decoded[$type])) {
  11902. return $this->addMainKey($type, array($package => $constraint));
  11903. }
  11904. $regex = '{^(\s*\{\s*(?:'.self::$JSON_STRING.'\s*:\s*'.self::$JSON_VALUE.'\s*,\s*)*?)'.
  11905. '('.preg_quote(JsonFile::encode($type)).'\s*:\s*)('.self::$JSON_VALUE.')(.*)}s';
  11906. if (!$this->pregMatch($regex, $this->contents, $matches)) {
  11907. return false;
  11908. }
  11909. $links = $matches[3];
  11910. if (isset($decoded[$type][$package])) {
  11911. $packageRegex = str_replace('/', '\\\\?/', preg_quote($package));
  11912. $links = preg_replace('{"'.$packageRegex.'"(\s*:\s*)'.self::$JSON_STRING.'}i', addcslashes(JsonFile::encode($package).'${1}"'.$constraint.'"', '\\'), $links);
  11913. } else {
  11914. if ($this->pregMatch('#^\s*\{\s*\S+.*?(\s*\}\s*)$#s', $links, $match)) {
  11915. $links = preg_replace(
  11916. '{'.preg_quote($match[1]).'$}',
  11917. addcslashes(',' . $this->newline . $this->indent . $this->indent . JsonFile::encode($package).': '.JsonFile::encode($constraint) . $match[1], '\\'),
  11918. $links
  11919. );
  11920. } else {
  11921. $links = '{' . $this->newline .
  11922. $this->indent . $this->indent . JsonFile::encode($package).': '.JsonFile::encode($constraint) . $this->newline .
  11923. $this->indent . '}';
  11924. }
  11925. }
  11926. if (true === $sortPackages) {
  11927. $requirements = json_decode($links, true);
  11928. $this->sortPackages($requirements);
  11929. $links = $this->format($requirements);
  11930. }
  11931. $this->contents = $matches[1] . $matches[2] . $links . $matches[4];
  11932. return true;
  11933. }
  11934. private function sortPackages(array &$packages = array())
  11935. {
  11936. $prefix = function ($requirement) {
  11937. if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $requirement)) {
  11938. return preg_replace(
  11939. array(
  11940. '/^php/',
  11941. '/^hhvm/',
  11942. '/^ext/',
  11943. '/^lib/',
  11944. '/^\D/',
  11945. ),
  11946. array(
  11947. '0-$0',
  11948. '1-$0',
  11949. '2-$0',
  11950. '3-$0',
  11951. '4-$0',
  11952. ),
  11953. $requirement
  11954. );
  11955. }
  11956. return '5-'.$requirement;
  11957. };
  11958. uksort($packages, function ($a, $b) use ($prefix) {
  11959. return strnatcmp($prefix($a), $prefix($b));
  11960. });
  11961. }
  11962. public function addRepository($name, $config)
  11963. {
  11964. return $this->addSubNode('repositories', $name, $config);
  11965. }
  11966. public function removeRepository($name)
  11967. {
  11968. return $this->removeSubNode('repositories', $name);
  11969. }
  11970. public function addConfigSetting($name, $value)
  11971. {
  11972. return $this->addSubNode('config', $name, $value);
  11973. }
  11974. public function removeConfigSetting($name)
  11975. {
  11976. return $this->removeSubNode('config', $name);
  11977. }
  11978. public function addSubNode($mainNode, $name, $value)
  11979. {
  11980. $decoded = JsonFile::parseJson($this->contents);
  11981. $subName = null;
  11982. if (in_array($mainNode, array('config', 'repositories')) && false !== strpos($name, '.')) {
  11983. list($name, $subName) = explode('.', $name, 2);
  11984. }
  11985. if (!isset($decoded[$mainNode])) {
  11986. if ($subName !== null) {
  11987. $this->addMainKey($mainNode, array($name => array($subName => $value)));
  11988. } else {
  11989. $this->addMainKey($mainNode, array($name => $value));
  11990. }
  11991. return true;
  11992. }
  11993. $nodeRegex = '{^(\s*\{\s*(?:'.self::$JSON_STRING.'\s*:\s*'.self::$JSON_VALUE.'\s*,\s*)*?)'.
  11994. '('.preg_quote(JsonFile::encode($mainNode)).'\s*:\s*\{)('.self::$RECURSE_BLOCKS.')(\})(.*)}s';
  11995. try {
  11996. if (!$this->pregMatch($nodeRegex, $this->contents, $match)) {
  11997. return false;
  11998. }
  11999. } catch (\RuntimeException $e) {
  12000. if ($e->getCode() === PREG_BACKTRACK_LIMIT_ERROR) {
  12001. return false;
  12002. }
  12003. throw $e;
  12004. }
  12005. $children = $match[3];
  12006. if (!@json_decode('{'.$children.'}')) {
  12007. return false;
  12008. }
  12009. $that = $this;
  12010. if ($this->pregMatch('{("'.preg_quote($name).'"\s*:\s*)('.self::$JSON_VALUE.')(,?)}', $children, $matches)) {
  12011. $children = preg_replace_callback('{("'.preg_quote($name).'"\s*:\s*)('.self::$JSON_VALUE.')(,?)}', function ($matches) use ($name, $subName, $value, $that) {
  12012. if ($subName !== null) {
  12013. $curVal = json_decode($matches[2], true);
  12014. $curVal[$subName] = $value;
  12015. $value = $curVal;
  12016. }
  12017. return $matches[1] . $that->format($value, 1) . $matches[3];
  12018. }, $children);
  12019. } elseif ($this->pregMatch('#[^\s](\s*)$#', $children, $match)) {
  12020. if ($subName !== null) {
  12021. $value = array($subName => $value);
  12022. }
  12023. $children = preg_replace(
  12024. '#'.$match[1].'$#',
  12025. addcslashes(',' . $this->newline . $this->indent . $this->indent . JsonFile::encode($name).': '.$this->format($value, 1) . $match[1], '\\'),
  12026. $children
  12027. );
  12028. } else {
  12029. if ($subName !== null) {
  12030. $value = array($subName => $value);
  12031. }
  12032. $children = $this->newline . $this->indent . $this->indent . JsonFile::encode($name).': '.$this->format($value, 1) . $children;
  12033. }
  12034. $this->contents = preg_replace($nodeRegex, addcslashes('${1}${2}'.$children.'${4}${5}', '\\'), $this->contents);
  12035. return true;
  12036. }
  12037. public function removeSubNode($mainNode, $name)
  12038. {
  12039. $decoded = JsonFile::parseJson($this->contents);
  12040. if (empty($decoded[$mainNode])) {
  12041. return true;
  12042. }
  12043. $nodeRegex = '{^(\s*\{\s*(?:'.self::$JSON_STRING.'\s*:\s*'.self::$JSON_VALUE.'\s*,\s*)*?)'.
  12044. '('.preg_quote(JsonFile::encode($mainNode)).'\s*:\s*\{)('.self::$RECURSE_BLOCKS.')(\})(.*)}s';
  12045. try {
  12046. if (!$this->pregMatch($nodeRegex, $this->contents, $match)) {
  12047. return false;
  12048. }
  12049. } catch (\RuntimeException $e) {
  12050. if ($e->getCode() === PREG_BACKTRACK_LIMIT_ERROR) {
  12051. return false;
  12052. }
  12053. throw $e;
  12054. }
  12055. $children = $match[3];
  12056. if (!@json_decode('{'.$children.'}', true)) {
  12057. return false;
  12058. }
  12059. $subName = null;
  12060. if (in_array($mainNode, array('config', 'repositories')) && false !== strpos($name, '.')) {
  12061. list($name, $subName) = explode('.', $name, 2);
  12062. }
  12063. if (!isset($decoded[$mainNode][$name]) || ($subName && !isset($decoded[$mainNode][$name][$subName]))) {
  12064. return true;
  12065. }
  12066. if ($this->pregMatch('{"'.preg_quote($name).'"\s*:}i', $children)) {
  12067. if (preg_match_all('{"'.preg_quote($name).'"\s*:\s*(?:'.self::$JSON_VALUE.')}', $children, $matches)) {
  12068. $bestMatch = '';
  12069. foreach ($matches[0] as $match) {
  12070. if (strlen($bestMatch) < strlen($match)) {
  12071. $bestMatch = $match;
  12072. }
  12073. }
  12074. $childrenClean = preg_replace('{,\s*'.preg_quote($bestMatch).'}i', '', $children, -1, $count);
  12075. if (1 !== $count) {
  12076. $childrenClean = preg_replace('{'.preg_quote($bestMatch).'\s*,?\s*}i', '', $childrenClean, -1, $count);
  12077. if (1 !== $count) {
  12078. return false;
  12079. }
  12080. }
  12081. }
  12082. } else {
  12083. $childrenClean = $children;
  12084. }
  12085. if (!trim($childrenClean)) {
  12086. $this->contents = preg_replace($nodeRegex, '$1$2'.$this->newline.$this->indent.'$4$5', $this->contents);
  12087. if ($subName !== null) {
  12088. $curVal = json_decode('{'.$children.'}', true);
  12089. unset($curVal[$name][$subName]);
  12090. $this->addSubNode($mainNode, $name, $curVal[$name]);
  12091. }
  12092. return true;
  12093. }
  12094. $that = $this;
  12095. $this->contents = preg_replace_callback($nodeRegex, function ($matches) use ($that, $name, $subName, $childrenClean) {
  12096. if ($subName !== null) {
  12097. $curVal = json_decode('{'.$matches[3].'}', true);
  12098. unset($curVal[$name][$subName]);
  12099. $childrenClean = substr($that->format($curVal, 0), 1, -1);
  12100. }
  12101. return $matches[1] . $matches[2] . $childrenClean . $matches[4] . $matches[5];
  12102. }, $this->contents);
  12103. return true;
  12104. }
  12105. public function addMainKey($key, $content)
  12106. {
  12107. $decoded = JsonFile::parseJson($this->contents);
  12108. $content = $this->format($content);
  12109. $regex = '{^(\s*\{\s*(?:'.self::$JSON_STRING.'\s*:\s*'.self::$JSON_VALUE.'\s*,\s*)*?)'.
  12110. '('.preg_quote(JsonFile::encode($key)).'\s*:\s*'.self::$JSON_VALUE.')(.*)}s';
  12111. if (isset($decoded[$key]) && $this->pregMatch($regex, $this->contents, $matches)) {
  12112. if (!@json_decode('{'.$matches[2].'}')) {
  12113. return false;
  12114. }
  12115. $this->contents = $matches[1] . JsonFile::encode($key).': '.$content . $matches[3];
  12116. return true;
  12117. }
  12118. if ($this->pregMatch('#[^{\s](\s*)\}$#', $this->contents, $match)) {
  12119. $this->contents = preg_replace(
  12120. '#'.$match[1].'\}$#',
  12121. addcslashes(',' . $this->newline . $this->indent . JsonFile::encode($key). ': '. $content . $this->newline . '}', '\\'),
  12122. $this->contents
  12123. );
  12124. return true;
  12125. }
  12126. $this->contents = preg_replace(
  12127. '#\}$#',
  12128. addcslashes($this->indent . JsonFile::encode($key). ': '.$content . $this->newline . '}', '\\'),
  12129. $this->contents
  12130. );
  12131. return true;
  12132. }
  12133. public function format($data, $depth = 0)
  12134. {
  12135. if (is_array($data)) {
  12136. reset($data);
  12137. if (is_numeric(key($data))) {
  12138. foreach ($data as $key => $val) {
  12139. $data[$key] = $this->format($val, $depth + 1);
  12140. }
  12141. return '['.implode(', ', $data).']';
  12142. }
  12143. $out = '{' . $this->newline;
  12144. $elems = array();
  12145. foreach ($data as $key => $val) {
  12146. $elems[] = str_repeat($this->indent, $depth + 2) . JsonFile::encode($key). ': '.$this->format($val, $depth + 1);
  12147. }
  12148. return $out . implode(','.$this->newline, $elems) . $this->newline . str_repeat($this->indent, $depth + 1) . '}';
  12149. }
  12150. return JsonFile::encode($data);
  12151. }
  12152. protected function detectIndenting()
  12153. {
  12154. if ($this->pregMatch('{^([ \t]+)"}m', $this->contents, $match)) {
  12155. $this->indent = $match[1];
  12156. } else {
  12157. $this->indent = ' ';
  12158. }
  12159. }
  12160. protected function pregMatch($re, $str, &$matches = array())
  12161. {
  12162. $count = preg_match($re, $str, $matches);
  12163. if ($count === false) {
  12164. switch (preg_last_error()) {
  12165. case PREG_NO_ERROR:
  12166. throw new \RuntimeException('Failed to execute regex: PREG_NO_ERROR', PREG_NO_ERROR);
  12167. case PREG_INTERNAL_ERROR:
  12168. throw new \RuntimeException('Failed to execute regex: PREG_INTERNAL_ERROR', PREG_INTERNAL_ERROR);
  12169. case PREG_BACKTRACK_LIMIT_ERROR:
  12170. throw new \RuntimeException('Failed to execute regex: PREG_BACKTRACK_LIMIT_ERROR', PREG_BACKTRACK_LIMIT_ERROR);
  12171. case PREG_RECURSION_LIMIT_ERROR:
  12172. throw new \RuntimeException('Failed to execute regex: PREG_RECURSION_LIMIT_ERROR', PREG_RECURSION_LIMIT_ERROR);
  12173. case PREG_BAD_UTF8_ERROR:
  12174. throw new \RuntimeException('Failed to execute regex: PREG_BAD_UTF8_ERROR', PREG_BAD_UTF8_ERROR);
  12175. case PREG_BAD_UTF8_OFFSET_ERROR:
  12176. throw new \RuntimeException('Failed to execute regex: PREG_BAD_UTF8_OFFSET_ERROR', PREG_BAD_UTF8_OFFSET_ERROR);
  12177. default:
  12178. throw new \RuntimeException('Failed to execute regex: Unknown error');
  12179. }
  12180. }
  12181. return $count;
  12182. }
  12183. }
  12184. <?php
  12185. namespace Composer\Json;
  12186. use Exception;
  12187. class JsonValidationException extends Exception
  12188. {
  12189. protected $errors;
  12190. public function __construct($message, $errors = array(), Exception $previous = null)
  12191. {
  12192. $this->errors = $errors;
  12193. parent::__construct($message, 0, $previous);
  12194. }
  12195. public function getErrors()
  12196. {
  12197. return $this->errors;
  12198. }
  12199. }
  12200. <?php
  12201. namespace Composer\Package;
  12202. use Composer\Semver\Constraint\Constraint;
  12203. use Composer\Semver\VersionParser;
  12204. class AliasPackage extends BasePackage implements CompletePackageInterface
  12205. {
  12206. protected $version;
  12207. protected $prettyVersion;
  12208. protected $dev;
  12209. protected $aliasOf;
  12210. protected $rootPackageAlias = false;
  12211. protected $stability;
  12212. protected $requires;
  12213. protected $devRequires;
  12214. protected $conflicts;
  12215. protected $provides;
  12216. protected $replaces;
  12217. protected $recommends;
  12218. protected $suggests;
  12219. public function __construct(PackageInterface $aliasOf, $version, $prettyVersion)
  12220. {
  12221. parent::__construct($aliasOf->getName());
  12222. $this->version = $version;
  12223. $this->prettyVersion = $prettyVersion;
  12224. $this->aliasOf = $aliasOf;
  12225. $this->stability = VersionParser::parseStability($version);
  12226. $this->dev = $this->stability === 'dev';
  12227. foreach (array('requires', 'devRequires', 'conflicts', 'provides', 'replaces') as $type) {
  12228. $links = $aliasOf->{'get' . ucfirst($type)}();
  12229. $this->$type = $this->replaceSelfVersionDependencies($links, $type);
  12230. }
  12231. }
  12232. public function getAliasOf()
  12233. {
  12234. return $this->aliasOf;
  12235. }
  12236. public function getVersion()
  12237. {
  12238. return $this->version;
  12239. }
  12240. public function getStability()
  12241. {
  12242. return $this->stability;
  12243. }
  12244. public function getPrettyVersion()
  12245. {
  12246. return $this->prettyVersion;
  12247. }
  12248. public function isDev()
  12249. {
  12250. return $this->dev;
  12251. }
  12252. public function getRequires()
  12253. {
  12254. return $this->requires;
  12255. }
  12256. public function getConflicts()
  12257. {
  12258. return $this->conflicts;
  12259. }
  12260. public function getProvides()
  12261. {
  12262. return $this->provides;
  12263. }
  12264. public function getReplaces()
  12265. {
  12266. return $this->replaces;
  12267. }
  12268. public function getDevRequires()
  12269. {
  12270. return $this->devRequires;
  12271. }
  12272. public function setRootPackageAlias($value)
  12273. {
  12274. return $this->rootPackageAlias = $value;
  12275. }
  12276. public function isRootPackageAlias()
  12277. {
  12278. return $this->rootPackageAlias;
  12279. }
  12280. protected function replaceSelfVersionDependencies(array $links, $linkType)
  12281. {
  12282. if (in_array($linkType, array('conflicts', 'provides', 'replaces'), true)) {
  12283. $newLinks = array();
  12284. foreach ($links as $link) {
  12285. if ('self.version' === $link->getPrettyConstraint()) {
  12286. $newLinks[] = new Link($link->getSource(), $link->getTarget(), new Constraint('=', $this->version), $linkType, $this->prettyVersion);
  12287. }
  12288. }
  12289. $links = array_merge($links, $newLinks);
  12290. } else {
  12291. foreach ($links as $index => $link) {
  12292. if ('self.version' === $link->getPrettyConstraint()) {
  12293. $links[$index] = new Link($link->getSource(), $link->getTarget(), new Constraint('=', $this->version), $linkType, $this->prettyVersion);
  12294. }
  12295. }
  12296. }
  12297. return $links;
  12298. }
  12299. public function getType()
  12300. {
  12301. return $this->aliasOf->getType();
  12302. }
  12303. public function getTargetDir()
  12304. {
  12305. return $this->aliasOf->getTargetDir();
  12306. }
  12307. public function getExtra()
  12308. {
  12309. return $this->aliasOf->getExtra();
  12310. }
  12311. public function setInstallationSource($type)
  12312. {
  12313. $this->aliasOf->setInstallationSource($type);
  12314. }
  12315. public function getInstallationSource()
  12316. {
  12317. return $this->aliasOf->getInstallationSource();
  12318. }
  12319. public function getSourceType()
  12320. {
  12321. return $this->aliasOf->getSourceType();
  12322. }
  12323. public function getSourceUrl()
  12324. {
  12325. return $this->aliasOf->getSourceUrl();
  12326. }
  12327. public function getSourceUrls()
  12328. {
  12329. return $this->aliasOf->getSourceUrls();
  12330. }
  12331. public function getSourceReference()
  12332. {
  12333. return $this->aliasOf->getSourceReference();
  12334. }
  12335. public function setSourceReference($reference)
  12336. {
  12337. return $this->aliasOf->setSourceReference($reference);
  12338. }
  12339. public function setSourceMirrors($mirrors)
  12340. {
  12341. return $this->aliasOf->setSourceMirrors($mirrors);
  12342. }
  12343. public function getSourceMirrors()
  12344. {
  12345. return $this->aliasOf->getSourceMirrors();
  12346. }
  12347. public function getDistType()
  12348. {
  12349. return $this->aliasOf->getDistType();
  12350. }
  12351. public function getDistUrl()
  12352. {
  12353. return $this->aliasOf->getDistUrl();
  12354. }
  12355. public function getDistUrls()
  12356. {
  12357. return $this->aliasOf->getDistUrls();
  12358. }
  12359. public function getDistReference()
  12360. {
  12361. return $this->aliasOf->getDistReference();
  12362. }
  12363. public function setDistReference($reference)
  12364. {
  12365. return $this->aliasOf->setDistReference($reference);
  12366. }
  12367. public function getDistSha1Checksum()
  12368. {
  12369. return $this->aliasOf->getDistSha1Checksum();
  12370. }
  12371. public function setTransportOptions(array $options)
  12372. {
  12373. return $this->aliasOf->setTransportOptions($options);
  12374. }
  12375. public function getTransportOptions()
  12376. {
  12377. return $this->aliasOf->getTransportOptions();
  12378. }
  12379. public function setDistMirrors($mirrors)
  12380. {
  12381. return $this->aliasOf->setDistMirrors($mirrors);
  12382. }
  12383. public function getDistMirrors()
  12384. {
  12385. return $this->aliasOf->getDistMirrors();
  12386. }
  12387. public function getScripts()
  12388. {
  12389. return $this->aliasOf->getScripts();
  12390. }
  12391. public function getLicense()
  12392. {
  12393. return $this->aliasOf->getLicense();
  12394. }
  12395. public function getAutoload()
  12396. {
  12397. return $this->aliasOf->getAutoload();
  12398. }
  12399. public function getDevAutoload()
  12400. {
  12401. return $this->aliasOf->getDevAutoload();
  12402. }
  12403. public function getIncludePaths()
  12404. {
  12405. return $this->aliasOf->getIncludePaths();
  12406. }
  12407. public function getRepositories()
  12408. {
  12409. return $this->aliasOf->getRepositories();
  12410. }
  12411. public function getReleaseDate()
  12412. {
  12413. return $this->aliasOf->getReleaseDate();
  12414. }
  12415. public function getBinaries()
  12416. {
  12417. return $this->aliasOf->getBinaries();
  12418. }
  12419. public function getKeywords()
  12420. {
  12421. return $this->aliasOf->getKeywords();
  12422. }
  12423. public function getDescription()
  12424. {
  12425. return $this->aliasOf->getDescription();
  12426. }
  12427. public function getHomepage()
  12428. {
  12429. return $this->aliasOf->getHomepage();
  12430. }
  12431. public function getSuggests()
  12432. {
  12433. return $this->aliasOf->getSuggests();
  12434. }
  12435. public function getAuthors()
  12436. {
  12437. return $this->aliasOf->getAuthors();
  12438. }
  12439. public function getSupport()
  12440. {
  12441. return $this->aliasOf->getSupport();
  12442. }
  12443. public function getNotificationUrl()
  12444. {
  12445. return $this->aliasOf->getNotificationUrl();
  12446. }
  12447. public function getArchiveExcludes()
  12448. {
  12449. return $this->aliasOf->getArchiveExcludes();
  12450. }
  12451. public function isAbandoned()
  12452. {
  12453. return $this->aliasOf->isAbandoned();
  12454. }
  12455. public function getReplacementPackage()
  12456. {
  12457. return $this->aliasOf->getReplacementPackage();
  12458. }
  12459. public function __toString()
  12460. {
  12461. return parent::__toString().' (alias of '.$this->aliasOf->getVersion().')';
  12462. }
  12463. }
  12464. <?php
  12465. namespace Composer\Package\Archiver;
  12466. use Composer\Util\Filesystem;
  12467. use Symfony\Component\Finder\Finder;
  12468. class ArchivableFilesFinder extends \FilterIterator
  12469. {
  12470. protected $finder;
  12471. public function __construct($sources, array $excludes)
  12472. {
  12473. $fs = new Filesystem();
  12474. $sources = $fs->normalizePath($sources);
  12475. $filters = array(
  12476. new HgExcludeFilter($sources),
  12477. new GitExcludeFilter($sources),
  12478. new ComposerExcludeFilter($sources, $excludes),
  12479. );
  12480. $this->finder = new Finder();
  12481. $filter = function (\SplFileInfo $file) use ($sources, $filters, $fs) {
  12482. if ($file->isLink() && strpos($file->getLinkTarget(), $sources) !== 0) {
  12483. return false;
  12484. }
  12485. $relativePath = preg_replace(
  12486. '#^'.preg_quote($sources, '#').'#',
  12487. '',
  12488. $fs->normalizePath($file->getRealPath())
  12489. );
  12490. $exclude = false;
  12491. foreach ($filters as $filter) {
  12492. $exclude = $filter->filter($relativePath, $exclude);
  12493. }
  12494. return !$exclude;
  12495. };
  12496. if (method_exists($filter, 'bindTo')) {
  12497. $filter = $filter->bindTo(null);
  12498. }
  12499. $this->finder
  12500. ->in($sources)
  12501. ->filter($filter)
  12502. ->ignoreVCS(true)
  12503. ->ignoreDotFiles(false);
  12504. parent::__construct($this->finder->getIterator());
  12505. }
  12506. public function accept()
  12507. {
  12508. return !$this->getInnerIterator()->current()->isDir();
  12509. }
  12510. }
  12511. <?php
  12512. namespace Composer\Package\Archiver;
  12513. use Composer\Downloader\DownloadManager;
  12514. use Composer\Package\PackageInterface;
  12515. use Composer\Package\RootPackageInterface;
  12516. use Composer\Util\Filesystem;
  12517. use Composer\Json\JsonFile;
  12518. class ArchiveManager
  12519. {
  12520. protected $downloadManager;
  12521. protected $archivers = array();
  12522. protected $overwriteFiles = true;
  12523. public function __construct(DownloadManager $downloadManager)
  12524. {
  12525. $this->downloadManager = $downloadManager;
  12526. }
  12527. public function addArchiver(ArchiverInterface $archiver)
  12528. {
  12529. $this->archivers[] = $archiver;
  12530. }
  12531. public function setOverwriteFiles($overwriteFiles)
  12532. {
  12533. $this->overwriteFiles = $overwriteFiles;
  12534. return $this;
  12535. }
  12536. public function getPackageFilename(PackageInterface $package)
  12537. {
  12538. $nameParts = array(preg_replace('#[^a-z0-9-_]#i', '-', $package->getName()));
  12539. if (preg_match('{^[a-f0-9]{40}$}', $package->getDistReference())) {
  12540. $nameParts = array_merge($nameParts, array($package->getDistReference(), $package->getDistType()));
  12541. } else {
  12542. $nameParts = array_merge($nameParts, array($package->getPrettyVersion(), $package->getDistReference()));
  12543. }
  12544. if ($package->getSourceReference()) {
  12545. $nameParts[] = substr(sha1($package->getSourceReference()), 0, 6);
  12546. }
  12547. $name = implode('-', array_filter($nameParts, function ($p) {
  12548. return !empty($p);
  12549. }));
  12550. return str_replace('/', '-', $name);
  12551. }
  12552. public function archive(PackageInterface $package, $format, $targetDir, $fileName = null)
  12553. {
  12554. if (empty($format)) {
  12555. throw new \InvalidArgumentException('Format must be specified');
  12556. }
  12557. $usableArchiver = null;
  12558. foreach ($this->archivers as $archiver) {
  12559. if ($archiver->supports($format, $package->getSourceType())) {
  12560. $usableArchiver = $archiver;
  12561. break;
  12562. }
  12563. }
  12564. if (null === $usableArchiver) {
  12565. throw new \RuntimeException(sprintf('No archiver found to support %s format', $format));
  12566. }
  12567. $filesystem = new Filesystem();
  12568. if (null === $fileName) {
  12569. $packageName = $this->getPackageFilename($package);
  12570. } else {
  12571. $packageName = $fileName;
  12572. }
  12573. $filesystem->ensureDirectoryExists($targetDir);
  12574. $target = realpath($targetDir).'/'.$packageName.'.'.$format;
  12575. $filesystem->ensureDirectoryExists(dirname($target));
  12576. if (!$this->overwriteFiles && file_exists($target)) {
  12577. return $target;
  12578. }
  12579. if ($package instanceof RootPackageInterface) {
  12580. $sourcePath = realpath('.');
  12581. } else {
  12582. $sourcePath = sys_get_temp_dir().'/composer_archive'.uniqid();
  12583. $filesystem->ensureDirectoryExists($sourcePath);
  12584. $this->downloadManager->download($package, $sourcePath);
  12585. if (file_exists($composerJsonPath = $sourcePath.'/composer.json')) {
  12586. $jsonFile = new JsonFile($composerJsonPath);
  12587. $jsonData = $jsonFile->read();
  12588. if (!empty($jsonData['archive']['exclude'])) {
  12589. $package->setArchiveExcludes($jsonData['archive']['exclude']);
  12590. }
  12591. }
  12592. }
  12593. $tempTarget = sys_get_temp_dir().'/composer_archive'.uniqid().'.'.$format;
  12594. $filesystem->ensureDirectoryExists(dirname($tempTarget));
  12595. $archivePath = $usableArchiver->archive($sourcePath, $tempTarget, $format, $package->getArchiveExcludes());
  12596. rename($archivePath, $target);
  12597. if (!$package instanceof RootPackageInterface) {
  12598. $filesystem->removeDirectory($sourcePath);
  12599. }
  12600. $filesystem->remove($tempTarget);
  12601. return $target;
  12602. }
  12603. }
  12604. <?php
  12605. namespace Composer\Package\Archiver;
  12606. interface ArchiverInterface
  12607. {
  12608. public function archive($sources, $target, $format, array $excludes = array());
  12609. public function supports($format, $sourceType);
  12610. }
  12611. <?php
  12612. namespace Composer\Package\Archiver;
  12613. use Symfony\Component\Finder;
  12614. abstract class BaseExcludeFilter
  12615. {
  12616. protected $sourcePath;
  12617. protected $excludePatterns;
  12618. public function __construct($sourcePath)
  12619. {
  12620. $this->sourcePath = $sourcePath;
  12621. $this->excludePatterns = array();
  12622. }
  12623. public function filter($relativePath, $exclude)
  12624. {
  12625. foreach ($this->excludePatterns as $patternData) {
  12626. list($pattern, $negate, $stripLeadingSlash) = $patternData;
  12627. if ($stripLeadingSlash) {
  12628. $path = substr($relativePath, 1);
  12629. } else {
  12630. $path = $relativePath;
  12631. }
  12632. if (preg_match($pattern, $path)) {
  12633. $exclude = !$negate;
  12634. }
  12635. }
  12636. return $exclude;
  12637. }
  12638. protected function parseLines(array $lines, $lineParser)
  12639. {
  12640. return array_filter(
  12641. array_map(
  12642. function ($line) use ($lineParser) {
  12643. $line = trim($line);
  12644. if (!$line || 0 === strpos($line, '#')) {
  12645. return;
  12646. }
  12647. return call_user_func($lineParser, $line);
  12648. },
  12649. $lines
  12650. ),
  12651. function ($pattern) {
  12652. return $pattern !== null;
  12653. }
  12654. );
  12655. }
  12656. protected function generatePatterns($rules)
  12657. {
  12658. $patterns = array();
  12659. foreach ($rules as $rule) {
  12660. $patterns[] = $this->generatePattern($rule);
  12661. }
  12662. return $patterns;
  12663. }
  12664. protected function generatePattern($rule)
  12665. {
  12666. $negate = false;
  12667. $pattern = '{';
  12668. if (strlen($rule) && $rule[0] === '!') {
  12669. $negate = true;
  12670. $rule = substr($rule, 1);
  12671. }
  12672. if (strlen($rule) && $rule[0] === '/') {
  12673. $pattern .= '^/';
  12674. $rule = substr($rule, 1);
  12675. } elseif (strlen($rule) - 1 === strpos($rule, '/')) {
  12676. $pattern .= '/';
  12677. $rule = substr($rule, 0, -1);
  12678. } elseif (false === strpos($rule, '/')) {
  12679. $pattern .= '/';
  12680. }
  12681. $pattern .= substr(Finder\Glob::toRegex($rule), 2, -2) . '(?=$|/)';
  12682. return array($pattern . '}', $negate, false);
  12683. }
  12684. }
  12685. <?php
  12686. namespace Composer\Package\Archiver;
  12687. class ComposerExcludeFilter extends BaseExcludeFilter
  12688. {
  12689. public function __construct($sourcePath, array $excludeRules)
  12690. {
  12691. parent::__construct($sourcePath);
  12692. $this->excludePatterns = $this->generatePatterns($excludeRules);
  12693. }
  12694. }
  12695. <?php
  12696. namespace Composer\Package\Archiver;
  12697. class GitExcludeFilter extends BaseExcludeFilter
  12698. {
  12699. public function __construct($sourcePath)
  12700. {
  12701. parent::__construct($sourcePath);
  12702. if (file_exists($sourcePath.'/.gitignore')) {
  12703. $this->excludePatterns = $this->parseLines(
  12704. file($sourcePath.'/.gitignore'),
  12705. array($this, 'parseGitIgnoreLine')
  12706. );
  12707. }
  12708. if (file_exists($sourcePath.'/.gitattributes')) {
  12709. $this->excludePatterns = array_merge(
  12710. $this->excludePatterns,
  12711. $this->parseLines(
  12712. file($sourcePath.'/.gitattributes'),
  12713. array($this, 'parseGitAttributesLine')
  12714. ));
  12715. }
  12716. }
  12717. public function parseGitIgnoreLine($line)
  12718. {
  12719. return $this->generatePattern($line);
  12720. }
  12721. public function parseGitAttributesLine($line)
  12722. {
  12723. $parts = preg_split('#\s+#', $line);
  12724. if (count($parts) != 2) {
  12725. return null;
  12726. }
  12727. if ($parts[1] === 'export-ignore') {
  12728. return $this->generatePattern($parts[0]);
  12729. }
  12730. }
  12731. }
  12732. <?php
  12733. namespace Composer\Package\Archiver;
  12734. use Symfony\Component\Finder;
  12735. class HgExcludeFilter extends BaseExcludeFilter
  12736. {
  12737. const HG_IGNORE_REGEX = 1;
  12738. const HG_IGNORE_GLOB = 2;
  12739. protected $patternMode;
  12740. public function __construct($sourcePath)
  12741. {
  12742. parent::__construct($sourcePath);
  12743. $this->patternMode = self::HG_IGNORE_REGEX;
  12744. if (file_exists($sourcePath.'/.hgignore')) {
  12745. $this->excludePatterns = $this->parseLines(
  12746. file($sourcePath.'/.hgignore'),
  12747. array($this, 'parseHgIgnoreLine')
  12748. );
  12749. }
  12750. }
  12751. public function parseHgIgnoreLine($line)
  12752. {
  12753. if (preg_match('#^syntax\s*:\s*(glob|regexp)$#', $line, $matches)) {
  12754. if ($matches[1] === 'glob') {
  12755. $this->patternMode = self::HG_IGNORE_GLOB;
  12756. } else {
  12757. $this->patternMode = self::HG_IGNORE_REGEX;
  12758. }
  12759. return null;
  12760. }
  12761. if ($this->patternMode == self::HG_IGNORE_GLOB) {
  12762. return $this->patternFromGlob($line);
  12763. } else {
  12764. return $this->patternFromRegex($line);
  12765. }
  12766. }
  12767. protected function patternFromGlob($line)
  12768. {
  12769. $pattern = '#'.substr(Finder\Glob::toRegex($line), 2, -1).'#';
  12770. $pattern = str_replace('[^/]*', '.*', $pattern);
  12771. return array($pattern, false, true);
  12772. }
  12773. public function patternFromRegex($line)
  12774. {
  12775. $pattern = '#'.preg_replace('/((?:\\\\\\\\)*)(\\\\?)#/', '\1\2\2\\#', $line).'#';
  12776. return array($pattern, false, true);
  12777. }
  12778. }
  12779. <?php
  12780. namespace Composer\Package\Archiver;
  12781. class PharArchiver implements ArchiverInterface
  12782. {
  12783. protected static $formats = array(
  12784. 'zip' => \Phar::ZIP,
  12785. 'tar' => \Phar::TAR,
  12786. );
  12787. public function archive($sources, $target, $format, array $excludes = array())
  12788. {
  12789. $sources = realpath($sources);
  12790. if (file_exists($target)) {
  12791. unlink($target);
  12792. }
  12793. try {
  12794. $phar = new \PharData($target, null, null, static::$formats[$format]);
  12795. $files = new ArchivableFilesFinder($sources, $excludes);
  12796. $phar->buildFromIterator($files, $sources);
  12797. return $target;
  12798. } catch (\UnexpectedValueException $e) {
  12799. $message = sprintf("Could not create archive '%s' from '%s': %s",
  12800. $target,
  12801. $sources,
  12802. $e->getMessage()
  12803. );
  12804. throw new \RuntimeException($message, $e->getCode(), $e);
  12805. }
  12806. }
  12807. public function supports($format, $sourceType)
  12808. {
  12809. return isset(static::$formats[$format]);
  12810. }
  12811. }
  12812. <?php
  12813. namespace Composer\Package;
  12814. use Composer\Repository\RepositoryInterface;
  12815. use Composer\Repository\PlatformRepository;
  12816. abstract class BasePackage implements PackageInterface
  12817. {
  12818. public static $supportedLinkTypes = array(
  12819. 'require' => array('description' => 'requires', 'method' => 'requires'),
  12820. 'conflict' => array('description' => 'conflicts', 'method' => 'conflicts'),
  12821. 'provide' => array('description' => 'provides', 'method' => 'provides'),
  12822. 'replace' => array('description' => 'replaces', 'method' => 'replaces'),
  12823. 'require-dev' => array('description' => 'requires (for development)', 'method' => 'devRequires'),
  12824. );
  12825. const STABILITY_STABLE = 0;
  12826. const STABILITY_RC = 5;
  12827. const STABILITY_BETA = 10;
  12828. const STABILITY_ALPHA = 15;
  12829. const STABILITY_DEV = 20;
  12830. public static $stabilities = array(
  12831. 'stable' => self::STABILITY_STABLE,
  12832. 'RC' => self::STABILITY_RC,
  12833. 'beta' => self::STABILITY_BETA,
  12834. 'alpha' => self::STABILITY_ALPHA,
  12835. 'dev' => self::STABILITY_DEV,
  12836. );
  12837. public $id;
  12838. protected $name;
  12839. protected $prettyName;
  12840. protected $repository;
  12841. protected $transportOptions;
  12842. public function __construct($name)
  12843. {
  12844. $this->prettyName = $name;
  12845. $this->name = strtolower($name);
  12846. $this->id = -1;
  12847. $this->transportOptions = array();
  12848. }
  12849. public function getName()
  12850. {
  12851. return $this->name;
  12852. }
  12853. public function getPrettyName()
  12854. {
  12855. return $this->prettyName;
  12856. }
  12857. public function getNames()
  12858. {
  12859. $names = array(
  12860. $this->getName() => true,
  12861. );
  12862. foreach ($this->getProvides() as $link) {
  12863. $names[$link->getTarget()] = true;
  12864. }
  12865. foreach ($this->getReplaces() as $link) {
  12866. $names[$link->getTarget()] = true;
  12867. }
  12868. return array_keys($names);
  12869. }
  12870. public function setId($id)
  12871. {
  12872. $this->id = $id;
  12873. }
  12874. public function getId()
  12875. {
  12876. return $this->id;
  12877. }
  12878. public function setRepository(RepositoryInterface $repository)
  12879. {
  12880. if ($this->repository && $repository !== $this->repository) {
  12881. throw new \LogicException('A package can only be added to one repository');
  12882. }
  12883. $this->repository = $repository;
  12884. }
  12885. public function getRepository()
  12886. {
  12887. return $this->repository;
  12888. }
  12889. public function getTransportOptions()
  12890. {
  12891. return $this->transportOptions;
  12892. }
  12893. public function setTransportOptions(array $options)
  12894. {
  12895. $this->transportOptions = $options;
  12896. }
  12897. public function isPlatform()
  12898. {
  12899. return $this->getRepository() instanceof PlatformRepository;
  12900. }
  12901. public function getUniqueName()
  12902. {
  12903. return $this->getName().'-'.$this->getVersion();
  12904. }
  12905. public function equals(PackageInterface $package)
  12906. {
  12907. $self = $this;
  12908. if ($this instanceof AliasPackage) {
  12909. $self = $this->getAliasOf();
  12910. }
  12911. if ($package instanceof AliasPackage) {
  12912. $package = $package->getAliasOf();
  12913. }
  12914. return $package === $self;
  12915. }
  12916. public function __toString()
  12917. {
  12918. return $this->getUniqueName();
  12919. }
  12920. public function getPrettyString()
  12921. {
  12922. return $this->getPrettyName().' '.$this->getPrettyVersion();
  12923. }
  12924. public function getFullPrettyVersion($truncate = true)
  12925. {
  12926. if (!$this->isDev() || !in_array($this->getSourceType(), array('hg', 'git'))) {
  12927. return $this->getPrettyVersion();
  12928. }
  12929. if ($truncate && strlen($this->getSourceReference()) === 40) {
  12930. return $this->getPrettyVersion() . ' ' . substr($this->getSourceReference(), 0, 7);
  12931. }
  12932. return $this->getPrettyVersion() . ' ' . $this->getSourceReference();
  12933. }
  12934. public function __clone()
  12935. {
  12936. $this->repository = null;
  12937. $this->id = -1;
  12938. }
  12939. }
  12940. <?php
  12941. namespace Composer\Package;
  12942. class CompletePackage extends Package implements CompletePackageInterface
  12943. {
  12944. protected $repositories;
  12945. protected $license = array();
  12946. protected $keywords;
  12947. protected $authors;
  12948. protected $description;
  12949. protected $homepage;
  12950. protected $scripts = array();
  12951. protected $support = array();
  12952. protected $abandoned = false;
  12953. public function setScripts(array $scripts)
  12954. {
  12955. $this->scripts = $scripts;
  12956. }
  12957. public function getScripts()
  12958. {
  12959. return $this->scripts;
  12960. }
  12961. public function setRepositories($repositories)
  12962. {
  12963. $this->repositories = $repositories;
  12964. }
  12965. public function getRepositories()
  12966. {
  12967. return $this->repositories;
  12968. }
  12969. public function setLicense(array $license)
  12970. {
  12971. $this->license = $license;
  12972. }
  12973. public function getLicense()
  12974. {
  12975. return $this->license;
  12976. }
  12977. public function setKeywords(array $keywords)
  12978. {
  12979. $this->keywords = $keywords;
  12980. }
  12981. public function getKeywords()
  12982. {
  12983. return $this->keywords;
  12984. }
  12985. public function setAuthors(array $authors)
  12986. {
  12987. $this->authors = $authors;
  12988. }
  12989. public function getAuthors()
  12990. {
  12991. return $this->authors;
  12992. }
  12993. public function setDescription($description)
  12994. {
  12995. $this->description = $description;
  12996. }
  12997. public function getDescription()
  12998. {
  12999. return $this->description;
  13000. }
  13001. public function setHomepage($homepage)
  13002. {
  13003. $this->homepage = $homepage;
  13004. }
  13005. public function getHomepage()
  13006. {
  13007. return $this->homepage;
  13008. }
  13009. public function setSupport(array $support)
  13010. {
  13011. $this->support = $support;
  13012. }
  13013. public function getSupport()
  13014. {
  13015. return $this->support;
  13016. }
  13017. public function isAbandoned()
  13018. {
  13019. return (boolean) $this->abandoned;
  13020. }
  13021. public function setAbandoned($abandoned)
  13022. {
  13023. $this->abandoned = $abandoned;
  13024. }
  13025. public function getReplacementPackage()
  13026. {
  13027. return is_string($this->abandoned) ? $this->abandoned : null;
  13028. }
  13029. }
  13030. <?php
  13031. namespace Composer\Package;
  13032. interface CompletePackageInterface extends PackageInterface
  13033. {
  13034. public function getScripts();
  13035. public function getRepositories();
  13036. public function getLicense();
  13037. public function getKeywords();
  13038. public function getDescription();
  13039. public function getHomepage();
  13040. public function getAuthors();
  13041. public function getSupport();
  13042. public function isAbandoned();
  13043. public function getReplacementPackage();
  13044. }
  13045. <?php
  13046. namespace Composer\Package\Dumper;
  13047. use Composer\Package\BasePackage;
  13048. use Composer\Package\PackageInterface;
  13049. use Composer\Package\CompletePackageInterface;
  13050. use Composer\Package\RootPackageInterface;
  13051. class ArrayDumper
  13052. {
  13053. public function dump(PackageInterface $package)
  13054. {
  13055. $keys = array(
  13056. 'binaries' => 'bin',
  13057. 'type',
  13058. 'extra',
  13059. 'installationSource' => 'installation-source',
  13060. 'autoload',
  13061. 'devAutoload' => 'autoload-dev',
  13062. 'notificationUrl' => 'notification-url',
  13063. 'includePaths' => 'include-path',
  13064. );
  13065. $data = array();
  13066. $data['name'] = $package->getPrettyName();
  13067. $data['version'] = $package->getPrettyVersion();
  13068. $data['version_normalized'] = $package->getVersion();
  13069. if ($package->getTargetDir()) {
  13070. $data['target-dir'] = $package->getTargetDir();
  13071. }
  13072. if ($package->getSourceType()) {
  13073. $data['source']['type'] = $package->getSourceType();
  13074. $data['source']['url'] = $package->getSourceUrl();
  13075. $data['source']['reference'] = $package->getSourceReference();
  13076. if ($mirrors = $package->getSourceMirrors()) {
  13077. $data['source']['mirrors'] = $mirrors;
  13078. }
  13079. }
  13080. if ($package->getDistType()) {
  13081. $data['dist']['type'] = $package->getDistType();
  13082. $data['dist']['url'] = $package->getDistUrl();
  13083. $data['dist']['reference'] = $package->getDistReference();
  13084. $data['dist']['shasum'] = $package->getDistSha1Checksum();
  13085. if ($mirrors = $package->getDistMirrors()) {
  13086. $data['dist']['mirrors'] = $mirrors;
  13087. }
  13088. }
  13089. if ($package->getArchiveExcludes()) {
  13090. $data['archive']['exclude'] = $package->getArchiveExcludes();
  13091. }
  13092. foreach (BasePackage::$supportedLinkTypes as $type => $opts) {
  13093. if ($links = $package->{'get'.ucfirst($opts['method'])}()) {
  13094. foreach ($links as $link) {
  13095. $data[$type][$link->getTarget()] = $link->getPrettyConstraint();
  13096. }
  13097. ksort($data[$type]);
  13098. }
  13099. }
  13100. if ($packages = $package->getSuggests()) {
  13101. ksort($packages);
  13102. $data['suggest'] = $packages;
  13103. }
  13104. if ($package->getReleaseDate()) {
  13105. $data['time'] = $package->getReleaseDate()->format('Y-m-d H:i:s');
  13106. }
  13107. $data = $this->dumpValues($package, $keys, $data);
  13108. if ($package instanceof CompletePackageInterface) {
  13109. $keys = array(
  13110. 'scripts',
  13111. 'license',
  13112. 'authors',
  13113. 'description',
  13114. 'homepage',
  13115. 'keywords',
  13116. 'repositories',
  13117. 'support',
  13118. );
  13119. $data = $this->dumpValues($package, $keys, $data);
  13120. if (isset($data['keywords']) && is_array($data['keywords'])) {
  13121. sort($data['keywords']);
  13122. }
  13123. if ($package->isAbandoned()) {
  13124. $data['abandoned'] = $package->getReplacementPackage() ?: true;
  13125. }
  13126. }
  13127. if ($package instanceof RootPackageInterface) {
  13128. $minimumStability = $package->getMinimumStability();
  13129. if ($minimumStability) {
  13130. $data['minimum-stability'] = $minimumStability;
  13131. }
  13132. }
  13133. if (count($package->getTransportOptions()) > 0) {
  13134. $data['transport-options'] = $package->getTransportOptions();
  13135. }
  13136. return $data;
  13137. }
  13138. private function dumpValues(PackageInterface $package, array $keys, array $data)
  13139. {
  13140. foreach ($keys as $method => $key) {
  13141. if (is_numeric($method)) {
  13142. $method = $key;
  13143. }
  13144. $getter = 'get'.ucfirst($method);
  13145. $value = $package->$getter();
  13146. if (null !== $value && !(is_array($value) && 0 === count($value))) {
  13147. $data[$key] = $value;
  13148. }
  13149. }
  13150. return $data;
  13151. }
  13152. }
  13153. <?php
  13154. namespace Composer\Package;
  13155. use Composer\Semver\Constraint\ConstraintInterface;
  13156. class Link
  13157. {
  13158. protected $source;
  13159. protected $target;
  13160. protected $constraint;
  13161. protected $description;
  13162. protected $prettyConstraint;
  13163. public function __construct($source, $target, ConstraintInterface $constraint = null, $description = 'relates to', $prettyConstraint = null)
  13164. {
  13165. $this->source = strtolower($source);
  13166. $this->target = strtolower($target);
  13167. $this->constraint = $constraint;
  13168. $this->description = $description;
  13169. $this->prettyConstraint = $prettyConstraint;
  13170. }
  13171. public function getSource()
  13172. {
  13173. return $this->source;
  13174. }
  13175. public function getTarget()
  13176. {
  13177. return $this->target;
  13178. }
  13179. public function getConstraint()
  13180. {
  13181. return $this->constraint;
  13182. }
  13183. public function getPrettyConstraint()
  13184. {
  13185. if (null === $this->prettyConstraint) {
  13186. throw new \UnexpectedValueException(sprintf('Link %s has been misconfigured and had no prettyConstraint given.', $this));
  13187. }
  13188. return $this->prettyConstraint;
  13189. }
  13190. public function __toString()
  13191. {
  13192. return $this->source.' '.$this->description.' '.$this->target.' ('.$this->constraint.')';
  13193. }
  13194. public function getPrettyString(PackageInterface $sourcePackage)
  13195. {
  13196. return $sourcePackage->getPrettyString().' '.$this->description.' '.$this->target.' '.$this->constraint->getPrettyString().'';
  13197. }
  13198. }
  13199. <?php
  13200. namespace Composer\Package\LinkConstraint;
  13201. use Composer\Semver\Constraint\EmptyConstraint as SemverEmptyConstraint;
  13202. @trigger_error('The ' . __NAMESPACE__ . '\EmptyConstraint class is deprecated, use Composer\Semver\Constraint\EmptyConstraint instead.', E_USER_DEPRECATED);
  13203. class EmptyConstraint extends SemverEmptyConstraint implements LinkConstraintInterface
  13204. {
  13205. }
  13206. <?php
  13207. namespace Composer\Package\LinkConstraint;
  13208. use Composer\Semver\Constraint\ConstraintInterface;
  13209. @trigger_error('The ' . __NAMESPACE__ . '\LinkConstraintInterface interface is deprecated, use Composer\Semver\Constraint\ConstraintInterface instead.', E_USER_DEPRECATED);
  13210. interface LinkConstraintInterface extends ConstraintInterface
  13211. {
  13212. }
  13213. <?php
  13214. namespace Composer\Package\LinkConstraint;
  13215. use Composer\Semver\Constraint\MultiConstraint as SemverMultiConstraint;
  13216. @trigger_error('The ' . __NAMESPACE__ . '\MultiConstraint class is deprecated, use Composer\Semver\Constraint\MultiConstraint instead.', E_USER_DEPRECATED);
  13217. class MultiConstraint extends SemverMultiConstraint implements LinkConstraintInterface
  13218. {
  13219. }
  13220. <?php
  13221. namespace Composer\Package\LinkConstraint;
  13222. use Composer\Semver\Constraint\AbstractConstraint;
  13223. @trigger_error('The ' . __NAMESPACE__ . '\SpecificConstraint abstract class is deprecated, use Composer\Semver\Constraint\AbstractConstraint instead.', E_USER_DEPRECATED);
  13224. abstract class SpecificConstraint extends AbstractConstraint implements LinkConstraintInterface
  13225. {
  13226. }
  13227. <?php
  13228. namespace Composer\Package\LinkConstraint;
  13229. use Composer\Semver\Constraint\Constraint;
  13230. @trigger_error('The ' . __NAMESPACE__ . '\VersionConstraint class is deprecated, use Composer\Semver\Constraint\Constraint instead.', E_USER_DEPRECATED);
  13231. class VersionConstraint extends Constraint implements LinkConstraintInterface
  13232. {
  13233. }
  13234. <?php
  13235. namespace Composer\Package\Loader;
  13236. use Composer\Package;
  13237. use Composer\Package\AliasPackage;
  13238. use Composer\Package\Link;
  13239. use Composer\Package\RootAliasPackage;
  13240. use Composer\Package\RootPackageInterface;
  13241. use Composer\Semver\VersionParser;
  13242. class ArrayLoader implements LoaderInterface
  13243. {
  13244. protected $versionParser;
  13245. protected $loadOptions;
  13246. public function __construct(VersionParser $parser = null, $loadOptions = false)
  13247. {
  13248. if (!$parser) {
  13249. $parser = new VersionParser;
  13250. }
  13251. $this->versionParser = $parser;
  13252. $this->loadOptions = $loadOptions;
  13253. }
  13254. public function load(array $config, $class = 'Composer\Package\CompletePackage')
  13255. {
  13256. if (!isset($config['name'])) {
  13257. throw new \UnexpectedValueException('Unknown package has no name defined ('.json_encode($config).').');
  13258. }
  13259. if (!isset($config['version'])) {
  13260. throw new \UnexpectedValueException('Package '.$config['name'].' has no version defined.');
  13261. }
  13262. if (isset($config['version_normalized'])) {
  13263. $version = $config['version_normalized'];
  13264. } else {
  13265. $version = $this->versionParser->normalize($config['version']);
  13266. }
  13267. $package = new $class($config['name'], $version, $config['version']);
  13268. $package->setType(isset($config['type']) ? strtolower($config['type']) : 'library');
  13269. if (isset($config['target-dir'])) {
  13270. $package->setTargetDir($config['target-dir']);
  13271. }
  13272. if (isset($config['extra']) && is_array($config['extra'])) {
  13273. $package->setExtra($config['extra']);
  13274. }
  13275. if (isset($config['bin'])) {
  13276. if (!is_array($config['bin'])) {
  13277. throw new \UnexpectedValueException('Package '.$config['name'].'\'s bin key should be an array, '.gettype($config['bin']).' given.');
  13278. }
  13279. foreach ($config['bin'] as $key => $bin) {
  13280. $config['bin'][$key] = ltrim($bin, '/');
  13281. }
  13282. $package->setBinaries($config['bin']);
  13283. }
  13284. if (isset($config['installation-source'])) {
  13285. $package->setInstallationSource($config['installation-source']);
  13286. }
  13287. if (isset($config['source'])) {
  13288. if (!isset($config['source']['type']) || !isset($config['source']['url']) || !isset($config['source']['reference'])) {
  13289. throw new \UnexpectedValueException(sprintf(
  13290. "Package %s's source key should be specified as {\"type\": ..., \"url\": ..., \"reference\": ...},\n%s given.",
  13291. $config['name'],
  13292. json_encode($config['source'])
  13293. ));
  13294. }
  13295. $package->setSourceType($config['source']['type']);
  13296. $package->setSourceUrl($config['source']['url']);
  13297. $package->setSourceReference($config['source']['reference']);
  13298. if (isset($config['source']['mirrors'])) {
  13299. $package->setSourceMirrors($config['source']['mirrors']);
  13300. }
  13301. }
  13302. if (isset($config['dist'])) {
  13303. if (!isset($config['dist']['type'])
  13304. || !isset($config['dist']['url'])) {
  13305. throw new \UnexpectedValueException(sprintf(
  13306. "Package %s's dist key should be specified as ".
  13307. "{\"type\": ..., \"url\": ..., \"reference\": ..., \"shasum\": ...},\n%s given.",
  13308. $config['name'],
  13309. json_encode($config['dist'])
  13310. ));
  13311. }
  13312. $package->setDistType($config['dist']['type']);
  13313. $package->setDistUrl($config['dist']['url']);
  13314. $package->setDistReference(isset($config['dist']['reference']) ? $config['dist']['reference'] : null);
  13315. $package->setDistSha1Checksum(isset($config['dist']['shasum']) ? $config['dist']['shasum'] : null);
  13316. if (isset($config['dist']['mirrors'])) {
  13317. $package->setDistMirrors($config['dist']['mirrors']);
  13318. }
  13319. }
  13320. foreach (Package\BasePackage::$supportedLinkTypes as $type => $opts) {
  13321. if (isset($config[$type])) {
  13322. $method = 'set'.ucfirst($opts['method']);
  13323. $package->{$method}(
  13324. $this->parseLinks(
  13325. $package->getName(),
  13326. $package->getPrettyVersion(),
  13327. $opts['description'],
  13328. $config[$type]
  13329. )
  13330. );
  13331. }
  13332. }
  13333. if (isset($config['suggest']) && is_array($config['suggest'])) {
  13334. foreach ($config['suggest'] as $target => $reason) {
  13335. if ('self.version' === trim($reason)) {
  13336. $config['suggest'][$target] = $package->getPrettyVersion();
  13337. }
  13338. }
  13339. $package->setSuggests($config['suggest']);
  13340. }
  13341. if (isset($config['autoload'])) {
  13342. $package->setAutoload($config['autoload']);
  13343. }
  13344. if (isset($config['autoload-dev'])) {
  13345. $package->setDevAutoload($config['autoload-dev']);
  13346. }
  13347. if (isset($config['include-path'])) {
  13348. $package->setIncludePaths($config['include-path']);
  13349. }
  13350. if (!empty($config['time'])) {
  13351. $time = preg_match('/^\d++$/D', $config['time']) ? '@'.$config['time'] : $config['time'];
  13352. try {
  13353. $date = new \DateTime($time, new \DateTimeZone('UTC'));
  13354. $package->setReleaseDate($date);
  13355. } catch (\Exception $e) {
  13356. }
  13357. }
  13358. if (!empty($config['notification-url'])) {
  13359. $package->setNotificationUrl($config['notification-url']);
  13360. }
  13361. if (!empty($config['archive']['exclude'])) {
  13362. $package->setArchiveExcludes($config['archive']['exclude']);
  13363. }
  13364. if ($package instanceof Package\CompletePackageInterface) {
  13365. if (isset($config['scripts']) && is_array($config['scripts'])) {
  13366. foreach ($config['scripts'] as $event => $listeners) {
  13367. $config['scripts'][$event] = (array) $listeners;
  13368. }
  13369. $package->setScripts($config['scripts']);
  13370. }
  13371. if (!empty($config['description']) && is_string($config['description'])) {
  13372. $package->setDescription($config['description']);
  13373. }
  13374. if (!empty($config['homepage']) && is_string($config['homepage'])) {
  13375. $package->setHomepage($config['homepage']);
  13376. }
  13377. if (!empty($config['keywords']) && is_array($config['keywords'])) {
  13378. $package->setKeywords($config['keywords']);
  13379. }
  13380. if (!empty($config['license'])) {
  13381. $package->setLicense(is_array($config['license']) ? $config['license'] : array($config['license']));
  13382. }
  13383. if (!empty($config['authors']) && is_array($config['authors'])) {
  13384. $package->setAuthors($config['authors']);
  13385. }
  13386. if (isset($config['support'])) {
  13387. $package->setSupport($config['support']);
  13388. }
  13389. if (isset($config['abandoned'])) {
  13390. $package->setAbandoned($config['abandoned']);
  13391. }
  13392. }
  13393. if ($aliasNormalized = $this->getBranchAlias($config)) {
  13394. if ($package instanceof RootPackageInterface) {
  13395. $package = new RootAliasPackage($package, $aliasNormalized, preg_replace('{(\.9{7})+}', '.x', $aliasNormalized));
  13396. } else {
  13397. $package = new AliasPackage($package, $aliasNormalized, preg_replace('{(\.9{7})+}', '.x', $aliasNormalized));
  13398. }
  13399. }
  13400. if ($this->loadOptions && isset($config['transport-options'])) {
  13401. $package->setTransportOptions($config['transport-options']);
  13402. }
  13403. return $package;
  13404. }
  13405. public function parseLinks($source, $sourceVersion, $description, $links)
  13406. {
  13407. $res = array();
  13408. foreach ($links as $target => $constraint) {
  13409. if ('self.version' === $constraint) {
  13410. $parsedConstraint = $this->versionParser->parseConstraints($sourceVersion);
  13411. } else {
  13412. $parsedConstraint = $this->versionParser->parseConstraints($constraint);
  13413. }
  13414. $res[strtolower($target)] = new Link($source, $target, $parsedConstraint, $description, $constraint);
  13415. }
  13416. return $res;
  13417. }
  13418. public function getBranchAlias(array $config)
  13419. {
  13420. if (('dev-' !== substr($config['version'], 0, 4) && '-dev' !== substr($config['version'], -4))
  13421. || !isset($config['extra']['branch-alias'])
  13422. || !is_array($config['extra']['branch-alias'])
  13423. ) {
  13424. return;
  13425. }
  13426. foreach ($config['extra']['branch-alias'] as $sourceBranch => $targetBranch) {
  13427. if ('-dev' !== substr($targetBranch, -4)) {
  13428. continue;
  13429. }
  13430. $validatedTargetBranch = $this->versionParser->normalizeBranch(substr($targetBranch, 0, -4));
  13431. if ('-dev' !== substr($validatedTargetBranch, -4)) {
  13432. continue;
  13433. }
  13434. if (strtolower($config['version']) !== strtolower($sourceBranch)) {
  13435. continue;
  13436. }
  13437. if (($sourcePrefix = $this->versionParser->parseNumericAliasPrefix($sourceBranch))
  13438. && ($targetPrefix = $this->versionParser->parseNumericAliasPrefix($targetBranch))
  13439. && (stripos($targetPrefix, $sourcePrefix) !== 0)
  13440. ) {
  13441. continue;
  13442. }
  13443. return $validatedTargetBranch;
  13444. }
  13445. }
  13446. }
  13447. <?php
  13448. namespace Composer\Package\Loader;
  13449. class InvalidPackageException extends \Exception
  13450. {
  13451. private $errors;
  13452. private $warnings;
  13453. private $data;
  13454. public function __construct(array $errors, array $warnings, array $data)
  13455. {
  13456. $this->errors = $errors;
  13457. $this->warnings = $warnings;
  13458. $this->data = $data;
  13459. parent::__construct("Invalid package information: \n".implode("\n", array_merge($errors, $warnings)));
  13460. }
  13461. public function getData()
  13462. {
  13463. return $this->data;
  13464. }
  13465. public function getErrors()
  13466. {
  13467. return $this->errors;
  13468. }
  13469. public function getWarnings()
  13470. {
  13471. return $this->warnings;
  13472. }
  13473. }
  13474. <?php
  13475. namespace Composer\Package\Loader;
  13476. use Composer\Json\JsonFile;
  13477. class JsonLoader
  13478. {
  13479. private $loader;
  13480. public function __construct(LoaderInterface $loader)
  13481. {
  13482. $this->loader = $loader;
  13483. }
  13484. public function load($json)
  13485. {
  13486. if ($json instanceof JsonFile) {
  13487. $config = $json->read();
  13488. } elseif (file_exists($json)) {
  13489. $config = JsonFile::parseJson(file_get_contents($json), $json);
  13490. } elseif (is_string($json)) {
  13491. $config = JsonFile::parseJson($json);
  13492. }
  13493. return $this->loader->load($config);
  13494. }
  13495. }
  13496. <?php
  13497. namespace Composer\Package\Loader;
  13498. interface LoaderInterface
  13499. {
  13500. public function load(array $package, $class = 'Composer\Package\CompletePackage');
  13501. }
  13502. <?php
  13503. namespace Composer\Package\Loader;
  13504. use Composer\Package\BasePackage;
  13505. use Composer\Package\AliasPackage;
  13506. use Composer\Config;
  13507. use Composer\Factory;
  13508. use Composer\Package\Version\VersionGuesser;
  13509. use Composer\Semver\VersionParser;
  13510. use Composer\Repository\RepositoryManager;
  13511. use Composer\Util\ProcessExecutor;
  13512. class RootPackageLoader extends ArrayLoader
  13513. {
  13514. private $manager;
  13515. private $config;
  13516. private $versionGuesser;
  13517. public function __construct(RepositoryManager $manager, Config $config, VersionParser $parser = null, VersionGuesser $versionGuesser = null)
  13518. {
  13519. parent::__construct($parser);
  13520. $this->manager = $manager;
  13521. $this->config = $config;
  13522. $this->versionGuesser = $versionGuesser ?: new VersionGuesser($config, new ProcessExecutor(), $this->versionParser);
  13523. }
  13524. public function load(array $config, $class = 'Composer\Package\RootPackage')
  13525. {
  13526. if (!isset($config['name'])) {
  13527. $config['name'] = '__root__';
  13528. }
  13529. $autoVersioned = false;
  13530. if (!isset($config['version'])) {
  13531. if (getenv('COMPOSER_ROOT_VERSION')) {
  13532. $version = getenv('COMPOSER_ROOT_VERSION');
  13533. } else {
  13534. $version = $this->versionGuesser->guessVersion($config, getcwd());
  13535. }
  13536. if (!$version) {
  13537. $version = '1.0.0';
  13538. $autoVersioned = true;
  13539. }
  13540. $config['version'] = $version;
  13541. }
  13542. $realPackage = $package = parent::load($config, $class);
  13543. if ($realPackage instanceof AliasPackage) {
  13544. $realPackage = $package->getAliasOf();
  13545. }
  13546. if ($autoVersioned) {
  13547. $realPackage->replaceVersion($realPackage->getVersion(), 'No version set (parsed as 1.0.0)');
  13548. }
  13549. if (isset($config['minimum-stability'])) {
  13550. $realPackage->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability']));
  13551. }
  13552. $aliases = array();
  13553. $stabilityFlags = array();
  13554. $references = array();
  13555. foreach (array('require', 'require-dev') as $linkType) {
  13556. if (isset($config[$linkType])) {
  13557. $linkInfo = BasePackage::$supportedLinkTypes[$linkType];
  13558. $method = 'get'.ucfirst($linkInfo['method']);
  13559. $links = array();
  13560. foreach ($realPackage->$method() as $link) {
  13561. $links[$link->getTarget()] = $link->getConstraint()->getPrettyString();
  13562. }
  13563. $aliases = $this->extractAliases($links, $aliases);
  13564. $stabilityFlags = $this->extractStabilityFlags($links, $stabilityFlags, $realPackage->getMinimumStability());
  13565. $references = $this->extractReferences($links, $references);
  13566. }
  13567. }
  13568. $realPackage->setAliases($aliases);
  13569. $realPackage->setStabilityFlags($stabilityFlags);
  13570. $realPackage->setReferences($references);
  13571. if (isset($config['prefer-stable'])) {
  13572. $realPackage->setPreferStable((bool) $config['prefer-stable']);
  13573. }
  13574. $repos = Factory::createDefaultRepositories(null, $this->config, $this->manager);
  13575. foreach ($repos as $repo) {
  13576. $this->manager->addRepository($repo);
  13577. }
  13578. $realPackage->setRepositories($this->config->getRepositories());
  13579. return $package;
  13580. }
  13581. private function extractAliases(array $requires, array $aliases)
  13582. {
  13583. foreach ($requires as $reqName => $reqVersion) {
  13584. if (preg_match('{^([^,\s#]+)(?:#[^ ]+)? +as +([^,\s]+)$}', $reqVersion, $match)) {
  13585. $aliases[] = array(
  13586. 'package' => strtolower($reqName),
  13587. 'version' => $this->versionParser->normalize($match[1], $reqVersion),
  13588. 'alias' => $match[2],
  13589. 'alias_normalized' => $this->versionParser->normalize($match[2], $reqVersion),
  13590. );
  13591. }
  13592. }
  13593. return $aliases;
  13594. }
  13595. private function extractStabilityFlags(array $requires, array $stabilityFlags, $minimumStability)
  13596. {
  13597. $stabilities = BasePackage::$stabilities;
  13598. $minimumStability = $stabilities[$minimumStability];
  13599. foreach ($requires as $reqName => $reqVersion) {
  13600. if (preg_match('{^[^@]*?@('.implode('|', array_keys($stabilities)).')$}i', $reqVersion, $match)) {
  13601. $name = strtolower($reqName);
  13602. $stability = $stabilities[VersionParser::normalizeStability($match[1])];
  13603. if (isset($stabilityFlags[$name]) && $stabilityFlags[$name] > $stability) {
  13604. continue;
  13605. }
  13606. $stabilityFlags[$name] = $stability;
  13607. continue;
  13608. }
  13609. $reqVersion = preg_replace('{^([^,\s@]+) as .+$}', '$1', $reqVersion);
  13610. if (preg_match('{^[^,\s@]+$}', $reqVersion) && 'stable' !== ($stabilityName = VersionParser::parseStability($reqVersion))) {
  13611. $name = strtolower($reqName);
  13612. $stability = $stabilities[$stabilityName];
  13613. if ((isset($stabilityFlags[$name]) && $stabilityFlags[$name] > $stability) || ($minimumStability > $stability)) {
  13614. continue;
  13615. }
  13616. $stabilityFlags[$name] = $stability;
  13617. }
  13618. }
  13619. return $stabilityFlags;
  13620. }
  13621. private function extractReferences(array $requires, array $references)
  13622. {
  13623. foreach ($requires as $reqName => $reqVersion) {
  13624. $reqVersion = preg_replace('{^([^,\s@]+) as .+$}', '$1', $reqVersion);
  13625. if (preg_match('{^[^,\s@]+?#([a-f0-9]+)$}', $reqVersion, $match) && 'dev' === ($stabilityName = VersionParser::parseStability($reqVersion))) {
  13626. $name = strtolower($reqName);
  13627. $references[$name] = $match[1];
  13628. }
  13629. }
  13630. return $references;
  13631. }
  13632. }
  13633. <?php
  13634. namespace Composer\Package\Loader;
  13635. use Composer\Package;
  13636. use Composer\Package\BasePackage;
  13637. use Composer\Semver\Constraint\Constraint;
  13638. use Composer\Semver\VersionParser;
  13639. use Composer\Repository\PlatformRepository;
  13640. class ValidatingArrayLoader implements LoaderInterface
  13641. {
  13642. const CHECK_ALL = 1;
  13643. const CHECK_UNBOUND_CONSTRAINTS = 1;
  13644. private $loader;
  13645. private $versionParser;
  13646. private $errors;
  13647. private $warnings;
  13648. private $config;
  13649. private $strictName;
  13650. private $flags;
  13651. public function __construct(LoaderInterface $loader, $strictName = true, VersionParser $parser = null, $flags = 0)
  13652. {
  13653. $this->loader = $loader;
  13654. $this->versionParser = $parser ?: new VersionParser();
  13655. $this->strictName = $strictName;
  13656. $this->flags = $flags;
  13657. }
  13658. public function load(array $config, $class = 'Composer\Package\CompletePackage')
  13659. {
  13660. $this->errors = array();
  13661. $this->warnings = array();
  13662. $this->config = $config;
  13663. if ($this->strictName) {
  13664. $this->validateRegex('name', '[A-Za-z0-9][A-Za-z0-9_.-]*/[A-Za-z0-9][A-Za-z0-9_.-]*', true);
  13665. } else {
  13666. $this->validateString('name', true);
  13667. }
  13668. if (!empty($this->config['version'])) {
  13669. try {
  13670. $this->versionParser->normalize($this->config['version']);
  13671. } catch (\Exception $e) {
  13672. $this->errors[] = 'version : invalid value ('.$this->config['version'].'): '.$e->getMessage();
  13673. unset($this->config['version']);
  13674. }
  13675. }
  13676. $this->validateRegex('type', '[A-Za-z0-9-]+');
  13677. $this->validateString('target-dir');
  13678. $this->validateArray('extra');
  13679. $this->validateFlatArray('bin');
  13680. $this->validateArray('scripts');
  13681. $this->validateString('description');
  13682. $this->validateUrl('homepage');
  13683. $this->validateFlatArray('keywords', '[\p{N}\p{L} ._-]+');
  13684. if (isset($this->config['license'])) {
  13685. if (is_string($this->config['license'])) {
  13686. $this->validateRegex('license', '[A-Za-z0-9+. ()-]+');
  13687. } else {
  13688. $this->validateFlatArray('license', '[A-Za-z0-9+. ()-]+');
  13689. }
  13690. }
  13691. $this->validateString('time');
  13692. if (!empty($this->config['time'])) {
  13693. try {
  13694. $date = new \DateTime($this->config['time'], new \DateTimeZone('UTC'));
  13695. } catch (\Exception $e) {
  13696. $this->errors[] = 'time : invalid value ('.$this->config['time'].'): '.$e->getMessage();
  13697. unset($this->config['time']);
  13698. }
  13699. }
  13700. if ($this->validateArray('authors') && !empty($this->config['authors'])) {
  13701. foreach ($this->config['authors'] as $key => $author) {
  13702. if (!is_array($author)) {
  13703. $this->errors[] = 'authors.'.$key.' : should be an array, '.gettype($author).' given';
  13704. unset($this->config['authors'][$key]);
  13705. continue;
  13706. }
  13707. foreach (array('homepage', 'email', 'name', 'role') as $authorData) {
  13708. if (isset($author[$authorData]) && !is_string($author[$authorData])) {
  13709. $this->errors[] = 'authors.'.$key.'.'.$authorData.' : invalid value, must be a string';
  13710. unset($this->config['authors'][$key][$authorData]);
  13711. }
  13712. }
  13713. if (isset($author['homepage']) && !$this->filterUrl($author['homepage'])) {
  13714. $this->warnings[] = 'authors.'.$key.'.homepage : invalid value ('.$author['homepage'].'), must be an http/https URL';
  13715. unset($this->config['authors'][$key]['homepage']);
  13716. }
  13717. if (isset($author['email']) && !filter_var($author['email'], FILTER_VALIDATE_EMAIL)) {
  13718. $this->warnings[] = 'authors.'.$key.'.email : invalid value ('.$author['email'].'), must be a valid email address';
  13719. unset($this->config['authors'][$key]['email']);
  13720. }
  13721. if (empty($this->config['authors'][$key])) {
  13722. unset($this->config['authors'][$key]);
  13723. }
  13724. }
  13725. if (empty($this->config['authors'])) {
  13726. unset($this->config['authors']);
  13727. }
  13728. }
  13729. if ($this->validateArray('support') && !empty($this->config['support'])) {
  13730. foreach (array('issues', 'forum', 'wiki', 'source', 'email', 'irc', 'docs') as $key) {
  13731. if (isset($this->config['support'][$key]) && !is_string($this->config['support'][$key])) {
  13732. $this->errors[] = 'support.'.$key.' : invalid value, must be a string';
  13733. unset($this->config['support'][$key]);
  13734. }
  13735. }
  13736. if (isset($this->config['support']['email']) && !filter_var($this->config['support']['email'], FILTER_VALIDATE_EMAIL)) {
  13737. $this->warnings[] = 'support.email : invalid value ('.$this->config['support']['email'].'), must be a valid email address';
  13738. unset($this->config['support']['email']);
  13739. }
  13740. if (isset($this->config['support']['irc']) && !$this->filterUrl($this->config['support']['irc'], array('irc'))) {
  13741. $this->warnings[] = 'support.irc : invalid value ('.$this->config['support']['irc'].'), must be a irc://<server>/<channel> URL';
  13742. unset($this->config['support']['irc']);
  13743. }
  13744. foreach (array('issues', 'forum', 'wiki', 'source', 'docs') as $key) {
  13745. if (isset($this->config['support'][$key]) && !$this->filterUrl($this->config['support'][$key])) {
  13746. $this->warnings[] = 'support.'.$key.' : invalid value ('.$this->config['support'][$key].'), must be an http/https URL';
  13747. unset($this->config['support'][$key]);
  13748. }
  13749. }
  13750. if (empty($this->config['support'])) {
  13751. unset($this->config['support']);
  13752. }
  13753. }
  13754. $unboundConstraint = new Constraint('=', $this->versionParser->normalize('dev-master'));
  13755. foreach (array_keys(BasePackage::$supportedLinkTypes) as $linkType) {
  13756. if ($this->validateArray($linkType) && isset($this->config[$linkType])) {
  13757. foreach ($this->config[$linkType] as $package => $constraint) {
  13758. if (!preg_match('{^[A-Za-z0-9_./-]+$}', $package)) {
  13759. $this->warnings[] = $linkType.'.'.$package.' : invalid key, package names must be strings containing only [A-Za-z0-9_./-]';
  13760. }
  13761. if (!is_string($constraint)) {
  13762. $this->errors[] = $linkType.'.'.$package.' : invalid value, must be a string containing a version constraint';
  13763. unset($this->config[$linkType][$package]);
  13764. } elseif ('self.version' !== $constraint) {
  13765. try {
  13766. $linkConstraint = $this->versionParser->parseConstraints($constraint);
  13767. } catch (\Exception $e) {
  13768. $this->errors[] = $linkType.'.'.$package.' : invalid version constraint ('.$e->getMessage().')';
  13769. unset($this->config[$linkType][$package]);
  13770. continue;
  13771. }
  13772. if (
  13773. ($this->flags & self::CHECK_UNBOUND_CONSTRAINTS)
  13774. && 'require' === $linkType
  13775. && $linkConstraint->matches($unboundConstraint)
  13776. && !preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $package)
  13777. ) {
  13778. $this->warnings[] = $linkType.'.'.$package.' : unbound version constraints ('.$constraint.') should be avoided';
  13779. }
  13780. }
  13781. }
  13782. }
  13783. }
  13784. if ($this->validateArray('suggest') && !empty($this->config['suggest'])) {
  13785. foreach ($this->config['suggest'] as $package => $description) {
  13786. if (!is_string($description)) {
  13787. $this->errors[] = 'suggest.'.$package.' : invalid value, must be a string describing why the package is suggested';
  13788. unset($this->config['suggest'][$package]);
  13789. }
  13790. }
  13791. }
  13792. if ($this->validateString('minimum-stability') && !empty($this->config['minimum-stability'])) {
  13793. if (!isset(BasePackage::$stabilities[$this->config['minimum-stability']])) {
  13794. $this->errors[] = 'minimum-stability : invalid value ('.$this->config['minimum-stability'].'), must be one of '.implode(', ', array_keys(BasePackage::$stabilities));
  13795. unset($this->config['minimum-stability']);
  13796. }
  13797. }
  13798. if ($this->validateArray('autoload') && !empty($this->config['autoload'])) {
  13799. $types = array('psr-0', 'psr-4', 'classmap', 'files');
  13800. foreach ($this->config['autoload'] as $type => $typeConfig) {
  13801. if (!in_array($type, $types)) {
  13802. $this->errors[] = 'autoload : invalid value ('.$type.'), must be one of '.implode(', ', $types);
  13803. unset($this->config['autoload'][$type]);
  13804. }
  13805. if ($type === 'psr-4') {
  13806. foreach ($typeConfig as $namespace => $dirs) {
  13807. if ($namespace !== '' && '\\' !== substr($namespace, -1)) {
  13808. $this->errors[] = 'autoload.psr-4 : invalid value ('.$namespace.'), namespaces must end with a namespace separator, should be '.$namespace.'\\';
  13809. }
  13810. }
  13811. }
  13812. }
  13813. }
  13814. if (!empty($this->config['autoload']['psr-4']) && !empty($this->config['target-dir'])) {
  13815. $this->errors[] = 'target-dir : this can not be used together with the autoload.psr-4 setting, remove target-dir to upgrade to psr-4';
  13816. unset($this->config['autoload']['psr-4']);
  13817. }
  13818. $this->validateFlatArray('include-path');
  13819. $this->validateArray('transport-options');
  13820. if (isset($this->config['extra']['branch-alias'])) {
  13821. if (!is_array($this->config['extra']['branch-alias'])) {
  13822. $this->errors[] = 'extra.branch-alias : must be an array of versions => aliases';
  13823. } else {
  13824. foreach ($this->config['extra']['branch-alias'] as $sourceBranch => $targetBranch) {
  13825. if ('-dev' !== substr($targetBranch, -4)) {
  13826. $this->warnings[] = 'extra.branch-alias.'.$sourceBranch.' : the target branch ('.$targetBranch.') must end in -dev';
  13827. unset($this->config['extra']['branch-alias'][$sourceBranch]);
  13828. continue;
  13829. }
  13830. $validatedTargetBranch = $this->versionParser->normalizeBranch(substr($targetBranch, 0, -4));
  13831. if ('-dev' !== substr($validatedTargetBranch, -4)) {
  13832. $this->warnings[] = 'extra.branch-alias.'.$sourceBranch.' : the target branch ('.$targetBranch.') must be a parseable number like 2.0-dev';
  13833. unset($this->config['extra']['branch-alias'][$sourceBranch]);
  13834. continue;
  13835. }
  13836. if (($sourcePrefix = $this->versionParser->parseNumericAliasPrefix($sourceBranch))
  13837. && ($targetPrefix = $this->versionParser->parseNumericAliasPrefix($targetBranch))
  13838. && (stripos($targetPrefix, $sourcePrefix) !== 0)
  13839. ) {
  13840. $this->warnings[] = 'extra.branch-alias.'.$sourceBranch.' : the target branch ('.$targetBranch.') is not a valid numeric alias for this version';
  13841. unset($this->config['extra']['branch-alias'][$sourceBranch]);
  13842. }
  13843. }
  13844. }
  13845. }
  13846. if ($this->errors) {
  13847. throw new InvalidPackageException($this->errors, $this->warnings, $config);
  13848. }
  13849. $package = $this->loader->load($this->config, $class);
  13850. $this->config = null;
  13851. return $package;
  13852. }
  13853. public function getWarnings()
  13854. {
  13855. return $this->warnings;
  13856. }
  13857. public function getErrors()
  13858. {
  13859. return $this->errors;
  13860. }
  13861. private function validateRegex($property, $regex, $mandatory = false)
  13862. {
  13863. if (!$this->validateString($property, $mandatory)) {
  13864. return false;
  13865. }
  13866. if (!preg_match('{^'.$regex.'$}u', $this->config[$property])) {
  13867. $message = $property.' : invalid value ('.$this->config[$property].'), must match '.$regex;
  13868. if ($mandatory) {
  13869. $this->errors[] = $message;
  13870. } else {
  13871. $this->warnings[] = $message;
  13872. }
  13873. unset($this->config[$property]);
  13874. return false;
  13875. }
  13876. return true;
  13877. }
  13878. private function validateString($property, $mandatory = false)
  13879. {
  13880. if (isset($this->config[$property]) && !is_string($this->config[$property])) {
  13881. $this->errors[] = $property.' : should be a string, '.gettype($this->config[$property]).' given';
  13882. unset($this->config[$property]);
  13883. return false;
  13884. }
  13885. if (!isset($this->config[$property]) || trim($this->config[$property]) === '') {
  13886. if ($mandatory) {
  13887. $this->errors[] = $property.' : must be present';
  13888. }
  13889. unset($this->config[$property]);
  13890. return false;
  13891. }
  13892. return true;
  13893. }
  13894. private function validateArray($property, $mandatory = false)
  13895. {
  13896. if (isset($this->config[$property]) && !is_array($this->config[$property])) {
  13897. $this->errors[] = $property.' : should be an array, '.gettype($this->config[$property]).' given';
  13898. unset($this->config[$property]);
  13899. return false;
  13900. }
  13901. if (!isset($this->config[$property]) || !count($this->config[$property])) {
  13902. if ($mandatory) {
  13903. $this->errors[] = $property.' : must be present and contain at least one element';
  13904. }
  13905. unset($this->config[$property]);
  13906. return false;
  13907. }
  13908. return true;
  13909. }
  13910. private function validateFlatArray($property, $regex = null, $mandatory = false)
  13911. {
  13912. if (!$this->validateArray($property, $mandatory)) {
  13913. return false;
  13914. }
  13915. $pass = true;
  13916. foreach ($this->config[$property] as $key => $value) {
  13917. if (!is_string($value) && !is_numeric($value)) {
  13918. $this->errors[] = $property.'.'.$key.' : must be a string or int, '.gettype($value).' given';
  13919. unset($this->config[$property][$key]);
  13920. $pass = false;
  13921. continue;
  13922. }
  13923. if ($regex && !preg_match('{^'.$regex.'$}u', $value)) {
  13924. $this->warnings[] = $property.'.'.$key.' : invalid value ('.$value.'), must match '.$regex;
  13925. unset($this->config[$property][$key]);
  13926. $pass = false;
  13927. }
  13928. }
  13929. return $pass;
  13930. }
  13931. private function validateUrl($property, $mandatory = false)
  13932. {
  13933. if (!$this->validateString($property, $mandatory)) {
  13934. return false;
  13935. }
  13936. if (!$this->filterUrl($this->config[$property])) {
  13937. $this->warnings[] = $property.' : invalid value ('.$this->config[$property].'), must be an http/https URL';
  13938. unset($this->config[$property]);
  13939. return false;
  13940. }
  13941. return true;
  13942. }
  13943. private function filterUrl($value, array $schemes = array('http', 'https'))
  13944. {
  13945. if ($value === '') {
  13946. return true;
  13947. }
  13948. $bits = parse_url($value);
  13949. if (empty($bits['scheme']) || empty($bits['host'])) {
  13950. return false;
  13951. }
  13952. if (!in_array($bits['scheme'], $schemes, true)) {
  13953. return false;
  13954. }
  13955. return true;
  13956. }
  13957. }
  13958. <?php
  13959. namespace Composer\Package;
  13960. use Composer\Json\JsonFile;
  13961. use Composer\Installer\InstallationManager;
  13962. use Composer\Repository\RepositoryManager;
  13963. use Composer\Util\ProcessExecutor;
  13964. use Composer\Repository\ArrayRepository;
  13965. use Composer\Package\Dumper\ArrayDumper;
  13966. use Composer\Package\Loader\ArrayLoader;
  13967. use Composer\Util\Git as GitUtil;
  13968. use Composer\IO\IOInterface;
  13969. use Seld\JsonLint\ParsingException;
  13970. class Locker
  13971. {
  13972. private $lockFile;
  13973. private $repositoryManager;
  13974. private $installationManager;
  13975. private $hash;
  13976. private $contentHash;
  13977. private $loader;
  13978. private $dumper;
  13979. private $process;
  13980. private $lockDataCache;
  13981. public function __construct(IOInterface $io, JsonFile $lockFile, RepositoryManager $repositoryManager, InstallationManager $installationManager, $composerFileContents)
  13982. {
  13983. $this->lockFile = $lockFile;
  13984. $this->repositoryManager = $repositoryManager;
  13985. $this->installationManager = $installationManager;
  13986. $this->hash = md5($composerFileContents);
  13987. $this->contentHash = $this->getContentHash($composerFileContents);
  13988. $this->loader = new ArrayLoader(null, true);
  13989. $this->dumper = new ArrayDumper();
  13990. $this->process = new ProcessExecutor($io);
  13991. }
  13992. public function isLocked()
  13993. {
  13994. if (!$this->lockFile->exists()) {
  13995. return false;
  13996. }
  13997. $data = $this->getLockData();
  13998. return isset($data['packages']);
  13999. }
  14000. public function isFresh()
  14001. {
  14002. $lock = $this->lockFile->read();
  14003. if (!empty($lock['content-hash'])) {
  14004. return $this->contentHash === $lock['content-hash'];
  14005. }
  14006. return $this->hash === $lock['hash'];
  14007. }
  14008. public function getLockedRepository($withDevReqs = false)
  14009. {
  14010. $lockData = $this->getLockData();
  14011. $packages = new ArrayRepository();
  14012. $lockedPackages = $lockData['packages'];
  14013. if ($withDevReqs) {
  14014. if (isset($lockData['packages-dev'])) {
  14015. $lockedPackages = array_merge($lockedPackages, $lockData['packages-dev']);
  14016. } else {
  14017. throw new \RuntimeException('The lock file does not contain require-dev information, run install with the --no-dev option or run update to install those packages.');
  14018. }
  14019. }
  14020. if (empty($lockedPackages)) {
  14021. return $packages;
  14022. }
  14023. if (isset($lockedPackages[0]['name'])) {
  14024. foreach ($lockedPackages as $info) {
  14025. $packages->addPackage($this->loader->load($info));
  14026. }
  14027. return $packages;
  14028. }
  14029. throw new \RuntimeException('Your composer.lock was created before 2012-09-15, and is not supported anymore. Run "composer update" to generate a new one.');
  14030. }
  14031. public function getPlatformRequirements($withDevReqs = false)
  14032. {
  14033. $lockData = $this->getLockData();
  14034. $requirements = array();
  14035. if (!empty($lockData['platform'])) {
  14036. $requirements = $this->loader->parseLinks(
  14037. '__ROOT__',
  14038. '1.0.0',
  14039. 'requires',
  14040. isset($lockData['platform']) ? $lockData['platform'] : array()
  14041. );
  14042. }
  14043. if ($withDevReqs && !empty($lockData['platform-dev'])) {
  14044. $devRequirements = $this->loader->parseLinks(
  14045. '__ROOT__',
  14046. '1.0.0',
  14047. 'requires',
  14048. isset($lockData['platform-dev']) ? $lockData['platform-dev'] : array()
  14049. );
  14050. $requirements = array_merge($requirements, $devRequirements);
  14051. }
  14052. return $requirements;
  14053. }
  14054. public function getMinimumStability()
  14055. {
  14056. $lockData = $this->getLockData();
  14057. return isset($lockData['minimum-stability']) ? $lockData['minimum-stability'] : 'stable';
  14058. }
  14059. public function getStabilityFlags()
  14060. {
  14061. $lockData = $this->getLockData();
  14062. return isset($lockData['stability-flags']) ? $lockData['stability-flags'] : array();
  14063. }
  14064. public function getPreferStable()
  14065. {
  14066. $lockData = $this->getLockData();
  14067. return isset($lockData['prefer-stable']) ? $lockData['prefer-stable'] : null;
  14068. }
  14069. public function getPreferLowest()
  14070. {
  14071. $lockData = $this->getLockData();
  14072. return isset($lockData['prefer-lowest']) ? $lockData['prefer-lowest'] : null;
  14073. }
  14074. public function getPlatformOverrides()
  14075. {
  14076. $lockData = $this->getLockData();
  14077. return isset($lockData['platform-overrides']) ? $lockData['platform-overrides'] : array();
  14078. }
  14079. public function getAliases()
  14080. {
  14081. $lockData = $this->getLockData();
  14082. return isset($lockData['aliases']) ? $lockData['aliases'] : array();
  14083. }
  14084. public function getLockData()
  14085. {
  14086. if (null !== $this->lockDataCache) {
  14087. return $this->lockDataCache;
  14088. }
  14089. if (!$this->lockFile->exists()) {
  14090. throw new \LogicException('No lockfile found. Unable to read locked packages');
  14091. }
  14092. return $this->lockDataCache = $this->lockFile->read();
  14093. }
  14094. public function setLockData(array $packages, $devPackages, array $platformReqs, $platformDevReqs, array $aliases, $minimumStability, array $stabilityFlags, $preferStable, $preferLowest, array $platformOverrides)
  14095. {
  14096. $lock = array(
  14097. '_readme' => array('This file locks the dependencies of your project to a known state',
  14098. 'Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file',
  14099. 'This file is @gener'.'ated automatically', ),
  14100. 'hash' => $this->hash,
  14101. 'content-hash' => $this->contentHash,
  14102. 'packages' => null,
  14103. 'packages-dev' => null,
  14104. 'aliases' => array(),
  14105. 'minimum-stability' => $minimumStability,
  14106. 'stability-flags' => $stabilityFlags,
  14107. 'prefer-stable' => $preferStable,
  14108. 'prefer-lowest' => $preferLowest,
  14109. );
  14110. foreach ($aliases as $package => $versions) {
  14111. foreach ($versions as $version => $alias) {
  14112. $lock['aliases'][] = array(
  14113. 'alias' => $alias['alias'],
  14114. 'alias_normalized' => $alias['alias_normalized'],
  14115. 'version' => $version,
  14116. 'package' => $package,
  14117. );
  14118. }
  14119. }
  14120. $lock['packages'] = $this->lockPackages($packages);
  14121. if (null !== $devPackages) {
  14122. $lock['packages-dev'] = $this->lockPackages($devPackages);
  14123. }
  14124. $lock['platform'] = $platformReqs;
  14125. $lock['platform-dev'] = $platformDevReqs;
  14126. if ($platformOverrides) {
  14127. $lock['platform-overrides'] = $platformOverrides;
  14128. }
  14129. if (empty($lock['packages']) && empty($lock['packages-dev']) && empty($lock['platform']) && empty($lock['platform-dev'])) {
  14130. if ($this->lockFile->exists()) {
  14131. unlink($this->lockFile->getPath());
  14132. }
  14133. return false;
  14134. }
  14135. try {
  14136. $isLocked = $this->isLocked();
  14137. } catch (ParsingException $e) {
  14138. $isLocked = false;
  14139. }
  14140. if (!$isLocked || $lock !== $this->getLockData()) {
  14141. $this->lockFile->write($lock);
  14142. $this->lockDataCache = null;
  14143. return true;
  14144. }
  14145. return false;
  14146. }
  14147. private function lockPackages(array $packages)
  14148. {
  14149. $locked = array();
  14150. foreach ($packages as $package) {
  14151. if ($package instanceof AliasPackage) {
  14152. continue;
  14153. }
  14154. $name = $package->getPrettyName();
  14155. $version = $package->getPrettyVersion();
  14156. if (!$name || !$version) {
  14157. throw new \LogicException(sprintf(
  14158. 'Package "%s" has no version or name and can not be locked', $package
  14159. ));
  14160. }
  14161. $spec = $this->dumper->dump($package);
  14162. unset($spec['version_normalized']);
  14163. $time = isset($spec['time']) ? $spec['time'] : null;
  14164. unset($spec['time']);
  14165. if ($package->isDev() && $package->getInstallationSource() === 'source') {
  14166. $time = $this->getPackageTime($package) ?: $time;
  14167. }
  14168. if (null !== $time) {
  14169. $spec['time'] = $time;
  14170. }
  14171. unset($spec['installation-source']);
  14172. $locked[] = $spec;
  14173. }
  14174. usort($locked, function ($a, $b) {
  14175. $comparison = strcmp($a['name'], $b['name']);
  14176. if (0 !== $comparison) {
  14177. return $comparison;
  14178. }
  14179. return strcmp($a['version'], $b['version']);
  14180. });
  14181. return $locked;
  14182. }
  14183. private function getPackageTime(PackageInterface $package)
  14184. {
  14185. if (!function_exists('proc_open')) {
  14186. return null;
  14187. }
  14188. $path = realpath($this->installationManager->getInstallPath($package));
  14189. $sourceType = $package->getSourceType();
  14190. $datetime = null;
  14191. if ($path && in_array($sourceType, array('git', 'hg'))) {
  14192. $sourceRef = $package->getSourceReference() ?: $package->getDistReference();
  14193. switch ($sourceType) {
  14194. case 'git':
  14195. GitUtil::cleanEnv();
  14196. if (0 === $this->process->execute('git log -n1 --pretty=%ct '.ProcessExecutor::escape($sourceRef), $output, $path) && preg_match('{^\s*\d+\s*$}', $output)) {
  14197. $datetime = new \DateTime('@'.trim($output), new \DateTimeZone('UTC'));
  14198. }
  14199. break;
  14200. case 'hg':
  14201. if (0 === $this->process->execute('hg log --template "{date|hgdate}" -r '.ProcessExecutor::escape($sourceRef), $output, $path) && preg_match('{^\s*(\d+)\s*}', $output, $match)) {
  14202. $datetime = new \DateTime('@'.$match[1], new \DateTimeZone('UTC'));
  14203. }
  14204. break;
  14205. }
  14206. }
  14207. return $datetime ? $datetime->format('Y-m-d H:i:s') : null;
  14208. }
  14209. private function getContentHash($composerFileContents)
  14210. {
  14211. $content = json_decode($composerFileContents, true);
  14212. $relevantKeys = array(
  14213. 'name',
  14214. 'version',
  14215. 'require',
  14216. 'require-dev',
  14217. 'conflict',
  14218. 'replace',
  14219. 'provide',
  14220. 'minimum-stability',
  14221. 'prefer-stable',
  14222. 'repositories',
  14223. 'extra',
  14224. );
  14225. $relevantContent = array();
  14226. foreach (array_intersect($relevantKeys, array_keys($content)) as $key) {
  14227. $relevantContent[$key] = $content[$key];
  14228. }
  14229. if (isset($content['config']['platform'])) {
  14230. $relevantContent['config']['platform'] = $content['config']['platform'];
  14231. }
  14232. ksort($relevantContent);
  14233. return md5(json_encode($relevantContent));
  14234. }
  14235. }
  14236. <?php
  14237. namespace Composer\Package;
  14238. use Composer\Semver\VersionParser;
  14239. use Composer\Util\ComposerMirror;
  14240. class Package extends BasePackage
  14241. {
  14242. protected $type;
  14243. protected $targetDir;
  14244. protected $installationSource;
  14245. protected $sourceType;
  14246. protected $sourceUrl;
  14247. protected $sourceReference;
  14248. protected $sourceMirrors;
  14249. protected $distType;
  14250. protected $distUrl;
  14251. protected $distReference;
  14252. protected $distSha1Checksum;
  14253. protected $distMirrors;
  14254. protected $version;
  14255. protected $prettyVersion;
  14256. protected $releaseDate;
  14257. protected $extra = array();
  14258. protected $binaries = array();
  14259. protected $dev;
  14260. protected $stability;
  14261. protected $notificationUrl;
  14262. protected $requires = array();
  14263. protected $conflicts = array();
  14264. protected $provides = array();
  14265. protected $replaces = array();
  14266. protected $devRequires = array();
  14267. protected $suggests = array();
  14268. protected $autoload = array();
  14269. protected $devAutoload = array();
  14270. protected $includePaths = array();
  14271. protected $archiveExcludes = array();
  14272. public function __construct($name, $version, $prettyVersion)
  14273. {
  14274. parent::__construct($name);
  14275. $this->version = $version;
  14276. $this->prettyVersion = $prettyVersion;
  14277. $this->stability = VersionParser::parseStability($version);
  14278. $this->dev = $this->stability === 'dev';
  14279. }
  14280. public function isDev()
  14281. {
  14282. return $this->dev;
  14283. }
  14284. public function setType($type)
  14285. {
  14286. $this->type = $type;
  14287. }
  14288. public function getType()
  14289. {
  14290. return $this->type ?: 'library';
  14291. }
  14292. public function getStability()
  14293. {
  14294. return $this->stability;
  14295. }
  14296. public function setTargetDir($targetDir)
  14297. {
  14298. $this->targetDir = $targetDir;
  14299. }
  14300. public function getTargetDir()
  14301. {
  14302. if (null === $this->targetDir) {
  14303. return;
  14304. }
  14305. return ltrim(preg_replace('{ (?:^|[\\\\/]+) \.\.? (?:[\\\\/]+|$) (?:\.\.? (?:[\\\\/]+|$) )*}x', '/', $this->targetDir), '/');
  14306. }
  14307. public function setExtra(array $extra)
  14308. {
  14309. $this->extra = $extra;
  14310. }
  14311. public function getExtra()
  14312. {
  14313. return $this->extra;
  14314. }
  14315. public function setBinaries(array $binaries)
  14316. {
  14317. $this->binaries = $binaries;
  14318. }
  14319. public function getBinaries()
  14320. {
  14321. return $this->binaries;
  14322. }
  14323. public function setInstallationSource($type)
  14324. {
  14325. $this->installationSource = $type;
  14326. }
  14327. public function getInstallationSource()
  14328. {
  14329. return $this->installationSource;
  14330. }
  14331. public function setSourceType($type)
  14332. {
  14333. $this->sourceType = $type;
  14334. }
  14335. public function getSourceType()
  14336. {
  14337. return $this->sourceType;
  14338. }
  14339. public function setSourceUrl($url)
  14340. {
  14341. $this->sourceUrl = $url;
  14342. }
  14343. public function getSourceUrl()
  14344. {
  14345. return $this->sourceUrl;
  14346. }
  14347. public function setSourceReference($reference)
  14348. {
  14349. $this->sourceReference = $reference;
  14350. }
  14351. public function getSourceReference()
  14352. {
  14353. return $this->sourceReference;
  14354. }
  14355. public function setSourceMirrors($mirrors)
  14356. {
  14357. $this->sourceMirrors = $mirrors;
  14358. }
  14359. public function getSourceMirrors()
  14360. {
  14361. return $this->sourceMirrors;
  14362. }
  14363. public function getSourceUrls()
  14364. {
  14365. return $this->getUrls($this->sourceUrl, $this->sourceMirrors, $this->sourceReference, $this->sourceType, 'source');
  14366. }
  14367. public function setDistType($type)
  14368. {
  14369. $this->distType = $type;
  14370. }
  14371. public function getDistType()
  14372. {
  14373. return $this->distType;
  14374. }
  14375. public function setDistUrl($url)
  14376. {
  14377. $this->distUrl = $url;
  14378. }
  14379. public function getDistUrl()
  14380. {
  14381. return $this->distUrl;
  14382. }
  14383. public function setDistReference($reference)
  14384. {
  14385. $this->distReference = $reference;
  14386. }
  14387. public function getDistReference()
  14388. {
  14389. return $this->distReference;
  14390. }
  14391. public function setDistSha1Checksum($sha1checksum)
  14392. {
  14393. $this->distSha1Checksum = $sha1checksum;
  14394. }
  14395. public function getDistSha1Checksum()
  14396. {
  14397. return $this->distSha1Checksum;
  14398. }
  14399. public function setDistMirrors($mirrors)
  14400. {
  14401. $this->distMirrors = $mirrors;
  14402. }
  14403. public function getDistMirrors()
  14404. {
  14405. return $this->distMirrors;
  14406. }
  14407. public function getDistUrls()
  14408. {
  14409. return $this->getUrls($this->distUrl, $this->distMirrors, $this->distReference, $this->distType, 'dist');
  14410. }
  14411. public function getVersion()
  14412. {
  14413. return $this->version;
  14414. }
  14415. public function getPrettyVersion()
  14416. {
  14417. return $this->prettyVersion;
  14418. }
  14419. public function setReleaseDate(\DateTime $releaseDate)
  14420. {
  14421. $this->releaseDate = $releaseDate;
  14422. }
  14423. public function getReleaseDate()
  14424. {
  14425. return $this->releaseDate;
  14426. }
  14427. public function setRequires(array $requires)
  14428. {
  14429. $this->requires = $requires;
  14430. }
  14431. public function getRequires()
  14432. {
  14433. return $this->requires;
  14434. }
  14435. public function setConflicts(array $conflicts)
  14436. {
  14437. $this->conflicts = $conflicts;
  14438. }
  14439. public function getConflicts()
  14440. {
  14441. return $this->conflicts;
  14442. }
  14443. public function setProvides(array $provides)
  14444. {
  14445. $this->provides = $provides;
  14446. }
  14447. public function getProvides()
  14448. {
  14449. return $this->provides;
  14450. }
  14451. public function setReplaces(array $replaces)
  14452. {
  14453. $this->replaces = $replaces;
  14454. }
  14455. public function getReplaces()
  14456. {
  14457. return $this->replaces;
  14458. }
  14459. public function setDevRequires(array $devRequires)
  14460. {
  14461. $this->devRequires = $devRequires;
  14462. }
  14463. public function getDevRequires()
  14464. {
  14465. return $this->devRequires;
  14466. }
  14467. public function setSuggests(array $suggests)
  14468. {
  14469. $this->suggests = $suggests;
  14470. }
  14471. public function getSuggests()
  14472. {
  14473. return $this->suggests;
  14474. }
  14475. public function setAutoload(array $autoload)
  14476. {
  14477. $this->autoload = $autoload;
  14478. }
  14479. public function getAutoload()
  14480. {
  14481. return $this->autoload;
  14482. }
  14483. public function setDevAutoload(array $devAutoload)
  14484. {
  14485. $this->devAutoload = $devAutoload;
  14486. }
  14487. public function getDevAutoload()
  14488. {
  14489. return $this->devAutoload;
  14490. }
  14491. public function setIncludePaths(array $includePaths)
  14492. {
  14493. $this->includePaths = $includePaths;
  14494. }
  14495. public function getIncludePaths()
  14496. {
  14497. return $this->includePaths;
  14498. }
  14499. public function setNotificationUrl($notificationUrl)
  14500. {
  14501. $this->notificationUrl = $notificationUrl;
  14502. }
  14503. public function getNotificationUrl()
  14504. {
  14505. return $this->notificationUrl;
  14506. }
  14507. public function setArchiveExcludes(array $excludes)
  14508. {
  14509. $this->archiveExcludes = $excludes;
  14510. }
  14511. public function getArchiveExcludes()
  14512. {
  14513. return $this->archiveExcludes;
  14514. }
  14515. public function replaceVersion($version, $prettyVersion)
  14516. {
  14517. $this->version = $version;
  14518. $this->prettyVersion = $prettyVersion;
  14519. $this->stability = VersionParser::parseStability($version);
  14520. $this->dev = $this->stability === 'dev';
  14521. }
  14522. protected function getUrls($url, $mirrors, $ref, $type, $urlType)
  14523. {
  14524. if (!$url) {
  14525. return array();
  14526. }
  14527. $urls = array($url);
  14528. if ($mirrors) {
  14529. foreach ($mirrors as $mirror) {
  14530. if ($urlType === 'dist') {
  14531. $mirrorUrl = ComposerMirror::processUrl($mirror['url'], $this->name, $this->version, $ref, $type);
  14532. } elseif ($urlType === 'source' && $type === 'git') {
  14533. $mirrorUrl = ComposerMirror::processGitUrl($mirror['url'], $this->name, $url, $type);
  14534. } elseif ($urlType === 'source' && $type === 'hg') {
  14535. $mirrorUrl = ComposerMirror::processHgUrl($mirror['url'], $this->name, $url, $type);
  14536. }
  14537. if (!in_array($mirrorUrl, $urls)) {
  14538. $func = $mirror['preferred'] ? 'array_unshift' : 'array_push';
  14539. $func($urls, $mirrorUrl);
  14540. }
  14541. }
  14542. }
  14543. return $urls;
  14544. }
  14545. }
  14546. <?php
  14547. namespace Composer\Package;
  14548. use Composer\Repository\RepositoryInterface;
  14549. interface PackageInterface
  14550. {
  14551. public function getName();
  14552. public function getPrettyName();
  14553. public function getNames();
  14554. public function setId($id);
  14555. public function getId();
  14556. public function isDev();
  14557. public function getType();
  14558. public function getTargetDir();
  14559. public function getExtra();
  14560. public function setInstallationSource($type);
  14561. public function getInstallationSource();
  14562. public function getSourceType();
  14563. public function getSourceUrl();
  14564. public function getSourceUrls();
  14565. public function getSourceReference();
  14566. public function getSourceMirrors();
  14567. public function getDistType();
  14568. public function getDistUrl();
  14569. public function getDistUrls();
  14570. public function getDistReference();
  14571. public function getDistSha1Checksum();
  14572. public function getDistMirrors();
  14573. public function getVersion();
  14574. public function getPrettyVersion();
  14575. public function getFullPrettyVersion($truncate = true);
  14576. public function getReleaseDate();
  14577. public function getStability();
  14578. public function getRequires();
  14579. public function getConflicts();
  14580. public function getProvides();
  14581. public function getReplaces();
  14582. public function getDevRequires();
  14583. public function getSuggests();
  14584. public function getAutoload();
  14585. public function getDevAutoload();
  14586. public function getIncludePaths();
  14587. public function setRepository(RepositoryInterface $repository);
  14588. public function getRepository();
  14589. public function getBinaries();
  14590. public function getUniqueName();
  14591. public function getNotificationUrl();
  14592. public function __toString();
  14593. public function getPrettyString();
  14594. public function getArchiveExcludes();
  14595. public function getTransportOptions();
  14596. }
  14597. <?php
  14598. namespace Composer\Package;
  14599. class RootAliasPackage extends AliasPackage implements RootPackageInterface
  14600. {
  14601. public function __construct(RootPackageInterface $aliasOf, $version, $prettyVersion)
  14602. {
  14603. parent::__construct($aliasOf, $version, $prettyVersion);
  14604. }
  14605. public function getAliases()
  14606. {
  14607. return $this->aliasOf->getAliases();
  14608. }
  14609. public function getMinimumStability()
  14610. {
  14611. return $this->aliasOf->getMinimumStability();
  14612. }
  14613. public function getStabilityFlags()
  14614. {
  14615. return $this->aliasOf->getStabilityFlags();
  14616. }
  14617. public function getReferences()
  14618. {
  14619. return $this->aliasOf->getReferences();
  14620. }
  14621. public function getPreferStable()
  14622. {
  14623. return $this->aliasOf->getPreferStable();
  14624. }
  14625. public function setRequires(array $require)
  14626. {
  14627. $this->requires = $this->replaceSelfVersionDependencies($require, 'requires');
  14628. $this->aliasOf->setRequires($require);
  14629. }
  14630. public function setDevRequires(array $devRequire)
  14631. {
  14632. $this->devRequires = $this->replaceSelfVersionDependencies($devRequire, 'devRequires');
  14633. $this->aliasOf->setDevRequires($devRequire);
  14634. }
  14635. public function __clone()
  14636. {
  14637. parent::__clone();
  14638. $this->aliasOf = clone $this->aliasOf;
  14639. }
  14640. }
  14641. <?php
  14642. namespace Composer\Package;
  14643. class RootPackage extends CompletePackage implements RootPackageInterface
  14644. {
  14645. protected $minimumStability = 'stable';
  14646. protected $preferStable = false;
  14647. protected $stabilityFlags = array();
  14648. protected $references = array();
  14649. protected $aliases = array();
  14650. public function setMinimumStability($minimumStability)
  14651. {
  14652. $this->minimumStability = $minimumStability;
  14653. }
  14654. public function getMinimumStability()
  14655. {
  14656. return $this->minimumStability;
  14657. }
  14658. public function setStabilityFlags(array $stabilityFlags)
  14659. {
  14660. $this->stabilityFlags = $stabilityFlags;
  14661. }
  14662. public function getStabilityFlags()
  14663. {
  14664. return $this->stabilityFlags;
  14665. }
  14666. public function setPreferStable($preferStable)
  14667. {
  14668. $this->preferStable = $preferStable;
  14669. }
  14670. public function getPreferStable()
  14671. {
  14672. return $this->preferStable;
  14673. }
  14674. public function setReferences(array $references)
  14675. {
  14676. $this->references = $references;
  14677. }
  14678. public function getReferences()
  14679. {
  14680. return $this->references;
  14681. }
  14682. public function setAliases(array $aliases)
  14683. {
  14684. $this->aliases = $aliases;
  14685. }
  14686. public function getAliases()
  14687. {
  14688. return $this->aliases;
  14689. }
  14690. }
  14691. <?php
  14692. namespace Composer\Package;
  14693. interface RootPackageInterface extends CompletePackageInterface
  14694. {
  14695. public function getAliases();
  14696. public function getMinimumStability();
  14697. public function getStabilityFlags();
  14698. public function getReferences();
  14699. public function getPreferStable();
  14700. public function setRequires(array $requires);
  14701. public function setDevRequires(array $devRequires);
  14702. }
  14703. <?php
  14704. namespace Composer\Package\Version;
  14705. use Composer\Config;
  14706. use Composer\Repository\Vcs\HgDriver;
  14707. use Composer\IO\NullIO;
  14708. use Composer\Semver\VersionParser as SemverVersionParser;
  14709. use Composer\Util\Git as GitUtil;
  14710. use Composer\Util\ProcessExecutor;
  14711. use Composer\Util\Svn as SvnUtil;
  14712. class VersionGuesser
  14713. {
  14714. private $config;
  14715. private $process;
  14716. private $versionParser;
  14717. public function __construct(Config $config, ProcessExecutor $process, SemverVersionParser $versionParser)
  14718. {
  14719. $this->config = $config;
  14720. $this->process = $process;
  14721. $this->versionParser = $versionParser;
  14722. }
  14723. public function guessVersion(array $packageConfig, $path)
  14724. {
  14725. if (function_exists('proc_open')) {
  14726. $version = $this->guessGitVersion($packageConfig, $path);
  14727. if (null !== $version) {
  14728. return $version;
  14729. }
  14730. $version = $this->guessHgVersion($packageConfig, $path);
  14731. if (null !== $version) {
  14732. return $version;
  14733. }
  14734. return $this->guessSvnVersion($packageConfig, $path);
  14735. }
  14736. }
  14737. private function guessGitVersion(array $packageConfig, $path)
  14738. {
  14739. GitUtil::cleanEnv();
  14740. if (0 === $this->process->execute('git describe --exact-match --tags', $output, $path)) {
  14741. try {
  14742. return $this->versionParser->normalize(trim($output));
  14743. } catch (\Exception $e) {
  14744. }
  14745. }
  14746. if (0 === $this->process->execute('git branch --no-color --no-abbrev -v', $output, $path)) {
  14747. $branches = array();
  14748. $isFeatureBranch = false;
  14749. $version = null;
  14750. foreach ($this->process->splitLines($output) as $branch) {
  14751. if ($branch && preg_match('{^(?:\* ) *(\(no branch\)|\(detached from \S+\)|\S+) *([a-f0-9]+) .*$}', $branch, $match)) {
  14752. if ($match[1] === '(no branch)' || substr($match[1], 0, 10) === '(detached ') {
  14753. $version = 'dev-'.$match[2];
  14754. $isFeatureBranch = true;
  14755. } else {
  14756. $version = $this->versionParser->normalizeBranch($match[1]);
  14757. $isFeatureBranch = 0 === strpos($version, 'dev-');
  14758. if ('9999999-dev' === $version) {
  14759. $version = 'dev-'.$match[1];
  14760. }
  14761. }
  14762. }
  14763. if ($branch && !preg_match('{^ *[^/]+/HEAD }', $branch)) {
  14764. if (preg_match('{^(?:\* )? *(\S+) *([a-f0-9]+) .*$}', $branch, $match)) {
  14765. $branches[] = $match[1];
  14766. }
  14767. }
  14768. }
  14769. if (!$isFeatureBranch) {
  14770. return $version;
  14771. }
  14772. $version = $this->guessFeatureVersion($packageConfig, $version, $branches, 'git rev-list %candidate%..%branch%', $path);
  14773. return $version;
  14774. }
  14775. }
  14776. private function guessHgVersion(array $packageConfig, $path)
  14777. {
  14778. if (0 === $this->process->execute('hg branch', $output, $path)) {
  14779. $branch = trim($output);
  14780. $version = $this->versionParser->normalizeBranch($branch);
  14781. $isFeatureBranch = 0 === strpos($version, 'dev-');
  14782. if ('9999999-dev' === $version) {
  14783. $version = 'dev-'.$branch;
  14784. }
  14785. if (!$isFeatureBranch) {
  14786. return $version;
  14787. }
  14788. $driver = new HgDriver(array('url' => $path), new NullIO(), $this->config, $this->process);
  14789. $branches = array_keys($driver->getBranches());
  14790. $version = $this->guessFeatureVersion($packageConfig, $version, $branches, 'hg log -r "not ancestors(\'%candidate%\') and ancestors(\'%branch%\')" --template "{node}\\n"', $path);
  14791. return $version;
  14792. }
  14793. }
  14794. private function guessFeatureVersion(array $packageConfig, $version, array $branches, $scmCmdline, $path)
  14795. {
  14796. if ((isset($packageConfig['extra']['branch-alias']) && !isset($packageConfig['extra']['branch-alias'][$version]))
  14797. || strpos(json_encode($packageConfig), '"self.version"')
  14798. ) {
  14799. $branch = preg_replace('{^dev-}', '', $version);
  14800. $length = PHP_INT_MAX;
  14801. $nonFeatureBranches = '';
  14802. if (!empty($packageConfig['non-feature-branches'])) {
  14803. $nonFeatureBranches = implode('|', $packageConfig['non-feature-branches']);
  14804. }
  14805. foreach ($branches as $candidate) {
  14806. if ($candidate === $branch && preg_match('{^(' . $nonFeatureBranches . ')$}', $candidate)) {
  14807. return $version;
  14808. }
  14809. if ($candidate === $branch || !preg_match('{^(master|trunk|default|develop|\d+\..+)$}', $candidate, $match)) {
  14810. continue;
  14811. }
  14812. $cmdLine = str_replace(array('%candidate%', '%branch%'), array($candidate, $branch), $scmCmdline);
  14813. if (0 !== $this->process->execute($cmdLine, $output, $path)) {
  14814. continue;
  14815. }
  14816. if (strlen($output) < $length) {
  14817. $length = strlen($output);
  14818. $version = $this->versionParser->normalizeBranch($candidate);
  14819. if ('9999999-dev' === $version) {
  14820. $version = 'dev-'.$match[1];
  14821. }
  14822. }
  14823. }
  14824. }
  14825. return $version;
  14826. }
  14827. private function guessSvnVersion(array $packageConfig, $path)
  14828. {
  14829. SvnUtil::cleanEnv();
  14830. if (0 === $this->process->execute('svn info --xml', $output, $path)) {
  14831. $trunkPath = isset($packageConfig['trunk-path']) ? preg_quote($packageConfig['trunk-path'], '#') : 'trunk';
  14832. $branchesPath = isset($packageConfig['branches-path']) ? preg_quote($packageConfig['branches-path'], '#') : 'branches';
  14833. $tagsPath = isset($packageConfig['tags-path']) ? preg_quote($packageConfig['tags-path'], '#') : 'tags';
  14834. $urlPattern = '#<url>.*/('.$trunkPath.'|('.$branchesPath.'|'. $tagsPath .')/(.*))</url>#';
  14835. if (preg_match($urlPattern, $output, $matches)) {
  14836. if (isset($matches[2]) && ($branchesPath === $matches[2] || $tagsPath === $matches[2])) {
  14837. $version = $this->versionParser->normalizeBranch($matches[3]);
  14838. if ('9999999-dev' === $version) {
  14839. $version = 'dev-'.$matches[3];
  14840. }
  14841. return $version;
  14842. }
  14843. return $this->versionParser->normalize(trim($matches[1]));
  14844. }
  14845. }
  14846. }
  14847. }
  14848. <?php
  14849. namespace Composer\Package\Version;
  14850. use Composer\Semver\VersionParser as SemverVersionParser;
  14851. class VersionParser extends SemverVersionParser
  14852. {
  14853. public function parseNameVersionPairs(array $pairs)
  14854. {
  14855. $pairs = array_values($pairs);
  14856. $result = array();
  14857. for ($i = 0, $count = count($pairs); $i < $count; $i++) {
  14858. $pair = preg_replace('{^([^=: ]+)[=: ](.*)$}', '$1 $2', trim($pairs[$i]));
  14859. if (false === strpos($pair, ' ') && isset($pairs[$i + 1]) && false === strpos($pairs[$i + 1], '/')) {
  14860. $pair .= ' '.$pairs[$i + 1];
  14861. $i++;
  14862. }
  14863. if (strpos($pair, ' ')) {
  14864. list($name, $version) = explode(" ", $pair, 2);
  14865. $result[] = array('name' => $name, 'version' => $version);
  14866. } else {
  14867. $result[] = array('name' => $pair);
  14868. }
  14869. }
  14870. return $result;
  14871. }
  14872. }
  14873. <?php
  14874. namespace Composer\Package\Version;
  14875. use Composer\DependencyResolver\Pool;
  14876. use Composer\Package\PackageInterface;
  14877. use Composer\Package\Loader\ArrayLoader;
  14878. use Composer\Package\Dumper\ArrayDumper;
  14879. use Composer\Semver\VersionParser as SemverVersionParser;
  14880. class VersionSelector
  14881. {
  14882. private $pool;
  14883. private $parser;
  14884. public function __construct(Pool $pool)
  14885. {
  14886. $this->pool = $pool;
  14887. }
  14888. public function findBestCandidate($packageName, $targetPackageVersion = null)
  14889. {
  14890. $constraint = $targetPackageVersion ? $this->getParser()->parseConstraints($targetPackageVersion) : null;
  14891. $candidates = $this->pool->whatProvides(strtolower($packageName), $constraint, true);
  14892. if (!$candidates) {
  14893. return false;
  14894. }
  14895. $package = reset($candidates);
  14896. foreach ($candidates as $candidate) {
  14897. if (version_compare($package->getVersion(), $candidate->getVersion(), '<')) {
  14898. $package = $candidate;
  14899. }
  14900. }
  14901. return $package;
  14902. }
  14903. public function findRecommendedRequireVersion(PackageInterface $package)
  14904. {
  14905. $version = $package->getVersion();
  14906. if (!$package->isDev()) {
  14907. return $this->transformVersion($version, $package->getPrettyVersion(), $package->getStability());
  14908. }
  14909. $loader = new ArrayLoader($this->getParser());
  14910. $dumper = new ArrayDumper();
  14911. $extra = $loader->getBranchAlias($dumper->dump($package));
  14912. if ($extra) {
  14913. $extra = preg_replace('{^(\d+\.\d+\.\d+)(\.9999999)-dev$}', '$1.0', $extra, -1, $count);
  14914. if ($count) {
  14915. $extra = str_replace('.9999999', '.0', $extra);
  14916. return $this->transformVersion($extra, $extra, 'dev');
  14917. }
  14918. }
  14919. return $package->getPrettyVersion();
  14920. }
  14921. private function transformVersion($version, $prettyVersion, $stability)
  14922. {
  14923. $semanticVersionParts = explode('.', $version);
  14924. if (count($semanticVersionParts) == 4 && preg_match('{^0\D?}', $semanticVersionParts[3])) {
  14925. if ($semanticVersionParts[0] === '0') {
  14926. unset($semanticVersionParts[3]);
  14927. } else {
  14928. unset($semanticVersionParts[2], $semanticVersionParts[3]);
  14929. }
  14930. $version = implode('.', $semanticVersionParts);
  14931. } else {
  14932. return $prettyVersion;
  14933. }
  14934. if ($stability != 'stable') {
  14935. $version .= '@'.$stability;
  14936. }
  14937. return '^' . $version;
  14938. }
  14939. private function getParser()
  14940. {
  14941. if ($this->parser === null) {
  14942. $this->parser = new SemverVersionParser();
  14943. }
  14944. return $this->parser;
  14945. }
  14946. }
  14947. <?php
  14948. namespace Composer\Plugin;
  14949. use Composer\EventDispatcher\Event;
  14950. use Symfony\Component\Console\Input\InputInterface;
  14951. use Symfony\Component\Console\Output\OutputInterface;
  14952. class CommandEvent extends Event
  14953. {
  14954. private $commandName;
  14955. private $input;
  14956. private $output;
  14957. public function __construct($name, $commandName, $input, $output, array $args = array(), array $flags = array())
  14958. {
  14959. parent::__construct($name, $args, $flags);
  14960. $this->commandName = $commandName;
  14961. $this->input = $input;
  14962. $this->output = $output;
  14963. }
  14964. public function getInput()
  14965. {
  14966. return $this->input;
  14967. }
  14968. public function getOutput()
  14969. {
  14970. return $this->output;
  14971. }
  14972. public function getCommandName()
  14973. {
  14974. return $this->commandName;
  14975. }
  14976. }
  14977. <?php
  14978. namespace Composer\Plugin;
  14979. class PluginEvents
  14980. {
  14981. const COMMAND = 'command';
  14982. const PRE_FILE_DOWNLOAD = 'pre-file-download';
  14983. }
  14984. <?php
  14985. namespace Composer\Plugin;
  14986. use Composer\Composer;
  14987. use Composer\IO\IOInterface;
  14988. interface PluginInterface
  14989. {
  14990. const PLUGIN_API_VERSION = '1.0.0';
  14991. public function activate(Composer $composer, IOInterface $io);
  14992. }
  14993. <?php
  14994. namespace Composer\Plugin;
  14995. use Composer\Composer;
  14996. use Composer\EventDispatcher\EventSubscriberInterface;
  14997. use Composer\IO\IOInterface;
  14998. use Composer\Package\Package;
  14999. use Composer\Semver\VersionParser;
  15000. use Composer\Repository\RepositoryInterface;
  15001. use Composer\Package\AliasPackage;
  15002. use Composer\Package\PackageInterface;
  15003. use Composer\Package\Link;
  15004. use Composer\Semver\Constraint\Constraint;
  15005. use Composer\DependencyResolver\Pool;
  15006. class PluginManager
  15007. {
  15008. protected $composer;
  15009. protected $io;
  15010. protected $globalComposer;
  15011. protected $versionParser;
  15012. protected $plugins = array();
  15013. protected $registeredPlugins = array();
  15014. private static $classCounter = 0;
  15015. public function __construct(IOInterface $io, Composer $composer, Composer $globalComposer = null)
  15016. {
  15017. $this->io = $io;
  15018. $this->composer = $composer;
  15019. $this->globalComposer = $globalComposer;
  15020. $this->versionParser = new VersionParser();
  15021. }
  15022. public function loadInstalledPlugins()
  15023. {
  15024. $repo = $this->composer->getRepositoryManager()->getLocalRepository();
  15025. $globalRepo = $this->globalComposer ? $this->globalComposer->getRepositoryManager()->getLocalRepository() : null;
  15026. if ($repo) {
  15027. $this->loadRepository($repo);
  15028. }
  15029. if ($globalRepo) {
  15030. $this->loadRepository($globalRepo);
  15031. }
  15032. }
  15033. public function addPlugin(PluginInterface $plugin)
  15034. {
  15035. if ($this->io->isDebug()) {
  15036. $this->io->writeError('Loading plugin '.get_class($plugin));
  15037. }
  15038. $this->plugins[] = $plugin;
  15039. $plugin->activate($this->composer, $this->io);
  15040. if ($plugin instanceof EventSubscriberInterface) {
  15041. $this->composer->getEventDispatcher()->addSubscriber($plugin);
  15042. }
  15043. }
  15044. public function getPlugins()
  15045. {
  15046. return $this->plugins;
  15047. }
  15048. public function loadRepository(RepositoryInterface $repo)
  15049. {
  15050. foreach ($repo->getPackages() as $package) {
  15051. if ($package instanceof AliasPackage) {
  15052. continue;
  15053. }
  15054. if ('composer-plugin' === $package->getType()) {
  15055. $requiresComposer = null;
  15056. foreach ($package->getRequires() as $link) {
  15057. if ('composer-plugin-api' === $link->getTarget()) {
  15058. $requiresComposer = $link->getConstraint();
  15059. break;
  15060. }
  15061. }
  15062. if (!$requiresComposer) {
  15063. throw new \RuntimeException("Plugin ".$package->getName()." is missing a require statement for a version of the composer-plugin-api package.");
  15064. }
  15065. $currentPluginApiVersion = $this->getPluginApiVersion();
  15066. $currentPluginApiConstraint = new Constraint('==', $this->versionParser->normalize($currentPluginApiVersion));
  15067. if (!$requiresComposer->matches($currentPluginApiConstraint)) {
  15068. $this->io->writeError('<warning>The "' . $package->getName() . '" plugin was skipped because it requires a Plugin API version ("' . $requiresComposer->getPrettyString() . '") that does not match your Composer installation ("' . $currentPluginApiVersion . '"). You may need to run composer update with the "--no-plugins" option.</warning>');
  15069. continue;
  15070. }
  15071. $this->registerPackage($package);
  15072. } elseif ('composer-installer' === $package->getType()) {
  15073. $this->registerPackage($package);
  15074. }
  15075. }
  15076. }
  15077. protected function collectDependencies(Pool $pool, array $collected, PackageInterface $package)
  15078. {
  15079. $requires = array_merge(
  15080. $package->getRequires(),
  15081. $package->getDevRequires()
  15082. );
  15083. foreach ($requires as $requireLink) {
  15084. $requiredPackage = $this->lookupInstalledPackage($pool, $requireLink);
  15085. if ($requiredPackage && !isset($collected[$requiredPackage->getName()])) {
  15086. $collected[$requiredPackage->getName()] = $requiredPackage;
  15087. $collected = $this->collectDependencies($pool, $collected, $requiredPackage);
  15088. }
  15089. }
  15090. return $collected;
  15091. }
  15092. protected function lookupInstalledPackage(Pool $pool, Link $link)
  15093. {
  15094. $packages = $pool->whatProvides($link->getTarget(), $link->getConstraint());
  15095. return (!empty($packages)) ? $packages[0] : null;
  15096. }
  15097. public function registerPackage(PackageInterface $package, $failOnMissingClasses = false)
  15098. {
  15099. $oldInstallerPlugin = ($package->getType() === 'composer-installer');
  15100. if (in_array($package->getName(), $this->registeredPlugins)) {
  15101. return;
  15102. }
  15103. $extra = $package->getExtra();
  15104. if (empty($extra['class'])) {
  15105. throw new \UnexpectedValueException('Error while installing '.$package->getPrettyName().', composer-plugin packages should have a class defined in their extra key to be usable.');
  15106. }
  15107. $classes = is_array($extra['class']) ? $extra['class'] : array($extra['class']);
  15108. $localRepo = $this->composer->getRepositoryManager()->getLocalRepository();
  15109. $globalRepo = $this->globalComposer ? $this->globalComposer->getRepositoryManager()->getLocalRepository() : null;
  15110. $pool = new Pool('dev');
  15111. $pool->addRepository($localRepo);
  15112. if ($globalRepo) {
  15113. $pool->addRepository($globalRepo);
  15114. }
  15115. $autoloadPackages = array($package->getName() => $package);
  15116. $autoloadPackages = $this->collectDependencies($pool, $autoloadPackages, $package);
  15117. $generator = $this->composer->getAutoloadGenerator();
  15118. $autoloads = array();
  15119. foreach ($autoloadPackages as $autoloadPackage) {
  15120. $downloadPath = $this->getInstallPath($autoloadPackage, ($globalRepo && $globalRepo->hasPackage($autoloadPackage)));
  15121. $autoloads[] = array($autoloadPackage, $downloadPath);
  15122. }
  15123. $map = $generator->parseAutoloads($autoloads, new Package('dummy', '1.0.0.0', '1.0.0'));
  15124. $classLoader = $generator->createLoader($map);
  15125. $classLoader->register();
  15126. foreach ($classes as $class) {
  15127. if (class_exists($class, false)) {
  15128. $code = file_get_contents($classLoader->findFile($class));
  15129. $code = preg_replace('{^(\s*)class\s+(\S+)}mi', '$1class $2_composer_tmp'.self::$classCounter, $code);
  15130. eval('?>'.$code);
  15131. $class .= '_composer_tmp'.self::$classCounter;
  15132. self::$classCounter++;
  15133. }
  15134. if ($oldInstallerPlugin) {
  15135. $installer = new $class($this->io, $this->composer);
  15136. $this->composer->getInstallationManager()->addInstaller($installer);
  15137. } elseif (class_exists($class)) {
  15138. $plugin = new $class();
  15139. $this->addPlugin($plugin);
  15140. $this->registeredPlugins[] = $package->getName();
  15141. } elseif ($failOnMissingClasses) {
  15142. throw new \UnexpectedValueException('Plugin '.$package->getName().' could not be initialized, class not found: '.$class);
  15143. }
  15144. }
  15145. }
  15146. public function getInstallPath(PackageInterface $package, $global = false)
  15147. {
  15148. if (!$global) {
  15149. return $this->composer->getInstallationManager()->getInstallPath($package);
  15150. }
  15151. return $this->globalComposer->getInstallationManager()->getInstallPath($package);
  15152. }
  15153. protected function getPluginApiVersion()
  15154. {
  15155. return PluginInterface::PLUGIN_API_VERSION;
  15156. }
  15157. }
  15158. <?php
  15159. namespace Composer\Plugin;
  15160. use Composer\EventDispatcher\Event;
  15161. use Composer\Util\RemoteFilesystem;
  15162. class PreFileDownloadEvent extends Event
  15163. {
  15164. private $rfs;
  15165. private $processedUrl;
  15166. public function __construct($name, RemoteFilesystem $rfs, $processedUrl)
  15167. {
  15168. parent::__construct($name);
  15169. $this->rfs = $rfs;
  15170. $this->processedUrl = $processedUrl;
  15171. }
  15172. public function getRemoteFilesystem()
  15173. {
  15174. return $this->rfs;
  15175. }
  15176. public function setRemoteFilesystem(RemoteFilesystem $rfs)
  15177. {
  15178. $this->rfs = $rfs;
  15179. }
  15180. public function getProcessedUrl()
  15181. {
  15182. return $this->processedUrl;
  15183. }
  15184. }
  15185. <?php
  15186. namespace Composer\Repository;
  15187. use Composer\Package\AliasPackage;
  15188. use Composer\Package\PackageInterface;
  15189. use Composer\Package\CompletePackageInterface;
  15190. use Composer\Semver\VersionParser;
  15191. use Composer\Semver\Constraint\ConstraintInterface;
  15192. use Composer\Semver\Constraint\Constraint;
  15193. class ArrayRepository implements RepositoryInterface
  15194. {
  15195. protected $packages;
  15196. public function __construct(array $packages = array())
  15197. {
  15198. foreach ($packages as $package) {
  15199. $this->addPackage($package);
  15200. }
  15201. }
  15202. public function findPackage($name, $constraint)
  15203. {
  15204. $name = strtolower($name);
  15205. if (!$constraint instanceof ConstraintInterface) {
  15206. $versionParser = new VersionParser();
  15207. $constraint = $versionParser->parseConstraints($constraint);
  15208. }
  15209. foreach ($this->getPackages() as $package) {
  15210. if ($name === $package->getName()) {
  15211. $pkgConstraint = new Constraint('==', $package->getVersion());
  15212. if ($constraint->matches($pkgConstraint)) {
  15213. return $package;
  15214. }
  15215. }
  15216. }
  15217. }
  15218. public function findPackages($name, $constraint = null)
  15219. {
  15220. $name = strtolower($name);
  15221. $packages = array();
  15222. if (null !== $constraint && !$constraint instanceof ConstraintInterface) {
  15223. $versionParser = new VersionParser();
  15224. $constraint = $versionParser->parseConstraints($constraint);
  15225. }
  15226. foreach ($this->getPackages() as $package) {
  15227. if ($name === $package->getName()) {
  15228. $pkgConstraint = new Constraint('==', $package->getVersion());
  15229. if (null === $constraint || $constraint->matches($pkgConstraint)) {
  15230. $packages[] = $package;
  15231. }
  15232. }
  15233. }
  15234. return $packages;
  15235. }
  15236. public function search($query, $mode = 0)
  15237. {
  15238. $regex = '{(?:'.implode('|', preg_split('{\s+}', $query)).')}i';
  15239. $matches = array();
  15240. foreach ($this->getPackages() as $package) {
  15241. $name = $package->getName();
  15242. if (isset($matches[$name])) {
  15243. continue;
  15244. }
  15245. if (preg_match($regex, $name)
  15246. || ($mode === self::SEARCH_FULLTEXT && $package instanceof CompletePackageInterface && preg_match($regex, implode(' ', (array) $package->getKeywords()) . ' ' . $package->getDescription()))
  15247. ) {
  15248. $matches[$name] = array(
  15249. 'name' => $package->getPrettyName(),
  15250. 'description' => $package->getDescription(),
  15251. );
  15252. }
  15253. }
  15254. return array_values($matches);
  15255. }
  15256. public function hasPackage(PackageInterface $package)
  15257. {
  15258. $packageId = $package->getUniqueName();
  15259. foreach ($this->getPackages() as $repoPackage) {
  15260. if ($packageId === $repoPackage->getUniqueName()) {
  15261. return true;
  15262. }
  15263. }
  15264. return false;
  15265. }
  15266. public function addPackage(PackageInterface $package)
  15267. {
  15268. if (null === $this->packages) {
  15269. $this->initialize();
  15270. }
  15271. $package->setRepository($this);
  15272. $this->packages[] = $package;
  15273. if ($package instanceof AliasPackage) {
  15274. $aliasedPackage = $package->getAliasOf();
  15275. if (null === $aliasedPackage->getRepository()) {
  15276. $this->addPackage($aliasedPackage);
  15277. }
  15278. }
  15279. }
  15280. protected function createAliasPackage(PackageInterface $package, $alias, $prettyAlias)
  15281. {
  15282. return new AliasPackage($package instanceof AliasPackage ? $package->getAliasOf() : $package, $alias, $prettyAlias);
  15283. }
  15284. public function removePackage(PackageInterface $package)
  15285. {
  15286. $packageId = $package->getUniqueName();
  15287. foreach ($this->getPackages() as $key => $repoPackage) {
  15288. if ($packageId === $repoPackage->getUniqueName()) {
  15289. array_splice($this->packages, $key, 1);
  15290. return;
  15291. }
  15292. }
  15293. }
  15294. public function getPackages()
  15295. {
  15296. if (null === $this->packages) {
  15297. $this->initialize();
  15298. }
  15299. return $this->packages;
  15300. }
  15301. public function count()
  15302. {
  15303. return count($this->packages);
  15304. }
  15305. protected function initialize()
  15306. {
  15307. $this->packages = array();
  15308. }
  15309. }
  15310. <?php
  15311. namespace Composer\Repository;
  15312. use Composer\IO\IOInterface;
  15313. use Composer\Json\JsonFile;
  15314. use Composer\Package\Loader\ArrayLoader;
  15315. use Composer\Package\Loader\LoaderInterface;
  15316. class ArtifactRepository extends ArrayRepository
  15317. {
  15318. protected $loader;
  15319. protected $lookup;
  15320. public function __construct(array $repoConfig, IOInterface $io)
  15321. {
  15322. if (!extension_loaded('zip')) {
  15323. throw new \RuntimeException('The artifact repository requires PHP\'s zip extension');
  15324. }
  15325. $this->loader = new ArrayLoader();
  15326. $this->lookup = $repoConfig['url'];
  15327. $this->io = $io;
  15328. }
  15329. protected function initialize()
  15330. {
  15331. parent::initialize();
  15332. $this->scanDirectory($this->lookup);
  15333. }
  15334. private function scanDirectory($path)
  15335. {
  15336. $io = $this->io;
  15337. $directory = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS);
  15338. $iterator = new \RecursiveIteratorIterator($directory);
  15339. $regex = new \RegexIterator($iterator, '/^.+\.(zip|phar)$/i');
  15340. foreach ($regex as $file) {
  15341. if (!$file->isFile()) {
  15342. continue;
  15343. }
  15344. $package = $this->getComposerInformation($file);
  15345. if (!$package) {
  15346. if ($io->isVerbose()) {
  15347. $io->writeError("File <comment>{$file->getBasename()}</comment> doesn't seem to hold a package");
  15348. }
  15349. continue;
  15350. }
  15351. if ($io->isVerbose()) {
  15352. $template = 'Found package <info>%s</info> (<comment>%s</comment>) in file <info>%s</info>';
  15353. $io->writeError(sprintf($template, $package->getName(), $package->getPrettyVersion(), $file->getBasename()));
  15354. }
  15355. $this->addPackage($package);
  15356. }
  15357. }
  15358. private function locateFile(\ZipArchive $zip, $filename)
  15359. {
  15360. $indexOfShortestMatch = false;
  15361. $lengthOfShortestMatch = -1;
  15362. for ($i = 0; $i < $zip->numFiles; $i++) {
  15363. $stat = $zip->statIndex($i);
  15364. if (strcmp(basename($stat['name']), $filename) === 0) {
  15365. $directoryName = dirname($stat['name']);
  15366. if ($directoryName == '.') {
  15367. return $i;
  15368. }
  15369. if (strpos($directoryName, '\\') !== false ||
  15370. strpos($directoryName, '/') !== false) {
  15371. continue;
  15372. }
  15373. $length = strlen($stat['name']);
  15374. if ($indexOfShortestMatch == false || $length < $lengthOfShortestMatch) {
  15375. $contents = $zip->getFromIndex($i);
  15376. if ($contents !== false) {
  15377. $indexOfShortestMatch = $i;
  15378. $lengthOfShortestMatch = $length;
  15379. }
  15380. }
  15381. }
  15382. }
  15383. return $indexOfShortestMatch;
  15384. }
  15385. private function getComposerInformation(\SplFileInfo $file)
  15386. {
  15387. $zip = new \ZipArchive();
  15388. $zip->open($file->getPathname());
  15389. if (0 == $zip->numFiles) {
  15390. return false;
  15391. }
  15392. $foundFileIndex = $this->locateFile($zip, 'composer.json');
  15393. if (false === $foundFileIndex) {
  15394. return false;
  15395. }
  15396. $configurationFileName = $zip->getNameIndex($foundFileIndex);
  15397. $composerFile = "zip://{$file->getPathname()}#$configurationFileName";
  15398. $json = file_get_contents($composerFile);
  15399. $package = JsonFile::parseJson($json, $composerFile);
  15400. $package['dist'] = array(
  15401. 'type' => 'zip',
  15402. 'url' => $file->getPathname(),
  15403. 'shasum' => sha1_file($file->getRealPath()),
  15404. );
  15405. $package = $this->loader->load($package);
  15406. return $package;
  15407. }
  15408. }
  15409. <?php
  15410. namespace Composer\Repository;
  15411. use Composer\Package\Loader\ArrayLoader;
  15412. use Composer\Package\PackageInterface;
  15413. use Composer\Package\AliasPackage;
  15414. use Composer\Semver\VersionParser;
  15415. use Composer\DependencyResolver\Pool;
  15416. use Composer\Json\JsonFile;
  15417. use Composer\Cache;
  15418. use Composer\Config;
  15419. use Composer\IO\IOInterface;
  15420. use Composer\Util\RemoteFilesystem;
  15421. use Composer\Plugin\PluginEvents;
  15422. use Composer\Plugin\PreFileDownloadEvent;
  15423. use Composer\EventDispatcher\EventDispatcher;
  15424. use Composer\Semver\Constraint\ConstraintInterface;
  15425. use Composer\Semver\Constraint\Constraint;
  15426. class ComposerRepository extends ArrayRepository
  15427. {
  15428. protected $config;
  15429. protected $options;
  15430. protected $url;
  15431. protected $baseUrl;
  15432. protected $io;
  15433. protected $rfs;
  15434. protected $cache;
  15435. protected $notifyUrl;
  15436. protected $searchUrl;
  15437. protected $hasProviders = false;
  15438. protected $providersUrl;
  15439. protected $lazyProvidersUrl;
  15440. protected $providerListing;
  15441. protected $providers = array();
  15442. protected $providersByUid = array();
  15443. protected $loader;
  15444. protected $rootAliases;
  15445. protected $allowSslDowngrade = false;
  15446. protected $eventDispatcher;
  15447. protected $sourceMirrors;
  15448. protected $distMirrors;
  15449. private $degradedMode = false;
  15450. private $rootData;
  15451. public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null)
  15452. {
  15453. if (!preg_match('{^[\w.]+\??://}', $repoConfig['url'])) {
  15454. $repoConfig['url'] = 'http://'.$repoConfig['url'];
  15455. }
  15456. $repoConfig['url'] = rtrim($repoConfig['url'], '/');
  15457. if ('https?' === substr($repoConfig['url'], 0, 6)) {
  15458. $repoConfig['url'] = (extension_loaded('openssl') ? 'https' : 'http') . substr($repoConfig['url'], 6);
  15459. }
  15460. $urlBits = parse_url($repoConfig['url']);
  15461. if ($urlBits === false || empty($urlBits['scheme'])) {
  15462. throw new \UnexpectedValueException('Invalid url given for Composer repository: '.$repoConfig['url']);
  15463. }
  15464. if (!isset($repoConfig['options'])) {
  15465. $repoConfig['options'] = array();
  15466. }
  15467. if (isset($repoConfig['allow_ssl_downgrade']) && true === $repoConfig['allow_ssl_downgrade']) {
  15468. $this->allowSslDowngrade = true;
  15469. }
  15470. $this->config = $config;
  15471. $this->options = $repoConfig['options'];
  15472. $this->url = $repoConfig['url'];
  15473. $this->baseUrl = rtrim(preg_replace('{^(.*)(?:/[^/\\]+.json)?(?:[?#].*)?$}', '$1', $this->url), '/');
  15474. $this->io = $io;
  15475. $this->cache = new Cache($io, $config->get('cache-repo-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $this->url), 'a-z0-9.$');
  15476. $this->loader = new ArrayLoader();
  15477. $this->rfs = new RemoteFilesystem($this->io, $this->config, $this->options);
  15478. $this->eventDispatcher = $eventDispatcher;
  15479. }
  15480. public function setRootAliases(array $rootAliases)
  15481. {
  15482. $this->rootAliases = $rootAliases;
  15483. }
  15484. public function findPackage($name, $constraint)
  15485. {
  15486. if (!$this->hasProviders()) {
  15487. return parent::findPackage($name, $constraint);
  15488. }
  15489. $name = strtolower($name);
  15490. if (!$constraint instanceof ConstraintInterface) {
  15491. $versionParser = new VersionParser();
  15492. $constraint = $versionParser->parseConstraints($constraint);
  15493. }
  15494. foreach ($this->getProviderNames() as $providerName) {
  15495. if ($name === $providerName) {
  15496. $packages = $this->whatProvides(new Pool('dev'), $providerName);
  15497. foreach ($packages as $package) {
  15498. if ($name === $package->getName()) {
  15499. $pkgConstraint = new Constraint('==', $package->getVersion());
  15500. if ($constraint->matches($pkgConstraint)) {
  15501. return $package;
  15502. }
  15503. }
  15504. }
  15505. }
  15506. }
  15507. }
  15508. public function findPackages($name, $constraint = null)
  15509. {
  15510. if (!$this->hasProviders()) {
  15511. return parent::findPackages($name, $constraint);
  15512. }
  15513. $name = strtolower($name);
  15514. if (null !== $constraint && !$constraint instanceof ConstraintInterface) {
  15515. $versionParser = new VersionParser();
  15516. $constraint = $versionParser->parseConstraints($constraint);
  15517. }
  15518. $packages = array();
  15519. foreach ($this->getProviderNames() as $providerName) {
  15520. if ($name === $providerName) {
  15521. $candidates = $this->whatProvides(new Pool('dev'), $providerName);
  15522. foreach ($candidates as $package) {
  15523. if ($name === $package->getName()) {
  15524. $pkgConstraint = new Constraint('==', $package->getVersion());
  15525. if (null === $constraint || $constraint->matches($pkgConstraint)) {
  15526. $packages[] = $package;
  15527. }
  15528. }
  15529. }
  15530. }
  15531. }
  15532. return $packages;
  15533. }
  15534. public function getPackages()
  15535. {
  15536. if ($this->hasProviders()) {
  15537. throw new \LogicException('Composer repositories that have providers can not load the complete list of packages, use getProviderNames instead.');
  15538. }
  15539. return parent::getPackages();
  15540. }
  15541. public function search($query, $mode = 0)
  15542. {
  15543. $this->loadRootServerFile();
  15544. if ($this->searchUrl && $mode === self::SEARCH_FULLTEXT) {
  15545. $url = str_replace('%query%', $query, $this->searchUrl);
  15546. $hostname = parse_url($url, PHP_URL_HOST) ?: $url;
  15547. $json = $this->rfs->getContents($hostname, $url, false);
  15548. $results = JsonFile::parseJson($json, $url);
  15549. return $results['results'];
  15550. }
  15551. if ($this->hasProviders()) {
  15552. $results = array();
  15553. $regex = '{(?:'.implode('|', preg_split('{\s+}', $query)).')}i';
  15554. foreach ($this->getProviderNames() as $name) {
  15555. if (preg_match($regex, $name)) {
  15556. $results[] = array('name' => $name);
  15557. }
  15558. }
  15559. return $results;
  15560. }
  15561. return parent::search($query, $mode);
  15562. }
  15563. public function getProviderNames()
  15564. {
  15565. $this->loadRootServerFile();
  15566. if (null === $this->providerListing) {
  15567. $this->loadProviderListings($this->loadRootServerFile());
  15568. }
  15569. if ($this->lazyProvidersUrl) {
  15570. return array();
  15571. }
  15572. if ($this->providersUrl) {
  15573. return array_keys($this->providerListing);
  15574. }
  15575. $providers = array();
  15576. foreach (array_keys($this->providerListing) as $provider) {
  15577. $providers[] = substr($provider, 2, -5);
  15578. }
  15579. return $providers;
  15580. }
  15581. protected function configurePackageTransportOptions(PackageInterface $package)
  15582. {
  15583. foreach ($package->getDistUrls() as $url) {
  15584. if (strpos($url, $this->baseUrl) === 0) {
  15585. $package->setTransportOptions($this->options);
  15586. return;
  15587. }
  15588. }
  15589. }
  15590. public function hasProviders()
  15591. {
  15592. $this->loadRootServerFile();
  15593. return $this->hasProviders;
  15594. }
  15595. public function resetPackageIds()
  15596. {
  15597. foreach ($this->providersByUid as $package) {
  15598. if ($package instanceof AliasPackage) {
  15599. $package->getAliasOf()->setId(-1);
  15600. }
  15601. $package->setId(-1);
  15602. }
  15603. }
  15604. public function whatProvides(Pool $pool, $name)
  15605. {
  15606. if (isset($this->providers[$name])) {
  15607. return $this->providers[$name];
  15608. }
  15609. if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $name) || '__root__' === $name) {
  15610. return array();
  15611. }
  15612. if (null === $this->providerListing) {
  15613. $this->loadProviderListings($this->loadRootServerFile());
  15614. }
  15615. if ($this->lazyProvidersUrl && !isset($this->providerListing[$name])) {
  15616. $hash = null;
  15617. $url = str_replace('%package%', $name, $this->lazyProvidersUrl);
  15618. $cacheKey = false;
  15619. } elseif ($this->providersUrl) {
  15620. if (!isset($this->providerListing[$name])) {
  15621. return array();
  15622. }
  15623. $hash = $this->providerListing[$name]['sha256'];
  15624. $url = str_replace(array('%package%', '%hash%'), array($name, $hash), $this->providersUrl);
  15625. $cacheKey = 'provider-'.strtr($name, '/', '$').'.json';
  15626. } else {
  15627. $url = 'p/'.$name.'.json';
  15628. if (!isset($this->providerListing[$url])) {
  15629. return array();
  15630. }
  15631. $hash = $this->providerListing[$url]['sha256'];
  15632. $cacheKey = null;
  15633. }
  15634. if ($cacheKey && $this->cache->sha256($cacheKey) === $hash) {
  15635. $packages = json_decode($this->cache->read($cacheKey), true);
  15636. } else {
  15637. $packages = $this->fetchFile($url, $cacheKey, $hash);
  15638. }
  15639. $this->providers[$name] = array();
  15640. foreach ($packages['packages'] as $versions) {
  15641. foreach ($versions as $version) {
  15642. if (isset($this->providersByUid[$version['uid']])) {
  15643. if (!isset($this->providers[$name][$version['uid']])) {
  15644. if ($this->providersByUid[$version['uid']] instanceof AliasPackage) {
  15645. $this->providers[$name][$version['uid']] = $this->providersByUid[$version['uid']]->getAliasOf();
  15646. $this->providers[$name][$version['uid'].'-alias'] = $this->providersByUid[$version['uid']];
  15647. } else {
  15648. $this->providers[$name][$version['uid']] = $this->providersByUid[$version['uid']];
  15649. }
  15650. if (isset($this->providersByUid[$version['uid'].'-root'])) {
  15651. $this->providers[$name][$version['uid'].'-root'] = $this->providersByUid[$version['uid'].'-root'];
  15652. }
  15653. }
  15654. } else {
  15655. if (!$pool->isPackageAcceptable(strtolower($version['name']), VersionParser::parseStability($version['version']))) {
  15656. continue;
  15657. }
  15658. $package = $this->createPackage($version, 'Composer\Package\Package');
  15659. $package->setRepository($this);
  15660. if ($package instanceof AliasPackage) {
  15661. $aliased = $package->getAliasOf();
  15662. $aliased->setRepository($this);
  15663. $this->providers[$name][$version['uid']] = $aliased;
  15664. $this->providers[$name][$version['uid'].'-alias'] = $package;
  15665. $this->providersByUid[$version['uid']] = $package;
  15666. } else {
  15667. $this->providers[$name][$version['uid']] = $package;
  15668. $this->providersByUid[$version['uid']] = $package;
  15669. }
  15670. unset($rootAliasData);
  15671. if (isset($this->rootAliases[$package->getName()][$package->getVersion()])) {
  15672. $rootAliasData = $this->rootAliases[$package->getName()][$package->getVersion()];
  15673. } elseif ($package instanceof AliasPackage && isset($this->rootAliases[$package->getName()][$package->getAliasOf()->getVersion()])) {
  15674. $rootAliasData = $this->rootAliases[$package->getName()][$package->getAliasOf()->getVersion()];
  15675. }
  15676. if (isset($rootAliasData)) {
  15677. $alias = $this->createAliasPackage($package, $rootAliasData['alias_normalized'], $rootAliasData['alias']);
  15678. $alias->setRepository($this);
  15679. $this->providers[$name][$version['uid'].'-root'] = $alias;
  15680. $this->providersByUid[$version['uid'].'-root'] = $alias;
  15681. }
  15682. }
  15683. }
  15684. }
  15685. return $this->providers[$name];
  15686. }
  15687. protected function initialize()
  15688. {
  15689. parent::initialize();
  15690. $repoData = $this->loadDataFromServer();
  15691. foreach ($repoData as $package) {
  15692. $this->addPackage($this->createPackage($package, 'Composer\Package\CompletePackage'));
  15693. }
  15694. }
  15695. public function addPackage(PackageInterface $package)
  15696. {
  15697. parent::addPackage($package);
  15698. $this->configurePackageTransportOptions($package);
  15699. }
  15700. protected function loadRootServerFile()
  15701. {
  15702. if (null !== $this->rootData) {
  15703. return $this->rootData;
  15704. }
  15705. if (!extension_loaded('openssl') && 'https' === substr($this->url, 0, 5)) {
  15706. throw new \RuntimeException('You must enable the openssl extension in your php.ini to load information from '.$this->url);
  15707. }
  15708. $jsonUrlParts = parse_url($this->url);
  15709. if (isset($jsonUrlParts['path']) && false !== strpos($jsonUrlParts['path'], '.json')) {
  15710. $jsonUrl = $this->url;
  15711. } else {
  15712. $jsonUrl = $this->url . '/packages.json';
  15713. }
  15714. $data = $this->fetchFile($jsonUrl, 'packages.json');
  15715. if (!empty($data['notify-batch'])) {
  15716. $this->notifyUrl = $this->canonicalizeUrl($data['notify-batch']);
  15717. } elseif (!empty($data['notify_batch'])) {
  15718. $this->notifyUrl = $this->canonicalizeUrl($data['notify_batch']);
  15719. } elseif (!empty($data['notify'])) {
  15720. $this->notifyUrl = $this->canonicalizeUrl($data['notify']);
  15721. }
  15722. if (!empty($data['search'])) {
  15723. $this->searchUrl = $this->canonicalizeUrl($data['search']);
  15724. }
  15725. if (!empty($data['mirrors'])) {
  15726. foreach ($data['mirrors'] as $mirror) {
  15727. if (!empty($mirror['git-url'])) {
  15728. $this->sourceMirrors['git'][] = array('url' => $mirror['git-url'], 'preferred' => !empty($mirror['preferred']));
  15729. }
  15730. if (!empty($mirror['hg-url'])) {
  15731. $this->sourceMirrors['hg'][] = array('url' => $mirror['hg-url'], 'preferred' => !empty($mirror['preferred']));
  15732. }
  15733. if (!empty($mirror['dist-url'])) {
  15734. $this->distMirrors[] = array('url' => $mirror['dist-url'], 'preferred' => !empty($mirror['preferred']));
  15735. }
  15736. }
  15737. }
  15738. if (!empty($data['warning'])) {
  15739. $this->io->writeError('<warning>Warning from '.$this->url.': '.$data['warning'].'</warning>');
  15740. }
  15741. if (!empty($data['providers-lazy-url'])) {
  15742. $this->lazyProvidersUrl = $this->canonicalizeUrl($data['providers-lazy-url']);
  15743. $this->hasProviders = true;
  15744. }
  15745. if ($this->allowSslDowngrade) {
  15746. $this->url = str_replace('https://', 'http://', $this->url);
  15747. $this->baseUrl = str_replace('https://', 'http://', $this->baseUrl);
  15748. }
  15749. if (!empty($data['providers-url'])) {
  15750. $this->providersUrl = $this->canonicalizeUrl($data['providers-url']);
  15751. $this->hasProviders = true;
  15752. }
  15753. if (!empty($data['providers']) || !empty($data['providers-includes'])) {
  15754. $this->hasProviders = true;
  15755. }
  15756. return $this->rootData = $data;
  15757. }
  15758. protected function canonicalizeUrl($url)
  15759. {
  15760. if ('/' === $url[0]) {
  15761. return preg_replace('{(https?://[^/]+).*}i', '$1' . $url, $this->url);
  15762. }
  15763. return $url;
  15764. }
  15765. protected function loadDataFromServer()
  15766. {
  15767. $data = $this->loadRootServerFile();
  15768. return $this->loadIncludes($data);
  15769. }
  15770. protected function loadProviderListings($data)
  15771. {
  15772. if (isset($data['providers'])) {
  15773. if (!is_array($this->providerListing)) {
  15774. $this->providerListing = array();
  15775. }
  15776. $this->providerListing = array_merge($this->providerListing, $data['providers']);
  15777. }
  15778. if ($this->providersUrl && isset($data['provider-includes'])) {
  15779. $includes = $data['provider-includes'];
  15780. foreach ($includes as $include => $metadata) {
  15781. $url = $this->baseUrl . '/' . str_replace('%hash%', $metadata['sha256'], $include);
  15782. $cacheKey = str_replace(array('%hash%','$'), '', $include);
  15783. if ($this->cache->sha256($cacheKey) === $metadata['sha256']) {
  15784. $includedData = json_decode($this->cache->read($cacheKey), true);
  15785. } else {
  15786. $includedData = $this->fetchFile($url, $cacheKey, $metadata['sha256']);
  15787. }
  15788. $this->loadProviderListings($includedData);
  15789. }
  15790. } elseif (isset($data['providers-includes'])) {
  15791. $includes = $data['providers-includes'];
  15792. foreach ($includes as $include => $metadata) {
  15793. if ($this->cache->sha256($include) === $metadata['sha256']) {
  15794. $includedData = json_decode($this->cache->read($include), true);
  15795. } else {
  15796. $includedData = $this->fetchFile($include, null, $metadata['sha256']);
  15797. }
  15798. $this->loadProviderListings($includedData);
  15799. }
  15800. }
  15801. }
  15802. protected function loadIncludes($data)
  15803. {
  15804. $packages = array();
  15805. if (!isset($data['packages']) && !isset($data['includes'])) {
  15806. foreach ($data as $pkg) {
  15807. foreach ($pkg['versions'] as $metadata) {
  15808. $packages[] = $metadata;
  15809. }
  15810. }
  15811. return $packages;
  15812. }
  15813. if (isset($data['packages'])) {
  15814. foreach ($data['packages'] as $package => $versions) {
  15815. foreach ($versions as $version => $metadata) {
  15816. $packages[] = $metadata;
  15817. }
  15818. }
  15819. }
  15820. if (isset($data['includes'])) {
  15821. foreach ($data['includes'] as $include => $metadata) {
  15822. if ($this->cache->sha1($include) === $metadata['sha1']) {
  15823. $includedData = json_decode($this->cache->read($include), true);
  15824. } else {
  15825. $includedData = $this->fetchFile($include);
  15826. }
  15827. $packages = array_merge($packages, $this->loadIncludes($includedData));
  15828. }
  15829. }
  15830. return $packages;
  15831. }
  15832. protected function createPackage(array $data, $class)
  15833. {
  15834. try {
  15835. if (!isset($data['notification-url'])) {
  15836. $data['notification-url'] = $this->notifyUrl;
  15837. }
  15838. $package = $this->loader->load($data, 'Composer\Package\CompletePackage');
  15839. if (isset($this->sourceMirrors[$package->getSourceType()])) {
  15840. $package->setSourceMirrors($this->sourceMirrors[$package->getSourceType()]);
  15841. }
  15842. $package->setDistMirrors($this->distMirrors);
  15843. $this->configurePackageTransportOptions($package);
  15844. return $package;
  15845. } catch (\Exception $e) {
  15846. throw new \RuntimeException('Could not load package '.(isset($data['name']) ? $data['name'] : json_encode($data)).' in '.$this->url.': ['.get_class($e).'] '.$e->getMessage(), 0, $e);
  15847. }
  15848. }
  15849. protected function fetchFile($filename, $cacheKey = null, $sha256 = null)
  15850. {
  15851. if (null === $cacheKey) {
  15852. $cacheKey = $filename;
  15853. $filename = $this->baseUrl.'/'.$filename;
  15854. }
  15855. if (($pos = strpos($filename, '$')) && preg_match('{^https?://.*}i', $filename)) {
  15856. $filename = substr($filename, 0, $pos) . '%24' . substr($filename, $pos + 1);
  15857. }
  15858. $retries = 3;
  15859. while ($retries--) {
  15860. try {
  15861. $preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->rfs, $filename);
  15862. if ($this->eventDispatcher) {
  15863. $this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
  15864. }
  15865. $hostname = parse_url($filename, PHP_URL_HOST) ?: $filename;
  15866. $json = $preFileDownloadEvent->getRemoteFilesystem()->getContents($hostname, $filename, false);
  15867. if ($sha256 && $sha256 !== hash('sha256', $json)) {
  15868. if ($retries) {
  15869. usleep(100000);
  15870. continue;
  15871. }
  15872. throw new RepositorySecurityException('The contents of '.$filename.' do not match its signature. This should indicate a man-in-the-middle attack. Try running composer again and report this if you think it is a mistake.');
  15873. }
  15874. $data = JsonFile::parseJson($json, $filename);
  15875. if ($cacheKey) {
  15876. $this->cache->write($cacheKey, $json);
  15877. }
  15878. break;
  15879. } catch (\Exception $e) {
  15880. if ($retries) {
  15881. usleep(100000);
  15882. continue;
  15883. }
  15884. if ($e instanceof RepositorySecurityException) {
  15885. throw $e;
  15886. }
  15887. if ($cacheKey && ($contents = $this->cache->read($cacheKey))) {
  15888. if (!$this->degradedMode) {
  15889. $this->io->writeError('<warning>'.$e->getMessage().'</warning>');
  15890. $this->io->writeError('<warning>'.$this->url.' could not be fully loaded, package information was loaded from the local cache and may be out of date</warning>');
  15891. }
  15892. $this->degradedMode = true;
  15893. $data = JsonFile::parseJson($contents, $this->cache->getRoot().$cacheKey);
  15894. break;
  15895. }
  15896. throw $e;
  15897. }
  15898. }
  15899. return $data;
  15900. }
  15901. }
  15902. <?php
  15903. namespace Composer\Repository;
  15904. use Composer\Package\PackageInterface;
  15905. class CompositeRepository implements RepositoryInterface
  15906. {
  15907. private $repositories;
  15908. public function __construct(array $repositories)
  15909. {
  15910. $this->repositories = array();
  15911. foreach ($repositories as $repo) {
  15912. $this->addRepository($repo);
  15913. }
  15914. }
  15915. public function getRepositories()
  15916. {
  15917. return $this->repositories;
  15918. }
  15919. public function hasPackage(PackageInterface $package)
  15920. {
  15921. foreach ($this->repositories as $repository) {
  15922. if ($repository->hasPackage($package)) {
  15923. return true;
  15924. }
  15925. }
  15926. return false;
  15927. }
  15928. public function findPackage($name, $constraint)
  15929. {
  15930. foreach ($this->repositories as $repository) {
  15931. $package = $repository->findPackage($name, $constraint);
  15932. if (null !== $package) {
  15933. return $package;
  15934. }
  15935. }
  15936. return null;
  15937. }
  15938. public function findPackages($name, $constraint = null)
  15939. {
  15940. $packages = array();
  15941. foreach ($this->repositories as $repository) {
  15942. $packages[] = $repository->findPackages($name, $constraint);
  15943. }
  15944. return $packages ? call_user_func_array('array_merge', $packages) : array();
  15945. }
  15946. public function search($query, $mode = 0)
  15947. {
  15948. $matches = array();
  15949. foreach ($this->repositories as $repository) {
  15950. $matches[] = $repository->search($query, $mode);
  15951. }
  15952. return $matches ? call_user_func_array('array_merge', $matches) : array();
  15953. }
  15954. public function getPackages()
  15955. {
  15956. $packages = array();
  15957. foreach ($this->repositories as $repository) {
  15958. $packages[] = $repository->getPackages();
  15959. }
  15960. return $packages ? call_user_func_array('array_merge', $packages) : array();
  15961. }
  15962. public function removePackage(PackageInterface $package)
  15963. {
  15964. foreach ($this->repositories as $repository) {
  15965. $repository->removePackage($package);
  15966. }
  15967. }
  15968. public function count()
  15969. {
  15970. $total = 0;
  15971. foreach ($this->repositories as $repository) {
  15972. $total += $repository->count();
  15973. }
  15974. return $total;
  15975. }
  15976. public function addRepository(RepositoryInterface $repository)
  15977. {
  15978. if ($repository instanceof self) {
  15979. foreach ($repository->getRepositories() as $repo) {
  15980. $this->addRepository($repo);
  15981. }
  15982. } else {
  15983. $this->repositories[] = $repository;
  15984. }
  15985. }
  15986. }
  15987. <?php
  15988. namespace Composer\Repository;
  15989. use Composer\Json\JsonFile;
  15990. use Composer\Package\Loader\ArrayLoader;
  15991. use Composer\Package\Dumper\ArrayDumper;
  15992. class FilesystemRepository extends WritableArrayRepository
  15993. {
  15994. private $file;
  15995. public function __construct(JsonFile $repositoryFile)
  15996. {
  15997. $this->file = $repositoryFile;
  15998. }
  15999. protected function initialize()
  16000. {
  16001. parent::initialize();
  16002. if (!$this->file->exists()) {
  16003. return;
  16004. }
  16005. try {
  16006. $packages = $this->file->read();
  16007. if (!is_array($packages)) {
  16008. throw new \UnexpectedValueException('Could not parse package list from the repository');
  16009. }
  16010. } catch (\Exception $e) {
  16011. throw new InvalidRepositoryException('Invalid repository data in '.$this->file->getPath().', packages could not be loaded: ['.get_class($e).'] '.$e->getMessage());
  16012. }
  16013. $loader = new ArrayLoader(null, true);
  16014. foreach ($packages as $packageData) {
  16015. $package = $loader->load($packageData);
  16016. $this->addPackage($package);
  16017. }
  16018. }
  16019. public function reload()
  16020. {
  16021. $this->packages = null;
  16022. $this->initialize();
  16023. }
  16024. public function write()
  16025. {
  16026. $data = array();
  16027. $dumper = new ArrayDumper();
  16028. foreach ($this->getCanonicalPackages() as $package) {
  16029. $data[] = $dumper->dump($package);
  16030. }
  16031. $this->file->write($data);
  16032. }
  16033. }
  16034. <?php
  16035. namespace Composer\Repository;
  16036. class InstalledArrayRepository extends WritableArrayRepository implements InstalledRepositoryInterface
  16037. {
  16038. }
  16039. <?php
  16040. namespace Composer\Repository;
  16041. class InstalledFilesystemRepository extends FilesystemRepository implements InstalledRepositoryInterface
  16042. {
  16043. }
  16044. <?php
  16045. namespace Composer\Repository;
  16046. interface InstalledRepositoryInterface extends WritableRepositoryInterface
  16047. {
  16048. }
  16049. <?php
  16050. namespace Composer\Repository;
  16051. class InvalidRepositoryException extends \Exception
  16052. {
  16053. }
  16054. <?php
  16055. namespace Composer\Repository;
  16056. use Composer\Package\Loader\ArrayLoader;
  16057. use Composer\Package\Loader\ValidatingArrayLoader;
  16058. class PackageRepository extends ArrayRepository
  16059. {
  16060. private $config;
  16061. public function __construct(array $config)
  16062. {
  16063. $this->config = $config['package'];
  16064. if (!is_numeric(key($this->config))) {
  16065. $this->config = array($this->config);
  16066. }
  16067. }
  16068. protected function initialize()
  16069. {
  16070. parent::initialize();
  16071. $loader = new ValidatingArrayLoader(new ArrayLoader, false);
  16072. foreach ($this->config as $package) {
  16073. try {
  16074. $package = $loader->load($package);
  16075. } catch (\Exception $e) {
  16076. throw new InvalidRepositoryException('A repository of type "package" contains an invalid package definition: '.$e->getMessage()."\n\nInvalid package definition:\n".json_encode($package));
  16077. }
  16078. $this->addPackage($package);
  16079. }
  16080. }
  16081. }
  16082. <?php
  16083. namespace Composer\Repository;
  16084. use Composer\Config;
  16085. use Composer\IO\IOInterface;
  16086. use Composer\Json\JsonFile;
  16087. use Composer\Package\Loader\ArrayLoader;
  16088. use Composer\Package\Version\VersionGuesser;
  16089. use Composer\Semver\VersionParser;
  16090. use Composer\Util\ProcessExecutor;
  16091. class PathRepository extends ArrayRepository
  16092. {
  16093. private $loader;
  16094. private $versionGuesser;
  16095. private $url;
  16096. private $process;
  16097. public function __construct(array $repoConfig, IOInterface $io, Config $config)
  16098. {
  16099. if (!isset($repoConfig['url'])) {
  16100. throw new \RuntimeException('You must specify the `url` configuration for the path repository');
  16101. }
  16102. $this->loader = new ArrayLoader();
  16103. $this->url = $repoConfig['url'];
  16104. $this->process = new ProcessExecutor($io);
  16105. $this->versionGuesser = new VersionGuesser($config, $this->process, new VersionParser());
  16106. parent::__construct();
  16107. }
  16108. protected function initialize()
  16109. {
  16110. parent::initialize();
  16111. foreach ($this->getUrlMatches() as $url) {
  16112. $path = realpath($url) . '/';
  16113. $composerFilePath = $path.'composer.json';
  16114. if (!file_exists($composerFilePath)) {
  16115. continue;
  16116. }
  16117. $json = file_get_contents($composerFilePath);
  16118. $package = JsonFile::parseJson($json, $composerFilePath);
  16119. $package['dist'] = array(
  16120. 'type' => 'path',
  16121. 'url' => $url,
  16122. 'reference' => '',
  16123. );
  16124. if (!isset($package['version'])) {
  16125. $package['version'] = $this->versionGuesser->guessVersion($package, $path) ?: 'dev-master';
  16126. }
  16127. if (is_dir($path.'/.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) {
  16128. $package['dist']['reference'] = trim($output);
  16129. }
  16130. $package = $this->loader->load($package);
  16131. $this->addPackage($package);
  16132. }
  16133. if (count($this->getPackages()) == 0) {
  16134. throw new \RuntimeException(sprintf('No `composer.json` file found in any path repository in "%s"', $this->url));
  16135. }
  16136. }
  16137. private function getUrlMatches()
  16138. {
  16139. return glob($this->url, GLOB_MARK | GLOB_ONLYDIR);
  16140. }
  16141. }
  16142. <?php
  16143. namespace Composer\Repository\Pear;
  16144. use Composer\Util\RemoteFilesystem;
  16145. abstract class BaseChannelReader
  16146. {
  16147. const CHANNEL_NS = 'http://pear.php.net/channel-1.0';
  16148. const ALL_CATEGORIES_NS = 'http://pear.php.net/dtd/rest.allcategories';
  16149. const CATEGORY_PACKAGES_INFO_NS = 'http://pear.php.net/dtd/rest.categorypackageinfo';
  16150. const ALL_PACKAGES_NS = 'http://pear.php.net/dtd/rest.allpackages';
  16151. const ALL_RELEASES_NS = 'http://pear.php.net/dtd/rest.allreleases';
  16152. const PACKAGE_INFO_NS = 'http://pear.php.net/dtd/rest.package';
  16153. private $rfs;
  16154. protected function __construct(RemoteFilesystem $rfs)
  16155. {
  16156. $this->rfs = $rfs;
  16157. }
  16158. protected function requestContent($origin, $path)
  16159. {
  16160. $url = rtrim($origin, '/') . '/' . ltrim($path, '/');
  16161. $content = $this->rfs->getContents($origin, $url, false);
  16162. if (!$content) {
  16163. throw new \UnexpectedValueException('The PEAR channel at ' . $url . ' did not respond.');
  16164. }
  16165. return $content;
  16166. }
  16167. protected function requestXml($origin, $path)
  16168. {
  16169. $xml = simplexml_load_string($this->requestContent($origin, $path), "SimpleXMLElement", LIBXML_NOERROR);
  16170. if (false == $xml) {
  16171. $url = rtrim($origin, '/') . '/' . ltrim($path, '/');
  16172. throw new \UnexpectedValueException(sprintf('The PEAR channel at ' . $origin . ' is broken. (Invalid XML at file `%s`)', $path));
  16173. }
  16174. return $xml;
  16175. }
  16176. }
  16177. <?php
  16178. namespace Composer\Repository\Pear;
  16179. class ChannelInfo
  16180. {
  16181. private $name;
  16182. private $alias;
  16183. private $packages;
  16184. public function __construct($name, $alias, array $packages)
  16185. {
  16186. $this->name = $name;
  16187. $this->alias = $alias;
  16188. $this->packages = $packages;
  16189. }
  16190. public function getName()
  16191. {
  16192. return $this->name;
  16193. }
  16194. public function getAlias()
  16195. {
  16196. return $this->alias;
  16197. }
  16198. public function getPackages()
  16199. {
  16200. return $this->packages;
  16201. }
  16202. }
  16203. <?php
  16204. namespace Composer\Repository\Pear;
  16205. use Composer\Util\RemoteFilesystem;
  16206. class ChannelReader extends BaseChannelReader
  16207. {
  16208. private $readerMap;
  16209. public function __construct(RemoteFilesystem $rfs)
  16210. {
  16211. parent::__construct($rfs);
  16212. $rest10reader = new ChannelRest10Reader($rfs);
  16213. $rest11reader = new ChannelRest11Reader($rfs);
  16214. $this->readerMap = array(
  16215. 'REST1.3' => $rest11reader,
  16216. 'REST1.2' => $rest11reader,
  16217. 'REST1.1' => $rest11reader,
  16218. 'REST1.0' => $rest10reader,
  16219. );
  16220. }
  16221. public function read($url)
  16222. {
  16223. $xml = $this->requestXml($url, "/channel.xml");
  16224. $channelName = (string) $xml->name;
  16225. $channelSummary = (string) $xml->summary;
  16226. $channelAlias = (string) $xml->suggestedalias;
  16227. $supportedVersions = array_keys($this->readerMap);
  16228. $selectedRestVersion = $this->selectRestVersion($xml, $supportedVersions);
  16229. if (!$selectedRestVersion) {
  16230. throw new \UnexpectedValueException(sprintf('PEAR repository %s does not supports any of %s protocols.', $url, implode(', ', $supportedVersions)));
  16231. }
  16232. $reader = $this->readerMap[$selectedRestVersion['version']];
  16233. $packageDefinitions = $reader->read($selectedRestVersion['baseUrl']);
  16234. return new ChannelInfo($channelName, $channelAlias, $packageDefinitions);
  16235. }
  16236. private function selectRestVersion($channelXml, $supportedVersions)
  16237. {
  16238. $channelXml->registerXPathNamespace('ns', self::CHANNEL_NS);
  16239. foreach ($supportedVersions as $version) {
  16240. $xpathTest = "ns:servers/ns:primary/ns:rest/ns:baseurl[@type='{$version}']";
  16241. $testResult = $channelXml->xpath($xpathTest);
  16242. if (count($testResult) > 0) {
  16243. return array('version' => $version, 'baseUrl' => (string) $testResult[0]);
  16244. }
  16245. }
  16246. return null;
  16247. }
  16248. }
  16249. <?php
  16250. namespace Composer\Repository\Pear;
  16251. use Composer\Downloader\TransportException;
  16252. class ChannelRest10Reader extends BaseChannelReader
  16253. {
  16254. private $dependencyReader;
  16255. public function __construct($rfs)
  16256. {
  16257. parent::__construct($rfs);
  16258. $this->dependencyReader = new PackageDependencyParser();
  16259. }
  16260. public function read($baseUrl)
  16261. {
  16262. return $this->readPackages($baseUrl);
  16263. }
  16264. private function readPackages($baseUrl)
  16265. {
  16266. $result = array();
  16267. $xmlPath = '/p/packages.xml';
  16268. $xml = $this->requestXml($baseUrl, $xmlPath);
  16269. $xml->registerXPathNamespace('ns', self::ALL_PACKAGES_NS);
  16270. foreach ($xml->xpath('ns:p') as $node) {
  16271. $packageName = (string) $node;
  16272. $packageInfo = $this->readPackage($baseUrl, $packageName);
  16273. $result[] = $packageInfo;
  16274. }
  16275. return $result;
  16276. }
  16277. private function readPackage($baseUrl, $packageName)
  16278. {
  16279. $xmlPath = '/p/' . strtolower($packageName) . '/info.xml';
  16280. $xml = $this->requestXml($baseUrl, $xmlPath);
  16281. $xml->registerXPathNamespace('ns', self::PACKAGE_INFO_NS);
  16282. $channelName = (string) $xml->c;
  16283. $packageName = (string) $xml->n;
  16284. $license = (string) $xml->l;
  16285. $shortDescription = (string) $xml->s;
  16286. $description = (string) $xml->d;
  16287. return new PackageInfo(
  16288. $channelName,
  16289. $packageName,
  16290. $license,
  16291. $shortDescription,
  16292. $description,
  16293. $this->readPackageReleases($baseUrl, $packageName)
  16294. );
  16295. }
  16296. private function readPackageReleases($baseUrl, $packageName)
  16297. {
  16298. $result = array();
  16299. try {
  16300. $xmlPath = '/r/' . strtolower($packageName) . '/allreleases.xml';
  16301. $xml = $this->requestXml($baseUrl, $xmlPath);
  16302. $xml->registerXPathNamespace('ns', self::ALL_RELEASES_NS);
  16303. foreach ($xml->xpath('ns:r') as $node) {
  16304. $releaseVersion = (string) $node->v;
  16305. $releaseStability = (string) $node->s;
  16306. try {
  16307. $result[$releaseVersion] = new ReleaseInfo(
  16308. $releaseStability,
  16309. $this->readPackageReleaseDependencies($baseUrl, $packageName, $releaseVersion)
  16310. );
  16311. } catch (TransportException $exception) {
  16312. if ($exception->getCode() != 404) {
  16313. throw $exception;
  16314. }
  16315. }
  16316. }
  16317. } catch (TransportException $exception) {
  16318. if ($exception->getCode() != 404) {
  16319. throw $exception;
  16320. }
  16321. }
  16322. return $result;
  16323. }
  16324. private function readPackageReleaseDependencies($baseUrl, $packageName, $version)
  16325. {
  16326. $dependencyReader = new PackageDependencyParser();
  16327. $depthPath = '/r/' . strtolower($packageName) . '/deps.' . $version . '.txt';
  16328. $content = $this->requestContent($baseUrl, $depthPath);
  16329. $dependencyArray = unserialize($content);
  16330. $result = $dependencyReader->buildDependencyInfo($dependencyArray);
  16331. return $result;
  16332. }
  16333. }
  16334. <?php
  16335. namespace Composer\Repository\Pear;
  16336. class ChannelRest11Reader extends BaseChannelReader
  16337. {
  16338. private $dependencyReader;
  16339. public function __construct($rfs)
  16340. {
  16341. parent::__construct($rfs);
  16342. $this->dependencyReader = new PackageDependencyParser();
  16343. }
  16344. public function read($baseUrl)
  16345. {
  16346. return $this->readChannelPackages($baseUrl);
  16347. }
  16348. private function readChannelPackages($baseUrl)
  16349. {
  16350. $result = array();
  16351. $xml = $this->requestXml($baseUrl, "/c/categories.xml");
  16352. $xml->registerXPathNamespace('ns', self::ALL_CATEGORIES_NS);
  16353. foreach ($xml->xpath('ns:c') as $node) {
  16354. $categoryName = (string) $node;
  16355. $categoryPackages = $this->readCategoryPackages($baseUrl, $categoryName);
  16356. $result = array_merge($result, $categoryPackages);
  16357. }
  16358. return $result;
  16359. }
  16360. private function readCategoryPackages($baseUrl, $categoryName)
  16361. {
  16362. $result = array();
  16363. $categoryPath = '/c/'.urlencode($categoryName).'/packagesinfo.xml';
  16364. $xml = $this->requestXml($baseUrl, $categoryPath);
  16365. $xml->registerXPathNamespace('ns', self::CATEGORY_PACKAGES_INFO_NS);
  16366. foreach ($xml->xpath('ns:pi') as $node) {
  16367. $packageInfo = $this->parsePackage($node);
  16368. $result[] = $packageInfo;
  16369. }
  16370. return $result;
  16371. }
  16372. private function parsePackage($packageInfo)
  16373. {
  16374. $packageInfo->registerXPathNamespace('ns', self::CATEGORY_PACKAGES_INFO_NS);
  16375. $channelName = (string) $packageInfo->p->c;
  16376. $packageName = (string) $packageInfo->p->n;
  16377. $license = (string) $packageInfo->p->l;
  16378. $shortDescription = (string) $packageInfo->p->s;
  16379. $description = (string) $packageInfo->p->d;
  16380. $dependencies = array();
  16381. foreach ($packageInfo->xpath('ns:deps') as $node) {
  16382. $dependencyVersion = (string) $node->v;
  16383. $dependencyArray = unserialize((string) $node->d);
  16384. $dependencyInfo = $this->dependencyReader->buildDependencyInfo($dependencyArray);
  16385. $dependencies[$dependencyVersion] = $dependencyInfo;
  16386. }
  16387. $releases = array();
  16388. $releasesInfo = $packageInfo->xpath('ns:a/ns:r');
  16389. if ($releasesInfo) {
  16390. foreach ($releasesInfo as $node) {
  16391. $releaseVersion = (string) $node->v;
  16392. $releaseStability = (string) $node->s;
  16393. $releases[$releaseVersion] = new ReleaseInfo(
  16394. $releaseStability,
  16395. isset($dependencies[$releaseVersion]) ? $dependencies[$releaseVersion] : new DependencyInfo(array(), array())
  16396. );
  16397. }
  16398. }
  16399. return new PackageInfo(
  16400. $channelName,
  16401. $packageName,
  16402. $license,
  16403. $shortDescription,
  16404. $description,
  16405. $releases
  16406. );
  16407. }
  16408. }
  16409. <?php
  16410. namespace Composer\Repository\Pear;
  16411. class DependencyConstraint
  16412. {
  16413. private $type;
  16414. private $constraint;
  16415. private $channelName;
  16416. private $packageName;
  16417. public function __construct($type, $constraint, $channelName, $packageName)
  16418. {
  16419. $this->type = $type;
  16420. $this->constraint = $constraint;
  16421. $this->channelName = $channelName;
  16422. $this->packageName = $packageName;
  16423. }
  16424. public function getChannelName()
  16425. {
  16426. return $this->channelName;
  16427. }
  16428. public function getConstraint()
  16429. {
  16430. return $this->constraint;
  16431. }
  16432. public function getPackageName()
  16433. {
  16434. return $this->packageName;
  16435. }
  16436. public function getType()
  16437. {
  16438. return $this->type;
  16439. }
  16440. }
  16441. <?php
  16442. namespace Composer\Repository\Pear;
  16443. class DependencyInfo
  16444. {
  16445. private $requires;
  16446. private $optionals;
  16447. public function __construct($requires, $optionals)
  16448. {
  16449. $this->requires = $requires;
  16450. $this->optionals = $optionals;
  16451. }
  16452. public function getRequires()
  16453. {
  16454. return $this->requires;
  16455. }
  16456. public function getOptionals()
  16457. {
  16458. return $this->optionals;
  16459. }
  16460. }
  16461. <?php
  16462. namespace Composer\Repository\Pear;
  16463. class PackageDependencyParser
  16464. {
  16465. public function buildDependencyInfo($depArray)
  16466. {
  16467. if (!is_array($depArray)) {
  16468. return new DependencyInfo(array(), array());
  16469. }
  16470. if (!$this->isHash($depArray)) {
  16471. return new DependencyInfo($this->buildDependency10Info($depArray), array());
  16472. }
  16473. return $this->buildDependency20Info($depArray);
  16474. }
  16475. private function buildDependency10Info($depArray)
  16476. {
  16477. static $dep10toOperatorMap = array('has' => '==', 'eq' => '==', 'ge' => '>=', 'gt' => '>', 'le' => '<=', 'lt' => '<', 'not' => '!=');
  16478. $result = array();
  16479. foreach ($depArray as $depItem) {
  16480. if (empty($depItem['rel']) || !array_key_exists($depItem['rel'], $dep10toOperatorMap)) {
  16481. continue;
  16482. }
  16483. $depType = !empty($depItem['optional']) && 'yes' == $depItem['optional']
  16484. ? 'optional'
  16485. : 'required';
  16486. $depType = 'not' == $depItem['rel']
  16487. ? 'conflicts'
  16488. : $depType;
  16489. $depVersion = !empty($depItem['version']) ? $this->parseVersion($depItem['version']) : '*';
  16490. $depVersionConstraint = ('has' == $depItem['rel'] || 'not' == $depItem['rel']) && '*' == $depVersion
  16491. ? '*'
  16492. : $dep10toOperatorMap[$depItem['rel']] . $depVersion;
  16493. switch ($depItem['type']) {
  16494. case 'php':
  16495. $depChannelName = 'php';
  16496. $depPackageName = '';
  16497. break;
  16498. case 'pkg':
  16499. $depChannelName = !empty($depItem['channel']) ? $depItem['channel'] : 'pear.php.net';
  16500. $depPackageName = $depItem['name'];
  16501. break;
  16502. case 'ext':
  16503. $depChannelName = 'ext';
  16504. $depPackageName = $depItem['name'];
  16505. break;
  16506. case 'os':
  16507. case 'sapi':
  16508. $depChannelName = '';
  16509. $depPackageName = '';
  16510. break;
  16511. default:
  16512. $depChannelName = '';
  16513. $depPackageName = '';
  16514. break;
  16515. }
  16516. if ('' != $depChannelName) {
  16517. $result[] = new DependencyConstraint(
  16518. $depType,
  16519. $depVersionConstraint,
  16520. $depChannelName,
  16521. $depPackageName
  16522. );
  16523. }
  16524. }
  16525. return $result;
  16526. }
  16527. private function buildDependency20Info($depArray)
  16528. {
  16529. $result = array();
  16530. $optionals = array();
  16531. $defaultOptionals = array();
  16532. foreach ($depArray as $depType => $depTypeGroup) {
  16533. if (!is_array($depTypeGroup)) {
  16534. continue;
  16535. }
  16536. if ('required' == $depType || 'optional' == $depType) {
  16537. foreach ($depTypeGroup as $depItemType => $depItem) {
  16538. switch ($depItemType) {
  16539. case 'php':
  16540. $result[] = new DependencyConstraint(
  16541. $depType,
  16542. $this->parse20VersionConstraint($depItem),
  16543. 'php',
  16544. ''
  16545. );
  16546. break;
  16547. case 'package':
  16548. $deps = $this->buildDepPackageConstraints($depItem, $depType);
  16549. $result = array_merge($result, $deps);
  16550. break;
  16551. case 'extension':
  16552. $deps = $this->buildDepExtensionConstraints($depItem, $depType);
  16553. $result = array_merge($result, $deps);
  16554. break;
  16555. case 'subpackage':
  16556. $deps = $this->buildDepPackageConstraints($depItem, 'replaces');
  16557. $defaultOptionals += $deps;
  16558. break;
  16559. case 'os':
  16560. case 'pearinstaller':
  16561. break;
  16562. default:
  16563. break;
  16564. }
  16565. }
  16566. } elseif ('group' == $depType) {
  16567. if ($this->isHash($depTypeGroup)) {
  16568. $depTypeGroup = array($depTypeGroup);
  16569. }
  16570. foreach ($depTypeGroup as $depItem) {
  16571. $groupName = $depItem['attribs']['name'];
  16572. if (!isset($optionals[$groupName])) {
  16573. $optionals[$groupName] = array();
  16574. }
  16575. if (isset($depItem['subpackage'])) {
  16576. $optionals[$groupName] += $this->buildDepPackageConstraints($depItem['subpackage'], 'replaces');
  16577. } else {
  16578. $result += $this->buildDepPackageConstraints($depItem['package'], 'optional');
  16579. }
  16580. }
  16581. }
  16582. }
  16583. if (count($defaultOptionals) > 0) {
  16584. $optionals['*'] = $defaultOptionals;
  16585. }
  16586. return new DependencyInfo($result, $optionals);
  16587. }
  16588. private function buildDepExtensionConstraints($depItem, $depType)
  16589. {
  16590. if ($this->isHash($depItem)) {
  16591. $depItem = array($depItem);
  16592. }
  16593. $result = array();
  16594. foreach ($depItem as $subDepItem) {
  16595. $depChannelName = 'ext';
  16596. $depPackageName = $subDepItem['name'];
  16597. $depVersionConstraint = $this->parse20VersionConstraint($subDepItem);
  16598. $result[] = new DependencyConstraint(
  16599. $depType,
  16600. $depVersionConstraint,
  16601. $depChannelName,
  16602. $depPackageName
  16603. );
  16604. }
  16605. return $result;
  16606. }
  16607. private function buildDepPackageConstraints($depItem, $depType)
  16608. {
  16609. if ($this->isHash($depItem)) {
  16610. $depItem = array($depItem);
  16611. }
  16612. $result = array();
  16613. foreach ($depItem as $subDepItem) {
  16614. $depChannelName = $subDepItem['channel'];
  16615. $depPackageName = $subDepItem['name'];
  16616. $depVersionConstraint = $this->parse20VersionConstraint($subDepItem);
  16617. if (isset($subDepItem['conflicts'])) {
  16618. $depType = 'conflicts';
  16619. }
  16620. $result[] = new DependencyConstraint(
  16621. $depType,
  16622. $depVersionConstraint,
  16623. $depChannelName,
  16624. $depPackageName
  16625. );
  16626. }
  16627. return $result;
  16628. }
  16629. private function parse20VersionConstraint(array $data)
  16630. {
  16631. static $dep20toOperatorMap = array('has' => '==', 'min' => '>=', 'max' => '<=', 'exclude' => '!=');
  16632. $versions = array();
  16633. $values = array_intersect_key($data, $dep20toOperatorMap);
  16634. if (0 == count($values)) {
  16635. return '*';
  16636. }
  16637. if (isset($values['min']) && isset($values['exclude']) && $data['min'] == $data['exclude']) {
  16638. $versions[] = '>' . $this->parseVersion($values['min']);
  16639. } elseif (isset($values['max']) && isset($values['exclude']) && $data['max'] == $data['exclude']) {
  16640. $versions[] = '<' . $this->parseVersion($values['max']);
  16641. } else {
  16642. foreach ($values as $op => $version) {
  16643. if ('exclude' == $op && is_array($version)) {
  16644. foreach ($version as $versionPart) {
  16645. $versions[] = $dep20toOperatorMap[$op] . $this->parseVersion($versionPart);
  16646. }
  16647. } else {
  16648. $versions[] = $dep20toOperatorMap[$op] . $this->parseVersion($version);
  16649. }
  16650. }
  16651. }
  16652. return implode(',', $versions);
  16653. }
  16654. private function parseVersion($version)
  16655. {
  16656. if (preg_match('{^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?}i', $version, $matches)) {
  16657. $version = $matches[1]
  16658. .(!empty($matches[2]) ? $matches[2] : '.0')
  16659. .(!empty($matches[3]) ? $matches[3] : '.0')
  16660. .(!empty($matches[4]) ? $matches[4] : '.0');
  16661. return $version;
  16662. }
  16663. return null;
  16664. }
  16665. private function isHash(array $array)
  16666. {
  16667. return !array_key_exists(1, $array) && !array_key_exists(0, $array);
  16668. }
  16669. }
  16670. <?php
  16671. namespace Composer\Repository\Pear;
  16672. class PackageInfo
  16673. {
  16674. private $channelName;
  16675. private $packageName;
  16676. private $license;
  16677. private $shortDescription;
  16678. private $description;
  16679. private $releases;
  16680. public function __construct($channelName, $packageName, $license, $shortDescription, $description, $releases)
  16681. {
  16682. $this->channelName = $channelName;
  16683. $this->packageName = $packageName;
  16684. $this->license = $license;
  16685. $this->shortDescription = $shortDescription;
  16686. $this->description = $description;
  16687. $this->releases = $releases;
  16688. }
  16689. public function getChannelName()
  16690. {
  16691. return $this->channelName;
  16692. }
  16693. public function getPackageName()
  16694. {
  16695. return $this->packageName;
  16696. }
  16697. public function getDescription()
  16698. {
  16699. return $this->description;
  16700. }
  16701. public function getShortDescription()
  16702. {
  16703. return $this->shortDescription;
  16704. }
  16705. public function getLicense()
  16706. {
  16707. return $this->license;
  16708. }
  16709. public function getReleases()
  16710. {
  16711. return $this->releases;
  16712. }
  16713. }
  16714. <?php
  16715. namespace Composer\Repository\Pear;
  16716. class ReleaseInfo
  16717. {
  16718. private $stability;
  16719. private $dependencyInfo;
  16720. public function __construct($stability, $dependencyInfo)
  16721. {
  16722. $this->stability = $stability;
  16723. $this->dependencyInfo = $dependencyInfo;
  16724. }
  16725. public function getDependencyInfo()
  16726. {
  16727. return $this->dependencyInfo;
  16728. }
  16729. public function getStability()
  16730. {
  16731. return $this->stability;
  16732. }
  16733. }
  16734. <?php
  16735. namespace Composer\Repository;
  16736. use Composer\IO\IOInterface;
  16737. use Composer\Semver\VersionParser;
  16738. use Composer\Repository\Pear\ChannelReader;
  16739. use Composer\Package\CompletePackage;
  16740. use Composer\Repository\Pear\ChannelInfo;
  16741. use Composer\EventDispatcher\EventDispatcher;
  16742. use Composer\Package\Link;
  16743. use Composer\Semver\Constraint\Constraint;
  16744. use Composer\Util\RemoteFilesystem;
  16745. use Composer\Config;
  16746. class PearRepository extends ArrayRepository
  16747. {
  16748. private $url;
  16749. private $io;
  16750. private $rfs;
  16751. private $versionParser;
  16752. private $vendorAlias;
  16753. public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $dispatcher = null, RemoteFilesystem $rfs = null)
  16754. {
  16755. if (!preg_match('{^https?://}', $repoConfig['url'])) {
  16756. $repoConfig['url'] = 'http://'.$repoConfig['url'];
  16757. }
  16758. $urlBits = parse_url($repoConfig['url']);
  16759. if (empty($urlBits['scheme']) || empty($urlBits['host'])) {
  16760. throw new \UnexpectedValueException('Invalid url given for PEAR repository: '.$repoConfig['url']);
  16761. }
  16762. $this->url = rtrim($repoConfig['url'], '/');
  16763. $this->io = $io;
  16764. $this->rfs = $rfs ?: new RemoteFilesystem($this->io, $config);
  16765. $this->vendorAlias = isset($repoConfig['vendor-alias']) ? $repoConfig['vendor-alias'] : null;
  16766. $this->versionParser = new VersionParser();
  16767. }
  16768. protected function initialize()
  16769. {
  16770. parent::initialize();
  16771. $this->io->writeError('Initializing PEAR repository '.$this->url);
  16772. $reader = new ChannelReader($this->rfs);
  16773. try {
  16774. $channelInfo = $reader->read($this->url);
  16775. } catch (\Exception $e) {
  16776. $this->io->writeError('<warning>PEAR repository from '.$this->url.' could not be loaded. '.$e->getMessage().'</warning>');
  16777. return;
  16778. }
  16779. $packages = $this->buildComposerPackages($channelInfo, $this->versionParser);
  16780. foreach ($packages as $package) {
  16781. $this->addPackage($package);
  16782. }
  16783. }
  16784. private function buildComposerPackages(ChannelInfo $channelInfo, VersionParser $versionParser)
  16785. {
  16786. $result = array();
  16787. foreach ($channelInfo->getPackages() as $packageDefinition) {
  16788. foreach ($packageDefinition->getReleases() as $version => $releaseInfo) {
  16789. try {
  16790. $normalizedVersion = $versionParser->normalize($version);
  16791. } catch (\UnexpectedValueException $e) {
  16792. if ($this->io->isVerbose()) {
  16793. $this->io->writeError('Could not load '.$packageDefinition->getPackageName().' '.$version.': '.$e->getMessage());
  16794. }
  16795. continue;
  16796. }
  16797. $composerPackageName = $this->buildComposerPackageName($packageDefinition->getChannelName(), $packageDefinition->getPackageName());
  16798. $urlBits = parse_url($this->url);
  16799. $scheme = (isset($urlBits['scheme']) && 'https' === $urlBits['scheme'] && extension_loaded('openssl')) ? 'https' : 'http';
  16800. $distUrl = "{$scheme}://{$packageDefinition->getChannelName()}/get/{$packageDefinition->getPackageName()}-{$version}.tgz";
  16801. $requires = array();
  16802. $suggests = array();
  16803. $conflicts = array();
  16804. $replaces = array();
  16805. if ($channelInfo->getName() == $packageDefinition->getChannelName()) {
  16806. $composerPackageAlias = $this->buildComposerPackageName($channelInfo->getAlias(), $packageDefinition->getPackageName());
  16807. $aliasConstraint = new Constraint('==', $normalizedVersion);
  16808. $replaces[] = new Link($composerPackageName, $composerPackageAlias, $aliasConstraint, 'replaces', (string) $aliasConstraint);
  16809. }
  16810. if (!empty($this->vendorAlias)
  16811. && ($this->vendorAlias != 'pear-'.$channelInfo->getAlias() || $channelInfo->getName() != $packageDefinition->getChannelName())
  16812. ) {
  16813. $composerPackageAlias = "{$this->vendorAlias}/{$packageDefinition->getPackageName()}";
  16814. $aliasConstraint = new Constraint('==', $normalizedVersion);
  16815. $replaces[] = new Link($composerPackageName, $composerPackageAlias, $aliasConstraint, 'replaces', (string) $aliasConstraint);
  16816. }
  16817. foreach ($releaseInfo->getDependencyInfo()->getRequires() as $dependencyConstraint) {
  16818. $dependencyPackageName = $this->buildComposerPackageName($dependencyConstraint->getChannelName(), $dependencyConstraint->getPackageName());
  16819. $constraint = $versionParser->parseConstraints($dependencyConstraint->getConstraint());
  16820. $link = new Link($composerPackageName, $dependencyPackageName, $constraint, $dependencyConstraint->getType(), $dependencyConstraint->getConstraint());
  16821. switch ($dependencyConstraint->getType()) {
  16822. case 'required':
  16823. $requires[] = $link;
  16824. break;
  16825. case 'conflicts':
  16826. $conflicts[] = $link;
  16827. break;
  16828. case 'replaces':
  16829. $replaces[] = $link;
  16830. break;
  16831. }
  16832. }
  16833. foreach ($releaseInfo->getDependencyInfo()->getOptionals() as $group => $dependencyConstraints) {
  16834. foreach ($dependencyConstraints as $dependencyConstraint) {
  16835. $dependencyPackageName = $this->buildComposerPackageName($dependencyConstraint->getChannelName(), $dependencyConstraint->getPackageName());
  16836. $suggests[$group.'-'.$dependencyPackageName] = $dependencyConstraint->getConstraint();
  16837. }
  16838. }
  16839. $package = new CompletePackage($composerPackageName, $normalizedVersion, $version);
  16840. $package->setType('pear-library');
  16841. $package->setDescription($packageDefinition->getDescription());
  16842. $package->setLicense(array($packageDefinition->getLicense()));
  16843. $package->setDistType('file');
  16844. $package->setDistUrl($distUrl);
  16845. $package->setAutoload(array('classmap' => array('')));
  16846. $package->setIncludePaths(array('/'));
  16847. $package->setRequires($requires);
  16848. $package->setConflicts($conflicts);
  16849. $package->setSuggests($suggests);
  16850. $package->setReplaces($replaces);
  16851. $result[] = $package;
  16852. }
  16853. }
  16854. return $result;
  16855. }
  16856. private function buildComposerPackageName($channelName, $packageName)
  16857. {
  16858. if ('php' === $channelName) {
  16859. return "php";
  16860. }
  16861. if ('ext' === $channelName) {
  16862. return "ext-{$packageName}";
  16863. }
  16864. return "pear-{$channelName}/{$packageName}";
  16865. }
  16866. }
  16867. <?php
  16868. namespace Composer\Repository;
  16869. use Composer\Config;
  16870. use Composer\Package\PackageInterface;
  16871. use Composer\Package\CompletePackage;
  16872. use Composer\Semver\VersionParser;
  16873. use Composer\Plugin\PluginInterface;
  16874. class PlatformRepository extends ArrayRepository
  16875. {
  16876. const PLATFORM_PACKAGE_REGEX = '{^(?:php(?:-64bit)?|hhvm|(?:ext|lib)-[^/]+)$}i';
  16877. private $overrides = array();
  16878. public function __construct(array $packages = array(), array $overrides = array())
  16879. {
  16880. foreach ($overrides as $name => $version) {
  16881. $this->overrides[strtolower($name)] = array('name' => $name, 'version' => $version);
  16882. }
  16883. parent::__construct($packages);
  16884. }
  16885. protected function initialize()
  16886. {
  16887. parent::initialize();
  16888. $versionParser = new VersionParser();
  16889. foreach ($this->overrides as $override) {
  16890. if (!preg_match(self::PLATFORM_PACKAGE_REGEX, $override['name'])) {
  16891. throw new \InvalidArgumentException('Invalid platform package name in config.platform: '.$override['name']);
  16892. }
  16893. $version = $versionParser->normalize($override['version']);
  16894. $package = new CompletePackage($override['name'], $version, $override['version']);
  16895. $package->setDescription('Overridden virtual platform package '.$override['name']);
  16896. parent::addPackage($package);
  16897. }
  16898. $prettyVersion = PluginInterface::PLUGIN_API_VERSION;
  16899. $version = $versionParser->normalize($prettyVersion);
  16900. $composerPluginApi = new CompletePackage('composer-plugin-api', $version, $prettyVersion);
  16901. $composerPluginApi->setDescription('The Composer Plugin API');
  16902. $this->addPackage($composerPluginApi);
  16903. try {
  16904. $prettyVersion = PHP_VERSION;
  16905. $version = $versionParser->normalize($prettyVersion);
  16906. } catch (\UnexpectedValueException $e) {
  16907. $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', PHP_VERSION);
  16908. $version = $versionParser->normalize($prettyVersion);
  16909. }
  16910. $php = new CompletePackage('php', $version, $prettyVersion);
  16911. $php->setDescription('The PHP interpreter');
  16912. $this->addPackage($php);
  16913. if (PHP_INT_SIZE === 8) {
  16914. $php64 = new CompletePackage('php-64bit', $version, $prettyVersion);
  16915. $php64->setDescription('The PHP interpreter (64bit)');
  16916. $this->addPackage($php64);
  16917. }
  16918. $loadedExtensions = get_loaded_extensions();
  16919. foreach ($loadedExtensions as $name) {
  16920. if (in_array($name, array('standard', 'Core'))) {
  16921. continue;
  16922. }
  16923. $reflExt = new \ReflectionExtension($name);
  16924. try {
  16925. $prettyVersion = $reflExt->getVersion();
  16926. $version = $versionParser->normalize($prettyVersion);
  16927. } catch (\UnexpectedValueException $e) {
  16928. $prettyVersion = '0';
  16929. $version = $versionParser->normalize($prettyVersion);
  16930. }
  16931. $packageName = $this->buildPackageName($name);
  16932. $ext = new CompletePackage($packageName, $version, $prettyVersion);
  16933. $ext->setDescription('The '.$name.' PHP extension');
  16934. $this->addPackage($ext);
  16935. }
  16936. foreach ($loadedExtensions as $name) {
  16937. $prettyVersion = null;
  16938. switch ($name) {
  16939. case 'curl':
  16940. $curlVersion = curl_version();
  16941. $prettyVersion = $curlVersion['version'];
  16942. break;
  16943. case 'iconv':
  16944. $prettyVersion = ICONV_VERSION;
  16945. break;
  16946. case 'intl':
  16947. $name = 'ICU';
  16948. if (defined('INTL_ICU_VERSION')) {
  16949. $prettyVersion = INTL_ICU_VERSION;
  16950. } else {
  16951. $reflector = new \ReflectionExtension('intl');
  16952. ob_start();
  16953. $reflector->info();
  16954. $output = ob_get_clean();
  16955. preg_match('/^ICU version => (.*)$/m', $output, $matches);
  16956. $prettyVersion = $matches[1];
  16957. }
  16958. break;
  16959. case 'libxml':
  16960. $prettyVersion = LIBXML_DOTTED_VERSION;
  16961. break;
  16962. case 'openssl':
  16963. $prettyVersion = preg_replace_callback('{^(?:OpenSSL\s*)?([0-9.]+)([a-z]?).*}', function ($match) {
  16964. return $match[1] . (empty($match[2]) ? '' : '.'.(ord($match[2]) - 96));
  16965. }, OPENSSL_VERSION_TEXT);
  16966. break;
  16967. case 'pcre':
  16968. $prettyVersion = preg_replace('{^(\S+).*}', '$1', PCRE_VERSION);
  16969. break;
  16970. case 'uuid':
  16971. $prettyVersion = phpversion('uuid');
  16972. break;
  16973. case 'xsl':
  16974. $prettyVersion = LIBXSLT_DOTTED_VERSION;
  16975. break;
  16976. default:
  16977. continue 2;
  16978. }
  16979. try {
  16980. $version = $versionParser->normalize($prettyVersion);
  16981. } catch (\UnexpectedValueException $e) {
  16982. continue;
  16983. }
  16984. $lib = new CompletePackage('lib-'.$name, $version, $prettyVersion);
  16985. $lib->setDescription('The '.$name.' PHP library');
  16986. $this->addPackage($lib);
  16987. }
  16988. if (defined('HHVM_VERSION')) {
  16989. try {
  16990. $prettyVersion = HHVM_VERSION;
  16991. $version = $versionParser->normalize($prettyVersion);
  16992. } catch (\UnexpectedValueException $e) {
  16993. $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', HHVM_VERSION);
  16994. $version = $versionParser->normalize($prettyVersion);
  16995. }
  16996. $hhvm = new CompletePackage('hhvm', $version, $prettyVersion);
  16997. $hhvm->setDescription('The HHVM Runtime (64bit)');
  16998. $this->addPackage($hhvm);
  16999. }
  17000. }
  17001. public function addPackage(PackageInterface $package)
  17002. {
  17003. if (isset($this->overrides[strtolower($package->getName())])) {
  17004. return;
  17005. }
  17006. parent::addPackage($package);
  17007. }
  17008. private function buildPackageName($name)
  17009. {
  17010. return 'ext-' . str_replace(' ', '-', $name);
  17011. }
  17012. }
  17013. <?php
  17014. namespace Composer\Repository;
  17015. use Composer\Package\PackageInterface;
  17016. interface RepositoryInterface extends \Countable
  17017. {
  17018. const SEARCH_FULLTEXT = 0;
  17019. const SEARCH_NAME = 1;
  17020. public function hasPackage(PackageInterface $package);
  17021. public function findPackage($name, $constraint);
  17022. public function findPackages($name, $constraint = null);
  17023. public function getPackages();
  17024. public function search($query, $mode = 0);
  17025. }
  17026. <?php
  17027. namespace Composer\Repository;
  17028. use Composer\IO\IOInterface;
  17029. use Composer\Config;
  17030. use Composer\EventDispatcher\EventDispatcher;
  17031. use Composer\Package\PackageInterface;
  17032. class RepositoryManager
  17033. {
  17034. private $localRepository;
  17035. private $repositories = array();
  17036. private $repositoryClasses = array();
  17037. private $io;
  17038. private $config;
  17039. private $eventDispatcher;
  17040. public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null)
  17041. {
  17042. $this->io = $io;
  17043. $this->config = $config;
  17044. $this->eventDispatcher = $eventDispatcher;
  17045. }
  17046. public function findPackage($name, $constraint)
  17047. {
  17048. foreach ($this->repositories as $repository) {
  17049. if ($package = $repository->findPackage($name, $constraint)) {
  17050. return $package;
  17051. }
  17052. }
  17053. }
  17054. public function findPackages($name, $constraint)
  17055. {
  17056. $packages = array();
  17057. foreach ($this->repositories as $repository) {
  17058. $packages = array_merge($packages, $repository->findPackages($name, $constraint));
  17059. }
  17060. return $packages;
  17061. }
  17062. public function addRepository(RepositoryInterface $repository)
  17063. {
  17064. $this->repositories[] = $repository;
  17065. }
  17066. public function createRepository($type, $config)
  17067. {
  17068. if (!isset($this->repositoryClasses[$type])) {
  17069. throw new \InvalidArgumentException('Repository type is not registered: '.$type);
  17070. }
  17071. $class = $this->repositoryClasses[$type];
  17072. return new $class($config, $this->io, $this->config, $this->eventDispatcher);
  17073. }
  17074. public function setRepositoryClass($type, $class)
  17075. {
  17076. $this->repositoryClasses[$type] = $class;
  17077. }
  17078. public function getRepositories()
  17079. {
  17080. return $this->repositories;
  17081. }
  17082. public function setLocalRepository(WritableRepositoryInterface $repository)
  17083. {
  17084. $this->localRepository = $repository;
  17085. }
  17086. public function getLocalRepository()
  17087. {
  17088. return $this->localRepository;
  17089. }
  17090. public function getLocalRepositories()
  17091. {
  17092. trigger_error('This method is deprecated, use getLocalRepository instead since the getLocalDevRepository is now gone', E_USER_DEPRECATED);
  17093. return array($this->localRepository);
  17094. }
  17095. }
  17096. <?php
  17097. namespace Composer\Repository;
  17098. class RepositorySecurityException extends \Exception
  17099. {
  17100. }
  17101. <?php
  17102. namespace Composer\Repository\Vcs;
  17103. use Composer\Config;
  17104. use Composer\Json\JsonFile;
  17105. use Composer\IO\IOInterface;
  17106. class GitBitbucketDriver extends VcsDriver implements VcsDriverInterface
  17107. {
  17108. protected $owner;
  17109. protected $repository;
  17110. protected $tags;
  17111. protected $branches;
  17112. protected $rootIdentifier;
  17113. protected $infoCache = array();
  17114. public function initialize()
  17115. {
  17116. preg_match('#^https?://bitbucket\.org/([^/]+)/(.+?)\.git$#', $this->url, $match);
  17117. $this->owner = $match[1];
  17118. $this->repository = $match[2];
  17119. $this->originUrl = 'bitbucket.org';
  17120. }
  17121. public function getRootIdentifier()
  17122. {
  17123. if (null === $this->rootIdentifier) {
  17124. $resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/'.$this->owner.'/'.$this->repository;
  17125. $repoData = JsonFile::parseJson($this->getContents($resource), $resource);
  17126. $this->rootIdentifier = !empty($repoData['main_branch']) ? $repoData['main_branch'] : 'master';
  17127. }
  17128. return $this->rootIdentifier;
  17129. }
  17130. public function getUrl()
  17131. {
  17132. return $this->url;
  17133. }
  17134. public function getSource($identifier)
  17135. {
  17136. return array('type' => 'git', 'url' => $this->getUrl(), 'reference' => $identifier);
  17137. }
  17138. public function getDist($identifier)
  17139. {
  17140. $url = $this->getScheme() . '://bitbucket.org/'.$this->owner.'/'.$this->repository.'/get/'.$identifier.'.zip';
  17141. return array('type' => 'zip', 'url' => $url, 'reference' => $identifier, 'shasum' => '');
  17142. }
  17143. public function getComposerInformation($identifier)
  17144. {
  17145. if (!isset($this->infoCache[$identifier])) {
  17146. $resource = $this->getScheme() . '://bitbucket.org/'.$this->owner.'/'.$this->repository.'/raw/'.$identifier.'/composer.json';
  17147. $composer = $this->getContents($resource);
  17148. if (!$composer) {
  17149. return;
  17150. }
  17151. $composer = JsonFile::parseJson($composer, $resource);
  17152. if (empty($composer['time'])) {
  17153. $resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/'.$this->owner.'/'.$this->repository.'/changesets/'.$identifier;
  17154. $changeset = JsonFile::parseJson($this->getContents($resource), $resource);
  17155. $composer['time'] = $changeset['timestamp'];
  17156. }
  17157. $this->infoCache[$identifier] = $composer;
  17158. }
  17159. return $this->infoCache[$identifier];
  17160. }
  17161. public function getTags()
  17162. {
  17163. if (null === $this->tags) {
  17164. $resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/'.$this->owner.'/'.$this->repository.'/tags';
  17165. $tagsData = JsonFile::parseJson($this->getContents($resource), $resource);
  17166. $this->tags = array();
  17167. foreach ($tagsData as $tag => $data) {
  17168. $this->tags[$tag] = $data['raw_node'];
  17169. }
  17170. }
  17171. return $this->tags;
  17172. }
  17173. public function getBranches()
  17174. {
  17175. if (null === $this->branches) {
  17176. $resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/'.$this->owner.'/'.$this->repository.'/branches';
  17177. $branchData = JsonFile::parseJson($this->getContents($resource), $resource);
  17178. $this->branches = array();
  17179. foreach ($branchData as $branch => $data) {
  17180. $this->branches[$branch] = $data['raw_node'];
  17181. }
  17182. }
  17183. return $this->branches;
  17184. }
  17185. public static function supports(IOInterface $io, Config $config, $url, $deep = false)
  17186. {
  17187. if (!preg_match('#^https?://bitbucket\.org/([^/]+)/(.+?)\.git$#', $url)) {
  17188. return false;
  17189. }
  17190. if (!extension_loaded('openssl')) {
  17191. if ($io->isVerbose()) {
  17192. $io->writeError('Skipping Bitbucket git driver for '.$url.' because the OpenSSL PHP extension is missing.');
  17193. }
  17194. return false;
  17195. }
  17196. return true;
  17197. }
  17198. }
  17199. <?php
  17200. namespace Composer\Repository\Vcs;
  17201. use Composer\Json\JsonFile;
  17202. use Composer\Util\ProcessExecutor;
  17203. use Composer\Util\Filesystem;
  17204. use Composer\Util\Git as GitUtil;
  17205. use Composer\IO\IOInterface;
  17206. use Composer\Cache;
  17207. use Composer\Config;
  17208. class GitDriver extends VcsDriver
  17209. {
  17210. protected $cache;
  17211. protected $tags;
  17212. protected $branches;
  17213. protected $rootIdentifier;
  17214. protected $repoDir;
  17215. protected $infoCache = array();
  17216. public function initialize()
  17217. {
  17218. if (Filesystem::isLocalPath($this->url)) {
  17219. $this->repoDir = $this->url;
  17220. $cacheUrl = realpath($this->url);
  17221. } else {
  17222. $this->repoDir = $this->config->get('cache-vcs-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $this->url) . '/';
  17223. GitUtil::cleanEnv();
  17224. $fs = new Filesystem();
  17225. $fs->ensureDirectoryExists(dirname($this->repoDir));
  17226. if (!is_writable(dirname($this->repoDir))) {
  17227. throw new \RuntimeException('Can not clone '.$this->url.' to access package information. The "'.dirname($this->repoDir).'" directory is not writable by the current user.');
  17228. }
  17229. if (preg_match('{^ssh://[^@]+@[^:]+:[^0-9]+}', $this->url)) {
  17230. throw new \InvalidArgumentException('The source URL '.$this->url.' is invalid, ssh URLs should have a port number after ":".'."\n".'Use ssh://git@example.com:22/path or just git@example.com:path if you do not want to provide a password or custom port.');
  17231. }
  17232. $gitUtil = new GitUtil($this->io, $this->config, $this->process, $fs);
  17233. if (is_dir($this->repoDir) && 0 === $this->process->execute('git rev-parse --git-dir', $output, $this->repoDir) && trim($output) === '.') {
  17234. try {
  17235. $commandCallable = function ($url) {
  17236. return sprintf('git remote set-url origin %s && git remote update --prune origin', ProcessExecutor::escape($url));
  17237. };
  17238. $gitUtil->runCommand($commandCallable, $this->url, $this->repoDir);
  17239. } catch (\Exception $e) {
  17240. $this->io->writeError('<error>Failed to update '.$this->url.', package information from this repository may be outdated ('.$e->getMessage().')</error>');
  17241. }
  17242. } else {
  17243. $fs->removeDirectory($this->repoDir);
  17244. $repoDir = $this->repoDir;
  17245. $commandCallable = function ($url) use ($repoDir) {
  17246. return sprintf('git clone --mirror %s %s', ProcessExecutor::escape($url), ProcessExecutor::escape($repoDir));
  17247. };
  17248. $gitUtil->runCommand($commandCallable, $this->url, $this->repoDir, true);
  17249. }
  17250. $cacheUrl = $this->url;
  17251. }
  17252. $this->getTags();
  17253. $this->getBranches();
  17254. $this->cache = new Cache($this->io, $this->config->get('cache-repo-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $cacheUrl));
  17255. }
  17256. public function getRootIdentifier()
  17257. {
  17258. if (null === $this->rootIdentifier) {
  17259. $this->rootIdentifier = 'master';
  17260. $this->process->execute('git branch --no-color', $output, $this->repoDir);
  17261. $branches = $this->process->splitLines($output);
  17262. if (!in_array('* master', $branches)) {
  17263. foreach ($branches as $branch) {
  17264. if ($branch && preg_match('{^\* +(\S+)}', $branch, $match)) {
  17265. $this->rootIdentifier = $match[1];
  17266. break;
  17267. }
  17268. }
  17269. }
  17270. }
  17271. return $this->rootIdentifier;
  17272. }
  17273. public function getUrl()
  17274. {
  17275. return $this->url;
  17276. }
  17277. public function getSource($identifier)
  17278. {
  17279. return array('type' => 'git', 'url' => $this->getUrl(), 'reference' => $identifier);
  17280. }
  17281. public function getDist($identifier)
  17282. {
  17283. return null;
  17284. }
  17285. public function getComposerInformation($identifier)
  17286. {
  17287. if (preg_match('{[a-f0-9]{40}}i', $identifier) && $res = $this->cache->read($identifier)) {
  17288. $this->infoCache[$identifier] = JsonFile::parseJson($res);
  17289. }
  17290. if (!isset($this->infoCache[$identifier])) {
  17291. $resource = sprintf('%s:composer.json', ProcessExecutor::escape($identifier));
  17292. $this->process->execute(sprintf('git show %s', $resource), $composer, $this->repoDir);
  17293. if (!trim($composer)) {
  17294. return;
  17295. }
  17296. $composer = JsonFile::parseJson($composer, $resource);
  17297. if (empty($composer['time'])) {
  17298. $this->process->execute(sprintf('git log -1 --format=%%at %s', ProcessExecutor::escape($identifier)), $output, $this->repoDir);
  17299. $date = new \DateTime('@'.trim($output), new \DateTimeZone('UTC'));
  17300. $composer['time'] = $date->format('Y-m-d H:i:s');
  17301. }
  17302. if (preg_match('{[a-f0-9]{40}}i', $identifier)) {
  17303. $this->cache->write($identifier, json_encode($composer));
  17304. }
  17305. $this->infoCache[$identifier] = $composer;
  17306. }
  17307. return $this->infoCache[$identifier];
  17308. }
  17309. public function getTags()
  17310. {
  17311. if (null === $this->tags) {
  17312. $this->tags = array();
  17313. $this->process->execute('git show-ref --tags', $output, $this->repoDir);
  17314. foreach ($output = $this->process->splitLines($output) as $tag) {
  17315. if ($tag && preg_match('{^([a-f0-9]{40}) refs/tags/(\S+)$}', $tag, $match)) {
  17316. $this->tags[$match[2]] = $match[1];
  17317. }
  17318. }
  17319. }
  17320. return $this->tags;
  17321. }
  17322. public function getBranches()
  17323. {
  17324. if (null === $this->branches) {
  17325. $branches = array();
  17326. $this->process->execute('git branch --no-color --no-abbrev -v', $output, $this->repoDir);
  17327. foreach ($this->process->splitLines($output) as $branch) {
  17328. if ($branch && !preg_match('{^ *[^/]+/HEAD }', $branch)) {
  17329. if (preg_match('{^(?:\* )? *(\S+) *([a-f0-9]+)(?: .*)?$}', $branch, $match)) {
  17330. $branches[$match[1]] = $match[2];
  17331. }
  17332. }
  17333. }
  17334. $this->branches = $branches;
  17335. }
  17336. return $this->branches;
  17337. }
  17338. public static function supports(IOInterface $io, Config $config, $url, $deep = false)
  17339. {
  17340. if (preg_match('#(^git://|\.git$|git(?:olite)?@|//git\.|//github.com/)#i', $url)) {
  17341. return true;
  17342. }
  17343. if (Filesystem::isLocalPath($url)) {
  17344. $url = Filesystem::getPlatformPath($url);
  17345. if (!is_dir($url)) {
  17346. return false;
  17347. }
  17348. $process = new ProcessExecutor($io);
  17349. if ($process->execute('git tag', $output, $url) === 0) {
  17350. return true;
  17351. }
  17352. }
  17353. if (!$deep) {
  17354. return false;
  17355. }
  17356. $process = new ProcessExecutor($io);
  17357. if ($process->execute('git ls-remote --heads ' . ProcessExecutor::escape($url), $output) === 0) {
  17358. return true;
  17359. }
  17360. return false;
  17361. }
  17362. }
  17363. <?php
  17364. namespace Composer\Repository\Vcs;
  17365. use Composer\Config;
  17366. use Composer\Downloader\TransportException;
  17367. use Composer\Json\JsonFile;
  17368. use Composer\Cache;
  17369. use Composer\IO\IOInterface;
  17370. use Composer\Util\GitHub;
  17371. class GitHubDriver extends VcsDriver
  17372. {
  17373. protected $cache;
  17374. protected $owner;
  17375. protected $repository;
  17376. protected $tags;
  17377. protected $branches;
  17378. protected $rootIdentifier;
  17379. protected $hasIssues;
  17380. protected $infoCache = array();
  17381. protected $isPrivate = false;
  17382. protected $gitDriver;
  17383. public function initialize()
  17384. {
  17385. preg_match('#^(?:(?:https?|git)://([^/]+)/|git@([^:]+):)([^/]+)/(.+?)(?:\.git|/)?$#', $this->url, $match);
  17386. $this->owner = $match[3];
  17387. $this->repository = $match[4];
  17388. $this->originUrl = !empty($match[1]) ? $match[1] : $match[2];
  17389. if ($this->originUrl === 'www.github.com') {
  17390. $this->originUrl = 'github.com';
  17391. }
  17392. $this->cache = new Cache($this->io, $this->config->get('cache-repo-dir').'/'.$this->originUrl.'/'.$this->owner.'/'.$this->repository);
  17393. if (isset($this->repoConfig['no-api']) && $this->repoConfig['no-api']) {
  17394. $this->setupGitDriver($this->url);
  17395. return;
  17396. }
  17397. $this->fetchRootIdentifier();
  17398. }
  17399. public function getRepositoryUrl()
  17400. {
  17401. return 'https://'.$this->originUrl.'/'.$this->owner.'/'.$this->repository;
  17402. }
  17403. public function getRootIdentifier()
  17404. {
  17405. if ($this->gitDriver) {
  17406. return $this->gitDriver->getRootIdentifier();
  17407. }
  17408. return $this->rootIdentifier;
  17409. }
  17410. public function getUrl()
  17411. {
  17412. if ($this->gitDriver) {
  17413. return $this->gitDriver->getUrl();
  17414. }
  17415. return 'https://' . $this->originUrl . '/'.$this->owner.'/'.$this->repository.'.git';
  17416. }
  17417. protected function getApiUrl()
  17418. {
  17419. if ('github.com' === $this->originUrl) {
  17420. $apiUrl = 'api.github.com';
  17421. } else {
  17422. $apiUrl = $this->originUrl . '/api/v3';
  17423. }
  17424. return 'https://' . $apiUrl;
  17425. }
  17426. public function getSource($identifier)
  17427. {
  17428. if ($this->gitDriver) {
  17429. return $this->gitDriver->getSource($identifier);
  17430. }
  17431. if ($this->isPrivate) {
  17432. $url = $this->generateSshUrl();
  17433. } else {
  17434. $url = $this->getUrl();
  17435. }
  17436. return array('type' => 'git', 'url' => $url, 'reference' => $identifier);
  17437. }
  17438. public function getDist($identifier)
  17439. {
  17440. $url = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository.'/zipball/'.$identifier;
  17441. return array('type' => 'zip', 'url' => $url, 'reference' => $identifier, 'shasum' => '');
  17442. }
  17443. public function getComposerInformation($identifier)
  17444. {
  17445. if ($this->gitDriver) {
  17446. return $this->gitDriver->getComposerInformation($identifier);
  17447. }
  17448. if (preg_match('{[a-f0-9]{40}}i', $identifier) && $res = $this->cache->read($identifier)) {
  17449. $this->infoCache[$identifier] = JsonFile::parseJson($res);
  17450. }
  17451. if (!isset($this->infoCache[$identifier])) {
  17452. $notFoundRetries = 2;
  17453. while ($notFoundRetries) {
  17454. try {
  17455. $resource = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository.'/contents/composer.json?ref='.urlencode($identifier);
  17456. $composer = JsonFile::parseJson($this->getContents($resource));
  17457. if (empty($composer['content']) || $composer['encoding'] !== 'base64' || !($composer = base64_decode($composer['content']))) {
  17458. throw new \RuntimeException('Could not retrieve composer.json from '.$resource);
  17459. }
  17460. break;
  17461. } catch (TransportException $e) {
  17462. if (404 !== $e->getCode()) {
  17463. throw $e;
  17464. }
  17465. $notFoundRetries--;
  17466. $composer = false;
  17467. }
  17468. }
  17469. if ($composer) {
  17470. $composer = JsonFile::parseJson($composer, $resource);
  17471. if (empty($composer['time'])) {
  17472. $resource = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository.'/commits/'.urlencode($identifier);
  17473. $commit = JsonFile::parseJson($this->getContents($resource), $resource);
  17474. $composer['time'] = $commit['commit']['committer']['date'];
  17475. }
  17476. if (!isset($composer['support']['source'])) {
  17477. $label = array_search($identifier, $this->getTags()) ?: array_search($identifier, $this->getBranches()) ?: $identifier;
  17478. $composer['support']['source'] = sprintf('https://%s/%s/%s/tree/%s', $this->originUrl, $this->owner, $this->repository, $label);
  17479. }
  17480. if (!isset($composer['support']['issues']) && $this->hasIssues) {
  17481. $composer['support']['issues'] = sprintf('https://%s/%s/%s/issues', $this->originUrl, $this->owner, $this->repository);
  17482. }
  17483. }
  17484. if (preg_match('{[a-f0-9]{40}}i', $identifier)) {
  17485. $this->cache->write($identifier, json_encode($composer));
  17486. }
  17487. $this->infoCache[$identifier] = $composer;
  17488. }
  17489. return $this->infoCache[$identifier];
  17490. }
  17491. public function getTags()
  17492. {
  17493. if ($this->gitDriver) {
  17494. return $this->gitDriver->getTags();
  17495. }
  17496. if (null === $this->tags) {
  17497. $this->tags = array();
  17498. $resource = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository.'/tags?per_page=100';
  17499. do {
  17500. $tagsData = JsonFile::parseJson($this->getContents($resource), $resource);
  17501. foreach ($tagsData as $tag) {
  17502. $this->tags[$tag['name']] = $tag['commit']['sha'];
  17503. }
  17504. $resource = $this->getNextPage();
  17505. } while ($resource);
  17506. }
  17507. return $this->tags;
  17508. }
  17509. public function getBranches()
  17510. {
  17511. if ($this->gitDriver) {
  17512. return $this->gitDriver->getBranches();
  17513. }
  17514. if (null === $this->branches) {
  17515. $this->branches = array();
  17516. $resource = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository.'/git/refs/heads?per_page=100';
  17517. $branchBlacklist = array('gh-pages');
  17518. do {
  17519. $branchData = JsonFile::parseJson($this->getContents($resource), $resource);
  17520. foreach ($branchData as $branch) {
  17521. $name = substr($branch['ref'], 11);
  17522. if (!in_array($name, $branchBlacklist)) {
  17523. $this->branches[$name] = $branch['object']['sha'];
  17524. }
  17525. }
  17526. $resource = $this->getNextPage();
  17527. } while ($resource);
  17528. }
  17529. return $this->branches;
  17530. }
  17531. public static function supports(IOInterface $io, Config $config, $url, $deep = false)
  17532. {
  17533. if (!preg_match('#^((?:https?|git)://([^/]+)/|git@([^:]+):)([^/]+)/(.+?)(?:\.git|/)?$#', $url, $matches)) {
  17534. return false;
  17535. }
  17536. $originUrl = !empty($matches[2]) ? $matches[2] : $matches[3];
  17537. if (!in_array(preg_replace('{^www\.}i', '', $originUrl), $config->get('github-domains'))) {
  17538. return false;
  17539. }
  17540. if (!extension_loaded('openssl')) {
  17541. if ($io->isVerbose()) {
  17542. $io->writeError('Skipping GitHub driver for '.$url.' because the OpenSSL PHP extension is missing.');
  17543. }
  17544. return false;
  17545. }
  17546. return true;
  17547. }
  17548. protected function generateSshUrl()
  17549. {
  17550. return 'git@' . $this->originUrl . ':'.$this->owner.'/'.$this->repository.'.git';
  17551. }
  17552. protected function getContents($url, $fetchingRepoData = false)
  17553. {
  17554. try {
  17555. return parent::getContents($url);
  17556. } catch (TransportException $e) {
  17557. $gitHubUtil = new GitHub($this->io, $this->config, $this->process, $this->remoteFilesystem);
  17558. switch ($e->getCode()) {
  17559. case 401:
  17560. case 404:
  17561. if (!$fetchingRepoData) {
  17562. throw $e;
  17563. }
  17564. if ($gitHubUtil->authorizeOAuth($this->originUrl)) {
  17565. return parent::getContents($url);
  17566. }
  17567. if (!$this->io->isInteractive()) {
  17568. return $this->attemptCloneFallback();
  17569. }
  17570. $gitHubUtil->authorizeOAuthInteractively($this->originUrl, 'Your GitHub credentials are required to fetch private repository metadata (<info>'.$this->url.'</info>)');
  17571. return parent::getContents($url);
  17572. case 403:
  17573. if (!$this->io->hasAuthentication($this->originUrl) && $gitHubUtil->authorizeOAuth($this->originUrl)) {
  17574. return parent::getContents($url);
  17575. }
  17576. if (!$this->io->isInteractive() && $fetchingRepoData) {
  17577. return $this->attemptCloneFallback();
  17578. }
  17579. $rateLimited = false;
  17580. foreach ($e->getHeaders() as $header) {
  17581. if (preg_match('{^X-RateLimit-Remaining: *0$}i', trim($header))) {
  17582. $rateLimited = true;
  17583. }
  17584. }
  17585. if (!$this->io->hasAuthentication($this->originUrl)) {
  17586. if (!$this->io->isInteractive()) {
  17587. $this->io->writeError('<error>GitHub API limit exhausted. Failed to get metadata for the '.$this->url.' repository, try running in interactive mode so that you can enter your GitHub credentials to increase the API limit</error>');
  17588. throw $e;
  17589. }
  17590. $gitHubUtil->authorizeOAuthInteractively($this->originUrl, 'API limit exhausted. Enter your GitHub credentials to get a larger API limit (<info>'.$this->url.'</info>)');
  17591. return parent::getContents($url);
  17592. }
  17593. if ($rateLimited) {
  17594. $rateLimit = $this->getRateLimit($e->getHeaders());
  17595. $this->io->writeError(sprintf(
  17596. '<error>GitHub API limit (%d calls/hr) is exhausted. You are already authorized so you have to wait until %s before doing more requests</error>',
  17597. $rateLimit['limit'],
  17598. $rateLimit['reset']
  17599. ));
  17600. }
  17601. throw $e;
  17602. default:
  17603. throw $e;
  17604. }
  17605. }
  17606. }
  17607. protected function getRateLimit(array $headers)
  17608. {
  17609. $rateLimit = array(
  17610. 'limit' => '?',
  17611. 'reset' => '?',
  17612. );
  17613. foreach ($headers as $header) {
  17614. $header = trim($header);
  17615. if (false === strpos($header, 'X-RateLimit-')) {
  17616. continue;
  17617. }
  17618. list($type, $value) = explode(':', $header, 2);
  17619. switch ($type) {
  17620. case 'X-RateLimit-Limit':
  17621. $rateLimit['limit'] = (int) trim($value);
  17622. break;
  17623. case 'X-RateLimit-Reset':
  17624. $rateLimit['reset'] = date('Y-m-d H:i:s', (int) trim($value));
  17625. break;
  17626. }
  17627. }
  17628. return $rateLimit;
  17629. }
  17630. protected function fetchRootIdentifier()
  17631. {
  17632. $repoDataUrl = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository;
  17633. $repoData = JsonFile::parseJson($this->getContents($repoDataUrl, true), $repoDataUrl);
  17634. if (null === $repoData && null !== $this->gitDriver) {
  17635. return;
  17636. }
  17637. $this->owner = $repoData['owner']['login'];
  17638. $this->repository = $repoData['name'];
  17639. $this->isPrivate = !empty($repoData['private']);
  17640. if (isset($repoData['default_branch'])) {
  17641. $this->rootIdentifier = $repoData['default_branch'];
  17642. } elseif (isset($repoData['master_branch'])) {
  17643. $this->rootIdentifier = $repoData['master_branch'];
  17644. } else {
  17645. $this->rootIdentifier = 'master';
  17646. }
  17647. $this->hasIssues = !empty($repoData['has_issues']);
  17648. }
  17649. protected function attemptCloneFallback()
  17650. {
  17651. $this->isPrivate = true;
  17652. try {
  17653. $this->setupGitDriver($this->generateSshUrl());
  17654. return;
  17655. } catch (\RuntimeException $e) {
  17656. $this->gitDriver = null;
  17657. $this->io->writeError('<error>Failed to clone the '.$this->generateSshUrl().' repository, try running in interactive mode so that you can enter your GitHub credentials</error>');
  17658. throw $e;
  17659. }
  17660. }
  17661. protected function setupGitDriver($url)
  17662. {
  17663. $this->gitDriver = new GitDriver(
  17664. array('url' => $url),
  17665. $this->io,
  17666. $this->config,
  17667. $this->process,
  17668. $this->remoteFilesystem
  17669. );
  17670. $this->gitDriver->initialize();
  17671. }
  17672. protected function getNextPage()
  17673. {
  17674. $headers = $this->remoteFilesystem->getLastHeaders();
  17675. foreach ($headers as $header) {
  17676. if (substr($header, 0, 5) === 'Link:') {
  17677. $links = explode(',', substr($header, 5));
  17678. foreach ($links as $link) {
  17679. if (preg_match('{<(.+?)>; *rel="next"}', $link, $match)) {
  17680. return $match[1];
  17681. }
  17682. }
  17683. }
  17684. }
  17685. }
  17686. }
  17687. <?php
  17688. namespace Composer\Repository\Vcs;
  17689. use Composer\Config;
  17690. use Composer\Json\JsonFile;
  17691. use Composer\IO\IOInterface;
  17692. class HgBitbucketDriver extends VcsDriver
  17693. {
  17694. protected $owner;
  17695. protected $repository;
  17696. protected $tags;
  17697. protected $branches;
  17698. protected $rootIdentifier;
  17699. protected $infoCache = array();
  17700. public function initialize()
  17701. {
  17702. preg_match('#^https?://bitbucket\.org/([^/]+)/([^/]+)/?$#', $this->url, $match);
  17703. $this->owner = $match[1];
  17704. $this->repository = $match[2];
  17705. $this->originUrl = 'bitbucket.org';
  17706. }
  17707. public function getRootIdentifier()
  17708. {
  17709. if (null === $this->rootIdentifier) {
  17710. $resource = $this->getScheme() . '://bitbucket.org/api/1.0/repositories/'.$this->owner.'/'.$this->repository.'/tags';
  17711. $repoData = JsonFile::parseJson($this->getContents($resource), $resource);
  17712. if (array() === $repoData || !isset($repoData['tip'])) {
  17713. throw new \RuntimeException($this->url.' does not appear to be a mercurial repository, use '.$this->url.'.git if this is a git bitbucket repository');
  17714. }
  17715. $this->rootIdentifier = $repoData['tip']['raw_node'];
  17716. }
  17717. return $this->rootIdentifier;
  17718. }
  17719. public function getUrl()
  17720. {
  17721. return $this->url;
  17722. }
  17723. public function getSource($identifier)
  17724. {
  17725. return array('type' => 'hg', 'url' => $this->getUrl(), 'reference' => $identifier);
  17726. }
  17727. public function getDist($identifier)
  17728. {
  17729. $url = $this->getScheme() . '://bitbucket.org/'.$this->owner.'/'.$this->repository.'/get/'.$identifier.'.zip';
  17730. return array('type' => 'zip', 'url' => $url, 'reference' => $identifier, 'shasum' => '');
  17731. }
  17732. public function getComposerInformation($identifier)
  17733. {
  17734. if (!isset($this->infoCache[$identifier])) {
  17735. $resource = $this->getScheme() . '://bitbucket.org/api/1.0/repositories/'.$this->owner.'/'.$this->repository.'/src/'.$identifier.'/composer.json';
  17736. $repoData = JsonFile::parseJson($this->getContents($resource), $resource);
  17737. if (!array_key_exists('data', $repoData)) {
  17738. return;
  17739. }
  17740. $composer = JsonFile::parseJson($repoData['data'], $resource);
  17741. if (empty($composer['time'])) {
  17742. $resource = $this->getScheme() . '://bitbucket.org/api/1.0/repositories/'.$this->owner.'/'.$this->repository.'/changesets/'.$identifier;
  17743. $changeset = JsonFile::parseJson($this->getContents($resource), $resource);
  17744. $composer['time'] = $changeset['timestamp'];
  17745. }
  17746. $this->infoCache[$identifier] = $composer;
  17747. }
  17748. return $this->infoCache[$identifier];
  17749. }
  17750. public function getTags()
  17751. {
  17752. if (null === $this->tags) {
  17753. $resource = $this->getScheme() . '://bitbucket.org/api/1.0/repositories/'.$this->owner.'/'.$this->repository.'/tags';
  17754. $tagsData = JsonFile::parseJson($this->getContents($resource), $resource);
  17755. $this->tags = array();
  17756. foreach ($tagsData as $tag => $data) {
  17757. $this->tags[$tag] = $data['raw_node'];
  17758. }
  17759. unset($this->tags['tip']);
  17760. }
  17761. return $this->tags;
  17762. }
  17763. public function getBranches()
  17764. {
  17765. if (null === $this->branches) {
  17766. $resource = $this->getScheme() . '://bitbucket.org/api/1.0/repositories/'.$this->owner.'/'.$this->repository.'/branches';
  17767. $branchData = JsonFile::parseJson($this->getContents($resource), $resource);
  17768. $this->branches = array();
  17769. foreach ($branchData as $branch => $data) {
  17770. $this->branches[$branch] = $data['raw_node'];
  17771. }
  17772. }
  17773. return $this->branches;
  17774. }
  17775. public static function supports(IOInterface $io, Config $config, $url, $deep = false)
  17776. {
  17777. if (!preg_match('#^https?://bitbucket\.org/([^/]+)/([^/]+)/?$#', $url)) {
  17778. return false;
  17779. }
  17780. if (!extension_loaded('openssl')) {
  17781. if ($io->isVerbose()) {
  17782. $io->writeError('Skipping Bitbucket hg driver for '.$url.' because the OpenSSL PHP extension is missing.');
  17783. }
  17784. return false;
  17785. }
  17786. return true;
  17787. }
  17788. }
  17789. <?php
  17790. namespace Composer\Repository\Vcs;
  17791. use Composer\Config;
  17792. use Composer\Json\JsonFile;
  17793. use Composer\Util\ProcessExecutor;
  17794. use Composer\Util\Filesystem;
  17795. use Composer\IO\IOInterface;
  17796. class HgDriver extends VcsDriver
  17797. {
  17798. protected $tags;
  17799. protected $branches;
  17800. protected $rootIdentifier;
  17801. protected $repoDir;
  17802. protected $infoCache = array();
  17803. public function initialize()
  17804. {
  17805. if (Filesystem::isLocalPath($this->url)) {
  17806. $this->repoDir = $this->url;
  17807. } else {
  17808. $cacheDir = $this->config->get('cache-vcs-dir');
  17809. $this->repoDir = $cacheDir . '/' . preg_replace('{[^a-z0-9]}i', '-', $this->url) . '/';
  17810. $fs = new Filesystem();
  17811. $fs->ensureDirectoryExists($cacheDir);
  17812. if (!is_writable(dirname($this->repoDir))) {
  17813. throw new \RuntimeException('Can not clone '.$this->url.' to access package information. The "'.$cacheDir.'" directory is not writable by the current user.');
  17814. }
  17815. if (is_dir($this->repoDir) && 0 === $this->process->execute('hg summary', $output, $this->repoDir)) {
  17816. if (0 !== $this->process->execute('hg pull', $output, $this->repoDir)) {
  17817. $this->io->writeError('<error>Failed to update '.$this->url.', package information from this repository may be outdated ('.$this->process->getErrorOutput().')</error>');
  17818. }
  17819. } else {
  17820. $fs->removeDirectory($this->repoDir);
  17821. if (0 !== $this->process->execute(sprintf('hg clone --noupdate %s %s', ProcessExecutor::escape($this->url), ProcessExecutor::escape($this->repoDir)), $output, $cacheDir)) {
  17822. $output = $this->process->getErrorOutput();
  17823. if (0 !== $this->process->execute('hg --version', $ignoredOutput)) {
  17824. throw new \RuntimeException('Failed to clone '.$this->url.', hg was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput());
  17825. }
  17826. throw new \RuntimeException('Failed to clone '.$this->url.', could not read packages from it' . "\n\n" .$output);
  17827. }
  17828. }
  17829. }
  17830. $this->getTags();
  17831. $this->getBranches();
  17832. }
  17833. public function getRootIdentifier()
  17834. {
  17835. if (null === $this->rootIdentifier) {
  17836. $this->process->execute(sprintf('hg tip --template "{node}"'), $output, $this->repoDir);
  17837. $output = $this->process->splitLines($output);
  17838. $this->rootIdentifier = $output[0];
  17839. }
  17840. return $this->rootIdentifier;
  17841. }
  17842. public function getUrl()
  17843. {
  17844. return $this->url;
  17845. }
  17846. public function getSource($identifier)
  17847. {
  17848. return array('type' => 'hg', 'url' => $this->getUrl(), 'reference' => $identifier);
  17849. }
  17850. public function getDist($identifier)
  17851. {
  17852. return null;
  17853. }
  17854. public function getComposerInformation($identifier)
  17855. {
  17856. if (!isset($this->infoCache[$identifier])) {
  17857. $this->process->execute(sprintf('hg cat -r %s composer.json', ProcessExecutor::escape($identifier)), $composer, $this->repoDir);
  17858. if (!trim($composer)) {
  17859. return;
  17860. }
  17861. $composer = JsonFile::parseJson($composer, $identifier);
  17862. if (empty($composer['time'])) {
  17863. $this->process->execute(sprintf('hg log --template "{date|rfc3339date}" -r %s', ProcessExecutor::escape($identifier)), $output, $this->repoDir);
  17864. $date = new \DateTime(trim($output), new \DateTimeZone('UTC'));
  17865. $composer['time'] = $date->format('Y-m-d H:i:s');
  17866. }
  17867. $this->infoCache[$identifier] = $composer;
  17868. }
  17869. return $this->infoCache[$identifier];
  17870. }
  17871. public function getTags()
  17872. {
  17873. if (null === $this->tags) {
  17874. $tags = array();
  17875. $this->process->execute('hg tags', $output, $this->repoDir);
  17876. foreach ($this->process->splitLines($output) as $tag) {
  17877. if ($tag && preg_match('(^([^\s]+)\s+\d+:(.*)$)', $tag, $match)) {
  17878. $tags[$match[1]] = $match[2];
  17879. }
  17880. }
  17881. unset($tags['tip']);
  17882. $this->tags = $tags;
  17883. }
  17884. return $this->tags;
  17885. }
  17886. public function getBranches()
  17887. {
  17888. if (null === $this->branches) {
  17889. $branches = array();
  17890. $bookmarks = array();
  17891. $this->process->execute('hg branches', $output, $this->repoDir);
  17892. foreach ($this->process->splitLines($output) as $branch) {
  17893. if ($branch && preg_match('(^([^\s]+)\s+\d+:([a-f0-9]+))', $branch, $match)) {
  17894. $branches[$match[1]] = $match[2];
  17895. }
  17896. }
  17897. $this->process->execute('hg bookmarks', $output, $this->repoDir);
  17898. foreach ($this->process->splitLines($output) as $branch) {
  17899. if ($branch && preg_match('(^(?:[\s*]*)([^\s]+)\s+\d+:(.*)$)', $branch, $match)) {
  17900. $bookmarks[$match[1]] = $match[2];
  17901. }
  17902. }
  17903. $this->branches = array_merge($bookmarks, $branches);
  17904. }
  17905. return $this->branches;
  17906. }
  17907. public static function supports(IOInterface $io, Config $config, $url, $deep = false)
  17908. {
  17909. if (preg_match('#(^(?:https?|ssh)://(?:[^@]@)?bitbucket.org|https://(?:.*?)\.kilnhg.com)#i', $url)) {
  17910. return true;
  17911. }
  17912. if (Filesystem::isLocalPath($url)) {
  17913. $url = Filesystem::getPlatformPath($url);
  17914. if (!is_dir($url)) {
  17915. return false;
  17916. }
  17917. $process = new ProcessExecutor();
  17918. if ($process->execute('hg summary', $output, $url) === 0) {
  17919. return true;
  17920. }
  17921. }
  17922. if (!$deep) {
  17923. return false;
  17924. }
  17925. $processExecutor = new ProcessExecutor();
  17926. $exit = $processExecutor->execute(sprintf('hg identify %s', ProcessExecutor::escape($url)), $ignored);
  17927. return $exit === 0;
  17928. }
  17929. }
  17930. <?php
  17931. namespace Composer\Repository\Vcs;
  17932. use Composer\Config;
  17933. use Composer\IO\IOInterface;
  17934. use Composer\Util\ProcessExecutor;
  17935. use Composer\Util\Perforce;
  17936. class PerforceDriver extends VcsDriver
  17937. {
  17938. protected $depot;
  17939. protected $branch;
  17940. protected $perforce;
  17941. protected $composerInfo;
  17942. protected $composerInfoIdentifier;
  17943. public function initialize()
  17944. {
  17945. $this->depot = $this->repoConfig['depot'];
  17946. $this->branch = '';
  17947. if (!empty($this->repoConfig['branch'])) {
  17948. $this->branch = $this->repoConfig['branch'];
  17949. }
  17950. $this->initPerforce($this->repoConfig);
  17951. $this->perforce->p4Login($this->io);
  17952. $this->perforce->checkStream($this->depot);
  17953. $this->perforce->writeP4ClientSpec();
  17954. $this->perforce->connectClient();
  17955. return true;
  17956. }
  17957. private function initPerforce($repoConfig)
  17958. {
  17959. if (!empty($this->perforce)) {
  17960. return;
  17961. }
  17962. $repoDir = $this->config->get('cache-vcs-dir') . '/' . $this->depot;
  17963. $this->perforce = Perforce::create($repoConfig, $this->getUrl(), $repoDir, $this->process, $this->io);
  17964. }
  17965. public function getComposerInformation($identifier)
  17966. {
  17967. if (!empty($this->composerInfoIdentifier)) {
  17968. if (strcmp($identifier, $this->composerInfoIdentifier) === 0) {
  17969. return $this->composerInfo;
  17970. }
  17971. }
  17972. $composer_info = $this->perforce->getComposerInformation($identifier);
  17973. return $composer_info;
  17974. }
  17975. public function getRootIdentifier()
  17976. {
  17977. return $this->branch;
  17978. }
  17979. public function getBranches()
  17980. {
  17981. $branches = $this->perforce->getBranches();
  17982. return $branches;
  17983. }
  17984. public function getTags()
  17985. {
  17986. $tags = $this->perforce->getTags();
  17987. return $tags;
  17988. }
  17989. public function getDist($identifier)
  17990. {
  17991. return null;
  17992. }
  17993. public function getSource($identifier)
  17994. {
  17995. $source = array(
  17996. 'type' => 'perforce',
  17997. 'url' => $this->repoConfig['url'],
  17998. 'reference' => $identifier,
  17999. 'p4user' => $this->perforce->getUser(),
  18000. );
  18001. return $source;
  18002. }
  18003. public function getUrl()
  18004. {
  18005. return $this->url;
  18006. }
  18007. public function hasComposerFile($identifier)
  18008. {
  18009. $this->composerInfo = $this->perforce->getComposerInformation('//' . $this->depot . '/' . $identifier);
  18010. $this->composerInfoIdentifier = $identifier;
  18011. return !empty($this->composerInfo);
  18012. }
  18013. public function getContents($url)
  18014. {
  18015. return false;
  18016. }
  18017. public static function supports(IOInterface $io, Config $config, $url, $deep = false)
  18018. {
  18019. if ($deep || preg_match('#\b(perforce|p4)\b#i', $url)) {
  18020. return Perforce::checkServerExists($url, new ProcessExecutor($io));
  18021. }
  18022. return false;
  18023. }
  18024. public function cleanup()
  18025. {
  18026. $this->perforce->cleanupClientSpec();
  18027. $this->perforce = null;
  18028. }
  18029. public function getDepot()
  18030. {
  18031. return $this->depot;
  18032. }
  18033. public function getBranch()
  18034. {
  18035. return $this->branch;
  18036. }
  18037. }
  18038. <?php
  18039. namespace Composer\Repository\Vcs;
  18040. use Composer\Cache;
  18041. use Composer\Config;
  18042. use Composer\Json\JsonFile;
  18043. use Composer\Util\ProcessExecutor;
  18044. use Composer\Util\Filesystem;
  18045. use Composer\Util\Svn as SvnUtil;
  18046. use Composer\IO\IOInterface;
  18047. use Composer\Downloader\TransportException;
  18048. class SvnDriver extends VcsDriver
  18049. {
  18050. protected $cache;
  18051. protected $baseUrl;
  18052. protected $tags;
  18053. protected $branches;
  18054. protected $rootIdentifier;
  18055. protected $infoCache = array();
  18056. protected $trunkPath = 'trunk';
  18057. protected $branchesPath = 'branches';
  18058. protected $tagsPath = 'tags';
  18059. protected $packagePath = '';
  18060. protected $cacheCredentials = true;
  18061. private $util;
  18062. public function initialize()
  18063. {
  18064. $this->url = $this->baseUrl = rtrim(self::normalizeUrl($this->url), '/');
  18065. SvnUtil::cleanEnv();
  18066. if (isset($this->repoConfig['trunk-path'])) {
  18067. $this->trunkPath = $this->repoConfig['trunk-path'];
  18068. }
  18069. if (isset($this->repoConfig['branches-path'])) {
  18070. $this->branchesPath = $this->repoConfig['branches-path'];
  18071. }
  18072. if (isset($this->repoConfig['tags-path'])) {
  18073. $this->tagsPath = $this->repoConfig['tags-path'];
  18074. }
  18075. if (array_key_exists('svn-cache-credentials', $this->repoConfig)) {
  18076. $this->cacheCredentials = (bool) $this->repoConfig['svn-cache-credentials'];
  18077. }
  18078. if (isset($this->repoConfig['package-path'])) {
  18079. $this->packagePath = '/' . trim($this->repoConfig['package-path'], '/');
  18080. }
  18081. if (false !== ($pos = strrpos($this->url, '/' . $this->trunkPath))) {
  18082. $this->baseUrl = substr($this->url, 0, $pos);
  18083. }
  18084. $this->cache = new Cache($this->io, $this->config->get('cache-repo-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $this->baseUrl));
  18085. $this->getBranches();
  18086. $this->getTags();
  18087. }
  18088. public function getRootIdentifier()
  18089. {
  18090. return $this->rootIdentifier ?: $this->trunkPath;
  18091. }
  18092. public function getUrl()
  18093. {
  18094. return $this->url;
  18095. }
  18096. public function getSource($identifier)
  18097. {
  18098. return array('type' => 'svn', 'url' => $this->baseUrl, 'reference' => $identifier);
  18099. }
  18100. public function getDist($identifier)
  18101. {
  18102. return null;
  18103. }
  18104. public function getComposerInformation($identifier)
  18105. {
  18106. $identifier = '/' . trim($identifier, '/') . '/';
  18107. if ($res = $this->cache->read($identifier.'.json')) {
  18108. $this->infoCache[$identifier] = JsonFile::parseJson($res);
  18109. }
  18110. if (!isset($this->infoCache[$identifier])) {
  18111. preg_match('{^(.+?)(@\d+)?/$}', $identifier, $match);
  18112. if (!empty($match[2])) {
  18113. $path = $match[1];
  18114. $rev = $match[2];
  18115. } else {
  18116. $path = $identifier;
  18117. $rev = '';
  18118. }
  18119. try {
  18120. $resource = $path.'composer.json';
  18121. $output = $this->execute('svn cat', $this->baseUrl . $resource . $rev);
  18122. if (!trim($output)) {
  18123. return;
  18124. }
  18125. } catch (\RuntimeException $e) {
  18126. throw new TransportException($e->getMessage());
  18127. }
  18128. $composer = JsonFile::parseJson($output, $this->baseUrl . $resource . $rev);
  18129. if (empty($composer['time'])) {
  18130. $output = $this->execute('svn info', $this->baseUrl . $path . $rev);
  18131. foreach ($this->process->splitLines($output) as $line) {
  18132. if ($line && preg_match('{^Last Changed Date: ([^(]+)}', $line, $match)) {
  18133. $date = new \DateTime($match[1], new \DateTimeZone('UTC'));
  18134. $composer['time'] = $date->format('Y-m-d H:i:s');
  18135. break;
  18136. }
  18137. }
  18138. }
  18139. $this->cache->write($identifier.'.json', json_encode($composer));
  18140. $this->infoCache[$identifier] = $composer;
  18141. }
  18142. return $this->infoCache[$identifier];
  18143. }
  18144. public function getTags()
  18145. {
  18146. if (null === $this->tags) {
  18147. $this->tags = array();
  18148. if ($this->tagsPath !== false) {
  18149. $output = $this->execute('svn ls --verbose', $this->baseUrl . '/' . $this->tagsPath);
  18150. if ($output) {
  18151. foreach ($this->process->splitLines($output) as $line) {
  18152. $line = trim($line);
  18153. if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) {
  18154. if (isset($match[1]) && isset($match[2]) && $match[2] !== './') {
  18155. $this->tags[rtrim($match[2], '/')] = $this->buildIdentifier(
  18156. '/' . $this->tagsPath . '/' . $match[2],
  18157. $match[1]
  18158. );
  18159. }
  18160. }
  18161. }
  18162. }
  18163. }
  18164. }
  18165. return $this->tags;
  18166. }
  18167. public function getBranches()
  18168. {
  18169. if (null === $this->branches) {
  18170. $this->branches = array();
  18171. if (false === $this->trunkPath) {
  18172. $trunkParent = $this->baseUrl . '/';
  18173. } else {
  18174. $trunkParent = $this->baseUrl . '/' . $this->trunkPath;
  18175. }
  18176. $output = $this->execute('svn ls --verbose', $trunkParent);
  18177. if ($output) {
  18178. foreach ($this->process->splitLines($output) as $line) {
  18179. $line = trim($line);
  18180. if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) {
  18181. if (isset($match[1]) && isset($match[2]) && $match[2] === './') {
  18182. $this->branches['trunk'] = $this->buildIdentifier(
  18183. '/' . $this->trunkPath,
  18184. $match[1]
  18185. );
  18186. $this->rootIdentifier = $this->branches['trunk'];
  18187. break;
  18188. }
  18189. }
  18190. }
  18191. }
  18192. unset($output);
  18193. if ($this->branchesPath !== false) {
  18194. $output = $this->execute('svn ls --verbose', $this->baseUrl . '/' . $this->branchesPath);
  18195. if ($output) {
  18196. foreach ($this->process->splitLines(trim($output)) as $line) {
  18197. $line = trim($line);
  18198. if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) {
  18199. if (isset($match[1]) && isset($match[2]) && $match[2] !== './') {
  18200. $this->branches[rtrim($match[2], '/')] = $this->buildIdentifier(
  18201. '/' . $this->branchesPath . '/' . $match[2],
  18202. $match[1]
  18203. );
  18204. }
  18205. }
  18206. }
  18207. }
  18208. }
  18209. }
  18210. return $this->branches;
  18211. }
  18212. public static function supports(IOInterface $io, Config $config, $url, $deep = false)
  18213. {
  18214. $url = self::normalizeUrl($url);
  18215. if (preg_match('#(^svn://|^svn\+ssh://|svn\.)#i', $url)) {
  18216. return true;
  18217. }
  18218. if (!$deep && !Filesystem::isLocalPath($url)) {
  18219. return false;
  18220. }
  18221. $processExecutor = new ProcessExecutor();
  18222. $exit = $processExecutor->execute(
  18223. "svn info --non-interactive {$url}",
  18224. $ignoredOutput
  18225. );
  18226. if ($exit === 0) {
  18227. return true;
  18228. }
  18229. if (false !== stripos($processExecutor->getErrorOutput(), 'authorization failed:')) {
  18230. return true;
  18231. }
  18232. return false;
  18233. }
  18234. protected static function normalizeUrl($url)
  18235. {
  18236. $fs = new Filesystem();
  18237. if ($fs->isAbsolutePath($url)) {
  18238. return 'file://' . strtr($url, '\\', '/');
  18239. }
  18240. return $url;
  18241. }
  18242. protected function execute($command, $url)
  18243. {
  18244. if (null === $this->util) {
  18245. $this->util = new SvnUtil($this->baseUrl, $this->io, $this->config, $this->process);
  18246. $this->util->setCacheCredentials($this->cacheCredentials);
  18247. }
  18248. try {
  18249. return $this->util->execute($command, $url);
  18250. } catch (\RuntimeException $e) {
  18251. if (0 !== $this->process->execute('svn --version', $ignoredOutput)) {
  18252. throw new \RuntimeException('Failed to load '.$this->url.', svn was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput());
  18253. }
  18254. throw new \RuntimeException(
  18255. 'Repository '.$this->url.' could not be processed, '.$e->getMessage()
  18256. );
  18257. }
  18258. }
  18259. protected function buildIdentifier($baseDir, $revision)
  18260. {
  18261. return rtrim($baseDir, '/') . $this->packagePath . '/@' . $revision;
  18262. }
  18263. }
  18264. <?php
  18265. namespace Composer\Repository\Vcs;
  18266. use Composer\Downloader\TransportException;
  18267. use Composer\Config;
  18268. use Composer\IO\IOInterface;
  18269. use Composer\Util\ProcessExecutor;
  18270. use Composer\Util\RemoteFilesystem;
  18271. use Composer\Util\Filesystem;
  18272. abstract class VcsDriver implements VcsDriverInterface
  18273. {
  18274. protected $url;
  18275. protected $originUrl;
  18276. protected $repoConfig;
  18277. protected $io;
  18278. protected $config;
  18279. protected $process;
  18280. protected $remoteFilesystem;
  18281. final public function __construct(array $repoConfig, IOInterface $io, Config $config, ProcessExecutor $process = null, RemoteFilesystem $remoteFilesystem = null)
  18282. {
  18283. if (Filesystem::isLocalPath($repoConfig['url'])) {
  18284. $repoConfig['url'] = Filesystem::getPlatformPath($repoConfig['url']);
  18285. }
  18286. $this->url = $repoConfig['url'];
  18287. $this->originUrl = $repoConfig['url'];
  18288. $this->repoConfig = $repoConfig;
  18289. $this->io = $io;
  18290. $this->config = $config;
  18291. $this->process = $process ?: new ProcessExecutor($io);
  18292. $this->remoteFilesystem = $remoteFilesystem ?: new RemoteFilesystem($io, $config);
  18293. }
  18294. public function hasComposerFile($identifier)
  18295. {
  18296. try {
  18297. return (bool) $this->getComposerInformation($identifier);
  18298. } catch (TransportException $e) {
  18299. }
  18300. return false;
  18301. }
  18302. protected function getScheme()
  18303. {
  18304. if (extension_loaded('openssl')) {
  18305. return 'https';
  18306. }
  18307. return 'http';
  18308. }
  18309. protected function getContents($url)
  18310. {
  18311. return $this->remoteFilesystem->getContents($this->originUrl, $url, false);
  18312. }
  18313. public function cleanup()
  18314. {
  18315. return;
  18316. }
  18317. }
  18318. <?php
  18319. namespace Composer\Repository\Vcs;
  18320. use Composer\Config;
  18321. use Composer\IO\IOInterface;
  18322. interface VcsDriverInterface
  18323. {
  18324. public function initialize();
  18325. public function getComposerInformation($identifier);
  18326. public function getRootIdentifier();
  18327. public function getBranches();
  18328. public function getTags();
  18329. public function getDist($identifier);
  18330. public function getSource($identifier);
  18331. public function getUrl();
  18332. public function hasComposerFile($identifier);
  18333. public function cleanup();
  18334. public static function supports(IOInterface $io, Config $config, $url, $deep = false);
  18335. }
  18336. <?php
  18337. namespace Composer\Repository;
  18338. use Composer\Downloader\TransportException;
  18339. use Composer\Repository\Vcs\VcsDriverInterface;
  18340. use Composer\Semver\VersionParser;
  18341. use Composer\Package\Loader\ArrayLoader;
  18342. use Composer\Package\Loader\ValidatingArrayLoader;
  18343. use Composer\Package\Loader\InvalidPackageException;
  18344. use Composer\Package\Loader\LoaderInterface;
  18345. use Composer\EventDispatcher\EventDispatcher;
  18346. use Composer\IO\IOInterface;
  18347. use Composer\Config;
  18348. class VcsRepository extends ArrayRepository
  18349. {
  18350. protected $url;
  18351. protected $packageName;
  18352. protected $verbose;
  18353. protected $io;
  18354. protected $config;
  18355. protected $versionParser;
  18356. protected $type;
  18357. protected $loader;
  18358. protected $repoConfig;
  18359. protected $branchErrorOccurred = false;
  18360. public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $dispatcher = null, array $drivers = null)
  18361. {
  18362. $this->drivers = $drivers ?: array(
  18363. 'github' => 'Composer\Repository\Vcs\GitHubDriver',
  18364. 'git-bitbucket' => 'Composer\Repository\Vcs\GitBitbucketDriver',
  18365. 'git' => 'Composer\Repository\Vcs\GitDriver',
  18366. 'hg-bitbucket' => 'Composer\Repository\Vcs\HgBitbucketDriver',
  18367. 'hg' => 'Composer\Repository\Vcs\HgDriver',
  18368. 'perforce' => 'Composer\Repository\Vcs\PerforceDriver',
  18369. 'svn' => 'Composer\Repository\Vcs\SvnDriver',
  18370. );
  18371. $this->url = $repoConfig['url'];
  18372. $this->io = $io;
  18373. $this->type = isset($repoConfig['type']) ? $repoConfig['type'] : 'vcs';
  18374. $this->verbose = $io->isVeryVerbose();
  18375. $this->config = $config;
  18376. $this->repoConfig = $repoConfig;
  18377. }
  18378. public function getRepoConfig()
  18379. {
  18380. return $this->repoConfig;
  18381. }
  18382. public function setLoader(LoaderInterface $loader)
  18383. {
  18384. $this->loader = $loader;
  18385. }
  18386. public function getDriver()
  18387. {
  18388. if (isset($this->drivers[$this->type])) {
  18389. $class = $this->drivers[$this->type];
  18390. $driver = new $class($this->repoConfig, $this->io, $this->config);
  18391. $driver->initialize();
  18392. return $driver;
  18393. }
  18394. foreach ($this->drivers as $driver) {
  18395. if ($driver::supports($this->io, $this->config, $this->url)) {
  18396. $driver = new $driver($this->repoConfig, $this->io, $this->config);
  18397. $driver->initialize();
  18398. return $driver;
  18399. }
  18400. }
  18401. foreach ($this->drivers as $driver) {
  18402. if ($driver::supports($this->io, $this->config, $this->url, true)) {
  18403. $driver = new $driver($this->repoConfig, $this->io, $this->config);
  18404. $driver->initialize();
  18405. return $driver;
  18406. }
  18407. }
  18408. }
  18409. public function hadInvalidBranches()
  18410. {
  18411. return $this->branchErrorOccurred;
  18412. }
  18413. protected function initialize()
  18414. {
  18415. parent::initialize();
  18416. $verbose = $this->verbose;
  18417. $driver = $this->getDriver();
  18418. if (!$driver) {
  18419. throw new \InvalidArgumentException('No driver found to handle VCS repository '.$this->url);
  18420. }
  18421. $this->versionParser = new VersionParser;
  18422. if (!$this->loader) {
  18423. $this->loader = new ArrayLoader($this->versionParser);
  18424. }
  18425. try {
  18426. if ($driver->hasComposerFile($driver->getRootIdentifier())) {
  18427. $data = $driver->getComposerInformation($driver->getRootIdentifier());
  18428. $this->packageName = !empty($data['name']) ? $data['name'] : null;
  18429. }
  18430. } catch (\Exception $e) {
  18431. if ($verbose) {
  18432. $this->io->writeError('<error>Skipped parsing '.$driver->getRootIdentifier().', '.$e->getMessage().'</error>');
  18433. }
  18434. }
  18435. foreach ($driver->getTags() as $tag => $identifier) {
  18436. $msg = 'Reading composer.json of <info>' . ($this->packageName ?: $this->url) . '</info> (<comment>' . $tag . '</comment>)';
  18437. if ($verbose) {
  18438. $this->io->writeError($msg);
  18439. } else {
  18440. $this->io->overwriteError($msg, false);
  18441. }
  18442. $tag = str_replace('release-', '', $tag);
  18443. if (!$parsedTag = $this->validateTag($tag)) {
  18444. if ($verbose) {
  18445. $this->io->writeError('<warning>Skipped tag '.$tag.', invalid tag name</warning>');
  18446. }
  18447. continue;
  18448. }
  18449. try {
  18450. if (!$data = $driver->getComposerInformation($identifier)) {
  18451. if ($verbose) {
  18452. $this->io->writeError('<warning>Skipped tag '.$tag.', no composer file</warning>');
  18453. }
  18454. continue;
  18455. }
  18456. if (isset($data['version'])) {
  18457. $data['version_normalized'] = $this->versionParser->normalize($data['version']);
  18458. } else {
  18459. $data['version'] = $tag;
  18460. $data['version_normalized'] = $parsedTag;
  18461. }
  18462. $data['version'] = preg_replace('{[.-]?dev$}i', '', $data['version']);
  18463. $data['version_normalized'] = preg_replace('{(^dev-|[.-]?dev$)}i', '', $data['version_normalized']);
  18464. if ($data['version_normalized'] !== $parsedTag) {
  18465. if ($verbose) {
  18466. $this->io->writeError('<warning>Skipped tag '.$tag.', tag ('.$parsedTag.') does not match version ('.$data['version_normalized'].') in composer.json</warning>');
  18467. }
  18468. continue;
  18469. }
  18470. if ($verbose) {
  18471. $this->io->writeError('Importing tag '.$tag.' ('.$data['version_normalized'].')');
  18472. }
  18473. $this->addPackage($this->loader->load($this->preProcess($driver, $data, $identifier)));
  18474. } catch (\Exception $e) {
  18475. if ($verbose) {
  18476. $this->io->writeError('<warning>Skipped tag '.$tag.', '.($e instanceof TransportException ? 'no composer file was found' : $e->getMessage()).'</warning>');
  18477. }
  18478. continue;
  18479. }
  18480. }
  18481. if (!$verbose) {
  18482. $this->io->overwriteError('', false);
  18483. }
  18484. foreach ($driver->getBranches() as $branch => $identifier) {
  18485. $msg = 'Reading composer.json of <info>' . ($this->packageName ?: $this->url) . '</info> (<comment>' . $branch . '</comment>)';
  18486. if ($verbose) {
  18487. $this->io->writeError($msg);
  18488. } else {
  18489. $this->io->overwriteError($msg, false);
  18490. }
  18491. if (!$parsedBranch = $this->validateBranch($branch)) {
  18492. if ($verbose) {
  18493. $this->io->writeError('<warning>Skipped branch '.$branch.', invalid name</warning>');
  18494. }
  18495. continue;
  18496. }
  18497. try {
  18498. if (!$data = $driver->getComposerInformation($identifier)) {
  18499. if ($verbose) {
  18500. $this->io->writeError('<warning>Skipped branch '.$branch.', no composer file</warning>');
  18501. }
  18502. continue;
  18503. }
  18504. $data['version'] = $branch;
  18505. $data['version_normalized'] = $parsedBranch;
  18506. if ('dev-' === substr($parsedBranch, 0, 4) || '9999999-dev' === $parsedBranch) {
  18507. $data['version'] = 'dev-' . $data['version'];
  18508. } else {
  18509. $data['version'] = preg_replace('{(\.9{7})+}', '.x', $parsedBranch);
  18510. }
  18511. if ($verbose) {
  18512. $this->io->writeError('Importing branch '.$branch.' ('.$data['version'].')');
  18513. }
  18514. $packageData = $this->preProcess($driver, $data, $identifier);
  18515. $package = $this->loader->load($packageData);
  18516. if ($this->loader instanceof ValidatingArrayLoader && $this->loader->getWarnings()) {
  18517. throw new InvalidPackageException($this->loader->getErrors(), $this->loader->getWarnings(), $packageData);
  18518. }
  18519. $this->addPackage($package);
  18520. } catch (TransportException $e) {
  18521. if ($verbose) {
  18522. $this->io->writeError('<warning>Skipped branch '.$branch.', no composer file was found</warning>');
  18523. }
  18524. continue;
  18525. } catch (\Exception $e) {
  18526. if (!$verbose) {
  18527. $this->io->writeError('');
  18528. }
  18529. $this->branchErrorOccurred = true;
  18530. $this->io->writeError('<error>Skipped branch '.$branch.', '.$e->getMessage().'</error>');
  18531. $this->io->writeError('');
  18532. continue;
  18533. }
  18534. }
  18535. $driver->cleanup();
  18536. if (!$verbose) {
  18537. $this->io->overwriteError('', false);
  18538. }
  18539. if (!$this->getPackages()) {
  18540. throw new InvalidRepositoryException('No valid composer.json was found in any branch or tag of '.$this->url.', could not load a package from it.');
  18541. }
  18542. }
  18543. protected function preProcess(VcsDriverInterface $driver, array $data, $identifier)
  18544. {
  18545. $data['name'] = $this->packageName ?: $data['name'];
  18546. if (!isset($data['dist'])) {
  18547. $data['dist'] = $driver->getDist($identifier);
  18548. }
  18549. if (!isset($data['source'])) {
  18550. $data['source'] = $driver->getSource($identifier);
  18551. }
  18552. return $data;
  18553. }
  18554. private function validateBranch($branch)
  18555. {
  18556. try {
  18557. return $this->versionParser->normalizeBranch($branch);
  18558. } catch (\Exception $e) {
  18559. }
  18560. return false;
  18561. }
  18562. private function validateTag($version)
  18563. {
  18564. try {
  18565. return $this->versionParser->normalize($version);
  18566. } catch (\Exception $e) {
  18567. }
  18568. return false;
  18569. }
  18570. }
  18571. <?php
  18572. namespace Composer\Repository;
  18573. use Composer\Package\AliasPackage;
  18574. class WritableArrayRepository extends ArrayRepository implements WritableRepositoryInterface
  18575. {
  18576. public function write()
  18577. {
  18578. }
  18579. public function reload()
  18580. {
  18581. }
  18582. public function getCanonicalPackages()
  18583. {
  18584. $packages = $this->getPackages();
  18585. $packagesByName = array();
  18586. foreach ($packages as $package) {
  18587. if (!isset($packagesByName[$package->getName()]) || $packagesByName[$package->getName()] instanceof AliasPackage) {
  18588. $packagesByName[$package->getName()] = $package;
  18589. }
  18590. }
  18591. $canonicalPackages = array();
  18592. foreach ($packagesByName as $package) {
  18593. while ($package instanceof AliasPackage) {
  18594. $package = $package->getAliasOf();
  18595. }
  18596. $canonicalPackages[] = $package;
  18597. }
  18598. return $canonicalPackages;
  18599. }
  18600. }
  18601. <?php
  18602. namespace Composer\Repository;
  18603. use Composer\Package\PackageInterface;
  18604. interface WritableRepositoryInterface extends RepositoryInterface
  18605. {
  18606. public function write();
  18607. public function addPackage(PackageInterface $package);
  18608. public function removePackage(PackageInterface $package);
  18609. public function getCanonicalPackages();
  18610. public function reload();
  18611. }
  18612. <?php
  18613. namespace Composer\Script;
  18614. class CommandEvent extends Event
  18615. {
  18616. }
  18617. <?php
  18618. namespace Composer\Script;
  18619. use Composer\Composer;
  18620. use Composer\IO\IOInterface;
  18621. use Composer\EventDispatcher\Event as BaseEvent;
  18622. class Event extends BaseEvent
  18623. {
  18624. private $composer;
  18625. private $io;
  18626. private $devMode;
  18627. public function __construct($name, Composer $composer, IOInterface $io, $devMode = false, array $args = array(), array $flags = array())
  18628. {
  18629. parent::__construct($name, $args, $flags);
  18630. $this->composer = $composer;
  18631. $this->io = $io;
  18632. $this->devMode = $devMode;
  18633. }
  18634. public function getComposer()
  18635. {
  18636. return $this->composer;
  18637. }
  18638. public function getIO()
  18639. {
  18640. return $this->io;
  18641. }
  18642. public function isDevMode()
  18643. {
  18644. return $this->devMode;
  18645. }
  18646. }
  18647. <?php
  18648. namespace Composer\Script;
  18649. use Composer\Installer\PackageEvent as BasePackageEvent;
  18650. class PackageEvent extends BasePackageEvent
  18651. {
  18652. }
  18653. <?php
  18654. namespace Composer\Script;
  18655. class ScriptEvents
  18656. {
  18657. const PRE_INSTALL_CMD = 'pre-install-cmd';
  18658. const POST_INSTALL_CMD = 'post-install-cmd';
  18659. const PRE_UPDATE_CMD = 'pre-update-cmd';
  18660. const POST_UPDATE_CMD = 'post-update-cmd';
  18661. const PRE_STATUS_CMD = 'pre-status-cmd';
  18662. const POST_STATUS_CMD = 'post-status-cmd';
  18663. const PRE_AUTOLOAD_DUMP = 'pre-autoload-dump';
  18664. const POST_AUTOLOAD_DUMP = 'post-autoload-dump';
  18665. const POST_ROOT_PACKAGE_INSTALL = 'post-root-package-install';
  18666. const POST_CREATE_PROJECT_CMD = 'post-create-project-cmd';
  18667. const PRE_ARCHIVE_CMD = 'pre-archive-cmd';
  18668. const POST_ARCHIVE_CMD = 'post-archive-cmd';
  18669. const PRE_PACKAGE_INSTALL = 'pre-package-install';
  18670. const POST_PACKAGE_INSTALL = 'post-package-install';
  18671. const PRE_PACKAGE_UPDATE = 'pre-package-update';
  18672. const POST_PACKAGE_UPDATE = 'post-package-update';
  18673. const PRE_PACKAGE_UNINSTALL = 'pre-package-uninstall';
  18674. const POST_PACKAGE_UNINSTALL = 'post-package-uninstall';
  18675. }
  18676. <?php
  18677. namespace Composer\Util;
  18678. use Composer\Config;
  18679. use Composer\IO\IOInterface;
  18680. class AuthHelper
  18681. {
  18682. protected $io;
  18683. protected $config;
  18684. public function __construct(IOInterface $io, Config $config)
  18685. {
  18686. $this->io = $io;
  18687. $this->config = $config;
  18688. }
  18689. public function storeAuth($originUrl, $storeAuth)
  18690. {
  18691. $store = false;
  18692. $configSource = $this->config->getAuthConfigSource();
  18693. if ($storeAuth === true) {
  18694. $store = $configSource;
  18695. } elseif ($storeAuth === 'prompt') {
  18696. $answer = $this->io->askAndValidate(
  18697. 'Do you want to store credentials for '.$originUrl.' in '.$configSource->getName().' ? [Yn] ',
  18698. function ($value) {
  18699. $input = strtolower(substr(trim($value), 0, 1));
  18700. if (in_array($input, array('y','n'))) {
  18701. return $input;
  18702. }
  18703. throw new \RuntimeException('Please answer (y)es or (n)o');
  18704. },
  18705. null,
  18706. 'y'
  18707. );
  18708. if ($answer === 'y') {
  18709. $store = $configSource;
  18710. }
  18711. }
  18712. if ($store) {
  18713. $store->addConfigSetting(
  18714. 'http-basic.'.$originUrl,
  18715. $this->io->getAuthentication($originUrl)
  18716. );
  18717. }
  18718. }
  18719. }
  18720. <?php
  18721. namespace Composer\Util;
  18722. class ComposerMirror
  18723. {
  18724. public static function processUrl($mirrorUrl, $packageName, $version, $reference, $type)
  18725. {
  18726. if ($reference) {
  18727. $reference = preg_match('{^([a-f0-9]*|%reference%)$}', $reference) ? $reference : md5($reference);
  18728. }
  18729. $version = strpos($version, '/') === false ? $version : md5($version);
  18730. return str_replace(
  18731. array('%package%', '%version%', '%reference%', '%type%'),
  18732. array($packageName, $version, $reference, $type),
  18733. $mirrorUrl
  18734. );
  18735. }
  18736. public static function processGitUrl($mirrorUrl, $packageName, $url, $type)
  18737. {
  18738. if (preg_match('#^(?:(?:https?|git)://github\.com/|git@github\.com:)([^/]+)/(.+?)(?:\.git)?$#', $url, $match)) {
  18739. $url = 'gh-'.$match[1].'/'.$match[2];
  18740. } elseif (preg_match('#^https://bitbucket\.org/([^/]+)/(.+?)(?:\.git)?/?$#', $url, $match)) {
  18741. $url = 'bb-'.$match[1].'/'.$match[2];
  18742. } else {
  18743. $url = preg_replace('{[^a-z0-9_.-]}i', '-', trim($url, '/'));
  18744. }
  18745. return str_replace(
  18746. array('%package%', '%normalizedUrl%', '%type%'),
  18747. array($packageName, $url, $type),
  18748. $mirrorUrl
  18749. );
  18750. }
  18751. public static function processHgUrl($mirrorUrl, $packageName, $url, $type)
  18752. {
  18753. return self::processGitUrl($mirrorUrl, $packageName, $url, $type);
  18754. }
  18755. }
  18756. <?php
  18757. namespace Composer\Util;
  18758. use Composer\Package\Loader\ArrayLoader;
  18759. use Composer\Package\Loader\ValidatingArrayLoader;
  18760. use Composer\Package\Loader\InvalidPackageException;
  18761. use Composer\Json\JsonValidationException;
  18762. use Composer\IO\IOInterface;
  18763. use Composer\Json\JsonFile;
  18764. use Composer\Spdx\SpdxLicenses;
  18765. class ConfigValidator
  18766. {
  18767. private $io;
  18768. public function __construct(IOInterface $io)
  18769. {
  18770. $this->io = $io;
  18771. }
  18772. public function validate($file, $arrayLoaderValidationFlags = ValidatingArrayLoader::CHECK_ALL)
  18773. {
  18774. $errors = array();
  18775. $publishErrors = array();
  18776. $warnings = array();
  18777. $laxValid = false;
  18778. try {
  18779. $json = new JsonFile($file, new RemoteFilesystem($this->io));
  18780. $manifest = $json->read();
  18781. $json->validateSchema(JsonFile::LAX_SCHEMA);
  18782. $laxValid = true;
  18783. $json->validateSchema();
  18784. } catch (JsonValidationException $e) {
  18785. foreach ($e->getErrors() as $message) {
  18786. if ($laxValid) {
  18787. $publishErrors[] = $message;
  18788. } else {
  18789. $errors[] = $message;
  18790. }
  18791. }
  18792. } catch (\Exception $e) {
  18793. $errors[] = $e->getMessage();
  18794. return array($errors, $publishErrors, $warnings);
  18795. }
  18796. if (!empty($manifest['license'])) {
  18797. if (is_array($manifest['license'])) {
  18798. foreach ($manifest['license'] as $key => $license) {
  18799. if ('proprietary' === $license) {
  18800. unset($manifest['license'][$key]);
  18801. }
  18802. }
  18803. }
  18804. $licenseValidator = new SpdxLicenses();
  18805. if ('proprietary' !== $manifest['license'] && array() !== $manifest['license'] && !$licenseValidator->validate($manifest['license'])) {
  18806. $warnings[] = sprintf(
  18807. 'License %s is not a valid SPDX license identifier, see http://www.spdx.org/licenses/ if you use an open license.'
  18808. ."\nIf the software is closed-source, you may use \"proprietary\" as license.",
  18809. json_encode($manifest['license'])
  18810. );
  18811. }
  18812. } else {
  18813. $warnings[] = 'No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.';
  18814. }
  18815. if (isset($manifest['version'])) {
  18816. $warnings[] = 'The version field is present, it is recommended to leave it out if the package is published on Packagist.';
  18817. }
  18818. if (!empty($manifest['name']) && preg_match('{[A-Z]}', $manifest['name'])) {
  18819. $suggestName = preg_replace('{(?:([a-z])([A-Z])|([A-Z])([A-Z][a-z]))}', '\\1\\3-\\2\\4', $manifest['name']);
  18820. $suggestName = strtolower($suggestName);
  18821. $publishErrors[] = sprintf(
  18822. 'Name "%s" does not match the best practice (e.g. lower-cased/with-dashes). We suggest using "%s" instead. As such you will not be able to submit it to Packagist.',
  18823. $manifest['name'],
  18824. $suggestName
  18825. );
  18826. }
  18827. if (!empty($manifest['type']) && $manifest['type'] == 'composer-installer') {
  18828. $warnings[] = "The package type 'composer-installer' is deprecated. Please distribute your custom installers as plugins from now on. See http://getcomposer.org/doc/articles/plugins.md for plugin documentation.";
  18829. }
  18830. if (isset($manifest['require']) && isset($manifest['require-dev'])) {
  18831. $requireOverrides = array_intersect_key($manifest['require'], $manifest['require-dev']);
  18832. if (!empty($requireOverrides)) {
  18833. $plural = (count($requireOverrides) > 1) ? 'are' : 'is';
  18834. $warnings[] = implode(', ', array_keys($requireOverrides)). " {$plural} required both in require and require-dev, this can lead to unexpected behavior";
  18835. }
  18836. }
  18837. if (isset($manifest['autoload']['psr-0'][''])) {
  18838. $warnings[] = "Defining autoload.psr-0 with an empty namespace prefix is a bad idea for performance";
  18839. }
  18840. if (isset($manifest['autoload']['psr-4'][''])) {
  18841. $warnings[] = "Defining autoload.psr-4 with an empty namespace prefix is a bad idea for performance";
  18842. }
  18843. try {
  18844. $loader = new ValidatingArrayLoader(new ArrayLoader(), true, null, $arrayLoaderValidationFlags);
  18845. if (!isset($manifest['version'])) {
  18846. $manifest['version'] = '1.0.0';
  18847. }
  18848. if (!isset($manifest['name'])) {
  18849. $manifest['name'] = 'dummy/dummy';
  18850. }
  18851. $loader->load($manifest);
  18852. } catch (InvalidPackageException $e) {
  18853. $errors = array_merge($errors, $e->getErrors());
  18854. }
  18855. $warnings = array_merge($warnings, $loader->getWarnings());
  18856. return array($errors, $publishErrors, $warnings);
  18857. }
  18858. }
  18859. <?php
  18860. namespace Composer\Util;
  18861. use Composer\IO\IOInterface;
  18862. class ErrorHandler
  18863. {
  18864. private static $io;
  18865. public static function handle($level, $message, $file, $line)
  18866. {
  18867. if (!error_reporting()) {
  18868. return;
  18869. }
  18870. if (ini_get('xdebug.scream')) {
  18871. $message .= "\n\nWarning: You have xdebug.scream enabled, the warning above may be".
  18872. "\na legitimately suppressed error that you were not supposed to see.";
  18873. }
  18874. if ($level !== E_DEPRECATED && $level !== E_USER_DEPRECATED) {
  18875. throw new \ErrorException($message, 0, $level, $file, $line);
  18876. }
  18877. if (self::$io) {
  18878. self::$io->writeError('<warning>Deprecation Notice: '.$message.' in '.$file.':'.$line.'</warning>');
  18879. if (self::$io->isVerbose()) {
  18880. self::$io->writeError('<warning>Stack trace:</warning>');
  18881. self::$io->writeError(array_filter(array_map(function ($a) {
  18882. if (isset($a['line'], $a['file'])) {
  18883. return '<warning> '.$a['file'].':'.$a['line'].'</warning>';
  18884. }
  18885. return null;
  18886. }, array_slice(debug_backtrace(), 2))));
  18887. }
  18888. }
  18889. }
  18890. public static function register(IOInterface $io = null)
  18891. {
  18892. set_error_handler(array(__CLASS__, 'handle'));
  18893. self::$io = $io;
  18894. }
  18895. }
  18896. <?php
  18897. namespace Composer\Util;
  18898. use RecursiveDirectoryIterator;
  18899. use RecursiveIteratorIterator;
  18900. use Symfony\Component\Finder\Finder;
  18901. class Filesystem
  18902. {
  18903. private $processExecutor;
  18904. public function __construct(ProcessExecutor $executor = null)
  18905. {
  18906. $this->processExecutor = $executor ?: new ProcessExecutor();
  18907. }
  18908. public function remove($file)
  18909. {
  18910. if (is_dir($file)) {
  18911. return $this->removeDirectory($file);
  18912. }
  18913. if (file_exists($file)) {
  18914. return $this->unlink($file);
  18915. }
  18916. return false;
  18917. }
  18918. public function isDirEmpty($dir)
  18919. {
  18920. $finder = Finder::create()
  18921. ->ignoreVCS(false)
  18922. ->ignoreDotFiles(false)
  18923. ->depth(0)
  18924. ->in($dir);
  18925. return count($finder) === 0;
  18926. }
  18927. public function emptyDirectory($dir, $ensureDirectoryExists = true)
  18928. {
  18929. if (file_exists($dir) && is_link($dir)) {
  18930. $this->unlink($dir);
  18931. }
  18932. if ($ensureDirectoryExists) {
  18933. $this->ensureDirectoryExists($dir);
  18934. }
  18935. if (is_dir($dir)) {
  18936. $finder = Finder::create()
  18937. ->ignoreVCS(false)
  18938. ->ignoreDotFiles(false)
  18939. ->depth(0)
  18940. ->in($dir);
  18941. foreach ($finder as $path) {
  18942. $this->remove((string) $path);
  18943. }
  18944. }
  18945. }
  18946. public function removeDirectory($directory)
  18947. {
  18948. if ($this->isSymlinkedDirectory($directory)) {
  18949. return $this->unlinkSymlinkedDirectory($directory);
  18950. }
  18951. if (!file_exists($directory) || !is_dir($directory)) {
  18952. return true;
  18953. }
  18954. if (preg_match('{^(?:[a-z]:)?[/\\\\]+$}i', $directory)) {
  18955. throw new \RuntimeException('Aborting an attempted deletion of '.$directory.', this was probably not intended, if it is a real use case please report it.');
  18956. }
  18957. if (!function_exists('proc_open')) {
  18958. return $this->removeDirectoryPhp($directory);
  18959. }
  18960. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  18961. $cmd = sprintf('rmdir /S /Q %s', ProcessExecutor::escape(realpath($directory)));
  18962. } else {
  18963. $cmd = sprintf('rm -rf %s', ProcessExecutor::escape($directory));
  18964. }
  18965. $result = $this->getProcess()->execute($cmd, $output) === 0;
  18966. clearstatcache();
  18967. if ($result && !file_exists($directory)) {
  18968. return true;
  18969. }
  18970. return $this->removeDirectoryPhp($directory);
  18971. }
  18972. public function removeDirectoryPhp($directory)
  18973. {
  18974. $it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
  18975. $ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
  18976. foreach ($ri as $file) {
  18977. if ($file->isDir()) {
  18978. $this->rmdir($file->getPathname());
  18979. } else {
  18980. $this->unlink($file->getPathname());
  18981. }
  18982. }
  18983. return $this->rmdir($directory);
  18984. }
  18985. public function ensureDirectoryExists($directory)
  18986. {
  18987. if (!is_dir($directory)) {
  18988. if (file_exists($directory)) {
  18989. throw new \RuntimeException(
  18990. $directory.' exists and is not a directory.'
  18991. );
  18992. }
  18993. if (!@mkdir($directory, 0777, true)) {
  18994. throw new \RuntimeException(
  18995. $directory.' does not exist and could not be created.'
  18996. );
  18997. }
  18998. }
  18999. }
  19000. public function unlink($path)
  19001. {
  19002. if (!@$this->unlinkImplementation($path)) {
  19003. if (!defined('PHP_WINDOWS_VERSION_BUILD') || (usleep(350000) && !@$this->unlinkImplementation($path))) {
  19004. $error = error_get_last();
  19005. $message = 'Could not delete '.$path.': ' . @$error['message'];
  19006. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  19007. $message .= "\nThis can be due to an antivirus or the Windows Search Indexer locking the file while they are analyzed";
  19008. }
  19009. throw new \RuntimeException($message);
  19010. }
  19011. }
  19012. return true;
  19013. }
  19014. public function rmdir($path)
  19015. {
  19016. if (!@rmdir($path)) {
  19017. if (!defined('PHP_WINDOWS_VERSION_BUILD') || (usleep(350000) && !@rmdir($path))) {
  19018. $error = error_get_last();
  19019. $message = 'Could not delete '.$path.': ' . @$error['message'];
  19020. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  19021. $message .= "\nThis can be due to an antivirus or the Windows Search Indexer locking the file while they are analyzed";
  19022. }
  19023. throw new \RuntimeException($message);
  19024. }
  19025. }
  19026. return true;
  19027. }
  19028. public function copyThenRemove($source, $target)
  19029. {
  19030. if (!is_dir($source)) {
  19031. copy($source, $target);
  19032. $this->unlink($source);
  19033. return;
  19034. }
  19035. $it = new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS);
  19036. $ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::SELF_FIRST);
  19037. $this->ensureDirectoryExists($target);
  19038. foreach ($ri as $file) {
  19039. $targetPath = $target . DIRECTORY_SEPARATOR . $ri->getSubPathName();
  19040. if ($file->isDir()) {
  19041. $this->ensureDirectoryExists($targetPath);
  19042. } else {
  19043. copy($file->getPathname(), $targetPath);
  19044. }
  19045. }
  19046. $this->removeDirectoryPhp($source);
  19047. }
  19048. public function rename($source, $target)
  19049. {
  19050. if (true === @rename($source, $target)) {
  19051. return;
  19052. }
  19053. if (!function_exists('proc_open')) {
  19054. return $this->copyThenRemove($source, $target);
  19055. }
  19056. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  19057. $command = sprintf('xcopy %s %s /E /I /Q', ProcessExecutor::escape($source), ProcessExecutor::escape($target));
  19058. $result = $this->processExecutor->execute($command, $output);
  19059. clearstatcache();
  19060. if (0 === $result) {
  19061. $this->remove($source);
  19062. return;
  19063. }
  19064. } else {
  19065. $command = sprintf('mv %s %s', ProcessExecutor::escape($source), ProcessExecutor::escape($target));
  19066. $result = $this->processExecutor->execute($command, $output);
  19067. clearstatcache();
  19068. if (0 === $result) {
  19069. return;
  19070. }
  19071. }
  19072. return $this->copyThenRemove($source, $target);
  19073. }
  19074. public function findShortestPath($from, $to, $directories = false)
  19075. {
  19076. if (!$this->isAbsolutePath($from) || !$this->isAbsolutePath($to)) {
  19077. throw new \InvalidArgumentException(sprintf('$from (%s) and $to (%s) must be absolute paths.', $from, $to));
  19078. }
  19079. $from = lcfirst($this->normalizePath($from));
  19080. $to = lcfirst($this->normalizePath($to));
  19081. if ($directories) {
  19082. $from = rtrim($from, '/') . '/dummy_file';
  19083. }
  19084. if (dirname($from) === dirname($to)) {
  19085. return './'.basename($to);
  19086. }
  19087. $commonPath = $to;
  19088. while (strpos($from.'/', $commonPath.'/') !== 0 && '/' !== $commonPath && !preg_match('{^[a-z]:/?$}i', $commonPath)) {
  19089. $commonPath = strtr(dirname($commonPath), '\\', '/');
  19090. }
  19091. if (0 !== strpos($from, $commonPath) || '/' === $commonPath) {
  19092. return $to;
  19093. }
  19094. $commonPath = rtrim($commonPath, '/') . '/';
  19095. $sourcePathDepth = substr_count(substr($from, strlen($commonPath)), '/');
  19096. $commonPathCode = str_repeat('../', $sourcePathDepth);
  19097. return ($commonPathCode . substr($to, strlen($commonPath))) ?: './';
  19098. }
  19099. public function findShortestPathCode($from, $to, $directories = false)
  19100. {
  19101. if (!$this->isAbsolutePath($from) || !$this->isAbsolutePath($to)) {
  19102. throw new \InvalidArgumentException(sprintf('$from (%s) and $to (%s) must be absolute paths.', $from, $to));
  19103. }
  19104. $from = lcfirst($this->normalizePath($from));
  19105. $to = lcfirst($this->normalizePath($to));
  19106. if ($from === $to) {
  19107. return $directories ? '__DIR__' : '__FILE__';
  19108. }
  19109. $commonPath = $to;
  19110. while (strpos($from.'/', $commonPath.'/') !== 0 && '/' !== $commonPath && !preg_match('{^[a-z]:/?$}i', $commonPath) && '.' !== $commonPath) {
  19111. $commonPath = strtr(dirname($commonPath), '\\', '/');
  19112. }
  19113. if (0 !== strpos($from, $commonPath) || '/' === $commonPath || '.' === $commonPath) {
  19114. return var_export($to, true);
  19115. }
  19116. $commonPath = rtrim($commonPath, '/') . '/';
  19117. if (strpos($to, $from.'/') === 0) {
  19118. return '__DIR__ . '.var_export(substr($to, strlen($from)), true);
  19119. }
  19120. $sourcePathDepth = substr_count(substr($from, strlen($commonPath)), '/') + $directories;
  19121. $commonPathCode = str_repeat('dirname(', $sourcePathDepth).'__DIR__'.str_repeat(')', $sourcePathDepth);
  19122. $relTarget = substr($to, strlen($commonPath));
  19123. return $commonPathCode . (strlen($relTarget) ? '.' . var_export('/' . $relTarget, true) : '');
  19124. }
  19125. public function isAbsolutePath($path)
  19126. {
  19127. return substr($path, 0, 1) === '/' || substr($path, 1, 1) === ':';
  19128. }
  19129. public function size($path)
  19130. {
  19131. if (!file_exists($path)) {
  19132. throw new \RuntimeException("$path does not exist.");
  19133. }
  19134. if (is_dir($path)) {
  19135. return $this->directorySize($path);
  19136. }
  19137. return filesize($path);
  19138. }
  19139. public function normalizePath($path)
  19140. {
  19141. $parts = array();
  19142. $path = strtr($path, '\\', '/');
  19143. $prefix = '';
  19144. $absolute = false;
  19145. if (preg_match('{^([0-9a-z]+:(?://(?:[a-z]:)?)?)}i', $path, $match)) {
  19146. $prefix = $match[1];
  19147. $path = substr($path, strlen($prefix));
  19148. }
  19149. if (substr($path, 0, 1) === '/') {
  19150. $absolute = true;
  19151. $path = substr($path, 1);
  19152. }
  19153. $up = false;
  19154. foreach (explode('/', $path) as $chunk) {
  19155. if ('..' === $chunk && ($absolute || $up)) {
  19156. array_pop($parts);
  19157. $up = !(empty($parts) || '..' === end($parts));
  19158. } elseif ('.' !== $chunk && '' !== $chunk) {
  19159. $parts[] = $chunk;
  19160. $up = '..' !== $chunk;
  19161. }
  19162. }
  19163. return $prefix.($absolute ? '/' : '').implode('/', $parts);
  19164. }
  19165. public static function isLocalPath($path)
  19166. {
  19167. return (bool) preg_match('{^(file://|/|[a-z]:[\\\\/]|\.\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i', $path);
  19168. }
  19169. public static function getPlatformPath($path)
  19170. {
  19171. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  19172. $path = preg_replace('{^(?:file:///([a-z])/)}i', 'file://$1:/', $path);
  19173. }
  19174. return preg_replace('{^file://}i', '', $path);
  19175. }
  19176. protected function directorySize($directory)
  19177. {
  19178. $it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
  19179. $ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
  19180. $size = 0;
  19181. foreach ($ri as $file) {
  19182. if ($file->isFile()) {
  19183. $size += $file->getSize();
  19184. }
  19185. }
  19186. return $size;
  19187. }
  19188. protected function getProcess()
  19189. {
  19190. return new ProcessExecutor;
  19191. }
  19192. private function unlinkImplementation($path)
  19193. {
  19194. if (defined('PHP_WINDOWS_VERSION_BUILD') && is_dir($path) && is_link($path)) {
  19195. return rmdir($path);
  19196. }
  19197. return unlink($path);
  19198. }
  19199. public function isSymlinkedDirectory($directory)
  19200. {
  19201. if (!is_dir($directory)) {
  19202. return false;
  19203. }
  19204. $resolved = $this->resolveSymlinkedDirectorySymlink($directory);
  19205. return is_link($resolved);
  19206. }
  19207. private function unlinkSymlinkedDirectory($directory)
  19208. {
  19209. $resolved = $this->resolveSymlinkedDirectorySymlink($directory);
  19210. return $this->unlink($resolved);
  19211. }
  19212. private function resolveSymlinkedDirectorySymlink($pathname)
  19213. {
  19214. if (!is_dir($pathname)) {
  19215. return $pathname;
  19216. }
  19217. $resolved = rtrim($pathname, '/');
  19218. if (!strlen($resolved)) {
  19219. return $pathname;
  19220. }
  19221. return $resolved;
  19222. }
  19223. }
  19224. <?php
  19225. namespace Composer\Util;
  19226. use Composer\Config;
  19227. use Composer\IO\IOInterface;
  19228. class Git
  19229. {
  19230. protected $io;
  19231. protected $config;
  19232. protected $process;
  19233. protected $filesystem;
  19234. public function __construct(IOInterface $io, Config $config, ProcessExecutor $process, Filesystem $fs)
  19235. {
  19236. $this->io = $io;
  19237. $this->config = $config;
  19238. $this->process = $process;
  19239. $this->filesystem = $fs;
  19240. }
  19241. public function runCommand($commandCallable, $url, $cwd, $initialClone = false)
  19242. {
  19243. if ($initialClone) {
  19244. $origCwd = $cwd;
  19245. $cwd = null;
  19246. }
  19247. if (preg_match('{^ssh://[^@]+@[^:]+:[^0-9]+}', $url)) {
  19248. throw new \InvalidArgumentException('The source URL '.$url.' is invalid, ssh URLs should have a port number after ":".'."\n".'Use ssh://git@example.com:22/path or just git@example.com:path if you do not want to provide a password or custom port.');
  19249. }
  19250. if (!$initialClone) {
  19251. $this->process->execute('git remote -v', $output, $cwd);
  19252. if (preg_match('{^(?:composer|origin)\s+https?://(.+):(.+)@([^/]+)}im', $output, $match)) {
  19253. $this->io->setAuthentication($match[3], urldecode($match[1]), urldecode($match[2]));
  19254. }
  19255. }
  19256. $protocols = $this->config->get('github-protocols');
  19257. if (!is_array($protocols)) {
  19258. throw new \RuntimeException('Config value "github-protocols" must be an array, got '.gettype($protocols));
  19259. }
  19260. if (preg_match('{^(?:https?|git)://'.self::getGitHubDomainsRegex($this->config).'/(.*)}', $url, $match)) {
  19261. $messages = array();
  19262. foreach ($protocols as $protocol) {
  19263. if ('ssh' === $protocol) {
  19264. $url = "git@" . $match[1] . ":" . $match[2];
  19265. } else {
  19266. $url = $protocol ."://" . $match[1] . "/" . $match[2];
  19267. }
  19268. if (0 === $this->process->execute(call_user_func($commandCallable, $url), $ignoredOutput, $cwd)) {
  19269. return;
  19270. }
  19271. $messages[] = '- ' . $url . "\n" . preg_replace('#^#m', ' ', $this->process->getErrorOutput());
  19272. if ($initialClone) {
  19273. $this->filesystem->removeDirectory($origCwd);
  19274. }
  19275. }
  19276. $this->throwException('Failed to clone ' . self::sanitizeUrl($url) .' via '.implode(', ', $protocols).' protocols, aborting.' . "\n\n" . implode("\n", $messages), $url);
  19277. }
  19278. $bypassSshForGitHub = preg_match('{^git@'.self::getGitHubDomainsRegex($this->config).':(.+?)\.git$}i', $url) && !in_array('ssh', $protocols, true);
  19279. $command = call_user_func($commandCallable, $url);
  19280. if ($bypassSshForGitHub || 0 !== $this->process->execute($command, $ignoredOutput, $cwd)) {
  19281. if (preg_match('{^git@'.self::getGitHubDomainsRegex($this->config).':(.+?)\.git$}i', $url, $match)) {
  19282. if (!$this->io->hasAuthentication($match[1])) {
  19283. $gitHubUtil = new GitHub($this->io, $this->config, $this->process);
  19284. $message = 'Cloning failed using an ssh key for authentication, enter your GitHub credentials to access private repos';
  19285. if (!$gitHubUtil->authorizeOAuth($match[1]) && $this->io->isInteractive()) {
  19286. $gitHubUtil->authorizeOAuthInteractively($match[1], $message);
  19287. }
  19288. }
  19289. if ($this->io->hasAuthentication($match[1])) {
  19290. $auth = $this->io->getAuthentication($match[1]);
  19291. $url = 'https://'.rawurlencode($auth['username']) . ':' . rawurlencode($auth['password']) . '@'.$match[1].'/'.$match[2].'.git';
  19292. $command = call_user_func($commandCallable, $url);
  19293. if (0 === $this->process->execute($command, $ignoredOutput, $cwd)) {
  19294. return;
  19295. }
  19296. }
  19297. } elseif ($this->isAuthenticationFailure($url, $match)) {
  19298. if (strpos($match[2], '@')) {
  19299. list($authParts, $match[2]) = explode('@', $match[2], 2);
  19300. }
  19301. $storeAuth = false;
  19302. if ($this->io->hasAuthentication($match[2])) {
  19303. $auth = $this->io->getAuthentication($match[2]);
  19304. } elseif ($this->io->isInteractive()) {
  19305. $defaultUsername = null;
  19306. if (isset($authParts) && $authParts) {
  19307. if (false !== strpos($authParts, ':')) {
  19308. list($defaultUsername, ) = explode(':', $authParts, 2);
  19309. } else {
  19310. $defaultUsername = $authParts;
  19311. }
  19312. }
  19313. $this->io->writeError(' Authentication required (<info>'.parse_url($url, PHP_URL_HOST).'</info>):');
  19314. $auth = array(
  19315. 'username' => $this->io->ask(' Username: ', $defaultUsername),
  19316. 'password' => $this->io->askAndHideAnswer(' Password: '),
  19317. );
  19318. $storeAuth = $this->config->get('store-auths');
  19319. }
  19320. if ($auth) {
  19321. $url = $match[1].rawurlencode($auth['username']).':'.rawurlencode($auth['password']).'@'.$match[2].$match[3];
  19322. $command = call_user_func($commandCallable, $url);
  19323. if (0 === $this->process->execute($command, $ignoredOutput, $cwd)) {
  19324. $this->io->setAuthentication($match[2], $auth['username'], $auth['password']);
  19325. $authHelper = new AuthHelper($this->io, $this->config);
  19326. $authHelper->storeAuth($match[2], $storeAuth);
  19327. return;
  19328. }
  19329. }
  19330. }
  19331. if ($initialClone) {
  19332. $this->filesystem->removeDirectory($origCwd);
  19333. }
  19334. $this->throwException('Failed to execute ' . self::sanitizeUrl($command) . "\n\n" . $this->process->getErrorOutput(), $url);
  19335. }
  19336. }
  19337. private function isAuthenticationFailure($url, &$match)
  19338. {
  19339. if (!preg_match('{(https?://)([^/]+)(.*)$}i', $url, $match)) {
  19340. return false;
  19341. }
  19342. $authFailures = array('fatal: Authentication failed', 'remote error: Invalid username or password.');
  19343. foreach ($authFailures as $authFailure) {
  19344. if (strpos($this->process->getErrorOutput(), $authFailure) !== false) {
  19345. return true;
  19346. }
  19347. }
  19348. return false;
  19349. }
  19350. public static function cleanEnv()
  19351. {
  19352. if (ini_get('safe_mode') && false === strpos(ini_get('safe_mode_allowed_env_vars'), 'GIT_ASKPASS')) {
  19353. throw new \RuntimeException('safe_mode is enabled and safe_mode_allowed_env_vars does not contain GIT_ASKPASS, can not set env var. You can disable safe_mode with "-dsafe_mode=0" when running composer');
  19354. }
  19355. if (getenv('GIT_ASKPASS') !== 'echo') {
  19356. putenv('GIT_ASKPASS=echo');
  19357. unset($_SERVER['GIT_ASKPASS']);
  19358. }
  19359. if (getenv('GIT_DIR')) {
  19360. putenv('GIT_DIR');
  19361. unset($_SERVER['GIT_DIR']);
  19362. }
  19363. if (getenv('GIT_WORK_TREE')) {
  19364. putenv('GIT_WORK_TREE');
  19365. unset($_SERVER['GIT_WORK_TREE']);
  19366. }
  19367. if (getenv('LANGUAGE') !== 'C') {
  19368. putenv('LANGUAGE=C');
  19369. }
  19370. putenv("DYLD_LIBRARY_PATH");
  19371. unset($_SERVER['DYLD_LIBRARY_PATH']);
  19372. }
  19373. public static function getGitHubDomainsRegex(Config $config)
  19374. {
  19375. return '('.implode('|', array_map('preg_quote', $config->get('github-domains'))).')';
  19376. }
  19377. public static function sanitizeUrl($message)
  19378. {
  19379. return preg_replace('{://([^@]+?):.+?@}', '://$1:***@', $message);
  19380. }
  19381. private function throwException($message, $url)
  19382. {
  19383. clearstatcache();
  19384. if (0 !== $this->process->execute('git --version', $ignoredOutput)) {
  19385. throw new \RuntimeException('Failed to clone '.self::sanitizeUrl($url).', git was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput());
  19386. }
  19387. throw new \RuntimeException($message);
  19388. }
  19389. }
  19390. <?php
  19391. namespace Composer\Util;
  19392. use Composer\IO\IOInterface;
  19393. use Composer\Config;
  19394. use Composer\Downloader\TransportException;
  19395. class GitHub
  19396. {
  19397. protected $io;
  19398. protected $config;
  19399. protected $process;
  19400. protected $remoteFilesystem;
  19401. public function __construct(IOInterface $io, Config $config, ProcessExecutor $process = null, RemoteFilesystem $remoteFilesystem = null)
  19402. {
  19403. $this->io = $io;
  19404. $this->config = $config;
  19405. $this->process = $process ?: new ProcessExecutor;
  19406. $this->remoteFilesystem = $remoteFilesystem ?: new RemoteFilesystem($io, $config);
  19407. }
  19408. public function authorizeOAuth($originUrl)
  19409. {
  19410. if (!in_array($originUrl, $this->config->get('github-domains'))) {
  19411. return false;
  19412. }
  19413. if (0 === $this->process->execute('git config github.accesstoken', $output)) {
  19414. $this->io->setAuthentication($originUrl, trim($output), 'x-oauth-basic');
  19415. return true;
  19416. }
  19417. return false;
  19418. }
  19419. public function authorizeOAuthInteractively($originUrl, $message = null)
  19420. {
  19421. if ($message) {
  19422. $this->io->writeError($message);
  19423. }
  19424. $note = 'Composer';
  19425. if ($this->config->get('github-expose-hostname') === true && 0 === $this->process->execute('hostname', $output)) {
  19426. $note .= ' on ' . trim($output);
  19427. }
  19428. $note .= ' ' . date('Y-m-d Hi');
  19429. $url = 'https://'.$originUrl.'/settings/tokens/new?scopes=repo&description=' . str_replace('%20', '+', rawurlencode($note));
  19430. $this->io->writeError(sprintf('Head to %s', $url));
  19431. $this->io->writeError(sprintf('to retrieve a token. It will be stored in "%s" for future use by Composer.', $this->config->getAuthConfigSource()->getName()));
  19432. $token = trim($this->io->askAndHideAnswer('Token (hidden): '));
  19433. if (!$token) {
  19434. $this->io->writeError('<warning>No token given, aborting.</warning>');
  19435. $this->io->writeError('You can also add it manually later by using "composer config github-oauth.github.com <token>"');
  19436. return false;
  19437. }
  19438. $this->io->setAuthentication($originUrl, $token, 'x-oauth-basic');
  19439. try {
  19440. $apiUrl = ('github.com' === $originUrl) ? 'api.github.com' : $originUrl . '/api/v3';
  19441. $this->remoteFilesystem->getContents($originUrl, 'https://'. $apiUrl . '/rate_limit', false, array(
  19442. 'retry-auth-failure' => false,
  19443. ));
  19444. } catch (TransportException $e) {
  19445. if (in_array($e->getCode(), array(403, 401))) {
  19446. $this->io->writeError('<error>Invalid token provided.</error>');
  19447. $this->io->writeError('You can also add it manually later by using "composer config github-oauth.github.com <token>"');
  19448. return false;
  19449. }
  19450. throw $e;
  19451. }
  19452. $this->config->getConfigSource()->removeConfigSetting('github-oauth.'.$originUrl);
  19453. $this->config->getAuthConfigSource()->addConfigSetting('github-oauth.'.$originUrl, $token);
  19454. $this->io->writeError('<info>Token stored successfully.</info>');
  19455. return true;
  19456. }
  19457. }
  19458. <?php
  19459. namespace Composer\Util;
  19460. class NoProxyPattern
  19461. {
  19462. protected $rules = array();
  19463. public function __construct($pattern)
  19464. {
  19465. $this->rules = preg_split("/[\s,]+/", $pattern);
  19466. }
  19467. public function test($url)
  19468. {
  19469. $host = parse_url($url, PHP_URL_HOST);
  19470. $port = parse_url($url, PHP_URL_PORT);
  19471. if (empty($port)) {
  19472. switch (parse_url($url, PHP_URL_SCHEME)) {
  19473. case 'http':
  19474. $port = 80;
  19475. break;
  19476. case 'https':
  19477. $port = 443;
  19478. break;
  19479. }
  19480. }
  19481. foreach ($this->rules as $rule) {
  19482. if ($rule == '*') {
  19483. return true;
  19484. }
  19485. $match = false;
  19486. list($ruleHost) = explode(':', $rule);
  19487. list($base) = explode('/', $ruleHost);
  19488. if (filter_var($base, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
  19489. if (!isset($ip)) {
  19490. $ip = gethostbyname($host);
  19491. }
  19492. if (strpos($ruleHost, '/') === false) {
  19493. $match = $ip === $ruleHost;
  19494. } else {
  19495. if ($ip === $host) {
  19496. $match = false;
  19497. } else {
  19498. $match = self::inCIDRBlock($ruleHost, $ip);
  19499. }
  19500. }
  19501. } else {
  19502. $haystack = '.' . trim($host, '.') . '.';
  19503. $needle = '.'. trim($ruleHost, '.') .'.';
  19504. $match = stripos(strrev($haystack), strrev($needle)) === 0;
  19505. }
  19506. if ($match && strpos($rule, ':') !== false) {
  19507. list(, $rulePort) = explode(':', $rule);
  19508. if (!empty($rulePort) && $port != $rulePort) {
  19509. $match = false;
  19510. }
  19511. }
  19512. if ($match) {
  19513. return true;
  19514. }
  19515. }
  19516. return false;
  19517. }
  19518. private static function inCIDRBlock($cidr, $ip)
  19519. {
  19520. list($base, $bits) = explode('/', $cidr);
  19521. list($a, $b, $c, $d) = explode('.', $base);
  19522. $i = ($a << 24) + ($b << 16) + ($c << 8) + $d;
  19523. $mask = $bits == 0 ? 0 : (~0 << (32 - $bits));
  19524. $low = $i & $mask;
  19525. $high = $i | (~$mask & 0xFFFFFFFF);
  19526. list($a, $b, $c, $d) = explode('.', $ip);
  19527. $check = ($a << 24) + ($b << 16) + ($c << 8) + $d;
  19528. return $check >= $low && $check <= $high;
  19529. }
  19530. }
  19531. <?php
  19532. namespace Composer\Util;
  19533. use Composer\IO\IOInterface;
  19534. use Symfony\Component\Process\Process;
  19535. class Perforce
  19536. {
  19537. protected $path;
  19538. protected $p4Depot;
  19539. protected $p4Client;
  19540. protected $p4User;
  19541. protected $p4Password;
  19542. protected $p4Port;
  19543. protected $p4Stream;
  19544. protected $p4ClientSpec;
  19545. protected $p4DepotType;
  19546. protected $p4Branch;
  19547. protected $process;
  19548. protected $uniquePerforceClientName;
  19549. protected $windowsFlag;
  19550. protected $commandResult;
  19551. protected $io;
  19552. protected $filesystem;
  19553. public function __construct($repoConfig, $port, $path, ProcessExecutor $process, $isWindows, IOInterface $io)
  19554. {
  19555. $this->windowsFlag = $isWindows;
  19556. $this->p4Port = $port;
  19557. $this->initializePath($path);
  19558. $this->process = $process;
  19559. $this->initialize($repoConfig);
  19560. $this->io = $io;
  19561. }
  19562. public static function create($repoConfig, $port, $path, ProcessExecutor $process, IOInterface $io)
  19563. {
  19564. $isWindows = defined('PHP_WINDOWS_VERSION_BUILD');
  19565. $perforce = new Perforce($repoConfig, $port, $path, $process, $isWindows, $io);
  19566. return $perforce;
  19567. }
  19568. public static function checkServerExists($url, ProcessExecutor $processExecutor)
  19569. {
  19570. $output = null;
  19571. return 0 === $processExecutor->execute('p4 -p ' . $url . ' info -s', $output);
  19572. }
  19573. public function initialize($repoConfig)
  19574. {
  19575. $this->uniquePerforceClientName = $this->generateUniquePerforceClientName();
  19576. if (null == $repoConfig) {
  19577. return;
  19578. }
  19579. if (isset($repoConfig['unique_perforce_client_name'])) {
  19580. $this->uniquePerforceClientName = $repoConfig['unique_perforce_client_name'];
  19581. }
  19582. if (isset($repoConfig['depot'])) {
  19583. $this->p4Depot = $repoConfig['depot'];
  19584. }
  19585. if (isset($repoConfig['branch'])) {
  19586. $this->p4Branch = $repoConfig['branch'];
  19587. }
  19588. if (isset($repoConfig['p4user'])) {
  19589. $this->p4User = $repoConfig['p4user'];
  19590. } else {
  19591. $this->p4User = $this->getP4variable('P4USER');
  19592. }
  19593. if (isset($repoConfig['p4password'])) {
  19594. $this->p4Password = $repoConfig['p4password'];
  19595. }
  19596. }
  19597. public function initializeDepotAndBranch($depot, $branch)
  19598. {
  19599. if (isset($depot)) {
  19600. $this->p4Depot = $depot;
  19601. }
  19602. if (isset($branch)) {
  19603. $this->p4Branch = $branch;
  19604. }
  19605. }
  19606. public function generateUniquePerforceClientName()
  19607. {
  19608. return gethostname() . "_" . time();
  19609. }
  19610. public function cleanupClientSpec()
  19611. {
  19612. $client = $this->getClient();
  19613. $task = 'client -d ' . $client;
  19614. $useP4Client = false;
  19615. $command = $this->generateP4Command($task, $useP4Client);
  19616. $this->executeCommand($command);
  19617. $clientSpec = $this->getP4ClientSpec();
  19618. $fileSystem = $this->getFilesystem();
  19619. $fileSystem->remove($clientSpec);
  19620. }
  19621. protected function executeCommand($command)
  19622. {
  19623. $this->commandResult = "";
  19624. $exit_code = $this->process->execute($command, $this->commandResult);
  19625. return $exit_code;
  19626. }
  19627. public function getClient()
  19628. {
  19629. if (!isset($this->p4Client)) {
  19630. $cleanStreamName = str_replace('@', '', str_replace('/', '_', str_replace('//', '', $this->getStream())));
  19631. $this->p4Client = 'composer_perforce_' . $this->uniquePerforceClientName . '_' . $cleanStreamName;
  19632. }
  19633. return $this->p4Client;
  19634. }
  19635. protected function getPath()
  19636. {
  19637. return $this->path;
  19638. }
  19639. public function initializePath($path)
  19640. {
  19641. $this->path = $path;
  19642. $fs = $this->getFilesystem();
  19643. $fs->ensureDirectoryExists($path);
  19644. }
  19645. protected function getPort()
  19646. {
  19647. return $this->p4Port;
  19648. }
  19649. public function setStream($stream)
  19650. {
  19651. $this->p4Stream = $stream;
  19652. $index = strrpos($stream, '/');
  19653. if ($index > 2) {
  19654. $this->p4DepotType = 'stream';
  19655. }
  19656. }
  19657. public function isStream()
  19658. {
  19659. return (strcmp($this->p4DepotType, 'stream') === 0);
  19660. }
  19661. public function getStream()
  19662. {
  19663. if (!isset($this->p4Stream)) {
  19664. if ($this->isStream()) {
  19665. $this->p4Stream = '//' . $this->p4Depot . '/' . $this->p4Branch;
  19666. } else {
  19667. $this->p4Stream = '//' . $this->p4Depot;
  19668. }
  19669. }
  19670. return $this->p4Stream;
  19671. }
  19672. public function getStreamWithoutLabel($stream)
  19673. {
  19674. $index = strpos($stream, '@');
  19675. if ($index === false) {
  19676. return $stream;
  19677. }
  19678. return substr($stream, 0, $index);
  19679. }
  19680. public function getP4ClientSpec()
  19681. {
  19682. $p4clientSpec = $this->path . '/' . $this->getClient() . '.p4.spec';
  19683. return $p4clientSpec;
  19684. }
  19685. public function getUser()
  19686. {
  19687. return $this->p4User;
  19688. }
  19689. public function setUser($user)
  19690. {
  19691. $this->p4User = $user;
  19692. }
  19693. public function queryP4User()
  19694. {
  19695. $this->getUser();
  19696. if (strlen($this->p4User) > 0) {
  19697. return;
  19698. }
  19699. $this->p4User = $this->getP4variable('P4USER');
  19700. if (strlen($this->p4User) > 0) {
  19701. return;
  19702. }
  19703. $this->p4User = $this->io->ask('Enter P4 User:');
  19704. if ($this->windowsFlag) {
  19705. $command = 'p4 set P4USER=' . $this->p4User;
  19706. } else {
  19707. $command = 'export P4USER=' . $this->p4User;
  19708. }
  19709. $this->executeCommand($command);
  19710. }
  19711. protected function getP4variable($name)
  19712. {
  19713. if ($this->windowsFlag) {
  19714. $command = 'p4 set';
  19715. $this->executeCommand($command);
  19716. $result = trim($this->commandResult);
  19717. $resArray = explode(PHP_EOL, $result);
  19718. foreach ($resArray as $line) {
  19719. $fields = explode('=', $line);
  19720. if (strcmp($name, $fields[0]) == 0) {
  19721. $index = strpos($fields[1], ' ');
  19722. if ($index === false) {
  19723. $value = $fields[1];
  19724. } else {
  19725. $value = substr($fields[1], 0, $index);
  19726. }
  19727. $value = trim($value);
  19728. return $value;
  19729. }
  19730. }
  19731. } else {
  19732. $command = 'echo $' . $name;
  19733. $this->executeCommand($command);
  19734. $result = trim($this->commandResult);
  19735. return $result;
  19736. }
  19737. }
  19738. public function queryP4Password()
  19739. {
  19740. if (isset($this->p4Password)) {
  19741. return $this->p4Password;
  19742. }
  19743. $password = $this->getP4variable('P4PASSWD');
  19744. if (strlen($password) <= 0) {
  19745. $password = $this->io->askAndHideAnswer('Enter password for Perforce user ' . $this->getUser() . ': ');
  19746. }
  19747. $this->p4Password = $password;
  19748. return $password;
  19749. }
  19750. public function generateP4Command($command, $useClient = true)
  19751. {
  19752. $p4Command = 'p4 ';
  19753. $p4Command = $p4Command . '-u ' . $this->getUser() . ' ';
  19754. if ($useClient) {
  19755. $p4Command = $p4Command . '-c ' . $this->getClient() . ' ';
  19756. }
  19757. $p4Command = $p4Command . '-p ' . $this->getPort() . ' ';
  19758. $p4Command = $p4Command . $command;
  19759. return $p4Command;
  19760. }
  19761. public function isLoggedIn()
  19762. {
  19763. $command = $this->generateP4Command('login -s', false);
  19764. $exitCode = $this->executeCommand($command);
  19765. if ($exitCode) {
  19766. $errorOutput = $this->process->getErrorOutput();
  19767. $index = strpos($errorOutput, $this->getUser());
  19768. if ($index === false) {
  19769. $index = strpos($errorOutput, 'p4');
  19770. if ($index === false) {
  19771. return false;
  19772. }
  19773. throw new \Exception('p4 command not found in path: ' . $errorOutput);
  19774. }
  19775. throw new \Exception('Invalid user name: ' . $this->getUser());
  19776. }
  19777. return true;
  19778. }
  19779. public function connectClient()
  19780. {
  19781. $p4CreateClientCommand = $this->generateP4Command('client -i < ' . str_replace(" ", "\\ ", $this->getP4ClientSpec()));
  19782. $this->executeCommand($p4CreateClientCommand);
  19783. }
  19784. public function syncCodeBase($sourceReference)
  19785. {
  19786. $prevDir = getcwd();
  19787. chdir($this->path);
  19788. $p4SyncCommand = $this->generateP4Command('sync -f ');
  19789. if (null != $sourceReference) {
  19790. $p4SyncCommand = $p4SyncCommand . '@' . $sourceReference;
  19791. }
  19792. $this->executeCommand($p4SyncCommand);
  19793. chdir($prevDir);
  19794. }
  19795. public function writeClientSpecToFile($spec)
  19796. {
  19797. fwrite($spec, 'Client: ' . $this->getClient() . PHP_EOL . PHP_EOL);
  19798. fwrite($spec, 'Update: ' . date('Y/m/d H:i:s') . PHP_EOL . PHP_EOL);
  19799. fwrite($spec, 'Access: ' . date('Y/m/d H:i:s') . PHP_EOL);
  19800. fwrite($spec, 'Owner: ' . $this->getUser() . PHP_EOL . PHP_EOL);
  19801. fwrite($spec, 'Description:' . PHP_EOL);
  19802. fwrite($spec, ' Created by ' . $this->getUser() . ' from composer.' . PHP_EOL . PHP_EOL);
  19803. fwrite($spec, 'Root: ' . $this->getPath() . PHP_EOL . PHP_EOL);
  19804. fwrite($spec, 'Options: noallwrite noclobber nocompress unlocked modtime rmdir' . PHP_EOL . PHP_EOL);
  19805. fwrite($spec, 'SubmitOptions: revertunchanged' . PHP_EOL . PHP_EOL);
  19806. fwrite($spec, 'LineEnd: local' . PHP_EOL . PHP_EOL);
  19807. if ($this->isStream()) {
  19808. fwrite($spec, 'Stream:' . PHP_EOL);
  19809. fwrite($spec, ' ' . $this->getStreamWithoutLabel($this->p4Stream) . PHP_EOL);
  19810. } else {
  19811. fwrite(
  19812. $spec,
  19813. 'View: ' . $this->getStream() . '/... //' . $this->getClient() . '/... ' . PHP_EOL
  19814. );
  19815. }
  19816. }
  19817. public function writeP4ClientSpec()
  19818. {
  19819. $clientSpec = $this->getP4ClientSpec();
  19820. $spec = fopen($clientSpec, 'w');
  19821. try {
  19822. $this->writeClientSpecToFile($spec);
  19823. } catch (\Exception $e) {
  19824. fclose($spec);
  19825. throw $e;
  19826. }
  19827. fclose($spec);
  19828. }
  19829. protected function read($pipe, $name)
  19830. {
  19831. if (feof($pipe)) {
  19832. return;
  19833. }
  19834. $line = fgets($pipe);
  19835. while ($line != false) {
  19836. $line = fgets($pipe);
  19837. }
  19838. return;
  19839. }
  19840. public function windowsLogin($password)
  19841. {
  19842. $command = $this->generateP4Command(' login -a');
  19843. $process = new Process($command, null, null, $password);
  19844. return $process->run();
  19845. }
  19846. public function p4Login()
  19847. {
  19848. $this->queryP4User();
  19849. if (!$this->isLoggedIn()) {
  19850. $password = $this->queryP4Password();
  19851. if ($this->windowsFlag) {
  19852. $this->windowsLogin($password);
  19853. } else {
  19854. $command = 'echo ' . $password . ' | ' . $this->generateP4Command(' login -a', false);
  19855. $exitCode = $this->executeCommand($command);
  19856. $result = trim($this->commandResult);
  19857. if ($exitCode) {
  19858. throw new \Exception("Error logging in:" . $this->process->getErrorOutput());
  19859. }
  19860. }
  19861. }
  19862. }
  19863. public function getComposerInformation($identifier)
  19864. {
  19865. $index = strpos($identifier, '@');
  19866. if ($index === false) {
  19867. $composerJson = $identifier. '/composer.json';
  19868. return $this->getComposerInformationFromPath($composerJson);
  19869. }
  19870. return $this->getComposerInformationFromLabel($identifier, $index);
  19871. }
  19872. public function getComposerInformationFromPath($composerJson)
  19873. {
  19874. $command = $this->generateP4Command(' print ' . $composerJson);
  19875. $this->executeCommand($command);
  19876. $result = $this->commandResult;
  19877. $index = strpos($result, '{');
  19878. if ($index === false) {
  19879. return '';
  19880. }
  19881. if ($index >= 0) {
  19882. $rawData = substr($result, $index);
  19883. $composer_info = json_decode($rawData, true);
  19884. return $composer_info;
  19885. }
  19886. return '';
  19887. }
  19888. public function getComposerInformationFromLabel($identifier, $index)
  19889. {
  19890. $composerJsonPath = substr($identifier, 0, $index) . '/composer.json' . substr($identifier, $index);
  19891. $command = $this->generateP4Command(' files ' . $composerJsonPath, false);
  19892. $this->executeCommand($command);
  19893. $result = $this->commandResult;
  19894. $index2 = strpos($result, 'no such file(s).');
  19895. if ($index2 === false) {
  19896. $index3 = strpos($result, 'change');
  19897. if (!($index3 === false)) {
  19898. $phrase = trim(substr($result, $index3));
  19899. $fields = explode(' ', $phrase);
  19900. $id = $fields[1];
  19901. $composerJson = substr($identifier, 0, $index) . '/composer.json@' . $id;
  19902. return $this->getComposerInformationFromPath($composerJson);
  19903. }
  19904. }
  19905. return "";
  19906. }
  19907. public function getBranches()
  19908. {
  19909. $possibleBranches = array();
  19910. if (!$this->isStream()) {
  19911. $possibleBranches[$this->p4Branch] = $this->getStream();
  19912. } else {
  19913. $command = $this->generateP4Command('streams //' . $this->p4Depot . '/...');
  19914. $this->executeCommand($command);
  19915. $result = $this->commandResult;
  19916. $resArray = explode(PHP_EOL, $result);
  19917. foreach ($resArray as $line) {
  19918. $resBits = explode(' ', $line);
  19919. if (count($resBits) > 4) {
  19920. $branch = preg_replace('/[^A-Za-z0-9 ]/', '', $resBits[4]);
  19921. $possibleBranches[$branch] = $resBits[1];
  19922. }
  19923. }
  19924. }
  19925. $command = $this->generateP4Command('changes '. $this->getStream() . '/...', false);
  19926. $this->executeCommand($command);
  19927. $result = $this->commandResult;
  19928. $resArray = explode(PHP_EOL, $result);
  19929. $lastCommit = $resArray[0];
  19930. $lastCommitArr = explode(' ', $lastCommit);
  19931. $lastCommitNum = $lastCommitArr[1];
  19932. $branches = array('master' => $possibleBranches[$this->p4Branch] . '@'. $lastCommitNum);
  19933. return $branches;
  19934. }
  19935. public function getTags()
  19936. {
  19937. $command = $this->generateP4Command('labels');
  19938. $this->executeCommand($command);
  19939. $result = $this->commandResult;
  19940. $resArray = explode(PHP_EOL, $result);
  19941. $tags = array();
  19942. foreach ($resArray as $line) {
  19943. $index = strpos($line, 'Label');
  19944. if (!($index === false)) {
  19945. $fields = explode(' ', $line);
  19946. $tags[$fields[1]] = $this->getStream() . '@' . $fields[1];
  19947. }
  19948. }
  19949. return $tags;
  19950. }
  19951. public function checkStream()
  19952. {
  19953. $command = $this->generateP4Command('depots', false);
  19954. $this->executeCommand($command);
  19955. $result = $this->commandResult;
  19956. $resArray = explode(PHP_EOL, $result);
  19957. foreach ($resArray as $line) {
  19958. $index = strpos($line, 'Depot');
  19959. if (!($index === false)) {
  19960. $fields = explode(' ', $line);
  19961. if (strcmp($this->p4Depot, $fields[1]) === 0) {
  19962. $this->p4DepotType = $fields[3];
  19963. return $this->isStream();
  19964. }
  19965. }
  19966. }
  19967. return false;
  19968. }
  19969. protected function getChangeList($reference)
  19970. {
  19971. $index = strpos($reference, '@');
  19972. if ($index === false) {
  19973. return;
  19974. }
  19975. $label = substr($reference, $index);
  19976. $command = $this->generateP4Command(' changes -m1 ' . $label);
  19977. $this->executeCommand($command);
  19978. $changes = $this->commandResult;
  19979. if (strpos($changes, 'Change') !== 0) {
  19980. return;
  19981. }
  19982. $fields = explode(' ', $changes);
  19983. $changeList = $fields[1];
  19984. return $changeList;
  19985. }
  19986. public function getCommitLogs($fromReference, $toReference)
  19987. {
  19988. $fromChangeList = $this->getChangeList($fromReference);
  19989. if ($fromChangeList == null) {
  19990. return;
  19991. }
  19992. $toChangeList = $this->getChangeList($toReference);
  19993. if ($toChangeList == null) {
  19994. return;
  19995. }
  19996. $index = strpos($fromReference, '@');
  19997. $main = substr($fromReference, 0, $index) . '/...';
  19998. $command = $this->generateP4Command('filelog ' . $main . '@' . $fromChangeList. ',' . $toChangeList);
  19999. $this->executeCommand($command);
  20000. $result = $this->commandResult;
  20001. return $result;
  20002. }
  20003. public function getFilesystem()
  20004. {
  20005. if (empty($this->filesystem)) {
  20006. $this->filesystem = new Filesystem($this->process);
  20007. }
  20008. return $this->filesystem;
  20009. }
  20010. public function setFilesystem(Filesystem $fs)
  20011. {
  20012. $this->filesystem = $fs;
  20013. }
  20014. }
  20015. <?php
  20016. namespace Composer\Util;
  20017. use Symfony\Component\Process\Process;
  20018. use Symfony\Component\Process\ProcessUtils;
  20019. use Composer\IO\IOInterface;
  20020. class ProcessExecutor
  20021. {
  20022. protected static $timeout = 300;
  20023. protected $captureOutput;
  20024. protected $errorOutput;
  20025. protected $io;
  20026. public function __construct(IOInterface $io = null)
  20027. {
  20028. $this->io = $io;
  20029. }
  20030. public function execute($command, &$output = null, $cwd = null)
  20031. {
  20032. if ($this->io && $this->io->isDebug()) {
  20033. $safeCommand = preg_replace('{(://[^:/\s]+:)[^@\s/]+}i', '$1****', $command);
  20034. $this->io->writeError('Executing command ('.($cwd ?: 'CWD').'): '.$safeCommand);
  20035. }
  20036. if (null === $cwd && defined('PHP_WINDOWS_VERSION_BUILD') && false !== strpos($command, 'git') && getcwd()) {
  20037. $cwd = realpath(getcwd());
  20038. }
  20039. $this->captureOutput = count(func_get_args()) > 1;
  20040. $this->errorOutput = null;
  20041. $process = new Process($command, $cwd, null, null, static::getTimeout());
  20042. $callback = is_callable($output) ? $output : array($this, 'outputHandler');
  20043. $process->run($callback);
  20044. if ($this->captureOutput && !is_callable($output)) {
  20045. $output = $process->getOutput();
  20046. }
  20047. $this->errorOutput = $process->getErrorOutput();
  20048. return $process->getExitCode();
  20049. }
  20050. public function splitLines($output)
  20051. {
  20052. $output = trim($output);
  20053. return ((string) $output === '') ? array() : preg_split('{\r?\n}', $output);
  20054. }
  20055. public function getErrorOutput()
  20056. {
  20057. return $this->errorOutput;
  20058. }
  20059. public function outputHandler($type, $buffer)
  20060. {
  20061. if ($this->captureOutput) {
  20062. return;
  20063. }
  20064. echo $buffer;
  20065. }
  20066. public static function getTimeout()
  20067. {
  20068. return static::$timeout;
  20069. }
  20070. public static function setTimeout($timeout)
  20071. {
  20072. static::$timeout = $timeout;
  20073. }
  20074. public static function escape($argument)
  20075. {
  20076. return ProcessUtils::escapeArgument($argument);
  20077. }
  20078. }
  20079. <?php
  20080. namespace Composer\Util;
  20081. use Composer\Composer;
  20082. use Composer\Config;
  20083. use Composer\IO\IOInterface;
  20084. use Composer\Downloader\TransportException;
  20085. class RemoteFilesystem
  20086. {
  20087. private $io;
  20088. private $config;
  20089. private $bytesMax;
  20090. private $originUrl;
  20091. private $fileUrl;
  20092. private $fileName;
  20093. private $retry;
  20094. private $progress;
  20095. private $lastProgress;
  20096. private $options;
  20097. private $retryAuthFailure;
  20098. private $lastHeaders;
  20099. private $storeAuth;
  20100. private $degradedMode = false;
  20101. public function __construct(IOInterface $io, Config $config = null, array $options = array())
  20102. {
  20103. $this->io = $io;
  20104. $this->config = $config;
  20105. $this->options = $options;
  20106. }
  20107. public function copy($originUrl, $fileUrl, $fileName, $progress = true, $options = array())
  20108. {
  20109. return $this->get($originUrl, $fileUrl, $options, $fileName, $progress);
  20110. }
  20111. public function getContents($originUrl, $fileUrl, $progress = true, $options = array())
  20112. {
  20113. return $this->get($originUrl, $fileUrl, $options, null, $progress);
  20114. }
  20115. public function getOptions()
  20116. {
  20117. return $this->options;
  20118. }
  20119. public function getLastHeaders()
  20120. {
  20121. return $this->lastHeaders;
  20122. }
  20123. protected function get($originUrl, $fileUrl, $additionalOptions = array(), $fileName = null, $progress = true)
  20124. {
  20125. if (strpos($originUrl, '.github.com') === (strlen($originUrl) - 11)) {
  20126. $originUrl = 'github.com';
  20127. }
  20128. $this->bytesMax = 0;
  20129. $this->originUrl = $originUrl;
  20130. $this->fileUrl = $fileUrl;
  20131. $this->fileName = $fileName;
  20132. $this->progress = $progress;
  20133. $this->lastProgress = null;
  20134. $this->retryAuthFailure = true;
  20135. $this->lastHeaders = array();
  20136. if (preg_match('{^https?://(.+):(.+)@([^/]+)}i', $fileUrl, $match)) {
  20137. $this->io->setAuthentication($originUrl, urldecode($match[1]), urldecode($match[2]));
  20138. }
  20139. if (isset($additionalOptions['retry-auth-failure'])) {
  20140. $this->retryAuthFailure = (bool) $additionalOptions['retry-auth-failure'];
  20141. unset($additionalOptions['retry-auth-failure']);
  20142. }
  20143. $options = $this->getOptionsForUrl($originUrl, $additionalOptions);
  20144. if ($this->io->isDebug()) {
  20145. $this->io->writeError((substr($fileUrl, 0, 4) === 'http' ? 'Downloading ' : 'Reading ') . $fileUrl);
  20146. }
  20147. if (isset($options['github-token'])) {
  20148. $fileUrl .= (false === strpos($fileUrl, '?') ? '?' : '&') . 'access_token='.$options['github-token'];
  20149. unset($options['github-token']);
  20150. }
  20151. if (isset($options['http'])) {
  20152. $options['http']['ignore_errors'] = true;
  20153. }
  20154. if ($this->degradedMode && substr($fileUrl, 0, 21) === 'http://packagist.org/') {
  20155. $fileUrl = 'http://' . gethostbyname('packagist.org') . substr($fileUrl, 20);
  20156. }
  20157. $ctx = StreamContextFactory::getContext($fileUrl, $options, array('notification' => array($this, 'callbackGet')));
  20158. if ($this->progress) {
  20159. $this->io->writeError(" Downloading: <comment>Connecting...</comment>", false);
  20160. }
  20161. $errorMessage = '';
  20162. $errorCode = 0;
  20163. $result = false;
  20164. set_error_handler(function ($code, $msg) use (&$errorMessage) {
  20165. if ($errorMessage) {
  20166. $errorMessage .= "\n";
  20167. }
  20168. $errorMessage .= preg_replace('{^file_get_contents\(.*?\): }', '', $msg);
  20169. });
  20170. try {
  20171. $result = file_get_contents($fileUrl, false, $ctx);
  20172. } catch (\Exception $e) {
  20173. if ($e instanceof TransportException && !empty($http_response_header[0])) {
  20174. $e->setHeaders($http_response_header);
  20175. }
  20176. if ($e instanceof TransportException && $result !== false) {
  20177. $e->setResponse($result);
  20178. }
  20179. $result = false;
  20180. }
  20181. if ($errorMessage && !ini_get('allow_url_fopen')) {
  20182. $errorMessage = 'allow_url_fopen must be enabled in php.ini ('.$errorMessage.')';
  20183. }
  20184. restore_error_handler();
  20185. if (isset($e) && !$this->retry) {
  20186. if (!$this->degradedMode && false !== strpos($e->getMessage(), 'Operation timed out')) {
  20187. $this->degradedMode = true;
  20188. $this->io->writeError(array(
  20189. '<error>'.$e->getMessage().'</error>',
  20190. '<error>Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info</error>',
  20191. ));
  20192. return $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName, $this->progress);
  20193. }
  20194. throw $e;
  20195. }
  20196. if (!empty($http_response_header[0]) && preg_match('{^HTTP/\S+ ([45]\d\d)}i', $http_response_header[0], $match)) {
  20197. $errorCode = $match[1];
  20198. if (!$this->retry) {
  20199. $e = new TransportException('The "'.$this->fileUrl.'" file could not be downloaded ('.$http_response_header[0].')', $errorCode);
  20200. $e->setHeaders($http_response_header);
  20201. $e->setResponse($result);
  20202. throw $e;
  20203. }
  20204. $result = false;
  20205. }
  20206. if ($this->progress && !$this->retry) {
  20207. $this->io->overwriteError(" Downloading: <comment>100%</comment>");
  20208. }
  20209. if ($result && extension_loaded('zlib') && substr($fileUrl, 0, 4) === 'http') {
  20210. $decode = false;
  20211. foreach ($http_response_header as $header) {
  20212. if (preg_match('{^content-encoding: *gzip *$}i', $header)) {
  20213. $decode = true;
  20214. } elseif (preg_match('{^HTTP/}i', $header)) {
  20215. $decode = false;
  20216. }
  20217. }
  20218. if ($decode) {
  20219. try {
  20220. if (PHP_VERSION_ID >= 50400) {
  20221. $result = zlib_decode($result);
  20222. } else {
  20223. $result = file_get_contents('compress.zlib://data:application/octet-stream;base64,'.base64_encode($result));
  20224. }
  20225. if (!$result) {
  20226. throw new TransportException('Failed to decode zlib stream');
  20227. }
  20228. } catch (\Exception $e) {
  20229. if ($this->degradedMode) {
  20230. throw $e;
  20231. }
  20232. $this->degradedMode = true;
  20233. $this->io->writeError(array(
  20234. '<error>Failed to decode response: '.$e->getMessage().'</error>',
  20235. '<error>Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info</error>',
  20236. ));
  20237. return $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName, $this->progress);
  20238. }
  20239. }
  20240. }
  20241. if (false !== $result && null !== $fileName) {
  20242. if ('' === $result) {
  20243. throw new TransportException('"'.$this->fileUrl.'" appears broken, and returned an empty 200 response');
  20244. }
  20245. $errorMessage = '';
  20246. set_error_handler(function ($code, $msg) use (&$errorMessage) {
  20247. if ($errorMessage) {
  20248. $errorMessage .= "\n";
  20249. }
  20250. $errorMessage .= preg_replace('{^file_put_contents\(.*?\): }', '', $msg);
  20251. });
  20252. $result = (bool) file_put_contents($fileName, $result);
  20253. restore_error_handler();
  20254. if (false === $result) {
  20255. throw new TransportException('The "'.$this->fileUrl.'" file could not be written to '.$fileName.': '.$errorMessage);
  20256. }
  20257. }
  20258. if ($this->retry) {
  20259. $this->retry = false;
  20260. $result = $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName, $this->progress);
  20261. $authHelper = new AuthHelper($this->io, $this->config);
  20262. $authHelper->storeAuth($this->originUrl, $this->storeAuth);
  20263. $this->storeAuth = false;
  20264. return $result;
  20265. }
  20266. if (false === $result) {
  20267. $e = new TransportException('The "'.$this->fileUrl.'" file could not be downloaded: '.$errorMessage, $errorCode);
  20268. if (!empty($http_response_header[0])) {
  20269. $e->setHeaders($http_response_header);
  20270. }
  20271. if (!$this->degradedMode && false !== strpos($e->getMessage(), 'Operation timed out')) {
  20272. $this->degradedMode = true;
  20273. $this->io->writeError(array(
  20274. '<error>'.$e->getMessage().'</error>',
  20275. '<error>Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info</error>',
  20276. ));
  20277. return $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName, $this->progress);
  20278. }
  20279. throw $e;
  20280. }
  20281. if (!empty($http_response_header[0])) {
  20282. $this->lastHeaders = $http_response_header;
  20283. }
  20284. return $result;
  20285. }
  20286. protected function callbackGet($notificationCode, $severity, $message, $messageCode, $bytesTransferred, $bytesMax)
  20287. {
  20288. switch ($notificationCode) {
  20289. case STREAM_NOTIFY_FAILURE:
  20290. case STREAM_NOTIFY_AUTH_REQUIRED:
  20291. if (401 === $messageCode) {
  20292. if (!$this->retryAuthFailure) {
  20293. break;
  20294. }
  20295. $this->promptAuthAndRetry($messageCode);
  20296. }
  20297. break;
  20298. case STREAM_NOTIFY_AUTH_RESULT:
  20299. if (403 === $messageCode) {
  20300. if (!$this->retryAuthFailure) {
  20301. break;
  20302. }
  20303. $this->promptAuthAndRetry($messageCode, $message);
  20304. }
  20305. break;
  20306. case STREAM_NOTIFY_FILE_SIZE_IS:
  20307. if ($this->bytesMax < $bytesMax) {
  20308. $this->bytesMax = $bytesMax;
  20309. }
  20310. break;
  20311. case STREAM_NOTIFY_PROGRESS:
  20312. if ($this->bytesMax > 0 && $this->progress) {
  20313. $progression = round($bytesTransferred / $this->bytesMax * 100);
  20314. if ((0 === $progression % 5) && 100 !== $progression && $progression !== $this->lastProgress) {
  20315. $this->lastProgress = $progression;
  20316. $this->io->overwriteError(" Downloading: <comment>$progression%</comment>", false);
  20317. }
  20318. }
  20319. break;
  20320. default:
  20321. break;
  20322. }
  20323. }
  20324. protected function promptAuthAndRetry($httpStatus, $reason = null)
  20325. {
  20326. if ($this->config && in_array($this->originUrl, $this->config->get('github-domains'), true)) {
  20327. $message = "\n".'Could not fetch '.$this->fileUrl.', please create a GitHub OAuth token '.($httpStatus === 404 ? 'to access private repos' : 'to go over the API rate limit');
  20328. $gitHubUtil = new GitHub($this->io, $this->config, null);
  20329. if (!$gitHubUtil->authorizeOAuth($this->originUrl)
  20330. && (!$this->io->isInteractive() || !$gitHubUtil->authorizeOAuthInteractively($this->originUrl, $message))
  20331. ) {
  20332. throw new TransportException('Could not authenticate against '.$this->originUrl, 401);
  20333. }
  20334. } else {
  20335. if ($httpStatus === 404) {
  20336. return;
  20337. }
  20338. if (!$this->io->isInteractive()) {
  20339. if ($httpStatus === 401) {
  20340. $message = "The '" . $this->fileUrl . "' URL required authentication.\nYou must be using the interactive console to authenticate";
  20341. }
  20342. if ($httpStatus === 403) {
  20343. $message = "The '" . $this->fileUrl . "' URL could not be accessed: " . $reason;
  20344. }
  20345. throw new TransportException($message, $httpStatus);
  20346. }
  20347. if ($this->io->hasAuthentication($this->originUrl)) {
  20348. throw new TransportException("Invalid credentials for '" . $this->fileUrl . "', aborting.", $httpStatus);
  20349. }
  20350. $this->io->overwriteError(' Authentication required (<info>'.parse_url($this->fileUrl, PHP_URL_HOST).'</info>):');
  20351. $username = $this->io->ask(' Username: ');
  20352. $password = $this->io->askAndHideAnswer(' Password: ');
  20353. $this->io->setAuthentication($this->originUrl, $username, $password);
  20354. $this->storeAuth = $this->config->get('store-auths');
  20355. }
  20356. $this->retry = true;
  20357. throw new TransportException('RETRY');
  20358. }
  20359. protected function getOptionsForUrl($originUrl, $additionalOptions)
  20360. {
  20361. if (defined('HHVM_VERSION')) {
  20362. $phpVersion = 'HHVM ' . HHVM_VERSION;
  20363. } else {
  20364. $phpVersion = 'PHP ' . PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION;
  20365. }
  20366. $headers = array(
  20367. sprintf(
  20368. 'User-Agent: Composer/%s (%s; %s; %s)',
  20369. Composer::VERSION === '@package_version@' ? 'source' : Composer::VERSION,
  20370. php_uname('s'),
  20371. php_uname('r'),
  20372. $phpVersion
  20373. ),
  20374. );
  20375. if (extension_loaded('zlib')) {
  20376. $headers[] = 'Accept-Encoding: gzip';
  20377. }
  20378. $options = array_replace_recursive($this->options, $additionalOptions);
  20379. if (!$this->degradedMode) {
  20380. $options['http']['protocol_version'] = 1.1;
  20381. $headers[] = 'Connection: close';
  20382. }
  20383. if ($this->io->hasAuthentication($originUrl)) {
  20384. $auth = $this->io->getAuthentication($originUrl);
  20385. if ('github.com' === $originUrl && 'x-oauth-basic' === $auth['password']) {
  20386. $options['github-token'] = $auth['username'];
  20387. } else {
  20388. $authStr = base64_encode($auth['username'] . ':' . $auth['password']);
  20389. $headers[] = 'Authorization: Basic '.$authStr;
  20390. }
  20391. }
  20392. if (isset($options['http']['header']) && !is_array($options['http']['header'])) {
  20393. $options['http']['header'] = explode("\r\n", trim($options['http']['header'], "\r\n"));
  20394. }
  20395. foreach ($headers as $header) {
  20396. $options['http']['header'][] = $header;
  20397. }
  20398. return $options;
  20399. }
  20400. }
  20401. <?php
  20402. namespace Composer\Util;
  20403. use Composer\Spdx\SpdxLicenses;
  20404. @trigger_error('The ' . __NAMESPACE__ . '\SpdxLicense class is deprecated, use Composer\Spdx\SpdxLicenses instead.', E_USER_DEPRECATED);
  20405. class SpdxLicense extends SpdxLicenses
  20406. {
  20407. }
  20408. <?php
  20409. namespace Composer\Util;
  20410. final class StreamContextFactory
  20411. {
  20412. public static function getContext($url, array $defaultOptions = array(), array $defaultParams = array())
  20413. {
  20414. $options = array('http' => array(
  20415. 'follow_location' => 1,
  20416. 'max_redirects' => 20,
  20417. ));
  20418. if (!empty($_SERVER['HTTP_PROXY']) || !empty($_SERVER['http_proxy'])) {
  20419. $proxy = parse_url(!empty($_SERVER['http_proxy']) ? $_SERVER['http_proxy'] : $_SERVER['HTTP_PROXY']);
  20420. }
  20421. if (preg_match('{^https://}i', $url) && (!empty($_SERVER['HTTPS_PROXY']) || !empty($_SERVER['https_proxy']))) {
  20422. $proxy = parse_url(!empty($_SERVER['https_proxy']) ? $_SERVER['https_proxy'] : $_SERVER['HTTPS_PROXY']);
  20423. }
  20424. if (!empty($_SERVER['no_proxy']) && parse_url($url, PHP_URL_HOST)) {
  20425. $pattern = new NoProxyPattern($_SERVER['no_proxy']);
  20426. if ($pattern->test($url)) {
  20427. unset($proxy);
  20428. }
  20429. }
  20430. if (!empty($proxy)) {
  20431. $proxyURL = isset($proxy['scheme']) ? $proxy['scheme'] . '://' : '';
  20432. $proxyURL .= isset($proxy['host']) ? $proxy['host'] : '';
  20433. if (isset($proxy['port'])) {
  20434. $proxyURL .= ":" . $proxy['port'];
  20435. } elseif ('http://' == substr($proxyURL, 0, 7)) {
  20436. $proxyURL .= ":80";
  20437. } elseif ('https://' == substr($proxyURL, 0, 8)) {
  20438. $proxyURL .= ":443";
  20439. }
  20440. $proxyURL = str_replace(array('http://', 'https://'), array('tcp://', 'ssl://'), $proxyURL);
  20441. if (0 === strpos($proxyURL, 'ssl:') && !extension_loaded('openssl')) {
  20442. throw new \RuntimeException('You must enable the openssl extension to use a proxy over https');
  20443. }
  20444. $options['http']['proxy'] = $proxyURL;
  20445. switch (parse_url($url, PHP_URL_SCHEME)) {
  20446. case 'http':
  20447. $reqFullUriEnv = getenv('HTTP_PROXY_REQUEST_FULLURI');
  20448. if ($reqFullUriEnv === false || $reqFullUriEnv === '' || (strtolower($reqFullUriEnv) !== 'false' && (bool) $reqFullUriEnv)) {
  20449. $options['http']['request_fulluri'] = true;
  20450. }
  20451. break;
  20452. case 'https':
  20453. $reqFullUriEnv = getenv('HTTPS_PROXY_REQUEST_FULLURI');
  20454. if ($reqFullUriEnv === false || $reqFullUriEnv === '' || (strtolower($reqFullUriEnv) !== 'false' && (bool) $reqFullUriEnv)) {
  20455. $options['http']['request_fulluri'] = true;
  20456. }
  20457. break;
  20458. }
  20459. if ('https' === parse_url($url, PHP_URL_SCHEME)) {
  20460. $options['ssl']['SNI_enabled'] = true;
  20461. if (PHP_VERSION_ID < 50600) {
  20462. $options['ssl']['SNI_server_name'] = parse_url($url, PHP_URL_HOST);
  20463. }
  20464. }
  20465. if (isset($proxy['user'])) {
  20466. $auth = urldecode($proxy['user']);
  20467. if (isset($proxy['pass'])) {
  20468. $auth .= ':' . urldecode($proxy['pass']);
  20469. }
  20470. $auth = base64_encode($auth);
  20471. if (isset($defaultOptions['http']['header'])) {
  20472. if (is_string($defaultOptions['http']['header'])) {
  20473. $defaultOptions['http']['header'] = array($defaultOptions['http']['header']);
  20474. }
  20475. $defaultOptions['http']['header'][] = "Proxy-Authorization: Basic {$auth}";
  20476. } else {
  20477. $options['http']['header'] = array("Proxy-Authorization: Basic {$auth}");
  20478. }
  20479. }
  20480. }
  20481. $options = array_replace_recursive($options, $defaultOptions);
  20482. if (isset($options['http']['header'])) {
  20483. $options['http']['header'] = self::fixHttpHeaderField($options['http']['header']);
  20484. }
  20485. return stream_context_create($options, $defaultParams);
  20486. }
  20487. private static function fixHttpHeaderField($header)
  20488. {
  20489. if (!is_array($header)) {
  20490. $header = explode("\r\n", $header);
  20491. }
  20492. uasort($header, function ($el) {
  20493. return preg_match('{^content-type}i', $el) ? 1 : -1;
  20494. });
  20495. return $header;
  20496. }
  20497. }
  20498. <?php
  20499. namespace Composer\Util;
  20500. use Composer\Config;
  20501. use Composer\IO\IOInterface;
  20502. class Svn
  20503. {
  20504. const MAX_QTY_AUTH_TRIES = 5;
  20505. protected $credentials;
  20506. protected $hasAuth;
  20507. protected $io;
  20508. protected $url;
  20509. protected $cacheCredentials = true;
  20510. protected $process;
  20511. protected $qtyAuthTries = 0;
  20512. protected $config;
  20513. public function __construct($url, IOInterface $io, Config $config, ProcessExecutor $process = null)
  20514. {
  20515. $this->url = $url;
  20516. $this->io = $io;
  20517. $this->config = $config;
  20518. $this->process = $process ?: new ProcessExecutor;
  20519. }
  20520. public static function cleanEnv()
  20521. {
  20522. putenv("DYLD_LIBRARY_PATH");
  20523. unset($_SERVER['DYLD_LIBRARY_PATH']);
  20524. }
  20525. public function execute($command, $url, $cwd = null, $path = null, $verbose = false)
  20526. {
  20527. $svnCommand = $this->getCommand($command, $url, $path);
  20528. $output = null;
  20529. $io = $this->io;
  20530. $handler = function ($type, $buffer) use (&$output, $io, $verbose) {
  20531. if ($type !== 'out') {
  20532. return;
  20533. }
  20534. if ('Redirecting to URL ' === substr($buffer, 0, 19)) {
  20535. return;
  20536. }
  20537. $output .= $buffer;
  20538. if ($verbose) {
  20539. $io->writeError($buffer, false);
  20540. }
  20541. };
  20542. $status = $this->process->execute($svnCommand, $handler, $cwd);
  20543. if (0 === $status) {
  20544. return $output;
  20545. }
  20546. $errorOutput = $this->process->getErrorOutput();
  20547. $fullOutput = implode("\n", array($output, $errorOutput));
  20548. if (false === stripos($fullOutput, 'Could not authenticate to server:')
  20549. && false === stripos($fullOutput, 'authorization failed')
  20550. && false === stripos($fullOutput, 'svn: E170001:')
  20551. && false === stripos($fullOutput, 'svn: E215004:')) {
  20552. throw new \RuntimeException($fullOutput);
  20553. }
  20554. if (!$this->hasAuth()) {
  20555. $this->doAuthDance();
  20556. }
  20557. if ($this->qtyAuthTries++ < self::MAX_QTY_AUTH_TRIES) {
  20558. return $this->execute($command, $url, $cwd, $path, $verbose);
  20559. }
  20560. throw new \RuntimeException(
  20561. 'wrong credentials provided ('.$fullOutput.')'
  20562. );
  20563. }
  20564. public function setCacheCredentials($cacheCredentials)
  20565. {
  20566. $this->cacheCredentials = $cacheCredentials;
  20567. }
  20568. protected function doAuthDance()
  20569. {
  20570. if (!$this->io->isInteractive()) {
  20571. throw new \RuntimeException(
  20572. 'can not ask for authentication in non interactive mode'
  20573. );
  20574. }
  20575. $this->io->writeError("The Subversion server ({$this->url}) requested credentials:");
  20576. $this->hasAuth = true;
  20577. $this->credentials['username'] = $this->io->ask("Username: ");
  20578. $this->credentials['password'] = $this->io->askAndHideAnswer("Password: ");
  20579. $this->cacheCredentials = $this->io->askConfirmation("Should Subversion cache these credentials? (yes/no) ", true);
  20580. return $this;
  20581. }
  20582. protected function getCommand($cmd, $url, $path = null)
  20583. {
  20584. $cmd = sprintf('%s %s%s %s',
  20585. $cmd,
  20586. '--non-interactive ',
  20587. $this->getCredentialString(),
  20588. ProcessExecutor::escape($url)
  20589. );
  20590. if ($path) {
  20591. $cmd .= ' ' . ProcessExecutor::escape($path);
  20592. }
  20593. return $cmd;
  20594. }
  20595. protected function getCredentialString()
  20596. {
  20597. if (!$this->hasAuth()) {
  20598. return '';
  20599. }
  20600. return sprintf(
  20601. ' %s--username %s --password %s ',
  20602. $this->getAuthCache(),
  20603. ProcessExecutor::escape($this->getUsername()),
  20604. ProcessExecutor::escape($this->getPassword())
  20605. );
  20606. }
  20607. protected function getPassword()
  20608. {
  20609. if ($this->credentials === null) {
  20610. throw new \LogicException("No svn auth detected.");
  20611. }
  20612. return isset($this->credentials['password']) ? $this->credentials['password'] : '';
  20613. }
  20614. protected function getUsername()
  20615. {
  20616. if ($this->credentials === null) {
  20617. throw new \LogicException("No svn auth detected.");
  20618. }
  20619. return $this->credentials['username'];
  20620. }
  20621. protected function hasAuth()
  20622. {
  20623. if (null !== $this->hasAuth) {
  20624. return $this->hasAuth;
  20625. }
  20626. if (false === $this->createAuthFromConfig()) {
  20627. $this->createAuthFromUrl();
  20628. }
  20629. return $this->hasAuth;
  20630. }
  20631. protected function getAuthCache()
  20632. {
  20633. return $this->cacheCredentials ? '' : '--no-auth-cache ';
  20634. }
  20635. private function createAuthFromConfig()
  20636. {
  20637. if (!$this->config->has('http-basic')) {
  20638. return $this->hasAuth = false;
  20639. }
  20640. $authConfig = $this->config->get('http-basic');
  20641. $host = parse_url($this->url, PHP_URL_HOST);
  20642. if (isset($authConfig[$host])) {
  20643. $this->credentials['username'] = $authConfig[$host]['username'];
  20644. $this->credentials['password'] = $authConfig[$host]['password'];
  20645. return $this->hasAuth = true;
  20646. }
  20647. return $this->hasAuth = false;
  20648. }
  20649. private function createAuthFromUrl()
  20650. {
  20651. $uri = parse_url($this->url);
  20652. if (empty($uri['user'])) {
  20653. return $this->hasAuth = false;
  20654. }
  20655. $this->credentials['username'] = $uri['user'];
  20656. if (!empty($uri['pass'])) {
  20657. $this->credentials['password'] = $uri['pass'];
  20658. }
  20659. return $this->hasAuth = true;
  20660. }
  20661. }
  20662. <?php
  20663. function includeIfExists($file)
  20664. {
  20665. return file_exists($file) ? include $file : false;
  20666. }
  20667. if ((!$loader = includeIfExists(__DIR__.'/../vendor/autoload.php')) && (!$loader = includeIfExists(__DIR__.'/../../../autoload.php'))) {
  20668. echo 'You must set up the project dependencies, run the following commands:'.PHP_EOL.
  20669. 'curl -sS https://getcomposer.org/installer | php'.PHP_EOL.
  20670. 'php composer.phar install'.PHP_EOL;
  20671. exit(1);
  20672. }
  20673. return $loader;
  20674. <?php
  20675. /*
  20676. * This file is part of Composer.
  20677. *
  20678. * (c) Nils Adermann <naderman@naderman.de>
  20679. * Jordi Boggiano <j.boggiano@seld.be>
  20680. *
  20681. * For the full copyright and license information, please view the LICENSE
  20682. * file that was distributed with this source code.
  20683. */
  20684. namespace Composer\Autoload;
  20685. /**
  20686. * ClassLoader implements a PSR-0 class loader
  20687. *
  20688. * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
  20689. *
  20690. * $loader = new \Composer\Autoload\ClassLoader();
  20691. *
  20692. * // register classes with namespaces
  20693. * $loader->add('Symfony\Component', __DIR__.'/component');
  20694. * $loader->add('Symfony', __DIR__.'/framework');
  20695. *
  20696. * // activate the autoloader
  20697. * $loader->register();
  20698. *
  20699. * // to enable searching the include path (eg. for PEAR packages)
  20700. * $loader->setUseIncludePath(true);
  20701. *
  20702. * In this example, if you try to use a class in the Symfony\Component
  20703. * namespace or one of its children (Symfony\Component\Console for instance),
  20704. * the autoloader will first look for the class under the component/
  20705. * directory, and it will then fallback to the framework/ directory if not
  20706. * found before giving up.
  20707. *
  20708. * This class is loosely based on the Symfony UniversalClassLoader.
  20709. *
  20710. * @author Fabien Potencier <fabien@symfony.com>
  20711. * @author Jordi Boggiano <j.boggiano@seld.be>
  20712. */
  20713. class ClassLoader
  20714. {
  20715. // PSR-4
  20716. private $prefixLengthsPsr4 = array();
  20717. private $prefixDirsPsr4 = array();
  20718. private $fallbackDirsPsr4 = array();
  20719. // PSR-0
  20720. private $prefixesPsr0 = array();
  20721. private $fallbackDirsPsr0 = array();
  20722. private $useIncludePath = false;
  20723. private $classMap = array();
  20724. private $classMapAuthoritative = false;
  20725. public function getPrefixes()
  20726. {
  20727. if (!empty($this->prefixesPsr0)) {
  20728. return call_user_func_array('array_merge', $this->prefixesPsr0);
  20729. }
  20730. return array();
  20731. }
  20732. public function getPrefixesPsr4()
  20733. {
  20734. return $this->prefixDirsPsr4;
  20735. }
  20736. public function getFallbackDirs()
  20737. {
  20738. return $this->fallbackDirsPsr0;
  20739. }
  20740. public function getFallbackDirsPsr4()
  20741. {
  20742. return $this->fallbackDirsPsr4;
  20743. }
  20744. public function getClassMap()
  20745. {
  20746. return $this->classMap;
  20747. }
  20748. /**
  20749. * @param array $classMap Class to filename map
  20750. */
  20751. public function addClassMap(array $classMap)
  20752. {
  20753. if ($this->classMap) {
  20754. $this->classMap = array_merge($this->classMap, $classMap);
  20755. } else {
  20756. $this->classMap = $classMap;
  20757. }
  20758. }
  20759. /**
  20760. * Registers a set of PSR-0 directories for a given prefix, either
  20761. * appending or prepending to the ones previously set for this prefix.
  20762. *
  20763. * @param string $prefix The prefix
  20764. * @param array|string $paths The PSR-0 root directories
  20765. * @param bool $prepend Whether to prepend the directories
  20766. */
  20767. public function add($prefix, $paths, $prepend = false)
  20768. {
  20769. if (!$prefix) {
  20770. if ($prepend) {
  20771. $this->fallbackDirsPsr0 = array_merge(
  20772. (array) $paths,
  20773. $this->fallbackDirsPsr0
  20774. );
  20775. } else {
  20776. $this->fallbackDirsPsr0 = array_merge(
  20777. $this->fallbackDirsPsr0,
  20778. (array) $paths
  20779. );
  20780. }
  20781. return;
  20782. }
  20783. $first = $prefix[0];
  20784. if (!isset($this->prefixesPsr0[$first][$prefix])) {
  20785. $this->prefixesPsr0[$first][$prefix] = (array) $paths;
  20786. return;
  20787. }
  20788. if ($prepend) {
  20789. $this->prefixesPsr0[$first][$prefix] = array_merge(
  20790. (array) $paths,
  20791. $this->prefixesPsr0[$first][$prefix]
  20792. );
  20793. } else {
  20794. $this->prefixesPsr0[$first][$prefix] = array_merge(
  20795. $this->prefixesPsr0[$first][$prefix],
  20796. (array) $paths
  20797. );
  20798. }
  20799. }
  20800. /**
  20801. * Registers a set of PSR-4 directories for a given namespace, either
  20802. * appending or prepending to the ones previously set for this namespace.
  20803. *
  20804. * @param string $prefix The prefix/namespace, with trailing '\\'
  20805. * @param array|string $paths The PSR-0 base directories
  20806. * @param bool $prepend Whether to prepend the directories
  20807. *
  20808. * @throws \InvalidArgumentException
  20809. */
  20810. public function addPsr4($prefix, $paths, $prepend = false)
  20811. {
  20812. if (!$prefix) {
  20813. // Register directories for the root namespace.
  20814. if ($prepend) {
  20815. $this->fallbackDirsPsr4 = array_merge(
  20816. (array) $paths,
  20817. $this->fallbackDirsPsr4
  20818. );
  20819. } else {
  20820. $this->fallbackDirsPsr4 = array_merge(
  20821. $this->fallbackDirsPsr4,
  20822. (array) $paths
  20823. );
  20824. }
  20825. } elseif (!isset($this->prefixDirsPsr4[$prefix])) {
  20826. // Register directories for a new namespace.
  20827. $length = strlen($prefix);
  20828. if ('\\' !== $prefix[$length - 1]) {
  20829. throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
  20830. }
  20831. $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
  20832. $this->prefixDirsPsr4[$prefix] = (array) $paths;
  20833. } elseif ($prepend) {
  20834. // Prepend directories for an already registered namespace.
  20835. $this->prefixDirsPsr4[$prefix] = array_merge(
  20836. (array) $paths,
  20837. $this->prefixDirsPsr4[$prefix]
  20838. );
  20839. } else {
  20840. // Append directories for an already registered namespace.
  20841. $this->prefixDirsPsr4[$prefix] = array_merge(
  20842. $this->prefixDirsPsr4[$prefix],
  20843. (array) $paths
  20844. );
  20845. }
  20846. }
  20847. /**
  20848. * Registers a set of PSR-0 directories for a given prefix,
  20849. * replacing any others previously set for this prefix.
  20850. *
  20851. * @param string $prefix The prefix
  20852. * @param array|string $paths The PSR-0 base directories
  20853. */
  20854. public function set($prefix, $paths)
  20855. {
  20856. if (!$prefix) {
  20857. $this->fallbackDirsPsr0 = (array) $paths;
  20858. } else {
  20859. $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
  20860. }
  20861. }
  20862. /**
  20863. * Registers a set of PSR-4 directories for a given namespace,
  20864. * replacing any others previously set for this namespace.
  20865. *
  20866. * @param string $prefix The prefix/namespace, with trailing '\\'
  20867. * @param array|string $paths The PSR-4 base directories
  20868. *
  20869. * @throws \InvalidArgumentException
  20870. */
  20871. public function setPsr4($prefix, $paths)
  20872. {
  20873. if (!$prefix) {
  20874. $this->fallbackDirsPsr4 = (array) $paths;
  20875. } else {
  20876. $length = strlen($prefix);
  20877. if ('\\' !== $prefix[$length - 1]) {
  20878. throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
  20879. }
  20880. $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
  20881. $this->prefixDirsPsr4[$prefix] = (array) $paths;
  20882. }
  20883. }
  20884. /**
  20885. * Turns on searching the include path for class files.
  20886. *
  20887. * @param bool $useIncludePath
  20888. */
  20889. public function setUseIncludePath($useIncludePath)
  20890. {
  20891. $this->useIncludePath = $useIncludePath;
  20892. }
  20893. /**
  20894. * Can be used to check if the autoloader uses the include path to check
  20895. * for classes.
  20896. *
  20897. * @return bool
  20898. */
  20899. public function getUseIncludePath()
  20900. {
  20901. return $this->useIncludePath;
  20902. }
  20903. /**
  20904. * Turns off searching the prefix and fallback directories for classes
  20905. * that have not been registered with the class map.
  20906. *
  20907. * @param bool $classMapAuthoritative
  20908. */
  20909. public function setClassMapAuthoritative($classMapAuthoritative)
  20910. {
  20911. $this->classMapAuthoritative = $classMapAuthoritative;
  20912. }
  20913. /**
  20914. * Should class lookup fail if not found in the current class map?
  20915. *
  20916. * @return bool
  20917. */
  20918. public function isClassMapAuthoritative()
  20919. {
  20920. return $this->classMapAuthoritative;
  20921. }
  20922. /**
  20923. * Registers this instance as an autoloader.
  20924. *
  20925. * @param bool $prepend Whether to prepend the autoloader or not
  20926. */
  20927. public function register($prepend = false)
  20928. {
  20929. spl_autoload_register(array($this, 'loadClass'), true, $prepend);
  20930. }
  20931. /**
  20932. * Unregisters this instance as an autoloader.
  20933. */
  20934. public function unregister()
  20935. {
  20936. spl_autoload_unregister(array($this, 'loadClass'));
  20937. }
  20938. /**
  20939. * Loads the given class or interface.
  20940. *
  20941. * @param string $class The name of the class
  20942. * @return bool|null True if loaded, null otherwise
  20943. */
  20944. public function loadClass($class)
  20945. {
  20946. if ($file = $this->findFile($class)) {
  20947. includeFile($file);
  20948. return true;
  20949. }
  20950. }
  20951. /**
  20952. * Finds the path to the file where the class is defined.
  20953. *
  20954. * @param string $class The name of the class
  20955. *
  20956. * @return string|false The path if found, false otherwise
  20957. */
  20958. public function findFile($class)
  20959. {
  20960. // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
  20961. if ('\\' == $class[0]) {
  20962. $class = substr($class, 1);
  20963. }
  20964. // class map lookup
  20965. if (isset($this->classMap[$class])) {
  20966. return $this->classMap[$class];
  20967. }
  20968. if ($this->classMapAuthoritative) {
  20969. return false;
  20970. }
  20971. $file = $this->findFileWithExtension($class, '.php');
  20972. // Search for Hack files if we are running on HHVM
  20973. if ($file === null && defined('HHVM_VERSION')) {
  20974. $file = $this->findFileWithExtension($class, '.hh');
  20975. }
  20976. if ($file === null) {
  20977. // Remember that this class does not exist.
  20978. return $this->classMap[$class] = false;
  20979. }
  20980. return $file;
  20981. }
  20982. private function findFileWithExtension($class, $ext)
  20983. {
  20984. // PSR-4 lookup
  20985. $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
  20986. $first = $class[0];
  20987. if (isset($this->prefixLengthsPsr4[$first])) {
  20988. foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
  20989. if (0 === strpos($class, $prefix)) {
  20990. foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
  20991. if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
  20992. return $file;
  20993. }
  20994. }
  20995. }
  20996. }
  20997. }
  20998. // PSR-4 fallback dirs
  20999. foreach ($this->fallbackDirsPsr4 as $dir) {
  21000. if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
  21001. return $file;
  21002. }
  21003. }
  21004. // PSR-0 lookup
  21005. if (false !== $pos = strrpos($class, '\\')) {
  21006. // namespaced class name
  21007. $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
  21008. . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
  21009. } else {
  21010. // PEAR-like class name
  21011. $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
  21012. }
  21013. if (isset($this->prefixesPsr0[$first])) {
  21014. foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
  21015. if (0 === strpos($class, $prefix)) {
  21016. foreach ($dirs as $dir) {
  21017. if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
  21018. return $file;
  21019. }
  21020. }
  21021. }
  21022. }
  21023. }
  21024. // PSR-0 fallback dirs
  21025. foreach ($this->fallbackDirsPsr0 as $dir) {
  21026. if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
  21027. return $file;
  21028. }
  21029. }
  21030. // PSR-0 include paths.
  21031. if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
  21032. return $file;
  21033. }
  21034. }
  21035. }
  21036. /**
  21037. * Scope isolated include.
  21038. *
  21039. * Prevents access to $this/self from included files.
  21040. */
  21041. function includeFile($file)
  21042. {
  21043. include $file;
  21044. }
  21045. {
  21046. "$schema": "http://json-schema.org/draft-04/schema#",
  21047. "name": "Package",
  21048. "type": "object",
  21049. "additionalProperties": false,
  21050. "required": [ "name", "description" ],
  21051. "properties": {
  21052. "name": {
  21053. "type": "string",
  21054. "description": "Package name, including 'vendor-name/' prefix."
  21055. },
  21056. "type": {
  21057. "description": "Package type, either 'library' for common packages, 'composer-plugin' for plugins, 'metapackage' for empty packages, or a custom type ([a-z0-9-]+) defined by whatever project this package applies to.",
  21058. "type": "string"
  21059. },
  21060. "target-dir": {
  21061. "description": "DEPRECATED: Forces the package to be installed into the given subdirectory path. This is used for autoloading PSR-0 packages that do not contain their full path. Use forward slashes for cross-platform compatibility.",
  21062. "type": "string"
  21063. },
  21064. "description": {
  21065. "type": "string",
  21066. "description": "Short package description."
  21067. },
  21068. "keywords": {
  21069. "type": "array",
  21070. "items": {
  21071. "type": "string",
  21072. "description": "A tag/keyword that this package relates to."
  21073. }
  21074. },
  21075. "homepage": {
  21076. "type": "string",
  21077. "description": "Homepage URL for the project.",
  21078. "format": "uri"
  21079. },
  21080. "version": {
  21081. "type": "string",
  21082. "description": "Package version, see https://getcomposer.org/doc/04-schema.md#version for more info on valid schemes."
  21083. },
  21084. "time": {
  21085. "type": "string",
  21086. "description": "Package release date, in 'YYYY-MM-DD', 'YYYY-MM-DD HH:MM:SS' or 'YYYY-MM-DDTHH:MM:SSZ' format."
  21087. },
  21088. "license": {
  21089. "type": ["string", "array"],
  21090. "description": "License name. Or an array of license names."
  21091. },
  21092. "authors": {
  21093. "type": "array",
  21094. "description": "List of authors that contributed to the package. This is typically the main maintainers, not the full list.",
  21095. "items": {
  21096. "type": "object",
  21097. "additionalProperties": false,
  21098. "required": [ "name"],
  21099. "properties": {
  21100. "name": {
  21101. "type": "string",
  21102. "description": "Full name of the author."
  21103. },
  21104. "email": {
  21105. "type": "string",
  21106. "description": "Email address of the author.",
  21107. "format": "email"
  21108. },
  21109. "homepage": {
  21110. "type": "string",
  21111. "description": "Homepage URL for the author.",
  21112. "format": "uri"
  21113. },
  21114. "role": {
  21115. "type": "string",
  21116. "description": "Author's role in the project."
  21117. }
  21118. }
  21119. }
  21120. },
  21121. "require": {
  21122. "type": "object",
  21123. "description": "This is a hash of package name (keys) and version constraints (values) that are required to run this package.",
  21124. "additionalProperties": true
  21125. },
  21126. "replace": {
  21127. "type": "object",
  21128. "description": "This is a hash of package name (keys) and version constraints (values) that can be replaced by this package.",
  21129. "additionalProperties": true
  21130. },
  21131. "conflict": {
  21132. "type": "object",
  21133. "description": "This is a hash of package name (keys) and version constraints (values) that conflict with this package.",
  21134. "additionalProperties": true
  21135. },
  21136. "provide": {
  21137. "type": "object",
  21138. "description": "This is a hash of package name (keys) and version constraints (values) that this package provides in addition to this package's name.",
  21139. "additionalProperties": true
  21140. },
  21141. "require-dev": {
  21142. "type": "object",
  21143. "description": "This is a hash of package name (keys) and version constraints (values) that this package requires for developing it (testing tools and such).",
  21144. "additionalProperties": true
  21145. },
  21146. "suggest": {
  21147. "type": "object",
  21148. "description": "This is a hash of package name (keys) and descriptions (values) that this package suggests work well with it (this will be suggested to the user during installation).",
  21149. "additionalProperties": true
  21150. },
  21151. "config": {
  21152. "type": "object",
  21153. "description": "Composer options.",
  21154. "properties": {
  21155. "process-timeout": {
  21156. "type": "integer",
  21157. "description": "The timeout in seconds for process executions, defaults to 300 (5mins)."
  21158. },
  21159. "use-include-path": {
  21160. "type": "boolean",
  21161. "description": "If true, the Composer autoloader will also look for classes in the PHP include path."
  21162. },
  21163. "preferred-install": {
  21164. "type": "string",
  21165. "description": "The install method Composer will prefer to use, defaults to auto and can be any of source, dist or auto."
  21166. },
  21167. "notify-on-install": {
  21168. "type": "boolean",
  21169. "description": "Composer allows repositories to define a notification URL, so that they get notified whenever a package from that repository is installed. This option allows you to disable that behaviour, defaults to true."
  21170. },
  21171. "github-protocols": {
  21172. "type": "array",
  21173. "description": "A list of protocols to use for github.com clones, in priority order, defaults to [\"git\", \"https\", \"http\"].",
  21174. "items": {
  21175. "type": "string"
  21176. }
  21177. },
  21178. "github-oauth": {
  21179. "type": "object",
  21180. "description": "A hash of domain name => github API oauth tokens, typically {\"github.com\":\"<token>\"}.",
  21181. "additionalProperties": true
  21182. },
  21183. "http-basic": {
  21184. "type": "object",
  21185. "description": "A hash of domain name => {\"username\": \"...\", \"password\": \"...\"}.",
  21186. "additionalProperties": true
  21187. },
  21188. "store-auths": {
  21189. "type": ["string", "boolean"],
  21190. "description": "What to do after prompting for authentication, one of: true (store), false (do not store) or \"prompt\" (ask every time), defaults to prompt."
  21191. },
  21192. "platform": {
  21193. "type": "object",
  21194. "description": "This is a hash of package name (keys) and version (values) that will be used to mock the platform packages on this machine.",
  21195. "additionalProperties": true
  21196. },
  21197. "vendor-dir": {
  21198. "type": "string",
  21199. "description": "The location where all packages are installed, defaults to \"vendor\"."
  21200. },
  21201. "bin-dir": {
  21202. "type": "string",
  21203. "description": "The location where all binaries are linked, defaults to \"vendor/bin\"."
  21204. },
  21205. "cache-dir": {
  21206. "type": "string",
  21207. "description": "The location where all caches are located, defaults to \"~/.composer/cache\" on *nix and \"%LOCALAPPDATA%\\Composer\" on windows."
  21208. },
  21209. "cache-files-dir": {
  21210. "type": "string",
  21211. "description": "The location where files (zip downloads) are cached, defaults to \"{$cache-dir}/files\"."
  21212. },
  21213. "cache-repo-dir": {
  21214. "type": "string",
  21215. "description": "The location where repo (git/hg repo clones) are cached, defaults to \"{$cache-dir}/repo\"."
  21216. },
  21217. "cache-vcs-dir": {
  21218. "type": "string",
  21219. "description": "The location where vcs infos (git clones, github api calls, etc. when reading vcs repos) are cached, defaults to \"{$cache-dir}/vcs\"."
  21220. },
  21221. "cache-ttl": {
  21222. "type": "integer",
  21223. "description": "The default cache time-to-live, defaults to 15552000 (6 months)."
  21224. },
  21225. "cache-files-ttl": {
  21226. "type": "integer",
  21227. "description": "The cache time-to-live for files, defaults to the value of cache-ttl."
  21228. },
  21229. "cache-files-maxsize": {
  21230. "type": ["string", "integer"],
  21231. "description": "The cache max size for the files cache, defaults to \"300MiB\"."
  21232. },
  21233. "discard-changes": {
  21234. "type": ["string", "boolean"],
  21235. "description": "The default style of handling dirty updates, defaults to false and can be any of true, false or \"stash\"."
  21236. },
  21237. "autoloader-suffix": {
  21238. "type": "string",
  21239. "description": "Optional string to be used as a suffix for the generated Composer autoloader. When null a random one will be generated."
  21240. },
  21241. "optimize-autoloader": {
  21242. "type": "boolean",
  21243. "description": "Always optimize when dumping the autoloader."
  21244. },
  21245. "prepend-autoloader": {
  21246. "type": "boolean",
  21247. "description": "If false, the composer autoloader will not be prepended to existing autoloaders, defaults to true."
  21248. },
  21249. "classmap-authoritative": {
  21250. "type": "boolean",
  21251. "description": "If true, the composer autoloader will not scan the filesystem for classes that are not found in the class map, defaults to false."
  21252. },
  21253. "github-domains": {
  21254. "type": "array",
  21255. "description": "A list of domains to use in github mode. This is used for GitHub Enterprise setups, defaults to [\"github.com\"].",
  21256. "items": {
  21257. "type": "string"
  21258. }
  21259. },
  21260. "github-expose-hostname": {
  21261. "type": "boolean",
  21262. "description": "Defaults to true. If set to false, the OAuth tokens created to access the github API will have a date instead of the machine hostname."
  21263. },
  21264. "archive-format": {
  21265. "type": "string",
  21266. "description": "The default archiving format when not provided on cli, defaults to \"tar\"."
  21267. },
  21268. "archive-dir": {
  21269. "type": "string",
  21270. "description": "The default archive path when not provided on cli, defaults to \".\"."
  21271. }
  21272. }
  21273. },
  21274. "extra": {
  21275. "type": ["object", "array"],
  21276. "description": "Arbitrary extra data that can be used by plugins, for example, package of type composer-plugin may have a 'class' key defining an installer class name.",
  21277. "additionalProperties": true
  21278. },
  21279. "autoload": {
  21280. "type": "object",
  21281. "description": "Description of how the package can be autoloaded.",
  21282. "properties": {
  21283. "psr-0": {
  21284. "type": "object",
  21285. "description": "This is a hash of namespaces (keys) and the directories they can be found into (values, can be arrays of paths) by the autoloader.",
  21286. "additionalProperties": true
  21287. },
  21288. "psr-4": {
  21289. "type": "object",
  21290. "description": "This is a hash of namespaces (keys) and the PSR-4 directories they can map to (values, can be arrays of paths) by the autoloader.",
  21291. "additionalProperties": true
  21292. },
  21293. "classmap": {
  21294. "type": "array",
  21295. "description": "This is an array of directories that contain classes to be included in the class-map generation process."
  21296. },
  21297. "files": {
  21298. "type": "array",
  21299. "description": "This is an array of files that are always required on every request."
  21300. }
  21301. }
  21302. },
  21303. "autoload-dev": {
  21304. "type": "object",
  21305. "description": "Description of additional autoload rules for development purpose (eg. a test suite).",
  21306. "properties": {
  21307. "psr-0": {
  21308. "type": "object",
  21309. "description": "This is a hash of namespaces (keys) and the directories they can be found into (values, can be arrays of paths) by the autoloader.",
  21310. "additionalProperties": true
  21311. },
  21312. "psr-4": {
  21313. "type": "object",
  21314. "description": "This is a hash of namespaces (keys) and the PSR-4 directories they can map to (values, can be arrays of paths) by the autoloader.",
  21315. "additionalProperties": true
  21316. },
  21317. "classmap": {
  21318. "type": "array",
  21319. "description": "This is an array of directories that contain classes to be included in the class-map generation process."
  21320. },
  21321. "files": {
  21322. "type": "array",
  21323. "description": "This is an array of files that are always required on every request."
  21324. }
  21325. }
  21326. },
  21327. "archive": {
  21328. "type": ["object"],
  21329. "description": "Options for creating package archives for distribution.",
  21330. "properties": {
  21331. "exclude": {
  21332. "type": "array",
  21333. "description": "A list of patterns for paths to exclude or include if prefixed with an exclamation mark."
  21334. }
  21335. }
  21336. },
  21337. "repositories": {
  21338. "type": ["object", "array"],
  21339. "description": "A set of additional repositories where packages can be found.",
  21340. "additionalProperties": true
  21341. },
  21342. "minimum-stability": {
  21343. "type": ["string"],
  21344. "description": "The minimum stability the packages must have to be install-able. Possible values are: dev, alpha, beta, RC, stable.",
  21345. "pattern": "^dev|alpha|beta|rc|RC|stable$"
  21346. },
  21347. "prefer-stable": {
  21348. "type": ["boolean"],
  21349. "description": "If set to true, stable packages will be preferred to dev packages when possible, even if the minimum-stability allows unstable packages."
  21350. },
  21351. "bin": {
  21352. "type": ["array"],
  21353. "description": "A set of files that should be treated as binaries and symlinked into bin-dir (from config).",
  21354. "items": {
  21355. "type": "string"
  21356. }
  21357. },
  21358. "include-path": {
  21359. "type": ["array"],
  21360. "description": "DEPRECATED: A list of directories which should get added to PHP's include path. This is only present to support legacy projects, and all new code should preferably use autoloading.",
  21361. "items": {
  21362. "type": "string"
  21363. }
  21364. },
  21365. "scripts": {
  21366. "type": ["object"],
  21367. "description": "Scripts listeners that will be executed before/after some events.",
  21368. "properties": {
  21369. "pre-install-cmd": {
  21370. "type": ["array", "string"],
  21371. "description": "Occurs before the install command is executed, contains one or more Class::method callables or shell commands."
  21372. },
  21373. "post-install-cmd": {
  21374. "type": ["array", "string"],
  21375. "description": "Occurs after the install command is executed, contains one or more Class::method callables or shell commands."
  21376. },
  21377. "pre-update-cmd": {
  21378. "type": ["array", "string"],
  21379. "description": "Occurs before the update command is executed, contains one or more Class::method callables or shell commands."
  21380. },
  21381. "post-update-cmd": {
  21382. "type": ["array", "string"],
  21383. "description": "Occurs after the update command is executed, contains one or more Class::method callables or shell commands."
  21384. },
  21385. "pre-status-cmd": {
  21386. "type": ["array", "string"],
  21387. "description": "Occurs before the status command is executed, contains one or more Class::method callables or shell commands."
  21388. },
  21389. "post-status-cmd": {
  21390. "type": ["array", "string"],
  21391. "description": "Occurs after the status command is executed, contains one or more Class::method callables or shell commands."
  21392. },
  21393. "pre-package-install": {
  21394. "type": ["array", "string"],
  21395. "description": "Occurs before a package is installed, contains one or more Class::method callables or shell commands."
  21396. },
  21397. "post-package-install": {
  21398. "type": ["array", "string"],
  21399. "description": "Occurs after a package is installed, contains one or more Class::method callables or shell commands."
  21400. },
  21401. "pre-package-update": {
  21402. "type": ["array", "string"],
  21403. "description": "Occurs before a package is updated, contains one or more Class::method callables or shell commands."
  21404. },
  21405. "post-package-update": {
  21406. "type": ["array", "string"],
  21407. "description": "Occurs after a package is updated, contains one or more Class::method callables or shell commands."
  21408. },
  21409. "pre-package-uninstall": {
  21410. "type": ["array", "string"],
  21411. "description": "Occurs before a package has been uninstalled, contains one or more Class::method callables or shell commands."
  21412. },
  21413. "post-package-uninstall": {
  21414. "type": ["array", "string"],
  21415. "description": "Occurs after a package has been uninstalled, contains one or more Class::method callables or shell commands."
  21416. },
  21417. "pre-autoload-dump": {
  21418. "type": ["array", "string"],
  21419. "description": "Occurs before the autoloader is dumped, contains one or more Class::method callables or shell commands."
  21420. },
  21421. "post-autoload-dump": {
  21422. "type": ["array", "string"],
  21423. "description": "Occurs after the autoloader is dumped, contains one or more Class::method callables or shell commands."
  21424. },
  21425. "post-root-package-install": {
  21426. "type": ["array", "string"],
  21427. "description": "Occurs after the root-package is installed, contains one or more Class::method callables or shell commands."
  21428. },
  21429. "post-create-project-cmd": {
  21430. "type": ["array", "string"],
  21431. "description": "Occurs after the create-project command is executed, contains one or more Class::method callables or shell commands."
  21432. }
  21433. }
  21434. },
  21435. "support": {
  21436. "type": "object",
  21437. "properties": {
  21438. "email": {
  21439. "type": "string",
  21440. "description": "Email address for support.",
  21441. "format": "email"
  21442. },
  21443. "issues": {
  21444. "type": "string",
  21445. "description": "URL to the issue tracker.",
  21446. "format": "uri"
  21447. },
  21448. "forum": {
  21449. "type": "string",
  21450. "description": "URL to the forum.",
  21451. "format": "uri"
  21452. },
  21453. "wiki": {
  21454. "type": "string",
  21455. "description": "URL to the wiki.",
  21456. "format": "uri"
  21457. },
  21458. "irc": {
  21459. "type": "string",
  21460. "description": "IRC channel for support, as irc://server/channel.",
  21461. "format": "uri"
  21462. },
  21463. "source": {
  21464. "type": "string",
  21465. "description": "URL to browse or download the sources.",
  21466. "format": "uri"
  21467. },
  21468. "docs": {
  21469. "type": "string",
  21470. "description": "URL to the documentation.",
  21471. "format": "uri"
  21472. }
  21473. }
  21474. },
  21475. "non-feature-branches": {
  21476. "type": ["array"],
  21477. "description": "A set of string or regex patterns for non-numeric branch names that will not be handled as feature branches.",
  21478. "items": {
  21479. "type": "string"
  21480. }
  21481. }
  21482. }
  21483. }
  21484. {
  21485. "389-exception": [
  21486. "389 Directory Server\nException"
  21487. ],
  21488. "Autoconf-exception-2.0": [
  21489. "Autoconf exception 2.0"
  21490. ],
  21491. "Autoconf-exception-3.0": [
  21492. "Autoconf exception 3.0"
  21493. ],
  21494. "Bison-exception-2.2": [
  21495. "Bison exception 2.2"
  21496. ],
  21497. "Classpath-exception-2.0": [
  21498. "Classpath exception 2.0"
  21499. ],
  21500. "CLISP-exception-2.0": [
  21501. "CLISP exception 2.0"
  21502. ],
  21503. "eCos-exception-2.0": [
  21504. "eCos exception 2.0"
  21505. ],
  21506. "FLTK-exception": [
  21507. "FLTK exception"
  21508. ],
  21509. "Font-exception-2.0": [
  21510. "Font exception 2.0"
  21511. ],
  21512. "freertos-exception-2.0": [
  21513. "FreeRTOS Exception 2.0"
  21514. ],
  21515. "GCC-exception-2.0": [
  21516. "GCC Runtime Library exception 2.0"
  21517. ],
  21518. "GCC-exception-3.1": [
  21519. "GCC Runtime Library exception 3.1"
  21520. ],
  21521. "gnu-javamail-exception": [
  21522. "GNU JavaMail exception"
  21523. ],
  21524. "i2p-gpl-java-exception": [
  21525. "i2p GPL+Java Exception"
  21526. ],
  21527. "Libtool-exception": [
  21528. "Libtool Exception"
  21529. ],
  21530. "LZMA-exception": [
  21531. "LZMA exception"
  21532. ],
  21533. "mif-exception": [
  21534. "Macros and Inline Functions Exception"
  21535. ],
  21536. "Nokia-Qt-exception-1.1": [
  21537. "Nokia Qt LGPL exception 1.1"
  21538. ],
  21539. "Qwt-exception-1.0": [
  21540. "Qwt exception 1.0"
  21541. ],
  21542. "u-boot-exception-2.0": [
  21543. "U-Boot exception 2.0"
  21544. ],
  21545. "WxWindows-exception-3.1": [
  21546. "WxWindows Library Exception 3.1"
  21547. ]
  21548. }{
  21549. "AAL": [
  21550. "Attribution Assurance License",
  21551. true
  21552. ],
  21553. "Abstyles": [
  21554. "Abstyles License",
  21555. false
  21556. ],
  21557. "Adobe-2006": [
  21558. "Adobe Systems Incorporated Source Code License Agreement",
  21559. false
  21560. ],
  21561. "Adobe-Glyph": [
  21562. "Adobe Glyph List License",
  21563. false
  21564. ],
  21565. "ADSL": [
  21566. "Amazon Digital Services License",
  21567. false
  21568. ],
  21569. "AFL-1.1": [
  21570. "Academic Free License v1.1",
  21571. true
  21572. ],
  21573. "AFL-1.2": [
  21574. "Academic Free License v1.2",
  21575. true
  21576. ],
  21577. "AFL-2.0": [
  21578. "Academic Free License v2.0",
  21579. true
  21580. ],
  21581. "AFL-2.1": [
  21582. "Academic Free License v2.1",
  21583. true
  21584. ],
  21585. "AFL-3.0": [
  21586. "Academic Free License v3.0",
  21587. true
  21588. ],
  21589. "Afmparse": [
  21590. "Afmparse License",
  21591. false
  21592. ],
  21593. "AGPL-1.0": [
  21594. "Affero General Public License v1.0",
  21595. false
  21596. ],
  21597. "AGPL-3.0": [
  21598. "GNU Affero General Public License v3.0",
  21599. true
  21600. ],
  21601. "Aladdin": [
  21602. "Aladdin Free Public License",
  21603. false
  21604. ],
  21605. "AMDPLPA": [
  21606. "AMD's plpa_map.c License",
  21607. false
  21608. ],
  21609. "AML": [
  21610. "Apple MIT License",
  21611. false
  21612. ],
  21613. "AMPAS": [
  21614. "Academy of Motion Picture Arts and Sciences BSD",
  21615. false
  21616. ],
  21617. "ANTLR-PD": [
  21618. "ANTLR Software Rights Notice",
  21619. false
  21620. ],
  21621. "Apache-1.0": [
  21622. "Apache License 1.0",
  21623. false
  21624. ],
  21625. "Apache-1.1": [
  21626. "Apache License 1.1",
  21627. true
  21628. ],
  21629. "Apache-2.0": [
  21630. "Apache License 2.0",
  21631. true
  21632. ],
  21633. "APAFML": [
  21634. "Adobe Postscript AFM License",
  21635. false
  21636. ],
  21637. "APL-1.0": [
  21638. "Adaptive Public License 1.0",
  21639. true
  21640. ],
  21641. "APSL-1.0": [
  21642. "Apple Public Source License 1.0",
  21643. true
  21644. ],
  21645. "APSL-1.1": [
  21646. "Apple Public Source License 1.1",
  21647. true
  21648. ],
  21649. "APSL-1.2": [
  21650. "Apple Public Source License 1.2",
  21651. true
  21652. ],
  21653. "APSL-2.0": [
  21654. "Apple Public Source License 2.0",
  21655. true
  21656. ],
  21657. "Artistic-1.0": [
  21658. "Artistic License 1.0",
  21659. true
  21660. ],
  21661. "Artistic-1.0-cl8": [
  21662. "Artistic License 1.0 w/clause 8",
  21663. true
  21664. ],
  21665. "Artistic-1.0-Perl": [
  21666. "Artistic License 1.0 (Perl)",
  21667. true
  21668. ],
  21669. "Artistic-2.0": [
  21670. "Artistic License 2.0",
  21671. true
  21672. ],
  21673. "Bahyph": [
  21674. "Bahyph License",
  21675. false
  21676. ],
  21677. "Barr": [
  21678. "Barr License",
  21679. false
  21680. ],
  21681. "Beerware": [
  21682. "Beerware License",
  21683. false
  21684. ],
  21685. "BitTorrent-1.0": [
  21686. "BitTorrent Open Source License v1.0",
  21687. false
  21688. ],
  21689. "BitTorrent-1.1": [
  21690. "BitTorrent Open Source License v1.1",
  21691. false
  21692. ],
  21693. "Borceux": [
  21694. "Borceux license",
  21695. false
  21696. ],
  21697. "BSD-2-Clause": [
  21698. "BSD 2-clause \"Simplified\" License",
  21699. true
  21700. ],
  21701. "BSD-2-Clause-FreeBSD": [
  21702. "BSD 2-clause FreeBSD License",
  21703. false
  21704. ],
  21705. "BSD-2-Clause-NetBSD": [
  21706. "BSD 2-clause NetBSD License",
  21707. false
  21708. ],
  21709. "BSD-3-Clause": [
  21710. "BSD 3-clause \"New\" or \"Revised\" License",
  21711. true
  21712. ],
  21713. "BSD-3-Clause-Attribution": [
  21714. "BSD with attribution",
  21715. false
  21716. ],
  21717. "BSD-3-Clause-Clear": [
  21718. "BSD 3-clause Clear License",
  21719. false
  21720. ],
  21721. "BSD-3-Clause-LBNL": [
  21722. "Lawrence Berkeley National Labs BSD variant license",
  21723. false
  21724. ],
  21725. "BSD-4-Clause": [
  21726. "BSD 4-clause \"Original\" or \"Old\" License",
  21727. false
  21728. ],
  21729. "BSD-4-Clause-UC": [
  21730. "BSD-4-Clause (University of California-Specific)",
  21731. false
  21732. ],
  21733. "BSD-Protection": [
  21734. "BSD Protection License",
  21735. false
  21736. ],
  21737. "BSL-1.0": [
  21738. "Boost Software License 1.0",
  21739. true
  21740. ],
  21741. "bzip2-1.0.5": [
  21742. "bzip2 and libbzip2 License v1.0.5",
  21743. false
  21744. ],
  21745. "bzip2-1.0.6": [
  21746. "bzip2 and libbzip2 License v1.0.6",
  21747. false
  21748. ],
  21749. "Caldera": [
  21750. "Caldera License",
  21751. false
  21752. ],
  21753. "CATOSL-1.1": [
  21754. "Computer Associates Trusted Open Source License 1.1",
  21755. true
  21756. ],
  21757. "CC-BY-1.0": [
  21758. "Creative Commons Attribution 1.0",
  21759. false
  21760. ],
  21761. "CC-BY-2.0": [
  21762. "Creative Commons Attribution 2.0",
  21763. false
  21764. ],
  21765. "CC-BY-2.5": [
  21766. "Creative Commons Attribution 2.5",
  21767. false
  21768. ],
  21769. "CC-BY-3.0": [
  21770. "Creative Commons Attribution 3.0",
  21771. false
  21772. ],
  21773. "CC-BY-4.0": [
  21774. "Creative Commons Attribution 4.0",
  21775. false
  21776. ],
  21777. "CC-BY-NC-1.0": [
  21778. "Creative Commons Attribution Non Commercial 1.0",
  21779. false
  21780. ],
  21781. "CC-BY-NC-2.0": [
  21782. "Creative Commons Attribution Non Commercial 2.0",
  21783. false
  21784. ],
  21785. "CC-BY-NC-2.5": [
  21786. "Creative Commons Attribution Non Commercial 2.5",
  21787. false
  21788. ],
  21789. "CC-BY-NC-3.0": [
  21790. "Creative Commons Attribution Non Commercial 3.0",
  21791. false
  21792. ],
  21793. "CC-BY-NC-4.0": [
  21794. "Creative Commons Attribution Non Commercial 4.0",
  21795. false
  21796. ],
  21797. "CC-BY-NC-ND-1.0": [
  21798. "Creative Commons Attribution Non Commercial No Derivatives 1.0",
  21799. false
  21800. ],
  21801. "CC-BY-NC-ND-2.0": [
  21802. "Creative Commons Attribution Non Commercial No Derivatives 2.0",
  21803. false
  21804. ],
  21805. "CC-BY-NC-ND-2.5": [
  21806. "Creative Commons Attribution Non Commercial No Derivatives 2.5",
  21807. false
  21808. ],
  21809. "CC-BY-NC-ND-3.0": [
  21810. "Creative Commons Attribution Non Commercial No Derivatives 3.0",
  21811. false
  21812. ],
  21813. "CC-BY-NC-ND-4.0": [
  21814. "Creative Commons Attribution Non Commercial No Derivatives 4.0",
  21815. false
  21816. ],
  21817. "CC-BY-NC-SA-1.0": [
  21818. "Creative Commons Attribution Non Commercial Share Alike 1.0",
  21819. false
  21820. ],
  21821. "CC-BY-NC-SA-2.0": [
  21822. "Creative Commons Attribution Non Commercial Share Alike 2.0",
  21823. false
  21824. ],
  21825. "CC-BY-NC-SA-2.5": [
  21826. "Creative Commons Attribution Non Commercial Share Alike 2.5",
  21827. false
  21828. ],
  21829. "CC-BY-NC-SA-3.0": [
  21830. "Creative Commons Attribution Non Commercial Share Alike 3.0",
  21831. false
  21832. ],
  21833. "CC-BY-NC-SA-4.0": [
  21834. "Creative Commons Attribution Non Commercial Share Alike 4.0",
  21835. false
  21836. ],
  21837. "CC-BY-ND-1.0": [
  21838. "Creative Commons Attribution No Derivatives 1.0",
  21839. false
  21840. ],
  21841. "CC-BY-ND-2.0": [
  21842. "Creative Commons Attribution No Derivatives 2.0",
  21843. false
  21844. ],
  21845. "CC-BY-ND-2.5": [
  21846. "Creative Commons Attribution No Derivatives 2.5",
  21847. false
  21848. ],
  21849. "CC-BY-ND-3.0": [
  21850. "Creative Commons Attribution No Derivatives 3.0",
  21851. false
  21852. ],
  21853. "CC-BY-ND-4.0": [
  21854. "Creative Commons Attribution No Derivatives 4.0",
  21855. false
  21856. ],
  21857. "CC-BY-SA-1.0": [
  21858. "Creative Commons Attribution Share Alike 1.0",
  21859. false
  21860. ],
  21861. "CC-BY-SA-2.0": [
  21862. "Creative Commons Attribution Share Alike 2.0",
  21863. false
  21864. ],
  21865. "CC-BY-SA-2.5": [
  21866. "Creative Commons Attribution Share Alike 2.5",
  21867. false
  21868. ],
  21869. "CC-BY-SA-3.0": [
  21870. "Creative Commons Attribution Share Alike 3.0",
  21871. false
  21872. ],
  21873. "CC-BY-SA-4.0": [
  21874. "Creative Commons Attribution Share Alike 4.0",
  21875. false
  21876. ],
  21877. "CC0-1.0": [
  21878. "Creative Commons Zero v1.0 Universal",
  21879. false
  21880. ],
  21881. "CDDL-1.0": [
  21882. "Common Development and Distribution License 1.0",
  21883. true
  21884. ],
  21885. "CDDL-1.1": [
  21886. "Common Development and Distribution License 1.1",
  21887. false
  21888. ],
  21889. "CECILL-1.0": [
  21890. "CeCILL Free Software License Agreement v1.0",
  21891. false
  21892. ],
  21893. "CECILL-1.1": [
  21894. "CeCILL Free Software License Agreement v1.1",
  21895. false
  21896. ],
  21897. "CECILL-2.0": [
  21898. "CeCILL Free Software License Agreement v2.0",
  21899. false
  21900. ],
  21901. "CECILL-B": [
  21902. "CeCILL-B Free Software License Agreement",
  21903. false
  21904. ],
  21905. "CECILL-C": [
  21906. "CeCILL-C Free Software License Agreement",
  21907. false
  21908. ],
  21909. "ClArtistic": [
  21910. "Clarified Artistic License",
  21911. false
  21912. ],
  21913. "CNRI-Jython": [
  21914. "CNRI Jython License",
  21915. false
  21916. ],
  21917. "CNRI-Python": [
  21918. "CNRI Python License",
  21919. true
  21920. ],
  21921. "CNRI-Python-GPL-Compatible": [
  21922. "CNRI Python Open Source GPL Compatible License Agreement",
  21923. false
  21924. ],
  21925. "Condor-1.1": [
  21926. "Condor Public License v1.1",
  21927. false
  21928. ],
  21929. "CPAL-1.0": [
  21930. "Common Public Attribution License 1.0",
  21931. true
  21932. ],
  21933. "CPL-1.0": [
  21934. "Common Public License 1.0",
  21935. true
  21936. ],
  21937. "CPOL-1.02": [
  21938. "Code Project Open License 1.02",
  21939. false
  21940. ],
  21941. "Crossword": [
  21942. "Crossword License",
  21943. false
  21944. ],
  21945. "CUA-OPL-1.0": [
  21946. "CUA Office Public License v1.0",
  21947. true
  21948. ],
  21949. "Cube": [
  21950. "Cube License",
  21951. false
  21952. ],
  21953. "D-FSL-1.0": [
  21954. "Deutsche Freie Software Lizenz",
  21955. false
  21956. ],
  21957. "diffmark": [
  21958. "diffmark license",
  21959. false
  21960. ],
  21961. "DOC": [
  21962. "DOC License",
  21963. false
  21964. ],
  21965. "Dotseqn": [
  21966. "Dotseqn License",
  21967. false
  21968. ],
  21969. "DSDP": [
  21970. "DSDP License",
  21971. false
  21972. ],
  21973. "dvipdfm": [
  21974. "dvipdfm License",
  21975. false
  21976. ],
  21977. "ECL-1.0": [
  21978. "Educational Community License v1.0",
  21979. true
  21980. ],
  21981. "ECL-2.0": [
  21982. "Educational Community License v2.0",
  21983. true
  21984. ],
  21985. "EFL-1.0": [
  21986. "Eiffel Forum License v1.0",
  21987. true
  21988. ],
  21989. "EFL-2.0": [
  21990. "Eiffel Forum License v2.0",
  21991. true
  21992. ],
  21993. "eGenix": [
  21994. "eGenix.com Public License 1.1.0",
  21995. false
  21996. ],
  21997. "Entessa": [
  21998. "Entessa Public License v1.0",
  21999. true
  22000. ],
  22001. "EPL-1.0": [
  22002. "Eclipse Public License 1.0",
  22003. true
  22004. ],
  22005. "ErlPL-1.1": [
  22006. "Erlang Public License v1.1",
  22007. false
  22008. ],
  22009. "EUDatagrid": [
  22010. "EU DataGrid Software License",
  22011. true
  22012. ],
  22013. "EUPL-1.0": [
  22014. "European Union Public License 1.0",
  22015. false
  22016. ],
  22017. "EUPL-1.1": [
  22018. "European Union Public License 1.1",
  22019. true
  22020. ],
  22021. "Eurosym": [
  22022. "Eurosym License",
  22023. false
  22024. ],
  22025. "Fair": [
  22026. "Fair License",
  22027. true
  22028. ],
  22029. "Frameworx-1.0": [
  22030. "Frameworx Open License 1.0",
  22031. true
  22032. ],
  22033. "FreeImage": [
  22034. "FreeImage Public License v1.0",
  22035. false
  22036. ],
  22037. "FSFUL": [
  22038. "FSF Unlimited License",
  22039. false
  22040. ],
  22041. "FSFULLR": [
  22042. "FSF Unlimited License (with License Retention)",
  22043. false
  22044. ],
  22045. "FTL": [
  22046. "Freetype Project License",
  22047. false
  22048. ],
  22049. "GFDL-1.1": [
  22050. "GNU Free Documentation License v1.1",
  22051. false
  22052. ],
  22053. "GFDL-1.2": [
  22054. "GNU Free Documentation License v1.2",
  22055. false
  22056. ],
  22057. "GFDL-1.3": [
  22058. "GNU Free Documentation License v1.3",
  22059. false
  22060. ],
  22061. "Giftware": [
  22062. "Giftware License",
  22063. false
  22064. ],
  22065. "GL2PS": [
  22066. "GL2PS License",
  22067. false
  22068. ],
  22069. "Glide": [
  22070. "3dfx Glide License",
  22071. false
  22072. ],
  22073. "Glulxe": [
  22074. "Glulxe License",
  22075. false
  22076. ],
  22077. "gnuplot": [
  22078. "gnuplot License",
  22079. false
  22080. ],
  22081. "GPL-1.0": [
  22082. "GNU General Public License v1.0 only",
  22083. false
  22084. ],
  22085. "GPL-2.0": [
  22086. "GNU General Public License v2.0 only",
  22087. true
  22088. ],
  22089. "GPL-3.0": [
  22090. "GNU General Public License v3.0 only",
  22091. true
  22092. ],
  22093. "gSOAP-1.3b": [
  22094. "gSOAP Public License v1.3b",
  22095. false
  22096. ],
  22097. "HaskellReport": [
  22098. "Haskell Language Report License",
  22099. false
  22100. ],
  22101. "HPND": [
  22102. "Historic Permission Notice and Disclaimer",
  22103. true
  22104. ],
  22105. "IBM-pibs": [
  22106. "IBM PowerPC Initialization and Boot Software",
  22107. false
  22108. ],
  22109. "ICU": [
  22110. "ICU License",
  22111. false
  22112. ],
  22113. "IJG": [
  22114. "Independent JPEG Group License",
  22115. false
  22116. ],
  22117. "ImageMagick": [
  22118. "ImageMagick License",
  22119. false
  22120. ],
  22121. "iMatix": [
  22122. "iMatix Standard Function Library Agreement",
  22123. false
  22124. ],
  22125. "Imlib2": [
  22126. "Imlib2 License",
  22127. false
  22128. ],
  22129. "Intel": [
  22130. "Intel Open Source License",
  22131. true
  22132. ],
  22133. "Intel-ACPI": [
  22134. "Intel ACPI Software License Agreement",
  22135. false
  22136. ],
  22137. "IPA": [
  22138. "IPA Font License",
  22139. true
  22140. ],
  22141. "IPL-1.0": [
  22142. "IBM Public License v1.0",
  22143. true
  22144. ],
  22145. "ISC": [
  22146. "ISC License",
  22147. true
  22148. ],
  22149. "JasPer-2.0": [
  22150. "JasPer License",
  22151. false
  22152. ],
  22153. "JSON": [
  22154. "JSON License",
  22155. false
  22156. ],
  22157. "Latex2e": [
  22158. "Latex2e License",
  22159. false
  22160. ],
  22161. "Leptonica": [
  22162. "Leptonica License",
  22163. false
  22164. ],
  22165. "LGPL-2.0": [
  22166. "GNU Library General Public License v2 only",
  22167. true
  22168. ],
  22169. "LGPL-2.1": [
  22170. "GNU Lesser General Public License v2.1 only",
  22171. true
  22172. ],
  22173. "LGPL-3.0": [
  22174. "GNU Lesser General Public License v3.0 only",
  22175. true
  22176. ],
  22177. "LGPLLR": [
  22178. "Lesser General Public License For Linguistic Resources",
  22179. false
  22180. ],
  22181. "Libpng": [
  22182. "libpng License",
  22183. false
  22184. ],
  22185. "libtiff": [
  22186. "libtiff License",
  22187. false
  22188. ],
  22189. "LPL-1.0": [
  22190. "Lucent Public License Version 1.0",
  22191. true
  22192. ],
  22193. "LPL-1.02": [
  22194. "Lucent Public License v1.02",
  22195. true
  22196. ],
  22197. "LPPL-1.0": [
  22198. "LaTeX Project Public License v1.0",
  22199. false
  22200. ],
  22201. "LPPL-1.1": [
  22202. "LaTeX Project Public License v1.1",
  22203. false
  22204. ],
  22205. "LPPL-1.2": [
  22206. "LaTeX Project Public License v1.2",
  22207. false
  22208. ],
  22209. "LPPL-1.3a": [
  22210. "LaTeX Project Public License 1.3a",
  22211. false
  22212. ],
  22213. "LPPL-1.3c": [
  22214. "LaTeX Project Public License v1.3c",
  22215. true
  22216. ],
  22217. "MakeIndex": [
  22218. "MakeIndex License",
  22219. false
  22220. ],
  22221. "MirOS": [
  22222. "MirOS Licence",
  22223. true
  22224. ],
  22225. "MIT": [
  22226. "MIT License",
  22227. true
  22228. ],
  22229. "MIT-advertising": [
  22230. "Enlightenment License (e16)",
  22231. false
  22232. ],
  22233. "MIT-CMU": [
  22234. "CMU License",
  22235. false
  22236. ],
  22237. "MIT-enna": [
  22238. "enna License",
  22239. false
  22240. ],
  22241. "MIT-feh": [
  22242. "feh License",
  22243. false
  22244. ],
  22245. "MITNFA": [
  22246. "MIT +no-false-attribs license",
  22247. false
  22248. ],
  22249. "Motosoto": [
  22250. "Motosoto License",
  22251. true
  22252. ],
  22253. "mpich2": [
  22254. "mpich2 License",
  22255. false
  22256. ],
  22257. "MPL-1.0": [
  22258. "Mozilla Public License 1.0",
  22259. true
  22260. ],
  22261. "MPL-1.1": [
  22262. "Mozilla Public License 1.1",
  22263. true
  22264. ],
  22265. "MPL-2.0": [
  22266. "Mozilla Public License 2.0",
  22267. true
  22268. ],
  22269. "MPL-2.0-no-copyleft-exception": [
  22270. "Mozilla Public License 2.0 (no copyleft exception)",
  22271. true
  22272. ],
  22273. "MS-PL": [
  22274. "Microsoft Public License",
  22275. true
  22276. ],
  22277. "MS-RL": [
  22278. "Microsoft Reciprocal License",
  22279. true
  22280. ],
  22281. "MTLL": [
  22282. "Matrix Template Library License",
  22283. false
  22284. ],
  22285. "Multics": [
  22286. "Multics License",
  22287. true
  22288. ],
  22289. "Mup": [
  22290. "Mup License",
  22291. false
  22292. ],
  22293. "NASA-1.3": [
  22294. "NASA Open Source Agreement 1.3",
  22295. true
  22296. ],
  22297. "Naumen": [
  22298. "Naumen Public License",
  22299. true
  22300. ],
  22301. "NBPL-1.0": [
  22302. "Net Boolean Public License v1",
  22303. false
  22304. ],
  22305. "NCSA": [
  22306. "University of Illinois/NCSA Open Source License",
  22307. true
  22308. ],
  22309. "NetCDF": [
  22310. "NetCDF license",
  22311. false
  22312. ],
  22313. "Newsletr": [
  22314. "Newsletr License",
  22315. false
  22316. ],
  22317. "NGPL": [
  22318. "Nethack General Public License",
  22319. true
  22320. ],
  22321. "NLPL": [
  22322. "No Limit Public License",
  22323. false
  22324. ],
  22325. "Nokia": [
  22326. "Nokia Open Source License",
  22327. true
  22328. ],
  22329. "NOSL": [
  22330. "Netizen Open Source License",
  22331. false
  22332. ],
  22333. "Noweb": [
  22334. "Noweb License",
  22335. false
  22336. ],
  22337. "NPL-1.0": [
  22338. "Netscape Public License v1.0",
  22339. false
  22340. ],
  22341. "NPL-1.1": [
  22342. "Netscape Public License v1.1",
  22343. false
  22344. ],
  22345. "NPOSL-3.0": [
  22346. "Non-Profit Open Software License 3.0",
  22347. true
  22348. ],
  22349. "NRL": [
  22350. "NRL License",
  22351. false
  22352. ],
  22353. "NTP": [
  22354. "NTP License",
  22355. true
  22356. ],
  22357. "Nunit": [
  22358. "Nunit License",
  22359. false
  22360. ],
  22361. "OCLC-2.0": [
  22362. "OCLC Research Public License 2.0",
  22363. true
  22364. ],
  22365. "ODbL-1.0": [
  22366. "ODC Open Database License v1.0",
  22367. false
  22368. ],
  22369. "OFL-1.0": [
  22370. "SIL Open Font License 1.0",
  22371. false
  22372. ],
  22373. "OFL-1.1": [
  22374. "SIL Open Font License 1.1",
  22375. true
  22376. ],
  22377. "OGTSL": [
  22378. "Open Group Test Suite License",
  22379. true
  22380. ],
  22381. "OLDAP-1.1": [
  22382. "Open LDAP Public License v1.1",
  22383. false
  22384. ],
  22385. "OLDAP-1.2": [
  22386. "Open LDAP Public License v1.2",
  22387. false
  22388. ],
  22389. "OLDAP-1.3": [
  22390. "Open LDAP Public License v1.3",
  22391. false
  22392. ],
  22393. "OLDAP-1.4": [
  22394. "Open LDAP Public License v1.4",
  22395. false
  22396. ],
  22397. "OLDAP-2.0": [
  22398. "Open LDAP Public License v2.0 (or possibly 2.0A and 2.0B)",
  22399. false
  22400. ],
  22401. "OLDAP-2.0.1": [
  22402. "Open LDAP Public License v2.0.1",
  22403. false
  22404. ],
  22405. "OLDAP-2.1": [
  22406. "Open LDAP Public License v2.1",
  22407. false
  22408. ],
  22409. "OLDAP-2.2": [
  22410. "Open LDAP Public License v2.2",
  22411. false
  22412. ],
  22413. "OLDAP-2.2.1": [
  22414. "Open LDAP Public License v2.2.1",
  22415. false
  22416. ],
  22417. "OLDAP-2.2.2": [
  22418. "Open LDAP Public License 2.2.2",
  22419. false
  22420. ],
  22421. "OLDAP-2.3": [
  22422. "Open LDAP Public License v2.3",
  22423. false
  22424. ],
  22425. "OLDAP-2.4": [
  22426. "Open LDAP Public License v2.4",
  22427. false
  22428. ],
  22429. "OLDAP-2.5": [
  22430. "Open LDAP Public License v2.5",
  22431. false
  22432. ],
  22433. "OLDAP-2.6": [
  22434. "Open LDAP Public License v2.6",
  22435. false
  22436. ],
  22437. "OLDAP-2.7": [
  22438. "Open LDAP Public License v2.7",
  22439. false
  22440. ],
  22441. "OLDAP-2.8": [
  22442. "Open LDAP Public License v2.8",
  22443. false
  22444. ],
  22445. "OML": [
  22446. "Open Market License",
  22447. false
  22448. ],
  22449. "OpenSSL": [
  22450. "OpenSSL License",
  22451. false
  22452. ],
  22453. "OPL-1.0": [
  22454. "Open Public License v1.0",
  22455. false
  22456. ],
  22457. "OSL-1.0": [
  22458. "Open Software License 1.0",
  22459. true
  22460. ],
  22461. "OSL-1.1": [
  22462. "Open Software License 1.1",
  22463. false
  22464. ],
  22465. "OSL-2.0": [
  22466. "Open Software License 2.0",
  22467. true
  22468. ],
  22469. "OSL-2.1": [
  22470. "Open Software License 2.1",
  22471. true
  22472. ],
  22473. "OSL-3.0": [
  22474. "Open Software License 3.0",
  22475. true
  22476. ],
  22477. "PDDL-1.0": [
  22478. "ODC Public Domain Dedication & License 1.0",
  22479. false
  22480. ],
  22481. "PHP-3.0": [
  22482. "PHP License v3.0",
  22483. true
  22484. ],
  22485. "PHP-3.01": [
  22486. "PHP License v3.01",
  22487. false
  22488. ],
  22489. "Plexus": [
  22490. "Plexus Classworlds License",
  22491. false
  22492. ],
  22493. "PostgreSQL": [
  22494. "PostgreSQL License",
  22495. true
  22496. ],
  22497. "psfrag": [
  22498. "psfrag License",
  22499. false
  22500. ],
  22501. "psutils": [
  22502. "psutils License",
  22503. false
  22504. ],
  22505. "Python-2.0": [
  22506. "Python License 2.0",
  22507. true
  22508. ],
  22509. "Qhull": [
  22510. "Qhull License",
  22511. false
  22512. ],
  22513. "QPL-1.0": [
  22514. "Q Public License 1.0",
  22515. true
  22516. ],
  22517. "Rdisc": [
  22518. "Rdisc License",
  22519. false
  22520. ],
  22521. "RHeCos-1.1": [
  22522. "Red Hat eCos Public License v1.1",
  22523. false
  22524. ],
  22525. "RPL-1.1": [
  22526. "Reciprocal Public License 1.1",
  22527. true
  22528. ],
  22529. "RPL-1.5": [
  22530. "Reciprocal Public License 1.5",
  22531. true
  22532. ],
  22533. "RPSL-1.0": [
  22534. "RealNetworks Public Source License v1.0",
  22535. true
  22536. ],
  22537. "RSA-MD": [
  22538. "RSA Message-Digest License",
  22539. false
  22540. ],
  22541. "RSCPL": [
  22542. "Ricoh Source Code Public License",
  22543. true
  22544. ],
  22545. "Ruby": [
  22546. "Ruby License",
  22547. false
  22548. ],
  22549. "SAX-PD": [
  22550. "Sax Public Domain Notice",
  22551. false
  22552. ],
  22553. "Saxpath": [
  22554. "Saxpath License",
  22555. false
  22556. ],
  22557. "SCEA": [
  22558. "SCEA Shared Source License",
  22559. false
  22560. ],
  22561. "SGI-B-1.0": [
  22562. "SGI Free Software License B v1.0",
  22563. false
  22564. ],
  22565. "SGI-B-1.1": [
  22566. "SGI Free Software License B v1.1",
  22567. false
  22568. ],
  22569. "SGI-B-2.0": [
  22570. "SGI Free Software License B v2.0",
  22571. false
  22572. ],
  22573. "SimPL-2.0": [
  22574. "Simple Public License 2.0",
  22575. true
  22576. ],
  22577. "SISSL": [
  22578. "Sun Industry Standards Source License v1.1",
  22579. true
  22580. ],
  22581. "SISSL-1.2": [
  22582. "Sun Industry Standards Source License v1.2",
  22583. false
  22584. ],
  22585. "Sleepycat": [
  22586. "Sleepycat License",
  22587. true
  22588. ],
  22589. "SMLNJ": [
  22590. "Standard ML of New Jersey License",
  22591. false
  22592. ],
  22593. "SNIA": [
  22594. "SNIA Public License 1.1",
  22595. false
  22596. ],
  22597. "Spencer-86": [
  22598. "Spencer License 86",
  22599. false
  22600. ],
  22601. "Spencer-94": [
  22602. "Spencer License 94",
  22603. false
  22604. ],
  22605. "Spencer-99": [
  22606. "Spencer License 99",
  22607. false
  22608. ],
  22609. "SPL-1.0": [
  22610. "Sun Public License v1.0",
  22611. true
  22612. ],
  22613. "SugarCRM-1.1.3": [
  22614. "SugarCRM Public License v1.1.3",
  22615. false
  22616. ],
  22617. "SWL": [
  22618. "Scheme Widget Library (SWL) Software License Agreement",
  22619. false
  22620. ],
  22621. "TCL": [
  22622. "TCL/TK License",
  22623. false
  22624. ],
  22625. "TMate": [
  22626. "TMate Open Source License",
  22627. false
  22628. ],
  22629. "TORQUE-1.1": [
  22630. "TORQUE v2.5+ Software License v1.1",
  22631. false
  22632. ],
  22633. "TOSL": [
  22634. "Trusster Open Source License",
  22635. false
  22636. ],
  22637. "Unicode-TOU": [
  22638. "Unicode Terms of Use",
  22639. false
  22640. ],
  22641. "Unlicense": [
  22642. "The Unlicense",
  22643. false
  22644. ],
  22645. "UPL-1.0": [
  22646. "Universal Permissive License v1.0",
  22647. true
  22648. ],
  22649. "Vim": [
  22650. "Vim License",
  22651. false
  22652. ],
  22653. "VOSTROM": [
  22654. "VOSTROM Public License for Open Source",
  22655. false
  22656. ],
  22657. "VSL-1.0": [
  22658. "Vovida Software License v1.0",
  22659. true
  22660. ],
  22661. "W3C": [
  22662. "W3C Software Notice and License (2002-12-31)",
  22663. true
  22664. ],
  22665. "W3C-19980720": [
  22666. "W3C Software Notice and License (1998-07-20)",
  22667. false
  22668. ],
  22669. "Watcom-1.0": [
  22670. "Sybase Open Watcom Public License 1.0",
  22671. true
  22672. ],
  22673. "Wsuipa": [
  22674. "Wsuipa License",
  22675. false
  22676. ],
  22677. "WTFPL": [
  22678. "Do What The F*ck You Want To Public License",
  22679. false
  22680. ],
  22681. "X11": [
  22682. "X11 License",
  22683. false
  22684. ],
  22685. "Xerox": [
  22686. "Xerox License",
  22687. false
  22688. ],
  22689. "XFree86-1.1": [
  22690. "XFree86 License 1.1",
  22691. false
  22692. ],
  22693. "xinetd": [
  22694. "xinetd License",
  22695. false
  22696. ],
  22697. "Xnet": [
  22698. "X.Net License",
  22699. true
  22700. ],
  22701. "xpp": [
  22702. "XPP License",
  22703. false
  22704. ],
  22705. "XSkat": [
  22706. "XSkat License",
  22707. false
  22708. ],
  22709. "YPL-1.0": [
  22710. "Yahoo! Public License v1.0",
  22711. false
  22712. ],
  22713. "YPL-1.1": [
  22714. "Yahoo! Public License v1.1",
  22715. false
  22716. ],
  22717. "Zed": [
  22718. "Zed License",
  22719. false
  22720. ],
  22721. "Zend-2.0": [
  22722. "Zend License v2.0",
  22723. false
  22724. ],
  22725. "Zimbra-1.3": [
  22726. "Zimbra Public License v1.3",
  22727. false
  22728. ],
  22729. "Zimbra-1.4": [
  22730. "Zimbra Public License v1.4",
  22731. false
  22732. ],
  22733. "Zlib": [
  22734. "zlib License",
  22735. true
  22736. ],
  22737. "zlib-acknowledgement": [
  22738. "zlib/libpng License with Acknowledgement",
  22739. false
  22740. ],
  22741. "ZPL-1.1": [
  22742. "Zope Public License 1.1",
  22743. false
  22744. ],
  22745. "ZPL-2.0": [
  22746. "Zope Public License 2.0",
  22747. true
  22748. ],
  22749. "ZPL-2.1": [
  22750. "Zope Public License 2.1",
  22751. false
  22752. ]
  22753. }MZ��������ÿÿ��¸�������@�����������������������������������è���º�´ Í!¸LÍ!This program cannot be run in DOS mode.
  22754. $�������Æ,Í;§Bž;§Bž;§Bž2ßמ:§Bž2ßÁž-§Bž2ßÆž9§Bž2ßÑž?§Bža9ž8§Bž;§Cž§Bž2ßÈž:§Bž2ßÖž:§Bž2ßÓž:§BžRich;§Bž��������PE��L�¬MoO��������à�  ��
  22755. ���������8������ ����@����������������������`�����?œ���@�����������������������������"��P����@�� �������������������P��p���!�����������������������������8!��@������������ ��Ø���������������������������.text��� ������
  22756. ����������������� ��`.rdata����� ���
  22757. �����������������@��@.data�������0��������������������@��À.rsrc��� ���@��������������������@��@.reloc��Ì���P������"��������������@��B��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������j$¸æ@�èx��jöÿ @�ƒeÐ�‹ð�EÐPVÿ� @�‹EЃàûPVÿ @��MÔÿX @�ƒeü��EÔPÿ5H @�ÿL @�YYÿ5\ @��EÔPÿ5` @�ÿD @�YY‹ÈÿP @�ƒMüÿ�MÔÿT @�3ÀèH��Ã; �0@�uóÃé¬��h€@�è£��¡l3@�Ç$40@�ÿ5h3@�£40@�h$0@�h(0@�h 0@�ÿ  @�ƒÄ£00@�…À}jè¹��YÃjh"@�è��3Û‰]üd¡���‹p‰]ä¿€3@�SVWÿ0 @�;Ãt;Æu3öF‰uäëhè��ÿ4 @�ëÚ3öF¡|3@�;Æu
  22758. jè\��Yë;¡|3@�…Àu,‰5|3@�hð @�hä @�è§��YY…ÀtÇEüþÿÿÿ¸ÿ���éÝ���‰5<0@�¡|3@�;Æuhà @�hØ @�èl��YYÇ|3@����9]äuSWÿ8 @�9Œ3@�thŒ3@�èƒ��Y…Àt
  22759. SjSÿŒ3@�¡$0@�‹ ¼ @�‰ÿ5$0@�ÿ5(0@�ÿ5 0@�èþÿÿƒÄ £80@�9,0@�u7PÿÀ @�‹Eì‹‹ ‰MàPQèŽ��YYËeè‹Eà£80@�3Û9,0@�uPÿh @�9<0@�uÿœ @�ÇEüþÿÿÿ¡80@�èû��øMZ��f9��@�t3ÀëM¡<�@��€��@��8PE��ué·H�ù ��t�ù ��uÕƒ¸„���vÌ3É9ˆø���ëƒxtv¼3É9ˆè���•Á‹Áj£,0@�ÿp @�jÿÿl @�YY£„3@�£ˆ3@�ÿÌ @�‹ t3@�‰ÿˆ @�‹ p3@�‰¡¨ @�‹�£x3@�èV��è¬��ƒ=0@��u hµ@�ÿ¬ @�Yèg��ƒ=0@�ÿu jÿÿ° @�Y3ÀÃè{��éŸýÿÿ‹ÿU‹ì�ì(��£H1@�‰ D1@�‰@1@�‰<1@�‰581@�‰=41@�fŒ`1@�fŒ T1@�fŒ01@�fŒ,1@�fŒ%(1@�fŒ-$1@�œ�X1@�‹E�£L1@�‹E£P1@��E£\1@�‹…àüÿÿǘ0@���¡P1@�£L0@�Ç@0@� �ÀÇD0@����¡�0@�‰…Øüÿÿ¡0@�‰…Üüÿÿÿ @�£�0@�jè?��Yj�ÿ @�h!@�ÿ$ @�ƒ=�0@��ujè��Yh �Àÿ( @�Pÿ, @�ÉËÿU‹ì‹E‹��8csmàu*ƒxu$‹@= “t=!“t="“t=�@™uèÐ��3À]Â�hH@�ÿ @�3ÀÃÿ%¤ @�jh("@�èb��ÿ5ˆ3@�‹5Œ @�ÿÖY‰Eäƒøÿu ÿuÿÄ @�Yëgjè’��Yƒeü�ÿ5ˆ3@�ÿÖ‰Eäÿ5„3@�ÿÖYY‰Eà�EàP�EäPÿu‹5l @�ÿÖYPèU��‰EÜÿuäÿÖ£ˆ3@�ÿuàÿփģ„3@�ÇEüþÿÿÿè ���‹EÜè��Ãjè��YËÿU‹ìÿuèNÿÿÿ÷ØÀ÷ØYH]ËÿV¸ü!@�¾ü!@�W‹ø;Æs‹…ÀtÿЃÇ;þrñ_^ËÿV¸"@�¾"@�W‹ø;Æs‹…ÀtÿЃÇ;þrñ_^Ãÿ%È @�ÌÌÌÌ‹ÿU‹ì‹M¸MZ��f9t3À]ËA<Á�8PE��uï3Ò¹ ��f9H”‹Â]ÃÌÌÌÌÌÌÌÌÌÌÌ‹ÿU‹ì‹E‹H<È·ASV·q3ÒW�D…öv‹} ‹H ;ùr ‹XÙ;ûr
  22760. BƒÀ(;Örè3À_^[]ÃÌÌÌÌÌÌÌÌÌÌÌÌ‹ÿU‹ìjþhH"@�he@�d¡����PƒìSVW¡�0@�1Eø3ÅP�Eðd£����‰eèÇEü����h��@�è*ÿÿÿƒÄ…ÀtU‹E-��@�Ph��@�èPÿÿÿƒÄ…Àt;‹@$Áè÷ЃàÇEüþÿÿÿ‹Mðd‰ ����Y_^[‹å]ËEì‹‹3Ò=��À”‹ÂËeèÇEüþÿÿÿ3À‹Mðd‰ ����Y_^[‹å]ÃÌÿ%¸ @�ÿ%´ @�ÌÌhe@�dÿ5����‹D$‰l$�l$+àSVW¡�0@�1Eü3ÅP‰eèÿuø‹EüÇEüþÿÿÿ‰Eø�Eðd£����ËMðd‰ ����Y__^[‹å]QËÿU‹ìÿuÿuÿu ÿuh‡@�h�0@�èç���ƒÄ]ËÿVh���h���3öVèÙ���ƒÄ …Àt VVVVVèÂ���ƒÄ^Ã3ÀËÿU‹ìƒì¡�0@�ƒeø�ƒeü�SW¿Næ@»»��ÿÿ;Çt …Ãt ÷У0@�ë`V�EøPÿ< @�‹uü3uøÿ @�3ðÿ @�3ðÿ @�3ð�EðPÿ @�‹Eô3Eð3ð;÷u¾Oæ@»ë …óu‹ÆÁà ð‰5�0@�÷Ö‰50@�^_[ÉÃÿ%t @�ÿ%x @�ÿ%| @�ÿ%€ @�ÿ%„ @�ÿ%� @�ÿ%” @�ÿ%˜ @�ÿ%Ð @�Pdÿ5�����D$ +d$ SVW‰(‹è¡�0@�3ÅP‰EðÿuüÇEüÿÿÿÿ�Eôd£����ËMôd‰ ����Y__^[‹å]QËMð3Íè¯÷ÿÿéÝÿÿÿ�MÔÿ%T @�‹T$�B ‹JÌ3Èè�÷ÿÿ‹Jü3Èè†÷ÿÿ¸l"@�ésÿÿÿ�����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������¸#��Ê#��Ü#��ˆ)��r)��b)��H)��4)��)��ú(��æ(��Ò(��´(��¬(��–(��ž)������ú#��à$��%��Ê%��&��d&��®&��¤$������('��Ä'��Ö'��è'��þ'��(��((��6(��¦'��H(��Z(��t(��†(��'��'���'��–'��‚'��l'��^'��R'��F'��>'��>(��0'��¶'��¸)����������–@���������W@�Š@���������������������¬MoO�������l���€!��€��@0@�˜0@�bad allocation������H������������������������������������������������������������0@�ð!@����RSDSÑŒ³´�J¨!öÌëLZ����c:\users\seld\documents\visual studio 2010\Projects\hiddeninp\Release\hiddeninp.pdb�����e��æ������������������þÿÿÿ����Ðÿÿÿ����þÿÿÿ@�@�����þÿÿÿ����Ìÿÿÿ����þÿÿÿ����:@�����þÿÿÿ����Øÿÿÿ����þÿÿÿË@�ß@�ÿÿÿÿÝ@�"“���d"@������������������������à"����������ì#��� ��$#����������ô&��D ��H#����������(��h ����������������������¸#��Ê#��Ü#��ˆ)��r)��b)��H)��4)��)��ú(��æ(��Ò(��´(��¬(��–(��ž)������ú#��à$��%��Ê%��&��d&��®&��¤$������('��Ä'��Ö'��è'��þ'��(��((��6(��¦'��H(��Z(��t(��†(��'��'���'��–'��‚'��l'��^'��R'��F'��>'��>(��0'��¶'��¸)������•GetConsoleMode��·SetConsoleMode��;GetStdHandle��KERNEL32.dll���??$?6DU?$char_traits@D@std@@V?$allocator@D@1@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@@Z�‘?cout@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@A��J?cin@std@@3V?$basic_istream@DU?$char_traits@D@std@@@1@A�Â�??$getline@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@YAAAV?$basic_istream@DU?$char_traits@D@std@@@0@AAV10@AAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@@Z�??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z��_??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ��{??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ��³?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z��MSVCP90.dll�_amsg_exit��Ÿ�__getmainargs�,_cexit��|_exit�f�_XcptFilter�Ìexit�� �__initenv�_initterm�_initterm_e�<_configthreadlocale�ã�__setusermatherr�� _adjust_fdiv��Ë�__p__commode��Ï�__p__fmode��j_encode_pointer�à�__set_app_type��K_crt_debugger_hook��C�?terminate@@YAXXZ�MSVCR90.dll�æ_unlock�–�__dllonexit�v_lock�_onexit�`_decode_pointer�s_except_handler4_common� _invoke_watson��?_controlfp_s��½InterlockedExchange�!Sleep�ºInterlockedCompareExchange��-TerminateProcess��©GetCurrentProcess�>UnhandledExceptionFilter��SetUnhandledExceptionFilter�ÑIsDebuggerPresent�TQueryPerformanceCounter�fGetTickCount��­GetCurrentThreadId��ªGetCurrentProcessId�OGetSystemTimeAsFileTime�s�__CxxFrameHandler3����������������������������������������������������Næ@»±¿Dÿÿÿÿÿÿÿÿþÿÿÿ���$!@���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� ��€���8��€�����������������P��€�����������������h��€�������������� ��€����������������� ������ @��(��ä������ÈC��V��ä������(4���V�S�_�V�E�R�S�I�O�N�_�I�N�F�O�����½ïþ������������������������������������������†���S�t�r�i�n�g�F�i�l�e�I�n�f�o���b���0�4�0�9�0�4�b�0���Ê�Q��F�i�l�e�D�e�s�c�r�i�p�t�i�o�n�����R�e�a�d�s� �f�r�o�m� �s�t�d�i�n� �w�i�t�h�o�u�t� �l�e�a�k�i�n�g� �i�n�f�o� �t�o� �t�h�e� �t�e�r�m�i�n�a�l� �a�n�d� �o�u�t�p�u�t�s� �b�a�c�k� �t�o� �s�t�d�o�u�t�����6� ��F�i�l�e�V�e�r�s�i�o�n�����1�,� �0�,� �0�,� �0�����8� ��I�n�t�e�r�n�a�l�N�a�m�e���h�i�d�d�e�n�i�n�p�u�t���P���L�e�g�a�l�C�o�p�y�r�i�g�h�t���J�o�r�d�i� �B�o�g�g�i�a�n�o� �-� �2�0�1�2���H���O�r�i�g�i�n�a�l�F�i�l�e�n�a�m�e���h�i�d�d�e�n�i�n�p�u�t�.�e�x�e���:� ��P�r�o�d�u�c�t�N�a�m�e�����H�i�d�d�e�n� �I�n�p�u�t�����:� ��P�r�o�d�u�c�t�V�e�r�s�i�o�n���1�,� �0�,� �0�,� �0�����D����V�a�r�F�i�l�e�I�n�f�o�����$����T�r�a�n�s�l�a�t�i�o�n����� °<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  22761. <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
  22762. <security>
  22763. <requestedPrivileges>
  22764. <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
  22765. </requestedPrivileges>
  22766. </security>
  22767. </trustInfo>
  22768. <dependency>
  22769. <dependentAssembly>
  22770. <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
  22771. </dependentAssembly>
  22772. </dependency>
  22773. </assembly>PAPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDING���@��00!0/080F0L0T0^0d0n0{0‰0—0¡0¨0®0³0¸0½0Â0È0Ð0ä0ÿ01#1-1@1J1O1T1v1{1„1‰1–1§1­1´1È1Í1Ó1Û1á1ç1ô1ú12"2*23292A2M2_2j2p2¹2¿2Ç2Î2Ó2Ù2ß2ç2í2ô2û2 333%303N3T3Z3`3f3l3s3z3�3ˆ3�3–3�3¥3­3µ3Á3Ê3Ï3Õ3ß3è3ó3ÿ34444%4;4B4‹4‘4š4¡4¬4²4Æ4Û4æ4þ45!5^5c5„5‰5¨5H6M6_6}6‘6—6�77 7*7w7|7Á7ä7ñ7ý78 88=8E8P8V8\8b8h8n8t8z8€8œ8â89��� ��$���Ü0è0ì01 1t1x12 2@2\2`2h2t2�0�� ���0��������������������������������������������������������������������������������������������������������������������������������������������������<?php
  22774. namespace Symfony\Component\Console;
  22775. use Symfony\Component\Console\Descriptor\TextDescriptor;
  22776. use Symfony\Component\Console\Descriptor\XmlDescriptor;
  22777. use Symfony\Component\Console\Helper\DebugFormatterHelper;
  22778. use Symfony\Component\Console\Helper\ProcessHelper;
  22779. use Symfony\Component\Console\Helper\QuestionHelper;
  22780. use Symfony\Component\Console\Input\InputInterface;
  22781. use Symfony\Component\Console\Input\ArgvInput;
  22782. use Symfony\Component\Console\Input\ArrayInput;
  22783. use Symfony\Component\Console\Input\InputDefinition;
  22784. use Symfony\Component\Console\Input\InputOption;
  22785. use Symfony\Component\Console\Input\InputArgument;
  22786. use Symfony\Component\Console\Input\InputAwareInterface;
  22787. use Symfony\Component\Console\Output\BufferedOutput;
  22788. use Symfony\Component\Console\Output\OutputInterface;
  22789. use Symfony\Component\Console\Output\ConsoleOutput;
  22790. use Symfony\Component\Console\Output\ConsoleOutputInterface;
  22791. use Symfony\Component\Console\Command\Command;
  22792. use Symfony\Component\Console\Command\HelpCommand;
  22793. use Symfony\Component\Console\Command\ListCommand;
  22794. use Symfony\Component\Console\Helper\HelperSet;
  22795. use Symfony\Component\Console\Helper\FormatterHelper;
  22796. use Symfony\Component\Console\Helper\DialogHelper;
  22797. use Symfony\Component\Console\Helper\ProgressHelper;
  22798. use Symfony\Component\Console\Helper\TableHelper;
  22799. use Symfony\Component\Console\Event\ConsoleCommandEvent;
  22800. use Symfony\Component\Console\Event\ConsoleExceptionEvent;
  22801. use Symfony\Component\Console\Event\ConsoleTerminateEvent;
  22802. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  22803. class Application
  22804. {
  22805. private $commands = array();
  22806. private $wantHelps = false;
  22807. private $runningCommand;
  22808. private $name;
  22809. private $version;
  22810. private $catchExceptions = true;
  22811. private $autoExit = true;
  22812. private $definition;
  22813. private $helperSet;
  22814. private $dispatcher;
  22815. private $terminalDimensions;
  22816. private $defaultCommand;
  22817. public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
  22818. {
  22819. $this->name = $name;
  22820. $this->version = $version;
  22821. $this->defaultCommand = 'list';
  22822. $this->helperSet = $this->getDefaultHelperSet();
  22823. $this->definition = $this->getDefaultInputDefinition();
  22824. foreach ($this->getDefaultCommands() as $command) {
  22825. $this->add($command);
  22826. }
  22827. }
  22828. public function setDispatcher(EventDispatcherInterface $dispatcher)
  22829. {
  22830. $this->dispatcher = $dispatcher;
  22831. }
  22832. public function run(InputInterface $input = null, OutputInterface $output = null)
  22833. {
  22834. if (null === $input) {
  22835. $input = new ArgvInput();
  22836. }
  22837. if (null === $output) {
  22838. $output = new ConsoleOutput();
  22839. }
  22840. $this->configureIO($input, $output);
  22841. try {
  22842. $exitCode = $this->doRun($input, $output);
  22843. } catch (\Exception $e) {
  22844. if (!$this->catchExceptions) {
  22845. throw $e;
  22846. }
  22847. if ($output instanceof ConsoleOutputInterface) {
  22848. $this->renderException($e, $output->getErrorOutput());
  22849. } else {
  22850. $this->renderException($e, $output);
  22851. }
  22852. $exitCode = $e->getCode();
  22853. if (is_numeric($exitCode)) {
  22854. $exitCode = (int) $exitCode;
  22855. if (0 === $exitCode) {
  22856. $exitCode = 1;
  22857. }
  22858. } else {
  22859. $exitCode = 1;
  22860. }
  22861. }
  22862. if ($this->autoExit) {
  22863. if ($exitCode > 255) {
  22864. $exitCode = 255;
  22865. }
  22866. exit($exitCode);
  22867. }
  22868. return $exitCode;
  22869. }
  22870. public function doRun(InputInterface $input, OutputInterface $output)
  22871. {
  22872. if (true === $input->hasParameterOption(array('--version', '-V'))) {
  22873. $output->writeln($this->getLongVersion());
  22874. return 0;
  22875. }
  22876. $name = $this->getCommandName($input);
  22877. if (true === $input->hasParameterOption(array('--help', '-h'))) {
  22878. if (!$name) {
  22879. $name = 'help';
  22880. $input = new ArrayInput(array('command' => 'help'));
  22881. } else {
  22882. $this->wantHelps = true;
  22883. }
  22884. }
  22885. if (!$name) {
  22886. $name = $this->defaultCommand;
  22887. $input = new ArrayInput(array('command' => $this->defaultCommand));
  22888. }
  22889. $command = $this->find($name);
  22890. $this->runningCommand = $command;
  22891. $exitCode = $this->doRunCommand($command, $input, $output);
  22892. $this->runningCommand = null;
  22893. return $exitCode;
  22894. }
  22895. public function setHelperSet(HelperSet $helperSet)
  22896. {
  22897. $this->helperSet = $helperSet;
  22898. }
  22899. public function getHelperSet()
  22900. {
  22901. return $this->helperSet;
  22902. }
  22903. public function setDefinition(InputDefinition $definition)
  22904. {
  22905. $this->definition = $definition;
  22906. }
  22907. public function getDefinition()
  22908. {
  22909. return $this->definition;
  22910. }
  22911. public function getHelp()
  22912. {
  22913. return $this->getLongVersion();
  22914. }
  22915. public function setCatchExceptions($boolean)
  22916. {
  22917. $this->catchExceptions = (bool) $boolean;
  22918. }
  22919. public function setAutoExit($boolean)
  22920. {
  22921. $this->autoExit = (bool) $boolean;
  22922. }
  22923. public function getName()
  22924. {
  22925. return $this->name;
  22926. }
  22927. public function setName($name)
  22928. {
  22929. $this->name = $name;
  22930. }
  22931. public function getVersion()
  22932. {
  22933. return $this->version;
  22934. }
  22935. public function setVersion($version)
  22936. {
  22937. $this->version = $version;
  22938. }
  22939. public function getLongVersion()
  22940. {
  22941. if ('UNKNOWN' !== $this->getName() && 'UNKNOWN' !== $this->getVersion()) {
  22942. return sprintf('<info>%s</info> version <comment>%s</comment>', $this->getName(), $this->getVersion());
  22943. }
  22944. return '<info>Console Tool</info>';
  22945. }
  22946. public function register($name)
  22947. {
  22948. return $this->add(new Command($name));
  22949. }
  22950. public function addCommands(array $commands)
  22951. {
  22952. foreach ($commands as $command) {
  22953. $this->add($command);
  22954. }
  22955. }
  22956. public function add(Command $command)
  22957. {
  22958. $command->setApplication($this);
  22959. if (!$command->isEnabled()) {
  22960. $command->setApplication(null);
  22961. return;
  22962. }
  22963. if (null === $command->getDefinition()) {
  22964. throw new \LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', get_class($command)));
  22965. }
  22966. $this->commands[$command->getName()] = $command;
  22967. foreach ($command->getAliases() as $alias) {
  22968. $this->commands[$alias] = $command;
  22969. }
  22970. return $command;
  22971. }
  22972. public function get($name)
  22973. {
  22974. if (!isset($this->commands[$name])) {
  22975. throw new \InvalidArgumentException(sprintf('The command "%s" does not exist.', $name));
  22976. }
  22977. $command = $this->commands[$name];
  22978. if ($this->wantHelps) {
  22979. $this->wantHelps = false;
  22980. $helpCommand = $this->get('help');
  22981. $helpCommand->setCommand($command);
  22982. return $helpCommand;
  22983. }
  22984. return $command;
  22985. }
  22986. public function has($name)
  22987. {
  22988. return isset($this->commands[$name]);
  22989. }
  22990. public function getNamespaces()
  22991. {
  22992. $namespaces = array();
  22993. foreach ($this->commands as $command) {
  22994. $namespaces = array_merge($namespaces, $this->extractAllNamespaces($command->getName()));
  22995. foreach ($command->getAliases() as $alias) {
  22996. $namespaces = array_merge($namespaces, $this->extractAllNamespaces($alias));
  22997. }
  22998. }
  22999. return array_values(array_unique(array_filter($namespaces)));
  23000. }
  23001. public function findNamespace($namespace)
  23002. {
  23003. $allNamespaces = $this->getNamespaces();
  23004. $expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $namespace);
  23005. $namespaces = preg_grep('{^'.$expr.'}', $allNamespaces);
  23006. if (empty($namespaces)) {
  23007. $message = sprintf('There are no commands defined in the "%s" namespace.', $namespace);
  23008. if ($alternatives = $this->findAlternatives($namespace, $allNamespaces)) {
  23009. if (1 == count($alternatives)) {
  23010. $message .= "\n\nDid you mean this?\n ";
  23011. } else {
  23012. $message .= "\n\nDid you mean one of these?\n ";
  23013. }
  23014. $message .= implode("\n ", $alternatives);
  23015. }
  23016. throw new \InvalidArgumentException($message);
  23017. }
  23018. $exact = in_array($namespace, $namespaces, true);
  23019. if (count($namespaces) > 1 && !$exact) {
  23020. throw new \InvalidArgumentException(sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this->getAbbreviationSuggestions(array_values($namespaces))));
  23021. }
  23022. return $exact ? $namespace : reset($namespaces);
  23023. }
  23024. public function find($name)
  23025. {
  23026. $allCommands = array_keys($this->commands);
  23027. $expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $name);
  23028. $commands = preg_grep('{^'.$expr.'}', $allCommands);
  23029. if (empty($commands) || count(preg_grep('{^'.$expr.'$}', $commands)) < 1) {
  23030. if (false !== $pos = strrpos($name, ':')) {
  23031. $this->findNamespace(substr($name, 0, $pos));
  23032. }
  23033. $message = sprintf('Command "%s" is not defined.', $name);
  23034. if ($alternatives = $this->findAlternatives($name, $allCommands)) {
  23035. if (1 == count($alternatives)) {
  23036. $message .= "\n\nDid you mean this?\n ";
  23037. } else {
  23038. $message .= "\n\nDid you mean one of these?\n ";
  23039. }
  23040. $message .= implode("\n ", $alternatives);
  23041. }
  23042. throw new \InvalidArgumentException($message);
  23043. }
  23044. if (count($commands) > 1) {
  23045. $commandList = $this->commands;
  23046. $commands = array_filter($commands, function ($nameOrAlias) use ($commandList, $commands) {
  23047. $commandName = $commandList[$nameOrAlias]->getName();
  23048. return $commandName === $nameOrAlias || !in_array($commandName, $commands);
  23049. });
  23050. }
  23051. $exact = in_array($name, $commands, true);
  23052. if (count($commands) > 1 && !$exact) {
  23053. $suggestions = $this->getAbbreviationSuggestions(array_values($commands));
  23054. throw new \InvalidArgumentException(sprintf('Command "%s" is ambiguous (%s).', $name, $suggestions));
  23055. }
  23056. return $this->get($exact ? $name : reset($commands));
  23057. }
  23058. public function all($namespace = null)
  23059. {
  23060. if (null === $namespace) {
  23061. return $this->commands;
  23062. }
  23063. $commands = array();
  23064. foreach ($this->commands as $name => $command) {
  23065. if ($namespace === $this->extractNamespace($name, substr_count($namespace, ':') + 1)) {
  23066. $commands[$name] = $command;
  23067. }
  23068. }
  23069. return $commands;
  23070. }
  23071. public static function getAbbreviations($names)
  23072. {
  23073. $abbrevs = array();
  23074. foreach ($names as $name) {
  23075. for ($len = strlen($name); $len > 0; --$len) {
  23076. $abbrev = substr($name, 0, $len);
  23077. $abbrevs[$abbrev][] = $name;
  23078. }
  23079. }
  23080. return $abbrevs;
  23081. }
  23082. public function asText($namespace = null, $raw = false)
  23083. {
  23084. $descriptor = new TextDescriptor();
  23085. $output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, !$raw);
  23086. $descriptor->describe($output, $this, array('namespace' => $namespace, 'raw_output' => true));
  23087. return $output->fetch();
  23088. }
  23089. public function asXml($namespace = null, $asDom = false)
  23090. {
  23091. $descriptor = new XmlDescriptor();
  23092. if ($asDom) {
  23093. return $descriptor->getApplicationDocument($this, $namespace);
  23094. }
  23095. $output = new BufferedOutput();
  23096. $descriptor->describe($output, $this, array('namespace' => $namespace));
  23097. return $output->fetch();
  23098. }
  23099. public function renderException($e, $output)
  23100. {
  23101. do {
  23102. $title = sprintf(' [%s] ', get_class($e));
  23103. $len = $this->stringWidth($title);
  23104. $width = $this->getTerminalWidth() ? $this->getTerminalWidth() - 1 : PHP_INT_MAX;
  23105. if (defined('HHVM_VERSION') && $width > 1 << 31) {
  23106. $width = 1 << 31;
  23107. }
  23108. $formatter = $output->getFormatter();
  23109. $lines = array();
  23110. foreach (preg_split('/\r?\n/', $e->getMessage()) as $line) {
  23111. foreach ($this->splitStringByWidth($line, $width - 4) as $line) {
  23112. $lineLength = $this->stringWidth(preg_replace('/\[[^m]*m/', '', $formatter->format($line))) + 4;
  23113. $lines[] = array($line, $lineLength);
  23114. $len = max($lineLength, $len);
  23115. }
  23116. }
  23117. $messages = array('', '');
  23118. $messages[] = $emptyLine = $formatter->format(sprintf('<error>%s</error>', str_repeat(' ', $len)));
  23119. $messages[] = $formatter->format(sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - $this->stringWidth($title)))));
  23120. foreach ($lines as $line) {
  23121. $messages[] = $formatter->format(sprintf('<error> %s %s</error>', $line[0], str_repeat(' ', $len - $line[1])));
  23122. }
  23123. $messages[] = $emptyLine;
  23124. $messages[] = '';
  23125. $messages[] = '';
  23126. $output->writeln($messages, OutputInterface::OUTPUT_RAW);
  23127. if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
  23128. $output->writeln('<comment>Exception trace:</comment>');
  23129. $trace = $e->getTrace();
  23130. array_unshift($trace, array(
  23131. 'function' => '',
  23132. 'file' => $e->getFile() !== null ? $e->getFile() : 'n/a',
  23133. 'line' => $e->getLine() !== null ? $e->getLine() : 'n/a',
  23134. 'args' => array(),
  23135. ));
  23136. for ($i = 0, $count = count($trace); $i < $count; ++$i) {
  23137. $class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
  23138. $type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
  23139. $function = $trace[$i]['function'];
  23140. $file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
  23141. $line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
  23142. $output->writeln(sprintf(' %s%s%s() at <info>%s:%s</info>', $class, $type, $function, $file, $line));
  23143. }
  23144. $output->writeln('');
  23145. $output->writeln('');
  23146. }
  23147. } while ($e = $e->getPrevious());
  23148. if (null !== $this->runningCommand) {
  23149. $output->writeln(sprintf('<info>%s</info>', sprintf($this->runningCommand->getSynopsis(), $this->getName())));
  23150. $output->writeln('');
  23151. $output->writeln('');
  23152. }
  23153. }
  23154. protected function getTerminalWidth()
  23155. {
  23156. $dimensions = $this->getTerminalDimensions();
  23157. return $dimensions[0];
  23158. }
  23159. protected function getTerminalHeight()
  23160. {
  23161. $dimensions = $this->getTerminalDimensions();
  23162. return $dimensions[1];
  23163. }
  23164. public function getTerminalDimensions()
  23165. {
  23166. if ($this->terminalDimensions) {
  23167. return $this->terminalDimensions;
  23168. }
  23169. if ('\\' === DIRECTORY_SEPARATOR) {
  23170. if (preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', trim(getenv('ANSICON')), $matches)) {
  23171. return array((int) $matches[1], (int) $matches[2]);
  23172. }
  23173. if (preg_match('/^(\d+)x(\d+)$/', $this->getConsoleMode(), $matches)) {
  23174. return array((int) $matches[1], (int) $matches[2]);
  23175. }
  23176. }
  23177. if ($sttyString = $this->getSttyColumns()) {
  23178. if (preg_match('/rows.(\d+);.columns.(\d+);/i', $sttyString, $matches)) {
  23179. return array((int) $matches[2], (int) $matches[1]);
  23180. }
  23181. if (preg_match('/;.(\d+).rows;.(\d+).columns/i', $sttyString, $matches)) {
  23182. return array((int) $matches[2], (int) $matches[1]);
  23183. }
  23184. }
  23185. return array(null, null);
  23186. }
  23187. public function setTerminalDimensions($width, $height)
  23188. {
  23189. $this->terminalDimensions = array($width, $height);
  23190. return $this;
  23191. }
  23192. protected function configureIO(InputInterface $input, OutputInterface $output)
  23193. {
  23194. if (true === $input->hasParameterOption(array('--ansi'))) {
  23195. $output->setDecorated(true);
  23196. } elseif (true === $input->hasParameterOption(array('--no-ansi'))) {
  23197. $output->setDecorated(false);
  23198. }
  23199. if (true === $input->hasParameterOption(array('--no-interaction', '-n'))) {
  23200. $input->setInteractive(false);
  23201. } elseif (function_exists('posix_isatty') && $this->getHelperSet()->has('question')) {
  23202. $inputStream = $this->getHelperSet()->get('question')->getInputStream();
  23203. if (!@posix_isatty($inputStream) && false === getenv('SHELL_INTERACTIVE')) {
  23204. $input->setInteractive(false);
  23205. }
  23206. }
  23207. if (true === $input->hasParameterOption(array('--quiet', '-q'))) {
  23208. $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
  23209. } else {
  23210. if ($input->hasParameterOption('-vvv') || $input->hasParameterOption('--verbose=3') || $input->getParameterOption('--verbose') === 3) {
  23211. $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG);
  23212. } elseif ($input->hasParameterOption('-vv') || $input->hasParameterOption('--verbose=2') || $input->getParameterOption('--verbose') === 2) {
  23213. $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE);
  23214. } elseif ($input->hasParameterOption('-v') || $input->hasParameterOption('--verbose=1') || $input->hasParameterOption('--verbose') || $input->getParameterOption('--verbose')) {
  23215. $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
  23216. }
  23217. }
  23218. }
  23219. protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
  23220. {
  23221. foreach ($command->getHelperSet() as $helper) {
  23222. if ($helper instanceof InputAwareInterface) {
  23223. $helper->setInput($input);
  23224. }
  23225. }
  23226. if (null === $this->dispatcher) {
  23227. return $command->run($input, $output);
  23228. }
  23229. $event = new ConsoleCommandEvent($command, $input, $output);
  23230. $this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
  23231. if ($event->commandShouldRun()) {
  23232. try {
  23233. $exitCode = $command->run($input, $output);
  23234. } catch (\Exception $e) {
  23235. $event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode());
  23236. $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
  23237. $event = new ConsoleExceptionEvent($command, $input, $output, $e, $event->getExitCode());
  23238. $this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);
  23239. throw $event->getException();
  23240. }
  23241. } else {
  23242. $exitCode = ConsoleCommandEvent::RETURN_CODE_DISABLED;
  23243. }
  23244. $event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
  23245. $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
  23246. return $event->getExitCode();
  23247. }
  23248. protected function getCommandName(InputInterface $input)
  23249. {
  23250. return $input->getFirstArgument();
  23251. }
  23252. protected function getDefaultInputDefinition()
  23253. {
  23254. return new InputDefinition(array(
  23255. new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
  23256. new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message'),
  23257. new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message'),
  23258. new InputOption('--verbose', '-v|vv|vvv', InputOption::VALUE_NONE, 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug'),
  23259. new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this application version'),
  23260. new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output'),
  23261. new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output'),
  23262. new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question'),
  23263. ));
  23264. }
  23265. protected function getDefaultCommands()
  23266. {
  23267. return array(new HelpCommand(), new ListCommand());
  23268. }
  23269. protected function getDefaultHelperSet()
  23270. {
  23271. return new HelperSet(array(
  23272. new FormatterHelper(),
  23273. new DialogHelper(),
  23274. new ProgressHelper(),
  23275. new TableHelper(),
  23276. new DebugFormatterHelper(),
  23277. new ProcessHelper(),
  23278. new QuestionHelper(),
  23279. ));
  23280. }
  23281. private function getSttyColumns()
  23282. {
  23283. if (!function_exists('proc_open')) {
  23284. return;
  23285. }
  23286. $descriptorspec = array(1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
  23287. $process = proc_open('stty -a | grep columns', $descriptorspec, $pipes, null, null, array('suppress_errors' => true));
  23288. if (is_resource($process)) {
  23289. $info = stream_get_contents($pipes[1]);
  23290. fclose($pipes[1]);
  23291. fclose($pipes[2]);
  23292. proc_close($process);
  23293. return $info;
  23294. }
  23295. }
  23296. private function getConsoleMode()
  23297. {
  23298. if (!function_exists('proc_open')) {
  23299. return;
  23300. }
  23301. $descriptorspec = array(1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
  23302. $process = proc_open('mode CON', $descriptorspec, $pipes, null, null, array('suppress_errors' => true));
  23303. if (is_resource($process)) {
  23304. $info = stream_get_contents($pipes[1]);
  23305. fclose($pipes[1]);
  23306. fclose($pipes[2]);
  23307. proc_close($process);
  23308. if (preg_match('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) {
  23309. return $matches[2].'x'.$matches[1];
  23310. }
  23311. }
  23312. }
  23313. private function getAbbreviationSuggestions($abbrevs)
  23314. {
  23315. return sprintf('%s, %s%s', $abbrevs[0], $abbrevs[1], count($abbrevs) > 2 ? sprintf(' and %d more', count($abbrevs) - 2) : '');
  23316. }
  23317. public function extractNamespace($name, $limit = null)
  23318. {
  23319. $parts = explode(':', $name);
  23320. array_pop($parts);
  23321. return implode(':', null === $limit ? $parts : array_slice($parts, 0, $limit));
  23322. }
  23323. private function findAlternatives($name, $collection)
  23324. {
  23325. $threshold = 1e3;
  23326. $alternatives = array();
  23327. $collectionParts = array();
  23328. foreach ($collection as $item) {
  23329. $collectionParts[$item] = explode(':', $item);
  23330. }
  23331. foreach (explode(':', $name) as $i => $subname) {
  23332. foreach ($collectionParts as $collectionName => $parts) {
  23333. $exists = isset($alternatives[$collectionName]);
  23334. if (!isset($parts[$i]) && $exists) {
  23335. $alternatives[$collectionName] += $threshold;
  23336. continue;
  23337. } elseif (!isset($parts[$i])) {
  23338. continue;
  23339. }
  23340. $lev = levenshtein($subname, $parts[$i]);
  23341. if ($lev <= strlen($subname) / 3 || '' !== $subname && false !== strpos($parts[$i], $subname)) {
  23342. $alternatives[$collectionName] = $exists ? $alternatives[$collectionName] + $lev : $lev;
  23343. } elseif ($exists) {
  23344. $alternatives[$collectionName] += $threshold;
  23345. }
  23346. }
  23347. }
  23348. foreach ($collection as $item) {
  23349. $lev = levenshtein($name, $item);
  23350. if ($lev <= strlen($name) / 3 || false !== strpos($item, $name)) {
  23351. $alternatives[$item] = isset($alternatives[$item]) ? $alternatives[$item] - $lev : $lev;
  23352. }
  23353. }
  23354. $alternatives = array_filter($alternatives, function ($lev) use ($threshold) { return $lev < 2 * $threshold; });
  23355. asort($alternatives);
  23356. return array_keys($alternatives);
  23357. }
  23358. public function setDefaultCommand($commandName)
  23359. {
  23360. $this->defaultCommand = $commandName;
  23361. }
  23362. private function stringWidth($string)
  23363. {
  23364. if (!function_exists('mb_strwidth')) {
  23365. return strlen($string);
  23366. }
  23367. if (false === $encoding = mb_detect_encoding($string)) {
  23368. return strlen($string);
  23369. }
  23370. return mb_strwidth($string, $encoding);
  23371. }
  23372. private function splitStringByWidth($string, $width)
  23373. {
  23374. if (!function_exists('mb_strwidth')) {
  23375. return str_split($string, $width);
  23376. }
  23377. if (false === $encoding = mb_detect_encoding($string)) {
  23378. return str_split($string, $width);
  23379. }
  23380. $utf8String = mb_convert_encoding($string, 'utf8', $encoding);
  23381. $lines = array();
  23382. $line = '';
  23383. foreach (preg_split('//u', $utf8String) as $char) {
  23384. if (mb_strwidth($line.$char, 'utf8') <= $width) {
  23385. $line .= $char;
  23386. continue;
  23387. }
  23388. $lines[] = str_pad($line, $width);
  23389. $line = $char;
  23390. }
  23391. if ('' !== $line) {
  23392. $lines[] = count($lines) ? str_pad($line, $width) : $line;
  23393. }
  23394. mb_convert_variables($encoding, 'utf8', $lines);
  23395. return $lines;
  23396. }
  23397. private function extractAllNamespaces($name)
  23398. {
  23399. $parts = explode(':', $name, -1);
  23400. $namespaces = array();
  23401. foreach ($parts as $part) {
  23402. if (count($namespaces)) {
  23403. $namespaces[] = end($namespaces).':'.$part;
  23404. } else {
  23405. $namespaces[] = $part;
  23406. }
  23407. }
  23408. return $namespaces;
  23409. }
  23410. }
  23411. <?php
  23412. namespace Symfony\Component\Console\Command;
  23413. use Symfony\Component\Console\Descriptor\TextDescriptor;
  23414. use Symfony\Component\Console\Descriptor\XmlDescriptor;
  23415. use Symfony\Component\Console\Input\InputDefinition;
  23416. use Symfony\Component\Console\Input\InputOption;
  23417. use Symfony\Component\Console\Input\InputArgument;
  23418. use Symfony\Component\Console\Input\InputInterface;
  23419. use Symfony\Component\Console\Output\BufferedOutput;
  23420. use Symfony\Component\Console\Output\OutputInterface;
  23421. use Symfony\Component\Console\Application;
  23422. use Symfony\Component\Console\Helper\HelperSet;
  23423. class Command
  23424. {
  23425. private $application;
  23426. private $name;
  23427. private $processTitle;
  23428. private $aliases = array();
  23429. private $definition;
  23430. private $help;
  23431. private $description;
  23432. private $ignoreValidationErrors = false;
  23433. private $applicationDefinitionMerged = false;
  23434. private $applicationDefinitionMergedWithArgs = false;
  23435. private $code;
  23436. private $synopsis;
  23437. private $helperSet;
  23438. public function __construct($name = null)
  23439. {
  23440. $this->definition = new InputDefinition();
  23441. if (null !== $name) {
  23442. $this->setName($name);
  23443. }
  23444. $this->configure();
  23445. if (!$this->name) {
  23446. throw new \LogicException(sprintf('The command defined in "%s" cannot have an empty name.', get_class($this)));
  23447. }
  23448. }
  23449. public function ignoreValidationErrors()
  23450. {
  23451. $this->ignoreValidationErrors = true;
  23452. }
  23453. public function setApplication(Application $application = null)
  23454. {
  23455. $this->application = $application;
  23456. if ($application) {
  23457. $this->setHelperSet($application->getHelperSet());
  23458. } else {
  23459. $this->helperSet = null;
  23460. }
  23461. }
  23462. public function setHelperSet(HelperSet $helperSet)
  23463. {
  23464. $this->helperSet = $helperSet;
  23465. }
  23466. public function getHelperSet()
  23467. {
  23468. return $this->helperSet;
  23469. }
  23470. public function getApplication()
  23471. {
  23472. return $this->application;
  23473. }
  23474. public function isEnabled()
  23475. {
  23476. return true;
  23477. }
  23478. protected function configure()
  23479. {
  23480. }
  23481. protected function execute(InputInterface $input, OutputInterface $output)
  23482. {
  23483. throw new \LogicException('You must override the execute() method in the concrete command class.');
  23484. }
  23485. protected function interact(InputInterface $input, OutputInterface $output)
  23486. {
  23487. }
  23488. protected function initialize(InputInterface $input, OutputInterface $output)
  23489. {
  23490. }
  23491. public function run(InputInterface $input, OutputInterface $output)
  23492. {
  23493. $this->getSynopsis();
  23494. $this->mergeApplicationDefinition();
  23495. try {
  23496. $input->bind($this->definition);
  23497. } catch (\Exception $e) {
  23498. if (!$this->ignoreValidationErrors) {
  23499. throw $e;
  23500. }
  23501. }
  23502. $this->initialize($input, $output);
  23503. if (null !== $this->processTitle) {
  23504. if (function_exists('cli_set_process_title')) {
  23505. cli_set_process_title($this->processTitle);
  23506. } elseif (function_exists('setproctitle')) {
  23507. setproctitle($this->processTitle);
  23508. } elseif (OutputInterface::VERBOSITY_VERY_VERBOSE === $output->getVerbosity()) {
  23509. $output->writeln('<comment>Install the proctitle PECL to be able to change the process title.</comment>');
  23510. }
  23511. }
  23512. if ($input->isInteractive()) {
  23513. $this->interact($input, $output);
  23514. }
  23515. $input->validate();
  23516. if ($this->code) {
  23517. $statusCode = call_user_func($this->code, $input, $output);
  23518. } else {
  23519. $statusCode = $this->execute($input, $output);
  23520. }
  23521. return is_numeric($statusCode) ? (int) $statusCode : 0;
  23522. }
  23523. public function setCode($code)
  23524. {
  23525. if (!is_callable($code)) {
  23526. throw new \InvalidArgumentException('Invalid callable provided to Command::setCode.');
  23527. }
  23528. $this->code = $code;
  23529. return $this;
  23530. }
  23531. public function mergeApplicationDefinition($mergeArgs = true)
  23532. {
  23533. if (null === $this->application || (true === $this->applicationDefinitionMerged && ($this->applicationDefinitionMergedWithArgs || !$mergeArgs))) {
  23534. return;
  23535. }
  23536. if ($mergeArgs) {
  23537. $currentArguments = $this->definition->getArguments();
  23538. $this->definition->setArguments($this->application->getDefinition()->getArguments());
  23539. $this->definition->addArguments($currentArguments);
  23540. }
  23541. $this->definition->addOptions($this->application->getDefinition()->getOptions());
  23542. $this->applicationDefinitionMerged = true;
  23543. if ($mergeArgs) {
  23544. $this->applicationDefinitionMergedWithArgs = true;
  23545. }
  23546. }
  23547. public function setDefinition($definition)
  23548. {
  23549. if ($definition instanceof InputDefinition) {
  23550. $this->definition = $definition;
  23551. } else {
  23552. $this->definition->setDefinition($definition);
  23553. }
  23554. $this->applicationDefinitionMerged = false;
  23555. return $this;
  23556. }
  23557. public function getDefinition()
  23558. {
  23559. return $this->definition;
  23560. }
  23561. public function getNativeDefinition()
  23562. {
  23563. return $this->getDefinition();
  23564. }
  23565. public function addArgument($name, $mode = null, $description = '', $default = null)
  23566. {
  23567. $this->definition->addArgument(new InputArgument($name, $mode, $description, $default));
  23568. return $this;
  23569. }
  23570. public function addOption($name, $shortcut = null, $mode = null, $description = '', $default = null)
  23571. {
  23572. $this->definition->addOption(new InputOption($name, $shortcut, $mode, $description, $default));
  23573. return $this;
  23574. }
  23575. public function setName($name)
  23576. {
  23577. $this->validateName($name);
  23578. $this->name = $name;
  23579. return $this;
  23580. }
  23581. public function setProcessTitle($title)
  23582. {
  23583. $this->processTitle = $title;
  23584. return $this;
  23585. }
  23586. public function getName()
  23587. {
  23588. return $this->name;
  23589. }
  23590. public function setDescription($description)
  23591. {
  23592. $this->description = $description;
  23593. return $this;
  23594. }
  23595. public function getDescription()
  23596. {
  23597. return $this->description;
  23598. }
  23599. public function setHelp($help)
  23600. {
  23601. $this->help = $help;
  23602. return $this;
  23603. }
  23604. public function getHelp()
  23605. {
  23606. return $this->help;
  23607. }
  23608. public function getProcessedHelp()
  23609. {
  23610. $name = $this->name;
  23611. $placeholders = array(
  23612. '%command.name%',
  23613. '%command.full_name%',
  23614. );
  23615. $replacements = array(
  23616. $name,
  23617. $_SERVER['PHP_SELF'].' '.$name,
  23618. );
  23619. return str_replace($placeholders, $replacements, $this->getHelp());
  23620. }
  23621. public function setAliases($aliases)
  23622. {
  23623. if (!is_array($aliases) && !$aliases instanceof \Traversable) {
  23624. throw new \InvalidArgumentException('$aliases must be an array or an instance of \Traversable');
  23625. }
  23626. foreach ($aliases as $alias) {
  23627. $this->validateName($alias);
  23628. }
  23629. $this->aliases = $aliases;
  23630. return $this;
  23631. }
  23632. public function getAliases()
  23633. {
  23634. return $this->aliases;
  23635. }
  23636. public function getSynopsis()
  23637. {
  23638. if (null === $this->synopsis) {
  23639. $this->synopsis = trim(sprintf('%s %s', $this->name, $this->definition->getSynopsis()));
  23640. }
  23641. return $this->synopsis;
  23642. }
  23643. public function getHelper($name)
  23644. {
  23645. return $this->helperSet->get($name);
  23646. }
  23647. public function asText()
  23648. {
  23649. $descriptor = new TextDescriptor();
  23650. $output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true);
  23651. $descriptor->describe($output, $this, array('raw_output' => true));
  23652. return $output->fetch();
  23653. }
  23654. public function asXml($asDom = false)
  23655. {
  23656. $descriptor = new XmlDescriptor();
  23657. if ($asDom) {
  23658. return $descriptor->getCommandDocument($this);
  23659. }
  23660. $output = new BufferedOutput();
  23661. $descriptor->describe($output, $this);
  23662. return $output->fetch();
  23663. }
  23664. private function validateName($name)
  23665. {
  23666. if (!preg_match('/^[^\:]++(\:[^\:]++)*$/', $name)) {
  23667. throw new \InvalidArgumentException(sprintf('Command name "%s" is invalid.', $name));
  23668. }
  23669. }
  23670. }
  23671. <?php
  23672. namespace Symfony\Component\Console\Command;
  23673. use Symfony\Component\Console\Helper\DescriptorHelper;
  23674. use Symfony\Component\Console\Input\InputArgument;
  23675. use Symfony\Component\Console\Input\InputOption;
  23676. use Symfony\Component\Console\Input\InputInterface;
  23677. use Symfony\Component\Console\Output\OutputInterface;
  23678. class HelpCommand extends Command
  23679. {
  23680. private $command;
  23681. protected function configure()
  23682. {
  23683. $this->ignoreValidationErrors();
  23684. $this
  23685. ->setName('help')
  23686. ->setDefinition(array(
  23687. new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'),
  23688. new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
  23689. new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output help in other formats', 'txt'),
  23690. new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help'),
  23691. ))
  23692. ->setDescription('Displays help for a command')
  23693. ->setHelp(<<<EOF
  23694. The <info>%command.name%</info> command displays help for a given command:
  23695. <info>php %command.full_name% list</info>
  23696. You can also output the help in other formats by using the <comment>--format</comment> option:
  23697. <info>php %command.full_name% --format=xml list</info>
  23698. To display the list of available commands, please use the <info>list</info> command.
  23699. EOF
  23700. )
  23701. ;
  23702. }
  23703. public function setCommand(Command $command)
  23704. {
  23705. $this->command = $command;
  23706. }
  23707. protected function execute(InputInterface $input, OutputInterface $output)
  23708. {
  23709. if (null === $this->command) {
  23710. $this->command = $this->getApplication()->find($input->getArgument('command_name'));
  23711. }
  23712. if ($input->getOption('xml')) {
  23713. $input->setOption('format', 'xml');
  23714. }
  23715. $helper = new DescriptorHelper();
  23716. $helper->describe($output, $this->command, array(
  23717. 'format' => $input->getOption('format'),
  23718. 'raw_text' => $input->getOption('raw'),
  23719. ));
  23720. $this->command = null;
  23721. }
  23722. }
  23723. <?php
  23724. namespace Symfony\Component\Console\Command;
  23725. use Symfony\Component\Console\Helper\DescriptorHelper;
  23726. use Symfony\Component\Console\Input\InputArgument;
  23727. use Symfony\Component\Console\Input\InputOption;
  23728. use Symfony\Component\Console\Input\InputInterface;
  23729. use Symfony\Component\Console\Output\OutputInterface;
  23730. use Symfony\Component\Console\Input\InputDefinition;
  23731. class ListCommand extends Command
  23732. {
  23733. protected function configure()
  23734. {
  23735. $this
  23736. ->setName('list')
  23737. ->setDefinition($this->createDefinition())
  23738. ->setDescription('Lists commands')
  23739. ->setHelp(<<<EOF
  23740. The <info>%command.name%</info> command lists all commands:
  23741. <info>php %command.full_name%</info>
  23742. You can also display the commands for a specific namespace:
  23743. <info>php %command.full_name% test</info>
  23744. You can also output the information in other formats by using the <comment>--format</comment> option:
  23745. <info>php %command.full_name% --format=xml</info>
  23746. It's also possible to get raw list of commands (useful for embedding command runner):
  23747. <info>php %command.full_name% --raw</info>
  23748. EOF
  23749. )
  23750. ;
  23751. }
  23752. public function getNativeDefinition()
  23753. {
  23754. return $this->createDefinition();
  23755. }
  23756. protected function execute(InputInterface $input, OutputInterface $output)
  23757. {
  23758. if ($input->getOption('xml')) {
  23759. $input->setOption('format', 'xml');
  23760. }
  23761. $helper = new DescriptorHelper();
  23762. $helper->describe($output, $this->getApplication(), array(
  23763. 'format' => $input->getOption('format'),
  23764. 'raw_text' => $input->getOption('raw'),
  23765. 'namespace' => $input->getArgument('namespace'),
  23766. ));
  23767. }
  23768. private function createDefinition()
  23769. {
  23770. return new InputDefinition(array(
  23771. new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
  23772. new InputOption('xml', null, InputOption::VALUE_NONE, 'To output list as XML'),
  23773. new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'),
  23774. new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output list in other formats', 'txt'),
  23775. ));
  23776. }
  23777. }
  23778. <?php
  23779. namespace Symfony\Component\Console;
  23780. final class ConsoleEvents
  23781. {
  23782. const COMMAND = 'console.command';
  23783. const TERMINATE = 'console.terminate';
  23784. const EXCEPTION = 'console.exception';
  23785. }
  23786. <?php
  23787. namespace Symfony\Component\Console\Descriptor;
  23788. use Symfony\Component\Console\Application;
  23789. use Symfony\Component\Console\Command\Command;
  23790. class ApplicationDescription
  23791. {
  23792. const GLOBAL_NAMESPACE = '_global';
  23793. private $application;
  23794. private $namespace;
  23795. private $namespaces;
  23796. private $commands;
  23797. private $aliases;
  23798. public function __construct(Application $application, $namespace = null)
  23799. {
  23800. $this->application = $application;
  23801. $this->namespace = $namespace;
  23802. }
  23803. public function getNamespaces()
  23804. {
  23805. if (null === $this->namespaces) {
  23806. $this->inspectApplication();
  23807. }
  23808. return $this->namespaces;
  23809. }
  23810. public function getCommands()
  23811. {
  23812. if (null === $this->commands) {
  23813. $this->inspectApplication();
  23814. }
  23815. return $this->commands;
  23816. }
  23817. public function getCommand($name)
  23818. {
  23819. if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) {
  23820. throw new \InvalidArgumentException(sprintf('Command %s does not exist.', $name));
  23821. }
  23822. return isset($this->commands[$name]) ? $this->commands[$name] : $this->aliases[$name];
  23823. }
  23824. private function inspectApplication()
  23825. {
  23826. $this->commands = array();
  23827. $this->namespaces = array();
  23828. $all = $this->application->all($this->namespace ? $this->application->findNamespace($this->namespace) : null);
  23829. foreach ($this->sortCommands($all) as $namespace => $commands) {
  23830. $names = array();
  23831. foreach ($commands as $name => $command) {
  23832. if (!$command->getName()) {
  23833. continue;
  23834. }
  23835. if ($command->getName() === $name) {
  23836. $this->commands[$name] = $command;
  23837. } else {
  23838. $this->aliases[$name] = $command;
  23839. }
  23840. $names[] = $name;
  23841. }
  23842. $this->namespaces[$namespace] = array('id' => $namespace, 'commands' => $names);
  23843. }
  23844. }
  23845. private function sortCommands(array $commands)
  23846. {
  23847. $namespacedCommands = array();
  23848. foreach ($commands as $name => $command) {
  23849. $key = $this->application->extractNamespace($name, 1);
  23850. if (!$key) {
  23851. $key = '_global';
  23852. }
  23853. $namespacedCommands[$key][$name] = $command;
  23854. }
  23855. ksort($namespacedCommands);
  23856. foreach ($namespacedCommands as &$commandsSet) {
  23857. ksort($commandsSet);
  23858. }
  23859. unset($commandsSet);
  23860. return $namespacedCommands;
  23861. }
  23862. }
  23863. <?php
  23864. namespace Symfony\Component\Console\Descriptor;
  23865. use Symfony\Component\Console\Application;
  23866. use Symfony\Component\Console\Command\Command;
  23867. use Symfony\Component\Console\Input\InputArgument;
  23868. use Symfony\Component\Console\Input\InputDefinition;
  23869. use Symfony\Component\Console\Input\InputOption;
  23870. use Symfony\Component\Console\Output\OutputInterface;
  23871. abstract class Descriptor implements DescriptorInterface
  23872. {
  23873. private $output;
  23874. public function describe(OutputInterface $output, $object, array $options = array())
  23875. {
  23876. $this->output = $output;
  23877. switch (true) {
  23878. case $object instanceof InputArgument:
  23879. $this->describeInputArgument($object, $options);
  23880. break;
  23881. case $object instanceof InputOption:
  23882. $this->describeInputOption($object, $options);
  23883. break;
  23884. case $object instanceof InputDefinition:
  23885. $this->describeInputDefinition($object, $options);
  23886. break;
  23887. case $object instanceof Command:
  23888. $this->describeCommand($object, $options);
  23889. break;
  23890. case $object instanceof Application:
  23891. $this->describeApplication($object, $options);
  23892. break;
  23893. default:
  23894. throw new \InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_class($object)));
  23895. }
  23896. }
  23897. protected function write($content, $decorated = false)
  23898. {
  23899. $this->output->write($content, false, $decorated ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW);
  23900. }
  23901. abstract protected function describeInputArgument(InputArgument $argument, array $options = array());
  23902. abstract protected function describeInputOption(InputOption $option, array $options = array());
  23903. abstract protected function describeInputDefinition(InputDefinition $definition, array $options = array());
  23904. abstract protected function describeCommand(Command $command, array $options = array());
  23905. abstract protected function describeApplication(Application $application, array $options = array());
  23906. }
  23907. <?php
  23908. namespace Symfony\Component\Console\Descriptor;
  23909. use Symfony\Component\Console\Output\OutputInterface;
  23910. interface DescriptorInterface
  23911. {
  23912. public function describe(OutputInterface $output, $object, array $options = array());
  23913. }
  23914. <?php
  23915. namespace Symfony\Component\Console\Descriptor;
  23916. use Symfony\Component\Console\Application;
  23917. use Symfony\Component\Console\Command\Command;
  23918. use Symfony\Component\Console\Input\InputArgument;
  23919. use Symfony\Component\Console\Input\InputDefinition;
  23920. use Symfony\Component\Console\Input\InputOption;
  23921. class JsonDescriptor extends Descriptor
  23922. {
  23923. protected function describeInputArgument(InputArgument $argument, array $options = array())
  23924. {
  23925. $this->writeData($this->getInputArgumentData($argument), $options);
  23926. }
  23927. protected function describeInputOption(InputOption $option, array $options = array())
  23928. {
  23929. $this->writeData($this->getInputOptionData($option), $options);
  23930. }
  23931. protected function describeInputDefinition(InputDefinition $definition, array $options = array())
  23932. {
  23933. $this->writeData($this->getInputDefinitionData($definition), $options);
  23934. }
  23935. protected function describeCommand(Command $command, array $options = array())
  23936. {
  23937. $this->writeData($this->getCommandData($command), $options);
  23938. }
  23939. protected function describeApplication(Application $application, array $options = array())
  23940. {
  23941. $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
  23942. $description = new ApplicationDescription($application, $describedNamespace);
  23943. $commands = array();
  23944. foreach ($description->getCommands() as $command) {
  23945. $commands[] = $this->getCommandData($command);
  23946. }
  23947. $data = $describedNamespace
  23948. ? array('commands' => $commands, 'namespace' => $describedNamespace)
  23949. : array('commands' => $commands, 'namespaces' => array_values($description->getNamespaces()));
  23950. $this->writeData($data, $options);
  23951. }
  23952. private function writeData(array $data, array $options)
  23953. {
  23954. $this->write(json_encode($data, isset($options['json_encoding']) ? $options['json_encoding'] : 0));
  23955. }
  23956. private function getInputArgumentData(InputArgument $argument)
  23957. {
  23958. return array(
  23959. 'name' => $argument->getName(),
  23960. 'is_required' => $argument->isRequired(),
  23961. 'is_array' => $argument->isArray(),
  23962. 'description' => $argument->getDescription(),
  23963. 'default' => $argument->getDefault(),
  23964. );
  23965. }
  23966. private function getInputOptionData(InputOption $option)
  23967. {
  23968. return array(
  23969. 'name' => '--'.$option->getName(),
  23970. 'shortcut' => $option->getShortcut() ? '-'.implode('|-', explode('|', $option->getShortcut())) : '',
  23971. 'accept_value' => $option->acceptValue(),
  23972. 'is_value_required' => $option->isValueRequired(),
  23973. 'is_multiple' => $option->isArray(),
  23974. 'description' => $option->getDescription(),
  23975. 'default' => $option->getDefault(),
  23976. );
  23977. }
  23978. private function getInputDefinitionData(InputDefinition $definition)
  23979. {
  23980. $inputArguments = array();
  23981. foreach ($definition->getArguments() as $name => $argument) {
  23982. $inputArguments[$name] = $this->getInputArgumentData($argument);
  23983. }
  23984. $inputOptions = array();
  23985. foreach ($definition->getOptions() as $name => $option) {
  23986. $inputOptions[$name] = $this->getInputOptionData($option);
  23987. }
  23988. return array('arguments' => $inputArguments, 'options' => $inputOptions);
  23989. }
  23990. private function getCommandData(Command $command)
  23991. {
  23992. $command->getSynopsis();
  23993. $command->mergeApplicationDefinition(false);
  23994. return array(
  23995. 'name' => $command->getName(),
  23996. 'usage' => $command->getSynopsis(),
  23997. 'description' => $command->getDescription(),
  23998. 'help' => $command->getProcessedHelp(),
  23999. 'aliases' => $command->getAliases(),
  24000. 'definition' => $this->getInputDefinitionData($command->getNativeDefinition()),
  24001. );
  24002. }
  24003. }
  24004. <?php
  24005. namespace Symfony\Component\Console\Descriptor;
  24006. use Symfony\Component\Console\Application;
  24007. use Symfony\Component\Console\Command\Command;
  24008. use Symfony\Component\Console\Input\InputArgument;
  24009. use Symfony\Component\Console\Input\InputDefinition;
  24010. use Symfony\Component\Console\Input\InputOption;
  24011. class MarkdownDescriptor extends Descriptor
  24012. {
  24013. protected function describeInputArgument(InputArgument $argument, array $options = array())
  24014. {
  24015. $this->write(
  24016. '**'.$argument->getName().':**'."\n\n"
  24017. .'* Name: '.($argument->getName() ?: '<none>')."\n"
  24018. .'* Is required: '.($argument->isRequired() ? 'yes' : 'no')."\n"
  24019. .'* Is array: '.($argument->isArray() ? 'yes' : 'no')."\n"
  24020. .'* Description: '.($argument->getDescription() ?: '<none>')."\n"
  24021. .'* Default: `'.str_replace("\n", '', var_export($argument->getDefault(), true)).'`'
  24022. );
  24023. }
  24024. protected function describeInputOption(InputOption $option, array $options = array())
  24025. {
  24026. $this->write(
  24027. '**'.$option->getName().':**'."\n\n"
  24028. .'* Name: `--'.$option->getName().'`'."\n"
  24029. .'* Shortcut: '.($option->getShortcut() ? '`-'.implode('|-', explode('|', $option->getShortcut())).'`' : '<none>')."\n"
  24030. .'* Accept value: '.($option->acceptValue() ? 'yes' : 'no')."\n"
  24031. .'* Is value required: '.($option->isValueRequired() ? 'yes' : 'no')."\n"
  24032. .'* Is multiple: '.($option->isArray() ? 'yes' : 'no')."\n"
  24033. .'* Description: '.($option->getDescription() ?: '<none>')."\n"
  24034. .'* Default: `'.str_replace("\n", '', var_export($option->getDefault(), true)).'`'
  24035. );
  24036. }
  24037. protected function describeInputDefinition(InputDefinition $definition, array $options = array())
  24038. {
  24039. if ($showArguments = count($definition->getArguments()) > 0) {
  24040. $this->write('### Arguments:');
  24041. foreach ($definition->getArguments() as $argument) {
  24042. $this->write("\n\n");
  24043. $this->write($this->describeInputArgument($argument));
  24044. }
  24045. }
  24046. if (count($definition->getOptions()) > 0) {
  24047. if ($showArguments) {
  24048. $this->write("\n\n");
  24049. }
  24050. $this->write('### Options:');
  24051. foreach ($definition->getOptions() as $option) {
  24052. $this->write("\n\n");
  24053. $this->write($this->describeInputOption($option));
  24054. }
  24055. }
  24056. }
  24057. protected function describeCommand(Command $command, array $options = array())
  24058. {
  24059. $command->getSynopsis();
  24060. $command->mergeApplicationDefinition(false);
  24061. $this->write(
  24062. $command->getName()."\n"
  24063. .str_repeat('-', strlen($command->getName()))."\n\n"
  24064. .'* Description: '.($command->getDescription() ?: '<none>')."\n"
  24065. .'* Usage: `'.$command->getSynopsis().'`'."\n"
  24066. .'* Aliases: '.(count($command->getAliases()) ? '`'.implode('`, `', $command->getAliases()).'`' : '<none>')
  24067. );
  24068. if ($help = $command->getProcessedHelp()) {
  24069. $this->write("\n\n");
  24070. $this->write($help);
  24071. }
  24072. if ($command->getNativeDefinition()) {
  24073. $this->write("\n\n");
  24074. $this->describeInputDefinition($command->getNativeDefinition());
  24075. }
  24076. }
  24077. protected function describeApplication(Application $application, array $options = array())
  24078. {
  24079. $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
  24080. $description = new ApplicationDescription($application, $describedNamespace);
  24081. $this->write($application->getName()."\n".str_repeat('=', strlen($application->getName())));
  24082. foreach ($description->getNamespaces() as $namespace) {
  24083. if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
  24084. $this->write("\n\n");
  24085. $this->write('**'.$namespace['id'].':**');
  24086. }
  24087. $this->write("\n\n");
  24088. $this->write(implode("\n", array_map(function ($commandName) {
  24089. return '* '.$commandName;
  24090. }, $namespace['commands'])));
  24091. }
  24092. foreach ($description->getCommands() as $command) {
  24093. $this->write("\n\n");
  24094. $this->write($this->describeCommand($command));
  24095. }
  24096. }
  24097. }
  24098. <?php
  24099. namespace Symfony\Component\Console\Descriptor;
  24100. use Symfony\Component\Console\Application;
  24101. use Symfony\Component\Console\Command\Command;
  24102. use Symfony\Component\Console\Input\InputArgument;
  24103. use Symfony\Component\Console\Input\InputDefinition;
  24104. use Symfony\Component\Console\Input\InputOption;
  24105. class TextDescriptor extends Descriptor
  24106. {
  24107. protected function describeInputArgument(InputArgument $argument, array $options = array())
  24108. {
  24109. if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) {
  24110. $default = sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($argument->getDefault()));
  24111. } else {
  24112. $default = '';
  24113. }
  24114. $nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($argument->getName());
  24115. $this->writeText(sprintf(" <info>%-${nameWidth}s</info> %s%s",
  24116. $argument->getName(),
  24117. str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $argument->getDescription()),
  24118. $default
  24119. ), $options);
  24120. }
  24121. protected function describeInputOption(InputOption $option, array $options = array())
  24122. {
  24123. if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
  24124. $default = sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($option->getDefault()));
  24125. } else {
  24126. $default = '';
  24127. }
  24128. $nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($option->getName());
  24129. $nameWithShortcutWidth = $nameWidth - strlen($option->getName()) - 2;
  24130. $this->writeText(sprintf(" <info>%s</info> %-${nameWithShortcutWidth}s%s%s%s",
  24131. '--'.$option->getName(),
  24132. $option->getShortcut() ? sprintf('(-%s) ', $option->getShortcut()) : '',
  24133. str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $option->getDescription()),
  24134. $default,
  24135. $option->isArray() ? '<comment> (multiple values allowed)</comment>' : ''
  24136. ), $options);
  24137. }
  24138. protected function describeInputDefinition(InputDefinition $definition, array $options = array())
  24139. {
  24140. $nameWidth = 0;
  24141. foreach ($definition->getOptions() as $option) {
  24142. $nameLength = strlen($option->getName()) + 2;
  24143. if ($option->getShortcut()) {
  24144. $nameLength += strlen($option->getShortcut()) + 3;
  24145. }
  24146. $nameWidth = max($nameWidth, $nameLength);
  24147. }
  24148. foreach ($definition->getArguments() as $argument) {
  24149. $nameWidth = max($nameWidth, strlen($argument->getName()));
  24150. }
  24151. ++$nameWidth;
  24152. if ($definition->getArguments()) {
  24153. $this->writeText('<comment>Arguments:</comment>', $options);
  24154. $this->writeText("\n");
  24155. foreach ($definition->getArguments() as $argument) {
  24156. $this->describeInputArgument($argument, array_merge($options, array('name_width' => $nameWidth)));
  24157. $this->writeText("\n");
  24158. }
  24159. }
  24160. if ($definition->getArguments() && $definition->getOptions()) {
  24161. $this->writeText("\n");
  24162. }
  24163. if ($definition->getOptions()) {
  24164. $this->writeText('<comment>Options:</comment>', $options);
  24165. $this->writeText("\n");
  24166. foreach ($definition->getOptions() as $option) {
  24167. $this->describeInputOption($option, array_merge($options, array('name_width' => $nameWidth)));
  24168. $this->writeText("\n");
  24169. }
  24170. }
  24171. }
  24172. protected function describeCommand(Command $command, array $options = array())
  24173. {
  24174. $command->getSynopsis();
  24175. $command->mergeApplicationDefinition(false);
  24176. $this->writeText('<comment>Usage:</comment>', $options);
  24177. $this->writeText("\n");
  24178. $this->writeText(' '.$command->getSynopsis(), $options);
  24179. $this->writeText("\n");
  24180. if (count($command->getAliases()) > 0) {
  24181. $this->writeText("\n");
  24182. $this->writeText('<comment>Aliases:</comment> <info>'.implode(', ', $command->getAliases()).'</info>', $options);
  24183. }
  24184. if ($definition = $command->getNativeDefinition()) {
  24185. $this->writeText("\n");
  24186. $this->describeInputDefinition($definition, $options);
  24187. }
  24188. $this->writeText("\n");
  24189. if ($help = $command->getProcessedHelp()) {
  24190. $this->writeText('<comment>Help:</comment>', $options);
  24191. $this->writeText("\n");
  24192. $this->writeText(' '.str_replace("\n", "\n ", $help), $options);
  24193. $this->writeText("\n");
  24194. }
  24195. }
  24196. protected function describeApplication(Application $application, array $options = array())
  24197. {
  24198. $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
  24199. $description = new ApplicationDescription($application, $describedNamespace);
  24200. if (isset($options['raw_text']) && $options['raw_text']) {
  24201. $width = $this->getColumnWidth($description->getCommands());
  24202. foreach ($description->getCommands() as $command) {
  24203. $this->writeText(sprintf("%-${width}s %s", $command->getName(), $command->getDescription()), $options);
  24204. $this->writeText("\n");
  24205. }
  24206. } else {
  24207. if ('' != $help = $application->getHelp()) {
  24208. $this->writeText("$help\n\n", $options);
  24209. }
  24210. $this->writeText("<comment>Usage:</comment>\n", $options);
  24211. $this->writeText(" command [options] [arguments]\n\n", $options);
  24212. $this->writeText('<comment>Options:</comment>', $options);
  24213. $inputOptions = $application->getDefinition()->getOptions();
  24214. $width = 0;
  24215. foreach ($inputOptions as $option) {
  24216. $nameLength = strlen($option->getName()) + 2;
  24217. if ($option->getShortcut()) {
  24218. $nameLength += strlen($option->getShortcut()) + 3;
  24219. }
  24220. $width = max($width, $nameLength);
  24221. }
  24222. ++$width;
  24223. foreach ($inputOptions as $option) {
  24224. $this->writeText("\n", $options);
  24225. $this->describeInputOption($option, array_merge($options, array('name_width' => $width)));
  24226. }
  24227. $this->writeText("\n\n", $options);
  24228. $width = $this->getColumnWidth($description->getCommands());
  24229. if ($describedNamespace) {
  24230. $this->writeText(sprintf('<comment>Available commands for the "%s" namespace:</comment>', $describedNamespace), $options);
  24231. } else {
  24232. $this->writeText('<comment>Available commands:</comment>', $options);
  24233. }
  24234. foreach ($description->getNamespaces() as $namespace) {
  24235. if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
  24236. $this->writeText("\n");
  24237. $this->writeText('<comment>'.$namespace['id'].'</comment>', $options);
  24238. }
  24239. foreach ($namespace['commands'] as $name) {
  24240. $this->writeText("\n");
  24241. $this->writeText(sprintf(" <info>%-${width}s</info> %s", $name, $description->getCommand($name)->getDescription()), $options);
  24242. }
  24243. }
  24244. $this->writeText("\n");
  24245. }
  24246. }
  24247. private function writeText($content, array $options = array())
  24248. {
  24249. $this->write(
  24250. isset($options['raw_text']) && $options['raw_text'] ? strip_tags($content) : $content,
  24251. isset($options['raw_output']) ? !$options['raw_output'] : true
  24252. );
  24253. }
  24254. private function formatDefaultValue($default)
  24255. {
  24256. if (PHP_VERSION_ID < 50400) {
  24257. return str_replace('\/', '/', json_encode($default));
  24258. }
  24259. return json_encode($default, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
  24260. }
  24261. private function getColumnWidth(array $commands)
  24262. {
  24263. $width = 0;
  24264. foreach ($commands as $command) {
  24265. $width = strlen($command->getName()) > $width ? strlen($command->getName()) : $width;
  24266. }
  24267. return $width + 2;
  24268. }
  24269. }
  24270. <?php
  24271. namespace Symfony\Component\Console\Descriptor;
  24272. use Symfony\Component\Console\Application;
  24273. use Symfony\Component\Console\Command\Command;
  24274. use Symfony\Component\Console\Input\InputArgument;
  24275. use Symfony\Component\Console\Input\InputDefinition;
  24276. use Symfony\Component\Console\Input\InputOption;
  24277. class XmlDescriptor extends Descriptor
  24278. {
  24279. public function getInputDefinitionDocument(InputDefinition $definition)
  24280. {
  24281. $dom = new \DOMDocument('1.0', 'UTF-8');
  24282. $dom->appendChild($definitionXML = $dom->createElement('definition'));
  24283. $definitionXML->appendChild($argumentsXML = $dom->createElement('arguments'));
  24284. foreach ($definition->getArguments() as $argument) {
  24285. $this->appendDocument($argumentsXML, $this->getInputArgumentDocument($argument));
  24286. }
  24287. $definitionXML->appendChild($optionsXML = $dom->createElement('options'));
  24288. foreach ($definition->getOptions() as $option) {
  24289. $this->appendDocument($optionsXML, $this->getInputOptionDocument($option));
  24290. }
  24291. return $dom;
  24292. }
  24293. public function getCommandDocument(Command $command)
  24294. {
  24295. $dom = new \DOMDocument('1.0', 'UTF-8');
  24296. $dom->appendChild($commandXML = $dom->createElement('command'));
  24297. $command->getSynopsis();
  24298. $command->mergeApplicationDefinition(false);
  24299. $commandXML->setAttribute('id', $command->getName());
  24300. $commandXML->setAttribute('name', $command->getName());
  24301. $commandXML->appendChild($usageXML = $dom->createElement('usage'));
  24302. $usageXML->appendChild($dom->createTextNode(sprintf($command->getSynopsis(), '')));
  24303. $commandXML->appendChild($descriptionXML = $dom->createElement('description'));
  24304. $descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getDescription())));
  24305. $commandXML->appendChild($helpXML = $dom->createElement('help'));
  24306. $helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getProcessedHelp())));
  24307. $commandXML->appendChild($aliasesXML = $dom->createElement('aliases'));
  24308. foreach ($command->getAliases() as $alias) {
  24309. $aliasesXML->appendChild($aliasXML = $dom->createElement('alias'));
  24310. $aliasXML->appendChild($dom->createTextNode($alias));
  24311. }
  24312. $definitionXML = $this->getInputDefinitionDocument($command->getNativeDefinition());
  24313. $this->appendDocument($commandXML, $definitionXML->getElementsByTagName('definition')->item(0));
  24314. return $dom;
  24315. }
  24316. public function getApplicationDocument(Application $application, $namespace = null)
  24317. {
  24318. $dom = new \DOMDocument('1.0', 'UTF-8');
  24319. $dom->appendChild($rootXml = $dom->createElement('symfony'));
  24320. if ($application->getName() !== 'UNKNOWN') {
  24321. $rootXml->setAttribute('name', $application->getName());
  24322. if ($application->getVersion() !== 'UNKNOWN') {
  24323. $rootXml->setAttribute('version', $application->getVersion());
  24324. }
  24325. }
  24326. $rootXml->appendChild($commandsXML = $dom->createElement('commands'));
  24327. $description = new ApplicationDescription($application, $namespace);
  24328. if ($namespace) {
  24329. $commandsXML->setAttribute('namespace', $namespace);
  24330. }
  24331. foreach ($description->getCommands() as $command) {
  24332. $this->appendDocument($commandsXML, $this->getCommandDocument($command));
  24333. }
  24334. if (!$namespace) {
  24335. $rootXml->appendChild($namespacesXML = $dom->createElement('namespaces'));
  24336. foreach ($description->getNamespaces() as $namespaceDescription) {
  24337. $namespacesXML->appendChild($namespaceArrayXML = $dom->createElement('namespace'));
  24338. $namespaceArrayXML->setAttribute('id', $namespaceDescription['id']);
  24339. foreach ($namespaceDescription['commands'] as $name) {
  24340. $namespaceArrayXML->appendChild($commandXML = $dom->createElement('command'));
  24341. $commandXML->appendChild($dom->createTextNode($name));
  24342. }
  24343. }
  24344. }
  24345. return $dom;
  24346. }
  24347. protected function describeInputArgument(InputArgument $argument, array $options = array())
  24348. {
  24349. $this->writeDocument($this->getInputArgumentDocument($argument));
  24350. }
  24351. protected function describeInputOption(InputOption $option, array $options = array())
  24352. {
  24353. $this->writeDocument($this->getInputOptionDocument($option));
  24354. }
  24355. protected function describeInputDefinition(InputDefinition $definition, array $options = array())
  24356. {
  24357. $this->writeDocument($this->getInputDefinitionDocument($definition));
  24358. }
  24359. protected function describeCommand(Command $command, array $options = array())
  24360. {
  24361. $this->writeDocument($this->getCommandDocument($command));
  24362. }
  24363. protected function describeApplication(Application $application, array $options = array())
  24364. {
  24365. $this->writeDocument($this->getApplicationDocument($application, isset($options['namespace']) ? $options['namespace'] : null));
  24366. }
  24367. private function appendDocument(\DOMNode $parentNode, \DOMNode $importedParent)
  24368. {
  24369. foreach ($importedParent->childNodes as $childNode) {
  24370. $parentNode->appendChild($parentNode->ownerDocument->importNode($childNode, true));
  24371. }
  24372. }
  24373. private function writeDocument(\DOMDocument $dom)
  24374. {
  24375. $dom->formatOutput = true;
  24376. $this->write($dom->saveXML());
  24377. }
  24378. private function getInputArgumentDocument(InputArgument $argument)
  24379. {
  24380. $dom = new \DOMDocument('1.0', 'UTF-8');
  24381. $dom->appendChild($objectXML = $dom->createElement('argument'));
  24382. $objectXML->setAttribute('name', $argument->getName());
  24383. $objectXML->setAttribute('is_required', $argument->isRequired() ? 1 : 0);
  24384. $objectXML->setAttribute('is_array', $argument->isArray() ? 1 : 0);
  24385. $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
  24386. $descriptionXML->appendChild($dom->createTextNode($argument->getDescription()));
  24387. $objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));
  24388. $defaults = is_array($argument->getDefault()) ? $argument->getDefault() : (is_bool($argument->getDefault()) ? array(var_export($argument->getDefault(), true)) : ($argument->getDefault() ? array($argument->getDefault()) : array()));
  24389. foreach ($defaults as $default) {
  24390. $defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
  24391. $defaultXML->appendChild($dom->createTextNode($default));
  24392. }
  24393. return $dom;
  24394. }
  24395. private function getInputOptionDocument(InputOption $option)
  24396. {
  24397. $dom = new \DOMDocument('1.0', 'UTF-8');
  24398. $dom->appendChild($objectXML = $dom->createElement('option'));
  24399. $objectXML->setAttribute('name', '--'.$option->getName());
  24400. $pos = strpos($option->getShortcut(), '|');
  24401. if (false !== $pos) {
  24402. $objectXML->setAttribute('shortcut', '-'.substr($option->getShortcut(), 0, $pos));
  24403. $objectXML->setAttribute('shortcuts', '-'.implode('|-', explode('|', $option->getShortcut())));
  24404. } else {
  24405. $objectXML->setAttribute('shortcut', $option->getShortcut() ? '-'.$option->getShortcut() : '');
  24406. }
  24407. $objectXML->setAttribute('accept_value', $option->acceptValue() ? 1 : 0);
  24408. $objectXML->setAttribute('is_value_required', $option->isValueRequired() ? 1 : 0);
  24409. $objectXML->setAttribute('is_multiple', $option->isArray() ? 1 : 0);
  24410. $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
  24411. $descriptionXML->appendChild($dom->createTextNode($option->getDescription()));
  24412. if ($option->acceptValue()) {
  24413. $defaults = is_array($option->getDefault()) ? $option->getDefault() : (is_bool($option->getDefault()) ? array(var_export($option->getDefault(), true)) : ($option->getDefault() ? array($option->getDefault()) : array()));
  24414. $objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));
  24415. if (!empty($defaults)) {
  24416. foreach ($defaults as $default) {
  24417. $defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
  24418. $defaultXML->appendChild($dom->createTextNode($default));
  24419. }
  24420. }
  24421. }
  24422. return $dom;
  24423. }
  24424. }
  24425. <?php
  24426. namespace Symfony\Component\Console\Event;
  24427. class ConsoleCommandEvent extends ConsoleEvent
  24428. {
  24429. const RETURN_CODE_DISABLED = 113;
  24430. private $commandShouldRun = true;
  24431. public function disableCommand()
  24432. {
  24433. return $this->commandShouldRun = false;
  24434. }
  24435. public function enableCommand()
  24436. {
  24437. return $this->commandShouldRun = true;
  24438. }
  24439. public function commandShouldRun()
  24440. {
  24441. return $this->commandShouldRun;
  24442. }
  24443. }
  24444. <?php
  24445. namespace Symfony\Component\Console\Event;
  24446. use Symfony\Component\Console\Command\Command;
  24447. use Symfony\Component\Console\Input\InputInterface;
  24448. use Symfony\Component\Console\Output\OutputInterface;
  24449. use Symfony\Component\EventDispatcher\Event;
  24450. class ConsoleEvent extends Event
  24451. {
  24452. protected $command;
  24453. private $input;
  24454. private $output;
  24455. public function __construct(Command $command, InputInterface $input, OutputInterface $output)
  24456. {
  24457. $this->command = $command;
  24458. $this->input = $input;
  24459. $this->output = $output;
  24460. }
  24461. public function getCommand()
  24462. {
  24463. return $this->command;
  24464. }
  24465. public function getInput()
  24466. {
  24467. return $this->input;
  24468. }
  24469. public function getOutput()
  24470. {
  24471. return $this->output;
  24472. }
  24473. }
  24474. <?php
  24475. namespace Symfony\Component\Console\Event;
  24476. use Symfony\Component\Console\Command\Command;
  24477. use Symfony\Component\Console\Input\InputInterface;
  24478. use Symfony\Component\Console\Output\OutputInterface;
  24479. class ConsoleExceptionEvent extends ConsoleEvent
  24480. {
  24481. private $exception;
  24482. private $exitCode;
  24483. public function __construct(Command $command, InputInterface $input, OutputInterface $output, \Exception $exception, $exitCode)
  24484. {
  24485. parent::__construct($command, $input, $output);
  24486. $this->setException($exception);
  24487. $this->exitCode = (int) $exitCode;
  24488. }
  24489. public function getException()
  24490. {
  24491. return $this->exception;
  24492. }
  24493. public function setException(\Exception $exception)
  24494. {
  24495. $this->exception = $exception;
  24496. }
  24497. public function getExitCode()
  24498. {
  24499. return $this->exitCode;
  24500. }
  24501. }
  24502. <?php
  24503. namespace Symfony\Component\Console\Event;
  24504. use Symfony\Component\Console\Command\Command;
  24505. use Symfony\Component\Console\Input\InputInterface;
  24506. use Symfony\Component\Console\Output\OutputInterface;
  24507. class ConsoleTerminateEvent extends ConsoleEvent
  24508. {
  24509. private $exitCode;
  24510. public function __construct(Command $command, InputInterface $input, OutputInterface $output, $exitCode)
  24511. {
  24512. parent::__construct($command, $input, $output);
  24513. $this->setExitCode($exitCode);
  24514. }
  24515. public function setExitCode($exitCode)
  24516. {
  24517. $this->exitCode = (int) $exitCode;
  24518. }
  24519. public function getExitCode()
  24520. {
  24521. return $this->exitCode;
  24522. }
  24523. }
  24524. <?php
  24525. namespace Symfony\Component\Console\Formatter;
  24526. class OutputFormatter implements OutputFormatterInterface
  24527. {
  24528. private $decorated;
  24529. private $styles = array();
  24530. private $styleStack;
  24531. public static function escape($text)
  24532. {
  24533. return preg_replace('/([^\\\\]?)</', '$1\\<', $text);
  24534. }
  24535. public function __construct($decorated = false, array $styles = array())
  24536. {
  24537. $this->decorated = (bool) $decorated;
  24538. $this->setStyle('error', new OutputFormatterStyle('white', 'red'));
  24539. $this->setStyle('info', new OutputFormatterStyle('green'));
  24540. $this->setStyle('comment', new OutputFormatterStyle('yellow'));
  24541. $this->setStyle('question', new OutputFormatterStyle('black', 'cyan'));
  24542. foreach ($styles as $name => $style) {
  24543. $this->setStyle($name, $style);
  24544. }
  24545. $this->styleStack = new OutputFormatterStyleStack();
  24546. }
  24547. public function setDecorated($decorated)
  24548. {
  24549. $this->decorated = (bool) $decorated;
  24550. }
  24551. public function isDecorated()
  24552. {
  24553. return $this->decorated;
  24554. }
  24555. public function setStyle($name, OutputFormatterStyleInterface $style)
  24556. {
  24557. $this->styles[strtolower($name)] = $style;
  24558. }
  24559. public function hasStyle($name)
  24560. {
  24561. return isset($this->styles[strtolower($name)]);
  24562. }
  24563. public function getStyle($name)
  24564. {
  24565. if (!$this->hasStyle($name)) {
  24566. throw new \InvalidArgumentException(sprintf('Undefined style: %s', $name));
  24567. }
  24568. return $this->styles[strtolower($name)];
  24569. }
  24570. public function format($message)
  24571. {
  24572. $message = (string) $message;
  24573. $offset = 0;
  24574. $output = '';
  24575. $tagRegex = '[a-z][a-z0-9_=;-]*';
  24576. preg_match_all("#<(($tagRegex) | /($tagRegex)?)>#ix", $message, $matches, PREG_OFFSET_CAPTURE);
  24577. foreach ($matches[0] as $i => $match) {
  24578. $pos = $match[1];
  24579. $text = $match[0];
  24580. if (0 != $pos && '\\' == $message[$pos - 1]) {
  24581. continue;
  24582. }
  24583. $output .= $this->applyCurrentStyle(substr($message, $offset, $pos - $offset));
  24584. $offset = $pos + strlen($text);
  24585. if ($open = '/' != $text[1]) {
  24586. $tag = $matches[1][$i][0];
  24587. } else {
  24588. $tag = isset($matches[3][$i][0]) ? $matches[3][$i][0] : '';
  24589. }
  24590. if (!$open && !$tag) {
  24591. $this->styleStack->pop();
  24592. } elseif (false === $style = $this->createStyleFromString(strtolower($tag))) {
  24593. $output .= $this->applyCurrentStyle($text);
  24594. } elseif ($open) {
  24595. $this->styleStack->push($style);
  24596. } else {
  24597. $this->styleStack->pop($style);
  24598. }
  24599. }
  24600. $output .= $this->applyCurrentStyle(substr($message, $offset));
  24601. return str_replace('\\<', '<', $output);
  24602. }
  24603. public function getStyleStack()
  24604. {
  24605. return $this->styleStack;
  24606. }
  24607. private function createStyleFromString($string)
  24608. {
  24609. if (isset($this->styles[$string])) {
  24610. return $this->styles[$string];
  24611. }
  24612. if (!preg_match_all('/([^=]+)=([^;]+)(;|$)/', strtolower($string), $matches, PREG_SET_ORDER)) {
  24613. return false;
  24614. }
  24615. $style = new OutputFormatterStyle();
  24616. foreach ($matches as $match) {
  24617. array_shift($match);
  24618. if ('fg' == $match[0]) {
  24619. $style->setForeground($match[1]);
  24620. } elseif ('bg' == $match[0]) {
  24621. $style->setBackground($match[1]);
  24622. } else {
  24623. try {
  24624. $style->setOption($match[1]);
  24625. } catch (\InvalidArgumentException $e) {
  24626. return false;
  24627. }
  24628. }
  24629. }
  24630. return $style;
  24631. }
  24632. private function applyCurrentStyle($text)
  24633. {
  24634. return $this->isDecorated() && strlen($text) > 0 ? $this->styleStack->getCurrent()->apply($text) : $text;
  24635. }
  24636. }
  24637. <?php
  24638. namespace Symfony\Component\Console\Formatter;
  24639. interface OutputFormatterInterface
  24640. {
  24641. public function setDecorated($decorated);
  24642. public function isDecorated();
  24643. public function setStyle($name, OutputFormatterStyleInterface $style);
  24644. public function hasStyle($name);
  24645. public function getStyle($name);
  24646. public function format($message);
  24647. }
  24648. <?php
  24649. namespace Symfony\Component\Console\Formatter;
  24650. class OutputFormatterStyle implements OutputFormatterStyleInterface
  24651. {
  24652. private static $availableForegroundColors = array(
  24653. 'black' => array('set' => 30, 'unset' => 39),
  24654. 'red' => array('set' => 31, 'unset' => 39),
  24655. 'green' => array('set' => 32, 'unset' => 39),
  24656. 'yellow' => array('set' => 33, 'unset' => 39),
  24657. 'blue' => array('set' => 34, 'unset' => 39),
  24658. 'magenta' => array('set' => 35, 'unset' => 39),
  24659. 'cyan' => array('set' => 36, 'unset' => 39),
  24660. 'white' => array('set' => 37, 'unset' => 39),
  24661. 'default' => array('set' => 39, 'unset' => 39),
  24662. );
  24663. private static $availableBackgroundColors = array(
  24664. 'black' => array('set' => 40, 'unset' => 49),
  24665. 'red' => array('set' => 41, 'unset' => 49),
  24666. 'green' => array('set' => 42, 'unset' => 49),
  24667. 'yellow' => array('set' => 43, 'unset' => 49),
  24668. 'blue' => array('set' => 44, 'unset' => 49),
  24669. 'magenta' => array('set' => 45, 'unset' => 49),
  24670. 'cyan' => array('set' => 46, 'unset' => 49),
  24671. 'white' => array('set' => 47, 'unset' => 49),
  24672. 'default' => array('set' => 49, 'unset' => 49),
  24673. );
  24674. private static $availableOptions = array(
  24675. 'bold' => array('set' => 1, 'unset' => 22),
  24676. 'underscore' => array('set' => 4, 'unset' => 24),
  24677. 'blink' => array('set' => 5, 'unset' => 25),
  24678. 'reverse' => array('set' => 7, 'unset' => 27),
  24679. 'conceal' => array('set' => 8, 'unset' => 28),
  24680. );
  24681. private $foreground;
  24682. private $background;
  24683. private $options = array();
  24684. public function __construct($foreground = null, $background = null, array $options = array())
  24685. {
  24686. if (null !== $foreground) {
  24687. $this->setForeground($foreground);
  24688. }
  24689. if (null !== $background) {
  24690. $this->setBackground($background);
  24691. }
  24692. if (count($options)) {
  24693. $this->setOptions($options);
  24694. }
  24695. }
  24696. public function setForeground($color = null)
  24697. {
  24698. if (null === $color) {
  24699. $this->foreground = null;
  24700. return;
  24701. }
  24702. if (!isset(static::$availableForegroundColors[$color])) {
  24703. throw new \InvalidArgumentException(sprintf(
  24704. 'Invalid foreground color specified: "%s". Expected one of (%s)',
  24705. $color,
  24706. implode(', ', array_keys(static::$availableForegroundColors))
  24707. ));
  24708. }
  24709. $this->foreground = static::$availableForegroundColors[$color];
  24710. }
  24711. public function setBackground($color = null)
  24712. {
  24713. if (null === $color) {
  24714. $this->background = null;
  24715. return;
  24716. }
  24717. if (!isset(static::$availableBackgroundColors[$color])) {
  24718. throw new \InvalidArgumentException(sprintf(
  24719. 'Invalid background color specified: "%s". Expected one of (%s)',
  24720. $color,
  24721. implode(', ', array_keys(static::$availableBackgroundColors))
  24722. ));
  24723. }
  24724. $this->background = static::$availableBackgroundColors[$color];
  24725. }
  24726. public function setOption($option)
  24727. {
  24728. if (!isset(static::$availableOptions[$option])) {
  24729. throw new \InvalidArgumentException(sprintf(
  24730. 'Invalid option specified: "%s". Expected one of (%s)',
  24731. $option,
  24732. implode(', ', array_keys(static::$availableOptions))
  24733. ));
  24734. }
  24735. if (!in_array(static::$availableOptions[$option], $this->options)) {
  24736. $this->options[] = static::$availableOptions[$option];
  24737. }
  24738. }
  24739. public function unsetOption($option)
  24740. {
  24741. if (!isset(static::$availableOptions[$option])) {
  24742. throw new \InvalidArgumentException(sprintf(
  24743. 'Invalid option specified: "%s". Expected one of (%s)',
  24744. $option,
  24745. implode(', ', array_keys(static::$availableOptions))
  24746. ));
  24747. }
  24748. $pos = array_search(static::$availableOptions[$option], $this->options);
  24749. if (false !== $pos) {
  24750. unset($this->options[$pos]);
  24751. }
  24752. }
  24753. public function setOptions(array $options)
  24754. {
  24755. $this->options = array();
  24756. foreach ($options as $option) {
  24757. $this->setOption($option);
  24758. }
  24759. }
  24760. public function apply($text)
  24761. {
  24762. $setCodes = array();
  24763. $unsetCodes = array();
  24764. if (null !== $this->foreground) {
  24765. $setCodes[] = $this->foreground['set'];
  24766. $unsetCodes[] = $this->foreground['unset'];
  24767. }
  24768. if (null !== $this->background) {
  24769. $setCodes[] = $this->background['set'];
  24770. $unsetCodes[] = $this->background['unset'];
  24771. }
  24772. if (count($this->options)) {
  24773. foreach ($this->options as $option) {
  24774. $setCodes[] = $option['set'];
  24775. $unsetCodes[] = $option['unset'];
  24776. }
  24777. }
  24778. if (0 === count($setCodes)) {
  24779. return $text;
  24780. }
  24781. return sprintf("\033[%sm%s\033[%sm", implode(';', $setCodes), $text, implode(';', $unsetCodes));
  24782. }
  24783. }
  24784. <?php
  24785. namespace Symfony\Component\Console\Formatter;
  24786. interface OutputFormatterStyleInterface
  24787. {
  24788. public function setForeground($color = null);
  24789. public function setBackground($color = null);
  24790. public function setOption($option);
  24791. public function unsetOption($option);
  24792. public function setOptions(array $options);
  24793. public function apply($text);
  24794. }
  24795. <?php
  24796. namespace Symfony\Component\Console\Formatter;
  24797. class OutputFormatterStyleStack
  24798. {
  24799. private $styles;
  24800. private $emptyStyle;
  24801. public function __construct(OutputFormatterStyleInterface $emptyStyle = null)
  24802. {
  24803. $this->emptyStyle = $emptyStyle ?: new OutputFormatterStyle();
  24804. $this->reset();
  24805. }
  24806. public function reset()
  24807. {
  24808. $this->styles = array();
  24809. }
  24810. public function push(OutputFormatterStyleInterface $style)
  24811. {
  24812. $this->styles[] = $style;
  24813. }
  24814. public function pop(OutputFormatterStyleInterface $style = null)
  24815. {
  24816. if (empty($this->styles)) {
  24817. return $this->emptyStyle;
  24818. }
  24819. if (null === $style) {
  24820. return array_pop($this->styles);
  24821. }
  24822. foreach (array_reverse($this->styles, true) as $index => $stackedStyle) {
  24823. if ($style->apply('') === $stackedStyle->apply('')) {
  24824. $this->styles = array_slice($this->styles, 0, $index);
  24825. return $stackedStyle;
  24826. }
  24827. }
  24828. throw new \InvalidArgumentException('Incorrectly nested style tag found.');
  24829. }
  24830. public function getCurrent()
  24831. {
  24832. if (empty($this->styles)) {
  24833. return $this->emptyStyle;
  24834. }
  24835. return $this->styles[count($this->styles) - 1];
  24836. }
  24837. public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle)
  24838. {
  24839. $this->emptyStyle = $emptyStyle;
  24840. return $this;
  24841. }
  24842. public function getEmptyStyle()
  24843. {
  24844. return $this->emptyStyle;
  24845. }
  24846. }
  24847. <?php
  24848. namespace Symfony\Component\Console\Helper;
  24849. class DebugFormatterHelper extends Helper
  24850. {
  24851. private $colors = array('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'default');
  24852. private $started = array();
  24853. private $count = -1;
  24854. public function start($id, $message, $prefix = 'RUN')
  24855. {
  24856. $this->started[$id] = array('border' => ++$this->count % count($this->colors));
  24857. return sprintf("%s<bg=blue;fg=white> %s </> <fg=blue>%s</>\n", $this->getBorder($id), $prefix, $message);
  24858. }
  24859. public function progress($id, $buffer, $error = false, $prefix = 'OUT', $errorPrefix = 'ERR')
  24860. {
  24861. $message = '';
  24862. if ($error) {
  24863. if (isset($this->started[$id]['out'])) {
  24864. $message .= "\n";
  24865. unset($this->started[$id]['out']);
  24866. }
  24867. if (!isset($this->started[$id]['err'])) {
  24868. $message .= sprintf("%s<bg=red;fg=white> %s </> ", $this->getBorder($id), $errorPrefix);
  24869. $this->started[$id]['err'] = true;
  24870. }
  24871. $message .= str_replace("\n", sprintf("\n%s<bg=red;fg=white> %s </> ", $this->getBorder($id), $errorPrefix), $buffer);
  24872. } else {
  24873. if (isset($this->started[$id]['err'])) {
  24874. $message .= "\n";
  24875. unset($this->started[$id]['err']);
  24876. }
  24877. if (!isset($this->started[$id]['out'])) {
  24878. $message .= sprintf("%s<bg=green;fg=white> %s </> ", $this->getBorder($id), $prefix);
  24879. $this->started[$id]['out'] = true;
  24880. }
  24881. $message .= str_replace("\n", sprintf("\n%s<bg=green;fg=white> %s </> ", $this->getBorder($id), $prefix), $buffer);
  24882. }
  24883. return $message;
  24884. }
  24885. public function stop($id, $message, $successful, $prefix = 'RES')
  24886. {
  24887. $trailingEOL = isset($this->started[$id]['out']) || isset($this->started[$id]['err']) ? "\n" : '';
  24888. if ($successful) {
  24889. return sprintf("%s%s<bg=green;fg=white> %s </> <fg=green>%s</>\n", $trailingEOL, $this->getBorder($id), $prefix, $message);
  24890. }
  24891. $message = sprintf("%s%s<bg=red;fg=white> %s </> <fg=red>%s</>\n", $trailingEOL, $this->getBorder($id), $prefix, $message);
  24892. unset($this->started[$id]['out'], $this->started[$id]['err']);
  24893. return $message;
  24894. }
  24895. private function getBorder($id)
  24896. {
  24897. return sprintf('<bg=%s> </>', $this->colors[$this->started[$id]['border']]);
  24898. }
  24899. public function getName()
  24900. {
  24901. return 'debug_formatter';
  24902. }
  24903. }
  24904. <?php
  24905. namespace Symfony\Component\Console\Helper;
  24906. use Symfony\Component\Console\Descriptor\DescriptorInterface;
  24907. use Symfony\Component\Console\Descriptor\JsonDescriptor;
  24908. use Symfony\Component\Console\Descriptor\MarkdownDescriptor;
  24909. use Symfony\Component\Console\Descriptor\TextDescriptor;
  24910. use Symfony\Component\Console\Descriptor\XmlDescriptor;
  24911. use Symfony\Component\Console\Output\OutputInterface;
  24912. class DescriptorHelper extends Helper
  24913. {
  24914. private $descriptors = array();
  24915. public function __construct()
  24916. {
  24917. $this
  24918. ->register('txt', new TextDescriptor())
  24919. ->register('xml', new XmlDescriptor())
  24920. ->register('json', new JsonDescriptor())
  24921. ->register('md', new MarkdownDescriptor())
  24922. ;
  24923. }
  24924. public function describe(OutputInterface $output, $object, array $options = array())
  24925. {
  24926. $options = array_merge(array(
  24927. 'raw_text' => false,
  24928. 'format' => 'txt',
  24929. ), $options);
  24930. if (!isset($this->descriptors[$options['format']])) {
  24931. throw new \InvalidArgumentException(sprintf('Unsupported format "%s".', $options['format']));
  24932. }
  24933. $descriptor = $this->descriptors[$options['format']];
  24934. $descriptor->describe($output, $object, $options);
  24935. }
  24936. public function register($format, DescriptorInterface $descriptor)
  24937. {
  24938. $this->descriptors[$format] = $descriptor;
  24939. return $this;
  24940. }
  24941. public function getName()
  24942. {
  24943. return 'descriptor';
  24944. }
  24945. }
  24946. <?php
  24947. namespace Symfony\Component\Console\Helper;
  24948. use Symfony\Component\Console\Output\OutputInterface;
  24949. use Symfony\Component\Console\Formatter\OutputFormatterStyle;
  24950. class DialogHelper extends InputAwareHelper
  24951. {
  24952. private $inputStream;
  24953. private static $shell;
  24954. private static $stty;
  24955. public function select(OutputInterface $output, $question, $choices, $default = null, $attempts = false, $errorMessage = 'Value "%s" is invalid', $multiselect = false)
  24956. {
  24957. $width = max(array_map('strlen', array_keys($choices)));
  24958. $messages = (array) $question;
  24959. foreach ($choices as $key => $value) {
  24960. $messages[] = sprintf(" [<info>%-${width}s</info>] %s", $key, $value);
  24961. }
  24962. $output->writeln($messages);
  24963. $result = $this->askAndValidate($output, '> ', function ($picked) use ($choices, $errorMessage, $multiselect) {
  24964. $selectedChoices = str_replace(' ', '', $picked);
  24965. if ($multiselect) {
  24966. if (!preg_match('/^[a-zA-Z0-9_-]+(?:,[a-zA-Z0-9_-]+)*$/', $selectedChoices, $matches)) {
  24967. throw new \InvalidArgumentException(sprintf($errorMessage, $picked));
  24968. }
  24969. $selectedChoices = explode(',', $selectedChoices);
  24970. } else {
  24971. $selectedChoices = array($picked);
  24972. }
  24973. $multiselectChoices = array();
  24974. foreach ($selectedChoices as $value) {
  24975. if (empty($choices[$value])) {
  24976. throw new \InvalidArgumentException(sprintf($errorMessage, $value));
  24977. }
  24978. $multiselectChoices[] = $value;
  24979. }
  24980. if ($multiselect) {
  24981. return $multiselectChoices;
  24982. }
  24983. return $picked;
  24984. }, $attempts, $default);
  24985. return $result;
  24986. }
  24987. public function ask(OutputInterface $output, $question, $default = null, array $autocomplete = null)
  24988. {
  24989. if ($this->input && !$this->input->isInteractive()) {
  24990. return $default;
  24991. }
  24992. $output->write($question);
  24993. $inputStream = $this->inputStream ?: STDIN;
  24994. if (null === $autocomplete || !$this->hasSttyAvailable()) {
  24995. $ret = fgets($inputStream, 4096);
  24996. if (false === $ret) {
  24997. throw new \RuntimeException('Aborted');
  24998. }
  24999. $ret = trim($ret);
  25000. } else {
  25001. $ret = '';
  25002. $i = 0;
  25003. $ofs = -1;
  25004. $matches = $autocomplete;
  25005. $numMatches = count($matches);
  25006. $sttyMode = shell_exec('stty -g');
  25007. shell_exec('stty -icanon -echo');
  25008. $output->getFormatter()->setStyle('hl', new OutputFormatterStyle('black', 'white'));
  25009. while (!feof($inputStream)) {
  25010. $c = fread($inputStream, 1);
  25011. if ("\177" === $c) {
  25012. if (0 === $numMatches && 0 !== $i) {
  25013. --$i;
  25014. $output->write("\033[1D");
  25015. }
  25016. if ($i === 0) {
  25017. $ofs = -1;
  25018. $matches = $autocomplete;
  25019. $numMatches = count($matches);
  25020. } else {
  25021. $numMatches = 0;
  25022. }
  25023. $ret = substr($ret, 0, $i);
  25024. } elseif ("\033" === $c) {
  25025. $c .= fread($inputStream, 2);
  25026. if (isset($c[2]) && ('A' === $c[2] || 'B' === $c[2])) {
  25027. if ('A' === $c[2] && -1 === $ofs) {
  25028. $ofs = 0;
  25029. }
  25030. if (0 === $numMatches) {
  25031. continue;
  25032. }
  25033. $ofs += ('A' === $c[2]) ? -1 : 1;
  25034. $ofs = ($numMatches + $ofs) % $numMatches;
  25035. }
  25036. } elseif (ord($c) < 32) {
  25037. if ("\t" === $c || "\n" === $c) {
  25038. if ($numMatches > 0 && -1 !== $ofs) {
  25039. $ret = $matches[$ofs];
  25040. $output->write(substr($ret, $i));
  25041. $i = strlen($ret);
  25042. }
  25043. if ("\n" === $c) {
  25044. $output->write($c);
  25045. break;
  25046. }
  25047. $numMatches = 0;
  25048. }
  25049. continue;
  25050. } else {
  25051. $output->write($c);
  25052. $ret .= $c;
  25053. ++$i;
  25054. $numMatches = 0;
  25055. $ofs = 0;
  25056. foreach ($autocomplete as $value) {
  25057. if (0 === strpos($value, $ret) && $i !== strlen($value)) {
  25058. $matches[$numMatches++] = $value;
  25059. }
  25060. }
  25061. }
  25062. $output->write("\033[K");
  25063. if ($numMatches > 0 && -1 !== $ofs) {
  25064. $output->write("\0337");
  25065. $output->write('<hl>'.substr($matches[$ofs], $i).'</hl>');
  25066. $output->write("\0338");
  25067. }
  25068. }
  25069. shell_exec(sprintf('stty %s', $sttyMode));
  25070. }
  25071. return strlen($ret) > 0 ? $ret : $default;
  25072. }
  25073. public function askConfirmation(OutputInterface $output, $question, $default = true)
  25074. {
  25075. $answer = 'z';
  25076. while ($answer && !in_array(strtolower($answer[0]), array('y', 'n'))) {
  25077. $answer = $this->ask($output, $question);
  25078. }
  25079. if (false === $default) {
  25080. return $answer && 'y' == strtolower($answer[0]);
  25081. }
  25082. return !$answer || 'y' == strtolower($answer[0]);
  25083. }
  25084. public function askHiddenResponse(OutputInterface $output, $question, $fallback = true)
  25085. {
  25086. if ('\\' === DIRECTORY_SEPARATOR) {
  25087. $exe = __DIR__.'/../Resources/bin/hiddeninput.exe';
  25088. if ('phar:' === substr(__FILE__, 0, 5)) {
  25089. $tmpExe = sys_get_temp_dir().'/hiddeninput.exe';
  25090. copy($exe, $tmpExe);
  25091. $exe = $tmpExe;
  25092. }
  25093. $output->write($question);
  25094. $value = rtrim(shell_exec($exe));
  25095. $output->writeln('');
  25096. if (isset($tmpExe)) {
  25097. unlink($tmpExe);
  25098. }
  25099. return $value;
  25100. }
  25101. if ($this->hasSttyAvailable()) {
  25102. $output->write($question);
  25103. $sttyMode = shell_exec('stty -g');
  25104. shell_exec('stty -echo');
  25105. $value = fgets($this->inputStream ?: STDIN, 4096);
  25106. shell_exec(sprintf('stty %s', $sttyMode));
  25107. if (false === $value) {
  25108. throw new \RuntimeException('Aborted');
  25109. }
  25110. $value = trim($value);
  25111. $output->writeln('');
  25112. return $value;
  25113. }
  25114. if (false !== $shell = $this->getShell()) {
  25115. $output->write($question);
  25116. $readCmd = $shell === 'csh' ? 'set mypassword = $<' : 'read -r mypassword';
  25117. $command = sprintf("/usr/bin/env %s -c 'stty -echo; %s; stty echo; echo \$mypassword'", $shell, $readCmd);
  25118. $value = rtrim(shell_exec($command));
  25119. $output->writeln('');
  25120. return $value;
  25121. }
  25122. if ($fallback) {
  25123. return $this->ask($output, $question);
  25124. }
  25125. throw new \RuntimeException('Unable to hide the response');
  25126. }
  25127. public function askAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $default = null, array $autocomplete = null)
  25128. {
  25129. $that = $this;
  25130. $interviewer = function () use ($output, $question, $default, $autocomplete, $that) {
  25131. return $that->ask($output, $question, $default, $autocomplete);
  25132. };
  25133. return $this->validateAttempts($interviewer, $output, $validator, $attempts);
  25134. }
  25135. public function askHiddenResponseAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $fallback = true)
  25136. {
  25137. $that = $this;
  25138. $interviewer = function () use ($output, $question, $fallback, $that) {
  25139. return $that->askHiddenResponse($output, $question, $fallback);
  25140. };
  25141. return $this->validateAttempts($interviewer, $output, $validator, $attempts);
  25142. }
  25143. public function setInputStream($stream)
  25144. {
  25145. $this->inputStream = $stream;
  25146. }
  25147. public function getInputStream()
  25148. {
  25149. return $this->inputStream;
  25150. }
  25151. public function getName()
  25152. {
  25153. return 'dialog';
  25154. }
  25155. private function getShell()
  25156. {
  25157. if (null !== self::$shell) {
  25158. return self::$shell;
  25159. }
  25160. self::$shell = false;
  25161. if (file_exists('/usr/bin/env')) {
  25162. $test = "/usr/bin/env %s -c 'echo OK' 2> /dev/null";
  25163. foreach (array('bash', 'zsh', 'ksh', 'csh') as $sh) {
  25164. if ('OK' === rtrim(shell_exec(sprintf($test, $sh)))) {
  25165. self::$shell = $sh;
  25166. break;
  25167. }
  25168. }
  25169. }
  25170. return self::$shell;
  25171. }
  25172. private function hasSttyAvailable()
  25173. {
  25174. if (null !== self::$stty) {
  25175. return self::$stty;
  25176. }
  25177. exec('stty 2>&1', $output, $exitcode);
  25178. return self::$stty = $exitcode === 0;
  25179. }
  25180. private function validateAttempts($interviewer, OutputInterface $output, $validator, $attempts)
  25181. {
  25182. $e = null;
  25183. while (false === $attempts || $attempts--) {
  25184. if (null !== $e) {
  25185. $output->writeln($this->getHelperSet()->get('formatter')->formatBlock($e->getMessage(), 'error'));
  25186. }
  25187. try {
  25188. return call_user_func($validator, $interviewer());
  25189. } catch (\Exception $e) {
  25190. }
  25191. }
  25192. throw $e;
  25193. }
  25194. }
  25195. <?php
  25196. namespace Symfony\Component\Console\Helper;
  25197. use Symfony\Component\Console\Formatter\OutputFormatter;
  25198. class FormatterHelper extends Helper
  25199. {
  25200. public function formatSection($section, $message, $style = 'info')
  25201. {
  25202. return sprintf('<%s>[%s]</%s> %s', $style, $section, $style, $message);
  25203. }
  25204. public function formatBlock($messages, $style, $large = false)
  25205. {
  25206. if (!is_array($messages)) {
  25207. $messages = array($messages);
  25208. }
  25209. $len = 0;
  25210. $lines = array();
  25211. foreach ($messages as $message) {
  25212. $message = OutputFormatter::escape($message);
  25213. $lines[] = sprintf($large ? ' %s ' : ' %s ', $message);
  25214. $len = max($this->strlen($message) + ($large ? 4 : 2), $len);
  25215. }
  25216. $messages = $large ? array(str_repeat(' ', $len)) : array();
  25217. for ($i = 0; isset($lines[$i]); ++$i) {
  25218. $messages[] = $lines[$i].str_repeat(' ', $len - $this->strlen($lines[$i]));
  25219. }
  25220. if ($large) {
  25221. $messages[] = str_repeat(' ', $len);
  25222. }
  25223. for ($i = 0; isset($messages[$i]); ++$i) {
  25224. $messages[$i] = sprintf('<%s>%s</%s>', $style, $messages[$i], $style);
  25225. }
  25226. return implode("\n", $messages);
  25227. }
  25228. public function getName()
  25229. {
  25230. return 'formatter';
  25231. }
  25232. }
  25233. <?php
  25234. namespace Symfony\Component\Console\Helper;
  25235. use Symfony\Component\Console\Formatter\OutputFormatterInterface;
  25236. abstract class Helper implements HelperInterface
  25237. {
  25238. protected $helperSet = null;
  25239. public function setHelperSet(HelperSet $helperSet = null)
  25240. {
  25241. $this->helperSet = $helperSet;
  25242. }
  25243. public function getHelperSet()
  25244. {
  25245. return $this->helperSet;
  25246. }
  25247. public static function strlen($string)
  25248. {
  25249. if (!function_exists('mb_strwidth')) {
  25250. return strlen($string);
  25251. }
  25252. if (false === $encoding = mb_detect_encoding($string)) {
  25253. return strlen($string);
  25254. }
  25255. return mb_strwidth($string, $encoding);
  25256. }
  25257. public static function formatTime($secs)
  25258. {
  25259. static $timeFormats = array(
  25260. array(0, '< 1 sec'),
  25261. array(2, '1 sec'),
  25262. array(59, 'secs', 1),
  25263. array(60, '1 min'),
  25264. array(3600, 'mins', 60),
  25265. array(5400, '1 hr'),
  25266. array(86400, 'hrs', 3600),
  25267. array(129600, '1 day'),
  25268. array(604800, 'days', 86400),
  25269. );
  25270. foreach ($timeFormats as $format) {
  25271. if ($secs >= $format[0]) {
  25272. continue;
  25273. }
  25274. if (2 == count($format)) {
  25275. return $format[1];
  25276. }
  25277. return ceil($secs / $format[2]).' '.$format[1];
  25278. }
  25279. }
  25280. public static function formatMemory($memory)
  25281. {
  25282. if ($memory >= 1024 * 1024 * 1024) {
  25283. return sprintf('%.1f GiB', $memory / 1024 / 1024 / 1024);
  25284. }
  25285. if ($memory >= 1024 * 1024) {
  25286. return sprintf('%.1f MiB', $memory / 1024 / 1024);
  25287. }
  25288. if ($memory >= 1024) {
  25289. return sprintf('%d KiB', $memory / 1024);
  25290. }
  25291. return sprintf('%d B', $memory);
  25292. }
  25293. public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, $string)
  25294. {
  25295. $isDecorated = $formatter->isDecorated();
  25296. $formatter->setDecorated(false);
  25297. $string = $formatter->format($string);
  25298. $string = preg_replace("/\033\[[^m]*m/", '', $string);
  25299. $formatter->setDecorated($isDecorated);
  25300. return self::strlen($string);
  25301. }
  25302. }
  25303. <?php
  25304. namespace Symfony\Component\Console\Helper;
  25305. interface HelperInterface
  25306. {
  25307. public function setHelperSet(HelperSet $helperSet = null);
  25308. public function getHelperSet();
  25309. public function getName();
  25310. }
  25311. <?php
  25312. namespace Symfony\Component\Console\Helper;
  25313. use Symfony\Component\Console\Command\Command;
  25314. class HelperSet implements \IteratorAggregate
  25315. {
  25316. private $helpers = array();
  25317. private $command;
  25318. public function __construct(array $helpers = array())
  25319. {
  25320. foreach ($helpers as $alias => $helper) {
  25321. $this->set($helper, is_int($alias) ? null : $alias);
  25322. }
  25323. }
  25324. public function set(HelperInterface $helper, $alias = null)
  25325. {
  25326. $this->helpers[$helper->getName()] = $helper;
  25327. if (null !== $alias) {
  25328. $this->helpers[$alias] = $helper;
  25329. }
  25330. $helper->setHelperSet($this);
  25331. }
  25332. public function has($name)
  25333. {
  25334. return isset($this->helpers[$name]);
  25335. }
  25336. public function get($name)
  25337. {
  25338. if (!$this->has($name)) {
  25339. throw new \InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name));
  25340. }
  25341. return $this->helpers[$name];
  25342. }
  25343. public function setCommand(Command $command = null)
  25344. {
  25345. $this->command = $command;
  25346. }
  25347. public function getCommand()
  25348. {
  25349. return $this->command;
  25350. }
  25351. public function getIterator()
  25352. {
  25353. return new \ArrayIterator($this->helpers);
  25354. }
  25355. }
  25356. <?php
  25357. namespace Symfony\Component\Console\Helper;
  25358. use Symfony\Component\Console\Input\InputInterface;
  25359. use Symfony\Component\Console\Input\InputAwareInterface;
  25360. abstract class InputAwareHelper extends Helper implements InputAwareInterface
  25361. {
  25362. protected $input;
  25363. public function setInput(InputInterface $input)
  25364. {
  25365. $this->input = $input;
  25366. }
  25367. }
  25368. <?php
  25369. namespace Symfony\Component\Console\Helper;
  25370. use Symfony\Component\Console\Output\OutputInterface;
  25371. use Symfony\Component\Process\Exception\ProcessFailedException;
  25372. use Symfony\Component\Process\Process;
  25373. use Symfony\Component\Process\ProcessBuilder;
  25374. class ProcessHelper extends Helper
  25375. {
  25376. public function run(OutputInterface $output, $cmd, $error = null, $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE)
  25377. {
  25378. $formatter = $this->getHelperSet()->get('debug_formatter');
  25379. if (is_array($cmd)) {
  25380. $process = ProcessBuilder::create($cmd)->getProcess();
  25381. } elseif ($cmd instanceof Process) {
  25382. $process = $cmd;
  25383. } else {
  25384. $process = new Process($cmd);
  25385. }
  25386. if ($verbosity <= $output->getVerbosity()) {
  25387. $output->write($formatter->start(spl_object_hash($process), $this->escapeString($process->getCommandLine())));
  25388. }
  25389. if ($output->isDebug()) {
  25390. $callback = $this->wrapCallback($output, $process, $callback);
  25391. }
  25392. $process->run($callback);
  25393. if ($verbosity <= $output->getVerbosity()) {
  25394. $message = $process->isSuccessful() ? 'Command ran successfully' : sprintf('%s Command did not run successfully', $process->getExitCode());
  25395. $output->write($formatter->stop(spl_object_hash($process), $message, $process->isSuccessful()));
  25396. }
  25397. if (!$process->isSuccessful() && null !== $error) {
  25398. $output->writeln(sprintf('<error>%s</error>', $this->escapeString($error)));
  25399. }
  25400. return $process;
  25401. }
  25402. public function mustRun(OutputInterface $output, $cmd, $error = null, $callback = null)
  25403. {
  25404. $process = $this->run($output, $cmd, $error, $callback);
  25405. if (!$process->isSuccessful()) {
  25406. throw new ProcessFailedException($process);
  25407. }
  25408. return $process;
  25409. }
  25410. public function wrapCallback(OutputInterface $output, Process $process, $callback = null)
  25411. {
  25412. $formatter = $this->getHelperSet()->get('debug_formatter');
  25413. $that = $this;
  25414. return function ($type, $buffer) use ($output, $process, $callback, $formatter, $that) {
  25415. $output->write($formatter->progress(spl_object_hash($process), $that->escapeString($buffer), Process::ERR === $type));
  25416. if (null !== $callback) {
  25417. call_user_func($callback, $type, $buffer);
  25418. }
  25419. };
  25420. }
  25421. public function escapeString($str)
  25422. {
  25423. return str_replace('<', '\\<', $str);
  25424. }
  25425. public function getName()
  25426. {
  25427. return 'process';
  25428. }
  25429. }
  25430. <?php
  25431. namespace Symfony\Component\Console\Helper;
  25432. use Symfony\Component\Console\Output\OutputInterface;
  25433. class ProgressBar
  25434. {
  25435. private $barWidth = 28;
  25436. private $barChar;
  25437. private $emptyBarChar = '-';
  25438. private $progressChar = '>';
  25439. private $format = null;
  25440. private $redrawFreq = 1;
  25441. private $output;
  25442. private $step = 0;
  25443. private $max;
  25444. private $startTime;
  25445. private $stepWidth;
  25446. private $percent = 0.0;
  25447. private $lastMessagesLength = 0;
  25448. private $formatLineCount;
  25449. private $messages;
  25450. private $overwrite = true;
  25451. private static $formatters;
  25452. private static $formats;
  25453. public function __construct(OutputInterface $output, $max = 0)
  25454. {
  25455. $this->output = $output;
  25456. $this->setMaxSteps($max);
  25457. if (!$this->output->isDecorated()) {
  25458. $this->overwrite = false;
  25459. if ($this->max > 10) {
  25460. $this->setRedrawFrequency($max / 10);
  25461. }
  25462. }
  25463. $this->setFormat($this->determineBestFormat());
  25464. $this->startTime = time();
  25465. }
  25466. public static function setPlaceholderFormatterDefinition($name, $callable)
  25467. {
  25468. if (!self::$formatters) {
  25469. self::$formatters = self::initPlaceholderFormatters();
  25470. }
  25471. self::$formatters[$name] = $callable;
  25472. }
  25473. public static function getPlaceholderFormatterDefinition($name)
  25474. {
  25475. if (!self::$formatters) {
  25476. self::$formatters = self::initPlaceholderFormatters();
  25477. }
  25478. return isset(self::$formatters[$name]) ? self::$formatters[$name] : null;
  25479. }
  25480. public static function setFormatDefinition($name, $format)
  25481. {
  25482. if (!self::$formats) {
  25483. self::$formats = self::initFormats();
  25484. }
  25485. self::$formats[$name] = $format;
  25486. }
  25487. public static function getFormatDefinition($name)
  25488. {
  25489. if (!self::$formats) {
  25490. self::$formats = self::initFormats();
  25491. }
  25492. return isset(self::$formats[$name]) ? self::$formats[$name] : null;
  25493. }
  25494. public function setMessage($message, $name = 'message')
  25495. {
  25496. $this->messages[$name] = $message;
  25497. }
  25498. public function getMessage($name = 'message')
  25499. {
  25500. return $this->messages[$name];
  25501. }
  25502. public function getStartTime()
  25503. {
  25504. return $this->startTime;
  25505. }
  25506. public function getMaxSteps()
  25507. {
  25508. return $this->max;
  25509. }
  25510. public function getStep()
  25511. {
  25512. return $this->getProgress();
  25513. }
  25514. public function getProgress()
  25515. {
  25516. return $this->step;
  25517. }
  25518. public function getStepWidth()
  25519. {
  25520. return $this->stepWidth;
  25521. }
  25522. public function getProgressPercent()
  25523. {
  25524. return $this->percent;
  25525. }
  25526. public function setBarWidth($size)
  25527. {
  25528. $this->barWidth = (int) $size;
  25529. }
  25530. public function getBarWidth()
  25531. {
  25532. return $this->barWidth;
  25533. }
  25534. public function setBarCharacter($char)
  25535. {
  25536. $this->barChar = $char;
  25537. }
  25538. public function getBarCharacter()
  25539. {
  25540. if (null === $this->barChar) {
  25541. return $this->max ? '=' : $this->emptyBarChar;
  25542. }
  25543. return $this->barChar;
  25544. }
  25545. public function setEmptyBarCharacter($char)
  25546. {
  25547. $this->emptyBarChar = $char;
  25548. }
  25549. public function getEmptyBarCharacter()
  25550. {
  25551. return $this->emptyBarChar;
  25552. }
  25553. public function setProgressCharacter($char)
  25554. {
  25555. $this->progressChar = $char;
  25556. }
  25557. public function getProgressCharacter()
  25558. {
  25559. return $this->progressChar;
  25560. }
  25561. public function setFormat($format)
  25562. {
  25563. if (!$this->max && null !== self::getFormatDefinition($format.'_nomax')) {
  25564. $this->format = self::getFormatDefinition($format.'_nomax');
  25565. } elseif (null !== self::getFormatDefinition($format)) {
  25566. $this->format = self::getFormatDefinition($format);
  25567. } else {
  25568. $this->format = $format;
  25569. }
  25570. $this->formatLineCount = substr_count($this->format, "\n");
  25571. }
  25572. public function setRedrawFrequency($freq)
  25573. {
  25574. $this->redrawFreq = (int) $freq;
  25575. }
  25576. public function start($max = null)
  25577. {
  25578. $this->startTime = time();
  25579. $this->step = 0;
  25580. $this->percent = 0.0;
  25581. if (null !== $max) {
  25582. $this->setMaxSteps($max);
  25583. }
  25584. $this->display();
  25585. }
  25586. public function advance($step = 1)
  25587. {
  25588. $this->setProgress($this->step + $step);
  25589. }
  25590. public function setCurrent($step)
  25591. {
  25592. $this->setProgress($step);
  25593. }
  25594. public function setOverwrite($overwrite)
  25595. {
  25596. $this->overwrite = (bool) $overwrite;
  25597. }
  25598. public function setProgress($step)
  25599. {
  25600. $step = (int) $step;
  25601. if ($step < $this->step) {
  25602. throw new \LogicException('You can\'t regress the progress bar.');
  25603. }
  25604. if ($this->max && $step > $this->max) {
  25605. $this->max = $step;
  25606. }
  25607. $prevPeriod = (int) ($this->step / $this->redrawFreq);
  25608. $currPeriod = (int) ($step / $this->redrawFreq);
  25609. $this->step = $step;
  25610. $this->percent = $this->max ? (float) $this->step / $this->max : 0;
  25611. if ($prevPeriod !== $currPeriod || $this->max === $step) {
  25612. $this->display();
  25613. }
  25614. }
  25615. public function finish()
  25616. {
  25617. if (!$this->max) {
  25618. $this->max = $this->step;
  25619. }
  25620. if ($this->step === $this->max && !$this->overwrite) {
  25621. return;
  25622. }
  25623. $this->setProgress($this->max);
  25624. }
  25625. public function display()
  25626. {
  25627. if (OutputInterface::VERBOSITY_QUIET === $this->output->getVerbosity()) {
  25628. return;
  25629. }
  25630. $self = $this;
  25631. $output = $this->output;
  25632. $messages = $this->messages;
  25633. $this->overwrite(preg_replace_callback("{%([a-z\-_]+)(?:\:([^%]+))?%}i", function ($matches) use ($self, $output, $messages) {
  25634. if ($formatter = $self::getPlaceholderFormatterDefinition($matches[1])) {
  25635. $text = call_user_func($formatter, $self, $output);
  25636. } elseif (isset($messages[$matches[1]])) {
  25637. $text = $messages[$matches[1]];
  25638. } else {
  25639. return $matches[0];
  25640. }
  25641. if (isset($matches[2])) {
  25642. $text = sprintf('%'.$matches[2], $text);
  25643. }
  25644. return $text;
  25645. }, $this->format));
  25646. }
  25647. public function clear()
  25648. {
  25649. if (!$this->overwrite) {
  25650. return;
  25651. }
  25652. $this->overwrite(str_repeat("\n", $this->formatLineCount));
  25653. }
  25654. private function setMaxSteps($max)
  25655. {
  25656. $this->max = max(0, (int) $max);
  25657. $this->stepWidth = $this->max ? Helper::strlen($this->max) : 4;
  25658. }
  25659. private function overwrite($message)
  25660. {
  25661. $lines = explode("\n", $message);
  25662. if (null !== $this->lastMessagesLength) {
  25663. foreach ($lines as $i => $line) {
  25664. if ($this->lastMessagesLength > Helper::strlenWithoutDecoration($this->output->getFormatter(), $line)) {
  25665. $lines[$i] = str_pad($line, $this->lastMessagesLength, "\x20", STR_PAD_RIGHT);
  25666. }
  25667. }
  25668. }
  25669. if ($this->overwrite) {
  25670. $this->output->write("\x0D");
  25671. } elseif ($this->step > 0) {
  25672. $this->output->writeln('');
  25673. }
  25674. if ($this->formatLineCount) {
  25675. $this->output->write(sprintf("\033[%dA", $this->formatLineCount));
  25676. }
  25677. $this->output->write(implode("\n", $lines));
  25678. $this->lastMessagesLength = 0;
  25679. foreach ($lines as $line) {
  25680. $len = Helper::strlenWithoutDecoration($this->output->getFormatter(), $line);
  25681. if ($len > $this->lastMessagesLength) {
  25682. $this->lastMessagesLength = $len;
  25683. }
  25684. }
  25685. }
  25686. private function determineBestFormat()
  25687. {
  25688. switch ($this->output->getVerbosity()) {
  25689. case OutputInterface::VERBOSITY_VERBOSE:
  25690. return $this->max ? 'verbose' : 'verbose_nomax';
  25691. case OutputInterface::VERBOSITY_VERY_VERBOSE:
  25692. return $this->max ? 'very_verbose' : 'very_verbose_nomax';
  25693. case OutputInterface::VERBOSITY_DEBUG:
  25694. return $this->max ? 'debug' : 'debug_nomax';
  25695. default:
  25696. return $this->max ? 'normal' : 'normal_nomax';
  25697. }
  25698. }
  25699. private static function initPlaceholderFormatters()
  25700. {
  25701. return array(
  25702. 'bar' => function (ProgressBar $bar, OutputInterface $output) {
  25703. $completeBars = floor($bar->getMaxSteps() > 0 ? $bar->getProgressPercent() * $bar->getBarWidth() : $bar->getProgress() % $bar->getBarWidth());
  25704. $display = str_repeat($bar->getBarCharacter(), $completeBars);
  25705. if ($completeBars < $bar->getBarWidth()) {
  25706. $emptyBars = $bar->getBarWidth() - $completeBars - Helper::strlenWithoutDecoration($output->getFormatter(), $bar->getProgressCharacter());
  25707. $display .= $bar->getProgressCharacter().str_repeat($bar->getEmptyBarCharacter(), $emptyBars);
  25708. }
  25709. return $display;
  25710. },
  25711. 'elapsed' => function (ProgressBar $bar) {
  25712. return Helper::formatTime(time() - $bar->getStartTime());
  25713. },
  25714. 'remaining' => function (ProgressBar $bar) {
  25715. if (!$bar->getMaxSteps()) {
  25716. throw new \LogicException('Unable to display the remaining time if the maximum number of steps is not set.');
  25717. }
  25718. if (!$bar->getProgress()) {
  25719. $remaining = 0;
  25720. } else {
  25721. $remaining = round((time() - $bar->getStartTime()) / $bar->getProgress() * ($bar->getMaxSteps() - $bar->getProgress()));
  25722. }
  25723. return Helper::formatTime($remaining);
  25724. },
  25725. 'estimated' => function (ProgressBar $bar) {
  25726. if (!$bar->getMaxSteps()) {
  25727. throw new \LogicException('Unable to display the estimated time if the maximum number of steps is not set.');
  25728. }
  25729. if (!$bar->getProgress()) {
  25730. $estimated = 0;
  25731. } else {
  25732. $estimated = round((time() - $bar->getStartTime()) / $bar->getProgress() * $bar->getMaxSteps());
  25733. }
  25734. return Helper::formatTime($estimated);
  25735. },
  25736. 'memory' => function (ProgressBar $bar) {
  25737. return Helper::formatMemory(memory_get_usage(true));
  25738. },
  25739. 'current' => function (ProgressBar $bar) {
  25740. return str_pad($bar->getProgress(), $bar->getStepWidth(), ' ', STR_PAD_LEFT);
  25741. },
  25742. 'max' => function (ProgressBar $bar) {
  25743. return $bar->getMaxSteps();
  25744. },
  25745. 'percent' => function (ProgressBar $bar) {
  25746. return floor($bar->getProgressPercent() * 100);
  25747. },
  25748. );
  25749. }
  25750. private static function initFormats()
  25751. {
  25752. return array(
  25753. 'normal' => ' %current%/%max% [%bar%] %percent:3s%%',
  25754. 'normal_nomax' => ' %current% [%bar%]',
  25755. 'verbose' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%',
  25756. 'verbose_nomax' => ' %current% [%bar%] %elapsed:6s%',
  25757. 'very_verbose' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s%',
  25758. 'very_verbose_nomax' => ' %current% [%bar%] %elapsed:6s%',
  25759. 'debug' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%',
  25760. 'debug_nomax' => ' %current% [%bar%] %elapsed:6s% %memory:6s%',
  25761. );
  25762. }
  25763. }
  25764. <?php
  25765. namespace Symfony\Component\Console\Helper;
  25766. use Symfony\Component\Console\Output\NullOutput;
  25767. use Symfony\Component\Console\Output\OutputInterface;
  25768. class ProgressHelper extends Helper
  25769. {
  25770. const FORMAT_QUIET = ' %percent%%';
  25771. const FORMAT_NORMAL = ' %current%/%max% [%bar%] %percent%%';
  25772. const FORMAT_VERBOSE = ' %current%/%max% [%bar%] %percent%% Elapsed: %elapsed%';
  25773. const FORMAT_QUIET_NOMAX = ' %current%';
  25774. const FORMAT_NORMAL_NOMAX = ' %current% [%bar%]';
  25775. const FORMAT_VERBOSE_NOMAX = ' %current% [%bar%] Elapsed: %elapsed%';
  25776. private $barWidth = 28;
  25777. private $barChar = '=';
  25778. private $emptyBarChar = '-';
  25779. private $progressChar = '>';
  25780. private $format = null;
  25781. private $redrawFreq = 1;
  25782. private $lastMessagesLength;
  25783. private $barCharOriginal;
  25784. private $output;
  25785. private $current;
  25786. private $max;
  25787. private $startTime;
  25788. private $defaultFormatVars = array(
  25789. 'current',
  25790. 'max',
  25791. 'bar',
  25792. 'percent',
  25793. 'elapsed',
  25794. );
  25795. private $formatVars;
  25796. private $widths = array(
  25797. 'current' => 4,
  25798. 'max' => 4,
  25799. 'percent' => 3,
  25800. 'elapsed' => 6,
  25801. );
  25802. private $timeFormats = array(
  25803. array(0, '???'),
  25804. array(2, '1 sec'),
  25805. array(59, 'secs', 1),
  25806. array(60, '1 min'),
  25807. array(3600, 'mins', 60),
  25808. array(5400, '1 hr'),
  25809. array(86400, 'hrs', 3600),
  25810. array(129600, '1 day'),
  25811. array(604800, 'days', 86400),
  25812. );
  25813. public function setBarWidth($size)
  25814. {
  25815. $this->barWidth = (int) $size;
  25816. }
  25817. public function setBarCharacter($char)
  25818. {
  25819. $this->barChar = $char;
  25820. }
  25821. public function setEmptyBarCharacter($char)
  25822. {
  25823. $this->emptyBarChar = $char;
  25824. }
  25825. public function setProgressCharacter($char)
  25826. {
  25827. $this->progressChar = $char;
  25828. }
  25829. public function setFormat($format)
  25830. {
  25831. $this->format = $format;
  25832. }
  25833. public function setRedrawFrequency($freq)
  25834. {
  25835. $this->redrawFreq = (int) $freq;
  25836. }
  25837. public function start(OutputInterface $output, $max = null)
  25838. {
  25839. $this->startTime = time();
  25840. $this->current = 0;
  25841. $this->max = (int) $max;
  25842. $this->output = $output->isDecorated() ? $output : new NullOutput();
  25843. $this->lastMessagesLength = 0;
  25844. $this->barCharOriginal = '';
  25845. if (null === $this->format) {
  25846. switch ($output->getVerbosity()) {
  25847. case OutputInterface::VERBOSITY_QUIET:
  25848. $this->format = self::FORMAT_QUIET_NOMAX;
  25849. if ($this->max > 0) {
  25850. $this->format = self::FORMAT_QUIET;
  25851. }
  25852. break;
  25853. case OutputInterface::VERBOSITY_VERBOSE:
  25854. case OutputInterface::VERBOSITY_VERY_VERBOSE:
  25855. case OutputInterface::VERBOSITY_DEBUG:
  25856. $this->format = self::FORMAT_VERBOSE_NOMAX;
  25857. if ($this->max > 0) {
  25858. $this->format = self::FORMAT_VERBOSE;
  25859. }
  25860. break;
  25861. default:
  25862. $this->format = self::FORMAT_NORMAL_NOMAX;
  25863. if ($this->max > 0) {
  25864. $this->format = self::FORMAT_NORMAL;
  25865. }
  25866. break;
  25867. }
  25868. }
  25869. $this->initialize();
  25870. }
  25871. public function advance($step = 1, $redraw = false)
  25872. {
  25873. $this->setCurrent($this->current + $step, $redraw);
  25874. }
  25875. public function setCurrent($current, $redraw = false)
  25876. {
  25877. if (null === $this->startTime) {
  25878. throw new \LogicException('You must start the progress bar before calling setCurrent().');
  25879. }
  25880. $current = (int) $current;
  25881. if ($current < $this->current) {
  25882. throw new \LogicException('You can\'t regress the progress bar');
  25883. }
  25884. if (0 === $this->current) {
  25885. $redraw = true;
  25886. }
  25887. $prevPeriod = (int) ($this->current / $this->redrawFreq);
  25888. $this->current = $current;
  25889. $currPeriod = (int) ($this->current / $this->redrawFreq);
  25890. if ($redraw || $prevPeriod !== $currPeriod || $this->max === $this->current) {
  25891. $this->display();
  25892. }
  25893. }
  25894. public function display($finish = false)
  25895. {
  25896. if (null === $this->startTime) {
  25897. throw new \LogicException('You must start the progress bar before calling display().');
  25898. }
  25899. $message = $this->format;
  25900. foreach ($this->generate($finish) as $name => $value) {
  25901. $message = str_replace("%{$name}%", $value, $message);
  25902. }
  25903. $this->overwrite($this->output, $message);
  25904. }
  25905. public function clear()
  25906. {
  25907. $this->overwrite($this->output, '');
  25908. }
  25909. public function finish()
  25910. {
  25911. if (null === $this->startTime) {
  25912. throw new \LogicException('You must start the progress bar before calling finish().');
  25913. }
  25914. if (null !== $this->startTime) {
  25915. if (!$this->max) {
  25916. $this->barChar = $this->barCharOriginal;
  25917. $this->display(true);
  25918. }
  25919. $this->startTime = null;
  25920. $this->output->writeln('');
  25921. $this->output = null;
  25922. }
  25923. }
  25924. private function initialize()
  25925. {
  25926. $this->formatVars = array();
  25927. foreach ($this->defaultFormatVars as $var) {
  25928. if (false !== strpos($this->format, "%{$var}%")) {
  25929. $this->formatVars[$var] = true;
  25930. }
  25931. }
  25932. if ($this->max > 0) {
  25933. $this->widths['max'] = $this->strlen($this->max);
  25934. $this->widths['current'] = $this->widths['max'];
  25935. } else {
  25936. $this->barCharOriginal = $this->barChar;
  25937. $this->barChar = $this->emptyBarChar;
  25938. }
  25939. }
  25940. private function generate($finish = false)
  25941. {
  25942. $vars = array();
  25943. $percent = 0;
  25944. if ($this->max > 0) {
  25945. $percent = (float) $this->current / $this->max;
  25946. }
  25947. if (isset($this->formatVars['bar'])) {
  25948. $completeBars = 0;
  25949. if ($this->max > 0) {
  25950. $completeBars = floor($percent * $this->barWidth);
  25951. } else {
  25952. if (!$finish) {
  25953. $completeBars = floor($this->current % $this->barWidth);
  25954. } else {
  25955. $completeBars = $this->barWidth;
  25956. }
  25957. }
  25958. $emptyBars = $this->barWidth - $completeBars - $this->strlen($this->progressChar);
  25959. $bar = str_repeat($this->barChar, $completeBars);
  25960. if ($completeBars < $this->barWidth) {
  25961. $bar .= $this->progressChar;
  25962. $bar .= str_repeat($this->emptyBarChar, $emptyBars);
  25963. }
  25964. $vars['bar'] = $bar;
  25965. }
  25966. if (isset($this->formatVars['elapsed'])) {
  25967. $elapsed = time() - $this->startTime;
  25968. $vars['elapsed'] = str_pad($this->humaneTime($elapsed), $this->widths['elapsed'], ' ', STR_PAD_LEFT);
  25969. }
  25970. if (isset($this->formatVars['current'])) {
  25971. $vars['current'] = str_pad($this->current, $this->widths['current'], ' ', STR_PAD_LEFT);
  25972. }
  25973. if (isset($this->formatVars['max'])) {
  25974. $vars['max'] = $this->max;
  25975. }
  25976. if (isset($this->formatVars['percent'])) {
  25977. $vars['percent'] = str_pad(floor($percent * 100), $this->widths['percent'], ' ', STR_PAD_LEFT);
  25978. }
  25979. return $vars;
  25980. }
  25981. private function humaneTime($secs)
  25982. {
  25983. $text = '';
  25984. foreach ($this->timeFormats as $format) {
  25985. if ($secs < $format[0]) {
  25986. if (count($format) == 2) {
  25987. $text = $format[1];
  25988. break;
  25989. } else {
  25990. $text = ceil($secs / $format[2]).' '.$format[1];
  25991. break;
  25992. }
  25993. }
  25994. }
  25995. return $text;
  25996. }
  25997. private function overwrite(OutputInterface $output, $message)
  25998. {
  25999. $length = $this->strlen($message);
  26000. if (null !== $this->lastMessagesLength && $this->lastMessagesLength > $length) {
  26001. $message = str_pad($message, $this->lastMessagesLength, "\x20", STR_PAD_RIGHT);
  26002. }
  26003. $output->write("\x0D");
  26004. $output->write($message);
  26005. $this->lastMessagesLength = $this->strlen($message);
  26006. }
  26007. public function getName()
  26008. {
  26009. return 'progress';
  26010. }
  26011. }
  26012. <?php
  26013. namespace Symfony\Component\Console\Helper;
  26014. use Symfony\Component\Console\Input\InputInterface;
  26015. use Symfony\Component\Console\Output\OutputInterface;
  26016. use Symfony\Component\Console\Formatter\OutputFormatterStyle;
  26017. use Symfony\Component\Console\Question\Question;
  26018. use Symfony\Component\Console\Question\ChoiceQuestion;
  26019. class QuestionHelper extends Helper
  26020. {
  26021. private $inputStream;
  26022. private static $shell;
  26023. private static $stty;
  26024. public function ask(InputInterface $input, OutputInterface $output, Question $question)
  26025. {
  26026. if (!$input->isInteractive()) {
  26027. return $question->getDefault();
  26028. }
  26029. if (!$question->getValidator()) {
  26030. return $this->doAsk($output, $question);
  26031. }
  26032. $that = $this;
  26033. $interviewer = function () use ($output, $question, $that) {
  26034. return $that->doAsk($output, $question);
  26035. };
  26036. return $this->validateAttempts($interviewer, $output, $question);
  26037. }
  26038. public function setInputStream($stream)
  26039. {
  26040. if (!is_resource($stream)) {
  26041. throw new \InvalidArgumentException('Input stream must be a valid resource.');
  26042. }
  26043. $this->inputStream = $stream;
  26044. }
  26045. public function getInputStream()
  26046. {
  26047. return $this->inputStream;
  26048. }
  26049. public function getName()
  26050. {
  26051. return 'question';
  26052. }
  26053. public function doAsk(OutputInterface $output, Question $question)
  26054. {
  26055. $inputStream = $this->inputStream ?: STDIN;
  26056. $message = $question->getQuestion();
  26057. if ($question instanceof ChoiceQuestion) {
  26058. $width = max(array_map('strlen', array_keys($question->getChoices())));
  26059. $messages = (array) $question->getQuestion();
  26060. foreach ($question->getChoices() as $key => $value) {
  26061. $messages[] = sprintf(" [<info>%-${width}s</info>] %s", $key, $value);
  26062. }
  26063. $output->writeln($messages);
  26064. $message = $question->getPrompt();
  26065. }
  26066. $output->write($message);
  26067. $autocomplete = $question->getAutocompleterValues();
  26068. if (null === $autocomplete || !$this->hasSttyAvailable()) {
  26069. $ret = false;
  26070. if ($question->isHidden()) {
  26071. try {
  26072. $ret = trim($this->getHiddenResponse($output, $inputStream));
  26073. } catch (\RuntimeException $e) {
  26074. if (!$question->isHiddenFallback()) {
  26075. throw $e;
  26076. }
  26077. }
  26078. }
  26079. if (false === $ret) {
  26080. $ret = fgets($inputStream, 4096);
  26081. if (false === $ret) {
  26082. throw new \RuntimeException('Aborted');
  26083. }
  26084. $ret = trim($ret);
  26085. }
  26086. } else {
  26087. $ret = trim($this->autocomplete($output, $question, $inputStream));
  26088. }
  26089. $ret = strlen($ret) > 0 ? $ret : $question->getDefault();
  26090. if ($normalizer = $question->getNormalizer()) {
  26091. return $normalizer($ret);
  26092. }
  26093. return $ret;
  26094. }
  26095. private function autocomplete(OutputInterface $output, Question $question, $inputStream)
  26096. {
  26097. $autocomplete = $question->getAutocompleterValues();
  26098. $ret = '';
  26099. $i = 0;
  26100. $ofs = -1;
  26101. $matches = $autocomplete;
  26102. $numMatches = count($matches);
  26103. $sttyMode = shell_exec('stty -g');
  26104. shell_exec('stty -icanon -echo');
  26105. $output->getFormatter()->setStyle('hl', new OutputFormatterStyle('black', 'white'));
  26106. while (!feof($inputStream)) {
  26107. $c = fread($inputStream, 1);
  26108. if ("\177" === $c) {
  26109. if (0 === $numMatches && 0 !== $i) {
  26110. $i--;
  26111. $output->write("\033[1D");
  26112. }
  26113. if ($i === 0) {
  26114. $ofs = -1;
  26115. $matches = $autocomplete;
  26116. $numMatches = count($matches);
  26117. } else {
  26118. $numMatches = 0;
  26119. }
  26120. $ret = substr($ret, 0, $i);
  26121. } elseif ("\033" === $c) {
  26122. $c .= fread($inputStream, 2);
  26123. if (isset($c[2]) && ('A' === $c[2] || 'B' === $c[2])) {
  26124. if ('A' === $c[2] && -1 === $ofs) {
  26125. $ofs = 0;
  26126. }
  26127. if (0 === $numMatches) {
  26128. continue;
  26129. }
  26130. $ofs += ('A' === $c[2]) ? -1 : 1;
  26131. $ofs = ($numMatches + $ofs) % $numMatches;
  26132. }
  26133. } elseif (ord($c) < 32) {
  26134. if ("\t" === $c || "\n" === $c) {
  26135. if ($numMatches > 0 && -1 !== $ofs) {
  26136. $ret = $matches[$ofs];
  26137. $output->write(substr($ret, $i));
  26138. $i = strlen($ret);
  26139. }
  26140. if ("\n" === $c) {
  26141. $output->write($c);
  26142. break;
  26143. }
  26144. $numMatches = 0;
  26145. }
  26146. continue;
  26147. } else {
  26148. $output->write($c);
  26149. $ret .= $c;
  26150. $i++;
  26151. $numMatches = 0;
  26152. $ofs = 0;
  26153. foreach ($autocomplete as $value) {
  26154. if (0 === strpos($value, $ret) && $i !== strlen($value)) {
  26155. $matches[$numMatches++] = $value;
  26156. }
  26157. }
  26158. }
  26159. $output->write("\033[K");
  26160. if ($numMatches > 0 && -1 !== $ofs) {
  26161. $output->write("\0337");
  26162. $output->write('<hl>'.substr($matches[$ofs], $i).'</hl>');
  26163. $output->write("\0338");
  26164. }
  26165. }
  26166. shell_exec(sprintf('stty %s', $sttyMode));
  26167. return $ret;
  26168. }
  26169. private function getHiddenResponse(OutputInterface $output, $inputStream)
  26170. {
  26171. if ('\\' === DIRECTORY_SEPARATOR) {
  26172. $exe = __DIR__.'/../Resources/bin/hiddeninput.exe';
  26173. if ('phar:' === substr(__FILE__, 0, 5)) {
  26174. $tmpExe = sys_get_temp_dir().'/hiddeninput.exe';
  26175. copy($exe, $tmpExe);
  26176. $exe = $tmpExe;
  26177. }
  26178. $value = rtrim(shell_exec($exe));
  26179. $output->writeln('');
  26180. if (isset($tmpExe)) {
  26181. unlink($tmpExe);
  26182. }
  26183. return $value;
  26184. }
  26185. if ($this->hasSttyAvailable()) {
  26186. $sttyMode = shell_exec('stty -g');
  26187. shell_exec('stty -echo');
  26188. $value = fgets($inputStream, 4096);
  26189. shell_exec(sprintf('stty %s', $sttyMode));
  26190. if (false === $value) {
  26191. throw new \RuntimeException('Aborted');
  26192. }
  26193. $value = trim($value);
  26194. $output->writeln('');
  26195. return $value;
  26196. }
  26197. if (false !== $shell = $this->getShell()) {
  26198. $readCmd = $shell === 'csh' ? 'set mypassword = $<' : 'read -r mypassword';
  26199. $command = sprintf("/usr/bin/env %s -c 'stty -echo; %s; stty echo; echo \$mypassword'", $shell, $readCmd);
  26200. $value = rtrim(shell_exec($command));
  26201. $output->writeln('');
  26202. return $value;
  26203. }
  26204. throw new \RuntimeException('Unable to hide the response.');
  26205. }
  26206. private function validateAttempts($interviewer, OutputInterface $output, Question $question)
  26207. {
  26208. $error = null;
  26209. $attempts = $question->getMaxAttempts();
  26210. while (null === $attempts || $attempts--) {
  26211. if (null !== $error) {
  26212. if (null !== $this->getHelperSet() && $this->getHelperSet()->has('formatter')) {
  26213. $message = $this->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error');
  26214. } else {
  26215. $message = '<error>'.$error->getMessage().'</error>';
  26216. }
  26217. $output->writeln($message);
  26218. }
  26219. try {
  26220. return call_user_func($question->getValidator(), $interviewer());
  26221. } catch (\Exception $error) {
  26222. }
  26223. }
  26224. throw $error;
  26225. }
  26226. private function getShell()
  26227. {
  26228. if (null !== self::$shell) {
  26229. return self::$shell;
  26230. }
  26231. self::$shell = false;
  26232. if (file_exists('/usr/bin/env')) {
  26233. $test = "/usr/bin/env %s -c 'echo OK' 2> /dev/null";
  26234. foreach (array('bash', 'zsh', 'ksh', 'csh') as $sh) {
  26235. if ('OK' === rtrim(shell_exec(sprintf($test, $sh)))) {
  26236. self::$shell = $sh;
  26237. break;
  26238. }
  26239. }
  26240. }
  26241. return self::$shell;
  26242. }
  26243. private function hasSttyAvailable()
  26244. {
  26245. if (null !== self::$stty) {
  26246. return self::$stty;
  26247. }
  26248. exec('stty 2>&1', $output, $exitcode);
  26249. return self::$stty = $exitcode === 0;
  26250. }
  26251. }
  26252. <?php
  26253. namespace Symfony\Component\Console\Helper;
  26254. use Symfony\Component\Console\Output\OutputInterface;
  26255. class Table
  26256. {
  26257. private $headers = array();
  26258. private $rows = array();
  26259. private $columnWidths = array();
  26260. private $numberOfColumns;
  26261. private $output;
  26262. private $style;
  26263. private static $styles;
  26264. public function __construct(OutputInterface $output)
  26265. {
  26266. $this->output = $output;
  26267. if (!self::$styles) {
  26268. self::$styles = self::initStyles();
  26269. }
  26270. $this->setStyle('default');
  26271. }
  26272. public static function setStyleDefinition($name, TableStyle $style)
  26273. {
  26274. if (!self::$styles) {
  26275. self::$styles = self::initStyles();
  26276. }
  26277. self::$styles[$name] = $style;
  26278. }
  26279. public static function getStyleDefinition($name)
  26280. {
  26281. if (!self::$styles) {
  26282. self::$styles = self::initStyles();
  26283. }
  26284. if (!self::$styles[$name]) {
  26285. throw new \InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
  26286. }
  26287. return self::$styles[$name];
  26288. }
  26289. public function setStyle($name)
  26290. {
  26291. if ($name instanceof TableStyle) {
  26292. $this->style = $name;
  26293. } elseif (isset(self::$styles[$name])) {
  26294. $this->style = self::$styles[$name];
  26295. } else {
  26296. throw new \InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
  26297. }
  26298. return $this;
  26299. }
  26300. public function getStyle()
  26301. {
  26302. return $this->style;
  26303. }
  26304. public function setHeaders(array $headers)
  26305. {
  26306. $this->headers = array_values($headers);
  26307. return $this;
  26308. }
  26309. public function setRows(array $rows)
  26310. {
  26311. $this->rows = array();
  26312. return $this->addRows($rows);
  26313. }
  26314. public function addRows(array $rows)
  26315. {
  26316. foreach ($rows as $row) {
  26317. $this->addRow($row);
  26318. }
  26319. return $this;
  26320. }
  26321. public function addRow($row)
  26322. {
  26323. if ($row instanceof TableSeparator) {
  26324. $this->rows[] = $row;
  26325. return $this;
  26326. }
  26327. if (!is_array($row)) {
  26328. throw new \InvalidArgumentException('A row must be an array or a TableSeparator instance.');
  26329. }
  26330. $this->rows[] = array_values($row);
  26331. end($this->rows);
  26332. $rowKey = key($this->rows);
  26333. reset($this->rows);
  26334. foreach ($row as $key => $cellValue) {
  26335. if (false === strpos($cellValue, "\n")) {
  26336. continue;
  26337. }
  26338. $lines = explode("\n", $cellValue);
  26339. $this->rows[$rowKey][$key] = $lines[0];
  26340. unset($lines[0]);
  26341. foreach ($lines as $lineKey => $line) {
  26342. $nextRowKey = $rowKey + $lineKey + 1;
  26343. if (isset($this->rows[$nextRowKey])) {
  26344. $this->rows[$nextRowKey][$key] = $line;
  26345. } else {
  26346. $this->rows[$nextRowKey] = array($key => $line);
  26347. }
  26348. }
  26349. }
  26350. return $this;
  26351. }
  26352. public function setRow($column, array $row)
  26353. {
  26354. $this->rows[$column] = $row;
  26355. return $this;
  26356. }
  26357. public function render()
  26358. {
  26359. $this->renderRowSeparator();
  26360. $this->renderRow($this->headers, $this->style->getCellHeaderFormat());
  26361. if (!empty($this->headers)) {
  26362. $this->renderRowSeparator();
  26363. }
  26364. foreach ($this->rows as $row) {
  26365. if ($row instanceof TableSeparator) {
  26366. $this->renderRowSeparator();
  26367. } else {
  26368. $this->renderRow($row, $this->style->getCellRowFormat());
  26369. }
  26370. }
  26371. if (!empty($this->rows)) {
  26372. $this->renderRowSeparator();
  26373. }
  26374. $this->cleanup();
  26375. }
  26376. private function renderRowSeparator()
  26377. {
  26378. if (0 === $count = $this->getNumberOfColumns()) {
  26379. return;
  26380. }
  26381. if (!$this->style->getHorizontalBorderChar() && !$this->style->getCrossingChar()) {
  26382. return;
  26383. }
  26384. $markup = $this->style->getCrossingChar();
  26385. for ($column = 0; $column < $count; $column++) {
  26386. $markup .= str_repeat($this->style->getHorizontalBorderChar(), $this->getColumnWidth($column)).$this->style->getCrossingChar();
  26387. }
  26388. $this->output->writeln(sprintf($this->style->getBorderFormat(), $markup));
  26389. }
  26390. private function renderColumnSeparator()
  26391. {
  26392. $this->output->write(sprintf($this->style->getBorderFormat(), $this->style->getVerticalBorderChar()));
  26393. }
  26394. private function renderRow(array $row, $cellFormat)
  26395. {
  26396. if (empty($row)) {
  26397. return;
  26398. }
  26399. $this->renderColumnSeparator();
  26400. for ($column = 0, $count = $this->getNumberOfColumns(); $column < $count; $column++) {
  26401. $this->renderCell($row, $column, $cellFormat);
  26402. $this->renderColumnSeparator();
  26403. }
  26404. $this->output->writeln('');
  26405. }
  26406. private function renderCell(array $row, $column, $cellFormat)
  26407. {
  26408. $cell = isset($row[$column]) ? $row[$column] : '';
  26409. $width = $this->getColumnWidth($column);
  26410. if (function_exists('mb_strwidth') && false !== $encoding = mb_detect_encoding($cell)) {
  26411. $width += strlen($cell) - mb_strwidth($cell, $encoding);
  26412. }
  26413. $width += Helper::strlen($cell) - Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
  26414. $content = sprintf($this->style->getCellRowContentFormat(), $cell);
  26415. $this->output->write(sprintf($cellFormat, str_pad($content, $width, $this->style->getPaddingChar(), $this->style->getPadType())));
  26416. }
  26417. private function getNumberOfColumns()
  26418. {
  26419. if (null !== $this->numberOfColumns) {
  26420. return $this->numberOfColumns;
  26421. }
  26422. $columns = array(count($this->headers));
  26423. foreach ($this->rows as $row) {
  26424. $columns[] = count($row);
  26425. }
  26426. return $this->numberOfColumns = max($columns);
  26427. }
  26428. private function getColumnWidth($column)
  26429. {
  26430. if (isset($this->columnWidths[$column])) {
  26431. return $this->columnWidths[$column];
  26432. }
  26433. $lengths = array($this->getCellWidth($this->headers, $column));
  26434. foreach ($this->rows as $row) {
  26435. if ($row instanceof TableSeparator) {
  26436. continue;
  26437. }
  26438. $lengths[] = $this->getCellWidth($row, $column);
  26439. }
  26440. return $this->columnWidths[$column] = max($lengths) + strlen($this->style->getCellRowContentFormat()) - 2;
  26441. }
  26442. private function getCellWidth(array $row, $column)
  26443. {
  26444. return isset($row[$column]) ? Helper::strlenWithoutDecoration($this->output->getFormatter(), $row[$column]) : 0;
  26445. }
  26446. private function cleanup()
  26447. {
  26448. $this->columnWidths = array();
  26449. $this->numberOfColumns = null;
  26450. }
  26451. private static function initStyles()
  26452. {
  26453. $borderless = new TableStyle();
  26454. $borderless
  26455. ->setHorizontalBorderChar('=')
  26456. ->setVerticalBorderChar(' ')
  26457. ->setCrossingChar(' ')
  26458. ;
  26459. $compact = new TableStyle();
  26460. $compact
  26461. ->setHorizontalBorderChar('')
  26462. ->setVerticalBorderChar(' ')
  26463. ->setCrossingChar('')
  26464. ->setCellRowContentFormat('%s')
  26465. ;
  26466. return array(
  26467. 'default' => new TableStyle(),
  26468. 'borderless' => $borderless,
  26469. 'compact' => $compact,
  26470. );
  26471. }
  26472. }
  26473. <?php
  26474. namespace Symfony\Component\Console\Helper;
  26475. use Symfony\Component\Console\Output\OutputInterface;
  26476. use Symfony\Component\Console\Output\NullOutput;
  26477. class TableHelper extends Helper
  26478. {
  26479. const LAYOUT_DEFAULT = 0;
  26480. const LAYOUT_BORDERLESS = 1;
  26481. const LAYOUT_COMPACT = 2;
  26482. private $table;
  26483. public function __construct()
  26484. {
  26485. $this->table = new Table(new NullOutput());
  26486. }
  26487. public function setLayout($layout)
  26488. {
  26489. switch ($layout) {
  26490. case self::LAYOUT_BORDERLESS:
  26491. $this->table->setStyle('borderless');
  26492. break;
  26493. case self::LAYOUT_COMPACT:
  26494. $this->table->setStyle('compact');
  26495. break;
  26496. case self::LAYOUT_DEFAULT:
  26497. $this->table->setStyle('default');
  26498. break;
  26499. default:
  26500. throw new \InvalidArgumentException(sprintf('Invalid table layout "%s".', $layout));
  26501. };
  26502. return $this;
  26503. }
  26504. public function setHeaders(array $headers)
  26505. {
  26506. $this->table->setHeaders($headers);
  26507. return $this;
  26508. }
  26509. public function setRows(array $rows)
  26510. {
  26511. $this->table->setRows($rows);
  26512. return $this;
  26513. }
  26514. public function addRows(array $rows)
  26515. {
  26516. $this->table->addRows($rows);
  26517. return $this;
  26518. }
  26519. public function addRow(array $row)
  26520. {
  26521. $this->table->addRow($row);
  26522. return $this;
  26523. }
  26524. public function setRow($column, array $row)
  26525. {
  26526. $this->table->setRow($column, $row);
  26527. return $this;
  26528. }
  26529. public function setPaddingChar($paddingChar)
  26530. {
  26531. $this->table->getStyle()->setPaddingChar($paddingChar);
  26532. return $this;
  26533. }
  26534. public function setHorizontalBorderChar($horizontalBorderChar)
  26535. {
  26536. $this->table->getStyle()->setHorizontalBorderChar($horizontalBorderChar);
  26537. return $this;
  26538. }
  26539. public function setVerticalBorderChar($verticalBorderChar)
  26540. {
  26541. $this->table->getStyle()->setVerticalBorderChar($verticalBorderChar);
  26542. return $this;
  26543. }
  26544. public function setCrossingChar($crossingChar)
  26545. {
  26546. $this->table->getStyle()->setCrossingChar($crossingChar);
  26547. return $this;
  26548. }
  26549. public function setCellHeaderFormat($cellHeaderFormat)
  26550. {
  26551. $this->table->getStyle()->setCellHeaderFormat($cellHeaderFormat);
  26552. return $this;
  26553. }
  26554. public function setCellRowFormat($cellRowFormat)
  26555. {
  26556. $this->table->getStyle()->setCellHeaderFormat($cellRowFormat);
  26557. return $this;
  26558. }
  26559. public function setCellRowContentFormat($cellRowContentFormat)
  26560. {
  26561. $this->table->getStyle()->setCellRowContentFormat($cellRowContentFormat);
  26562. return $this;
  26563. }
  26564. public function setBorderFormat($borderFormat)
  26565. {
  26566. $this->table->getStyle()->setBorderFormat($borderFormat);
  26567. return $this;
  26568. }
  26569. public function setPadType($padType)
  26570. {
  26571. $this->table->getStyle()->setPadType($padType);
  26572. return $this;
  26573. }
  26574. public function render(OutputInterface $output)
  26575. {
  26576. $p = new \ReflectionProperty($this->table, 'output');
  26577. $p->setAccessible(true);
  26578. $p->setValue($this->table, $output);
  26579. $this->table->render();
  26580. }
  26581. public function getName()
  26582. {
  26583. return 'table';
  26584. }
  26585. }
  26586. <?php
  26587. namespace Symfony\Component\Console\Helper;
  26588. class TableSeparator
  26589. {
  26590. }
  26591. <?php
  26592. namespace Symfony\Component\Console\Helper;
  26593. class TableStyle
  26594. {
  26595. private $paddingChar = ' ';
  26596. private $horizontalBorderChar = '-';
  26597. private $verticalBorderChar = '|';
  26598. private $crossingChar = '+';
  26599. private $cellHeaderFormat = '<info>%s</info>';
  26600. private $cellRowFormat = '%s';
  26601. private $cellRowContentFormat = ' %s ';
  26602. private $borderFormat = '%s';
  26603. private $padType = STR_PAD_RIGHT;
  26604. public function setPaddingChar($paddingChar)
  26605. {
  26606. if (!$paddingChar) {
  26607. throw new \LogicException('The padding char must not be empty');
  26608. }
  26609. $this->paddingChar = $paddingChar;
  26610. return $this;
  26611. }
  26612. public function getPaddingChar()
  26613. {
  26614. return $this->paddingChar;
  26615. }
  26616. public function setHorizontalBorderChar($horizontalBorderChar)
  26617. {
  26618. $this->horizontalBorderChar = $horizontalBorderChar;
  26619. return $this;
  26620. }
  26621. public function getHorizontalBorderChar()
  26622. {
  26623. return $this->horizontalBorderChar;
  26624. }
  26625. public function setVerticalBorderChar($verticalBorderChar)
  26626. {
  26627. $this->verticalBorderChar = $verticalBorderChar;
  26628. return $this;
  26629. }
  26630. public function getVerticalBorderChar()
  26631. {
  26632. return $this->verticalBorderChar;
  26633. }
  26634. public function setCrossingChar($crossingChar)
  26635. {
  26636. $this->crossingChar = $crossingChar;
  26637. return $this;
  26638. }
  26639. public function getCrossingChar()
  26640. {
  26641. return $this->crossingChar;
  26642. }
  26643. public function setCellHeaderFormat($cellHeaderFormat)
  26644. {
  26645. $this->cellHeaderFormat = $cellHeaderFormat;
  26646. return $this;
  26647. }
  26648. public function getCellHeaderFormat()
  26649. {
  26650. return $this->cellHeaderFormat;
  26651. }
  26652. public function setCellRowFormat($cellRowFormat)
  26653. {
  26654. $this->cellRowFormat = $cellRowFormat;
  26655. return $this;
  26656. }
  26657. public function getCellRowFormat()
  26658. {
  26659. return $this->cellRowFormat;
  26660. }
  26661. public function setCellRowContentFormat($cellRowContentFormat)
  26662. {
  26663. $this->cellRowContentFormat = $cellRowContentFormat;
  26664. return $this;
  26665. }
  26666. public function getCellRowContentFormat()
  26667. {
  26668. return $this->cellRowContentFormat;
  26669. }
  26670. public function setBorderFormat($borderFormat)
  26671. {
  26672. $this->borderFormat = $borderFormat;
  26673. return $this;
  26674. }
  26675. public function getBorderFormat()
  26676. {
  26677. return $this->borderFormat;
  26678. }
  26679. public function setPadType($padType)
  26680. {
  26681. $this->padType = $padType;
  26682. return $this;
  26683. }
  26684. public function getPadType()
  26685. {
  26686. return $this->padType;
  26687. }
  26688. }
  26689. <?php
  26690. namespace Symfony\Component\Console\Input;
  26691. class ArgvInput extends Input
  26692. {
  26693. private $tokens;
  26694. private $parsed;
  26695. public function __construct(array $argv = null, InputDefinition $definition = null)
  26696. {
  26697. if (null === $argv) {
  26698. $argv = $_SERVER['argv'];
  26699. }
  26700. array_shift($argv);
  26701. $this->tokens = $argv;
  26702. parent::__construct($definition);
  26703. }
  26704. protected function setTokens(array $tokens)
  26705. {
  26706. $this->tokens = $tokens;
  26707. }
  26708. protected function parse()
  26709. {
  26710. $parseOptions = true;
  26711. $this->parsed = $this->tokens;
  26712. while (null !== $token = array_shift($this->parsed)) {
  26713. if ($parseOptions && '' == $token) {
  26714. $this->parseArgument($token);
  26715. } elseif ($parseOptions && '--' == $token) {
  26716. $parseOptions = false;
  26717. } elseif ($parseOptions && 0 === strpos($token, '--')) {
  26718. $this->parseLongOption($token);
  26719. } elseif ($parseOptions && '-' === $token[0] && '-' !== $token) {
  26720. $this->parseShortOption($token);
  26721. } else {
  26722. $this->parseArgument($token);
  26723. }
  26724. }
  26725. }
  26726. private function parseShortOption($token)
  26727. {
  26728. $name = substr($token, 1);
  26729. if (strlen($name) > 1) {
  26730. if ($this->definition->hasShortcut($name[0]) && $this->definition->getOptionForShortcut($name[0])->acceptValue()) {
  26731. $this->addShortOption($name[0], substr($name, 1));
  26732. } else {
  26733. $this->parseShortOptionSet($name);
  26734. }
  26735. } else {
  26736. $this->addShortOption($name, null);
  26737. }
  26738. }
  26739. private function parseShortOptionSet($name)
  26740. {
  26741. $len = strlen($name);
  26742. for ($i = 0; $i < $len; ++$i) {
  26743. if (!$this->definition->hasShortcut($name[$i])) {
  26744. throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $name[$i]));
  26745. }
  26746. $option = $this->definition->getOptionForShortcut($name[$i]);
  26747. if ($option->acceptValue()) {
  26748. $this->addLongOption($option->getName(), $i === $len - 1 ? null : substr($name, $i + 1));
  26749. break;
  26750. } else {
  26751. $this->addLongOption($option->getName(), null);
  26752. }
  26753. }
  26754. }
  26755. private function parseLongOption($token)
  26756. {
  26757. $name = substr($token, 2);
  26758. if (false !== $pos = strpos($name, '=')) {
  26759. $this->addLongOption(substr($name, 0, $pos), substr($name, $pos + 1));
  26760. } else {
  26761. $this->addLongOption($name, null);
  26762. }
  26763. }
  26764. private function parseArgument($token)
  26765. {
  26766. $c = count($this->arguments);
  26767. if ($this->definition->hasArgument($c)) {
  26768. $arg = $this->definition->getArgument($c);
  26769. $this->arguments[$arg->getName()] = $arg->isArray() ? array($token) : $token;
  26770. } elseif ($this->definition->hasArgument($c - 1) && $this->definition->getArgument($c - 1)->isArray()) {
  26771. $arg = $this->definition->getArgument($c - 1);
  26772. $this->arguments[$arg->getName()][] = $token;
  26773. } else {
  26774. throw new \RuntimeException('Too many arguments.');
  26775. }
  26776. }
  26777. private function addShortOption($shortcut, $value)
  26778. {
  26779. if (!$this->definition->hasShortcut($shortcut)) {
  26780. throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $shortcut));
  26781. }
  26782. $this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
  26783. }
  26784. private function addLongOption($name, $value)
  26785. {
  26786. if (!$this->definition->hasOption($name)) {
  26787. throw new \RuntimeException(sprintf('The "--%s" option does not exist.', $name));
  26788. }
  26789. $option = $this->definition->getOption($name);
  26790. if (false === $value) {
  26791. $value = null;
  26792. }
  26793. if (null !== $value && !$option->acceptValue()) {
  26794. throw new \RuntimeException(sprintf('The "--%s" option does not accept a value.', $name));
  26795. }
  26796. if (null === $value && $option->acceptValue() && count($this->parsed)) {
  26797. $next = array_shift($this->parsed);
  26798. if (isset($next[0]) && '-' !== $next[0]) {
  26799. $value = $next;
  26800. } elseif (empty($next)) {
  26801. $value = '';
  26802. } else {
  26803. array_unshift($this->parsed, $next);
  26804. }
  26805. }
  26806. if (null === $value) {
  26807. if ($option->isValueRequired()) {
  26808. throw new \RuntimeException(sprintf('The "--%s" option requires a value.', $name));
  26809. }
  26810. if (!$option->isArray()) {
  26811. $value = $option->isValueOptional() ? $option->getDefault() : true;
  26812. }
  26813. }
  26814. if ($option->isArray()) {
  26815. $this->options[$name][] = $value;
  26816. } else {
  26817. $this->options[$name] = $value;
  26818. }
  26819. }
  26820. public function getFirstArgument()
  26821. {
  26822. foreach ($this->tokens as $token) {
  26823. if ($token && '-' === $token[0]) {
  26824. continue;
  26825. }
  26826. return $token;
  26827. }
  26828. }
  26829. public function hasParameterOption($values)
  26830. {
  26831. $values = (array) $values;
  26832. foreach ($this->tokens as $token) {
  26833. foreach ($values as $value) {
  26834. if ($token === $value || 0 === strpos($token, $value.'=')) {
  26835. return true;
  26836. }
  26837. }
  26838. }
  26839. return false;
  26840. }
  26841. public function getParameterOption($values, $default = false)
  26842. {
  26843. $values = (array) $values;
  26844. $tokens = $this->tokens;
  26845. while (0 < count($tokens)) {
  26846. $token = array_shift($tokens);
  26847. foreach ($values as $value) {
  26848. if ($token === $value || 0 === strpos($token, $value.'=')) {
  26849. if (false !== $pos = strpos($token, '=')) {
  26850. return substr($token, $pos + 1);
  26851. }
  26852. return array_shift($tokens);
  26853. }
  26854. }
  26855. }
  26856. return $default;
  26857. }
  26858. public function __toString()
  26859. {
  26860. $self = $this;
  26861. $tokens = array_map(function ($token) use ($self) {
  26862. if (preg_match('{^(-[^=]+=)(.+)}', $token, $match)) {
  26863. return $match[1].$self->escapeToken($match[2]);
  26864. }
  26865. if ($token && $token[0] !== '-') {
  26866. return $self->escapeToken($token);
  26867. }
  26868. return $token;
  26869. }, $this->tokens);
  26870. return implode(' ', $tokens);
  26871. }
  26872. }
  26873. <?php
  26874. namespace Symfony\Component\Console\Input;
  26875. class ArrayInput extends Input
  26876. {
  26877. private $parameters;
  26878. public function __construct(array $parameters, InputDefinition $definition = null)
  26879. {
  26880. $this->parameters = $parameters;
  26881. parent::__construct($definition);
  26882. }
  26883. public function getFirstArgument()
  26884. {
  26885. foreach ($this->parameters as $key => $value) {
  26886. if ($key && '-' === $key[0]) {
  26887. continue;
  26888. }
  26889. return $value;
  26890. }
  26891. }
  26892. public function hasParameterOption($values)
  26893. {
  26894. $values = (array) $values;
  26895. foreach ($this->parameters as $k => $v) {
  26896. if (!is_int($k)) {
  26897. $v = $k;
  26898. }
  26899. if (in_array($v, $values)) {
  26900. return true;
  26901. }
  26902. }
  26903. return false;
  26904. }
  26905. public function getParameterOption($values, $default = false)
  26906. {
  26907. $values = (array) $values;
  26908. foreach ($this->parameters as $k => $v) {
  26909. if (is_int($k)) {
  26910. if (in_array($v, $values)) {
  26911. return true;
  26912. }
  26913. } elseif (in_array($k, $values)) {
  26914. return $v;
  26915. }
  26916. }
  26917. return $default;
  26918. }
  26919. public function __toString()
  26920. {
  26921. $params = array();
  26922. foreach ($this->parameters as $param => $val) {
  26923. if ($param && '-' === $param[0]) {
  26924. $params[] = $param.('' != $val ? '='.$this->escapeToken($val) : '');
  26925. } else {
  26926. $params[] = $this->escapeToken($val);
  26927. }
  26928. }
  26929. return implode(' ', $params);
  26930. }
  26931. protected function parse()
  26932. {
  26933. foreach ($this->parameters as $key => $value) {
  26934. if (0 === strpos($key, '--')) {
  26935. $this->addLongOption(substr($key, 2), $value);
  26936. } elseif ('-' === $key[0]) {
  26937. $this->addShortOption(substr($key, 1), $value);
  26938. } else {
  26939. $this->addArgument($key, $value);
  26940. }
  26941. }
  26942. }
  26943. private function addShortOption($shortcut, $value)
  26944. {
  26945. if (!$this->definition->hasShortcut($shortcut)) {
  26946. throw new \InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut));
  26947. }
  26948. $this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
  26949. }
  26950. private function addLongOption($name, $value)
  26951. {
  26952. if (!$this->definition->hasOption($name)) {
  26953. throw new \InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name));
  26954. }
  26955. $option = $this->definition->getOption($name);
  26956. if (null === $value) {
  26957. if ($option->isValueRequired()) {
  26958. throw new \InvalidArgumentException(sprintf('The "--%s" option requires a value.', $name));
  26959. }
  26960. $value = $option->isValueOptional() ? $option->getDefault() : true;
  26961. }
  26962. $this->options[$name] = $value;
  26963. }
  26964. private function addArgument($name, $value)
  26965. {
  26966. if (!$this->definition->hasArgument($name)) {
  26967. throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
  26968. }
  26969. $this->arguments[$name] = $value;
  26970. }
  26971. }
  26972. <?php
  26973. namespace Symfony\Component\Console\Input;
  26974. abstract class Input implements InputInterface
  26975. {
  26976. protected $definition;
  26977. protected $options = array();
  26978. protected $arguments = array();
  26979. protected $interactive = true;
  26980. public function __construct(InputDefinition $definition = null)
  26981. {
  26982. if (null === $definition) {
  26983. $this->definition = new InputDefinition();
  26984. } else {
  26985. $this->bind($definition);
  26986. $this->validate();
  26987. }
  26988. }
  26989. public function bind(InputDefinition $definition)
  26990. {
  26991. $this->arguments = array();
  26992. $this->options = array();
  26993. $this->definition = $definition;
  26994. $this->parse();
  26995. }
  26996. abstract protected function parse();
  26997. public function validate()
  26998. {
  26999. if (count($this->arguments) < $this->definition->getArgumentRequiredCount()) {
  27000. throw new \RuntimeException('Not enough arguments.');
  27001. }
  27002. }
  27003. public function isInteractive()
  27004. {
  27005. return $this->interactive;
  27006. }
  27007. public function setInteractive($interactive)
  27008. {
  27009. $this->interactive = (bool) $interactive;
  27010. }
  27011. public function getArguments()
  27012. {
  27013. return array_merge($this->definition->getArgumentDefaults(), $this->arguments);
  27014. }
  27015. public function getArgument($name)
  27016. {
  27017. if (!$this->definition->hasArgument($name)) {
  27018. throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
  27019. }
  27020. return isset($this->arguments[$name]) ? $this->arguments[$name] : $this->definition->getArgument($name)->getDefault();
  27021. }
  27022. public function setArgument($name, $value)
  27023. {
  27024. if (!$this->definition->hasArgument($name)) {
  27025. throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
  27026. }
  27027. $this->arguments[$name] = $value;
  27028. }
  27029. public function hasArgument($name)
  27030. {
  27031. return $this->definition->hasArgument($name);
  27032. }
  27033. public function getOptions()
  27034. {
  27035. return array_merge($this->definition->getOptionDefaults(), $this->options);
  27036. }
  27037. public function getOption($name)
  27038. {
  27039. if (!$this->definition->hasOption($name)) {
  27040. throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
  27041. }
  27042. return isset($this->options[$name]) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
  27043. }
  27044. public function setOption($name, $value)
  27045. {
  27046. if (!$this->definition->hasOption($name)) {
  27047. throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
  27048. }
  27049. $this->options[$name] = $value;
  27050. }
  27051. public function hasOption($name)
  27052. {
  27053. return $this->definition->hasOption($name);
  27054. }
  27055. public function escapeToken($token)
  27056. {
  27057. return preg_match('{^[\w-]+$}', $token) ? $token : escapeshellarg($token);
  27058. }
  27059. }
  27060. <?php
  27061. namespace Symfony\Component\Console\Input;
  27062. class InputArgument
  27063. {
  27064. const REQUIRED = 1;
  27065. const OPTIONAL = 2;
  27066. const IS_ARRAY = 4;
  27067. private $name;
  27068. private $mode;
  27069. private $default;
  27070. private $description;
  27071. public function __construct($name, $mode = null, $description = '', $default = null)
  27072. {
  27073. if (null === $mode) {
  27074. $mode = self::OPTIONAL;
  27075. } elseif (!is_int($mode) || $mode > 7 || $mode < 1) {
  27076. throw new \InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode));
  27077. }
  27078. $this->name = $name;
  27079. $this->mode = $mode;
  27080. $this->description = $description;
  27081. $this->setDefault($default);
  27082. }
  27083. public function getName()
  27084. {
  27085. return $this->name;
  27086. }
  27087. public function isRequired()
  27088. {
  27089. return self::REQUIRED === (self::REQUIRED & $this->mode);
  27090. }
  27091. public function isArray()
  27092. {
  27093. return self::IS_ARRAY === (self::IS_ARRAY & $this->mode);
  27094. }
  27095. public function setDefault($default = null)
  27096. {
  27097. if (self::REQUIRED === $this->mode && null !== $default) {
  27098. throw new \LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.');
  27099. }
  27100. if ($this->isArray()) {
  27101. if (null === $default) {
  27102. $default = array();
  27103. } elseif (!is_array($default)) {
  27104. throw new \LogicException('A default value for an array argument must be an array.');
  27105. }
  27106. }
  27107. $this->default = $default;
  27108. }
  27109. public function getDefault()
  27110. {
  27111. return $this->default;
  27112. }
  27113. public function getDescription()
  27114. {
  27115. return $this->description;
  27116. }
  27117. }
  27118. <?php
  27119. namespace Symfony\Component\Console\Input;
  27120. interface InputAwareInterface
  27121. {
  27122. public function setInput(InputInterface $input);
  27123. }
  27124. <?php
  27125. namespace Symfony\Component\Console\Input;
  27126. use Symfony\Component\Console\Descriptor\TextDescriptor;
  27127. use Symfony\Component\Console\Descriptor\XmlDescriptor;
  27128. use Symfony\Component\Console\Output\BufferedOutput;
  27129. class InputDefinition
  27130. {
  27131. private $arguments;
  27132. private $requiredCount;
  27133. private $hasAnArrayArgument = false;
  27134. private $hasOptional;
  27135. private $options;
  27136. private $shortcuts;
  27137. public function __construct(array $definition = array())
  27138. {
  27139. $this->setDefinition($definition);
  27140. }
  27141. public function setDefinition(array $definition)
  27142. {
  27143. $arguments = array();
  27144. $options = array();
  27145. foreach ($definition as $item) {
  27146. if ($item instanceof InputOption) {
  27147. $options[] = $item;
  27148. } else {
  27149. $arguments[] = $item;
  27150. }
  27151. }
  27152. $this->setArguments($arguments);
  27153. $this->setOptions($options);
  27154. }
  27155. public function setArguments($arguments = array())
  27156. {
  27157. $this->arguments = array();
  27158. $this->requiredCount = 0;
  27159. $this->hasOptional = false;
  27160. $this->hasAnArrayArgument = false;
  27161. $this->addArguments($arguments);
  27162. }
  27163. public function addArguments($arguments = array())
  27164. {
  27165. if (null !== $arguments) {
  27166. foreach ($arguments as $argument) {
  27167. $this->addArgument($argument);
  27168. }
  27169. }
  27170. }
  27171. public function addArgument(InputArgument $argument)
  27172. {
  27173. if (isset($this->arguments[$argument->getName()])) {
  27174. throw new \LogicException(sprintf('An argument with name "%s" already exists.', $argument->getName()));
  27175. }
  27176. if ($this->hasAnArrayArgument) {
  27177. throw new \LogicException('Cannot add an argument after an array argument.');
  27178. }
  27179. if ($argument->isRequired() && $this->hasOptional) {
  27180. throw new \LogicException('Cannot add a required argument after an optional one.');
  27181. }
  27182. if ($argument->isArray()) {
  27183. $this->hasAnArrayArgument = true;
  27184. }
  27185. if ($argument->isRequired()) {
  27186. ++$this->requiredCount;
  27187. } else {
  27188. $this->hasOptional = true;
  27189. }
  27190. $this->arguments[$argument->getName()] = $argument;
  27191. }
  27192. public function getArgument($name)
  27193. {
  27194. if (!$this->hasArgument($name)) {
  27195. throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
  27196. }
  27197. $arguments = is_int($name) ? array_values($this->arguments) : $this->arguments;
  27198. return $arguments[$name];
  27199. }
  27200. public function hasArgument($name)
  27201. {
  27202. $arguments = is_int($name) ? array_values($this->arguments) : $this->arguments;
  27203. return isset($arguments[$name]);
  27204. }
  27205. public function getArguments()
  27206. {
  27207. return $this->arguments;
  27208. }
  27209. public function getArgumentCount()
  27210. {
  27211. return $this->hasAnArrayArgument ? PHP_INT_MAX : count($this->arguments);
  27212. }
  27213. public function getArgumentRequiredCount()
  27214. {
  27215. return $this->requiredCount;
  27216. }
  27217. public function getArgumentDefaults()
  27218. {
  27219. $values = array();
  27220. foreach ($this->arguments as $argument) {
  27221. $values[$argument->getName()] = $argument->getDefault();
  27222. }
  27223. return $values;
  27224. }
  27225. public function setOptions($options = array())
  27226. {
  27227. $this->options = array();
  27228. $this->shortcuts = array();
  27229. $this->addOptions($options);
  27230. }
  27231. public function addOptions($options = array())
  27232. {
  27233. foreach ($options as $option) {
  27234. $this->addOption($option);
  27235. }
  27236. }
  27237. public function addOption(InputOption $option)
  27238. {
  27239. if (isset($this->options[$option->getName()]) && !$option->equals($this->options[$option->getName()])) {
  27240. throw new \LogicException(sprintf('An option named "%s" already exists.', $option->getName()));
  27241. }
  27242. if ($option->getShortcut()) {
  27243. foreach (explode('|', $option->getShortcut()) as $shortcut) {
  27244. if (isset($this->shortcuts[$shortcut]) && !$option->equals($this->options[$this->shortcuts[$shortcut]])) {
  27245. throw new \LogicException(sprintf('An option with shortcut "%s" already exists.', $shortcut));
  27246. }
  27247. }
  27248. }
  27249. $this->options[$option->getName()] = $option;
  27250. if ($option->getShortcut()) {
  27251. foreach (explode('|', $option->getShortcut()) as $shortcut) {
  27252. $this->shortcuts[$shortcut] = $option->getName();
  27253. }
  27254. }
  27255. }
  27256. public function getOption($name)
  27257. {
  27258. if (!$this->hasOption($name)) {
  27259. throw new \InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name));
  27260. }
  27261. return $this->options[$name];
  27262. }
  27263. public function hasOption($name)
  27264. {
  27265. return isset($this->options[$name]);
  27266. }
  27267. public function getOptions()
  27268. {
  27269. return $this->options;
  27270. }
  27271. public function hasShortcut($name)
  27272. {
  27273. return isset($this->shortcuts[$name]);
  27274. }
  27275. public function getOptionForShortcut($shortcut)
  27276. {
  27277. return $this->getOption($this->shortcutToName($shortcut));
  27278. }
  27279. public function getOptionDefaults()
  27280. {
  27281. $values = array();
  27282. foreach ($this->options as $option) {
  27283. $values[$option->getName()] = $option->getDefault();
  27284. }
  27285. return $values;
  27286. }
  27287. private function shortcutToName($shortcut)
  27288. {
  27289. if (!isset($this->shortcuts[$shortcut])) {
  27290. throw new \InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut));
  27291. }
  27292. return $this->shortcuts[$shortcut];
  27293. }
  27294. public function getSynopsis()
  27295. {
  27296. $elements = array();
  27297. foreach ($this->getOptions() as $option) {
  27298. $shortcut = $option->getShortcut() ? sprintf('-%s|', $option->getShortcut()) : '';
  27299. $elements[] = sprintf('['.($option->isValueRequired() ? '%s--%s="..."' : ($option->isValueOptional() ? '%s--%s[="..."]' : '%s--%s')).']', $shortcut, $option->getName());
  27300. }
  27301. foreach ($this->getArguments() as $argument) {
  27302. $elements[] = sprintf($argument->isRequired() ? '%s' : '[%s]', $argument->getName().($argument->isArray() ? '1' : ''));
  27303. if ($argument->isArray()) {
  27304. $elements[] = sprintf('... [%sN]', $argument->getName());
  27305. }
  27306. }
  27307. return implode(' ', $elements);
  27308. }
  27309. public function asText()
  27310. {
  27311. $descriptor = new TextDescriptor();
  27312. $output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true);
  27313. $descriptor->describe($output, $this, array('raw_output' => true));
  27314. return $output->fetch();
  27315. }
  27316. public function asXml($asDom = false)
  27317. {
  27318. $descriptor = new XmlDescriptor();
  27319. if ($asDom) {
  27320. return $descriptor->getInputDefinitionDocument($this);
  27321. }
  27322. $output = new BufferedOutput();
  27323. $descriptor->describe($output, $this);
  27324. return $output->fetch();
  27325. }
  27326. }
  27327. <?php
  27328. namespace Symfony\Component\Console\Input;
  27329. interface InputInterface
  27330. {
  27331. public function getFirstArgument();
  27332. public function hasParameterOption($values);
  27333. public function getParameterOption($values, $default = false);
  27334. public function bind(InputDefinition $definition);
  27335. public function validate();
  27336. public function getArguments();
  27337. public function getArgument($name);
  27338. public function setArgument($name, $value);
  27339. public function hasArgument($name);
  27340. public function getOptions();
  27341. public function getOption($name);
  27342. public function setOption($name, $value);
  27343. public function hasOption($name);
  27344. public function isInteractive();
  27345. public function setInteractive($interactive);
  27346. }
  27347. <?php
  27348. namespace Symfony\Component\Console\Input;
  27349. class InputOption
  27350. {
  27351. const VALUE_NONE = 1;
  27352. const VALUE_REQUIRED = 2;
  27353. const VALUE_OPTIONAL = 4;
  27354. const VALUE_IS_ARRAY = 8;
  27355. private $name;
  27356. private $shortcut;
  27357. private $mode;
  27358. private $default;
  27359. private $description;
  27360. public function __construct($name, $shortcut = null, $mode = null, $description = '', $default = null)
  27361. {
  27362. if (0 === strpos($name, '--')) {
  27363. $name = substr($name, 2);
  27364. }
  27365. if (empty($name)) {
  27366. throw new \InvalidArgumentException('An option name cannot be empty.');
  27367. }
  27368. if (empty($shortcut)) {
  27369. $shortcut = null;
  27370. }
  27371. if (null !== $shortcut) {
  27372. if (is_array($shortcut)) {
  27373. $shortcut = implode('|', $shortcut);
  27374. }
  27375. $shortcuts = preg_split('{(\|)-?}', ltrim($shortcut, '-'));
  27376. $shortcuts = array_filter($shortcuts);
  27377. $shortcut = implode('|', $shortcuts);
  27378. if (empty($shortcut)) {
  27379. throw new \InvalidArgumentException('An option shortcut cannot be empty.');
  27380. }
  27381. }
  27382. if (null === $mode) {
  27383. $mode = self::VALUE_NONE;
  27384. } elseif (!is_int($mode) || $mode > 15 || $mode < 1) {
  27385. throw new \InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode));
  27386. }
  27387. $this->name = $name;
  27388. $this->shortcut = $shortcut;
  27389. $this->mode = $mode;
  27390. $this->description = $description;
  27391. if ($this->isArray() && !$this->acceptValue()) {
  27392. throw new \InvalidArgumentException('Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.');
  27393. }
  27394. $this->setDefault($default);
  27395. }
  27396. public function getShortcut()
  27397. {
  27398. return $this->shortcut;
  27399. }
  27400. public function getName()
  27401. {
  27402. return $this->name;
  27403. }
  27404. public function acceptValue()
  27405. {
  27406. return $this->isValueRequired() || $this->isValueOptional();
  27407. }
  27408. public function isValueRequired()
  27409. {
  27410. return self::VALUE_REQUIRED === (self::VALUE_REQUIRED & $this->mode);
  27411. }
  27412. public function isValueOptional()
  27413. {
  27414. return self::VALUE_OPTIONAL === (self::VALUE_OPTIONAL & $this->mode);
  27415. }
  27416. public function isArray()
  27417. {
  27418. return self::VALUE_IS_ARRAY === (self::VALUE_IS_ARRAY & $this->mode);
  27419. }
  27420. public function setDefault($default = null)
  27421. {
  27422. if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) {
  27423. throw new \LogicException('Cannot set a default value when using InputOption::VALUE_NONE mode.');
  27424. }
  27425. if ($this->isArray()) {
  27426. if (null === $default) {
  27427. $default = array();
  27428. } elseif (!is_array($default)) {
  27429. throw new \LogicException('A default value for an array option must be an array.');
  27430. }
  27431. }
  27432. $this->default = $this->acceptValue() ? $default : false;
  27433. }
  27434. public function getDefault()
  27435. {
  27436. return $this->default;
  27437. }
  27438. public function getDescription()
  27439. {
  27440. return $this->description;
  27441. }
  27442. public function equals(InputOption $option)
  27443. {
  27444. return $option->getName() === $this->getName()
  27445. && $option->getShortcut() === $this->getShortcut()
  27446. && $option->getDefault() === $this->getDefault()
  27447. && $option->isArray() === $this->isArray()
  27448. && $option->isValueRequired() === $this->isValueRequired()
  27449. && $option->isValueOptional() === $this->isValueOptional()
  27450. ;
  27451. }
  27452. }
  27453. <?php
  27454. namespace Symfony\Component\Console\Input;
  27455. class StringInput extends ArgvInput
  27456. {
  27457. const REGEX_STRING = '([^\s]+?)(?:\s|(?<!\\\\)"|(?<!\\\\)\'|$)';
  27458. const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')';
  27459. public function __construct($input, InputDefinition $definition = null)
  27460. {
  27461. parent::__construct(array(), null);
  27462. $this->setTokens($this->tokenize($input));
  27463. if (null !== $definition) {
  27464. $this->bind($definition);
  27465. }
  27466. }
  27467. private function tokenize($input)
  27468. {
  27469. $tokens = array();
  27470. $length = strlen($input);
  27471. $cursor = 0;
  27472. while ($cursor < $length) {
  27473. if (preg_match('/\s+/A', $input, $match, null, $cursor)) {
  27474. } elseif (preg_match('/([^="\'\s]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, null, $cursor)) {
  27475. $tokens[] = $match[1].$match[2].stripcslashes(str_replace(array('"\'', '\'"', '\'\'', '""'), '', substr($match[3], 1, strlen($match[3]) - 2)));
  27476. } elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, null, $cursor)) {
  27477. $tokens[] = stripcslashes(substr($match[0], 1, strlen($match[0]) - 2));
  27478. } elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, null, $cursor)) {
  27479. $tokens[] = stripcslashes($match[1]);
  27480. } else {
  27481. throw new \InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10)));
  27482. }
  27483. $cursor += strlen($match[0]);
  27484. }
  27485. return $tokens;
  27486. }
  27487. }
  27488. Copyright (c) 2004-2015 Fabien Potencier
  27489. Permission is hereby granted, free of charge, to any person obtaining a copy
  27490. of this software and associated documentation files (the "Software"), to deal
  27491. in the Software without restriction, including without limitation the rights
  27492. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  27493. copies of the Software, and to permit persons to whom the Software is furnished
  27494. to do so, subject to the following conditions:
  27495. The above copyright notice and this permission notice shall be included in all
  27496. copies or substantial portions of the Software.
  27497. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  27498. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  27499. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  27500. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27501. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  27502. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  27503. THE SOFTWARE.
  27504. <?php
  27505. namespace Symfony\Component\Console\Logger;
  27506. use Psr\Log\AbstractLogger;
  27507. use Psr\Log\InvalidArgumentException;
  27508. use Psr\Log\LogLevel;
  27509. use Symfony\Component\Console\Output\OutputInterface;
  27510. use Symfony\Component\Console\Output\ConsoleOutputInterface;
  27511. class ConsoleLogger extends AbstractLogger
  27512. {
  27513. const INFO = 'info';
  27514. const ERROR = 'error';
  27515. private $output;
  27516. private $verbosityLevelMap = array(
  27517. LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL,
  27518. LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL,
  27519. LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL,
  27520. LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL,
  27521. LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL,
  27522. LogLevel::NOTICE => OutputInterface::VERBOSITY_VERBOSE,
  27523. LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE,
  27524. LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG,
  27525. );
  27526. private $formatLevelMap = array(
  27527. LogLevel::EMERGENCY => self::ERROR,
  27528. LogLevel::ALERT => self::ERROR,
  27529. LogLevel::CRITICAL => self::ERROR,
  27530. LogLevel::ERROR => self::ERROR,
  27531. LogLevel::WARNING => self::INFO,
  27532. LogLevel::NOTICE => self::INFO,
  27533. LogLevel::INFO => self::INFO,
  27534. LogLevel::DEBUG => self::INFO,
  27535. );
  27536. public function __construct(OutputInterface $output, array $verbosityLevelMap = array(), array $formatLevelMap = array())
  27537. {
  27538. $this->output = $output;
  27539. $this->verbosityLevelMap = $verbosityLevelMap + $this->verbosityLevelMap;
  27540. $this->formatLevelMap = $formatLevelMap + $this->formatLevelMap;
  27541. }
  27542. public function log($level, $message, array $context = array())
  27543. {
  27544. if (!isset($this->verbosityLevelMap[$level])) {
  27545. throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level));
  27546. }
  27547. if ($this->formatLevelMap[$level] === self::ERROR && $this->output instanceof ConsoleOutputInterface) {
  27548. $output = $this->output->getErrorOutput();
  27549. } else {
  27550. $output = $this->output;
  27551. }
  27552. if ($output->getVerbosity() >= $this->verbosityLevelMap[$level]) {
  27553. $output->writeln(sprintf('<%1$s>[%2$s] %3$s</%1$s>', $this->formatLevelMap[$level], $level, $this->interpolate($message, $context)));
  27554. }
  27555. }
  27556. private function interpolate($message, array $context)
  27557. {
  27558. $replace = array();
  27559. foreach ($context as $key => $val) {
  27560. if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString'))) {
  27561. $replace[sprintf('{%s}', $key)] = $val;
  27562. }
  27563. }
  27564. return strtr($message, $replace);
  27565. }
  27566. }
  27567. <?php
  27568. namespace Symfony\Component\Console\Output;
  27569. class BufferedOutput extends Output
  27570. {
  27571. private $buffer = '';
  27572. public function fetch()
  27573. {
  27574. $content = $this->buffer;
  27575. $this->buffer = '';
  27576. return $content;
  27577. }
  27578. protected function doWrite($message, $newline)
  27579. {
  27580. $this->buffer .= $message;
  27581. if ($newline) {
  27582. $this->buffer .= "\n";
  27583. }
  27584. }
  27585. }
  27586. <?php
  27587. namespace Symfony\Component\Console\Output;
  27588. use Symfony\Component\Console\Formatter\OutputFormatterInterface;
  27589. class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
  27590. {
  27591. private $stderr;
  27592. public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
  27593. {
  27594. parent::__construct($this->openOutputStream(), $verbosity, $decorated, $formatter);
  27595. $this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated, $this->getFormatter());
  27596. }
  27597. public function setDecorated($decorated)
  27598. {
  27599. parent::setDecorated($decorated);
  27600. $this->stderr->setDecorated($decorated);
  27601. }
  27602. public function setFormatter(OutputFormatterInterface $formatter)
  27603. {
  27604. parent::setFormatter($formatter);
  27605. $this->stderr->setFormatter($formatter);
  27606. }
  27607. public function setVerbosity($level)
  27608. {
  27609. parent::setVerbosity($level);
  27610. $this->stderr->setVerbosity($level);
  27611. }
  27612. public function getErrorOutput()
  27613. {
  27614. return $this->stderr;
  27615. }
  27616. public function setErrorOutput(OutputInterface $error)
  27617. {
  27618. $this->stderr = $error;
  27619. }
  27620. protected function hasStdoutSupport()
  27621. {
  27622. return false === $this->isRunningOS400();
  27623. }
  27624. protected function hasStderrSupport()
  27625. {
  27626. return false === $this->isRunningOS400();
  27627. }
  27628. private function isRunningOS400()
  27629. {
  27630. return 'OS400' === php_uname('s');
  27631. }
  27632. private function openOutputStream()
  27633. {
  27634. $outputStream = $this->hasStdoutSupport() ? 'php://stdout' : 'php://output';
  27635. return @fopen($outputStream, 'w') ?: fopen('php://output', 'w');
  27636. }
  27637. private function openErrorStream()
  27638. {
  27639. $errorStream = $this->hasStderrSupport() ? 'php://stderr' : 'php://output';
  27640. return fopen($errorStream, 'w');
  27641. }
  27642. }
  27643. <?php
  27644. namespace Symfony\Component\Console\Output;
  27645. interface ConsoleOutputInterface extends OutputInterface
  27646. {
  27647. public function getErrorOutput();
  27648. public function setErrorOutput(OutputInterface $error);
  27649. }
  27650. <?php
  27651. namespace Symfony\Component\Console\Output;
  27652. use Symfony\Component\Console\Formatter\OutputFormatter;
  27653. use Symfony\Component\Console\Formatter\OutputFormatterInterface;
  27654. class NullOutput implements OutputInterface
  27655. {
  27656. public function setFormatter(OutputFormatterInterface $formatter)
  27657. {
  27658. }
  27659. public function getFormatter()
  27660. {
  27661. return new OutputFormatter();
  27662. }
  27663. public function setDecorated($decorated)
  27664. {
  27665. }
  27666. public function isDecorated()
  27667. {
  27668. return false;
  27669. }
  27670. public function setVerbosity($level)
  27671. {
  27672. }
  27673. public function getVerbosity()
  27674. {
  27675. return self::VERBOSITY_QUIET;
  27676. }
  27677. public function isQuiet()
  27678. {
  27679. return true;
  27680. }
  27681. public function isVerbose()
  27682. {
  27683. return false;
  27684. }
  27685. public function isVeryVerbose()
  27686. {
  27687. return false;
  27688. }
  27689. public function isDebug()
  27690. {
  27691. return false;
  27692. }
  27693. public function writeln($messages, $type = self::OUTPUT_NORMAL)
  27694. {
  27695. }
  27696. public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL)
  27697. {
  27698. }
  27699. }
  27700. <?php
  27701. namespace Symfony\Component\Console\Output;
  27702. use Symfony\Component\Console\Formatter\OutputFormatterInterface;
  27703. use Symfony\Component\Console\Formatter\OutputFormatter;
  27704. abstract class Output implements OutputInterface
  27705. {
  27706. private $verbosity;
  27707. private $formatter;
  27708. public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = false, OutputFormatterInterface $formatter = null)
  27709. {
  27710. $this->verbosity = null === $verbosity ? self::VERBOSITY_NORMAL : $verbosity;
  27711. $this->formatter = $formatter ?: new OutputFormatter();
  27712. $this->formatter->setDecorated($decorated);
  27713. }
  27714. public function setFormatter(OutputFormatterInterface $formatter)
  27715. {
  27716. $this->formatter = $formatter;
  27717. }
  27718. public function getFormatter()
  27719. {
  27720. return $this->formatter;
  27721. }
  27722. public function setDecorated($decorated)
  27723. {
  27724. $this->formatter->setDecorated($decorated);
  27725. }
  27726. public function isDecorated()
  27727. {
  27728. return $this->formatter->isDecorated();
  27729. }
  27730. public function setVerbosity($level)
  27731. {
  27732. $this->verbosity = (int) $level;
  27733. }
  27734. public function getVerbosity()
  27735. {
  27736. return $this->verbosity;
  27737. }
  27738. public function isQuiet()
  27739. {
  27740. return self::VERBOSITY_QUIET === $this->verbosity;
  27741. }
  27742. public function isVerbose()
  27743. {
  27744. return self::VERBOSITY_VERBOSE <= $this->verbosity;
  27745. }
  27746. public function isVeryVerbose()
  27747. {
  27748. return self::VERBOSITY_VERY_VERBOSE <= $this->verbosity;
  27749. }
  27750. public function isDebug()
  27751. {
  27752. return self::VERBOSITY_DEBUG <= $this->verbosity;
  27753. }
  27754. public function writeln($messages, $type = self::OUTPUT_NORMAL)
  27755. {
  27756. $this->write($messages, true, $type);
  27757. }
  27758. public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL)
  27759. {
  27760. if (self::VERBOSITY_QUIET === $this->verbosity) {
  27761. return;
  27762. }
  27763. $messages = (array) $messages;
  27764. foreach ($messages as $message) {
  27765. switch ($type) {
  27766. case OutputInterface::OUTPUT_NORMAL:
  27767. $message = $this->formatter->format($message);
  27768. break;
  27769. case OutputInterface::OUTPUT_RAW:
  27770. break;
  27771. case OutputInterface::OUTPUT_PLAIN:
  27772. $message = strip_tags($this->formatter->format($message));
  27773. break;
  27774. default:
  27775. throw new \InvalidArgumentException(sprintf('Unknown output type given (%s)', $type));
  27776. }
  27777. $this->doWrite($message, $newline);
  27778. }
  27779. }
  27780. abstract protected function doWrite($message, $newline);
  27781. }
  27782. <?php
  27783. namespace Symfony\Component\Console\Output;
  27784. use Symfony\Component\Console\Formatter\OutputFormatterInterface;
  27785. interface OutputInterface
  27786. {
  27787. const VERBOSITY_QUIET = 0;
  27788. const VERBOSITY_NORMAL = 1;
  27789. const VERBOSITY_VERBOSE = 2;
  27790. const VERBOSITY_VERY_VERBOSE = 3;
  27791. const VERBOSITY_DEBUG = 4;
  27792. const OUTPUT_NORMAL = 0;
  27793. const OUTPUT_RAW = 1;
  27794. const OUTPUT_PLAIN = 2;
  27795. public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL);
  27796. public function writeln($messages, $type = self::OUTPUT_NORMAL);
  27797. public function setVerbosity($level);
  27798. public function getVerbosity();
  27799. public function setDecorated($decorated);
  27800. public function isDecorated();
  27801. public function setFormatter(OutputFormatterInterface $formatter);
  27802. public function getFormatter();
  27803. }
  27804. <?php
  27805. namespace Symfony\Component\Console\Output;
  27806. use Symfony\Component\Console\Formatter\OutputFormatterInterface;
  27807. class StreamOutput extends Output
  27808. {
  27809. private $stream;
  27810. public function __construct($stream, $verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
  27811. {
  27812. if (!is_resource($stream) || 'stream' !== get_resource_type($stream)) {
  27813. throw new \InvalidArgumentException('The StreamOutput class needs a stream as its first argument.');
  27814. }
  27815. $this->stream = $stream;
  27816. if (null === $decorated) {
  27817. $decorated = $this->hasColorSupport();
  27818. }
  27819. parent::__construct($verbosity, $decorated, $formatter);
  27820. }
  27821. public function getStream()
  27822. {
  27823. return $this->stream;
  27824. }
  27825. protected function doWrite($message, $newline)
  27826. {
  27827. if (false === @fwrite($this->stream, $message.($newline ? PHP_EOL : ''))) {
  27828. throw new \RuntimeException('Unable to write output.');
  27829. }
  27830. fflush($this->stream);
  27831. }
  27832. protected function hasColorSupport()
  27833. {
  27834. if (DIRECTORY_SEPARATOR === '\\') {
  27835. return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI');
  27836. }
  27837. return function_exists('posix_isatty') && @posix_isatty($this->stream);
  27838. }
  27839. }
  27840. <?php
  27841. namespace Symfony\Component\Console\Question;
  27842. class ChoiceQuestion extends Question
  27843. {
  27844. private $choices;
  27845. private $multiselect = false;
  27846. private $prompt = ' > ';
  27847. private $errorMessage = 'Value "%s" is invalid';
  27848. public function __construct($question, array $choices, $default = null)
  27849. {
  27850. parent::__construct($question, $default);
  27851. $this->choices = $choices;
  27852. $this->setValidator($this->getDefaultValidator());
  27853. $this->setAutocompleterValues(array_keys($choices));
  27854. }
  27855. public function getChoices()
  27856. {
  27857. return $this->choices;
  27858. }
  27859. public function setMultiselect($multiselect)
  27860. {
  27861. $this->multiselect = $multiselect;
  27862. $this->setValidator($this->getDefaultValidator());
  27863. return $this;
  27864. }
  27865. public function getPrompt()
  27866. {
  27867. return $this->prompt;
  27868. }
  27869. public function setPrompt($prompt)
  27870. {
  27871. $this->prompt = $prompt;
  27872. return $this;
  27873. }
  27874. public function setErrorMessage($errorMessage)
  27875. {
  27876. $this->errorMessage = $errorMessage;
  27877. $this->setValidator($this->getDefaultValidator());
  27878. return $this;
  27879. }
  27880. private function getDefaultValidator()
  27881. {
  27882. $choices = $this->choices;
  27883. $errorMessage = $this->errorMessage;
  27884. $multiselect = $this->multiselect;
  27885. return function ($selected) use ($choices, $errorMessage, $multiselect) {
  27886. $selectedChoices = str_replace(' ', '', $selected);
  27887. if ($multiselect) {
  27888. if (!preg_match('/^[a-zA-Z0-9_-]+(?:,[a-zA-Z0-9_-]+)*$/', $selectedChoices, $matches)) {
  27889. throw new \InvalidArgumentException(sprintf($errorMessage, $selected));
  27890. }
  27891. $selectedChoices = explode(',', $selectedChoices);
  27892. } else {
  27893. $selectedChoices = array($selected);
  27894. }
  27895. $multiselectChoices = array();
  27896. foreach ($selectedChoices as $value) {
  27897. if (empty($choices[$value])) {
  27898. throw new \InvalidArgumentException(sprintf($errorMessage, $value));
  27899. }
  27900. $multiselectChoices[] = $choices[$value];
  27901. }
  27902. if ($multiselect) {
  27903. return $multiselectChoices;
  27904. }
  27905. return $choices[$selected];
  27906. };
  27907. }
  27908. }
  27909. <?php
  27910. namespace Symfony\Component\Console\Question;
  27911. class ConfirmationQuestion extends Question
  27912. {
  27913. public function __construct($question, $default = true)
  27914. {
  27915. parent::__construct($question, (bool) $default);
  27916. $this->setNormalizer($this->getDefaultNormalizer());
  27917. }
  27918. private function getDefaultNormalizer()
  27919. {
  27920. $default = $this->getDefault();
  27921. return function ($answer) use ($default) {
  27922. if (is_bool($answer)) {
  27923. return $answer;
  27924. }
  27925. if (false === $default) {
  27926. return $answer && 'y' === strtolower($answer[0]);
  27927. }
  27928. return !$answer || 'y' === strtolower($answer[0]);
  27929. };
  27930. }
  27931. }
  27932. <?php
  27933. namespace Symfony\Component\Console\Question;
  27934. class Question
  27935. {
  27936. private $question;
  27937. private $attempts;
  27938. private $hidden = false;
  27939. private $hiddenFallback = true;
  27940. private $autocompleterValues;
  27941. private $validator;
  27942. private $default;
  27943. private $normalizer;
  27944. public function __construct($question, $default = null)
  27945. {
  27946. $this->question = $question;
  27947. $this->default = $default;
  27948. }
  27949. public function getQuestion()
  27950. {
  27951. return $this->question;
  27952. }
  27953. public function getDefault()
  27954. {
  27955. return $this->default;
  27956. }
  27957. public function isHidden()
  27958. {
  27959. return $this->hidden;
  27960. }
  27961. public function setHidden($hidden)
  27962. {
  27963. if ($this->autocompleterValues) {
  27964. throw new \LogicException('A hidden question cannot use the autocompleter.');
  27965. }
  27966. $this->hidden = (bool) $hidden;
  27967. return $this;
  27968. }
  27969. public function isHiddenFallback()
  27970. {
  27971. return $this->hiddenFallback;
  27972. }
  27973. public function setHiddenFallback($fallback)
  27974. {
  27975. $this->hiddenFallback = (bool) $fallback;
  27976. return $this;
  27977. }
  27978. public function getAutocompleterValues()
  27979. {
  27980. return $this->autocompleterValues;
  27981. }
  27982. public function setAutocompleterValues($values)
  27983. {
  27984. if (null !== $values && !is_array($values)) {
  27985. if (!$values instanceof \Traversable || $values instanceof \Countable) {
  27986. throw new \InvalidArgumentException('Autocompleter values can be either an array, `null` or an object implementing both `Countable` and `Traversable` interfaces.');
  27987. }
  27988. }
  27989. if ($this->hidden) {
  27990. throw new \LogicException('A hidden question cannot use the autocompleter.');
  27991. }
  27992. $this->autocompleterValues = $values;
  27993. return $this;
  27994. }
  27995. public function setValidator($validator)
  27996. {
  27997. $this->validator = $validator;
  27998. return $this;
  27999. }
  28000. public function getValidator()
  28001. {
  28002. return $this->validator;
  28003. }
  28004. public function setMaxAttempts($attempts)
  28005. {
  28006. if (null !== $attempts && $attempts < 1) {
  28007. throw new \InvalidArgumentException('Maximum number of attempts must be a positive value.');
  28008. }
  28009. $this->attempts = $attempts;
  28010. return $this;
  28011. }
  28012. public function getMaxAttempts()
  28013. {
  28014. return $this->attempts;
  28015. }
  28016. public function setNormalizer($normalizer)
  28017. {
  28018. $this->normalizer = $normalizer;
  28019. return $this;
  28020. }
  28021. public function getNormalizer()
  28022. {
  28023. return $this->normalizer;
  28024. }
  28025. }
  28026. <?php
  28027. namespace Symfony\Component\Console;
  28028. use Symfony\Component\Console\Input\StringInput;
  28029. use Symfony\Component\Console\Output\ConsoleOutput;
  28030. use Symfony\Component\Process\ProcessBuilder;
  28031. use Symfony\Component\Process\PhpExecutableFinder;
  28032. class Shell
  28033. {
  28034. private $application;
  28035. private $history;
  28036. private $output;
  28037. private $hasReadline;
  28038. private $processIsolation = false;
  28039. public function __construct(Application $application)
  28040. {
  28041. $this->hasReadline = function_exists('readline');
  28042. $this->application = $application;
  28043. $this->history = getenv('HOME').'/.history_'.$application->getName();
  28044. $this->output = new ConsoleOutput();
  28045. }
  28046. public function run()
  28047. {
  28048. $this->application->setAutoExit(false);
  28049. $this->application->setCatchExceptions(true);
  28050. if ($this->hasReadline) {
  28051. readline_read_history($this->history);
  28052. readline_completion_function(array($this, 'autocompleter'));
  28053. }
  28054. $this->output->writeln($this->getHeader());
  28055. $php = null;
  28056. if ($this->processIsolation) {
  28057. $finder = new PhpExecutableFinder();
  28058. $php = $finder->find();
  28059. $this->output->writeln(<<<EOF
  28060. <info>Running with process isolation, you should consider this:</info>
  28061. * each command is executed as separate process,
  28062. * commands don't support interactivity, all params must be passed explicitly,
  28063. * commands output is not colorized.
  28064. EOF
  28065. );
  28066. }
  28067. while (true) {
  28068. $command = $this->readline();
  28069. if (false === $command) {
  28070. $this->output->writeln("\n");
  28071. break;
  28072. }
  28073. if ($this->hasReadline) {
  28074. readline_add_history($command);
  28075. readline_write_history($this->history);
  28076. }
  28077. if ($this->processIsolation) {
  28078. $pb = new ProcessBuilder();
  28079. $process = $pb
  28080. ->add($php)
  28081. ->add($_SERVER['argv'][0])
  28082. ->add($command)
  28083. ->inheritEnvironmentVariables(true)
  28084. ->getProcess()
  28085. ;
  28086. $output = $this->output;
  28087. $process->run(function ($type, $data) use ($output) {
  28088. $output->writeln($data);
  28089. });
  28090. $ret = $process->getExitCode();
  28091. } else {
  28092. $ret = $this->application->run(new StringInput($command), $this->output);
  28093. }
  28094. if (0 !== $ret) {
  28095. $this->output->writeln(sprintf('<error>The command terminated with an error status (%s)</error>', $ret));
  28096. }
  28097. }
  28098. }
  28099. protected function getHeader()
  28100. {
  28101. return <<<EOF
  28102. Welcome to the <info>{$this->application->getName()}</info> shell (<comment>{$this->application->getVersion()}</comment>).
  28103. At the prompt, type <comment>help</comment> for some help,
  28104. or <comment>list</comment> to get a list of available commands.
  28105. To exit the shell, type <comment>^D</comment>.
  28106. EOF;
  28107. }
  28108. protected function getPrompt()
  28109. {
  28110. return $this->output->getFormatter()->format($this->application->getName().' > ');
  28111. }
  28112. protected function getOutput()
  28113. {
  28114. return $this->output;
  28115. }
  28116. protected function getApplication()
  28117. {
  28118. return $this->application;
  28119. }
  28120. private function autocompleter($text)
  28121. {
  28122. $info = readline_info();
  28123. $text = substr($info['line_buffer'], 0, $info['end']);
  28124. if ($info['point'] !== $info['end']) {
  28125. return true;
  28126. }
  28127. if (false === strpos($text, ' ') || !$text) {
  28128. return array_keys($this->application->all());
  28129. }
  28130. try {
  28131. $command = $this->application->find(substr($text, 0, strpos($text, ' ')));
  28132. } catch (\Exception $e) {
  28133. return true;
  28134. }
  28135. $list = array('--help');
  28136. foreach ($command->getDefinition()->getOptions() as $option) {
  28137. $list[] = '--'.$option->getName();
  28138. }
  28139. return $list;
  28140. }
  28141. private function readline()
  28142. {
  28143. if ($this->hasReadline) {
  28144. $line = readline($this->getPrompt());
  28145. } else {
  28146. $this->output->write($this->getPrompt());
  28147. $line = fgets(STDIN, 1024);
  28148. $line = (false === $line || '' === $line) ? false : rtrim($line);
  28149. }
  28150. return $line;
  28151. }
  28152. public function getProcessIsolation()
  28153. {
  28154. return $this->processIsolation;
  28155. }
  28156. public function setProcessIsolation($processIsolation)
  28157. {
  28158. $this->processIsolation = (bool) $processIsolation;
  28159. if ($this->processIsolation && !class_exists('Symfony\\Component\\Process\\Process')) {
  28160. throw new \RuntimeException('Unable to isolate processes as the Symfony Process Component is not installed.');
  28161. }
  28162. }
  28163. }
  28164. <?php
  28165. namespace Symfony\Component\Console\Tester;
  28166. use Symfony\Component\Console\Application;
  28167. use Symfony\Component\Console\Input\ArrayInput;
  28168. use Symfony\Component\Console\Input\InputInterface;
  28169. use Symfony\Component\Console\Output\OutputInterface;
  28170. use Symfony\Component\Console\Output\StreamOutput;
  28171. class ApplicationTester
  28172. {
  28173. private $application;
  28174. private $input;
  28175. private $output;
  28176. private $statusCode;
  28177. public function __construct(Application $application)
  28178. {
  28179. $this->application = $application;
  28180. }
  28181. public function run(array $input, $options = array())
  28182. {
  28183. $this->input = new ArrayInput($input);
  28184. if (isset($options['interactive'])) {
  28185. $this->input->setInteractive($options['interactive']);
  28186. }
  28187. $this->output = new StreamOutput(fopen('php://memory', 'w', false));
  28188. if (isset($options['decorated'])) {
  28189. $this->output->setDecorated($options['decorated']);
  28190. }
  28191. if (isset($options['verbosity'])) {
  28192. $this->output->setVerbosity($options['verbosity']);
  28193. }
  28194. return $this->statusCode = $this->application->run($this->input, $this->output);
  28195. }
  28196. public function getDisplay($normalize = false)
  28197. {
  28198. rewind($this->output->getStream());
  28199. $display = stream_get_contents($this->output->getStream());
  28200. if ($normalize) {
  28201. $display = str_replace(PHP_EOL, "\n", $display);
  28202. }
  28203. return $display;
  28204. }
  28205. public function getInput()
  28206. {
  28207. return $this->input;
  28208. }
  28209. public function getOutput()
  28210. {
  28211. return $this->output;
  28212. }
  28213. public function getStatusCode()
  28214. {
  28215. return $this->statusCode;
  28216. }
  28217. }
  28218. <?php
  28219. namespace Symfony\Component\Console\Tester;
  28220. use Symfony\Component\Console\Command\Command;
  28221. use Symfony\Component\Console\Input\ArrayInput;
  28222. use Symfony\Component\Console\Output\StreamOutput;
  28223. use Symfony\Component\Console\Input\InputInterface;
  28224. use Symfony\Component\Console\Output\OutputInterface;
  28225. class CommandTester
  28226. {
  28227. private $command;
  28228. private $input;
  28229. private $output;
  28230. private $statusCode;
  28231. public function __construct(Command $command)
  28232. {
  28233. $this->command = $command;
  28234. }
  28235. public function execute(array $input, array $options = array())
  28236. {
  28237. if (!isset($input['command'])
  28238. && (null !== $application = $this->command->getApplication())
  28239. && $application->getDefinition()->hasArgument('command')
  28240. ) {
  28241. $input = array_merge(array('command' => $this->command->getName()), $input);
  28242. }
  28243. $this->input = new ArrayInput($input);
  28244. if (isset($options['interactive'])) {
  28245. $this->input->setInteractive($options['interactive']);
  28246. }
  28247. $this->output = new StreamOutput(fopen('php://memory', 'w', false));
  28248. if (isset($options['decorated'])) {
  28249. $this->output->setDecorated($options['decorated']);
  28250. }
  28251. if (isset($options['verbosity'])) {
  28252. $this->output->setVerbosity($options['verbosity']);
  28253. }
  28254. return $this->statusCode = $this->command->run($this->input, $this->output);
  28255. }
  28256. public function getDisplay($normalize = false)
  28257. {
  28258. rewind($this->output->getStream());
  28259. $display = stream_get_contents($this->output->getStream());
  28260. if ($normalize) {
  28261. $display = str_replace(PHP_EOL, "\n", $display);
  28262. }
  28263. return $display;
  28264. }
  28265. public function getInput()
  28266. {
  28267. return $this->input;
  28268. }
  28269. public function getOutput()
  28270. {
  28271. return $this->output;
  28272. }
  28273. public function getStatusCode()
  28274. {
  28275. return $this->statusCode;
  28276. }
  28277. }
  28278. <?php
  28279. namespace Symfony\Component\Filesystem\Exception;
  28280. interface ExceptionInterface
  28281. {
  28282. }
  28283. <?php
  28284. namespace Symfony\Component\Filesystem\Exception;
  28285. class FileNotFoundException extends IOException
  28286. {
  28287. public function __construct($message = null, $code = 0, \Exception $previous = null, $path = null)
  28288. {
  28289. if (null === $message) {
  28290. if (null === $path) {
  28291. $message = 'File could not be found.';
  28292. } else {
  28293. $message = sprintf('File "%s" could not be found.', $path);
  28294. }
  28295. }
  28296. parent::__construct($message, $code, $previous, $path);
  28297. }
  28298. }
  28299. <?php
  28300. namespace Symfony\Component\Filesystem\Exception;
  28301. class IOException extends \RuntimeException implements IOExceptionInterface
  28302. {
  28303. private $path;
  28304. public function __construct($message, $code = 0, \Exception $previous = null, $path = null)
  28305. {
  28306. $this->path = $path;
  28307. parent::__construct($message, $code, $previous);
  28308. }
  28309. public function getPath()
  28310. {
  28311. return $this->path;
  28312. }
  28313. }
  28314. <?php
  28315. namespace Symfony\Component\Filesystem\Exception;
  28316. interface IOExceptionInterface extends ExceptionInterface
  28317. {
  28318. public function getPath();
  28319. }
  28320. <?php
  28321. namespace Symfony\Component\Filesystem;
  28322. use Symfony\Component\Filesystem\Exception\IOException;
  28323. use Symfony\Component\Filesystem\Exception\FileNotFoundException;
  28324. class Filesystem
  28325. {
  28326. public function copy($originFile, $targetFile, $override = false)
  28327. {
  28328. if (stream_is_local($originFile) && !is_file($originFile)) {
  28329. throw new FileNotFoundException(sprintf('Failed to copy "%s" because file does not exist.', $originFile), 0, null, $originFile);
  28330. }
  28331. $this->mkdir(dirname($targetFile));
  28332. $doCopy = true;
  28333. if (!$override && null === parse_url($originFile, PHP_URL_HOST) && is_file($targetFile)) {
  28334. $doCopy = filemtime($originFile) > filemtime($targetFile);
  28335. }
  28336. if ($doCopy) {
  28337. if (false === $source = @fopen($originFile, 'r')) {
  28338. throw new IOException(sprintf('Failed to copy "%s" to "%s" because source file could not be opened for reading.', $originFile, $targetFile), 0, null, $originFile);
  28339. }
  28340. if (false === $target = @fopen($targetFile, 'w', null, stream_context_create(array('ftp' => array('overwrite' => true))))) {
  28341. throw new IOException(sprintf('Failed to copy "%s" to "%s" because target file could not be opened for writing.', $originFile, $targetFile), 0, null, $originFile);
  28342. }
  28343. $bytesCopied = stream_copy_to_stream($source, $target);
  28344. fclose($source);
  28345. fclose($target);
  28346. unset($source, $target);
  28347. if (!is_file($targetFile)) {
  28348. throw new IOException(sprintf('Failed to copy "%s" to "%s".', $originFile, $targetFile), 0, null, $originFile);
  28349. }
  28350. if (stream_is_local($originFile) && $bytesCopied !== filesize($originFile)) {
  28351. throw new IOException(sprintf('Failed to copy the whole content of "%s" to "%s %g bytes copied".', $originFile, $targetFile, $bytesCopied), 0, null, $originFile);
  28352. }
  28353. }
  28354. }
  28355. public function mkdir($dirs, $mode = 0777)
  28356. {
  28357. foreach ($this->toIterator($dirs) as $dir) {
  28358. if (is_dir($dir)) {
  28359. continue;
  28360. }
  28361. if (true !== @mkdir($dir, $mode, true)) {
  28362. $error = error_get_last();
  28363. if (!is_dir($dir)) {
  28364. if ($error) {
  28365. throw new IOException(sprintf('Failed to create "%s": %s.', $dir, $error['message']), 0, null, $dir);
  28366. }
  28367. throw new IOException(sprintf('Failed to create "%s"', $dir), 0, null, $dir);
  28368. }
  28369. }
  28370. }
  28371. }
  28372. public function exists($files)
  28373. {
  28374. foreach ($this->toIterator($files) as $file) {
  28375. if (!file_exists($file)) {
  28376. return false;
  28377. }
  28378. }
  28379. return true;
  28380. }
  28381. public function touch($files, $time = null, $atime = null)
  28382. {
  28383. foreach ($this->toIterator($files) as $file) {
  28384. $touch = $time ? @touch($file, $time, $atime) : @touch($file);
  28385. if (true !== $touch) {
  28386. throw new IOException(sprintf('Failed to touch "%s".', $file), 0, null, $file);
  28387. }
  28388. }
  28389. }
  28390. public function remove($files)
  28391. {
  28392. $files = iterator_to_array($this->toIterator($files));
  28393. $files = array_reverse($files);
  28394. foreach ($files as $file) {
  28395. if (!file_exists($file) && !is_link($file)) {
  28396. continue;
  28397. }
  28398. if (is_dir($file) && !is_link($file)) {
  28399. $this->remove(new \FilesystemIterator($file));
  28400. if (true !== @rmdir($file)) {
  28401. throw new IOException(sprintf('Failed to remove directory "%s".', $file), 0, null, $file);
  28402. }
  28403. } else {
  28404. if ('\\' === DIRECTORY_SEPARATOR && is_dir($file)) {
  28405. if (true !== @rmdir($file)) {
  28406. throw new IOException(sprintf('Failed to remove file "%s".', $file), 0, null, $file);
  28407. }
  28408. } else {
  28409. if (true !== @unlink($file)) {
  28410. throw new IOException(sprintf('Failed to remove file "%s".', $file), 0, null, $file);
  28411. }
  28412. }
  28413. }
  28414. }
  28415. }
  28416. public function chmod($files, $mode, $umask = 0000, $recursive = false)
  28417. {
  28418. foreach ($this->toIterator($files) as $file) {
  28419. if ($recursive && is_dir($file) && !is_link($file)) {
  28420. $this->chmod(new \FilesystemIterator($file), $mode, $umask, true);
  28421. }
  28422. if (true !== @chmod($file, $mode & ~$umask)) {
  28423. throw new IOException(sprintf('Failed to chmod file "%s".', $file), 0, null, $file);
  28424. }
  28425. }
  28426. }
  28427. public function chown($files, $user, $recursive = false)
  28428. {
  28429. foreach ($this->toIterator($files) as $file) {
  28430. if ($recursive && is_dir($file) && !is_link($file)) {
  28431. $this->chown(new \FilesystemIterator($file), $user, true);
  28432. }
  28433. if (is_link($file) && function_exists('lchown')) {
  28434. if (true !== @lchown($file, $user)) {
  28435. throw new IOException(sprintf('Failed to chown file "%s".', $file), 0, null, $file);
  28436. }
  28437. } else {
  28438. if (true !== @chown($file, $user)) {
  28439. throw new IOException(sprintf('Failed to chown file "%s".', $file), 0, null, $file);
  28440. }
  28441. }
  28442. }
  28443. }
  28444. public function chgrp($files, $group, $recursive = false)
  28445. {
  28446. foreach ($this->toIterator($files) as $file) {
  28447. if ($recursive && is_dir($file) && !is_link($file)) {
  28448. $this->chgrp(new \FilesystemIterator($file), $group, true);
  28449. }
  28450. if (is_link($file) && function_exists('lchgrp')) {
  28451. if (true !== @lchgrp($file, $group) || (defined('HHVM_VERSION') && !posix_getgrnam($group))) {
  28452. throw new IOException(sprintf('Failed to chgrp file "%s".', $file), 0, null, $file);
  28453. }
  28454. } else {
  28455. if (true !== @chgrp($file, $group)) {
  28456. throw new IOException(sprintf('Failed to chgrp file "%s".', $file), 0, null, $file);
  28457. }
  28458. }
  28459. }
  28460. }
  28461. public function rename($origin, $target, $overwrite = false)
  28462. {
  28463. if (!$overwrite && is_readable($target)) {
  28464. throw new IOException(sprintf('Cannot rename because the target "%s" already exists.', $target), 0, null, $target);
  28465. }
  28466. if (true !== @rename($origin, $target)) {
  28467. throw new IOException(sprintf('Cannot rename "%s" to "%s".', $origin, $target), 0, null, $target);
  28468. }
  28469. }
  28470. public function symlink($originDir, $targetDir, $copyOnWindows = false)
  28471. {
  28472. if ('\\' === DIRECTORY_SEPARATOR && $copyOnWindows) {
  28473. $this->mirror($originDir, $targetDir);
  28474. return;
  28475. }
  28476. $this->mkdir(dirname($targetDir));
  28477. $ok = false;
  28478. if (is_link($targetDir)) {
  28479. if (readlink($targetDir) != $originDir) {
  28480. $this->remove($targetDir);
  28481. } else {
  28482. $ok = true;
  28483. }
  28484. }
  28485. if (!$ok && true !== @symlink($originDir, $targetDir)) {
  28486. $report = error_get_last();
  28487. if (is_array($report)) {
  28488. if ('\\' === DIRECTORY_SEPARATOR && false !== strpos($report['message'], 'error code(1314)')) {
  28489. throw new IOException('Unable to create symlink due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?');
  28490. }
  28491. throw new IOException(sprintf('Failed to create symbolic link from "%s" to "%s".', $originDir, $targetDir), 0, null, $targetDir);
  28492. }
  28493. throw new IOException(sprintf('Failed to create symbolic link from %s to %s', $originDir, $targetDir));
  28494. }
  28495. }
  28496. public function makePathRelative($endPath, $startPath)
  28497. {
  28498. if ('\\' === DIRECTORY_SEPARATOR) {
  28499. $endPath = strtr($endPath, '\\', '/');
  28500. $startPath = strtr($startPath, '\\', '/');
  28501. }
  28502. $startPathArr = explode('/', trim($startPath, '/'));
  28503. $endPathArr = explode('/', trim($endPath, '/'));
  28504. $index = 0;
  28505. while (isset($startPathArr[$index]) && isset($endPathArr[$index]) && $startPathArr[$index] === $endPathArr[$index]) {
  28506. ++$index;
  28507. }
  28508. $depth = count($startPathArr) - $index;
  28509. $traverser = str_repeat('../', $depth);
  28510. $endPathRemainder = implode('/', array_slice($endPathArr, $index));
  28511. $relativePath = $traverser.('' !== $endPathRemainder ? $endPathRemainder.'/' : '');
  28512. return '' === $relativePath ? './' : $relativePath;
  28513. }
  28514. public function mirror($originDir, $targetDir, \Traversable $iterator = null, $options = array())
  28515. {
  28516. $targetDir = rtrim($targetDir, '/\\');
  28517. $originDir = rtrim($originDir, '/\\');
  28518. if ($this->exists($targetDir) && isset($options['delete']) && $options['delete']) {
  28519. $deleteIterator = $iterator;
  28520. if (null === $deleteIterator) {
  28521. $flags = \FilesystemIterator::SKIP_DOTS;
  28522. $deleteIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($targetDir, $flags), \RecursiveIteratorIterator::CHILD_FIRST);
  28523. }
  28524. foreach ($deleteIterator as $file) {
  28525. $origin = str_replace($targetDir, $originDir, $file->getPathname());
  28526. if (!$this->exists($origin)) {
  28527. $this->remove($file);
  28528. }
  28529. }
  28530. }
  28531. $copyOnWindows = false;
  28532. if (isset($options['copy_on_windows'])) {
  28533. $copyOnWindows = $options['copy_on_windows'];
  28534. }
  28535. if (null === $iterator) {
  28536. $flags = $copyOnWindows ? \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS : \FilesystemIterator::SKIP_DOTS;
  28537. $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($originDir, $flags), \RecursiveIteratorIterator::SELF_FIRST);
  28538. }
  28539. if ($this->exists($originDir)) {
  28540. $this->mkdir($targetDir);
  28541. }
  28542. foreach ($iterator as $file) {
  28543. $target = str_replace($originDir, $targetDir, $file->getPathname());
  28544. if ($copyOnWindows) {
  28545. if (is_link($file) || is_file($file)) {
  28546. $this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
  28547. } elseif (is_dir($file)) {
  28548. $this->mkdir($target);
  28549. } else {
  28550. throw new IOException(sprintf('Unable to guess "%s" file type.', $file), 0, null, $file);
  28551. }
  28552. } else {
  28553. if (is_link($file)) {
  28554. $this->symlink($file->getRealPath(), $target);
  28555. } elseif (is_dir($file)) {
  28556. $this->mkdir($target);
  28557. } elseif (is_file($file)) {
  28558. $this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
  28559. } else {
  28560. throw new IOException(sprintf('Unable to guess "%s" file type.', $file), 0, null, $file);
  28561. }
  28562. }
  28563. }
  28564. }
  28565. public function isAbsolutePath($file)
  28566. {
  28567. return (strspn($file, '/\\', 0, 1)
  28568. || (strlen($file) > 3 && ctype_alpha($file[0])
  28569. && substr($file, 1, 1) === ':'
  28570. && (strspn($file, '/\\', 2, 1))
  28571. )
  28572. || null !== parse_url($file, PHP_URL_SCHEME)
  28573. );
  28574. }
  28575. public function dumpFile($filename, $content, $mode = 0666)
  28576. {
  28577. $dir = dirname($filename);
  28578. if (!is_dir($dir)) {
  28579. $this->mkdir($dir);
  28580. } elseif (!is_writable($dir)) {
  28581. throw new IOException(sprintf('Unable to write to the "%s" directory.', $dir), 0, null, $dir);
  28582. }
  28583. $tmpFile = tempnam($dir, basename($filename));
  28584. if (false === @file_put_contents($tmpFile, $content)) {
  28585. throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename);
  28586. }
  28587. $this->rename($tmpFile, $filename, true);
  28588. if (null !== $mode) {
  28589. $this->chmod($filename, $mode);
  28590. }
  28591. }
  28592. private function toIterator($files)
  28593. {
  28594. if (!$files instanceof \Traversable) {
  28595. $files = new \ArrayObject(is_array($files) ? $files : array($files));
  28596. }
  28597. return $files;
  28598. }
  28599. }
  28600. Copyright (c) 2004-2015 Fabien Potencier
  28601. Permission is hereby granted, free of charge, to any person obtaining a copy
  28602. of this software and associated documentation files (the "Software"), to deal
  28603. in the Software without restriction, including without limitation the rights
  28604. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  28605. copies of the Software, and to permit persons to whom the Software is furnished
  28606. to do so, subject to the following conditions:
  28607. The above copyright notice and this permission notice shall be included in all
  28608. copies or substantial portions of the Software.
  28609. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  28610. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  28611. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  28612. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  28613. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  28614. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  28615. THE SOFTWARE.
  28616. <?php
  28617. namespace Symfony\Component\Filesystem;
  28618. use Symfony\Component\Filesystem\Exception\IOException;
  28619. class LockHandler
  28620. {
  28621. private $file;
  28622. private $handle;
  28623. public function __construct($name, $lockPath = null)
  28624. {
  28625. $lockPath = $lockPath ?: sys_get_temp_dir();
  28626. if (!is_dir($lockPath)) {
  28627. $fs = new Filesystem();
  28628. $fs->mkdir($lockPath);
  28629. }
  28630. if (!is_writable($lockPath)) {
  28631. throw new IOException(sprintf('The directory "%s" is not writable.', $lockPath), 0, null, $lockPath);
  28632. }
  28633. $this->file = sprintf('%s/sf.%s.%s.lock', $lockPath, preg_replace('/[^a-z0-9\._-]+/i', '-', $name), hash('sha256', $name));
  28634. }
  28635. public function lock($blocking = false)
  28636. {
  28637. if ($this->handle) {
  28638. return true;
  28639. }
  28640. $errorLevel = error_reporting(0);
  28641. set_error_handler('var_dump', 0);
  28642. if (!$this->handle = fopen($this->file, 'r')) {
  28643. if ($this->handle = fopen($this->file, 'x')) {
  28644. chmod($this->file, 0444);
  28645. } elseif (!$this->handle = fopen($this->file, 'r')) {
  28646. usleep(100);
  28647. $this->handle = fopen($this->file, 'r');
  28648. }
  28649. }
  28650. restore_error_handler();
  28651. error_reporting($errorLevel);
  28652. if (!$this->handle) {
  28653. $error = error_get_last();
  28654. throw new IOException($error['message'], 0, null, $this->file);
  28655. }
  28656. if (!flock($this->handle, LOCK_EX | ($blocking ? 0 : LOCK_NB))) {
  28657. fclose($this->handle);
  28658. $this->handle = null;
  28659. return false;
  28660. }
  28661. return true;
  28662. }
  28663. public function release()
  28664. {
  28665. if ($this->handle) {
  28666. flock($this->handle, LOCK_UN | LOCK_NB);
  28667. fclose($this->handle);
  28668. $this->handle = null;
  28669. }
  28670. }
  28671. }
  28672. <?php
  28673. namespace Symfony\Component\Finder\Adapter;
  28674. abstract class AbstractAdapter implements AdapterInterface
  28675. {
  28676. protected $followLinks = false;
  28677. protected $mode = 0;
  28678. protected $minDepth = 0;
  28679. protected $maxDepth = PHP_INT_MAX;
  28680. protected $exclude = array();
  28681. protected $names = array();
  28682. protected $notNames = array();
  28683. protected $contains = array();
  28684. protected $notContains = array();
  28685. protected $sizes = array();
  28686. protected $dates = array();
  28687. protected $filters = array();
  28688. protected $sort = false;
  28689. protected $paths = array();
  28690. protected $notPaths = array();
  28691. protected $ignoreUnreadableDirs = false;
  28692. private static $areSupported = array();
  28693. public function isSupported()
  28694. {
  28695. $name = $this->getName();
  28696. if (!array_key_exists($name, self::$areSupported)) {
  28697. self::$areSupported[$name] = $this->canBeUsed();
  28698. }
  28699. return self::$areSupported[$name];
  28700. }
  28701. public function setFollowLinks($followLinks)
  28702. {
  28703. $this->followLinks = $followLinks;
  28704. return $this;
  28705. }
  28706. public function setMode($mode)
  28707. {
  28708. $this->mode = $mode;
  28709. return $this;
  28710. }
  28711. public function setDepths(array $depths)
  28712. {
  28713. $this->minDepth = 0;
  28714. $this->maxDepth = PHP_INT_MAX;
  28715. foreach ($depths as $comparator) {
  28716. switch ($comparator->getOperator()) {
  28717. case '>':
  28718. $this->minDepth = $comparator->getTarget() + 1;
  28719. break;
  28720. case '>=':
  28721. $this->minDepth = $comparator->getTarget();
  28722. break;
  28723. case '<':
  28724. $this->maxDepth = $comparator->getTarget() - 1;
  28725. break;
  28726. case '<=':
  28727. $this->maxDepth = $comparator->getTarget();
  28728. break;
  28729. default:
  28730. $this->minDepth = $this->maxDepth = $comparator->getTarget();
  28731. }
  28732. }
  28733. return $this;
  28734. }
  28735. public function setExclude(array $exclude)
  28736. {
  28737. $this->exclude = $exclude;
  28738. return $this;
  28739. }
  28740. public function setNames(array $names)
  28741. {
  28742. $this->names = $names;
  28743. return $this;
  28744. }
  28745. public function setNotNames(array $notNames)
  28746. {
  28747. $this->notNames = $notNames;
  28748. return $this;
  28749. }
  28750. public function setContains(array $contains)
  28751. {
  28752. $this->contains = $contains;
  28753. return $this;
  28754. }
  28755. public function setNotContains(array $notContains)
  28756. {
  28757. $this->notContains = $notContains;
  28758. return $this;
  28759. }
  28760. public function setSizes(array $sizes)
  28761. {
  28762. $this->sizes = $sizes;
  28763. return $this;
  28764. }
  28765. public function setDates(array $dates)
  28766. {
  28767. $this->dates = $dates;
  28768. return $this;
  28769. }
  28770. public function setFilters(array $filters)
  28771. {
  28772. $this->filters = $filters;
  28773. return $this;
  28774. }
  28775. public function setSort($sort)
  28776. {
  28777. $this->sort = $sort;
  28778. return $this;
  28779. }
  28780. public function setPath(array $paths)
  28781. {
  28782. $this->paths = $paths;
  28783. return $this;
  28784. }
  28785. public function setNotPath(array $notPaths)
  28786. {
  28787. $this->notPaths = $notPaths;
  28788. return $this;
  28789. }
  28790. public function ignoreUnreadableDirs($ignore = true)
  28791. {
  28792. $this->ignoreUnreadableDirs = (bool) $ignore;
  28793. return $this;
  28794. }
  28795. abstract protected function canBeUsed();
  28796. }
  28797. <?php
  28798. namespace Symfony\Component\Finder\Adapter;
  28799. use Symfony\Component\Finder\Exception\AccessDeniedException;
  28800. use Symfony\Component\Finder\Iterator;
  28801. use Symfony\Component\Finder\Shell\Shell;
  28802. use Symfony\Component\Finder\Expression\Expression;
  28803. use Symfony\Component\Finder\Shell\Command;
  28804. use Symfony\Component\Finder\Comparator\NumberComparator;
  28805. use Symfony\Component\Finder\Comparator\DateComparator;
  28806. abstract class AbstractFindAdapter extends AbstractAdapter
  28807. {
  28808. protected $shell;
  28809. public function __construct()
  28810. {
  28811. $this->shell = new Shell();
  28812. }
  28813. public function searchInDirectory($dir)
  28814. {
  28815. $dir = realpath($dir);
  28816. if (Iterator\FileTypeFilterIterator::ONLY_DIRECTORIES === $this->mode && ($this->contains || $this->notContains)) {
  28817. return new Iterator\FilePathsIterator(array(), $dir);
  28818. }
  28819. $command = Command::create();
  28820. $find = $this->buildFindCommand($command, $dir);
  28821. if ($this->followLinks) {
  28822. $find->add('-follow');
  28823. }
  28824. $find->add('-mindepth')->add($this->minDepth + 1);
  28825. if (PHP_INT_MAX !== $this->maxDepth) {
  28826. $find->add('-maxdepth')->add($this->maxDepth + 1);
  28827. }
  28828. if (Iterator\FileTypeFilterIterator::ONLY_DIRECTORIES === $this->mode) {
  28829. $find->add('-type d');
  28830. } elseif (Iterator\FileTypeFilterIterator::ONLY_FILES === $this->mode) {
  28831. $find->add('-type f');
  28832. }
  28833. $this->buildNamesFiltering($find, $this->names);
  28834. $this->buildNamesFiltering($find, $this->notNames, true);
  28835. $this->buildPathsFiltering($find, $dir, $this->paths);
  28836. $this->buildPathsFiltering($find, $dir, $this->notPaths, true);
  28837. $this->buildSizesFiltering($find, $this->sizes);
  28838. $this->buildDatesFiltering($find, $this->dates);
  28839. $useGrep = $this->shell->testCommand('grep') && $this->shell->testCommand('xargs');
  28840. $useSort = is_int($this->sort) && $this->shell->testCommand('sort') && $this->shell->testCommand('cut');
  28841. if ($useGrep && ($this->contains || $this->notContains)) {
  28842. $grep = $command->ins('grep');
  28843. $this->buildContentFiltering($grep, $this->contains);
  28844. $this->buildContentFiltering($grep, $this->notContains, true);
  28845. }
  28846. if ($useSort) {
  28847. $this->buildSorting($command, $this->sort);
  28848. }
  28849. $command->setErrorHandler(
  28850. $this->ignoreUnreadableDirs
  28851. ? function ($stderr) { return; }
  28852. : function ($stderr) { throw new AccessDeniedException($stderr); }
  28853. );
  28854. $paths = $this->shell->testCommand('uniq') ? $command->add('| uniq')->execute() : array_unique($command->execute());
  28855. $iterator = new Iterator\FilePathsIterator($paths, $dir);
  28856. if ($this->exclude) {
  28857. $iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
  28858. }
  28859. if (!$useGrep && ($this->contains || $this->notContains)) {
  28860. $iterator = new Iterator\FilecontentFilterIterator($iterator, $this->contains, $this->notContains);
  28861. }
  28862. if ($this->filters) {
  28863. $iterator = new Iterator\CustomFilterIterator($iterator, $this->filters);
  28864. }
  28865. if (!$useSort && $this->sort) {
  28866. $iteratorAggregate = new Iterator\SortableIterator($iterator, $this->sort);
  28867. $iterator = $iteratorAggregate->getIterator();
  28868. }
  28869. return $iterator;
  28870. }
  28871. protected function canBeUsed()
  28872. {
  28873. return $this->shell->testCommand('find');
  28874. }
  28875. protected function buildFindCommand(Command $command, $dir)
  28876. {
  28877. return $command
  28878. ->ins('find')
  28879. ->add('find ')
  28880. ->arg($dir)
  28881. ->add('-noleaf');
  28882. }
  28883. private function buildNamesFiltering(Command $command, array $names, $not = false)
  28884. {
  28885. if (0 === count($names)) {
  28886. return;
  28887. }
  28888. $command->add($not ? '-not' : null)->cmd('(');
  28889. foreach ($names as $i => $name) {
  28890. $expr = Expression::create($name);
  28891. if ($expr->isGlob() && $expr->getGlob()->isExpandable()) {
  28892. $expr = Expression::create($expr->getGlob()->toRegex(false));
  28893. }
  28894. if ($expr->isRegex()) {
  28895. $regex = $expr->getRegex();
  28896. $regex->prepend($regex->hasStartFlag() ? '/' : '/[^/]*')
  28897. ->setStartFlag(false)
  28898. ->setStartJoker(true)
  28899. ->replaceJokers('[^/]');
  28900. if (!$regex->hasEndFlag() || $regex->hasEndJoker()) {
  28901. $regex->setEndJoker(false)->append('[^/]*');
  28902. }
  28903. }
  28904. $command
  28905. ->add($i > 0 ? '-or' : null)
  28906. ->add($expr->isRegex()
  28907. ? ($expr->isCaseSensitive() ? '-regex' : '-iregex')
  28908. : ($expr->isCaseSensitive() ? '-name' : '-iname')
  28909. )
  28910. ->arg($expr->renderPattern());
  28911. }
  28912. $command->cmd(')');
  28913. }
  28914. private function buildPathsFiltering(Command $command, $dir, array $paths, $not = false)
  28915. {
  28916. if (0 === count($paths)) {
  28917. return;
  28918. }
  28919. $command->add($not ? '-not' : null)->cmd('(');
  28920. foreach ($paths as $i => $path) {
  28921. $expr = Expression::create($path);
  28922. if ($expr->isGlob() && $expr->getGlob()->isExpandable()) {
  28923. $expr = Expression::create($expr->getGlob()->toRegex(false));
  28924. }
  28925. if ($expr->isRegex()) {
  28926. $regex = $expr->getRegex();
  28927. $regex->prepend($regex->hasStartFlag() ? preg_quote($dir).DIRECTORY_SEPARATOR : '.*')->setEndJoker(!$regex->hasEndFlag());
  28928. } else {
  28929. $expr->prepend('*')->append('*');
  28930. }
  28931. $command
  28932. ->add($i > 0 ? '-or' : null)
  28933. ->add($expr->isRegex()
  28934. ? ($expr->isCaseSensitive() ? '-regex' : '-iregex')
  28935. : ($expr->isCaseSensitive() ? '-path' : '-ipath')
  28936. )
  28937. ->arg($expr->renderPattern());
  28938. }
  28939. $command->cmd(')');
  28940. }
  28941. private function buildSizesFiltering(Command $command, array $sizes)
  28942. {
  28943. foreach ($sizes as $i => $size) {
  28944. $command->add($i > 0 ? '-and' : null);
  28945. switch ($size->getOperator()) {
  28946. case '<=':
  28947. $command->add('-size -'.($size->getTarget() + 1).'c');
  28948. break;
  28949. case '>=':
  28950. $command->add('-size +'.($size->getTarget() - 1).'c');
  28951. break;
  28952. case '>':
  28953. $command->add('-size +'.$size->getTarget().'c');
  28954. break;
  28955. case '!=':
  28956. $command->add('-size -'.$size->getTarget().'c');
  28957. $command->add('-size +'.$size->getTarget().'c');
  28958. break;
  28959. case '<':
  28960. default:
  28961. $command->add('-size -'.$size->getTarget().'c');
  28962. }
  28963. }
  28964. }
  28965. private function buildDatesFiltering(Command $command, array $dates)
  28966. {
  28967. foreach ($dates as $i => $date) {
  28968. $command->add($i > 0 ? '-and' : null);
  28969. $mins = (int) round((time() - $date->getTarget()) / 60);
  28970. if (0 > $mins) {
  28971. $command->add(' -mmin -0');
  28972. return;
  28973. }
  28974. switch ($date->getOperator()) {
  28975. case '<=':
  28976. $command->add('-mmin +'.($mins - 1));
  28977. break;
  28978. case '>=':
  28979. $command->add('-mmin -'.($mins + 1));
  28980. break;
  28981. case '>':
  28982. $command->add('-mmin -'.$mins);
  28983. break;
  28984. case '!=':
  28985. $command->add('-mmin +'.$mins.' -or -mmin -'.$mins);
  28986. break;
  28987. case '<':
  28988. default:
  28989. $command->add('-mmin +'.$mins);
  28990. }
  28991. }
  28992. }
  28993. private function buildSorting(Command $command, $sort)
  28994. {
  28995. $this->buildFormatSorting($command, $sort);
  28996. }
  28997. abstract protected function buildFormatSorting(Command $command, $sort);
  28998. abstract protected function buildContentFiltering(Command $command, array $contains, $not = false);
  28999. }
  29000. <?php
  29001. namespace Symfony\Component\Finder\Adapter;
  29002. interface AdapterInterface
  29003. {
  29004. public function setFollowLinks($followLinks);
  29005. public function setMode($mode);
  29006. public function setExclude(array $exclude);
  29007. public function setDepths(array $depths);
  29008. public function setNames(array $names);
  29009. public function setNotNames(array $notNames);
  29010. public function setContains(array $contains);
  29011. public function setNotContains(array $notContains);
  29012. public function setSizes(array $sizes);
  29013. public function setDates(array $dates);
  29014. public function setFilters(array $filters);
  29015. public function setSort($sort);
  29016. public function setPath(array $paths);
  29017. public function setNotPath(array $notPaths);
  29018. public function ignoreUnreadableDirs($ignore = true);
  29019. public function searchInDirectory($dir);
  29020. public function isSupported();
  29021. public function getName();
  29022. }
  29023. <?php
  29024. namespace Symfony\Component\Finder\Adapter;
  29025. use Symfony\Component\Finder\Shell\Shell;
  29026. use Symfony\Component\Finder\Shell\Command;
  29027. use Symfony\Component\Finder\Iterator\SortableIterator;
  29028. use Symfony\Component\Finder\Expression\Expression;
  29029. class BsdFindAdapter extends AbstractFindAdapter
  29030. {
  29031. public function getName()
  29032. {
  29033. return 'bsd_find';
  29034. }
  29035. protected function canBeUsed()
  29036. {
  29037. return in_array($this->shell->getType(), array(Shell::TYPE_BSD, Shell::TYPE_DARWIN)) && parent::canBeUsed();
  29038. }
  29039. protected function buildFormatSorting(Command $command, $sort)
  29040. {
  29041. switch ($sort) {
  29042. case SortableIterator::SORT_BY_NAME:
  29043. $command->ins('sort')->add('| sort');
  29044. return;
  29045. case SortableIterator::SORT_BY_TYPE:
  29046. $format = '%HT';
  29047. break;
  29048. case SortableIterator::SORT_BY_ACCESSED_TIME:
  29049. $format = '%a';
  29050. break;
  29051. case SortableIterator::SORT_BY_CHANGED_TIME:
  29052. $format = '%c';
  29053. break;
  29054. case SortableIterator::SORT_BY_MODIFIED_TIME:
  29055. $format = '%m';
  29056. break;
  29057. default:
  29058. throw new \InvalidArgumentException(sprintf('Unknown sort options: %s.', $sort));
  29059. }
  29060. $command
  29061. ->add('-print0 | xargs -0 stat -f')
  29062. ->arg($format.'%t%N')
  29063. ->add('| sort | cut -f 2');
  29064. }
  29065. protected function buildFindCommand(Command $command, $dir)
  29066. {
  29067. parent::buildFindCommand($command, $dir)->addAtIndex('-E', 1);
  29068. return $command;
  29069. }
  29070. protected function buildContentFiltering(Command $command, array $contains, $not = false)
  29071. {
  29072. foreach ($contains as $contain) {
  29073. $expr = Expression::create($contain);
  29074. $command
  29075. ->add('| grep -v \'^$\'')
  29076. ->add('| xargs -I{} grep -I')
  29077. ->add($expr->isCaseSensitive() ? null : '-i')
  29078. ->add($not ? '-L' : '-l')
  29079. ->add('-Ee')->arg($expr->renderPattern())
  29080. ->add('{}')
  29081. ;
  29082. }
  29083. }
  29084. }
  29085. <?php
  29086. namespace Symfony\Component\Finder\Adapter;
  29087. use Symfony\Component\Finder\Shell\Shell;
  29088. use Symfony\Component\Finder\Shell\Command;
  29089. use Symfony\Component\Finder\Iterator\SortableIterator;
  29090. use Symfony\Component\Finder\Expression\Expression;
  29091. class GnuFindAdapter extends AbstractFindAdapter
  29092. {
  29093. public function getName()
  29094. {
  29095. return 'gnu_find';
  29096. }
  29097. protected function buildFormatSorting(Command $command, $sort)
  29098. {
  29099. switch ($sort) {
  29100. case SortableIterator::SORT_BY_NAME:
  29101. $command->ins('sort')->add('| sort');
  29102. return;
  29103. case SortableIterator::SORT_BY_TYPE:
  29104. $format = '%y';
  29105. break;
  29106. case SortableIterator::SORT_BY_ACCESSED_TIME:
  29107. $format = '%A@';
  29108. break;
  29109. case SortableIterator::SORT_BY_CHANGED_TIME:
  29110. $format = '%C@';
  29111. break;
  29112. case SortableIterator::SORT_BY_MODIFIED_TIME:
  29113. $format = '%T@';
  29114. break;
  29115. default:
  29116. throw new \InvalidArgumentException(sprintf('Unknown sort options: %s.', $sort));
  29117. }
  29118. $command
  29119. ->get('find')
  29120. ->add('-printf')
  29121. ->arg($format.' %h/%f\\n')
  29122. ->add('| sort | cut')
  29123. ->arg('-d ')
  29124. ->arg('-f2-')
  29125. ;
  29126. }
  29127. protected function canBeUsed()
  29128. {
  29129. return $this->shell->getType() === Shell::TYPE_UNIX && parent::canBeUsed();
  29130. }
  29131. protected function buildFindCommand(Command $command, $dir)
  29132. {
  29133. return parent::buildFindCommand($command, $dir)->add('-regextype posix-extended');
  29134. }
  29135. protected function buildContentFiltering(Command $command, array $contains, $not = false)
  29136. {
  29137. foreach ($contains as $contain) {
  29138. $expr = Expression::create($contain);
  29139. $command
  29140. ->add('| xargs -I{} -r grep -I')
  29141. ->add($expr->isCaseSensitive() ? null : '-i')
  29142. ->add($not ? '-L' : '-l')
  29143. ->add('-Ee')->arg($expr->renderPattern())
  29144. ->add('{}')
  29145. ;
  29146. }
  29147. }
  29148. }
  29149. <?php
  29150. namespace Symfony\Component\Finder\Adapter;
  29151. use Symfony\Component\Finder\Iterator;
  29152. class PhpAdapter extends AbstractAdapter
  29153. {
  29154. public function searchInDirectory($dir)
  29155. {
  29156. $flags = \RecursiveDirectoryIterator::SKIP_DOTS;
  29157. if ($this->followLinks) {
  29158. $flags |= \RecursiveDirectoryIterator::FOLLOW_SYMLINKS;
  29159. }
  29160. $iterator = new \RecursiveIteratorIterator(
  29161. new Iterator\RecursiveDirectoryIterator($dir, $flags, $this->ignoreUnreadableDirs),
  29162. \RecursiveIteratorIterator::SELF_FIRST
  29163. );
  29164. if ($this->minDepth > 0 || $this->maxDepth < PHP_INT_MAX) {
  29165. $iterator = new Iterator\DepthRangeFilterIterator($iterator, $this->minDepth, $this->maxDepth);
  29166. }
  29167. if ($this->mode) {
  29168. $iterator = new Iterator\FileTypeFilterIterator($iterator, $this->mode);
  29169. }
  29170. if ($this->exclude) {
  29171. $iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
  29172. }
  29173. if ($this->names || $this->notNames) {
  29174. $iterator = new Iterator\FilenameFilterIterator($iterator, $this->names, $this->notNames);
  29175. }
  29176. if ($this->contains || $this->notContains) {
  29177. $iterator = new Iterator\FilecontentFilterIterator($iterator, $this->contains, $this->notContains);
  29178. }
  29179. if ($this->sizes) {
  29180. $iterator = new Iterator\SizeRangeFilterIterator($iterator, $this->sizes);
  29181. }
  29182. if ($this->dates) {
  29183. $iterator = new Iterator\DateRangeFilterIterator($iterator, $this->dates);
  29184. }
  29185. if ($this->filters) {
  29186. $iterator = new Iterator\CustomFilterIterator($iterator, $this->filters);
  29187. }
  29188. if ($this->sort) {
  29189. $iteratorAggregate = new Iterator\SortableIterator($iterator, $this->sort);
  29190. $iterator = $iteratorAggregate->getIterator();
  29191. }
  29192. if ($this->paths || $this->notPaths) {
  29193. $iterator = new Iterator\PathFilterIterator($iterator, $this->paths, $this->notPaths);
  29194. }
  29195. return $iterator;
  29196. }
  29197. public function getName()
  29198. {
  29199. return 'php';
  29200. }
  29201. protected function canBeUsed()
  29202. {
  29203. return true;
  29204. }
  29205. }
  29206. <?php
  29207. namespace Symfony\Component\Finder\Comparator;
  29208. class Comparator
  29209. {
  29210. private $target;
  29211. private $operator = '==';
  29212. public function getTarget()
  29213. {
  29214. return $this->target;
  29215. }
  29216. public function setTarget($target)
  29217. {
  29218. $this->target = $target;
  29219. }
  29220. public function getOperator()
  29221. {
  29222. return $this->operator;
  29223. }
  29224. public function setOperator($operator)
  29225. {
  29226. if (!$operator) {
  29227. $operator = '==';
  29228. }
  29229. if (!in_array($operator, array('>', '<', '>=', '<=', '==', '!='))) {
  29230. throw new \InvalidArgumentException(sprintf('Invalid operator "%s".', $operator));
  29231. }
  29232. $this->operator = $operator;
  29233. }
  29234. public function test($test)
  29235. {
  29236. switch ($this->operator) {
  29237. case '>':
  29238. return $test > $this->target;
  29239. case '>=':
  29240. return $test >= $this->target;
  29241. case '<':
  29242. return $test < $this->target;
  29243. case '<=':
  29244. return $test <= $this->target;
  29245. case '!=':
  29246. return $test != $this->target;
  29247. }
  29248. return $test == $this->target;
  29249. }
  29250. }
  29251. <?php
  29252. namespace Symfony\Component\Finder\Comparator;
  29253. class DateComparator extends Comparator
  29254. {
  29255. public function __construct($test)
  29256. {
  29257. if (!preg_match('#^\s*(==|!=|[<>]=?|after|since|before|until)?\s*(.+?)\s*$#i', $test, $matches)) {
  29258. throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a date test.', $test));
  29259. }
  29260. try {
  29261. $date = new \DateTime($matches[2]);
  29262. $target = $date->format('U');
  29263. } catch (\Exception $e) {
  29264. throw new \InvalidArgumentException(sprintf('"%s" is not a valid date.', $matches[2]));
  29265. }
  29266. $operator = isset($matches[1]) ? $matches[1] : '==';
  29267. if ('since' === $operator || 'after' === $operator) {
  29268. $operator = '>';
  29269. }
  29270. if ('until' === $operator || 'before' === $operator) {
  29271. $operator = '<';
  29272. }
  29273. $this->setOperator($operator);
  29274. $this->setTarget($target);
  29275. }
  29276. }
  29277. <?php
  29278. namespace Symfony\Component\Finder\Comparator;
  29279. class NumberComparator extends Comparator
  29280. {
  29281. public function __construct($test)
  29282. {
  29283. if (!preg_match('#^\s*(==|!=|[<>]=?)?\s*([0-9\.]+)\s*([kmg]i?)?\s*$#i', $test, $matches)) {
  29284. throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a number test.', $test));
  29285. }
  29286. $target = $matches[2];
  29287. if (!is_numeric($target)) {
  29288. throw new \InvalidArgumentException(sprintf('Invalid number "%s".', $target));
  29289. }
  29290. if (isset($matches[3])) {
  29291. switch (strtolower($matches[3])) {
  29292. case 'k':
  29293. $target *= 1000;
  29294. break;
  29295. case 'ki':
  29296. $target *= 1024;
  29297. break;
  29298. case 'm':
  29299. $target *= 1000000;
  29300. break;
  29301. case 'mi':
  29302. $target *= 1024 * 1024;
  29303. break;
  29304. case 'g':
  29305. $target *= 1000000000;
  29306. break;
  29307. case 'gi':
  29308. $target *= 1024 * 1024 * 1024;
  29309. break;
  29310. }
  29311. }
  29312. $this->setTarget($target);
  29313. $this->setOperator(isset($matches[1]) ? $matches[1] : '==');
  29314. }
  29315. }
  29316. <?php
  29317. namespace Symfony\Component\Finder\Exception;
  29318. class AccessDeniedException extends \UnexpectedValueException
  29319. {
  29320. }
  29321. <?php
  29322. namespace Symfony\Component\Finder\Exception;
  29323. use Symfony\Component\Finder\Adapter\AdapterInterface;
  29324. class AdapterFailureException extends \RuntimeException implements ExceptionInterface
  29325. {
  29326. private $adapter;
  29327. public function __construct(AdapterInterface $adapter, $message = null, \Exception $previous = null)
  29328. {
  29329. $this->adapter = $adapter;
  29330. parent::__construct($message ?: 'Search failed with "'.$adapter->getName().'" adapter.', $previous);
  29331. }
  29332. public function getAdapter()
  29333. {
  29334. return $this->adapter;
  29335. }
  29336. }
  29337. <?php
  29338. namespace Symfony\Component\Finder\Exception;
  29339. interface ExceptionInterface
  29340. {
  29341. public function getAdapter();
  29342. }
  29343. <?php
  29344. namespace Symfony\Component\Finder\Exception;
  29345. class OperationNotPermitedException extends AdapterFailureException
  29346. {
  29347. }
  29348. <?php
  29349. namespace Symfony\Component\Finder\Exception;
  29350. use Symfony\Component\Finder\Adapter\AdapterInterface;
  29351. use Symfony\Component\Finder\Shell\Command;
  29352. class ShellCommandFailureException extends AdapterFailureException
  29353. {
  29354. private $command;
  29355. public function __construct(AdapterInterface $adapter, Command $command, \Exception $previous = null)
  29356. {
  29357. $this->command = $command;
  29358. parent::__construct($adapter, 'Shell command failed: "'.$command->join().'".', $previous);
  29359. }
  29360. public function getCommand()
  29361. {
  29362. return $this->command;
  29363. }
  29364. }
  29365. <?php
  29366. namespace Symfony\Component\Finder\Expression;
  29367. class Expression implements ValueInterface
  29368. {
  29369. const TYPE_REGEX = 1;
  29370. const TYPE_GLOB = 2;
  29371. private $value;
  29372. public static function create($expr)
  29373. {
  29374. return new self($expr);
  29375. }
  29376. public function __construct($expr)
  29377. {
  29378. try {
  29379. $this->value = Regex::create($expr);
  29380. } catch (\InvalidArgumentException $e) {
  29381. $this->value = new Glob($expr);
  29382. }
  29383. }
  29384. public function __toString()
  29385. {
  29386. return $this->render();
  29387. }
  29388. public function render()
  29389. {
  29390. return $this->value->render();
  29391. }
  29392. public function renderPattern()
  29393. {
  29394. return $this->value->renderPattern();
  29395. }
  29396. public function isCaseSensitive()
  29397. {
  29398. return $this->value->isCaseSensitive();
  29399. }
  29400. public function getType()
  29401. {
  29402. return $this->value->getType();
  29403. }
  29404. public function prepend($expr)
  29405. {
  29406. $this->value->prepend($expr);
  29407. return $this;
  29408. }
  29409. public function append($expr)
  29410. {
  29411. $this->value->append($expr);
  29412. return $this;
  29413. }
  29414. public function isRegex()
  29415. {
  29416. return self::TYPE_REGEX === $this->value->getType();
  29417. }
  29418. public function isGlob()
  29419. {
  29420. return self::TYPE_GLOB === $this->value->getType();
  29421. }
  29422. public function getGlob()
  29423. {
  29424. if (self::TYPE_GLOB !== $this->value->getType()) {
  29425. throw new \LogicException('Regex can\'t be transformed to glob.');
  29426. }
  29427. return $this->value;
  29428. }
  29429. public function getRegex()
  29430. {
  29431. return self::TYPE_REGEX === $this->value->getType() ? $this->value : $this->value->toRegex();
  29432. }
  29433. }
  29434. <?php
  29435. namespace Symfony\Component\Finder\Expression;
  29436. class Glob implements ValueInterface
  29437. {
  29438. private $pattern;
  29439. public function __construct($pattern)
  29440. {
  29441. $this->pattern = $pattern;
  29442. }
  29443. public function render()
  29444. {
  29445. return $this->pattern;
  29446. }
  29447. public function renderPattern()
  29448. {
  29449. return $this->pattern;
  29450. }
  29451. public function getType()
  29452. {
  29453. return Expression::TYPE_GLOB;
  29454. }
  29455. public function isCaseSensitive()
  29456. {
  29457. return true;
  29458. }
  29459. public function prepend($expr)
  29460. {
  29461. $this->pattern = $expr.$this->pattern;
  29462. return $this;
  29463. }
  29464. public function append($expr)
  29465. {
  29466. $this->pattern .= $expr;
  29467. return $this;
  29468. }
  29469. public function isExpandable()
  29470. {
  29471. return false !== strpos($this->pattern, '{')
  29472. && false !== strpos($this->pattern, '}');
  29473. }
  29474. public function toRegex($strictLeadingDot = true, $strictWildcardSlash = true)
  29475. {
  29476. $firstByte = true;
  29477. $escaping = false;
  29478. $inCurlies = 0;
  29479. $regex = '';
  29480. $sizeGlob = strlen($this->pattern);
  29481. for ($i = 0; $i < $sizeGlob; ++$i) {
  29482. $car = $this->pattern[$i];
  29483. if ($firstByte) {
  29484. if ($strictLeadingDot && '.' !== $car) {
  29485. $regex .= '(?=[^\.])';
  29486. }
  29487. $firstByte = false;
  29488. }
  29489. if ('/' === $car) {
  29490. $firstByte = true;
  29491. }
  29492. if ('.' === $car || '(' === $car || ')' === $car || '|' === $car || '+' === $car || '^' === $car || '$' === $car) {
  29493. $regex .= "\\$car";
  29494. } elseif ('*' === $car) {
  29495. $regex .= $escaping ? '\\*' : ($strictWildcardSlash ? '[^/]*' : '.*');
  29496. } elseif ('?' === $car) {
  29497. $regex .= $escaping ? '\\?' : ($strictWildcardSlash ? '[^/]' : '.');
  29498. } elseif ('{' === $car) {
  29499. $regex .= $escaping ? '\\{' : '(';
  29500. if (!$escaping) {
  29501. ++$inCurlies;
  29502. }
  29503. } elseif ('}' === $car && $inCurlies) {
  29504. $regex .= $escaping ? '}' : ')';
  29505. if (!$escaping) {
  29506. --$inCurlies;
  29507. }
  29508. } elseif (',' === $car && $inCurlies) {
  29509. $regex .= $escaping ? ',' : '|';
  29510. } elseif ('\\' === $car) {
  29511. if ($escaping) {
  29512. $regex .= '\\\\';
  29513. $escaping = false;
  29514. } else {
  29515. $escaping = true;
  29516. }
  29517. continue;
  29518. } else {
  29519. $regex .= $car;
  29520. }
  29521. $escaping = false;
  29522. }
  29523. return new Regex('^'.$regex.'$');
  29524. }
  29525. }
  29526. <?php
  29527. namespace Symfony\Component\Finder\Expression;
  29528. class Regex implements ValueInterface
  29529. {
  29530. const START_FLAG = '^';
  29531. const END_FLAG = '$';
  29532. const BOUNDARY = '~';
  29533. const JOKER = '.*';
  29534. const ESCAPING = '\\';
  29535. private $pattern;
  29536. private $options;
  29537. private $startFlag;
  29538. private $endFlag;
  29539. private $startJoker;
  29540. private $endJoker;
  29541. public static function create($expr)
  29542. {
  29543. if (preg_match('/^(.{3,}?)([imsxuADU]*)$/', $expr, $m)) {
  29544. $start = substr($m[1], 0, 1);
  29545. $end = substr($m[1], -1);
  29546. if (
  29547. ($start === $end && !preg_match('/[*?[:alnum:] \\\\]/', $start))
  29548. || ($start === '{' && $end === '}')
  29549. || ($start === '(' && $end === ')')
  29550. ) {
  29551. return new self(substr($m[1], 1, -1), $m[2], $end);
  29552. }
  29553. }
  29554. throw new \InvalidArgumentException('Given expression is not a regex.');
  29555. }
  29556. public function __construct($pattern, $options = '', $delimiter = null)
  29557. {
  29558. if (null !== $delimiter) {
  29559. $pattern = str_replace('\\'.$delimiter, $delimiter, $pattern);
  29560. }
  29561. $this->parsePattern($pattern);
  29562. $this->options = $options;
  29563. }
  29564. public function __toString()
  29565. {
  29566. return $this->render();
  29567. }
  29568. public function render()
  29569. {
  29570. return self::BOUNDARY
  29571. .$this->renderPattern()
  29572. .self::BOUNDARY
  29573. .$this->options;
  29574. }
  29575. public function renderPattern()
  29576. {
  29577. return ($this->startFlag ? self::START_FLAG : '')
  29578. .($this->startJoker ? self::JOKER : '')
  29579. .str_replace(self::BOUNDARY, '\\'.self::BOUNDARY, $this->pattern)
  29580. .($this->endJoker ? self::JOKER : '')
  29581. .($this->endFlag ? self::END_FLAG : '');
  29582. }
  29583. public function isCaseSensitive()
  29584. {
  29585. return !$this->hasOption('i');
  29586. }
  29587. public function getType()
  29588. {
  29589. return Expression::TYPE_REGEX;
  29590. }
  29591. public function prepend($expr)
  29592. {
  29593. $this->pattern = $expr.$this->pattern;
  29594. return $this;
  29595. }
  29596. public function append($expr)
  29597. {
  29598. $this->pattern .= $expr;
  29599. return $this;
  29600. }
  29601. public function hasOption($option)
  29602. {
  29603. return false !== strpos($this->options, $option);
  29604. }
  29605. public function addOption($option)
  29606. {
  29607. if (!$this->hasOption($option)) {
  29608. $this->options .= $option;
  29609. }
  29610. return $this;
  29611. }
  29612. public function removeOption($option)
  29613. {
  29614. $this->options = str_replace($option, '', $this->options);
  29615. return $this;
  29616. }
  29617. public function setStartFlag($startFlag)
  29618. {
  29619. $this->startFlag = $startFlag;
  29620. return $this;
  29621. }
  29622. public function hasStartFlag()
  29623. {
  29624. return $this->startFlag;
  29625. }
  29626. public function setEndFlag($endFlag)
  29627. {
  29628. $this->endFlag = (bool) $endFlag;
  29629. return $this;
  29630. }
  29631. public function hasEndFlag()
  29632. {
  29633. return $this->endFlag;
  29634. }
  29635. public function setStartJoker($startJoker)
  29636. {
  29637. $this->startJoker = $startJoker;
  29638. return $this;
  29639. }
  29640. public function hasStartJoker()
  29641. {
  29642. return $this->startJoker;
  29643. }
  29644. public function setEndJoker($endJoker)
  29645. {
  29646. $this->endJoker = (bool) $endJoker;
  29647. return $this;
  29648. }
  29649. public function hasEndJoker()
  29650. {
  29651. return $this->endJoker;
  29652. }
  29653. public function replaceJokers($replacement)
  29654. {
  29655. $replace = function ($subject) use ($replacement) {
  29656. $subject = $subject[0];
  29657. $replace = 0 === substr_count($subject, '\\') % 2;
  29658. return $replace ? str_replace('.', $replacement, $subject) : $subject;
  29659. };
  29660. $this->pattern = preg_replace_callback('~[\\\\]*\\.~', $replace, $this->pattern);
  29661. return $this;
  29662. }
  29663. private function parsePattern($pattern)
  29664. {
  29665. if ($this->startFlag = self::START_FLAG === substr($pattern, 0, 1)) {
  29666. $pattern = substr($pattern, 1);
  29667. }
  29668. if ($this->startJoker = self::JOKER === substr($pattern, 0, 2)) {
  29669. $pattern = substr($pattern, 2);
  29670. }
  29671. if ($this->endFlag = (self::END_FLAG === substr($pattern, -1) && self::ESCAPING !== substr($pattern, -2, -1))) {
  29672. $pattern = substr($pattern, 0, -1);
  29673. }
  29674. if ($this->endJoker = (self::JOKER === substr($pattern, -2) && self::ESCAPING !== substr($pattern, -3, -2))) {
  29675. $pattern = substr($pattern, 0, -2);
  29676. }
  29677. $this->pattern = $pattern;
  29678. }
  29679. }
  29680. <?php
  29681. namespace Symfony\Component\Finder\Expression;
  29682. interface ValueInterface
  29683. {
  29684. public function render();
  29685. public function renderPattern();
  29686. public function isCaseSensitive();
  29687. public function getType();
  29688. public function prepend($expr);
  29689. public function append($expr);
  29690. }
  29691. <?php
  29692. namespace Symfony\Component\Finder;
  29693. use Symfony\Component\Finder\Adapter\AdapterInterface;
  29694. use Symfony\Component\Finder\Adapter\GnuFindAdapter;
  29695. use Symfony\Component\Finder\Adapter\BsdFindAdapter;
  29696. use Symfony\Component\Finder\Adapter\PhpAdapter;
  29697. use Symfony\Component\Finder\Comparator\DateComparator;
  29698. use Symfony\Component\Finder\Comparator\NumberComparator;
  29699. use Symfony\Component\Finder\Exception\ExceptionInterface;
  29700. use Symfony\Component\Finder\Iterator\CustomFilterIterator;
  29701. use Symfony\Component\Finder\Iterator\DateRangeFilterIterator;
  29702. use Symfony\Component\Finder\Iterator\DepthRangeFilterIterator;
  29703. use Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator;
  29704. use Symfony\Component\Finder\Iterator\FilecontentFilterIterator;
  29705. use Symfony\Component\Finder\Iterator\FilenameFilterIterator;
  29706. use Symfony\Component\Finder\Iterator\SizeRangeFilterIterator;
  29707. use Symfony\Component\Finder\Iterator\SortableIterator;
  29708. class Finder implements \IteratorAggregate, \Countable
  29709. {
  29710. const IGNORE_VCS_FILES = 1;
  29711. const IGNORE_DOT_FILES = 2;
  29712. private $mode = 0;
  29713. private $names = array();
  29714. private $notNames = array();
  29715. private $exclude = array();
  29716. private $filters = array();
  29717. private $depths = array();
  29718. private $sizes = array();
  29719. private $followLinks = false;
  29720. private $sort = false;
  29721. private $ignore = 0;
  29722. private $dirs = array();
  29723. private $dates = array();
  29724. private $iterators = array();
  29725. private $contains = array();
  29726. private $notContains = array();
  29727. private $adapters = array();
  29728. private $paths = array();
  29729. private $notPaths = array();
  29730. private $ignoreUnreadableDirs = false;
  29731. private static $vcsPatterns = array('.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg');
  29732. public function __construct()
  29733. {
  29734. $this->ignore = static::IGNORE_VCS_FILES | static::IGNORE_DOT_FILES;
  29735. $this
  29736. ->addAdapter(new GnuFindAdapter())
  29737. ->addAdapter(new BsdFindAdapter())
  29738. ->addAdapter(new PhpAdapter(), -50)
  29739. ->setAdapter('php')
  29740. ;
  29741. }
  29742. public static function create()
  29743. {
  29744. return new static();
  29745. }
  29746. public function addAdapter(AdapterInterface $adapter, $priority = 0)
  29747. {
  29748. $this->adapters[$adapter->getName()] = array(
  29749. 'adapter' => $adapter,
  29750. 'priority' => $priority,
  29751. 'selected' => false,
  29752. );
  29753. return $this->sortAdapters();
  29754. }
  29755. public function useBestAdapter()
  29756. {
  29757. $this->resetAdapterSelection();
  29758. return $this->sortAdapters();
  29759. }
  29760. public function setAdapter($name)
  29761. {
  29762. if (!isset($this->adapters[$name])) {
  29763. throw new \InvalidArgumentException(sprintf('Adapter "%s" does not exist.', $name));
  29764. }
  29765. $this->resetAdapterSelection();
  29766. $this->adapters[$name]['selected'] = true;
  29767. return $this->sortAdapters();
  29768. }
  29769. public function removeAdapters()
  29770. {
  29771. $this->adapters = array();
  29772. return $this;
  29773. }
  29774. public function getAdapters()
  29775. {
  29776. return array_values(array_map(function (array $adapter) {
  29777. return $adapter['adapter'];
  29778. }, $this->adapters));
  29779. }
  29780. public function directories()
  29781. {
  29782. $this->mode = Iterator\FileTypeFilterIterator::ONLY_DIRECTORIES;
  29783. return $this;
  29784. }
  29785. public function files()
  29786. {
  29787. $this->mode = Iterator\FileTypeFilterIterator::ONLY_FILES;
  29788. return $this;
  29789. }
  29790. public function depth($level)
  29791. {
  29792. $this->depths[] = new Comparator\NumberComparator($level);
  29793. return $this;
  29794. }
  29795. public function date($date)
  29796. {
  29797. $this->dates[] = new Comparator\DateComparator($date);
  29798. return $this;
  29799. }
  29800. public function name($pattern)
  29801. {
  29802. $this->names[] = $pattern;
  29803. return $this;
  29804. }
  29805. public function notName($pattern)
  29806. {
  29807. $this->notNames[] = $pattern;
  29808. return $this;
  29809. }
  29810. public function contains($pattern)
  29811. {
  29812. $this->contains[] = $pattern;
  29813. return $this;
  29814. }
  29815. public function notContains($pattern)
  29816. {
  29817. $this->notContains[] = $pattern;
  29818. return $this;
  29819. }
  29820. public function path($pattern)
  29821. {
  29822. $this->paths[] = $pattern;
  29823. return $this;
  29824. }
  29825. public function notPath($pattern)
  29826. {
  29827. $this->notPaths[] = $pattern;
  29828. return $this;
  29829. }
  29830. public function size($size)
  29831. {
  29832. $this->sizes[] = new Comparator\NumberComparator($size);
  29833. return $this;
  29834. }
  29835. public function exclude($dirs)
  29836. {
  29837. $this->exclude = array_merge($this->exclude, (array) $dirs);
  29838. return $this;
  29839. }
  29840. public function ignoreDotFiles($ignoreDotFiles)
  29841. {
  29842. if ($ignoreDotFiles) {
  29843. $this->ignore |= static::IGNORE_DOT_FILES;
  29844. } else {
  29845. $this->ignore &= ~static::IGNORE_DOT_FILES;
  29846. }
  29847. return $this;
  29848. }
  29849. public function ignoreVCS($ignoreVCS)
  29850. {
  29851. if ($ignoreVCS) {
  29852. $this->ignore |= static::IGNORE_VCS_FILES;
  29853. } else {
  29854. $this->ignore &= ~static::IGNORE_VCS_FILES;
  29855. }
  29856. return $this;
  29857. }
  29858. public static function addVCSPattern($pattern)
  29859. {
  29860. foreach ((array) $pattern as $p) {
  29861. self::$vcsPatterns[] = $p;
  29862. }
  29863. self::$vcsPatterns = array_unique(self::$vcsPatterns);
  29864. }
  29865. public function sort(\Closure $closure)
  29866. {
  29867. $this->sort = $closure;
  29868. return $this;
  29869. }
  29870. public function sortByName()
  29871. {
  29872. $this->sort = Iterator\SortableIterator::SORT_BY_NAME;
  29873. return $this;
  29874. }
  29875. public function sortByType()
  29876. {
  29877. $this->sort = Iterator\SortableIterator::SORT_BY_TYPE;
  29878. return $this;
  29879. }
  29880. public function sortByAccessedTime()
  29881. {
  29882. $this->sort = Iterator\SortableIterator::SORT_BY_ACCESSED_TIME;
  29883. return $this;
  29884. }
  29885. public function sortByChangedTime()
  29886. {
  29887. $this->sort = Iterator\SortableIterator::SORT_BY_CHANGED_TIME;
  29888. return $this;
  29889. }
  29890. public function sortByModifiedTime()
  29891. {
  29892. $this->sort = Iterator\SortableIterator::SORT_BY_MODIFIED_TIME;
  29893. return $this;
  29894. }
  29895. public function filter(\Closure $closure)
  29896. {
  29897. $this->filters[] = $closure;
  29898. return $this;
  29899. }
  29900. public function followLinks()
  29901. {
  29902. $this->followLinks = true;
  29903. return $this;
  29904. }
  29905. public function ignoreUnreadableDirs($ignore = true)
  29906. {
  29907. $this->ignoreUnreadableDirs = (bool) $ignore;
  29908. return $this;
  29909. }
  29910. public function in($dirs)
  29911. {
  29912. $resolvedDirs = array();
  29913. foreach ((array) $dirs as $dir) {
  29914. if (is_dir($dir)) {
  29915. $resolvedDirs[] = $dir;
  29916. } elseif ($glob = glob($dir, (defined('GLOB_BRACE') ? GLOB_BRACE : 0) | GLOB_ONLYDIR)) {
  29917. $resolvedDirs = array_merge($resolvedDirs, $glob);
  29918. } else {
  29919. throw new \InvalidArgumentException(sprintf('The "%s" directory does not exist.', $dir));
  29920. }
  29921. }
  29922. $this->dirs = array_merge($this->dirs, $resolvedDirs);
  29923. return $this;
  29924. }
  29925. public function getIterator()
  29926. {
  29927. if (0 === count($this->dirs) && 0 === count($this->iterators)) {
  29928. throw new \LogicException('You must call one of in() or append() methods before iterating over a Finder.');
  29929. }
  29930. if (1 === count($this->dirs) && 0 === count($this->iterators)) {
  29931. return $this->searchInDirectory($this->dirs[0]);
  29932. }
  29933. $iterator = new \AppendIterator();
  29934. foreach ($this->dirs as $dir) {
  29935. $iterator->append($this->searchInDirectory($dir));
  29936. }
  29937. foreach ($this->iterators as $it) {
  29938. $iterator->append($it);
  29939. }
  29940. return $iterator;
  29941. }
  29942. public function append($iterator)
  29943. {
  29944. if ($iterator instanceof \IteratorAggregate) {
  29945. $this->iterators[] = $iterator->getIterator();
  29946. } elseif ($iterator instanceof \Iterator) {
  29947. $this->iterators[] = $iterator;
  29948. } elseif ($iterator instanceof \Traversable || is_array($iterator)) {
  29949. $it = new \ArrayIterator();
  29950. foreach ($iterator as $file) {
  29951. $it->append($file instanceof \SplFileInfo ? $file : new \SplFileInfo($file));
  29952. }
  29953. $this->iterators[] = $it;
  29954. } else {
  29955. throw new \InvalidArgumentException('Finder::append() method wrong argument type.');
  29956. }
  29957. return $this;
  29958. }
  29959. public function count()
  29960. {
  29961. return iterator_count($this->getIterator());
  29962. }
  29963. private function sortAdapters()
  29964. {
  29965. uasort($this->adapters, function (array $a, array $b) {
  29966. if ($a['selected'] || $b['selected']) {
  29967. return $a['selected'] ? -1 : 1;
  29968. }
  29969. return $a['priority'] > $b['priority'] ? -1 : 1;
  29970. });
  29971. return $this;
  29972. }
  29973. private function searchInDirectory($dir)
  29974. {
  29975. if (static::IGNORE_VCS_FILES === (static::IGNORE_VCS_FILES & $this->ignore)) {
  29976. $this->exclude = array_merge($this->exclude, self::$vcsPatterns);
  29977. }
  29978. if (static::IGNORE_DOT_FILES === (static::IGNORE_DOT_FILES & $this->ignore)) {
  29979. $this->notPaths[] = '#(^|/)\..+(/|$)#';
  29980. }
  29981. foreach ($this->adapters as $adapter) {
  29982. if ($adapter['adapter']->isSupported()) {
  29983. try {
  29984. return $this
  29985. ->buildAdapter($adapter['adapter'])
  29986. ->searchInDirectory($dir);
  29987. } catch (ExceptionInterface $e) {
  29988. }
  29989. }
  29990. }
  29991. throw new \RuntimeException('No supported adapter found.');
  29992. }
  29993. private function buildAdapter(AdapterInterface $adapter)
  29994. {
  29995. return $adapter
  29996. ->setFollowLinks($this->followLinks)
  29997. ->setDepths($this->depths)
  29998. ->setMode($this->mode)
  29999. ->setExclude($this->exclude)
  30000. ->setNames($this->names)
  30001. ->setNotNames($this->notNames)
  30002. ->setContains($this->contains)
  30003. ->setNotContains($this->notContains)
  30004. ->setSizes($this->sizes)
  30005. ->setDates($this->dates)
  30006. ->setFilters($this->filters)
  30007. ->setSort($this->sort)
  30008. ->setPath($this->paths)
  30009. ->setNotPath($this->notPaths)
  30010. ->ignoreUnreadableDirs($this->ignoreUnreadableDirs);
  30011. }
  30012. private function resetAdapterSelection()
  30013. {
  30014. $this->adapters = array_map(function (array $properties) {
  30015. $properties['selected'] = false;
  30016. return $properties;
  30017. }, $this->adapters);
  30018. }
  30019. }
  30020. <?php
  30021. namespace Symfony\Component\Finder;
  30022. class Glob
  30023. {
  30024. public static function toRegex($glob, $strictLeadingDot = true, $strictWildcardSlash = true)
  30025. {
  30026. $firstByte = true;
  30027. $escaping = false;
  30028. $inCurlies = 0;
  30029. $regex = '';
  30030. $sizeGlob = strlen($glob);
  30031. for ($i = 0; $i < $sizeGlob; ++$i) {
  30032. $car = $glob[$i];
  30033. if ($firstByte) {
  30034. if ($strictLeadingDot && '.' !== $car) {
  30035. $regex .= '(?=[^\.])';
  30036. }
  30037. $firstByte = false;
  30038. }
  30039. if ('/' === $car) {
  30040. $firstByte = true;
  30041. }
  30042. if ('.' === $car || '(' === $car || ')' === $car || '|' === $car || '+' === $car || '^' === $car || '$' === $car) {
  30043. $regex .= "\\$car";
  30044. } elseif ('*' === $car) {
  30045. $regex .= $escaping ? '\\*' : ($strictWildcardSlash ? '[^/]*' : '.*');
  30046. } elseif ('?' === $car) {
  30047. $regex .= $escaping ? '\\?' : ($strictWildcardSlash ? '[^/]' : '.');
  30048. } elseif ('{' === $car) {
  30049. $regex .= $escaping ? '\\{' : '(';
  30050. if (!$escaping) {
  30051. ++$inCurlies;
  30052. }
  30053. } elseif ('}' === $car && $inCurlies) {
  30054. $regex .= $escaping ? '}' : ')';
  30055. if (!$escaping) {
  30056. --$inCurlies;
  30057. }
  30058. } elseif (',' === $car && $inCurlies) {
  30059. $regex .= $escaping ? ',' : '|';
  30060. } elseif ('\\' === $car) {
  30061. if ($escaping) {
  30062. $regex .= '\\\\';
  30063. $escaping = false;
  30064. } else {
  30065. $escaping = true;
  30066. }
  30067. continue;
  30068. } else {
  30069. $regex .= $car;
  30070. }
  30071. $escaping = false;
  30072. }
  30073. return '#^'.$regex.'$#';
  30074. }
  30075. }
  30076. <?php
  30077. namespace Symfony\Component\Finder\Iterator;
  30078. class CustomFilterIterator extends FilterIterator
  30079. {
  30080. private $filters = array();
  30081. public function __construct(\Iterator $iterator, array $filters)
  30082. {
  30083. foreach ($filters as $filter) {
  30084. if (!is_callable($filter)) {
  30085. throw new \InvalidArgumentException('Invalid PHP callback.');
  30086. }
  30087. }
  30088. $this->filters = $filters;
  30089. parent::__construct($iterator);
  30090. }
  30091. public function accept()
  30092. {
  30093. $fileinfo = $this->current();
  30094. foreach ($this->filters as $filter) {
  30095. if (false === call_user_func($filter, $fileinfo)) {
  30096. return false;
  30097. }
  30098. }
  30099. return true;
  30100. }
  30101. }
  30102. <?php
  30103. namespace Symfony\Component\Finder\Iterator;
  30104. use Symfony\Component\Finder\Comparator\DateComparator;
  30105. class DateRangeFilterIterator extends FilterIterator
  30106. {
  30107. private $comparators = array();
  30108. public function __construct(\Iterator $iterator, array $comparators)
  30109. {
  30110. $this->comparators = $comparators;
  30111. parent::__construct($iterator);
  30112. }
  30113. public function accept()
  30114. {
  30115. $fileinfo = $this->current();
  30116. if (!file_exists($fileinfo->getRealPath())) {
  30117. return false;
  30118. }
  30119. $filedate = $fileinfo->getMTime();
  30120. foreach ($this->comparators as $compare) {
  30121. if (!$compare->test($filedate)) {
  30122. return false;
  30123. }
  30124. }
  30125. return true;
  30126. }
  30127. }
  30128. <?php
  30129. namespace Symfony\Component\Finder\Iterator;
  30130. class DepthRangeFilterIterator extends FilterIterator
  30131. {
  30132. private $minDepth = 0;
  30133. public function __construct(\RecursiveIteratorIterator $iterator, $minDepth = 0, $maxDepth = PHP_INT_MAX)
  30134. {
  30135. $this->minDepth = $minDepth;
  30136. $iterator->setMaxDepth(PHP_INT_MAX === $maxDepth ? -1 : $maxDepth);
  30137. parent::__construct($iterator);
  30138. }
  30139. public function accept()
  30140. {
  30141. return $this->getInnerIterator()->getDepth() >= $this->minDepth;
  30142. }
  30143. }
  30144. <?php
  30145. namespace Symfony\Component\Finder\Iterator;
  30146. class ExcludeDirectoryFilterIterator extends FilterIterator
  30147. {
  30148. private $patterns = array();
  30149. public function __construct(\Iterator $iterator, array $directories)
  30150. {
  30151. foreach ($directories as $directory) {
  30152. $this->patterns[] = '#(^|/)'.preg_quote($directory, '#').'(/|$)#';
  30153. }
  30154. parent::__construct($iterator);
  30155. }
  30156. public function accept()
  30157. {
  30158. $path = $this->isDir() ? $this->current()->getRelativePathname() : $this->current()->getRelativePath();
  30159. $path = strtr($path, '\\', '/');
  30160. foreach ($this->patterns as $pattern) {
  30161. if (preg_match($pattern, $path)) {
  30162. return false;
  30163. }
  30164. }
  30165. return true;
  30166. }
  30167. }
  30168. <?php
  30169. namespace Symfony\Component\Finder\Iterator;
  30170. use Symfony\Component\Finder\SplFileInfo;
  30171. class FilePathsIterator extends \ArrayIterator
  30172. {
  30173. private $baseDir;
  30174. private $baseDirLength;
  30175. private $subPath;
  30176. private $subPathname;
  30177. private $current;
  30178. public function __construct(array $paths, $baseDir)
  30179. {
  30180. $this->baseDir = $baseDir;
  30181. $this->baseDirLength = strlen($baseDir);
  30182. parent::__construct($paths);
  30183. }
  30184. public function __call($name, array $arguments)
  30185. {
  30186. return call_user_func_array(array($this->current(), $name), $arguments);
  30187. }
  30188. public function current()
  30189. {
  30190. return $this->current;
  30191. }
  30192. public function key()
  30193. {
  30194. return $this->current->getPathname();
  30195. }
  30196. public function next()
  30197. {
  30198. parent::next();
  30199. $this->buildProperties();
  30200. }
  30201. public function rewind()
  30202. {
  30203. parent::rewind();
  30204. $this->buildProperties();
  30205. }
  30206. public function getSubPath()
  30207. {
  30208. return $this->subPath;
  30209. }
  30210. public function getSubPathname()
  30211. {
  30212. return $this->subPathname;
  30213. }
  30214. private function buildProperties()
  30215. {
  30216. $absolutePath = parent::current();
  30217. if ($this->baseDir === substr($absolutePath, 0, $this->baseDirLength)) {
  30218. $this->subPathname = ltrim(substr($absolutePath, $this->baseDirLength), '/\\');
  30219. $dir = dirname($this->subPathname);
  30220. $this->subPath = '.' === $dir ? '' : $dir;
  30221. } else {
  30222. $this->subPath = $this->subPathname = '';
  30223. }
  30224. $this->current = new SplFileInfo(parent::current(), $this->subPath, $this->subPathname);
  30225. }
  30226. }
  30227. <?php
  30228. namespace Symfony\Component\Finder\Iterator;
  30229. class FileTypeFilterIterator extends FilterIterator
  30230. {
  30231. const ONLY_FILES = 1;
  30232. const ONLY_DIRECTORIES = 2;
  30233. private $mode;
  30234. public function __construct(\Iterator $iterator, $mode)
  30235. {
  30236. $this->mode = $mode;
  30237. parent::__construct($iterator);
  30238. }
  30239. public function accept()
  30240. {
  30241. $fileinfo = $this->current();
  30242. if (self::ONLY_DIRECTORIES === (self::ONLY_DIRECTORIES & $this->mode) && $fileinfo->isFile()) {
  30243. return false;
  30244. } elseif (self::ONLY_FILES === (self::ONLY_FILES & $this->mode) && $fileinfo->isDir()) {
  30245. return false;
  30246. }
  30247. return true;
  30248. }
  30249. }
  30250. <?php
  30251. namespace Symfony\Component\Finder\Iterator;
  30252. class FilecontentFilterIterator extends MultiplePcreFilterIterator
  30253. {
  30254. public function accept()
  30255. {
  30256. if (!$this->matchRegexps && !$this->noMatchRegexps) {
  30257. return true;
  30258. }
  30259. $fileinfo = $this->current();
  30260. if ($fileinfo->isDir() || !$fileinfo->isReadable()) {
  30261. return false;
  30262. }
  30263. $content = $fileinfo->getContents();
  30264. if (!$content) {
  30265. return false;
  30266. }
  30267. foreach ($this->noMatchRegexps as $regex) {
  30268. if (preg_match($regex, $content)) {
  30269. return false;
  30270. }
  30271. }
  30272. $match = true;
  30273. if ($this->matchRegexps) {
  30274. $match = false;
  30275. foreach ($this->matchRegexps as $regex) {
  30276. if (preg_match($regex, $content)) {
  30277. return true;
  30278. }
  30279. }
  30280. }
  30281. return $match;
  30282. }
  30283. protected function toRegex($str)
  30284. {
  30285. return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/';
  30286. }
  30287. }
  30288. <?php
  30289. namespace Symfony\Component\Finder\Iterator;
  30290. use Symfony\Component\Finder\Expression\Expression;
  30291. class FilenameFilterIterator extends MultiplePcreFilterIterator
  30292. {
  30293. public function accept()
  30294. {
  30295. $filename = $this->current()->getFilename();
  30296. foreach ($this->noMatchRegexps as $regex) {
  30297. if (preg_match($regex, $filename)) {
  30298. return false;
  30299. }
  30300. }
  30301. $match = true;
  30302. if ($this->matchRegexps) {
  30303. $match = false;
  30304. foreach ($this->matchRegexps as $regex) {
  30305. if (preg_match($regex, $filename)) {
  30306. return true;
  30307. }
  30308. }
  30309. }
  30310. return $match;
  30311. }
  30312. protected function toRegex($str)
  30313. {
  30314. return Expression::create($str)->getRegex()->render();
  30315. }
  30316. }
  30317. <?php
  30318. namespace Symfony\Component\Finder\Iterator;
  30319. abstract class FilterIterator extends \FilterIterator
  30320. {
  30321. public function rewind()
  30322. {
  30323. $iterator = $this;
  30324. while ($iterator instanceof \OuterIterator) {
  30325. $innerIterator = $iterator->getInnerIterator();
  30326. if ($innerIterator instanceof RecursiveDirectoryIterator) {
  30327. if ($innerIterator->isRewindable()) {
  30328. $innerIterator->next();
  30329. $innerIterator->rewind();
  30330. }
  30331. } elseif ($iterator->getInnerIterator() instanceof \FilesystemIterator) {
  30332. $iterator->getInnerIterator()->next();
  30333. $iterator->getInnerIterator()->rewind();
  30334. }
  30335. $iterator = $iterator->getInnerIterator();
  30336. }
  30337. parent::rewind();
  30338. }
  30339. }
  30340. <?php
  30341. namespace Symfony\Component\Finder\Iterator;
  30342. use Symfony\Component\Finder\Expression\Expression;
  30343. abstract class MultiplePcreFilterIterator extends FilterIterator
  30344. {
  30345. protected $matchRegexps = array();
  30346. protected $noMatchRegexps = array();
  30347. public function __construct(\Iterator $iterator, array $matchPatterns, array $noMatchPatterns)
  30348. {
  30349. foreach ($matchPatterns as $pattern) {
  30350. $this->matchRegexps[] = $this->toRegex($pattern);
  30351. }
  30352. foreach ($noMatchPatterns as $pattern) {
  30353. $this->noMatchRegexps[] = $this->toRegex($pattern);
  30354. }
  30355. parent::__construct($iterator);
  30356. }
  30357. protected function isRegex($str)
  30358. {
  30359. return Expression::create($str)->isRegex();
  30360. }
  30361. abstract protected function toRegex($str);
  30362. }
  30363. <?php
  30364. namespace Symfony\Component\Finder\Iterator;
  30365. class PathFilterIterator extends MultiplePcreFilterIterator
  30366. {
  30367. public function accept()
  30368. {
  30369. $filename = $this->current()->getRelativePathname();
  30370. if ('\\' === DIRECTORY_SEPARATOR) {
  30371. $filename = strtr($filename, '\\', '/');
  30372. }
  30373. foreach ($this->noMatchRegexps as $regex) {
  30374. if (preg_match($regex, $filename)) {
  30375. return false;
  30376. }
  30377. }
  30378. $match = true;
  30379. if ($this->matchRegexps) {
  30380. $match = false;
  30381. foreach ($this->matchRegexps as $regex) {
  30382. if (preg_match($regex, $filename)) {
  30383. return true;
  30384. }
  30385. }
  30386. }
  30387. return $match;
  30388. }
  30389. protected function toRegex($str)
  30390. {
  30391. return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/';
  30392. }
  30393. }
  30394. <?php
  30395. namespace Symfony\Component\Finder\Iterator;
  30396. use Symfony\Component\Finder\Exception\AccessDeniedException;
  30397. use Symfony\Component\Finder\SplFileInfo;
  30398. class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
  30399. {
  30400. private $ignoreUnreadableDirs;
  30401. private $rewindable;
  30402. public function __construct($path, $flags, $ignoreUnreadableDirs = false)
  30403. {
  30404. if ($flags & (self::CURRENT_AS_PATHNAME | self::CURRENT_AS_SELF)) {
  30405. throw new \RuntimeException('This iterator only support returning current as fileinfo.');
  30406. }
  30407. parent::__construct($path, $flags);
  30408. $this->ignoreUnreadableDirs = $ignoreUnreadableDirs;
  30409. }
  30410. public function current()
  30411. {
  30412. return new SplFileInfo(parent::current()->getPathname(), $this->getSubPath(), $this->getSubPathname());
  30413. }
  30414. public function getChildren()
  30415. {
  30416. try {
  30417. $children = parent::getChildren();
  30418. if ($children instanceof self) {
  30419. $children->ignoreUnreadableDirs = $this->ignoreUnreadableDirs;
  30420. }
  30421. return $children;
  30422. } catch (\UnexpectedValueException $e) {
  30423. if ($this->ignoreUnreadableDirs) {
  30424. return new \RecursiveArrayIterator(array());
  30425. } else {
  30426. throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e);
  30427. }
  30428. }
  30429. }
  30430. public function rewind()
  30431. {
  30432. if (false === $this->isRewindable()) {
  30433. return;
  30434. }
  30435. parent::next();
  30436. parent::rewind();
  30437. }
  30438. public function isRewindable()
  30439. {
  30440. if (null !== $this->rewindable) {
  30441. return $this->rewindable;
  30442. }
  30443. if (false !== $stream = @opendir($this->getPath())) {
  30444. $infos = stream_get_meta_data($stream);
  30445. closedir($stream);
  30446. if ($infos['seekable']) {
  30447. return $this->rewindable = true;
  30448. }
  30449. }
  30450. return $this->rewindable = false;
  30451. }
  30452. }
  30453. <?php
  30454. namespace Symfony\Component\Finder\Iterator;
  30455. use Symfony\Component\Finder\Comparator\NumberComparator;
  30456. class SizeRangeFilterIterator extends FilterIterator
  30457. {
  30458. private $comparators = array();
  30459. public function __construct(\Iterator $iterator, array $comparators)
  30460. {
  30461. $this->comparators = $comparators;
  30462. parent::__construct($iterator);
  30463. }
  30464. public function accept()
  30465. {
  30466. $fileinfo = $this->current();
  30467. if (!$fileinfo->isFile()) {
  30468. return true;
  30469. }
  30470. $filesize = $fileinfo->getSize();
  30471. foreach ($this->comparators as $compare) {
  30472. if (!$compare->test($filesize)) {
  30473. return false;
  30474. }
  30475. }
  30476. return true;
  30477. }
  30478. }
  30479. <?php
  30480. namespace Symfony\Component\Finder\Iterator;
  30481. class SortableIterator implements \IteratorAggregate
  30482. {
  30483. const SORT_BY_NAME = 1;
  30484. const SORT_BY_TYPE = 2;
  30485. const SORT_BY_ACCESSED_TIME = 3;
  30486. const SORT_BY_CHANGED_TIME = 4;
  30487. const SORT_BY_MODIFIED_TIME = 5;
  30488. private $iterator;
  30489. private $sort;
  30490. public function __construct(\Traversable $iterator, $sort)
  30491. {
  30492. $this->iterator = $iterator;
  30493. if (self::SORT_BY_NAME === $sort) {
  30494. $this->sort = function ($a, $b) {
  30495. return strcmp($a->getRealpath(), $b->getRealpath());
  30496. };
  30497. } elseif (self::SORT_BY_TYPE === $sort) {
  30498. $this->sort = function ($a, $b) {
  30499. if ($a->isDir() && $b->isFile()) {
  30500. return -1;
  30501. } elseif ($a->isFile() && $b->isDir()) {
  30502. return 1;
  30503. }
  30504. return strcmp($a->getRealpath(), $b->getRealpath());
  30505. };
  30506. } elseif (self::SORT_BY_ACCESSED_TIME === $sort) {
  30507. $this->sort = function ($a, $b) {
  30508. return ($a->getATime() - $b->getATime());
  30509. };
  30510. } elseif (self::SORT_BY_CHANGED_TIME === $sort) {
  30511. $this->sort = function ($a, $b) {
  30512. return ($a->getCTime() - $b->getCTime());
  30513. };
  30514. } elseif (self::SORT_BY_MODIFIED_TIME === $sort) {
  30515. $this->sort = function ($a, $b) {
  30516. return ($a->getMTime() - $b->getMTime());
  30517. };
  30518. } elseif (is_callable($sort)) {
  30519. $this->sort = $sort;
  30520. } else {
  30521. throw new \InvalidArgumentException('The SortableIterator takes a PHP callable or a valid built-in sort algorithm as an argument.');
  30522. }
  30523. }
  30524. public function getIterator()
  30525. {
  30526. $array = iterator_to_array($this->iterator, true);
  30527. uasort($array, $this->sort);
  30528. return new \ArrayIterator($array);
  30529. }
  30530. }
  30531. Copyright (c) 2004-2015 Fabien Potencier
  30532. Permission is hereby granted, free of charge, to any person obtaining a copy
  30533. of this software and associated documentation files (the "Software"), to deal
  30534. in the Software without restriction, including without limitation the rights
  30535. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  30536. copies of the Software, and to permit persons to whom the Software is furnished
  30537. to do so, subject to the following conditions:
  30538. The above copyright notice and this permission notice shall be included in all
  30539. copies or substantial portions of the Software.
  30540. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  30541. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  30542. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  30543. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  30544. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  30545. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  30546. THE SOFTWARE.
  30547. <?php
  30548. namespace Symfony\Component\Finder\Shell;
  30549. class Command
  30550. {
  30551. private $parent;
  30552. private $bits = array();
  30553. private $labels = array();
  30554. private $errorHandler;
  30555. public function __construct(Command $parent = null)
  30556. {
  30557. $this->parent = $parent;
  30558. }
  30559. public function __toString()
  30560. {
  30561. return $this->join();
  30562. }
  30563. public static function create(Command $parent = null)
  30564. {
  30565. return new self($parent);
  30566. }
  30567. public static function escape($input)
  30568. {
  30569. return escapeshellcmd($input);
  30570. }
  30571. public static function quote($input)
  30572. {
  30573. return escapeshellarg($input);
  30574. }
  30575. public function add($bit)
  30576. {
  30577. $this->bits[] = $bit;
  30578. return $this;
  30579. }
  30580. public function top($bit)
  30581. {
  30582. array_unshift($this->bits, $bit);
  30583. foreach ($this->labels as $label => $index) {
  30584. $this->labels[$label] += 1;
  30585. }
  30586. return $this;
  30587. }
  30588. public function arg($arg)
  30589. {
  30590. $this->bits[] = self::quote($arg);
  30591. return $this;
  30592. }
  30593. public function cmd($esc)
  30594. {
  30595. $this->bits[] = self::escape($esc);
  30596. return $this;
  30597. }
  30598. public function ins($label)
  30599. {
  30600. if (isset($this->labels[$label])) {
  30601. throw new \RuntimeException(sprintf('Label "%s" already exists.', $label));
  30602. }
  30603. $this->bits[] = self::create($this);
  30604. $this->labels[$label] = count($this->bits) - 1;
  30605. return $this->bits[$this->labels[$label]];
  30606. }
  30607. public function get($label)
  30608. {
  30609. if (!isset($this->labels[$label])) {
  30610. throw new \RuntimeException(sprintf('Label "%s" does not exist.', $label));
  30611. }
  30612. return $this->bits[$this->labels[$label]];
  30613. }
  30614. public function end()
  30615. {
  30616. if (null === $this->parent) {
  30617. throw new \RuntimeException('Calling end on root command doesn\'t make sense.');
  30618. }
  30619. return $this->parent;
  30620. }
  30621. public function length()
  30622. {
  30623. return count($this->bits);
  30624. }
  30625. public function setErrorHandler(\Closure $errorHandler)
  30626. {
  30627. $this->errorHandler = $errorHandler;
  30628. return $this;
  30629. }
  30630. public function getErrorHandler()
  30631. {
  30632. return $this->errorHandler;
  30633. }
  30634. public function execute()
  30635. {
  30636. if (null === $errorHandler = $this->errorHandler) {
  30637. exec($this->join(), $output);
  30638. } else {
  30639. $process = proc_open($this->join(), array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes);
  30640. $output = preg_split('~(\r\n|\r|\n)~', stream_get_contents($pipes[1]), -1, PREG_SPLIT_NO_EMPTY);
  30641. if ($error = stream_get_contents($pipes[2])) {
  30642. $errorHandler($error);
  30643. }
  30644. proc_close($process);
  30645. }
  30646. return $output ?: array();
  30647. }
  30648. public function join()
  30649. {
  30650. return implode(' ', array_filter(
  30651. array_map(function ($bit) {
  30652. return $bit instanceof Command ? $bit->join() : ($bit ?: null);
  30653. }, $this->bits),
  30654. function ($bit) { return null !== $bit; }
  30655. ));
  30656. }
  30657. public function addAtIndex($bit, $index)
  30658. {
  30659. array_splice($this->bits, $index, 0, $bit instanceof self ? array($bit) : $bit);
  30660. return $this;
  30661. }
  30662. }
  30663. <?php
  30664. namespace Symfony\Component\Finder\Shell;
  30665. class Shell
  30666. {
  30667. const TYPE_UNIX = 1;
  30668. const TYPE_DARWIN = 2;
  30669. const TYPE_CYGWIN = 3;
  30670. const TYPE_WINDOWS = 4;
  30671. const TYPE_BSD = 5;
  30672. private $type;
  30673. public function getType()
  30674. {
  30675. if (null === $this->type) {
  30676. $this->type = $this->guessType();
  30677. }
  30678. return $this->type;
  30679. }
  30680. public function testCommand($command)
  30681. {
  30682. if (!function_exists('exec')) {
  30683. return false;
  30684. }
  30685. $testCommand = 'which ';
  30686. if (self::TYPE_WINDOWS === $this->type) {
  30687. $testCommand = 'where ';
  30688. }
  30689. $command = escapeshellcmd($command);
  30690. exec($testCommand.$command, $output, $code);
  30691. return 0 === $code && count($output) > 0;
  30692. }
  30693. private function guessType()
  30694. {
  30695. $os = strtolower(PHP_OS);
  30696. if (false !== strpos($os, 'cygwin')) {
  30697. return self::TYPE_CYGWIN;
  30698. }
  30699. if (false !== strpos($os, 'darwin')) {
  30700. return self::TYPE_DARWIN;
  30701. }
  30702. if (false !== strpos($os, 'bsd')) {
  30703. return self::TYPE_BSD;
  30704. }
  30705. if (0 === strpos($os, 'win')) {
  30706. return self::TYPE_WINDOWS;
  30707. }
  30708. return self::TYPE_UNIX;
  30709. }
  30710. }
  30711. <?php
  30712. namespace Symfony\Component\Finder;
  30713. class SplFileInfo extends \SplFileInfo
  30714. {
  30715. private $relativePath;
  30716. private $relativePathname;
  30717. public function __construct($file, $relativePath, $relativePathname)
  30718. {
  30719. parent::__construct($file);
  30720. $this->relativePath = $relativePath;
  30721. $this->relativePathname = $relativePathname;
  30722. }
  30723. public function getRelativePath()
  30724. {
  30725. return $this->relativePath;
  30726. }
  30727. public function getRelativePathname()
  30728. {
  30729. return $this->relativePathname;
  30730. }
  30731. public function getContents()
  30732. {
  30733. $level = error_reporting(0);
  30734. $content = file_get_contents($this->getPathname());
  30735. error_reporting($level);
  30736. if (false === $content) {
  30737. $error = error_get_last();
  30738. throw new \RuntimeException($error['message']);
  30739. }
  30740. return $content;
  30741. }
  30742. }
  30743. <?php
  30744. namespace Symfony\Component\Process\Exception;
  30745. interface ExceptionInterface
  30746. {
  30747. }
  30748. <?php
  30749. namespace Symfony\Component\Process\Exception;
  30750. class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
  30751. {
  30752. }
  30753. <?php
  30754. namespace Symfony\Component\Process\Exception;
  30755. class LogicException extends \LogicException implements ExceptionInterface
  30756. {
  30757. }
  30758. <?php
  30759. namespace Symfony\Component\Process\Exception;
  30760. use Symfony\Component\Process\Process;
  30761. class ProcessFailedException extends RuntimeException
  30762. {
  30763. private $process;
  30764. public function __construct(Process $process)
  30765. {
  30766. if ($process->isSuccessful()) {
  30767. throw new InvalidArgumentException('Expected a failed process, but the given process was successful.');
  30768. }
  30769. $error = sprintf('The command "%s" failed.'."\nExit Code: %s(%s)",
  30770. $process->getCommandLine(),
  30771. $process->getExitCode(),
  30772. $process->getExitCodeText()
  30773. );
  30774. if (!$process->isOutputDisabled()) {
  30775. $error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
  30776. $process->getOutput(),
  30777. $process->getErrorOutput()
  30778. );
  30779. }
  30780. parent::__construct($error);
  30781. $this->process = $process;
  30782. }
  30783. public function getProcess()
  30784. {
  30785. return $this->process;
  30786. }
  30787. }
  30788. <?php
  30789. namespace Symfony\Component\Process\Exception;
  30790. use Symfony\Component\Process\Process;
  30791. class ProcessTimedOutException extends RuntimeException
  30792. {
  30793. const TYPE_GENERAL = 1;
  30794. const TYPE_IDLE = 2;
  30795. private $process;
  30796. private $timeoutType;
  30797. public function __construct(Process $process, $timeoutType)
  30798. {
  30799. $this->process = $process;
  30800. $this->timeoutType = $timeoutType;
  30801. parent::__construct(sprintf(
  30802. 'The process "%s" exceeded the timeout of %s seconds.',
  30803. $process->getCommandLine(),
  30804. $this->getExceededTimeout()
  30805. ));
  30806. }
  30807. public function getProcess()
  30808. {
  30809. return $this->process;
  30810. }
  30811. public function isGeneralTimeout()
  30812. {
  30813. return $this->timeoutType === self::TYPE_GENERAL;
  30814. }
  30815. public function isIdleTimeout()
  30816. {
  30817. return $this->timeoutType === self::TYPE_IDLE;
  30818. }
  30819. public function getExceededTimeout()
  30820. {
  30821. switch ($this->timeoutType) {
  30822. case self::TYPE_GENERAL:
  30823. return $this->process->getTimeout();
  30824. case self::TYPE_IDLE:
  30825. return $this->process->getIdleTimeout();
  30826. default:
  30827. throw new \LogicException(sprintf('Unknown timeout type "%d".', $this->timeoutType));
  30828. }
  30829. }
  30830. }
  30831. <?php
  30832. namespace Symfony\Component\Process\Exception;
  30833. class RuntimeException extends \RuntimeException implements ExceptionInterface
  30834. {
  30835. }
  30836. <?php
  30837. namespace Symfony\Component\Process;
  30838. class ExecutableFinder
  30839. {
  30840. private $suffixes = array('.exe', '.bat', '.cmd', '.com');
  30841. public function setSuffixes(array $suffixes)
  30842. {
  30843. $this->suffixes = $suffixes;
  30844. }
  30845. public function addSuffix($suffix)
  30846. {
  30847. $this->suffixes[] = $suffix;
  30848. }
  30849. public function find($name, $default = null, array $extraDirs = array())
  30850. {
  30851. if (ini_get('open_basedir')) {
  30852. $searchPath = explode(PATH_SEPARATOR, ini_get('open_basedir'));
  30853. $dirs = array();
  30854. foreach ($searchPath as $path) {
  30855. if (is_dir($path)) {
  30856. $dirs[] = $path;
  30857. } else {
  30858. if (basename($path) == $name && is_executable($path)) {
  30859. return $path;
  30860. }
  30861. }
  30862. }
  30863. } else {
  30864. $dirs = array_merge(
  30865. explode(PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')),
  30866. $extraDirs
  30867. );
  30868. }
  30869. $suffixes = array('');
  30870. if ('\\' === DIRECTORY_SEPARATOR) {
  30871. $pathExt = getenv('PATHEXT');
  30872. $suffixes = $pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes;
  30873. }
  30874. foreach ($suffixes as $suffix) {
  30875. foreach ($dirs as $dir) {
  30876. if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && ('\\' === DIRECTORY_SEPARATOR || is_executable($file))) {
  30877. return $file;
  30878. }
  30879. }
  30880. }
  30881. return $default;
  30882. }
  30883. }
  30884. Copyright (c) 2004-2015 Fabien Potencier
  30885. Permission is hereby granted, free of charge, to any person obtaining a copy
  30886. of this software and associated documentation files (the "Software"), to deal
  30887. in the Software without restriction, including without limitation the rights
  30888. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  30889. copies of the Software, and to permit persons to whom the Software is furnished
  30890. to do so, subject to the following conditions:
  30891. The above copyright notice and this permission notice shall be included in all
  30892. copies or substantial portions of the Software.
  30893. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  30894. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  30895. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  30896. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  30897. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  30898. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  30899. THE SOFTWARE.
  30900. <?php
  30901. namespace Symfony\Component\Process;
  30902. class PhpExecutableFinder
  30903. {
  30904. private $executableFinder;
  30905. public function __construct()
  30906. {
  30907. $this->executableFinder = new ExecutableFinder();
  30908. }
  30909. public function find($includeArgs = true)
  30910. {
  30911. if (defined('HHVM_VERSION')) {
  30912. return (getenv('PHP_BINARY') ?: PHP_BINARY).($includeArgs ? ' '.implode(' ', $this->findArguments()) : '');
  30913. }
  30914. if (defined('PHP_BINARY') && PHP_BINARY && in_array(PHP_SAPI, array('cli', 'cli-server')) && is_file(PHP_BINARY)) {
  30915. return PHP_BINARY;
  30916. }
  30917. if ($php = getenv('PHP_PATH')) {
  30918. if (!is_executable($php)) {
  30919. return false;
  30920. }
  30921. return $php;
  30922. }
  30923. if ($php = getenv('PHP_PEAR_PHP_BIN')) {
  30924. if (is_executable($php)) {
  30925. return $php;
  30926. }
  30927. }
  30928. $dirs = array(PHP_BINDIR);
  30929. if ('\\' === DIRECTORY_SEPARATOR) {
  30930. $dirs[] = 'C:\xampp\php\\';
  30931. }
  30932. return $this->executableFinder->find('php', false, $dirs);
  30933. }
  30934. public function findArguments()
  30935. {
  30936. $arguments = array();
  30937. if (defined('HHVM_VERSION')) {
  30938. $arguments[] = '--php';
  30939. }
  30940. return $arguments;
  30941. }
  30942. }
  30943. <?php
  30944. namespace Symfony\Component\Process;
  30945. use Symfony\Component\Process\Exception\RuntimeException;
  30946. class PhpProcess extends Process
  30947. {
  30948. public function __construct($script, $cwd = null, array $env = array(), $timeout = 60, array $options = array())
  30949. {
  30950. $executableFinder = new PhpExecutableFinder();
  30951. if (false === $php = $executableFinder->find()) {
  30952. $php = null;
  30953. }
  30954. parent::__construct($php, $cwd, $env, $script, $timeout, $options);
  30955. }
  30956. public function setPhpBinary($php)
  30957. {
  30958. $this->setCommandLine($php);
  30959. }
  30960. public function start($callback = null)
  30961. {
  30962. if (null === $this->getCommandLine()) {
  30963. throw new RuntimeException('Unable to find the PHP executable.');
  30964. }
  30965. parent::start($callback);
  30966. }
  30967. }
  30968. <?php
  30969. namespace Symfony\Component\Process\Pipes;
  30970. abstract class AbstractPipes implements PipesInterface
  30971. {
  30972. public $pipes = array();
  30973. protected $inputBuffer = '';
  30974. protected $input;
  30975. private $blocked = true;
  30976. public function close()
  30977. {
  30978. foreach ($this->pipes as $pipe) {
  30979. fclose($pipe);
  30980. }
  30981. $this->pipes = array();
  30982. }
  30983. protected function hasSystemCallBeenInterrupted()
  30984. {
  30985. $lastError = error_get_last();
  30986. return isset($lastError['message']) && false !== stripos($lastError['message'], 'interrupted system call');
  30987. }
  30988. protected function unblock()
  30989. {
  30990. if (!$this->blocked) {
  30991. return;
  30992. }
  30993. foreach ($this->pipes as $pipe) {
  30994. stream_set_blocking($pipe, 0);
  30995. }
  30996. if (null !== $this->input) {
  30997. stream_set_blocking($this->input, 0);
  30998. }
  30999. $this->blocked = false;
  31000. }
  31001. }
  31002. <?php
  31003. namespace Symfony\Component\Process\Pipes;
  31004. interface PipesInterface
  31005. {
  31006. const CHUNK_SIZE = 16384;
  31007. public function getDescriptors();
  31008. public function getFiles();
  31009. public function readAndWrite($blocking, $close = false);
  31010. public function areOpen();
  31011. public function close();
  31012. }
  31013. <?php
  31014. namespace Symfony\Component\Process\Pipes;
  31015. use Symfony\Component\Process\Process;
  31016. class UnixPipes extends AbstractPipes
  31017. {
  31018. private $ttyMode;
  31019. private $ptyMode;
  31020. private $disableOutput;
  31021. public function __construct($ttyMode, $ptyMode, $input, $disableOutput)
  31022. {
  31023. $this->ttyMode = (bool) $ttyMode;
  31024. $this->ptyMode = (bool) $ptyMode;
  31025. $this->disableOutput = (bool) $disableOutput;
  31026. if (is_resource($input)) {
  31027. $this->input = $input;
  31028. } else {
  31029. $this->inputBuffer = (string) $input;
  31030. }
  31031. }
  31032. public function __destruct()
  31033. {
  31034. $this->close();
  31035. }
  31036. public function getDescriptors()
  31037. {
  31038. if ($this->disableOutput) {
  31039. $nullstream = fopen('/dev/null', 'c');
  31040. return array(
  31041. array('pipe', 'r'),
  31042. $nullstream,
  31043. $nullstream,
  31044. );
  31045. }
  31046. if ($this->ttyMode) {
  31047. return array(
  31048. array('file', '/dev/tty', 'r'),
  31049. array('file', '/dev/tty', 'w'),
  31050. array('file', '/dev/tty', 'w'),
  31051. );
  31052. }
  31053. if ($this->ptyMode && Process::isPtySupported()) {
  31054. return array(
  31055. array('pty'),
  31056. array('pty'),
  31057. array('pty'),
  31058. );
  31059. }
  31060. return array(
  31061. array('pipe', 'r'),
  31062. array('pipe', 'w'),
  31063. array('pipe', 'w'),
  31064. );
  31065. }
  31066. public function getFiles()
  31067. {
  31068. return array();
  31069. }
  31070. public function readAndWrite($blocking, $close = false)
  31071. {
  31072. if (1 === count($this->pipes) && array(0) === array_keys($this->pipes)) {
  31073. fclose($this->pipes[0]);
  31074. unset($this->pipes[0]);
  31075. }
  31076. if (empty($this->pipes)) {
  31077. return array();
  31078. }
  31079. $this->unblock();
  31080. $read = array();
  31081. if (null !== $this->input) {
  31082. $r = array_merge($this->pipes, array('input' => $this->input));
  31083. } else {
  31084. $r = $this->pipes;
  31085. }
  31086. unset($r[0]);
  31087. $w = isset($this->pipes[0]) ? array($this->pipes[0]) : null;
  31088. $e = null;
  31089. if (false === $n = @stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) {
  31090. if (!$this->hasSystemCallBeenInterrupted()) {
  31091. $this->pipes = array();
  31092. }
  31093. return $read;
  31094. }
  31095. if (0 === $n) {
  31096. return $read;
  31097. }
  31098. foreach ($r as $pipe) {
  31099. $type = (false !== $found = array_search($pipe, $this->pipes)) ? $found : 'input';
  31100. $data = '';
  31101. while ('' !== $dataread = (string) fread($pipe, self::CHUNK_SIZE)) {
  31102. $data .= $dataread;
  31103. }
  31104. if ('' !== $data) {
  31105. if ($type === 'input') {
  31106. $this->inputBuffer .= $data;
  31107. } else {
  31108. $read[$type] = $data;
  31109. }
  31110. }
  31111. if (false === $data || (true === $close && feof($pipe) && '' === $data)) {
  31112. if ($type === 'input') {
  31113. $this->input = null;
  31114. } else {
  31115. fclose($this->pipes[$type]);
  31116. unset($this->pipes[$type]);
  31117. }
  31118. }
  31119. }
  31120. if (null !== $w && 0 < count($w)) {
  31121. while (strlen($this->inputBuffer)) {
  31122. $written = fwrite($w[0], $this->inputBuffer, 2 << 18);
  31123. if ($written > 0) {
  31124. $this->inputBuffer = (string) substr($this->inputBuffer, $written);
  31125. } else {
  31126. break;
  31127. }
  31128. }
  31129. }
  31130. if ('' === $this->inputBuffer && null === $this->input && isset($this->pipes[0])) {
  31131. fclose($this->pipes[0]);
  31132. unset($this->pipes[0]);
  31133. }
  31134. return $read;
  31135. }
  31136. public function areOpen()
  31137. {
  31138. return (bool) $this->pipes;
  31139. }
  31140. public static function create(Process $process, $input)
  31141. {
  31142. return new static($process->isTty(), $process->isPty(), $input, $process->isOutputDisabled());
  31143. }
  31144. }
  31145. <?php
  31146. namespace Symfony\Component\Process\Pipes;
  31147. use Symfony\Component\Process\Process;
  31148. use Symfony\Component\Process\Exception\RuntimeException;
  31149. class WindowsPipes extends AbstractPipes
  31150. {
  31151. private $files = array();
  31152. private $fileHandles = array();
  31153. private $readBytes = array(
  31154. Process::STDOUT => 0,
  31155. Process::STDERR => 0,
  31156. );
  31157. private $disableOutput;
  31158. public function __construct($disableOutput, $input)
  31159. {
  31160. $this->disableOutput = (bool) $disableOutput;
  31161. if (!$this->disableOutput) {
  31162. $this->files = array(
  31163. Process::STDOUT => tempnam(sys_get_temp_dir(), 'sf_proc_stdout'),
  31164. Process::STDERR => tempnam(sys_get_temp_dir(), 'sf_proc_stderr'),
  31165. );
  31166. foreach ($this->files as $offset => $file) {
  31167. $this->fileHandles[$offset] = fopen($this->files[$offset], 'rb');
  31168. if (false === $this->fileHandles[$offset]) {
  31169. throw new RuntimeException('A temporary file could not be opened to write the process output to, verify that your TEMP environment variable is writable');
  31170. }
  31171. }
  31172. }
  31173. if (is_resource($input)) {
  31174. $this->input = $input;
  31175. } else {
  31176. $this->inputBuffer = $input;
  31177. }
  31178. }
  31179. public function __destruct()
  31180. {
  31181. $this->close();
  31182. $this->removeFiles();
  31183. }
  31184. public function getDescriptors()
  31185. {
  31186. if ($this->disableOutput) {
  31187. $nullstream = fopen('NUL', 'c');
  31188. return array(
  31189. array('pipe', 'r'),
  31190. $nullstream,
  31191. $nullstream,
  31192. );
  31193. }
  31194. return array(
  31195. array('pipe', 'r'),
  31196. array('file', 'NUL', 'w'),
  31197. array('file', 'NUL', 'w'),
  31198. );
  31199. }
  31200. public function getFiles()
  31201. {
  31202. return $this->files;
  31203. }
  31204. public function readAndWrite($blocking, $close = false)
  31205. {
  31206. $this->write($blocking, $close);
  31207. $read = array();
  31208. $fh = $this->fileHandles;
  31209. foreach ($fh as $type => $fileHandle) {
  31210. if (0 !== fseek($fileHandle, $this->readBytes[$type])) {
  31211. continue;
  31212. }
  31213. $data = '';
  31214. $dataread = null;
  31215. while (!feof($fileHandle)) {
  31216. if (false !== $dataread = fread($fileHandle, self::CHUNK_SIZE)) {
  31217. $data .= $dataread;
  31218. }
  31219. }
  31220. if (0 < $length = strlen($data)) {
  31221. $this->readBytes[$type] += $length;
  31222. $read[$type] = $data;
  31223. }
  31224. if (false === $dataread || (true === $close && feof($fileHandle) && '' === $data)) {
  31225. fclose($this->fileHandles[$type]);
  31226. unset($this->fileHandles[$type]);
  31227. }
  31228. }
  31229. return $read;
  31230. }
  31231. public function areOpen()
  31232. {
  31233. return (bool) $this->pipes && (bool) $this->fileHandles;
  31234. }
  31235. public function close()
  31236. {
  31237. parent::close();
  31238. foreach ($this->fileHandles as $handle) {
  31239. fclose($handle);
  31240. }
  31241. $this->fileHandles = array();
  31242. }
  31243. public static function create(Process $process, $input)
  31244. {
  31245. return new static($process->isOutputDisabled(), $input);
  31246. }
  31247. private function removeFiles()
  31248. {
  31249. foreach ($this->files as $filename) {
  31250. if (file_exists($filename)) {
  31251. @unlink($filename);
  31252. }
  31253. }
  31254. $this->files = array();
  31255. }
  31256. private function write($blocking, $close)
  31257. {
  31258. if (empty($this->pipes)) {
  31259. return;
  31260. }
  31261. $this->unblock();
  31262. $r = null !== $this->input ? array('input' => $this->input) : null;
  31263. $w = isset($this->pipes[0]) ? array($this->pipes[0]) : null;
  31264. $e = null;
  31265. if (false === $n = @stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) {
  31266. if (!$this->hasSystemCallBeenInterrupted()) {
  31267. $this->pipes = array();
  31268. }
  31269. return;
  31270. }
  31271. if (0 === $n) {
  31272. return;
  31273. }
  31274. if (null !== $w && 0 < count($r)) {
  31275. $data = '';
  31276. while ($dataread = fread($r['input'], self::CHUNK_SIZE)) {
  31277. $data .= $dataread;
  31278. }
  31279. $this->inputBuffer .= $data;
  31280. if (false === $data || (true === $close && feof($r['input']) && '' === $data)) {
  31281. $this->input = null;
  31282. }
  31283. }
  31284. if (null !== $w && 0 < count($w)) {
  31285. while (strlen($this->inputBuffer)) {
  31286. $written = fwrite($w[0], $this->inputBuffer, 2 << 18);
  31287. if ($written > 0) {
  31288. $this->inputBuffer = (string) substr($this->inputBuffer, $written);
  31289. } else {
  31290. break;
  31291. }
  31292. }
  31293. }
  31294. if ('' === $this->inputBuffer && null === $this->input && isset($this->pipes[0])) {
  31295. fclose($this->pipes[0]);
  31296. unset($this->pipes[0]);
  31297. }
  31298. }
  31299. }
  31300. <?php
  31301. namespace Symfony\Component\Process;
  31302. use Symfony\Component\Process\Exception\InvalidArgumentException;
  31303. use Symfony\Component\Process\Exception\LogicException;
  31304. use Symfony\Component\Process\Exception\ProcessFailedException;
  31305. use Symfony\Component\Process\Exception\ProcessTimedOutException;
  31306. use Symfony\Component\Process\Exception\RuntimeException;
  31307. use Symfony\Component\Process\Pipes\PipesInterface;
  31308. use Symfony\Component\Process\Pipes\UnixPipes;
  31309. use Symfony\Component\Process\Pipes\WindowsPipes;
  31310. class Process
  31311. {
  31312. const ERR = 'err';
  31313. const OUT = 'out';
  31314. const STATUS_READY = 'ready';
  31315. const STATUS_STARTED = 'started';
  31316. const STATUS_TERMINATED = 'terminated';
  31317. const STDIN = 0;
  31318. const STDOUT = 1;
  31319. const STDERR = 2;
  31320. const TIMEOUT_PRECISION = 0.2;
  31321. private $callback;
  31322. private $commandline;
  31323. private $cwd;
  31324. private $env;
  31325. private $input;
  31326. private $starttime;
  31327. private $lastOutputTime;
  31328. private $timeout;
  31329. private $idleTimeout;
  31330. private $options;
  31331. private $exitcode;
  31332. private $fallbackExitcode;
  31333. private $processInformation;
  31334. private $outputDisabled = false;
  31335. private $stdout;
  31336. private $stderr;
  31337. private $enhanceWindowsCompatibility = true;
  31338. private $enhanceSigchildCompatibility;
  31339. private $process;
  31340. private $status = self::STATUS_READY;
  31341. private $incrementalOutputOffset = 0;
  31342. private $incrementalErrorOutputOffset = 0;
  31343. private $tty;
  31344. private $pty;
  31345. private $useFileHandles = false;
  31346. private $processPipes;
  31347. private $latestSignal;
  31348. private static $sigchild;
  31349. public static $exitCodes = array(
  31350. 0 => 'OK',
  31351. 1 => 'General error',
  31352. 2 => 'Misuse of shell builtins',
  31353. 126 => 'Invoked command cannot execute',
  31354. 127 => 'Command not found',
  31355. 128 => 'Invalid exit argument',
  31356. 129 => 'Hangup',
  31357. 130 => 'Interrupt',
  31358. 131 => 'Quit and dump core',
  31359. 132 => 'Illegal instruction',
  31360. 133 => 'Trace/breakpoint trap',
  31361. 134 => 'Process aborted',
  31362. 135 => 'Bus error: "access to undefined portion of memory object"',
  31363. 136 => 'Floating point exception: "erroneous arithmetic operation"',
  31364. 137 => 'Kill (terminate immediately)',
  31365. 138 => 'User-defined 1',
  31366. 139 => 'Segmentation violation',
  31367. 140 => 'User-defined 2',
  31368. 141 => 'Write to pipe with no one reading',
  31369. 142 => 'Signal raised by alarm',
  31370. 143 => 'Termination (request to terminate)',
  31371. 145 => 'Child process terminated, stopped (or continued*)',
  31372. 146 => 'Continue if stopped',
  31373. 147 => 'Stop executing temporarily',
  31374. 148 => 'Terminal stop signal',
  31375. 149 => 'Background process attempting to read from tty ("in")',
  31376. 150 => 'Background process attempting to write to tty ("out")',
  31377. 151 => 'Urgent data available on socket',
  31378. 152 => 'CPU time limit exceeded',
  31379. 153 => 'File size limit exceeded',
  31380. 154 => 'Signal raised by timer counting virtual time: "virtual timer expired"',
  31381. 155 => 'Profiling timer expired',
  31382. 157 => 'Pollable event',
  31383. 159 => 'Bad syscall',
  31384. );
  31385. public function __construct($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = array())
  31386. {
  31387. if (!function_exists('proc_open')) {
  31388. throw new RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.');
  31389. }
  31390. $this->commandline = $commandline;
  31391. $this->cwd = $cwd;
  31392. if (null === $this->cwd && (defined('ZEND_THREAD_SAFE') || '\\' === DIRECTORY_SEPARATOR)) {
  31393. $this->cwd = getcwd();
  31394. }
  31395. if (null !== $env) {
  31396. $this->setEnv($env);
  31397. }
  31398. $this->input = $input;
  31399. $this->setTimeout($timeout);
  31400. $this->useFileHandles = '\\' === DIRECTORY_SEPARATOR;
  31401. $this->pty = false;
  31402. $this->enhanceWindowsCompatibility = true;
  31403. $this->enhanceSigchildCompatibility = '\\' !== DIRECTORY_SEPARATOR && $this->isSigchildEnabled();
  31404. $this->options = array_replace(array('suppress_errors' => true, 'binary_pipes' => true), $options);
  31405. }
  31406. public function __destruct()
  31407. {
  31408. $this->stop();
  31409. }
  31410. public function __clone()
  31411. {
  31412. $this->resetProcessData();
  31413. }
  31414. public function run($callback = null)
  31415. {
  31416. $this->start($callback);
  31417. return $this->wait();
  31418. }
  31419. public function mustRun($callback = null)
  31420. {
  31421. if ($this->isSigchildEnabled() && !$this->enhanceSigchildCompatibility) {
  31422. throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
  31423. }
  31424. if (0 !== $this->run($callback)) {
  31425. throw new ProcessFailedException($this);
  31426. }
  31427. return $this;
  31428. }
  31429. public function start($callback = null)
  31430. {
  31431. if ($this->isRunning()) {
  31432. throw new RuntimeException('Process is already running');
  31433. }
  31434. if ($this->outputDisabled && null !== $callback) {
  31435. throw new LogicException('Output has been disabled, enable it to allow the use of a callback.');
  31436. }
  31437. $this->resetProcessData();
  31438. $this->starttime = $this->lastOutputTime = microtime(true);
  31439. $this->callback = $this->buildCallback($callback);
  31440. $descriptors = $this->getDescriptors();
  31441. $commandline = $this->commandline;
  31442. if ('\\' === DIRECTORY_SEPARATOR && $this->enhanceWindowsCompatibility) {
  31443. $commandline = 'cmd /V:ON /E:ON /C "('.$commandline.')';
  31444. foreach ($this->processPipes->getFiles() as $offset => $filename) {
  31445. $commandline .= ' '.$offset.'>'.ProcessUtils::escapeArgument($filename);
  31446. }
  31447. $commandline .= '"';
  31448. if (!isset($this->options['bypass_shell'])) {
  31449. $this->options['bypass_shell'] = true;
  31450. }
  31451. }
  31452. $this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $this->env, $this->options);
  31453. if (!is_resource($this->process)) {
  31454. throw new RuntimeException('Unable to launch a new process.');
  31455. }
  31456. $this->status = self::STATUS_STARTED;
  31457. if ($this->tty) {
  31458. return;
  31459. }
  31460. $this->updateStatus(false);
  31461. $this->checkTimeout();
  31462. }
  31463. public function restart($callback = null)
  31464. {
  31465. if ($this->isRunning()) {
  31466. throw new RuntimeException('Process is already running');
  31467. }
  31468. $process = clone $this;
  31469. $process->start($callback);
  31470. return $process;
  31471. }
  31472. public function wait($callback = null)
  31473. {
  31474. $this->requireProcessIsStarted(__FUNCTION__);
  31475. $this->updateStatus(false);
  31476. if (null !== $callback) {
  31477. $this->callback = $this->buildCallback($callback);
  31478. }
  31479. do {
  31480. $this->checkTimeout();
  31481. $running = '\\' === DIRECTORY_SEPARATOR ? $this->isRunning() : $this->processPipes->areOpen();
  31482. $close = '\\' !== DIRECTORY_SEPARATOR || !$running;
  31483. $this->readPipes(true, $close);
  31484. } while ($running);
  31485. while ($this->isRunning()) {
  31486. usleep(1000);
  31487. }
  31488. if ($this->processInformation['signaled'] && $this->processInformation['termsig'] !== $this->latestSignal) {
  31489. throw new RuntimeException(sprintf('The process has been signaled with signal "%s".', $this->processInformation['termsig']));
  31490. }
  31491. return $this->exitcode;
  31492. }
  31493. public function getPid()
  31494. {
  31495. if ($this->isSigchildEnabled()) {
  31496. throw new RuntimeException('This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved.');
  31497. }
  31498. $this->updateStatus(false);
  31499. return $this->isRunning() ? $this->processInformation['pid'] : null;
  31500. }
  31501. public function signal($signal)
  31502. {
  31503. $this->doSignal($signal, true);
  31504. return $this;
  31505. }
  31506. public function disableOutput()
  31507. {
  31508. if ($this->isRunning()) {
  31509. throw new RuntimeException('Disabling output while the process is running is not possible.');
  31510. }
  31511. if (null !== $this->idleTimeout) {
  31512. throw new LogicException('Output can not be disabled while an idle timeout is set.');
  31513. }
  31514. $this->outputDisabled = true;
  31515. return $this;
  31516. }
  31517. public function enableOutput()
  31518. {
  31519. if ($this->isRunning()) {
  31520. throw new RuntimeException('Enabling output while the process is running is not possible.');
  31521. }
  31522. $this->outputDisabled = false;
  31523. return $this;
  31524. }
  31525. public function isOutputDisabled()
  31526. {
  31527. return $this->outputDisabled;
  31528. }
  31529. public function getOutput()
  31530. {
  31531. if ($this->outputDisabled) {
  31532. throw new LogicException('Output has been disabled.');
  31533. }
  31534. $this->requireProcessIsStarted(__FUNCTION__);
  31535. $this->readPipes(false, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
  31536. return $this->stdout;
  31537. }
  31538. public function getIncrementalOutput()
  31539. {
  31540. $this->requireProcessIsStarted(__FUNCTION__);
  31541. $data = $this->getOutput();
  31542. $latest = substr($data, $this->incrementalOutputOffset);
  31543. if (false === $latest) {
  31544. return '';
  31545. }
  31546. $this->incrementalOutputOffset = strlen($data);
  31547. return $latest;
  31548. }
  31549. public function clearOutput()
  31550. {
  31551. $this->stdout = '';
  31552. $this->incrementalOutputOffset = 0;
  31553. return $this;
  31554. }
  31555. public function getErrorOutput()
  31556. {
  31557. if ($this->outputDisabled) {
  31558. throw new LogicException('Output has been disabled.');
  31559. }
  31560. $this->requireProcessIsStarted(__FUNCTION__);
  31561. $this->readPipes(false, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
  31562. return $this->stderr;
  31563. }
  31564. public function getIncrementalErrorOutput()
  31565. {
  31566. $this->requireProcessIsStarted(__FUNCTION__);
  31567. $data = $this->getErrorOutput();
  31568. $latest = substr($data, $this->incrementalErrorOutputOffset);
  31569. if (false === $latest) {
  31570. return '';
  31571. }
  31572. $this->incrementalErrorOutputOffset = strlen($data);
  31573. return $latest;
  31574. }
  31575. public function clearErrorOutput()
  31576. {
  31577. $this->stderr = '';
  31578. $this->incrementalErrorOutputOffset = 0;
  31579. return $this;
  31580. }
  31581. public function getExitCode()
  31582. {
  31583. if ($this->isSigchildEnabled() && !$this->enhanceSigchildCompatibility) {
  31584. throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
  31585. }
  31586. $this->updateStatus(false);
  31587. return $this->exitcode;
  31588. }
  31589. public function getExitCodeText()
  31590. {
  31591. if (null === $exitcode = $this->getExitCode()) {
  31592. return;
  31593. }
  31594. return isset(self::$exitCodes[$exitcode]) ? self::$exitCodes[$exitcode] : 'Unknown error';
  31595. }
  31596. public function isSuccessful()
  31597. {
  31598. return 0 === $this->getExitCode();
  31599. }
  31600. public function hasBeenSignaled()
  31601. {
  31602. $this->requireProcessIsTerminated(__FUNCTION__);
  31603. if ($this->isSigchildEnabled()) {
  31604. throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
  31605. }
  31606. $this->updateStatus(false);
  31607. return $this->processInformation['signaled'];
  31608. }
  31609. public function getTermSignal()
  31610. {
  31611. $this->requireProcessIsTerminated(__FUNCTION__);
  31612. if ($this->isSigchildEnabled()) {
  31613. throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
  31614. }
  31615. $this->updateStatus(false);
  31616. return $this->processInformation['termsig'];
  31617. }
  31618. public function hasBeenStopped()
  31619. {
  31620. $this->requireProcessIsTerminated(__FUNCTION__);
  31621. $this->updateStatus(false);
  31622. return $this->processInformation['stopped'];
  31623. }
  31624. public function getStopSignal()
  31625. {
  31626. $this->requireProcessIsTerminated(__FUNCTION__);
  31627. $this->updateStatus(false);
  31628. return $this->processInformation['stopsig'];
  31629. }
  31630. public function isRunning()
  31631. {
  31632. if (self::STATUS_STARTED !== $this->status) {
  31633. return false;
  31634. }
  31635. $this->updateStatus(false);
  31636. return $this->processInformation['running'];
  31637. }
  31638. public function isStarted()
  31639. {
  31640. return $this->status != self::STATUS_READY;
  31641. }
  31642. public function isTerminated()
  31643. {
  31644. $this->updateStatus(false);
  31645. return $this->status == self::STATUS_TERMINATED;
  31646. }
  31647. public function getStatus()
  31648. {
  31649. $this->updateStatus(false);
  31650. return $this->status;
  31651. }
  31652. public function stop($timeout = 10, $signal = null)
  31653. {
  31654. $timeoutMicro = microtime(true) + $timeout;
  31655. if ($this->isRunning()) {
  31656. if ('\\' === DIRECTORY_SEPARATOR && !$this->isSigchildEnabled()) {
  31657. exec(sprintf('taskkill /F /T /PID %d 2>&1', $this->getPid()), $output, $exitCode);
  31658. if ($exitCode > 0) {
  31659. throw new RuntimeException('Unable to kill the process');
  31660. }
  31661. }
  31662. $this->doSignal(15, false);
  31663. do {
  31664. usleep(1000);
  31665. } while ($this->isRunning() && microtime(true) < $timeoutMicro);
  31666. if ($this->isRunning() && !$this->isSigchildEnabled()) {
  31667. if (null !== $signal || defined('SIGKILL')) {
  31668. $this->doSignal($signal ?: SIGKILL, false);
  31669. }
  31670. }
  31671. }
  31672. $this->updateStatus(false);
  31673. if ($this->processInformation['running']) {
  31674. $this->close();
  31675. }
  31676. return $this->exitcode;
  31677. }
  31678. public function addOutput($line)
  31679. {
  31680. $this->lastOutputTime = microtime(true);
  31681. $this->stdout .= $line;
  31682. }
  31683. public function addErrorOutput($line)
  31684. {
  31685. $this->lastOutputTime = microtime(true);
  31686. $this->stderr .= $line;
  31687. }
  31688. public function getCommandLine()
  31689. {
  31690. return $this->commandline;
  31691. }
  31692. public function setCommandLine($commandline)
  31693. {
  31694. $this->commandline = $commandline;
  31695. return $this;
  31696. }
  31697. public function getTimeout()
  31698. {
  31699. return $this->timeout;
  31700. }
  31701. public function getIdleTimeout()
  31702. {
  31703. return $this->idleTimeout;
  31704. }
  31705. public function setTimeout($timeout)
  31706. {
  31707. $this->timeout = $this->validateTimeout($timeout);
  31708. return $this;
  31709. }
  31710. public function setIdleTimeout($timeout)
  31711. {
  31712. if (null !== $timeout && $this->outputDisabled) {
  31713. throw new LogicException('Idle timeout can not be set while the output is disabled.');
  31714. }
  31715. $this->idleTimeout = $this->validateTimeout($timeout);
  31716. return $this;
  31717. }
  31718. public function setTty($tty)
  31719. {
  31720. if ('\\' === DIRECTORY_SEPARATOR && $tty) {
  31721. throw new RuntimeException('TTY mode is not supported on Windows platform.');
  31722. }
  31723. if ($tty && (!file_exists('/dev/tty') || !is_readable('/dev/tty'))) {
  31724. throw new RuntimeException('TTY mode requires /dev/tty to be readable.');
  31725. }
  31726. $this->tty = (bool) $tty;
  31727. return $this;
  31728. }
  31729. public function isTty()
  31730. {
  31731. return $this->tty;
  31732. }
  31733. public function setPty($bool)
  31734. {
  31735. $this->pty = (bool) $bool;
  31736. return $this;
  31737. }
  31738. public function isPty()
  31739. {
  31740. return $this->pty;
  31741. }
  31742. public function getWorkingDirectory()
  31743. {
  31744. if (null === $this->cwd) {
  31745. return getcwd() ?: null;
  31746. }
  31747. return $this->cwd;
  31748. }
  31749. public function setWorkingDirectory($cwd)
  31750. {
  31751. $this->cwd = $cwd;
  31752. return $this;
  31753. }
  31754. public function getEnv()
  31755. {
  31756. return $this->env;
  31757. }
  31758. public function setEnv(array $env)
  31759. {
  31760. $env = array_filter($env, function ($value) {
  31761. return !is_array($value);
  31762. });
  31763. $this->env = array();
  31764. foreach ($env as $key => $value) {
  31765. $this->env[(binary) $key] = (binary) $value;
  31766. }
  31767. return $this;
  31768. }
  31769. public function getStdin()
  31770. {
  31771. return $this->getInput();
  31772. }
  31773. public function getInput()
  31774. {
  31775. return $this->input;
  31776. }
  31777. public function setStdin($stdin)
  31778. {
  31779. return $this->setInput($stdin);
  31780. }
  31781. public function setInput($input)
  31782. {
  31783. if ($this->isRunning()) {
  31784. throw new LogicException('Input can not be set while the process is running.');
  31785. }
  31786. $this->input = ProcessUtils::validateInput(sprintf('%s::%s', __CLASS__, __FUNCTION__), $input);
  31787. return $this;
  31788. }
  31789. public function getOptions()
  31790. {
  31791. return $this->options;
  31792. }
  31793. public function setOptions(array $options)
  31794. {
  31795. $this->options = $options;
  31796. return $this;
  31797. }
  31798. public function getEnhanceWindowsCompatibility()
  31799. {
  31800. return $this->enhanceWindowsCompatibility;
  31801. }
  31802. public function setEnhanceWindowsCompatibility($enhance)
  31803. {
  31804. $this->enhanceWindowsCompatibility = (bool) $enhance;
  31805. return $this;
  31806. }
  31807. public function getEnhanceSigchildCompatibility()
  31808. {
  31809. return $this->enhanceSigchildCompatibility;
  31810. }
  31811. public function setEnhanceSigchildCompatibility($enhance)
  31812. {
  31813. $this->enhanceSigchildCompatibility = (bool) $enhance;
  31814. return $this;
  31815. }
  31816. public function checkTimeout()
  31817. {
  31818. if ($this->status !== self::STATUS_STARTED) {
  31819. return;
  31820. }
  31821. if (null !== $this->timeout && $this->timeout < microtime(true) - $this->starttime) {
  31822. $this->stop(0);
  31823. throw new ProcessTimedOutException($this, ProcessTimedOutException::TYPE_GENERAL);
  31824. }
  31825. if (null !== $this->idleTimeout && $this->idleTimeout < microtime(true) - $this->lastOutputTime) {
  31826. $this->stop(0);
  31827. throw new ProcessTimedOutException($this, ProcessTimedOutException::TYPE_IDLE);
  31828. }
  31829. }
  31830. public static function isPtySupported()
  31831. {
  31832. static $result;
  31833. if (null !== $result) {
  31834. return $result;
  31835. }
  31836. if ('\\' === DIRECTORY_SEPARATOR) {
  31837. return $result = false;
  31838. }
  31839. $proc = @proc_open('echo 1', array(array('pty'), array('pty'), array('pty')), $pipes);
  31840. if (is_resource($proc)) {
  31841. proc_close($proc);
  31842. return $result = true;
  31843. }
  31844. return $result = false;
  31845. }
  31846. private function getDescriptors()
  31847. {
  31848. if ('\\' === DIRECTORY_SEPARATOR) {
  31849. $this->processPipes = WindowsPipes::create($this, $this->input);
  31850. } else {
  31851. $this->processPipes = UnixPipes::create($this, $this->input);
  31852. }
  31853. $descriptors = $this->processPipes->getDescriptors($this->outputDisabled);
  31854. if (!$this->useFileHandles && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
  31855. $descriptors = array_merge($descriptors, array(array('pipe', 'w')));
  31856. $this->commandline = '('.$this->commandline.') 3>/dev/null; code=$?; echo $code >&3; exit $code';
  31857. }
  31858. return $descriptors;
  31859. }
  31860. protected function buildCallback($callback)
  31861. {
  31862. $that = $this;
  31863. $out = self::OUT;
  31864. $callback = function ($type, $data) use ($that, $callback, $out) {
  31865. if ($out == $type) {
  31866. $that->addOutput($data);
  31867. } else {
  31868. $that->addErrorOutput($data);
  31869. }
  31870. if (null !== $callback) {
  31871. call_user_func($callback, $type, $data);
  31872. }
  31873. };
  31874. return $callback;
  31875. }
  31876. protected function updateStatus($blocking)
  31877. {
  31878. if (self::STATUS_STARTED !== $this->status) {
  31879. return;
  31880. }
  31881. $this->processInformation = proc_get_status($this->process);
  31882. $this->captureExitCode();
  31883. $this->readPipes($blocking, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
  31884. if (!$this->processInformation['running']) {
  31885. $this->close();
  31886. }
  31887. }
  31888. protected function isSigchildEnabled()
  31889. {
  31890. if (null !== self::$sigchild) {
  31891. return self::$sigchild;
  31892. }
  31893. if (!function_exists('phpinfo')) {
  31894. return self::$sigchild = false;
  31895. }
  31896. ob_start();
  31897. phpinfo(INFO_GENERAL);
  31898. return self::$sigchild = false !== strpos(ob_get_clean(), '--enable-sigchild');
  31899. }
  31900. private function validateTimeout($timeout)
  31901. {
  31902. $timeout = (float) $timeout;
  31903. if (0.0 === $timeout) {
  31904. $timeout = null;
  31905. } elseif ($timeout < 0) {
  31906. throw new InvalidArgumentException('The timeout value must be a valid positive integer or float number.');
  31907. }
  31908. return $timeout;
  31909. }
  31910. private function readPipes($blocking, $close)
  31911. {
  31912. $result = $this->processPipes->readAndWrite($blocking, $close);
  31913. $callback = $this->callback;
  31914. foreach ($result as $type => $data) {
  31915. if (3 == $type) {
  31916. $this->fallbackExitcode = (int) $data;
  31917. } else {
  31918. $callback($type === self::STDOUT ? self::OUT : self::ERR, $data);
  31919. }
  31920. }
  31921. }
  31922. private function captureExitCode()
  31923. {
  31924. if (isset($this->processInformation['exitcode']) && -1 != $this->processInformation['exitcode']) {
  31925. $this->exitcode = $this->processInformation['exitcode'];
  31926. }
  31927. }
  31928. private function close()
  31929. {
  31930. $this->processPipes->close();
  31931. if (is_resource($this->process)) {
  31932. $exitcode = proc_close($this->process);
  31933. } else {
  31934. $exitcode = -1;
  31935. }
  31936. $this->exitcode = -1 !== $exitcode ? $exitcode : (null !== $this->exitcode ? $this->exitcode : -1);
  31937. $this->status = self::STATUS_TERMINATED;
  31938. if (-1 === $this->exitcode && null !== $this->fallbackExitcode) {
  31939. $this->exitcode = $this->fallbackExitcode;
  31940. } elseif (-1 === $this->exitcode && $this->processInformation['signaled'] && 0 < $this->processInformation['termsig']) {
  31941. $this->exitcode = 128 + $this->processInformation['termsig'];
  31942. }
  31943. return $this->exitcode;
  31944. }
  31945. private function resetProcessData()
  31946. {
  31947. $this->starttime = null;
  31948. $this->callback = null;
  31949. $this->exitcode = null;
  31950. $this->fallbackExitcode = null;
  31951. $this->processInformation = null;
  31952. $this->stdout = null;
  31953. $this->stderr = null;
  31954. $this->process = null;
  31955. $this->latestSignal = null;
  31956. $this->status = self::STATUS_READY;
  31957. $this->incrementalOutputOffset = 0;
  31958. $this->incrementalErrorOutputOffset = 0;
  31959. }
  31960. private function doSignal($signal, $throwException)
  31961. {
  31962. if (!$this->isRunning()) {
  31963. if ($throwException) {
  31964. throw new LogicException('Can not send signal on a non running process.');
  31965. }
  31966. return false;
  31967. }
  31968. if ($this->isSigchildEnabled()) {
  31969. if ($throwException) {
  31970. throw new RuntimeException('This PHP has been compiled with --enable-sigchild. The process can not be signaled.');
  31971. }
  31972. return false;
  31973. }
  31974. if (true !== @proc_terminate($this->process, $signal)) {
  31975. if ($throwException) {
  31976. throw new RuntimeException(sprintf('Error while sending signal `%s`.', $signal));
  31977. }
  31978. return false;
  31979. }
  31980. $this->latestSignal = $signal;
  31981. return true;
  31982. }
  31983. private function requireProcessIsStarted($functionName)
  31984. {
  31985. if (!$this->isStarted()) {
  31986. throw new LogicException(sprintf('Process must be started before calling %s.', $functionName));
  31987. }
  31988. }
  31989. private function requireProcessIsTerminated($functionName)
  31990. {
  31991. if (!$this->isTerminated()) {
  31992. throw new LogicException(sprintf('Process must be terminated before calling %s.', $functionName));
  31993. }
  31994. }
  31995. }
  31996. <?php
  31997. namespace Symfony\Component\Process;
  31998. use Symfony\Component\Process\Exception\InvalidArgumentException;
  31999. use Symfony\Component\Process\Exception\LogicException;
  32000. class ProcessBuilder
  32001. {
  32002. private $arguments;
  32003. private $cwd;
  32004. private $env = array();
  32005. private $input;
  32006. private $timeout = 60;
  32007. private $options = array();
  32008. private $inheritEnv = true;
  32009. private $prefix = array();
  32010. private $outputDisabled = false;
  32011. public function __construct(array $arguments = array())
  32012. {
  32013. $this->arguments = $arguments;
  32014. }
  32015. public static function create(array $arguments = array())
  32016. {
  32017. return new static($arguments);
  32018. }
  32019. public function add($argument)
  32020. {
  32021. $this->arguments[] = $argument;
  32022. return $this;
  32023. }
  32024. public function setPrefix($prefix)
  32025. {
  32026. $this->prefix = is_array($prefix) ? $prefix : array($prefix);
  32027. return $this;
  32028. }
  32029. public function setArguments(array $arguments)
  32030. {
  32031. $this->arguments = $arguments;
  32032. return $this;
  32033. }
  32034. public function setWorkingDirectory($cwd)
  32035. {
  32036. $this->cwd = $cwd;
  32037. return $this;
  32038. }
  32039. public function inheritEnvironmentVariables($inheritEnv = true)
  32040. {
  32041. $this->inheritEnv = $inheritEnv;
  32042. return $this;
  32043. }
  32044. public function setEnv($name, $value)
  32045. {
  32046. $this->env[$name] = $value;
  32047. return $this;
  32048. }
  32049. public function addEnvironmentVariables(array $variables)
  32050. {
  32051. $this->env = array_replace($this->env, $variables);
  32052. return $this;
  32053. }
  32054. public function setInput($input)
  32055. {
  32056. $this->input = ProcessUtils::validateInput(sprintf('%s::%s', __CLASS__, __FUNCTION__), $input);
  32057. return $this;
  32058. }
  32059. public function setTimeout($timeout)
  32060. {
  32061. if (null === $timeout) {
  32062. $this->timeout = null;
  32063. return $this;
  32064. }
  32065. $timeout = (float) $timeout;
  32066. if ($timeout < 0) {
  32067. throw new InvalidArgumentException('The timeout value must be a valid positive integer or float number.');
  32068. }
  32069. $this->timeout = $timeout;
  32070. return $this;
  32071. }
  32072. public function setOption($name, $value)
  32073. {
  32074. $this->options[$name] = $value;
  32075. return $this;
  32076. }
  32077. public function disableOutput()
  32078. {
  32079. $this->outputDisabled = true;
  32080. return $this;
  32081. }
  32082. public function enableOutput()
  32083. {
  32084. $this->outputDisabled = false;
  32085. return $this;
  32086. }
  32087. public function getProcess()
  32088. {
  32089. if (0 === count($this->prefix) && 0 === count($this->arguments)) {
  32090. throw new LogicException('You must add() command arguments before calling getProcess().');
  32091. }
  32092. $options = $this->options;
  32093. $arguments = array_merge($this->prefix, $this->arguments);
  32094. $script = implode(' ', array_map(array(__NAMESPACE__.'\\ProcessUtils', 'escapeArgument'), $arguments));
  32095. if ($this->inheritEnv) {
  32096. $env = array_replace($_ENV, $_SERVER, $this->env);
  32097. } else {
  32098. $env = $this->env;
  32099. }
  32100. $process = new Process($script, $this->cwd, $env, $this->input, $this->timeout, $options);
  32101. if ($this->outputDisabled) {
  32102. $process->disableOutput();
  32103. }
  32104. return $process;
  32105. }
  32106. }
  32107. <?php
  32108. namespace Symfony\Component\Process;
  32109. use Symfony\Component\Process\Exception\InvalidArgumentException;
  32110. class ProcessUtils
  32111. {
  32112. private function __construct()
  32113. {
  32114. }
  32115. public static function escapeArgument($argument)
  32116. {
  32117. if ('\\' === DIRECTORY_SEPARATOR) {
  32118. if ('' === $argument) {
  32119. return escapeshellarg($argument);
  32120. }
  32121. $escapedArgument = '';
  32122. $quote = false;
  32123. foreach (preg_split('/(")/', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
  32124. if ('"' === $part) {
  32125. $escapedArgument .= '\\"';
  32126. } elseif (self::isSurroundedBy($part, '%')) {
  32127. $escapedArgument .= '^%"'.substr($part, 1, -1).'"^%';
  32128. } else {
  32129. if ('\\' === substr($part, -1)) {
  32130. $part .= '\\';
  32131. }
  32132. $quote = true;
  32133. $escapedArgument .= $part;
  32134. }
  32135. }
  32136. if ($quote) {
  32137. $escapedArgument = '"'.$escapedArgument.'"';
  32138. }
  32139. return $escapedArgument;
  32140. }
  32141. return escapeshellarg($argument);
  32142. }
  32143. public static function validateInput($caller, $input)
  32144. {
  32145. if (null !== $input) {
  32146. if (is_resource($input)) {
  32147. return $input;
  32148. }
  32149. if (is_scalar($input)) {
  32150. return (string) $input;
  32151. }
  32152. if (is_object($input) && method_exists($input, '__toString')) {
  32153. return (string) $input;
  32154. }
  32155. throw new InvalidArgumentException(sprintf('%s only accepts strings or stream resources.', $caller));
  32156. }
  32157. return $input;
  32158. }
  32159. private static function isSurroundedBy($arg, $char)
  32160. {
  32161. return 2 < strlen($arg) && $char === $arg[0] && $char === $arg[strlen($arg) - 1];
  32162. }
  32163. }
  32164. Copyright (c) 2011 Jordi Boggiano
  32165. Permission is hereby granted, free of charge, to any person obtaining a copy
  32166. of this software and associated documentation files (the "Software"), to deal
  32167. in the Software without restriction, including without limitation the rights
  32168. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  32169. copies of the Software, and to permit persons to whom the Software is furnished
  32170. to do so, subject to the following conditions:
  32171. The above copyright notice and this permission notice shall be included in all
  32172. copies or substantial portions of the Software.
  32173. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  32174. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  32175. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  32176. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  32177. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  32178. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  32179. THE SOFTWARE.
  32180. <?php
  32181. namespace Seld\JsonLint;
  32182. use stdClass;
  32183. class JsonParser
  32184. {
  32185. const DETECT_KEY_CONFLICTS = 1;
  32186. const ALLOW_DUPLICATE_KEYS = 2;
  32187. const PARSE_TO_ASSOC = 4;
  32188. private $lexer;
  32189. private $flags;
  32190. private $stack;
  32191. private $vstack;
  32192. private $lstack;
  32193. private $symbols = array(
  32194. 'error' => 2,
  32195. 'JSONString' => 3,
  32196. 'STRING' => 4,
  32197. 'JSONNumber' => 5,
  32198. 'NUMBER' => 6,
  32199. 'JSONNullLiteral' => 7,
  32200. 'NULL' => 8,
  32201. 'JSONBooleanLiteral' => 9,
  32202. 'TRUE' => 10,
  32203. 'FALSE' => 11,
  32204. 'JSONText' => 12,
  32205. 'JSONValue' => 13,
  32206. 'EOF' => 14,
  32207. 'JSONObject' => 15,
  32208. 'JSONArray' => 16,
  32209. '{' => 17,
  32210. '}' => 18,
  32211. 'JSONMemberList' => 19,
  32212. 'JSONMember' => 20,
  32213. ':' => 21,
  32214. ',' => 22,
  32215. '[' => 23,
  32216. ']' => 24,
  32217. 'JSONElementList' => 25,
  32218. '$accept' => 0,
  32219. '$end' => 1,
  32220. );
  32221. private $terminals_ = array(
  32222. 2 => "error",
  32223. 4 => "STRING",
  32224. 6 => "NUMBER",
  32225. 8 => "NULL",
  32226. 10 => "TRUE",
  32227. 11 => "FALSE",
  32228. 14 => "EOF",
  32229. 17 => "{",
  32230. 18 => "}",
  32231. 21 => ":",
  32232. 22 => ",",
  32233. 23 => "[",
  32234. 24 => "]",
  32235. );
  32236. private $productions_ = array(
  32237. 0,
  32238. array(3, 1),
  32239. array(5, 1),
  32240. array(7, 1),
  32241. array(9, 1),
  32242. array(9, 1),
  32243. array(12, 2),
  32244. array(13, 1),
  32245. array(13, 1),
  32246. array(13, 1),
  32247. array(13, 1),
  32248. array(13, 1),
  32249. array(13, 1),
  32250. array(15, 2),
  32251. array(15, 3),
  32252. array(20, 3),
  32253. array(19, 1),
  32254. array(19, 3),
  32255. array(16, 2),
  32256. array(16, 3),
  32257. array(25, 1),
  32258. array(25, 3)
  32259. );
  32260. private $table = array(array(3 => 5, 4 => array(1,12), 5 => 6, 6 => array(1,13), 7 => 3, 8 => array(1,9), 9 => 4, 10 => array(1,10), 11 => array(1,11), 12 => 1, 13 => 2, 15 => 7, 16 => 8, 17 => array(1,14), 23 => array(1,15)), array( 1 => array(3)), array( 14 => array(1,16)), array( 14 => array(2,7), 18 => array(2,7), 22 => array(2,7), 24 => array(2,7)), array( 14 => array(2,8), 18 => array(2,8), 22 => array(2,8), 24 => array(2,8)), array( 14 => array(2,9), 18 => array(2,9), 22 => array(2,9), 24 => array(2,9)), array( 14 => array(2,10), 18 => array(2,10), 22 => array(2,10), 24 => array(2,10)), array( 14 => array(2,11), 18 => array(2,11), 22 => array(2,11), 24 => array(2,11)), array( 14 => array(2,12), 18 => array(2,12), 22 => array(2,12), 24 => array(2,12)), array( 14 => array(2,3), 18 => array(2,3), 22 => array(2,3), 24 => array(2,3)), array( 14 => array(2,4), 18 => array(2,4), 22 => array(2,4), 24 => array(2,4)), array( 14 => array(2,5), 18 => array(2,5), 22 => array(2,5), 24 => array(2,5)), array( 14 => array(2,1), 18 => array(2,1), 21 => array(2,1), 22 => array(2,1), 24 => array(2,1)), array( 14 => array(2,2), 18 => array(2,2), 22 => array(2,2), 24 => array(2,2)), array( 3 => 20, 4 => array(1,12), 18 => array(1,17), 19 => 18, 20 => 19 ), array( 3 => 5, 4 => array(1,12), 5 => 6, 6 => array(1,13), 7 => 3, 8 => array(1,9), 9 => 4, 10 => array(1,10), 11 => array(1,11), 13 => 23, 15 => 7, 16 => 8, 17 => array(1,14), 23 => array(1,15), 24 => array(1,21), 25 => 22 ), array( 1 => array(2,6)), array( 14 => array(2,13), 18 => array(2,13), 22 => array(2,13), 24 => array(2,13)), array( 18 => array(1,24), 22 => array(1,25)), array( 18 => array(2,16), 22 => array(2,16)), array( 21 => array(1,26)), array( 14 => array(2,18), 18 => array(2,18), 22 => array(2,18), 24 => array(2,18)), array( 22 => array(1,28), 24 => array(1,27)), array( 22 => array(2,20), 24 => array(2,20)), array( 14 => array(2,14), 18 => array(2,14), 22 => array(2,14), 24 => array(2,14)), array( 3 => 20, 4 => array(1,12), 20 => 29 ), array( 3 => 5, 4 => array(1,12), 5 => 6, 6 => array(1,13), 7 => 3, 8 => array(1,9), 9 => 4, 10 => array(1,10), 11 => array(1,11), 13 => 30, 15 => 7, 16 => 8, 17 => array(1,14), 23 => array(1,15)), array( 14 => array(2,19), 18 => array(2,19), 22 => array(2,19), 24 => array(2,19)), array( 3 => 5, 4 => array(1,12), 5 => 6, 6 => array(1,13), 7 => 3, 8 => array(1,9), 9 => 4, 10 => array(1,10), 11 => array(1,11), 13 => 31, 15 => 7, 16 => 8, 17 => array(1,14), 23 => array(1,15)), array( 18 => array(2,17), 22 => array(2,17)), array( 18 => array(2,15), 22 => array(2,15)), array( 22 => array(2,21), 24 => array(2,21)),
  32261. );
  32262. private $defaultActions = array(
  32263. 16 => array(2, 6)
  32264. );
  32265. public function lint($input)
  32266. {
  32267. try {
  32268. $this->parse($input);
  32269. } catch (ParsingException $e) {
  32270. return $e;
  32271. }
  32272. }
  32273. public function parse($input, $flags = 0)
  32274. {
  32275. $this->failOnBOM($input);
  32276. $this->flags = $flags;
  32277. $this->stack = array(0);
  32278. $this->vstack = array(null);
  32279. $this->lstack = array();
  32280. $yytext = '';
  32281. $yylineno = 0;
  32282. $yyleng = 0;
  32283. $recovering = 0;
  32284. $TERROR = 2;
  32285. $EOF = 1;
  32286. $this->lexer = new Lexer();
  32287. $this->lexer->setInput($input);
  32288. $yyloc = $this->lexer->yylloc;
  32289. $this->lstack[] = $yyloc;
  32290. $symbol = null;
  32291. $preErrorSymbol = null;
  32292. $state = null;
  32293. $action = null;
  32294. $a = null;
  32295. $r = null;
  32296. $yyval = new stdClass;
  32297. $p = null;
  32298. $len = null;
  32299. $newState = null;
  32300. $expected = null;
  32301. $errStr = null;
  32302. while (true) {
  32303. $state = $this->stack[count($this->stack)-1];
  32304. if (isset($this->defaultActions[$state])) {
  32305. $action = $this->defaultActions[$state];
  32306. } else {
  32307. if ($symbol == null) {
  32308. $symbol = $this->lex();
  32309. }
  32310. $action = isset($this->table[$state][$symbol]) ? $this->table[$state][$symbol] : false;
  32311. }
  32312. if (!$action || !$action[0]) {
  32313. if (!$recovering) {
  32314. $expected = array();
  32315. foreach ($this->table[$state] as $p => $ignore) {
  32316. if (isset($this->terminals_[$p]) && $p > 2) {
  32317. $expected[] = "'" . $this->terminals_[$p] . "'";
  32318. }
  32319. }
  32320. $message = null;
  32321. if (in_array("'STRING'", $expected) && in_array(substr($this->lexer->match, 0, 1), array('"', "'"))) {
  32322. $message = "Invalid string";
  32323. if ("'" === substr($this->lexer->match, 0, 1)) {
  32324. $message .= ", it appears you used single quotes instead of double quotes";
  32325. } elseif (preg_match('{".+?(\\\\[^"bfnrt/\\\\u])}', $this->lexer->getUpcomingInput(), $match)) {
  32326. $message .= ", it appears you have an unescaped backslash at: ".$match[1];
  32327. } elseif (preg_match('{"(?:[^"]+|\\\\")*$}m', $this->lexer->getUpcomingInput())) {
  32328. $message .= ", it appears you forgot to terminated the string, or attempted to write a multiline string which is invalid";
  32329. }
  32330. }
  32331. $errStr = 'Parse error on line ' . ($yylineno+1) . ":\n";
  32332. $errStr .= $this->lexer->showPosition() . "\n";
  32333. if ($message) {
  32334. $errStr .= $message;
  32335. } else {
  32336. $errStr .= (count($expected) > 1) ? "Expected one of: " : "Expected: ";
  32337. $errStr .= implode(', ', $expected);
  32338. }
  32339. if (',' === substr(trim($this->lexer->getPastInput()), -1)) {
  32340. $errStr .= " - It appears you have an extra trailing comma";
  32341. }
  32342. $this->parseError($errStr, array(
  32343. 'text' => $this->lexer->match,
  32344. 'token' => !empty($this->terminals_[$symbol]) ? $this->terminals_[$symbol] : $symbol,
  32345. 'line' => $this->lexer->yylineno,
  32346. 'loc' => $yyloc,
  32347. 'expected' => $expected,
  32348. ));
  32349. }
  32350. if ($recovering == 3) {
  32351. if ($symbol == $EOF) {
  32352. throw new ParsingException($errStr ?: 'Parsing halted.');
  32353. }
  32354. $yyleng = $this->lexer->yyleng;
  32355. $yytext = $this->lexer->yytext;
  32356. $yylineno = $this->lexer->yylineno;
  32357. $yyloc = $this->lexer->yylloc;
  32358. $symbol = $this->lex();
  32359. }
  32360. while (true) {
  32361. if (array_key_exists($TERROR, $this->table[$state])) {
  32362. break;
  32363. }
  32364. if ($state == 0) {
  32365. throw new ParsingException($errStr ?: 'Parsing halted.');
  32366. }
  32367. $this->popStack(1);
  32368. $state = $this->stack[count($this->stack)-1];
  32369. }
  32370. $preErrorSymbol = $symbol;
  32371. $symbol = $TERROR;
  32372. $state = $this->stack[count($this->stack)-1];
  32373. $action = isset($this->table[$state][$TERROR]) ? $this->table[$state][$TERROR] : false;
  32374. $recovering = 3;
  32375. }
  32376. if (is_array($action[0]) && count($action) > 1) {
  32377. throw new ParsingException('Parse Error: multiple actions possible at state: ' . $state . ', token: ' . $symbol);
  32378. }
  32379. switch ($action[0]) {
  32380. case 1:
  32381. $this->stack[] = $symbol;
  32382. $this->vstack[] = $this->lexer->yytext;
  32383. $this->lstack[] = $this->lexer->yylloc;
  32384. $this->stack[] = $action[1];
  32385. $symbol = null;
  32386. if (!$preErrorSymbol) {
  32387. $yyleng = $this->lexer->yyleng;
  32388. $yytext = $this->lexer->yytext;
  32389. $yylineno = $this->lexer->yylineno;
  32390. $yyloc = $this->lexer->yylloc;
  32391. if ($recovering > 0) {
  32392. $recovering--;
  32393. }
  32394. } else {
  32395. $symbol = $preErrorSymbol;
  32396. $preErrorSymbol = null;
  32397. }
  32398. break;
  32399. case 2:
  32400. $len = $this->productions_[$action[1]][1];
  32401. $yyval->token = $this->vstack[count($this->vstack) - $len];
  32402. $yyval->store = array(
  32403. 'first_line' => $this->lstack[count($this->lstack) - ($len ?: 1)]['first_line'],
  32404. 'last_line' => $this->lstack[count($this->lstack) - 1]['last_line'],
  32405. 'first_column' => $this->lstack[count($this->lstack) - ($len ?: 1)]['first_column'],
  32406. 'last_column' => $this->lstack[count($this->lstack) - 1]['last_column'],
  32407. );
  32408. $r = $this->performAction($yyval, $yytext, $yyleng, $yylineno, $action[1], $this->vstack, $this->lstack);
  32409. if (!$r instanceof Undefined) {
  32410. return $r;
  32411. }
  32412. if ($len) {
  32413. $this->popStack($len);
  32414. }
  32415. $this->stack[] = $this->productions_[$action[1]][0];
  32416. $this->vstack[] = $yyval->token;
  32417. $this->lstack[] = $yyval->store;
  32418. $newState = $this->table[$this->stack[count($this->stack)-2]][$this->stack[count($this->stack)-1]];
  32419. $this->stack[] = $newState;
  32420. break;
  32421. case 3:
  32422. return true;
  32423. }
  32424. }
  32425. return true;
  32426. }
  32427. protected function parseError($str, $hash)
  32428. {
  32429. throw new ParsingException($str, $hash);
  32430. }
  32431. private function performAction(stdClass $yyval, $yytext, $yyleng, $yylineno, $yystate, &$tokens)
  32432. {
  32433. $len = count($tokens) - 1;
  32434. switch ($yystate) {
  32435. case 1:
  32436. $yytext = preg_replace_callback('{(?:\\\\["bfnrt/\\\\]|\\\\u[a-fA-F0-9]{4})}', array($this, 'stringInterpolation'), $yytext);
  32437. $yyval->token = $yytext;
  32438. break;
  32439. case 2:
  32440. if (strpos($yytext, 'e') !== false || strpos($yytext, 'E') !== false) {
  32441. $yyval->token = floatval($yytext);
  32442. } else {
  32443. $yyval->token = strpos($yytext, '.') === false ? intval($yytext) : floatval($yytext);
  32444. }
  32445. break;
  32446. case 3:
  32447. $yyval->token = null;
  32448. break;
  32449. case 4:
  32450. $yyval->token = true;
  32451. break;
  32452. case 5:
  32453. $yyval->token = false;
  32454. break;
  32455. case 6:
  32456. return $yyval->token = $tokens[$len-1];
  32457. case 13:
  32458. if ($this->flags & self::PARSE_TO_ASSOC) {
  32459. $yyval->token = array();
  32460. } else {
  32461. $yyval->token = new stdClass;
  32462. }
  32463. break;
  32464. case 14:
  32465. $yyval->token = $tokens[$len-1];
  32466. break;
  32467. case 15:
  32468. $yyval->token = array($tokens[$len-2], $tokens[$len]);
  32469. break;
  32470. case 16:
  32471. $property = $tokens[$len][0] === '' ? '_empty_' : $tokens[$len][0];
  32472. if ($this->flags & self::PARSE_TO_ASSOC) {
  32473. $yyval->token = array();
  32474. $yyval->token[$property] = $tokens[$len][1];
  32475. } else {
  32476. $yyval->token = new stdClass;
  32477. $yyval->token->$property = $tokens[$len][1];
  32478. }
  32479. break;
  32480. case 17:
  32481. if ($this->flags & self::PARSE_TO_ASSOC) {
  32482. $yyval->token =& $tokens[$len-2];
  32483. $key = $tokens[$len][0];
  32484. if (($this->flags & self::DETECT_KEY_CONFLICTS) && isset($tokens[$len-2][$key])) {
  32485. $errStr = 'Parse error on line ' . ($yylineno+1) . ":\n";
  32486. $errStr .= $this->lexer->showPosition() . "\n";
  32487. $errStr .= "Duplicate key: ".$tokens[$len][0];
  32488. throw new ParsingException($errStr);
  32489. } elseif (($this->flags & self::ALLOW_DUPLICATE_KEYS) && isset($tokens[$len-2][$key])) {
  32490. $duplicateCount = 1;
  32491. do {
  32492. $duplicateKey = $key . '.' . $duplicateCount++;
  32493. } while (isset($tokens[$len-2][$duplicateKey]));
  32494. $key = $duplicateKey;
  32495. }
  32496. $tokens[$len-2][$key] = $tokens[$len][1];
  32497. } else {
  32498. $yyval->token = $tokens[$len-2];
  32499. $key = $tokens[$len][0] === '' ? '_empty_' : $tokens[$len][0];
  32500. if (($this->flags & self::DETECT_KEY_CONFLICTS) && isset($tokens[$len-2]->{$key})) {
  32501. $errStr = 'Parse error on line ' . ($yylineno+1) . ":\n";
  32502. $errStr .= $this->lexer->showPosition() . "\n";
  32503. $errStr .= "Duplicate key: ".$tokens[$len][0];
  32504. throw new ParsingException($errStr);
  32505. } elseif (($this->flags & self::ALLOW_DUPLICATE_KEYS) && isset($tokens[$len-2]->{$key})) {
  32506. $duplicateCount = 1;
  32507. do {
  32508. $duplicateKey = $key . '.' . $duplicateCount++;
  32509. } while (isset($tokens[$len-2]->$duplicateKey));
  32510. $key = $duplicateKey;
  32511. }
  32512. $tokens[$len-2]->$key = $tokens[$len][1];
  32513. }
  32514. break;
  32515. case 18:
  32516. $yyval->token = array();
  32517. break;
  32518. case 19:
  32519. $yyval->token = $tokens[$len-1];
  32520. break;
  32521. case 20:
  32522. $yyval->token = array($tokens[$len]);
  32523. break;
  32524. case 21:
  32525. $tokens[$len-2][] = $tokens[$len];
  32526. $yyval->token = $tokens[$len-2];
  32527. break;
  32528. }
  32529. return new Undefined();
  32530. }
  32531. private function stringInterpolation($match)
  32532. {
  32533. switch ($match[0]) {
  32534. case '\\\\':
  32535. return '\\';
  32536. case '\"':
  32537. return '"';
  32538. case '\b':
  32539. return chr(8);
  32540. case '\f':
  32541. return chr(12);
  32542. case '\n':
  32543. return "\n";
  32544. case '\r':
  32545. return "\r";
  32546. case '\t':
  32547. return "\t";
  32548. case '\/':
  32549. return "/";
  32550. default:
  32551. return html_entity_decode('&#x'.ltrim(substr($match[0], 2), '0').';', 0, 'UTF-8');
  32552. }
  32553. }
  32554. private function popStack($n)
  32555. {
  32556. $this->stack = array_slice($this->stack, 0, - (2 * $n));
  32557. $this->vstack = array_slice($this->vstack, 0, - $n);
  32558. $this->lstack = array_slice($this->lstack, 0, - $n);
  32559. }
  32560. private function lex()
  32561. {
  32562. $token = $this->lexer->lex() ?: 1;
  32563. if (!is_numeric($token)) {
  32564. $token = isset($this->symbols[$token]) ? $this->symbols[$token] : $token;
  32565. }
  32566. return $token;
  32567. }
  32568. private function failOnBOM($input)
  32569. {
  32570. $bom = "\xEF\xBB\xBF";
  32571. if (substr($input, 0, 3) === $bom) {
  32572. $this->parseError("BOM detected, make sure your input does not include a Unicode Byte-Order-Mark", array());
  32573. }
  32574. }
  32575. }
  32576. <?php
  32577. namespace Seld\JsonLint;
  32578. class Lexer
  32579. {
  32580. private $EOF = 1;
  32581. private $rules = array(
  32582. 0 => '/^\s+/',
  32583. 1 => '/^-?([0-9]|[1-9][0-9]+)(\.[0-9]+)?([eE][+-]?[0-9]+)?\b/',
  32584. 2 => '{^"(?:\\\\["bfnrt/\\\\]|\\\\u[a-fA-F0-9]{4}|[^\0-\x09\x0a-\x1f\\\\"]+)*"}',
  32585. 3 => '/^\{/',
  32586. 4 => '/^\}/',
  32587. 5 => '/^\[/',
  32588. 6 => '/^\]/',
  32589. 7 => '/^,/',
  32590. 8 => '/^:/',
  32591. 9 => '/^true\b/',
  32592. 10 => '/^false\b/',
  32593. 11 => '/^null\b/',
  32594. 12 => '/^$/',
  32595. 13 => '/^./',
  32596. );
  32597. private $conditions = array(
  32598. "INITIAL" => array(
  32599. "rules" => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13),
  32600. "inclusive" => true,
  32601. ),
  32602. );
  32603. private $conditionStack;
  32604. private $input;
  32605. private $more;
  32606. private $done;
  32607. private $matched;
  32608. public $match;
  32609. public $yylineno;
  32610. public $yyleng;
  32611. public $yytext;
  32612. public $yylloc;
  32613. public function lex()
  32614. {
  32615. $r = $this->next();
  32616. if (!$r instanceof Undefined) {
  32617. return $r;
  32618. }
  32619. return $this->lex();
  32620. }
  32621. public function setInput($input)
  32622. {
  32623. $this->input = $input;
  32624. $this->more = false;
  32625. $this->done = false;
  32626. $this->yylineno = $this->yyleng = 0;
  32627. $this->yytext = $this->matched = $this->match = '';
  32628. $this->conditionStack = array('INITIAL');
  32629. $this->yylloc = array('first_line' => 1, 'first_column' => 0, 'last_line' => 1, 'last_column' => 0);
  32630. return $this;
  32631. }
  32632. public function showPosition()
  32633. {
  32634. $pre = str_replace("\n", '', $this->getPastInput());
  32635. $c = str_repeat('-', max(0, strlen($pre) - 1));
  32636. return $pre . str_replace("\n", '', $this->getUpcomingInput()) . "\n" . $c . "^";
  32637. }
  32638. public function getPastInput()
  32639. {
  32640. $past = substr($this->matched, 0, strlen($this->matched) - strlen($this->match));
  32641. return (strlen($past) > 20 ? '...' : '') . substr($past, -20);
  32642. }
  32643. public function getUpcomingInput()
  32644. {
  32645. $next = $this->match;
  32646. if (strlen($next) < 20) {
  32647. $next .= substr($this->input, 0, 20 - strlen($next));
  32648. }
  32649. return substr($next, 0, 20) . (strlen($next) > 20 ? '...' : '');
  32650. }
  32651. protected function parseError($str, $hash)
  32652. {
  32653. throw new \Exception($str);
  32654. }
  32655. private function next()
  32656. {
  32657. if ($this->done) {
  32658. return $this->EOF;
  32659. }
  32660. if (!$this->input) {
  32661. $this->done = true;
  32662. }
  32663. $token = null;
  32664. $match = null;
  32665. $col = null;
  32666. $lines = null;
  32667. if (!$this->more) {
  32668. $this->yytext = '';
  32669. $this->match = '';
  32670. }
  32671. $rules = $this->getCurrentRules();
  32672. $rulesLen = count($rules);
  32673. for ($i=0; $i < $rulesLen; $i++) {
  32674. if (preg_match($this->rules[$rules[$i]], $this->input, $match)) {
  32675. preg_match_all('/\n.*/', $match[0], $lines);
  32676. $lines = $lines[0];
  32677. if ($lines) {
  32678. $this->yylineno += count($lines);
  32679. }
  32680. $this->yylloc = array(
  32681. 'first_line' => $this->yylloc['last_line'],
  32682. 'last_line' => $this->yylineno+1,
  32683. 'first_column' => $this->yylloc['last_column'],
  32684. 'last_column' => $lines ? strlen($lines[count($lines) - 1]) - 1 : $this->yylloc['last_column'] + strlen($match[0]),
  32685. );
  32686. $this->yytext .= $match[0];
  32687. $this->match .= $match[0];
  32688. $this->yyleng = strlen($this->yytext);
  32689. $this->more = false;
  32690. $this->input = substr($this->input, strlen($match[0]));
  32691. $this->matched .= $match[0];
  32692. $token = $this->performAction($rules[$i], $this->conditionStack[count($this->conditionStack)-1]);
  32693. if ($token) {
  32694. return $token;
  32695. }
  32696. return new Undefined();
  32697. }
  32698. }
  32699. if ($this->input === "") {
  32700. return $this->EOF;
  32701. }
  32702. $this->parseError(
  32703. 'Lexical error on line ' . ($this->yylineno+1) . ". Unrecognized text.\n" . $this->showPosition(),
  32704. array(
  32705. 'text' => "",
  32706. 'token' => null,
  32707. 'line' => $this->yylineno,
  32708. )
  32709. );
  32710. }
  32711. private function getCurrentRules()
  32712. {
  32713. return $this->conditions[$this->conditionStack[count($this->conditionStack)-1]]['rules'];
  32714. }
  32715. private function performAction($avoiding_name_collisions, $YY_START)
  32716. {
  32717. switch ($avoiding_name_collisions) {
  32718. case 0:
  32719. break;
  32720. case 1:
  32721. return 6;
  32722. break;
  32723. case 2:
  32724. $this->yytext = substr($this->yytext, 1, $this->yyleng-2);
  32725. return 4;
  32726. case 3:
  32727. return 17;
  32728. case 4:
  32729. return 18;
  32730. case 5:
  32731. return 23;
  32732. case 6:
  32733. return 24;
  32734. case 7:
  32735. return 22;
  32736. case 8:
  32737. return 21;
  32738. case 9:
  32739. return 10;
  32740. case 10:
  32741. return 11;
  32742. case 11:
  32743. return 8;
  32744. case 12:
  32745. return 14;
  32746. case 13:
  32747. return 'INVALID';
  32748. }
  32749. }
  32750. }
  32751. <?php
  32752. namespace Seld\JsonLint;
  32753. class ParsingException extends \Exception
  32754. {
  32755. protected $details;
  32756. public function __construct($message, $details = array())
  32757. {
  32758. $this->details = $details;
  32759. parent::__construct($message);
  32760. }
  32761. public function getDetails()
  32762. {
  32763. return $this->details;
  32764. }
  32765. }
  32766. <?php
  32767. namespace Seld\JsonLint;
  32768. class Undefined
  32769. {
  32770. }
  32771. Copyright (c) 2015 Jordi Boggiano
  32772. Permission is hereby granted, free of charge, to any person obtaining a copy
  32773. of this software and associated documentation files (the "Software"), to deal
  32774. in the Software without restriction, including without limitation the rights
  32775. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  32776. copies of the Software, and to permit persons to whom the Software is furnished
  32777. to do so, subject to the following conditions:
  32778. The above copyright notice and this permission notice shall be included in all
  32779. copies or substantial portions of the Software.
  32780. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  32781. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  32782. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  32783. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  32784. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  32785. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  32786. THE SOFTWARE.
  32787. <?php
  32788. require __DIR__.'/../vendor/autoload.php';
  32789. echo 'Say hello (visible): ';
  32790. $answer = Seld\CliPrompt\CliPrompt::prompt();
  32791. echo 'You answered: '.$answer . PHP_EOL;
  32792. echo 'Say hello (hidden): ';
  32793. $answer = Seld\CliPrompt\CliPrompt::hiddenPrompt();
  32794. echo 'You answered: '.$answer . PHP_EOL;
  32795. <?php
  32796. namespace Seld\CliPrompt;
  32797. class CliPrompt
  32798. {
  32799. public static function prompt()
  32800. {
  32801. $stdin = fopen('php://stdin', 'r');
  32802. $answer = self::trimAnswer(fgets($stdin, 4096));
  32803. fclose($stdin);
  32804. return $answer;
  32805. }
  32806. public static function hiddenPrompt($allowFallback = false)
  32807. {
  32808. if (defined('PHP_WINDOWS_VERSION_BUILD')) {
  32809. $exe = __DIR__.'\\..\\res\\hiddeninput.exe';
  32810. if ('phar:' === substr(__FILE__, 0, 5)) {
  32811. $tmpExe = sys_get_temp_dir().'/hiddeninput.exe';
  32812. $source = fopen($exe, 'r');
  32813. $target = fopen($tmpExe, 'w+');
  32814. stream_copy_to_stream($source, $target);
  32815. fclose($source);
  32816. fclose($target);
  32817. unset($source, $target);
  32818. $exe = $tmpExe;
  32819. }
  32820. $answer = self::trimAnswer(shell_exec($exe));
  32821. if (isset($tmpExe)) {
  32822. unlink($tmpExe);
  32823. }
  32824. echo PHP_EOL;
  32825. return $answer;
  32826. }
  32827. if (file_exists('/usr/bin/env')) {
  32828. $test = "/usr/bin/env %s -c 'echo OK' 2> /dev/null";
  32829. foreach (array('bash', 'zsh', 'ksh', 'csh') as $sh) {
  32830. if ('OK' === rtrim(shell_exec(sprintf($test, $sh)))) {
  32831. $shell = $sh;
  32832. break;
  32833. }
  32834. }
  32835. if (isset($shell)) {
  32836. $readCmd = ($shell === 'csh') ? 'set mypassword = $<' : 'read -r mypassword';
  32837. $command = sprintf("/usr/bin/env %s -c 'stty -echo; %s; stty echo; echo \$mypassword'", $shell, $readCmd);
  32838. $value = self::trimAnswer(shell_exec($command));
  32839. echo PHP_EOL;
  32840. return $value;
  32841. }
  32842. }
  32843. if (!$allowFallback) {
  32844. throw new \RuntimeException('Could not prompt for input in a secure fashion, aborting');
  32845. }
  32846. return self::prompt();
  32847. }
  32848. private static function trimAnswer($str)
  32849. {
  32850. return preg_replace('{\r?\n$}D', '', $str);
  32851. }
  32852. }
  32853. Copyright (c) 2008, Gradua Networks
  32854. Author: Bruno Prieto Reis
  32855. All rights reserved.
  32856. Redistribution and use in source and binary forms, with or without
  32857. modification, are permitted provided that the following conditions are met:
  32858. * Redistributions of source code must retain the above copyright notice, this
  32859. list of conditions and the following disclaimer.
  32860. * Redistributions in binary form must reproduce the above copyright notice,
  32861. this list of conditions and the following disclaimer in the documentation
  32862. and/or other materials provided with the distribution.
  32863. * Neither the name of the Gradua Networks nor the names of its contributors
  32864. may be used to endorse or promote products derived from this software
  32865. without specific prior written permission.
  32866. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  32867. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  32868. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  32869. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  32870. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32871. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  32872. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32873. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32874. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32875. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32876. <?php
  32877. namespace JsonSchema\Constraints;
  32878. class CollectionConstraint extends Constraint
  32879. {
  32880. public function check($value, $schema = null, $path = null, $i = null)
  32881. {
  32882. if (isset($schema->minItems) && count($value) < $schema->minItems) {
  32883. $this->addError($path, "There must be a minimum of " . $schema->minItems . " items in the array");
  32884. }
  32885. if (isset($schema->maxItems) && count($value) > $schema->maxItems) {
  32886. $this->addError($path, "There must be a maximum of " . $schema->maxItems . " items in the array");
  32887. }
  32888. if (isset($schema->uniqueItems)) {
  32889. $unique = $value;
  32890. if (is_array($value) && count($value)) {
  32891. $unique = array_map(function($e) { return var_export($e, true); }, $value);
  32892. }
  32893. if (count(array_unique($unique)) != count($value)) {
  32894. $this->addError($path, "There are no duplicates allowed in the array");
  32895. }
  32896. }
  32897. if (isset($schema->items)) {
  32898. $this->validateItems($value, $schema, $path, $i);
  32899. }
  32900. }
  32901. protected function validateItems($value, $schema = null, $path = null, $i = null)
  32902. {
  32903. if (is_object($schema->items)) {
  32904. foreach ($value as $k => $v) {
  32905. $initErrors = $this->getErrors();
  32906. $this->checkUndefined($v, $schema->items, $path, $k);
  32907. if (count($initErrors) < count($this->getErrors()) && (isset($schema->additionalItems) && $schema->additionalItems !== false)) {
  32908. $secondErrors = $this->getErrors();
  32909. $this->checkUndefined($v, $schema->additionalItems, $path, $k);
  32910. }
  32911. if (isset($secondErrors) && count($secondErrors) < count($this->getErrors())) {
  32912. $this->errors = $secondErrors;
  32913. } else if (isset($secondErrors) && count($secondErrors) === count($this->getErrors())) {
  32914. $this->errors = $initErrors;
  32915. }
  32916. }
  32917. } else {
  32918. foreach ($value as $k => $v) {
  32919. if (array_key_exists($k, $schema->items)) {
  32920. $this->checkUndefined($v, $schema->items[$k], $path, $k);
  32921. } else {
  32922. if (property_exists($schema, 'additionalItems')) {
  32923. if ($schema->additionalItems !== false) {
  32924. $this->checkUndefined($v, $schema->additionalItems, $path, $k);
  32925. } else {
  32926. $this->addError(
  32927. $path, 'The item ' . $i . '[' . $k . '] is not defined and the definition does not allow additional items');
  32928. }
  32929. } else {
  32930. $this->checkUndefined($v, new \stdClass(), $path, $k);
  32931. }
  32932. }
  32933. }
  32934. if(count($value) > 0) {
  32935. for ($k = count($value); $k < count($schema->items); $k++) {
  32936. $this->checkUndefined(new UndefinedConstraint(), $schema->items[$k], $path, $k);
  32937. }
  32938. }
  32939. }
  32940. }
  32941. }
  32942. <?php
  32943. namespace JsonSchema\Constraints;
  32944. use JsonSchema\Uri\UriRetriever;
  32945. abstract class Constraint implements ConstraintInterface
  32946. {
  32947. protected $checkMode = self::CHECK_MODE_NORMAL;
  32948. protected $uriRetriever;
  32949. protected $errors = array();
  32950. protected $inlineSchemaProperty = '$schema';
  32951. const CHECK_MODE_NORMAL = 1;
  32952. const CHECK_MODE_TYPE_CAST = 2;
  32953. public function __construct($checkMode = self::CHECK_MODE_NORMAL, UriRetriever $uriRetriever = null)
  32954. {
  32955. $this->checkMode = $checkMode;
  32956. $this->uriRetriever = $uriRetriever;
  32957. }
  32958. public function getUriRetriever()
  32959. {
  32960. if (is_null($this->uriRetriever))
  32961. {
  32962. $this->setUriRetriever(new UriRetriever);
  32963. }
  32964. return $this->uriRetriever;
  32965. }
  32966. public function setUriRetriever(UriRetriever $uriRetriever)
  32967. {
  32968. $this->uriRetriever = $uriRetriever;
  32969. }
  32970. public function addError($path, $message)
  32971. {
  32972. $this->errors[] = array(
  32973. 'property' => $path,
  32974. 'message' => $message
  32975. );
  32976. }
  32977. public function addErrors(array $errors)
  32978. {
  32979. $this->errors = array_merge($this->errors, $errors);
  32980. }
  32981. public function getErrors()
  32982. {
  32983. return $this->errors;
  32984. }
  32985. public function isValid()
  32986. {
  32987. return !$this->getErrors();
  32988. }
  32989. public function reset()
  32990. {
  32991. $this->errors = array();
  32992. }
  32993. protected function incrementPath($path, $i)
  32994. {
  32995. if ($path !== '') {
  32996. if (is_int($i)) {
  32997. $path .= '[' . $i . ']';
  32998. } elseif ($i == '') {
  32999. $path .= '';
  33000. } else {
  33001. $path .= '.' . $i;
  33002. }
  33003. } else {
  33004. $path = $i;
  33005. }
  33006. return $path;
  33007. }
  33008. protected function checkArray($value, $schema = null, $path = null, $i = null)
  33009. {
  33010. $validator = new CollectionConstraint($this->checkMode, $this->uriRetriever);
  33011. $validator->check($value, $schema, $path, $i);
  33012. $this->addErrors($validator->getErrors());
  33013. }
  33014. protected function checkObject($value, $schema = null, $path = null, $i = null, $patternProperties = null)
  33015. {
  33016. $validator = new ObjectConstraint($this->checkMode, $this->uriRetriever);
  33017. $validator->check($value, $schema, $path, $i, $patternProperties);
  33018. $this->addErrors($validator->getErrors());
  33019. }
  33020. protected function checkType($value, $schema = null, $path = null, $i = null)
  33021. {
  33022. $validator = new TypeConstraint($this->checkMode, $this->uriRetriever);
  33023. $validator->check($value, $schema, $path, $i);
  33024. $this->addErrors($validator->getErrors());
  33025. }
  33026. protected function checkUndefined($value, $schema = null, $path = null, $i = null)
  33027. {
  33028. $validator = new UndefinedConstraint($this->checkMode, $this->uriRetriever);
  33029. $validator->check($value, $schema, $path, $i);
  33030. $this->addErrors($validator->getErrors());
  33031. }
  33032. protected function checkString($value, $schema = null, $path = null, $i = null)
  33033. {
  33034. $validator = new StringConstraint($this->checkMode, $this->uriRetriever);
  33035. $validator->check($value, $schema, $path, $i);
  33036. $this->addErrors($validator->getErrors());
  33037. }
  33038. protected function checkNumber($value, $schema = null, $path = null, $i = null)
  33039. {
  33040. $validator = new NumberConstraint($this->checkMode, $this->uriRetriever);
  33041. $validator->check($value, $schema, $path, $i);
  33042. $this->addErrors($validator->getErrors());
  33043. }
  33044. protected function checkEnum($value, $schema = null, $path = null, $i = null)
  33045. {
  33046. $validator = new EnumConstraint($this->checkMode, $this->uriRetriever);
  33047. $validator->check($value, $schema, $path, $i);
  33048. $this->addErrors($validator->getErrors());
  33049. }
  33050. protected function checkFormat($value, $schema = null, $path = null, $i = null)
  33051. {
  33052. $validator = new FormatConstraint($this->checkMode, $this->uriRetriever);
  33053. $validator->check($value, $schema, $path, $i);
  33054. $this->addErrors($validator->getErrors());
  33055. }
  33056. protected function retrieveUri($uri)
  33057. {
  33058. if (null === $this->uriRetriever) {
  33059. $this->setUriRetriever(new UriRetriever);
  33060. }
  33061. $jsonSchema = $this->uriRetriever->retrieve($uri);
  33062. return $jsonSchema;
  33063. }
  33064. }
  33065. <?php
  33066. namespace JsonSchema\Constraints;
  33067. interface ConstraintInterface
  33068. {
  33069. public function getErrors();
  33070. public function addErrors(array $errors);
  33071. public function addError($path, $message);
  33072. public function isValid();
  33073. public function check($value, $schema = null, $path = null, $i = null);
  33074. }<?php
  33075. namespace JsonSchema\Constraints;
  33076. class EnumConstraint extends Constraint
  33077. {
  33078. public function check($element, $schema = null, $path = null, $i = null)
  33079. {
  33080. if ($element instanceof UndefinedConstraint && (!isset($schema->required) || !$schema->required)) {
  33081. return;
  33082. }
  33083. foreach ($schema->enum as $enum) {
  33084. $type = gettype($element);
  33085. if ($type === gettype($enum)) {
  33086. if ($type == "object") {
  33087. if ($element == $enum)
  33088. return;
  33089. } else {
  33090. if ($element === $enum)
  33091. return;
  33092. }
  33093. }
  33094. }
  33095. $this->addError($path, "Does not have a value in the enumeration " . print_r($schema->enum, true));
  33096. }
  33097. }
  33098. <?php
  33099. namespace JsonSchema\Constraints;
  33100. class FormatConstraint extends Constraint
  33101. {
  33102. public function check($element, $schema = null, $path = null, $i = null)
  33103. {
  33104. if (!isset($schema->format)) {
  33105. return;
  33106. }
  33107. switch ($schema->format) {
  33108. case 'date':
  33109. if (!$date = $this->validateDateTime($element, 'Y-m-d')) {
  33110. $this->addError($path, sprintf('Invalid date %s, expected format YYYY-MM-DD', json_encode($element)));
  33111. }
  33112. break;
  33113. case 'time':
  33114. if (!$this->validateDateTime($element, 'H:i:s')) {
  33115. $this->addError($path, sprintf('Invalid time %s, expected format hh:mm:ss', json_encode($element)));
  33116. }
  33117. break;
  33118. case 'date-time':
  33119. if (!$this->validateDateTime($element, 'Y-m-d\TH:i:s\Z') &&
  33120. !$this->validateDateTime($element, 'Y-m-d\TH:i:s.u\Z') &&
  33121. !$this->validateDateTime($element, 'Y-m-d\TH:i:sP') &&
  33122. !$this->validateDateTime($element, 'Y-m-d\TH:i:sO')
  33123. ) {
  33124. $this->addError($path, sprintf('Invalid date-time %s, expected format YYYY-MM-DDThh:mm:ssZ or YYYY-MM-DDThh:mm:ss+hh:mm', json_encode($element)));
  33125. }
  33126. break;
  33127. case 'utc-millisec':
  33128. if (!$this->validateDateTime($element, 'U')) {
  33129. $this->addError($path, sprintf('Invalid time %s, expected integer of milliseconds since Epoch', json_encode($element)));
  33130. }
  33131. break;
  33132. case 'regex':
  33133. if (!$this->validateRegex($element)) {
  33134. $this->addError($path, 'Invalid regex format ' . $element);
  33135. }
  33136. break;
  33137. case 'color':
  33138. if (!$this->validateColor($element)) {
  33139. $this->addError($path, "Invalid color");
  33140. }
  33141. break;
  33142. case 'style':
  33143. if (!$this->validateStyle($element)) {
  33144. $this->addError($path, "Invalid style");
  33145. }
  33146. break;
  33147. case 'phone':
  33148. if (!$this->validatePhone($element)) {
  33149. $this->addError($path, "Invalid phone number");
  33150. }
  33151. break;
  33152. case 'uri':
  33153. if (null === filter_var($element, FILTER_VALIDATE_URL, FILTER_NULL_ON_FAILURE)) {
  33154. $this->addError($path, "Invalid URL format");
  33155. }
  33156. break;
  33157. case 'email':
  33158. if (null === filter_var($element, FILTER_VALIDATE_EMAIL, FILTER_NULL_ON_FAILURE)) {
  33159. $this->addError($path, "Invalid email");
  33160. }
  33161. break;
  33162. case 'ip-address':
  33163. case 'ipv4':
  33164. if (null === filter_var($element, FILTER_VALIDATE_IP, FILTER_NULL_ON_FAILURE | FILTER_FLAG_IPV4)) {
  33165. $this->addError($path, "Invalid IP address");
  33166. }
  33167. break;
  33168. case 'ipv6':
  33169. if (null === filter_var($element, FILTER_VALIDATE_IP, FILTER_NULL_ON_FAILURE | FILTER_FLAG_IPV6)) {
  33170. $this->addError($path, "Invalid IP address");
  33171. }
  33172. break;
  33173. case 'host-name':
  33174. case 'hostname':
  33175. if (!$this->validateHostname($element)) {
  33176. $this->addError($path, "Invalid hostname");
  33177. }
  33178. break;
  33179. default:
  33180. break;
  33181. }
  33182. }
  33183. protected function validateDateTime($datetime, $format)
  33184. {
  33185. $dt = \DateTime::createFromFormat($format, $datetime);
  33186. if (!$dt) {
  33187. return false;
  33188. }
  33189. return $datetime === $dt->format($format);
  33190. }
  33191. protected function validateRegex($regex)
  33192. {
  33193. return false !== @preg_match('/' . $regex . '/', '');
  33194. }
  33195. protected function validateColor($color)
  33196. {
  33197. if (in_array(strtolower($color), array('aqua', 'black', 'blue', 'fuchsia',
  33198. 'gray', 'green', 'lime', 'maroon', 'navy', 'olive', 'orange', 'purple',
  33199. 'red', 'silver', 'teal', 'white', 'yellow'))) {
  33200. return true;
  33201. }
  33202. return preg_match('/^#([a-f0-9]{3}|[a-f0-9]{6})$/i', $color);
  33203. }
  33204. protected function validateStyle($style)
  33205. {
  33206. $properties = explode(';', rtrim($style, ';'));
  33207. $invalidEntries = preg_grep('/^\s*[-a-z]+\s*:\s*.+$/i', $properties, PREG_GREP_INVERT);
  33208. return empty($invalidEntries);
  33209. }
  33210. protected function validatePhone($phone)
  33211. {
  33212. return preg_match('/^\+?(\(\d{3}\)|\d{3}) \d{3} \d{4}$/', $phone);
  33213. }
  33214. protected function validateHostname($host)
  33215. {
  33216. return preg_match('/^[_a-z]+\.([_a-z]+\.?)+$/i', $host);
  33217. }
  33218. }
  33219. <?php
  33220. namespace JsonSchema\Constraints;
  33221. class NumberConstraint extends Constraint
  33222. {
  33223. public function check($element, $schema = null, $path = null, $i = null)
  33224. {
  33225. if (isset($schema->exclusiveMinimum)) {
  33226. if (isset($schema->minimum)) {
  33227. if ($schema->exclusiveMinimum && $element === $schema->minimum) {
  33228. $this->addError($path, "Must have a minimum value greater than boundary value of " . $schema->minimum);
  33229. } else if ($element < $schema->minimum) {
  33230. $this->addError($path, "Must have a minimum value of " . $schema->minimum);
  33231. }
  33232. } else {
  33233. $this->addError($path, "Use of exclusiveMinimum requires presence of minimum");
  33234. }
  33235. } else if (isset($schema->minimum) && $element < $schema->minimum) {
  33236. $this->addError($path, "Must have a minimum value of " . $schema->minimum);
  33237. }
  33238. if (isset($schema->exclusiveMaximum)) {
  33239. if (isset($schema->maximum)) {
  33240. if ($schema->exclusiveMaximum && $element === $schema->maximum) {
  33241. $this->addError($path, "Must have a maximum value less than boundary value of " . $schema->maximum);
  33242. } else if ($element > $schema->maximum) {
  33243. $this->addError($path, "Must have a maximum value of " . $schema->maximum);
  33244. }
  33245. } else {
  33246. $this->addError($path, "Use of exclusiveMaximum requires presence of maximum");
  33247. }
  33248. } else if (isset($schema->maximum) && $element > $schema->maximum) {
  33249. $this->addError($path, "Must have a maximum value of " . $schema->maximum);
  33250. }
  33251. if (isset($schema->divisibleBy) && $this->fmod($element, $schema->divisibleBy) != 0) {
  33252. $this->addError($path, "Is not divisible by " . $schema->divisibleBy);
  33253. }
  33254. if (isset($schema->multipleOf) && $this->fmod($element, $schema->multipleOf) != 0) {
  33255. $this->addError($path, "Must be a multiple of " . $schema->multipleOf);
  33256. }
  33257. $this->checkFormat($element, $schema, $path, $i);
  33258. }
  33259. private function fmod($number1, $number2)
  33260. {
  33261. $modulus = fmod($number1, $number2);
  33262. $precision = abs(0.0000000001);
  33263. $diff = (float)($modulus - $number2);
  33264. if (-$precision < $diff && $diff < $precision) {
  33265. return 0.0;
  33266. }
  33267. $decimals1 = mb_strpos($number1, ".") ? mb_strlen($number1) - mb_strpos($number1, ".") - 1 : 0;
  33268. $decimals2 = mb_strpos($number2, ".") ? mb_strlen($number2) - mb_strpos($number2, ".") - 1 : 0;
  33269. return (float)round($modulus, max($decimals1, $decimals2));
  33270. }
  33271. }
  33272. <?php
  33273. namespace JsonSchema\Constraints;
  33274. class ObjectConstraint extends Constraint
  33275. {
  33276. function check($element, $definition = null, $path = null, $additionalProp = null, $patternProperties = null)
  33277. {
  33278. if ($element instanceof UndefinedConstraint) {
  33279. return;
  33280. }
  33281. $matches = array();
  33282. if ($patternProperties) {
  33283. $matches = $this->validatePatternProperties($element, $path, $patternProperties);
  33284. }
  33285. if ($definition) {
  33286. $this->validateDefinition($element, $definition, $path);
  33287. }
  33288. $this->validateElement($element, $matches, $definition, $path, $additionalProp);
  33289. }
  33290. public function validatePatternProperties($element, $path, $patternProperties)
  33291. {
  33292. $matches = array();
  33293. foreach ($patternProperties as $pregex => $schema) {
  33294. if (@preg_match('/'. $pregex . '/', '') === false) {
  33295. $this->addError($path, 'The pattern "' . $pregex . '" is invalid');
  33296. continue;
  33297. }
  33298. foreach ($element as $i => $value) {
  33299. if (preg_match('/' . $pregex . '/', $i)) {
  33300. $matches[] = $i;
  33301. $this->checkUndefined($value, $schema ? : new \stdClass(), $path, $i);
  33302. }
  33303. }
  33304. }
  33305. return $matches;
  33306. }
  33307. public function validateElement($element, $matches, $objectDefinition = null, $path = null, $additionalProp = null)
  33308. {
  33309. foreach ($element as $i => $value) {
  33310. $property = $this->getProperty($element, $i, new UndefinedConstraint());
  33311. $definition = $this->getProperty($objectDefinition, $i);
  33312. if (!in_array($i, $matches) && $additionalProp === false && $this->inlineSchemaProperty !== $i && !$definition) {
  33313. $this->addError($path, "The property - " . $i . " - is not defined and the definition does not allow additional properties");
  33314. }
  33315. if (!in_array($i, $matches) && $additionalProp && !$definition) {
  33316. if ($additionalProp === true) {
  33317. $this->checkUndefined($value, null, $path, $i);
  33318. } else {
  33319. $this->checkUndefined($value, $additionalProp, $path, $i);
  33320. }
  33321. }
  33322. $require = $this->getProperty($definition, 'requires');
  33323. if ($require && !$this->getProperty($element, $require)) {
  33324. $this->addError($path, "The presence of the property " . $i . " requires that " . $require . " also be present");
  33325. }
  33326. if (!$definition) {
  33327. $this->checkUndefined($value, new \stdClass(), $path, $i);
  33328. }
  33329. }
  33330. }
  33331. public function validateDefinition($element, $objectDefinition = null, $path = null)
  33332. {
  33333. foreach ($objectDefinition as $i => $value) {
  33334. $property = $this->getProperty($element, $i, new UndefinedConstraint());
  33335. $definition = $this->getProperty($objectDefinition, $i);
  33336. $this->checkUndefined($property, $definition, $path, $i);
  33337. }
  33338. }
  33339. protected function getProperty($element, $property, $fallback = null)
  33340. {
  33341. if (is_array($element) ) {
  33342. return array_key_exists($property, $element) ? $element[$property] : $fallback;
  33343. } elseif (is_object($element)) {
  33344. return property_exists($element, $property) ? $element->$property : $fallback;
  33345. }
  33346. return $fallback;
  33347. }
  33348. }
  33349. <?php
  33350. namespace JsonSchema\Constraints;
  33351. use JsonSchema\Exception\InvalidArgumentException;
  33352. class SchemaConstraint extends Constraint
  33353. {
  33354. public function check($element, $schema = null, $path = null, $i = null)
  33355. {
  33356. if ($schema !== null) {
  33357. $this->checkUndefined($element, $schema, '', '');
  33358. } elseif (property_exists($element, $this->inlineSchemaProperty)) {
  33359. $this->checkUndefined($element, $element->{$this->inlineSchemaProperty}, '', '');
  33360. } else {
  33361. throw new InvalidArgumentException('no schema found to verify against');
  33362. }
  33363. }
  33364. }<?php
  33365. namespace JsonSchema\Constraints;
  33366. class StringConstraint extends Constraint
  33367. {
  33368. public function check($element, $schema = null, $path = null, $i = null)
  33369. {
  33370. if (isset($schema->maxLength) && $this->strlen($element) > $schema->maxLength) {
  33371. $this->addError($path, "Must be at most " . $schema->maxLength . " characters long");
  33372. }
  33373. if (isset($schema->minLength) && $this->strlen($element) < $schema->minLength) {
  33374. $this->addError($path, "Must be at least " . $schema->minLength . " characters long");
  33375. }
  33376. if (isset($schema->pattern) && !preg_match('#' . str_replace('#', '\\#', $schema->pattern) . '#', $element)) {
  33377. $this->addError($path, "Does not match the regex pattern " . $schema->pattern);
  33378. }
  33379. $this->checkFormat($element, $schema, $path, $i);
  33380. }
  33381. private function strlen($string)
  33382. {
  33383. if (extension_loaded('mbstring')) {
  33384. return mb_strlen($string, mb_detect_encoding($string));
  33385. } else {
  33386. return strlen($string);
  33387. }
  33388. }
  33389. }
  33390. <?php
  33391. namespace JsonSchema\Constraints;
  33392. use JsonSchema\Exception\InvalidArgumentException;
  33393. use UnexpectedValueException as StandardUnexpectedValueException;
  33394. class TypeConstraint extends Constraint
  33395. {
  33396. static $wording = array(
  33397. 'integer' => 'an integer',
  33398. 'number' => 'a number',
  33399. 'boolean' => 'a boolean',
  33400. 'object' => 'an object',
  33401. 'array' => 'an array',
  33402. 'string' => 'a string',
  33403. 'null' => 'a null',
  33404. 'any' => NULL,
  33405. 0 => NULL,
  33406. );
  33407. public function check($value = null, $schema = null, $path = null, $i = null)
  33408. {
  33409. $type = isset($schema->type) ? $schema->type : null;
  33410. $isValid = true;
  33411. if (is_array($type)) {
  33412. $validatedOneType = false;
  33413. $errors = array();
  33414. foreach ($type as $tp) {
  33415. $validator = new TypeConstraint($this->checkMode);
  33416. $subSchema = new \stdClass();
  33417. $subSchema->type = $tp;
  33418. $validator->check($value, $subSchema, $path, null);
  33419. $error = $validator->getErrors();
  33420. if (!count($error)) {
  33421. $validatedOneType = true;
  33422. break;
  33423. }
  33424. $errors = $error;
  33425. }
  33426. if (!$validatedOneType) {
  33427. $this->addErrors($errors);
  33428. return;
  33429. }
  33430. } elseif (is_object($type)) {
  33431. $this->checkUndefined($value, $type, $path);
  33432. } else {
  33433. $isValid = $this->validateType($value, $type);
  33434. }
  33435. if ($isValid === false) {
  33436. if (!isset(self::$wording[$type])) {
  33437. throw new StandardUnexpectedValueException(
  33438. sprintf(
  33439. "No wording for %s available, expected wordings are: [%s]",
  33440. var_export($type, true),
  33441. implode(', ', array_filter(self::$wording)))
  33442. );
  33443. }
  33444. $this->addError($path, gettype($value) . " value found, but " . self::$wording[$type] . " is required");
  33445. }
  33446. }
  33447. protected function validateType($value, $type)
  33448. {
  33449. if (!$type) {
  33450. return true;
  33451. }
  33452. if ('integer' === $type) {
  33453. return is_int($value);
  33454. }
  33455. if ('number' === $type) {
  33456. return is_numeric($value) && !is_string($value);
  33457. }
  33458. if ('boolean' === $type) {
  33459. return is_bool($value);
  33460. }
  33461. if ('object' === $type) {
  33462. return is_object($value);
  33463. }
  33464. if ('array' === $type) {
  33465. return is_array($value);
  33466. }
  33467. if ('string' === $type) {
  33468. return is_string($value);
  33469. }
  33470. if ('null' === $type) {
  33471. return is_null($value);
  33472. }
  33473. if ('any' === $type) {
  33474. return true;
  33475. }
  33476. throw new InvalidArgumentException((is_object($value) ? 'object' : $value) . ' is an invalid type for ' . $type);
  33477. }
  33478. }
  33479. <?php
  33480. namespace JsonSchema\Constraints;
  33481. use JsonSchema\Exception\InvalidArgumentException;
  33482. use JsonSchema\Uri\UriResolver;
  33483. class UndefinedConstraint extends Constraint
  33484. {
  33485. public function check($value, $schema = null, $path = null, $i = null)
  33486. {
  33487. if (is_null($schema)) {
  33488. return;
  33489. }
  33490. if (!is_object($schema)) {
  33491. throw new InvalidArgumentException(
  33492. 'Given schema must be an object in ' . $path
  33493. . ' but is a ' . gettype($schema)
  33494. );
  33495. }
  33496. $i = is_null($i) ? "" : $i;
  33497. $path = $this->incrementPath($path, $i);
  33498. $this->validateCommonProperties($value, $schema, $path);
  33499. $this->validateOfProperties($value, $schema, $path);
  33500. $this->validateTypes($value, $schema, $path, $i);
  33501. }
  33502. public function validateTypes($value, $schema = null, $path = null, $i = null)
  33503. {
  33504. if (is_array($value)) {
  33505. $this->checkArray($value, $schema, $path, $i);
  33506. }
  33507. if (is_object($value) && (isset($schema->properties) || isset($schema->patternProperties))) {
  33508. $this->checkObject(
  33509. $value,
  33510. isset($schema->properties) ? $schema->properties : null,
  33511. $path,
  33512. isset($schema->additionalProperties) ? $schema->additionalProperties : null,
  33513. isset($schema->patternProperties) ? $schema->patternProperties : null
  33514. );
  33515. }
  33516. if (is_string($value)) {
  33517. $this->checkString($value, $schema, $path, $i);
  33518. }
  33519. if (is_numeric($value)) {
  33520. $this->checkNumber($value, $schema, $path, $i);
  33521. }
  33522. if (isset($schema->enum)) {
  33523. $this->checkEnum($value, $schema, $path, $i);
  33524. }
  33525. }
  33526. protected function validateCommonProperties($value, $schema = null, $path = null, $i = "")
  33527. {
  33528. if (isset($schema->extends)) {
  33529. if (is_string($schema->extends)) {
  33530. $schema->extends = $this->validateUri($schema, $schema->extends);
  33531. }
  33532. if (is_array($schema->extends)) {
  33533. foreach ($schema->extends as $extends) {
  33534. $this->checkUndefined($value, $extends, $path, $i);
  33535. }
  33536. } else {
  33537. $this->checkUndefined($value, $schema->extends, $path, $i);
  33538. }
  33539. }
  33540. if (is_object($value)) {
  33541. if (!($value instanceof UndefinedConstraint) && isset($schema->required) && is_array($schema->required) ) {
  33542. foreach ($schema->required as $required) {
  33543. if (!property_exists($value, $required)) {
  33544. $this->addError($required, "The property " . $required . " is required");
  33545. }
  33546. }
  33547. } else if (isset($schema->required) && !is_array($schema->required)) {
  33548. if ( $schema->required && $value instanceof UndefinedConstraint) {
  33549. $this->addError($path, "Is missing and it is required");
  33550. }
  33551. }
  33552. }
  33553. if (!($value instanceof UndefinedConstraint)) {
  33554. $this->checkType($value, $schema, $path);
  33555. }
  33556. if (isset($schema->disallow)) {
  33557. $initErrors = $this->getErrors();
  33558. $typeSchema = new \stdClass();
  33559. $typeSchema->type = $schema->disallow;
  33560. $this->checkType($value, $typeSchema, $path);
  33561. if (count($this->getErrors()) == count($initErrors)) {
  33562. $this->addError($path, "Disallowed value was matched");
  33563. } else {
  33564. $this->errors = $initErrors;
  33565. }
  33566. }
  33567. if (isset($schema->not)) {
  33568. $initErrors = $this->getErrors();
  33569. $this->checkUndefined($value, $schema->not, $path, $i);
  33570. if (count($this->getErrors()) == count($initErrors)) {
  33571. $this->addError($path, "Matched a schema which it should not");
  33572. } else {
  33573. $this->errors = $initErrors;
  33574. }
  33575. }
  33576. if (is_object($value)) {
  33577. if (isset($schema->minProperties)) {
  33578. if (count(get_object_vars($value)) < $schema->minProperties) {
  33579. $this->addError($path, "Must contain a minimum of " . $schema->minProperties . " properties");
  33580. }
  33581. }
  33582. if (isset($schema->maxProperties)) {
  33583. if (count(get_object_vars($value)) > $schema->maxProperties) {
  33584. $this->addError($path, "Must contain no more than " . $schema->maxProperties . " properties");
  33585. }
  33586. }
  33587. }
  33588. if (is_object($value) && isset($schema->dependencies)) {
  33589. $this->validateDependencies($value, $schema->dependencies, $path);
  33590. }
  33591. }
  33592. protected function validateOfProperties($value, $schema, $path, $i = "")
  33593. {
  33594. if ($value instanceof UndefinedConstraint) {
  33595. return;
  33596. }
  33597. if (isset($schema->allOf)) {
  33598. $isValid = true;
  33599. foreach ($schema->allOf as $allOf) {
  33600. $initErrors = $this->getErrors();
  33601. $this->checkUndefined($value, $allOf, $path, $i);
  33602. $isValid = $isValid && (count($this->getErrors()) == count($initErrors));
  33603. }
  33604. if (!$isValid) {
  33605. $this->addError($path, "Failed to match all schemas");
  33606. }
  33607. }
  33608. if (isset($schema->anyOf)) {
  33609. $isValid = false;
  33610. $startErrors = $this->getErrors();
  33611. foreach ($schema->anyOf as $anyOf) {
  33612. $initErrors = $this->getErrors();
  33613. $this->checkUndefined($value, $anyOf, $path, $i);
  33614. if ($isValid = (count($this->getErrors()) == count($initErrors))) {
  33615. break;
  33616. }
  33617. }
  33618. if (!$isValid) {
  33619. $this->addError($path, "Failed to match at least one schema");
  33620. } else {
  33621. $this->errors = $startErrors;
  33622. }
  33623. }
  33624. if (isset($schema->oneOf)) {
  33625. $allErrors = array();
  33626. $matchedSchemas = 0;
  33627. $startErrors = $this->getErrors();
  33628. foreach ($schema->oneOf as $oneOf) {
  33629. $this->errors = array();
  33630. $this->checkUndefined($value, $oneOf, $path, $i);
  33631. if (count($this->getErrors()) == 0) {
  33632. $matchedSchemas++;
  33633. }
  33634. $allErrors = array_merge($allErrors, array_values($this->getErrors()));
  33635. }
  33636. if ($matchedSchemas !== 1) {
  33637. $this->addErrors(
  33638. array_merge(
  33639. $allErrors,
  33640. array(array(
  33641. 'property' => $path,
  33642. 'message' => "failed to match exactly one schema"
  33643. ),),
  33644. $startErrors
  33645. )
  33646. );
  33647. } else {
  33648. $this->errors = $startErrors;
  33649. }
  33650. }
  33651. }
  33652. protected function validateDependencies($value, $dependencies, $path, $i = "")
  33653. {
  33654. foreach ($dependencies as $key => $dependency) {
  33655. if (property_exists($value, $key)) {
  33656. if (is_string($dependency)) {
  33657. if (!property_exists($value, $dependency)) {
  33658. $this->addError($path, "$key depends on $dependency and $dependency is missing");
  33659. }
  33660. } else if (is_array($dependency)) {
  33661. foreach ($dependency as $d) {
  33662. if (!property_exists($value, $d)) {
  33663. $this->addError($path, "$key depends on $d and $d is missing");
  33664. }
  33665. }
  33666. } else if (is_object($dependency)) {
  33667. $this->checkUndefined($value, $dependency, $path, $i);
  33668. }
  33669. }
  33670. }
  33671. }
  33672. protected function validateUri($schema, $schemaUri = null)
  33673. {
  33674. $resolver = new UriResolver();
  33675. $retriever = $this->getUriRetriever();
  33676. $jsonSchema = null;
  33677. if ($resolver->isValid($schemaUri)) {
  33678. $schemaId = property_exists($schema, 'id') ? $schema->id : null;
  33679. $jsonSchema = $retriever->retrieve($schemaId, $schemaUri);
  33680. }
  33681. return $jsonSchema;
  33682. }
  33683. }
  33684. <?php
  33685. namespace JsonSchema\Exception;
  33686. class InvalidArgumentException extends \InvalidArgumentException
  33687. {
  33688. }<?php
  33689. namespace JsonSchema\Exception;
  33690. class InvalidSchemaMediaTypeException extends \RuntimeException
  33691. {
  33692. }<?php
  33693. namespace JsonSchema\Exception;
  33694. class InvalidSourceUriException extends InvalidArgumentException
  33695. {
  33696. }
  33697. <?php
  33698. namespace JsonSchema\Exception;
  33699. class JsonDecodingException extends \RuntimeException
  33700. {
  33701. public function __construct($code = JSON_ERROR_NONE, \Exception $previous = null)
  33702. {
  33703. switch ($code) {
  33704. case JSON_ERROR_DEPTH:
  33705. $message = 'The maximum stack depth has been exceeded';
  33706. break;
  33707. case JSON_ERROR_STATE_MISMATCH:
  33708. $message = 'Invalid or malformed JSON';
  33709. break;
  33710. case JSON_ERROR_CTRL_CHAR:
  33711. $message = 'Control character error, possibly incorrectly encoded';
  33712. break;
  33713. case JSON_ERROR_UTF8:
  33714. $message = 'Malformed UTF-8 characters, possibly incorrectly encoded';
  33715. break;
  33716. case JSON_ERROR_SYNTAX:
  33717. $message = 'JSON syntax is malformed';
  33718. break;
  33719. default:
  33720. $message = 'Syntax error';
  33721. }
  33722. parent::__construct($message, $code, $previous);
  33723. }
  33724. }<?php
  33725. namespace JsonSchema\Exception;
  33726. class ResourceNotFoundException extends \RuntimeException
  33727. {
  33728. }<?php
  33729. namespace JsonSchema\Exception;
  33730. class UriResolverException extends \RuntimeException
  33731. {
  33732. }<?php
  33733. namespace JsonSchema;
  33734. use JsonSchema\Exception\JsonDecodingException;
  33735. use JsonSchema\Uri\Retrievers\UriRetrieverInterface;
  33736. use JsonSchema\Uri\UriRetriever;
  33737. class RefResolver
  33738. {
  33739. protected static $depth = 0;
  33740. public static $maxDepth = 7;
  33741. protected $uriRetriever = null;
  33742. protected $rootSchema = null;
  33743. public function __construct($retriever = null)
  33744. {
  33745. $this->uriRetriever = $retriever;
  33746. }
  33747. public function fetchRef($ref, $sourceUri)
  33748. {
  33749. $retriever = $this->getUriRetriever();
  33750. $jsonSchema = $retriever->retrieve($ref, $sourceUri);
  33751. $this->resolve($jsonSchema);
  33752. return $jsonSchema;
  33753. }
  33754. public function getUriRetriever()
  33755. {
  33756. if (is_null($this->uriRetriever)) {
  33757. $this->setUriRetriever(new UriRetriever);
  33758. }
  33759. return $this->uriRetriever;
  33760. }
  33761. public function resolve($schema, $sourceUri = null)
  33762. {
  33763. if (self::$depth > self::$maxDepth) {
  33764. throw new JsonDecodingException(JSON_ERROR_DEPTH);
  33765. }
  33766. ++self::$depth;
  33767. if (! is_object($schema)) {
  33768. --self::$depth;
  33769. return;
  33770. }
  33771. if (null === $sourceUri && ! empty($schema->id)) {
  33772. $sourceUri = $schema->id;
  33773. }
  33774. if (null === $this->rootSchema) {
  33775. $this->rootSchema = $schema;
  33776. }
  33777. $this->resolveRef($schema, $sourceUri);
  33778. foreach (array('additionalItems', 'additionalProperties', 'extends', 'items') as $propertyName) {
  33779. $this->resolveProperty($schema, $propertyName, $sourceUri);
  33780. }
  33781. foreach (array('disallow', 'extends', 'items', 'type', 'allOf', 'anyOf', 'oneOf') as $propertyName) {
  33782. $this->resolveArrayOfSchemas($schema, $propertyName, $sourceUri);
  33783. }
  33784. foreach (array('dependencies', 'patternProperties', 'properties') as $propertyName) {
  33785. $this->resolveObjectOfSchemas($schema, $propertyName, $sourceUri);
  33786. }
  33787. --self::$depth;
  33788. }
  33789. public function resolveArrayOfSchemas($schema, $propertyName, $sourceUri)
  33790. {
  33791. if (! isset($schema->$propertyName) || ! is_array($schema->$propertyName)) {
  33792. return;
  33793. }
  33794. foreach ($schema->$propertyName as $possiblySchema) {
  33795. $this->resolve($possiblySchema, $sourceUri);
  33796. }
  33797. }
  33798. public function resolveObjectOfSchemas($schema, $propertyName, $sourceUri)
  33799. {
  33800. if (! isset($schema->$propertyName) || ! is_object($schema->$propertyName)) {
  33801. return;
  33802. }
  33803. foreach (get_object_vars($schema->$propertyName) as $possiblySchema) {
  33804. $this->resolve($possiblySchema, $sourceUri);
  33805. }
  33806. }
  33807. public function resolveProperty($schema, $propertyName, $sourceUri)
  33808. {
  33809. if (! isset($schema->$propertyName)) {
  33810. return;
  33811. }
  33812. $this->resolve($schema->$propertyName, $sourceUri);
  33813. }
  33814. public function resolveRef($schema, $sourceUri)
  33815. {
  33816. $ref = '$ref';
  33817. if (empty($schema->$ref)) {
  33818. return;
  33819. }
  33820. $splitRef = explode('#', $schema->$ref, 2);
  33821. $refDoc = $splitRef[0];
  33822. $refPath = null;
  33823. if (count($splitRef) === 2) {
  33824. $refPath = explode('/', $splitRef[1]);
  33825. array_shift($refPath);
  33826. }
  33827. if (empty($refDoc) && empty($refPath)) {
  33828. return;
  33829. }
  33830. if (!empty($refDoc)) {
  33831. $refSchema = $this->fetchRef($refDoc, $sourceUri);
  33832. } else {
  33833. $refSchema = $this->rootSchema;
  33834. }
  33835. if (null !== $refPath) {
  33836. $refSchema = $this->resolveRefSegment($refSchema, $refPath);
  33837. }
  33838. unset($schema->$ref);
  33839. foreach (get_object_vars($refSchema) as $prop => $value) {
  33840. $schema->$prop = $value;
  33841. }
  33842. }
  33843. public function setUriRetriever(UriRetriever $retriever)
  33844. {
  33845. $this->uriRetriever = $retriever;
  33846. return $this;
  33847. }
  33848. protected function resolveRefSegment($data, $pathParts)
  33849. {
  33850. foreach ($pathParts as $path) {
  33851. $path = strtr($path, array('~1' => '/', '~0' => '~', '%25' => '%'));
  33852. if (is_array($data)) {
  33853. $data = $data[$path];
  33854. } else {
  33855. $data = $data->{$path};
  33856. }
  33857. }
  33858. return $data;
  33859. }
  33860. }
  33861. <?php
  33862. namespace JsonSchema\Uri\Retrievers;
  33863. abstract class AbstractRetriever implements UriRetrieverInterface
  33864. {
  33865. protected $contentType;
  33866. public function getContentType()
  33867. {
  33868. return $this->contentType;
  33869. }
  33870. }
  33871. <?php
  33872. namespace JsonSchema\Uri\Retrievers;
  33873. use JsonSchema\Validator;
  33874. class Curl extends AbstractRetriever
  33875. {
  33876. protected $messageBody;
  33877. public function __construct()
  33878. {
  33879. if (!function_exists('curl_init')) {
  33880. throw new \RuntimeException("cURL not installed");
  33881. }
  33882. }
  33883. public function retrieve($uri)
  33884. {
  33885. $ch = curl_init();
  33886. curl_setopt($ch, CURLOPT_URL, $uri);
  33887. curl_setopt($ch, CURLOPT_HEADER, true);
  33888. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  33889. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: ' . Validator::SCHEMA_MEDIA_TYPE));
  33890. $response = curl_exec($ch);
  33891. if (false === $response) {
  33892. throw new \JsonSchema\Exception\ResourceNotFoundException('JSON schema not found');
  33893. }
  33894. $this->fetchMessageBody($response);
  33895. $this->fetchContentType($response);
  33896. curl_close($ch);
  33897. return $this->messageBody;
  33898. }
  33899. private function fetchMessageBody($response)
  33900. {
  33901. preg_match("/(?:\r\n){2}(.*)$/ms", $response, $match);
  33902. $this->messageBody = $match[1];
  33903. }
  33904. protected function fetchContentType($response)
  33905. {
  33906. if (0 < preg_match("/Content-Type:(\V*)/ims", $response, $match)) {
  33907. $this->contentType = trim($match[1]);
  33908. return true;
  33909. }
  33910. return false;
  33911. }
  33912. }<?php
  33913. namespace JsonSchema\Uri\Retrievers;
  33914. use JsonSchema\Exception\ResourceNotFoundException;
  33915. use JsonSchema\Validator;
  33916. class FileGetContents extends AbstractRetriever
  33917. {
  33918. protected $messageBody;
  33919. public function retrieve($uri)
  33920. {
  33921. $context = stream_context_create(array(
  33922. 'http' => array(
  33923. 'method' => 'GET',
  33924. 'header' => "Accept: " . Validator::SCHEMA_MEDIA_TYPE
  33925. )));
  33926. set_error_handler(function() use ($uri) {
  33927. throw new ResourceNotFoundException('JSON schema not found at ' . $uri);
  33928. });
  33929. $response = file_get_contents($uri);
  33930. restore_error_handler();
  33931. if (false === $response) {
  33932. throw new ResourceNotFoundException('JSON schema not found at ' . $uri);
  33933. }
  33934. if ($response == ''
  33935. && substr($uri, 0, 7) == 'file://' && substr($uri, -1) == '/'
  33936. ) {
  33937. throw new ResourceNotFoundException('JSON schema not found at ' . $uri);
  33938. }
  33939. $this->messageBody = $response;
  33940. if (! empty($http_response_header)) {
  33941. $this->fetchContentType($http_response_header);
  33942. } else {
  33943. $this->contentType = null;
  33944. }
  33945. return $this->messageBody;
  33946. }
  33947. private function fetchContentType(array $headers)
  33948. {
  33949. foreach ($headers as $header) {
  33950. if ($this->contentType = self::getContentTypeMatchInHeader($header)) {
  33951. return true;
  33952. }
  33953. }
  33954. return false;
  33955. }
  33956. protected static function getContentTypeMatchInHeader($header)
  33957. {
  33958. if (0 < preg_match("/Content-Type:(\V*)/ims", $header, $match)) {
  33959. return trim($match[1]);
  33960. }
  33961. }
  33962. }
  33963. <?php
  33964. namespace JsonSchema\Uri\Retrievers;
  33965. use JsonSchema\Validator;
  33966. class PredefinedArray extends AbstractRetriever
  33967. {
  33968. private $schemas;
  33969. public function __construct(array $schemas, $contentType = Validator::SCHEMA_MEDIA_TYPE)
  33970. {
  33971. $this->schemas = $schemas;
  33972. $this->contentType = $contentType;
  33973. }
  33974. public function retrieve($uri)
  33975. {
  33976. if (!array_key_exists($uri, $this->schemas)) {
  33977. throw new \JsonSchema\Exception\ResourceNotFoundException(sprintf(
  33978. 'The JSON schema "%s" was not found.',
  33979. $uri
  33980. ));
  33981. }
  33982. return $this->schemas[$uri];
  33983. }
  33984. }
  33985. <?php
  33986. namespace JsonSchema\Uri\Retrievers;
  33987. interface UriRetrieverInterface
  33988. {
  33989. public function retrieve($uri);
  33990. public function getContentType();
  33991. }<?php
  33992. namespace JsonSchema\Uri;
  33993. use JsonSchema\Exception\UriResolverException;
  33994. class UriResolver
  33995. {
  33996. public function parse($uri)
  33997. {
  33998. preg_match('|^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?|', $uri, $match);
  33999. $components = array();
  34000. if (5 < count($match)) {
  34001. $components = array(
  34002. 'scheme' => $match[2],
  34003. 'authority' => $match[4],
  34004. 'path' => $match[5]
  34005. );
  34006. }
  34007. if (7 < count($match)) {
  34008. $components['query'] = $match[7];
  34009. }
  34010. if (9 < count($match)) {
  34011. $components['fragment'] = $match[9];
  34012. }
  34013. return $components;
  34014. }
  34015. public function generate(array $components)
  34016. {
  34017. $uri = $components['scheme'] . '://'
  34018. . $components['authority']
  34019. . $components['path'];
  34020. if (array_key_exists('query', $components)) {
  34021. $uri .= $components['query'];
  34022. }
  34023. if (array_key_exists('fragment', $components)) {
  34024. $uri .= '#' . $components['fragment'];
  34025. }
  34026. return $uri;
  34027. }
  34028. public function resolve($uri, $baseUri = null)
  34029. {
  34030. if ($uri == '') {
  34031. return $baseUri;
  34032. }
  34033. $components = $this->parse($uri);
  34034. $path = $components['path'];
  34035. if (! empty($components['scheme'])) {
  34036. return $uri;
  34037. }
  34038. $baseComponents = $this->parse($baseUri);
  34039. $basePath = $baseComponents['path'];
  34040. $baseComponents['path'] = self::combineRelativePathWithBasePath($path, $basePath);
  34041. if (isset($components['fragment'])) {
  34042. $baseComponents['fragment'] = $components['fragment'];
  34043. }
  34044. return $this->generate($baseComponents);
  34045. }
  34046. public static function combineRelativePathWithBasePath($relativePath, $basePath)
  34047. {
  34048. $relativePath = self::normalizePath($relativePath);
  34049. if ($relativePath == '') {
  34050. return $basePath;
  34051. }
  34052. if ($relativePath{0} == '/') {
  34053. return $relativePath;
  34054. }
  34055. $basePathSegments = explode('/', $basePath);
  34056. preg_match('|^/?(\.\./(?:\./)*)*|', $relativePath, $match);
  34057. $numLevelUp = strlen($match[0]) /3 + 1;
  34058. if ($numLevelUp >= count($basePathSegments)) {
  34059. throw new UriResolverException(sprintf("Unable to resolve URI '%s' from base '%s'", $relativePath, $basePath));
  34060. }
  34061. $basePathSegments = array_slice($basePathSegments, 0, -$numLevelUp);
  34062. $path = preg_replace('|^/?(\.\./(\./)*)*|', '', $relativePath);
  34063. return implode('/', $basePathSegments) . '/' . $path;
  34064. }
  34065. private static function normalizePath($path)
  34066. {
  34067. $path = preg_replace('|((?<!\.)\./)*|', '', $path);
  34068. $path = preg_replace('|//|', '/', $path);
  34069. return $path;
  34070. }
  34071. public function isValid($uri)
  34072. {
  34073. $components = $this->parse($uri);
  34074. return !empty($components);
  34075. }
  34076. }
  34077. <?php
  34078. namespace JsonSchema\Uri;
  34079. use JsonSchema\Uri\Retrievers\FileGetContents;
  34080. use JsonSchema\Uri\Retrievers\UriRetrieverInterface;
  34081. use JsonSchema\Validator;
  34082. use JsonSchema\Exception\InvalidSchemaMediaTypeException;
  34083. use JsonSchema\Exception\JsonDecodingException;
  34084. use JsonSchema\Exception\ResourceNotFoundException;
  34085. class UriRetriever
  34086. {
  34087. protected $uriRetriever = null;
  34088. private $schemaCache = array();
  34089. public function confirmMediaType($uriRetriever, $uri)
  34090. {
  34091. $contentType = $uriRetriever->getContentType();
  34092. if (is_null($contentType)) {
  34093. return;
  34094. }
  34095. if (Validator::SCHEMA_MEDIA_TYPE === $contentType) {
  34096. return;
  34097. }
  34098. if (substr($uri, 0, 23) == 'http://json-schema.org/') {
  34099. return true;
  34100. }
  34101. throw new InvalidSchemaMediaTypeException(sprintf('Media type %s expected', Validator::SCHEMA_MEDIA_TYPE));
  34102. }
  34103. public function getUriRetriever()
  34104. {
  34105. if (is_null($this->uriRetriever)) {
  34106. $this->setUriRetriever(new FileGetContents);
  34107. }
  34108. return $this->uriRetriever;
  34109. }
  34110. public function resolvePointer($jsonSchema, $uri)
  34111. {
  34112. $resolver = new UriResolver();
  34113. $parsed = $resolver->parse($uri);
  34114. if (empty($parsed['fragment'])) {
  34115. return $jsonSchema;
  34116. }
  34117. $path = explode('/', $parsed['fragment']);
  34118. while ($path) {
  34119. $pathElement = array_shift($path);
  34120. if (! empty($pathElement)) {
  34121. $pathElement = str_replace('~1', '/', $pathElement);
  34122. $pathElement = str_replace('~0', '~', $pathElement);
  34123. if (! empty($jsonSchema->$pathElement)) {
  34124. $jsonSchema = $jsonSchema->$pathElement;
  34125. } else {
  34126. throw new ResourceNotFoundException(
  34127. 'Fragment "' . $parsed['fragment'] . '" not found'
  34128. . ' in ' . $uri
  34129. );
  34130. }
  34131. if (! is_object($jsonSchema)) {
  34132. throw new ResourceNotFoundException(
  34133. 'Fragment part "' . $pathElement . '" is no object '
  34134. . ' in ' . $uri
  34135. );
  34136. }
  34137. }
  34138. }
  34139. return $jsonSchema;
  34140. }
  34141. public function retrieve($uri, $baseUri = null)
  34142. {
  34143. $resolver = new UriResolver();
  34144. $resolvedUri = $fetchUri = $resolver->resolve($uri, $baseUri);
  34145. $arParts = $resolver->parse($resolvedUri);
  34146. if (isset($arParts['fragment'])) {
  34147. unset($arParts['fragment']);
  34148. $fetchUri = $resolver->generate($arParts);
  34149. }
  34150. $jsonSchema = $this->loadSchema($fetchUri);
  34151. $jsonSchema = $this->resolvePointer($jsonSchema, $resolvedUri);
  34152. if ($jsonSchema instanceof \stdClass) {
  34153. $jsonSchema->id = $resolvedUri;
  34154. }
  34155. return $jsonSchema;
  34156. }
  34157. protected function loadSchema($fetchUri)
  34158. {
  34159. if (isset($this->schemaCache[$fetchUri])) {
  34160. return $this->schemaCache[$fetchUri];
  34161. }
  34162. $uriRetriever = $this->getUriRetriever();
  34163. $contents = $this->uriRetriever->retrieve($fetchUri);
  34164. $this->confirmMediaType($uriRetriever, $fetchUri);
  34165. $jsonSchema = json_decode($contents);
  34166. if (JSON_ERROR_NONE < $error = json_last_error()) {
  34167. throw new JsonDecodingException($error);
  34168. }
  34169. $this->schemaCache[$fetchUri] = $jsonSchema;
  34170. return $jsonSchema;
  34171. }
  34172. public function setUriRetriever(UriRetrieverInterface $uriRetriever)
  34173. {
  34174. $this->uriRetriever = $uriRetriever;
  34175. return $this;
  34176. }
  34177. public function parse($uri)
  34178. {
  34179. preg_match('|^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?|', $uri, $match);
  34180. $components = array();
  34181. if (5 < count($match)) {
  34182. $components = array(
  34183. 'scheme' => $match[2],
  34184. 'authority' => $match[4],
  34185. 'path' => $match[5]
  34186. );
  34187. }
  34188. if (7 < count($match)) {
  34189. $components['query'] = $match[7];
  34190. }
  34191. if (9 < count($match)) {
  34192. $components['fragment'] = $match[9];
  34193. }
  34194. return $components;
  34195. }
  34196. public function generate(array $components)
  34197. {
  34198. $uri = $components['scheme'] . '://'
  34199. . $components['authority']
  34200. . $components['path'];
  34201. if (array_key_exists('query', $components)) {
  34202. $uri .= $components['query'];
  34203. }
  34204. if (array_key_exists('fragment', $components)) {
  34205. $uri .= $components['fragment'];
  34206. }
  34207. return $uri;
  34208. }
  34209. public function resolve($uri, $baseUri = null)
  34210. {
  34211. $components = $this->parse($uri);
  34212. $path = $components['path'];
  34213. if ((array_key_exists('scheme', $components)) && ('http' === $components['scheme'])) {
  34214. return $uri;
  34215. }
  34216. $baseComponents = $this->parse($baseUri);
  34217. $basePath = $baseComponents['path'];
  34218. $baseComponents['path'] = UriResolver::combineRelativePathWithBasePath($path, $basePath);
  34219. return $this->generate($baseComponents);
  34220. }
  34221. public function isValid($uri)
  34222. {
  34223. $components = $this->parse($uri);
  34224. return !empty($components);
  34225. }
  34226. }
  34227. <?php
  34228. namespace JsonSchema;
  34229. use JsonSchema\Constraints\SchemaConstraint;
  34230. use JsonSchema\Constraints\Constraint;
  34231. class Validator extends Constraint
  34232. {
  34233. const SCHEMA_MEDIA_TYPE = 'application/schema+json';
  34234. public function check($value, $schema = null, $path = null, $i = null)
  34235. {
  34236. $validator = new SchemaConstraint($this->checkMode, $this->uriRetriever);
  34237. $validator->check($value, $schema);
  34238. $this->addErrors(array_unique($validator->getErrors(), SORT_REGULAR));
  34239. }
  34240. }
  34241. Copyright (C) 2015 Composer
  34242. Permission is hereby granted, free of charge, to any person obtaining a copy of
  34243. this software and associated documentation files (the "Software"), to deal in
  34244. the Software without restriction, including without limitation the rights to
  34245. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  34246. of the Software, and to permit persons to whom the Software is furnished to do
  34247. so, subject to the following conditions:
  34248. The above copyright notice and this permission notice shall be included in all
  34249. copies or substantial portions of the Software.
  34250. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  34251. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  34252. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  34253. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  34254. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  34255. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  34256. SOFTWARE.
  34257. <?php
  34258. namespace Composer\Spdx;
  34259. class SpdxLicenses
  34260. {
  34261. const LICENSES_FILE = 'spdx-licenses.json';
  34262. const EXCEPTIONS_FILE = 'spdx-exceptions.json';
  34263. private $licenses;
  34264. private $licensesExpression;
  34265. private $exceptions;
  34266. private $exceptionsExpression;
  34267. public function __construct()
  34268. {
  34269. $this->loadLicenses();
  34270. $this->loadExceptions();
  34271. }
  34272. public function getLicenseByIdentifier($identifier)
  34273. {
  34274. if (!isset($this->licenses[$identifier])) {
  34275. return;
  34276. }
  34277. $license = $this->licenses[$identifier];
  34278. $license[] = 'https://spdx.org/licenses/' . $identifier . '.html#licenseText';
  34279. return $license;
  34280. }
  34281. public function getExceptionByIdentifier($identifier)
  34282. {
  34283. if (!isset($this->exceptions[$identifier])) {
  34284. return;
  34285. }
  34286. $license = $this->exceptions[$identifier];
  34287. $license[] = 'https://spdx.org/licenses/' . $identifier . '.html#licenseExceptionText';
  34288. return $license;
  34289. }
  34290. public function getIdentifierByName($name)
  34291. {
  34292. foreach ($this->licenses as $identifier => $licenseData) {
  34293. if ($licenseData[0] === $name) {
  34294. return $identifier;
  34295. }
  34296. }
  34297. foreach ($this->exceptions as $identifier => $licenseData) {
  34298. if ($licenseData[0] === $name) {
  34299. return $identifier;
  34300. }
  34301. }
  34302. }
  34303. public function isOsiApprovedByIdentifier($identifier)
  34304. {
  34305. return $this->licenses[$identifier][1];
  34306. }
  34307. public function validate($license)
  34308. {
  34309. if (is_array($license)) {
  34310. $count = count($license);
  34311. if ($count !== count(array_filter($license, 'is_string'))) {
  34312. throw new \InvalidArgumentException('Array of strings expected.');
  34313. }
  34314. $license = $count > 1 ? '(' . implode(' OR ', $license) . ')' : (string) reset($license);
  34315. }
  34316. if (!is_string($license)) {
  34317. throw new \InvalidArgumentException(sprintf(
  34318. 'Array or String expected, %s given.',
  34319. gettype($license)
  34320. ));
  34321. }
  34322. return $this->isValidLicenseString($license);
  34323. }
  34324. public static function getResourcesDir()
  34325. {
  34326. return dirname(__DIR__) . '/res';
  34327. }
  34328. private function loadLicenses()
  34329. {
  34330. if (null === $this->licenses) {
  34331. $json = file_get_contents(self::getResourcesDir() . '/' . self::LICENSES_FILE);
  34332. $this->licenses = json_decode($json, true);
  34333. }
  34334. }
  34335. private function loadExceptions()
  34336. {
  34337. if (null === $this->exceptions) {
  34338. $json = file_get_contents(self::getResourcesDir() . '/' . self::EXCEPTIONS_FILE);
  34339. $this->exceptions = json_decode($json, true);
  34340. }
  34341. }
  34342. private function getLicensesExpression()
  34343. {
  34344. if (null === $this->licensesExpression) {
  34345. $licenses = array_map('preg_quote', array_keys($this->licenses));
  34346. rsort($licenses);
  34347. $licenses = implode('|', $licenses);
  34348. $this->licensesExpression = $licenses;
  34349. }
  34350. return $this->licensesExpression;
  34351. }
  34352. private function getExceptionsExpression()
  34353. {
  34354. if (null === $this->exceptionsExpression) {
  34355. $exceptions = array_map('preg_quote', array_keys($this->exceptions));
  34356. rsort($exceptions);
  34357. $exceptions = implode('|', $exceptions);
  34358. $this->exceptionsExpression = $exceptions;
  34359. }
  34360. return $this->exceptionsExpression;
  34361. }
  34362. private function isValidLicenseString($license)
  34363. {
  34364. if (isset($this->licenses[$license])) {
  34365. return true;
  34366. }
  34367. $licenses = $this->getLicensesExpression();
  34368. $exceptions = $this->getExceptionsExpression();
  34369. $regex = <<<REGEX
  34370. {
  34371. (?(DEFINE)
  34372. # idstring: 1*( ALPHA / DIGIT / - / . )
  34373. (?<idstring>[\pL\pN.-]{1,})
  34374. # license-id: taken from list
  34375. (?<licenseid>${licenses})
  34376. # license-exception-id: taken from list
  34377. (?<licenseexceptionid>${exceptions})
  34378. # license-ref: [DocumentRef-1*(idstring):]LicenseRef-1*(idstring)
  34379. (?<licenseref>(?:DocumentRef-(?&idstring):)?LicenseRef-(?&idstring))
  34380. # simple-expresssion: license-id / license-id+ / license-ref
  34381. (?<simple_expression>(?&licenseid)\+? | (?&licenseid) | (?&licenseref))
  34382. # compound-expression: 1*(
  34383. # simple-expression /
  34384. # simple-expression WITH license-exception-id /
  34385. # compound-expression AND compound-expression /
  34386. # compound-expression OR compound-expression
  34387. # ) / ( compound-expression ) )
  34388. (?<compound_head>
  34389. (?&simple_expression) ( \s+ (?:with|WITH) \s+ (?&licenseexceptionid))?
  34390. | \( \s* (?&compound_expression) \s* \)
  34391. )
  34392. (?<compound_expression>
  34393. (?&compound_head) (?: \s+ (?:and|AND|or|OR) \s+ (?&compound_expression))?
  34394. )
  34395. # license-expression: 1*1(simple-expression / compound-expression)
  34396. (?<license_expression>(?&compound_expression) | (?&simple_expression))
  34397. ) # end of define
  34398. ^(NONE | NOASSERTION | (?&license_expression))$
  34399. }x
  34400. REGEX;
  34401. $match = preg_match($regex, $license);
  34402. if (0 === $match) {
  34403. return false;
  34404. }
  34405. if (false === $match) {
  34406. throw new \RuntimeException('Regex failed to compile/run.');
  34407. }
  34408. return true;
  34409. }
  34410. }
  34411. Copyright (C) 2015 Composer
  34412. Permission is hereby granted, free of charge, to any person obtaining a copy of
  34413. this software and associated documentation files (the "Software"), to deal in
  34414. the Software without restriction, including without limitation the rights to
  34415. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  34416. of the Software, and to permit persons to whom the Software is furnished to do
  34417. so, subject to the following conditions:
  34418. The above copyright notice and this permission notice shall be included in all
  34419. copies or substantial portions of the Software.
  34420. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  34421. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  34422. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  34423. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  34424. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  34425. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  34426. SOFTWARE.
  34427. <?php
  34428. namespace Composer\Semver;
  34429. use Composer\Semver\Constraint\Constraint;
  34430. class Comparator
  34431. {
  34432. public static function greaterThan($version1, $version2)
  34433. {
  34434. return self::compare($version1, '>', $version2);
  34435. }
  34436. public static function greaterThanOrEqualTo($version1, $version2)
  34437. {
  34438. return self::compare($version1, '>=', $version2);
  34439. }
  34440. public static function lessThan($version1, $version2)
  34441. {
  34442. return self::compare($version1, '<', $version2);
  34443. }
  34444. public static function lessThanOrEqualTo($version1, $version2)
  34445. {
  34446. return self::compare($version1, '<=', $version2);
  34447. }
  34448. public static function equalTo($version1, $version2)
  34449. {
  34450. return self::compare($version1, '==', $version2);
  34451. }
  34452. public static function notEqualTo($version1, $version2)
  34453. {
  34454. return self::compare($version1, '!=', $version2);
  34455. }
  34456. public static function compare($version1, $operator, $version2)
  34457. {
  34458. $constraint = new Constraint($operator, $version2);
  34459. return $constraint->matches(new Constraint('==', $version1));
  34460. }
  34461. }
  34462. <?php
  34463. namespace Composer\Semver\Constraint;
  34464. abstract class AbstractConstraint implements ConstraintInterface
  34465. {
  34466. protected $prettyString;
  34467. public function matches(ConstraintInterface $provider)
  34468. {
  34469. if ($provider instanceof MultiConstraint) {
  34470. return $provider->matches($this);
  34471. }
  34472. if ($provider instanceof $this) {
  34473. return $this->matchSpecific($provider);
  34474. }
  34475. return true;
  34476. }
  34477. public function setPrettyString($prettyString)
  34478. {
  34479. $this->prettyString = $prettyString;
  34480. }
  34481. public function getPrettyString()
  34482. {
  34483. if ($this->prettyString) {
  34484. return $this->prettyString;
  34485. }
  34486. return $this->__toString();
  34487. }
  34488. }
  34489. <?php
  34490. namespace Composer\Semver\Constraint;
  34491. class Constraint extends AbstractConstraint
  34492. {
  34493. const OP_EQ = 0;
  34494. const OP_LT = 1;
  34495. const OP_LE = 2;
  34496. const OP_GT = 3;
  34497. const OP_GE = 4;
  34498. const OP_NE = 5;
  34499. private static $transOpStr = array(
  34500. '=' => self::OP_EQ,
  34501. '==' => self::OP_EQ,
  34502. '<' => self::OP_LT,
  34503. '<=' => self::OP_LE,
  34504. '>' => self::OP_GT,
  34505. '>=' => self::OP_GE,
  34506. '<>' => self::OP_NE,
  34507. '!=' => self::OP_NE,
  34508. );
  34509. private static $transOpInt = array(
  34510. self::OP_EQ => '==',
  34511. self::OP_LT => '<',
  34512. self::OP_LE => '<=',
  34513. self::OP_GT => '>',
  34514. self::OP_GE => '>=',
  34515. self::OP_NE => '!=',
  34516. );
  34517. private $operator;
  34518. private $version;
  34519. public static function getSupportedOperators()
  34520. {
  34521. return array_keys(self::$transOpStr);
  34522. }
  34523. public function __construct($operator, $version)
  34524. {
  34525. if (!isset(self::$transOpStr[$operator])) {
  34526. throw new \InvalidArgumentException(sprintf(
  34527. 'Invalid operator "%s" given, expected one of: %s',
  34528. $operator,
  34529. implode(', ', self::getSupportedOperators())
  34530. ));
  34531. }
  34532. $this->operator = self::$transOpStr[$operator];
  34533. $this->version = $version;
  34534. }
  34535. public function versionCompare($a, $b, $operator, $compareBranches = false)
  34536. {
  34537. if (!isset(self::$transOpStr[$operator])) {
  34538. throw new \InvalidArgumentException(sprintf(
  34539. 'Invalid operator "%s" given, expected one of: %s',
  34540. $operator,
  34541. implode(', ', self::getSupportedOperators())
  34542. ));
  34543. }
  34544. $aIsBranch = 'dev-' === substr($a, 0, 4);
  34545. $bIsBranch = 'dev-' === substr($b, 0, 4);
  34546. if ($aIsBranch && $bIsBranch) {
  34547. return $operator === '==' && $a === $b;
  34548. }
  34549. if (!$compareBranches && ($aIsBranch || $bIsBranch)) {
  34550. return false;
  34551. }
  34552. return version_compare($a, $b, $operator);
  34553. }
  34554. public function matchSpecific(Constraint $provider, $compareBranches = false)
  34555. {
  34556. $noEqualOp = str_replace('=', '', self::$transOpInt[$this->operator]);
  34557. $providerNoEqualOp = str_replace('=', '', self::$transOpInt[$provider->operator]);
  34558. $isEqualOp = self::OP_EQ === $this->operator;
  34559. $isNonEqualOp = self::OP_NE === $this->operator;
  34560. $isProviderEqualOp = self::OP_EQ === $provider->operator;
  34561. $isProviderNonEqualOp = self::OP_NE === $provider->operator;
  34562. if ($isNonEqualOp || $isProviderNonEqualOp) {
  34563. return !$isEqualOp && !$isProviderEqualOp
  34564. || $this->versionCompare($provider->version, $this->version, '!=', $compareBranches);
  34565. }
  34566. if ($this->operator !== self::OP_EQ && $noEqualOp === $providerNoEqualOp) {
  34567. return true;
  34568. }
  34569. if ($this->versionCompare($provider->version, $this->version, self::$transOpInt[$this->operator], $compareBranches)) {
  34570. if ($provider->version === $this->version
  34571. && self::$transOpInt[$provider->operator] === $providerNoEqualOp
  34572. && self::$transOpInt[$this->operator] !== $noEqualOp) {
  34573. return false;
  34574. }
  34575. return true;
  34576. }
  34577. return false;
  34578. }
  34579. public function __toString()
  34580. {
  34581. return self::$transOpInt[$this->operator] . ' ' . $this->version;
  34582. }
  34583. }
  34584. <?php
  34585. namespace Composer\Semver\Constraint;
  34586. interface ConstraintInterface
  34587. {
  34588. public function matches(ConstraintInterface $provider);
  34589. public function setPrettyString($prettyString);
  34590. public function getPrettyString();
  34591. public function __toString();
  34592. }
  34593. <?php
  34594. namespace Composer\Semver\Constraint;
  34595. class EmptyConstraint implements ConstraintInterface
  34596. {
  34597. protected $prettyString;
  34598. public function matches(ConstraintInterface $provider)
  34599. {
  34600. return true;
  34601. }
  34602. public function setPrettyString($prettyString)
  34603. {
  34604. $this->prettyString = $prettyString;
  34605. }
  34606. public function getPrettyString()
  34607. {
  34608. if ($this->prettyString) {
  34609. return $this->prettyString;
  34610. }
  34611. return $this->__toString();
  34612. }
  34613. public function __toString()
  34614. {
  34615. return '[]';
  34616. }
  34617. }
  34618. <?php
  34619. namespace Composer\Semver\Constraint;
  34620. class MultiConstraint implements ConstraintInterface
  34621. {
  34622. protected $constraints;
  34623. protected $prettyString;
  34624. protected $conjunctive;
  34625. public function __construct(array $constraints, $conjunctive = true)
  34626. {
  34627. $this->constraints = $constraints;
  34628. $this->conjunctive = $conjunctive;
  34629. }
  34630. public function matches(ConstraintInterface $provider)
  34631. {
  34632. if (false === $this->conjunctive) {
  34633. foreach ($this->constraints as $constraint) {
  34634. if ($constraint->matches($provider)) {
  34635. return true;
  34636. }
  34637. }
  34638. return false;
  34639. }
  34640. foreach ($this->constraints as $constraint) {
  34641. if (!$constraint->matches($provider)) {
  34642. return false;
  34643. }
  34644. }
  34645. return true;
  34646. }
  34647. public function setPrettyString($prettyString)
  34648. {
  34649. $this->prettyString = $prettyString;
  34650. }
  34651. public function getPrettyString()
  34652. {
  34653. if ($this->prettyString) {
  34654. return $this->prettyString;
  34655. }
  34656. return $this->__toString();
  34657. }
  34658. public function __toString()
  34659. {
  34660. $constraints = array();
  34661. foreach ($this->constraints as $constraint) {
  34662. $constraints[] = (string) $constraint;
  34663. }
  34664. return '[' . implode($this->conjunctive ? ' ' : ' || ', $constraints) . ']';
  34665. }
  34666. }
  34667. <?php
  34668. namespace Composer\Semver;
  34669. use Composer\Semver\Constraint\Constraint;
  34670. class Semver
  34671. {
  34672. const SORT_ASC = 1;
  34673. const SORT_DESC = -1;
  34674. private static $versionParser;
  34675. public static function satisfies($version, $constraints)
  34676. {
  34677. if (null === self::$versionParser) {
  34678. self::$versionParser = new VersionParser();
  34679. }
  34680. $versionParser = self::$versionParser;
  34681. $provider = new Constraint('==', $versionParser->normalize($version));
  34682. $constraints = $versionParser->parseConstraints($constraints);
  34683. return $constraints->matches($provider);
  34684. }
  34685. public static function satisfiedBy(array $versions, $constraints)
  34686. {
  34687. $versions = array_filter($versions, function ($version) use ($constraints) {
  34688. return Semver::satisfies($version, $constraints);
  34689. });
  34690. return array_values($versions);
  34691. }
  34692. public static function sort(array $versions)
  34693. {
  34694. return self::usort($versions, self::SORT_ASC);
  34695. }
  34696. public static function rsort(array $versions)
  34697. {
  34698. return self::usort($versions, self::SORT_DESC);
  34699. }
  34700. private static function usort(array $versions, $direction)
  34701. {
  34702. if (null === self::$versionParser) {
  34703. self::$versionParser = new VersionParser();
  34704. }
  34705. $versionParser = self::$versionParser;
  34706. $normalized = array();
  34707. foreach ($versions as $key => $version) {
  34708. $normalized[] = array($versionParser->normalize($version), $key);
  34709. }
  34710. usort($normalized, function (array $left, array $right) use ($direction) {
  34711. if ($left[0] === $right[0]) {
  34712. return 0;
  34713. }
  34714. if (Comparator::lessThan($left[0], $right[0])) {
  34715. return -$direction;
  34716. }
  34717. return $direction;
  34718. });
  34719. $sorted = array();
  34720. foreach ($normalized as $item) {
  34721. $sorted[] = $versions[$item[1]];
  34722. }
  34723. return $sorted;
  34724. }
  34725. }
  34726. <?php
  34727. namespace Composer\Semver;
  34728. use Composer\Semver\Constraint\ConstraintInterface;
  34729. use Composer\Semver\Constraint\EmptyConstraint;
  34730. use Composer\Semver\Constraint\MultiConstraint;
  34731. use Composer\Semver\Constraint\Constraint;
  34732. class VersionParser
  34733. {
  34734. private static $modifierRegex = '[._-]?(?:(stable|beta|b|RC|alpha|a|patch|pl|p)(?:[.-]?(\d+))?)?([.-]?dev)?';
  34735. private static $stabilities = array(
  34736. 'stable', 'RC', 'beta', 'alpha', 'dev',
  34737. );
  34738. public static function parseStability($version)
  34739. {
  34740. $version = preg_replace('{#.+$}i', '', $version);
  34741. if ('dev-' === substr($version, 0, 4) || '-dev' === substr($version, -4)) {
  34742. return 'dev';
  34743. }
  34744. preg_match('{' . self::$modifierRegex . '$}i', strtolower($version), $match);
  34745. if (!empty($match[3])) {
  34746. return 'dev';
  34747. }
  34748. if (!empty($match[1])) {
  34749. if ('beta' === $match[1] || 'b' === $match[1]) {
  34750. return 'beta';
  34751. }
  34752. if ('alpha' === $match[1] || 'a' === $match[1]) {
  34753. return 'alpha';
  34754. }
  34755. if ('rc' === $match[1]) {
  34756. return 'RC';
  34757. }
  34758. }
  34759. return 'stable';
  34760. }
  34761. public static function normalizeStability($stability)
  34762. {
  34763. $stability = strtolower($stability);
  34764. return $stability === 'rc' ? 'RC' : $stability;
  34765. }
  34766. public function normalize($version, $fullVersion = null)
  34767. {
  34768. $version = trim($version);
  34769. if (null === $fullVersion) {
  34770. $fullVersion = $version;
  34771. }
  34772. if (preg_match('{^([^,\s]+) +as +([^,\s]+)$}', $version, $match)) {
  34773. $version = $match[1];
  34774. }
  34775. if (preg_match('{^([^,\s+]+)\+[^\s]+$}', $version, $match)) {
  34776. $version = $match[1];
  34777. }
  34778. if (preg_match('{^(?:dev-)?(?:master|trunk|default)$}i', $version)) {
  34779. return '9999999-dev';
  34780. }
  34781. if ('dev-' === strtolower(substr($version, 0, 4))) {
  34782. return 'dev-' . substr($version, 4);
  34783. }
  34784. if (preg_match('{^v?(\d{1,5})(\.\d+)?(\.\d+)?(\.\d+)?' . self::$modifierRegex . '$}i', $version, $matches)) {
  34785. $version = $matches[1]
  34786. . (!empty($matches[2]) ? $matches[2] : '.0')
  34787. . (!empty($matches[3]) ? $matches[3] : '.0')
  34788. . (!empty($matches[4]) ? $matches[4] : '.0');
  34789. $index = 5;
  34790. } elseif (preg_match('{^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)' . self::$modifierRegex . '$}i', $version, $matches)) {
  34791. $version = preg_replace('{\D}', '-', $matches[1]);
  34792. $index = 2;
  34793. }
  34794. if (isset($index)) {
  34795. if (!empty($matches[$index])) {
  34796. if ('stable' === $matches[$index]) {
  34797. return $version;
  34798. }
  34799. $version .= '-' . $this->expandStability($matches[$index]) . (!empty($matches[$index + 1]) ? $matches[$index + 1] : '');
  34800. }
  34801. if (!empty($matches[$index + 2])) {
  34802. $version .= '-dev';
  34803. }
  34804. return $version;
  34805. }
  34806. if (preg_match('{(.*?)[.-]?dev$}i', $version, $match)) {
  34807. try {
  34808. return $this->normalizeBranch($match[1]);
  34809. } catch (\Exception $e) {
  34810. }
  34811. }
  34812. $extraMessage = '';
  34813. if (preg_match('{ +as +' . preg_quote($version) . '$}', $fullVersion)) {
  34814. $extraMessage = ' in "' . $fullVersion . '", the alias must be an exact version';
  34815. } elseif (preg_match('{^' . preg_quote($version) . ' +as +}', $fullVersion)) {
  34816. $extraMessage = ' in "' . $fullVersion . '", the alias source must be an exact version, if it is a branch name you should prefix it with dev-';
  34817. }
  34818. throw new \UnexpectedValueException('Invalid version string "' . $version . '"' . $extraMessage);
  34819. }
  34820. public function parseNumericAliasPrefix($branch)
  34821. {
  34822. if (preg_match('{^(?P<version>(\d+\\.)*\d+)(?:\.x)?-dev$}i', $branch, $matches)) {
  34823. return $matches['version'] . '.';
  34824. }
  34825. return false;
  34826. }
  34827. public function normalizeBranch($name)
  34828. {
  34829. $name = trim($name);
  34830. if (in_array($name, array('master', 'trunk', 'default'))) {
  34831. return $this->normalize($name);
  34832. }
  34833. if (preg_match('{^v?(\d+)(\.(?:\d+|[xX*]))?(\.(?:\d+|[xX*]))?(\.(?:\d+|[xX*]))?$}i', $name, $matches)) {
  34834. $version = '';
  34835. for ($i = 1; $i < 5; ++$i) {
  34836. $version .= isset($matches[$i]) ? str_replace(array('*', 'X'), 'x', $matches[$i]) : '.x';
  34837. }
  34838. return str_replace('x', '9999999', $version) . '-dev';
  34839. }
  34840. return 'dev-' . $name;
  34841. }
  34842. public function parseConstraints($constraints)
  34843. {
  34844. $prettyConstraint = $constraints;
  34845. if (preg_match('{^([^,\s]*?)@(' . implode('|', self::$stabilities) . ')$}i', $constraints, $match)) {
  34846. $constraints = empty($match[1]) ? '*' : $match[1];
  34847. }
  34848. if (preg_match('{^(dev-[^,\s@]+?|[^,\s@]+?\.x-dev)#.+$}i', $constraints, $match)) {
  34849. $constraints = $match[1];
  34850. }
  34851. $orConstraints = preg_split('{\s*\|\|?\s*}', trim($constraints));
  34852. $orGroups = array();
  34853. foreach ($orConstraints as $constraints) {
  34854. $andConstraints = preg_split('{(?<!^|as|[=>< ,]) *(?<!-)[, ](?!-) *(?!,|as|$)}', $constraints);
  34855. if (count($andConstraints) > 1) {
  34856. $constraintObjects = array();
  34857. foreach ($andConstraints as $constraint) {
  34858. foreach ($this->parseConstraint($constraint) as $parsedConstraint) {
  34859. $constraintObjects[] = $parsedConstraint;
  34860. }
  34861. }
  34862. } else {
  34863. $constraintObjects = $this->parseConstraint($andConstraints[0]);
  34864. }
  34865. if (1 === count($constraintObjects)) {
  34866. $constraint = $constraintObjects[0];
  34867. } else {
  34868. $constraint = new MultiConstraint($constraintObjects);
  34869. }
  34870. $orGroups[] = $constraint;
  34871. }
  34872. if (1 === count($orGroups)) {
  34873. $constraint = $orGroups[0];
  34874. } else {
  34875. $constraint = new MultiConstraint($orGroups, false);
  34876. }
  34877. $constraint->setPrettyString($prettyConstraint);
  34878. return $constraint;
  34879. }
  34880. private function parseConstraint($constraint)
  34881. {
  34882. if (preg_match('{^([^,\s]+?)@(' . implode('|', self::$stabilities) . ')$}i', $constraint, $match)) {
  34883. $constraint = $match[1];
  34884. if ($match[2] !== 'stable') {
  34885. $stabilityModifier = $match[2];
  34886. }
  34887. }
  34888. if (preg_match('{^[xX*](\.[xX*])*$}i', $constraint)) {
  34889. return array(new EmptyConstraint());
  34890. }
  34891. $versionRegex = 'v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?' . self::$modifierRegex . '(?:\+[^\s]+)?';
  34892. if (preg_match('{^~>?' . $versionRegex . '$}i', $constraint, $matches)) {
  34893. if (substr($constraint, 0, 2) === '~>') {
  34894. throw new \UnexpectedValueException(
  34895. 'Could not parse version constraint ' . $constraint . ': ' .
  34896. 'Invalid operator "~>", you probably meant to use the "~" operator'
  34897. );
  34898. }
  34899. if (isset($matches[4]) && '' !== $matches[4]) {
  34900. $position = 4;
  34901. } elseif (isset($matches[3]) && '' !== $matches[3]) {
  34902. $position = 3;
  34903. } elseif (isset($matches[2]) && '' !== $matches[2]) {
  34904. $position = 2;
  34905. } else {
  34906. $position = 1;
  34907. }
  34908. $stabilitySuffix = '';
  34909. if (!empty($matches[5])) {
  34910. $stabilitySuffix .= '-' . $this->expandStability($matches[5]) . (!empty($matches[6]) ? $matches[6] : '');
  34911. }
  34912. if (!empty($matches[7])) {
  34913. $stabilitySuffix .= '-dev';
  34914. }
  34915. if (!$stabilitySuffix) {
  34916. $stabilitySuffix = '-dev';
  34917. }
  34918. $lowVersion = $this->manipulateVersionString($matches, $position, 0) . $stabilitySuffix;
  34919. $lowerBound = new Constraint('>=', $lowVersion);
  34920. $highPosition = max(1, $position - 1);
  34921. $highVersion = $this->manipulateVersionString($matches, $highPosition, 1) . '-dev';
  34922. $upperBound = new Constraint('<', $highVersion);
  34923. return array(
  34924. $lowerBound,
  34925. $upperBound,
  34926. );
  34927. }
  34928. if (preg_match('{^\^' . $versionRegex . '($)}i', $constraint, $matches)) {
  34929. if ('0' !== $matches[1] || '' === $matches[2]) {
  34930. $position = 1;
  34931. } elseif ('0' !== $matches[2] || '' === $matches[3]) {
  34932. $position = 2;
  34933. } else {
  34934. $position = 3;
  34935. }
  34936. $stabilitySuffix = '';
  34937. if (empty($matches[5]) && empty($matches[7])) {
  34938. $stabilitySuffix .= '-dev';
  34939. }
  34940. $lowVersion = $this->normalize(substr($constraint . $stabilitySuffix, 1));
  34941. $lowerBound = new Constraint('>=', $lowVersion);
  34942. $highVersion = $this->manipulateVersionString($matches, $position, 1) . '-dev';
  34943. $upperBound = new Constraint('<', $highVersion);
  34944. return array(
  34945. $lowerBound,
  34946. $upperBound,
  34947. );
  34948. }
  34949. if (preg_match('{^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.[xX*])+$}', $constraint, $matches)) {
  34950. if (isset($matches[3]) && '' !== $matches[3]) {
  34951. $position = 3;
  34952. } elseif (isset($matches[2]) && '' !== $matches[2]) {
  34953. $position = 2;
  34954. } else {
  34955. $position = 1;
  34956. }
  34957. $lowVersion = $this->manipulateVersionString($matches, $position) . '-dev';
  34958. $highVersion = $this->manipulateVersionString($matches, $position, 1) . '-dev';
  34959. if ($lowVersion === '0.0.0.0-dev') {
  34960. return array(new Constraint('<', $highVersion));
  34961. }
  34962. return array(
  34963. new Constraint('>=', $lowVersion),
  34964. new Constraint('<', $highVersion),
  34965. );
  34966. }
  34967. if (preg_match('{^(?P<from>' . $versionRegex . ') +- +(?P<to>' . $versionRegex . ')($)}i', $constraint, $matches)) {
  34968. $lowStabilitySuffix = '';
  34969. if (empty($matches[6]) && empty($matches[8])) {
  34970. $lowStabilitySuffix = '-dev';
  34971. }
  34972. $lowVersion = $this->normalize($matches['from']);
  34973. $lowerBound = new Constraint('>=', $lowVersion . $lowStabilitySuffix);
  34974. $empty = function ($x) {
  34975. return ($x === 0 || $x === '0') ? false : empty($x);
  34976. };
  34977. if ((!$empty($matches[11]) && !$empty($matches[12])) || !empty($matches[14]) || !empty($matches[16])) {
  34978. $highVersion = $this->normalize($matches['to']);
  34979. $upperBound = new Constraint('<=', $highVersion);
  34980. } else {
  34981. $highMatch = array('', $matches[10], $matches[11], $matches[12], $matches[13]);
  34982. $highVersion = $this->manipulateVersionString($highMatch, $empty($matches[11]) ? 1 : 2, 1) . '-dev';
  34983. $upperBound = new Constraint('<', $highVersion);
  34984. }
  34985. return array(
  34986. $lowerBound,
  34987. $upperBound,
  34988. );
  34989. }
  34990. if (preg_match('{^(<>|!=|>=?|<=?|==?)?\s*(.*)}', $constraint, $matches)) {
  34991. try {
  34992. $version = $this->normalize($matches[2]);
  34993. if (!empty($stabilityModifier) && $this->parseStability($version) === 'stable') {
  34994. $version .= '-' . $stabilityModifier;
  34995. } elseif ('<' === $matches[1] || '>=' === $matches[1]) {
  34996. if (!preg_match('/-' . self::$modifierRegex . '$/', strtolower($matches[2]))) {
  34997. if (substr($matches[2], 0, 4) !== 'dev-') {
  34998. $version .= '-dev';
  34999. }
  35000. }
  35001. }
  35002. return array(new Constraint($matches[1] ?: '=', $version));
  35003. } catch (\Exception $e) {
  35004. }
  35005. }
  35006. $message = 'Could not parse version constraint ' . $constraint;
  35007. if (isset($e)) {
  35008. $message .= ': ' . $e->getMessage();
  35009. }
  35010. throw new \UnexpectedValueException($message);
  35011. }
  35012. private function manipulateVersionString($matches, $position, $increment = 0, $pad = '0')
  35013. {
  35014. for ($i = 4; $i > 0; --$i) {
  35015. if ($i > $position) {
  35016. $matches[$i] = $pad;
  35017. } elseif ($i === $position && $increment) {
  35018. $matches[$i] += $increment;
  35019. if ($matches[$i] < 0) {
  35020. $matches[$i] = $pad;
  35021. --$position;
  35022. if ($i === 1) {
  35023. return;
  35024. }
  35025. }
  35026. }
  35027. }
  35028. return $matches[1] . '.' . $matches[2] . '.' . $matches[3] . '.' . $matches[4];
  35029. }
  35030. private function expandStability($stability)
  35031. {
  35032. $stability = strtolower($stability);
  35033. switch ($stability) {
  35034. case 'a':
  35035. return 'alpha';
  35036. case 'b':
  35037. return 'beta';
  35038. case 'p':
  35039. case 'pl':
  35040. return 'patch';
  35041. case 'rc':
  35042. return 'RC';
  35043. default:
  35044. return $stability;
  35045. }
  35046. }
  35047. }
  35048. <?php
  35049. require_once __DIR__ . '/composer' . '/autoload_real.php';
  35050. return ComposerAutoloaderInitComposerPhar1445871666::getLoader();
  35051. <?php
  35052. $vendorDir = dirname(dirname(__FILE__));
  35053. $baseDir = dirname($vendorDir);
  35054. return array(
  35055. 'Symfony\\Component\\Process\\' => array($vendorDir . '/symfony/process'),
  35056. 'Symfony\\Component\\Finder\\' => array($vendorDir . '/symfony/finder'),
  35057. 'Symfony\\Component\\Filesystem\\' => array($vendorDir . '/symfony/filesystem'),
  35058. 'Symfony\\Component\\Console\\' => array($vendorDir . '/symfony/console'),
  35059. 'Composer' => array($baseDir . '/src'),
  35060. );
  35061. <?php
  35062. $vendorDir = dirname(dirname(__FILE__));
  35063. $baseDir = dirname($vendorDir);
  35064. return array(
  35065. 'Seld\\PharUtils\\' => array($vendorDir . '/seld/phar-utils/src'),
  35066. 'Seld\\JsonLint\\' => array($vendorDir . '/seld/jsonlint/src/Seld/JsonLint'),
  35067. 'Seld\\CliPrompt\\' => array($vendorDir . '/seld/cli-prompt/src'),
  35068. 'JsonSchema\\' => array($vendorDir . '/justinrainbow/json-schema/src/JsonSchema'),
  35069. 'Composer\\Spdx\\' => array($vendorDir . '/composer/spdx-licenses/src'),
  35070. 'Composer\\Semver\\' => array($vendorDir . '/composer/semver/src'),
  35071. );
  35072. <?php
  35073. $vendorDir = dirname(dirname(__FILE__));
  35074. $baseDir = dirname($vendorDir);
  35075. return array(
  35076. );
  35077. <?php
  35078. class ComposerAutoloaderInitComposerPhar1445871666
  35079. {
  35080. private static $loader;
  35081. public static function loadClassLoader($class)
  35082. {
  35083. if ('Composer\Autoload\ClassLoader' === $class) {
  35084. require __DIR__ . '/ClassLoader.php';
  35085. }
  35086. }
  35087. public static function getLoader()
  35088. {
  35089. if (null !== self::$loader) {
  35090. return self::$loader;
  35091. }
  35092. spl_autoload_register(array('ComposerAutoloaderInitComposerPhar1445871666', 'loadClassLoader'), true, true);
  35093. self::$loader = $loader = new \Composer\Autoload\ClassLoader();
  35094. spl_autoload_unregister(array('ComposerAutoloaderInitComposerPhar1445871666', 'loadClassLoader'));
  35095. $map = require __DIR__ . '/autoload_namespaces.php';
  35096. foreach ($map as $namespace => $path) {
  35097. $loader->set($namespace, $path);
  35098. }
  35099. $map = require __DIR__ . '/autoload_psr4.php';
  35100. foreach ($map as $namespace => $path) {
  35101. $loader->setPsr4($namespace, $path);
  35102. }
  35103. $classMap = require __DIR__ . '/autoload_classmap.php';
  35104. if ($classMap) {
  35105. $loader->addClassMap($classMap);
  35106. }
  35107. $loader->register(true);
  35108. return $loader;
  35109. }
  35110. }
  35111. function composerRequireComposerPhar1445871666($file)
  35112. {
  35113. require $file;
  35114. }
  35115. <?php
  35116. namespace Composer\Autoload;
  35117. class ClassLoader
  35118. {
  35119. private $prefixLengthsPsr4 = array();
  35120. private $prefixDirsPsr4 = array();
  35121. private $fallbackDirsPsr4 = array();
  35122. private $prefixesPsr0 = array();
  35123. private $fallbackDirsPsr0 = array();
  35124. private $useIncludePath = false;
  35125. private $classMap = array();
  35126. private $classMapAuthoritative = false;
  35127. public function getPrefixes()
  35128. {
  35129. if (!empty($this->prefixesPsr0)) {
  35130. return call_user_func_array('array_merge', $this->prefixesPsr0);
  35131. }
  35132. return array();
  35133. }
  35134. public function getPrefixesPsr4()
  35135. {
  35136. return $this->prefixDirsPsr4;
  35137. }
  35138. public function getFallbackDirs()
  35139. {
  35140. return $this->fallbackDirsPsr0;
  35141. }
  35142. public function getFallbackDirsPsr4()
  35143. {
  35144. return $this->fallbackDirsPsr4;
  35145. }
  35146. public function getClassMap()
  35147. {
  35148. return $this->classMap;
  35149. }
  35150. public function addClassMap(array $classMap)
  35151. {
  35152. if ($this->classMap) {
  35153. $this->classMap = array_merge($this->classMap, $classMap);
  35154. } else {
  35155. $this->classMap = $classMap;
  35156. }
  35157. }
  35158. public function add($prefix, $paths, $prepend = false)
  35159. {
  35160. if (!$prefix) {
  35161. if ($prepend) {
  35162. $this->fallbackDirsPsr0 = array_merge(
  35163. (array) $paths,
  35164. $this->fallbackDirsPsr0
  35165. );
  35166. } else {
  35167. $this->fallbackDirsPsr0 = array_merge(
  35168. $this->fallbackDirsPsr0,
  35169. (array) $paths
  35170. );
  35171. }
  35172. return;
  35173. }
  35174. $first = $prefix[0];
  35175. if (!isset($this->prefixesPsr0[$first][$prefix])) {
  35176. $this->prefixesPsr0[$first][$prefix] = (array) $paths;
  35177. return;
  35178. }
  35179. if ($prepend) {
  35180. $this->prefixesPsr0[$first][$prefix] = array_merge(
  35181. (array) $paths,
  35182. $this->prefixesPsr0[$first][$prefix]
  35183. );
  35184. } else {
  35185. $this->prefixesPsr0[$first][$prefix] = array_merge(
  35186. $this->prefixesPsr0[$first][$prefix],
  35187. (array) $paths
  35188. );
  35189. }
  35190. }
  35191. public function addPsr4($prefix, $paths, $prepend = false)
  35192. {
  35193. if (!$prefix) {
  35194. if ($prepend) {
  35195. $this->fallbackDirsPsr4 = array_merge(
  35196. (array) $paths,
  35197. $this->fallbackDirsPsr4
  35198. );
  35199. } else {
  35200. $this->fallbackDirsPsr4 = array_merge(
  35201. $this->fallbackDirsPsr4,
  35202. (array) $paths
  35203. );
  35204. }
  35205. } elseif (!isset($this->prefixDirsPsr4[$prefix])) {
  35206. $length = strlen($prefix);
  35207. if ('\\' !== $prefix[$length - 1]) {
  35208. throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
  35209. }
  35210. $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
  35211. $this->prefixDirsPsr4[$prefix] = (array) $paths;
  35212. } elseif ($prepend) {
  35213. $this->prefixDirsPsr4[$prefix] = array_merge(
  35214. (array) $paths,
  35215. $this->prefixDirsPsr4[$prefix]
  35216. );
  35217. } else {
  35218. $this->prefixDirsPsr4[$prefix] = array_merge(
  35219. $this->prefixDirsPsr4[$prefix],
  35220. (array) $paths
  35221. );
  35222. }
  35223. }
  35224. public function set($prefix, $paths)
  35225. {
  35226. if (!$prefix) {
  35227. $this->fallbackDirsPsr0 = (array) $paths;
  35228. } else {
  35229. $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
  35230. }
  35231. }
  35232. public function setPsr4($prefix, $paths)
  35233. {
  35234. if (!$prefix) {
  35235. $this->fallbackDirsPsr4 = (array) $paths;
  35236. } else {
  35237. $length = strlen($prefix);
  35238. if ('\\' !== $prefix[$length - 1]) {
  35239. throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
  35240. }
  35241. $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
  35242. $this->prefixDirsPsr4[$prefix] = (array) $paths;
  35243. }
  35244. }
  35245. public function setUseIncludePath($useIncludePath)
  35246. {
  35247. $this->useIncludePath = $useIncludePath;
  35248. }
  35249. public function getUseIncludePath()
  35250. {
  35251. return $this->useIncludePath;
  35252. }
  35253. public function setClassMapAuthoritative($classMapAuthoritative)
  35254. {
  35255. $this->classMapAuthoritative = $classMapAuthoritative;
  35256. }
  35257. public function isClassMapAuthoritative()
  35258. {
  35259. return $this->classMapAuthoritative;
  35260. }
  35261. public function register($prepend = false)
  35262. {
  35263. spl_autoload_register(array($this, 'loadClass'), true, $prepend);
  35264. }
  35265. public function unregister()
  35266. {
  35267. spl_autoload_unregister(array($this, 'loadClass'));
  35268. }
  35269. public function loadClass($class)
  35270. {
  35271. if ($file = $this->findFile($class)) {
  35272. includeFile($file);
  35273. return true;
  35274. }
  35275. }
  35276. public function findFile($class)
  35277. {
  35278. if ('\\' == $class[0]) {
  35279. $class = substr($class, 1);
  35280. }
  35281. if (isset($this->classMap[$class])) {
  35282. return $this->classMap[$class];
  35283. }
  35284. if ($this->classMapAuthoritative) {
  35285. return false;
  35286. }
  35287. $file = $this->findFileWithExtension($class, '.php');
  35288. if ($file === null && defined('HHVM_VERSION')) {
  35289. $file = $this->findFileWithExtension($class, '.hh');
  35290. }
  35291. if ($file === null) {
  35292. return $this->classMap[$class] = false;
  35293. }
  35294. return $file;
  35295. }
  35296. private function findFileWithExtension($class, $ext)
  35297. {
  35298. $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
  35299. $first = $class[0];
  35300. if (isset($this->prefixLengthsPsr4[$first])) {
  35301. foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
  35302. if (0 === strpos($class, $prefix)) {
  35303. foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
  35304. if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
  35305. return $file;
  35306. }
  35307. }
  35308. }
  35309. }
  35310. }
  35311. foreach ($this->fallbackDirsPsr4 as $dir) {
  35312. if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
  35313. return $file;
  35314. }
  35315. }
  35316. if (false !== $pos = strrpos($class, '\\')) {
  35317. $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
  35318. . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
  35319. } else {
  35320. $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
  35321. }
  35322. if (isset($this->prefixesPsr0[$first])) {
  35323. foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
  35324. if (0 === strpos($class, $prefix)) {
  35325. foreach ($dirs as $dir) {
  35326. if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
  35327. return $file;
  35328. }
  35329. }
  35330. }
  35331. }
  35332. }
  35333. foreach ($this->fallbackDirsPsr0 as $dir) {
  35334. if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
  35335. return $file;
  35336. }
  35337. }
  35338. if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
  35339. return $file;
  35340. }
  35341. }
  35342. }
  35343. function includeFile($file)
  35344. {
  35345. include $file;
  35346. }
  35347. <?php
  35348. if (PHP_SAPI !== 'cli') {
  35349. echo 'Warning: Composer should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL;
  35350. }
  35351. require __DIR__.'/../src/bootstrap.php';
  35352. use Composer\Console\Application;
  35353. error_reporting(-1);
  35354. if (function_exists('ini_set')) {
  35355. @ini_set('display_errors', 1);
  35356. $memoryInBytes = function ($value) {
  35357. $unit = strtolower(substr($value, -1, 1));
  35358. $value = (int) $value;
  35359. switch($unit) {
  35360. case 'g':
  35361. $value *= 1024;
  35362. // no break (cumulative multiplier)
  35363. case 'm':
  35364. $value *= 1024;
  35365. // no break (cumulative multiplier)
  35366. case 'k':
  35367. $value *= 1024;
  35368. }
  35369. return $value;
  35370. };
  35371. $memoryLimit = trim(ini_get('memory_limit'));
  35372. // Increase memory_limit if it is lower than 1GB
  35373. if ($memoryLimit != -1 && $memoryInBytes($memoryLimit) < 1024 * 1024 * 1024) {
  35374. @ini_set('memory_limit', '1G');
  35375. }
  35376. unset($memoryInBytes, $memoryLimit);
  35377. }
  35378. // run the command application
  35379. $application = new Application();
  35380. $application->run();
  35381. Copyright (c) 2015 Nils Adermann, Jordi Boggiano
  35382. Permission is hereby granted, free of charge, to any person obtaining a copy
  35383. of this software and associated documentation files (the "Software"), to deal
  35384. in the Software without restriction, including without limitation the rights
  35385. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  35386. copies of the Software, and to permit persons to whom the Software is furnished
  35387. to do so, subject to the following conditions:
  35388. The above copyright notice and this permission notice shall be included in all
  35389. copies or substantial portions of the Software.
  35390. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  35391. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  35392. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  35393. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  35394. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  35395. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  35396. THE SOFTWARE.
  35397. �î8U�rÛ° k&Úå£èÖŒú^˜���GBMB