How To Add PHP Projects to Composer Packagist Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone welcome back to yet another Xin cast in this video we will talk about how we can publish our PHP library to packages so anyone can install our library using composer in their own project if you don't know about composer it's like NPM for PHP composers that package a dependency manager for PHP in the previous video I have created a random code generator that has a simple class that basically generates a random code here's the code that we have done in the previous video so it basically generates a random code for us so in order to publish it to packages we have to create a composite or JSON file so let's do this I'll open up the terminal here in the terminal type composer in it hit return or enter so what would be the package name I will keep the package name as it is right now I'm gonna hit return to continue the default one in description I'm gonna add a description you should add institution to your library as well so let's say it's library I will generate a random code for here so package type this is important which one is going to be our package type a framework could be a project for example laravel is a project and packages like this is basically a library I'm going to type your library this is the MIT license no we don't have any dependencies yes so composable generate a composite chisholm file for us everything is just perfect here but all we need to do is we have to add a autoload property so inside the auto property we will tell composer which standard we are going to use and dynamic space it should map to so we means the PSL for and now we will map our library to a custom namespace to avoid further issues we should always use the namespace that we have defined in our class file followed by double slashes and here I have to tell the destination so this is for in our cases SRC directory so this is visible telling composer in where it should look for our class file this inside SRC directory all right now I'm going to commit this change and push it to our github repository as you can see the composer to JSON file was added now we are ready to publish our library to packages so go to packages orz and log in using your github or whatever and hit the submit link here and in here you have to type your repository URL so I'm going to copy this URL and paste it back here and click the check button alright now click the submit button to confirm submission now we will have to add packages to the github service code in order to do that go to the github repository and click on the settings now go to the integrations and services and here quickly add service and type your packages select packages and here we have to give some credentials so the user type your email address here please don't send a spam email okay now here I have to type the token so from where are you gonna get the token go back to packages and go to your profile in the profile there is a button called show if it opens you click on this the token will be appearing here let's copy the token and paste it back here I'm gonna leave the domain and make sure the active is selected click on the add service alright that hook was successfully created now we have to create a new release here you will see 0 releases before I started creating this video I feel release in your case there should be 0 release so click on this link and click on draft a new release but I'm gonna name this version 1.0 and here it should keep the realest title and describe about the rel is like what kind of bugs you have faced or what kind of new features there there could be I'm gonna leave that empty for now so click the publish release alright we now have the Aurelia's here I'll go back to the packages and click on the object and once you update that you can see that inside the tag lists i have the 1.0 now in your case you will not going to have these tags I created them earlier all right probably and can delete them but I will leave it as it is for now ok so now it's time for us to test so I'll copy this command I'll go back to my desktop I'm gonna create a new project here let's call our project and good codes going to open this again in vs code I'm gonna open up a terminal say the terminal man is a composer I'm gonna just paste that command alright hit return and that composer installed the library for you all right so composer installed the library but if you take a look at here it picked the previous release though I have a latest release composer didn't pick that up all right so to fix that if you take a look at the tag is one point zero so the latest release is one point zero I'm gonna have to manually update that you probably not gonna have to do that because you don't gonna have this tag I'm hoping that I'm not making you confused but again this is important for you to understand so now how you how you gonna upgrade your library to the latest version so you just have the ID and the really is ID here and here now you have this a composer update so you learned a new thing which is good all right composer is a good buy it upgraded the library to 1.0 great now I'm gonna have a test file here let's do this index not HP so inside the test file I'm gonna first have to import the other work autoloader require once inside the vendor I have the autoloader PHP so now here I'm gonna say code it's still new well take a look at the vendor here I have my library inside the source random codes the name is business random codes as well according to the class name however if you take a look at the composer inside the autoload psr-4 dot PHP here you can see that composer has mapped our namespace with the library okay so now we're gonna have to follow thee now we are going to have to call the generate method that our library provides so I'm gonna print are a citizen array killed generate sounds a PHP PHP and mr. PHP and boom here we have a new code let's do it again okay let's read the cover what you are is what you have been what you will be is what you do now my goodness that's something okay let's do another one when it is obvious that the goals cannot be reached don't adjust the goal adjust the action steps okay it's good one if you want things to be different perhaps the answer is to become different yourself happiness happens next intro adore you didn't know you left open this is kind of true I have but this happened to me one today is worth day to tomorrow's ok that's all for today I'm not gonna waste your time anymore but but to be honest I think I'm going to read a few more coats it's going to really inspire me help me motivate keep things doing however if you want to motivate me on doing this thing make more videos please go ahead subscribe to my youtube channel now someone I'm available on every social media only on this username self-promotion time recently metadata bases in PHP called slick daily it's available in slightly bit of github that I owe so make sure give it a try if you are interested it works it works just intuitively and I hope you're gonna love it that's all for today's video thank you for watching I hope it helps
Info
Channel: RakibTG
Views: 8,822
Rating: 4.9337015 out of 5
Keywords: PHP, Web Development, Composer
Id: B2DFoO_CMwQ
Channel Id: undefined
Length: 10min 23sec (623 seconds)
Published: Fri Apr 27 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.