PHP Composer dependency of library - php

I'm developing a PHP-App using composer.
Now I need a PHP-Libary, which is also developed by me.
Inside the IDE there is no problem using the library-classes. But when the app is running inside Apache2 I need to install the library via "composer update".
But when I change some library-class I always need to reinstall the new code via composer. Before that I have to push my changes to the SCM.
Is there a way to simplify this process during development?

After trying out symlinks, the solution for me is symlinking the dependend library with ln -s TARGET NAME. Adding the dependency to composer.json is for generating the classmaps and running without errors after deleting the symlink. It works fine. Also a "composer update" is working without overriding the symlink. New classes are found immedeately without doing the whole process described in the question.

Related

How do I update my core project when using composer?

I recently started a project using composer for the first time, and I just deployed it to Q&A (demo), with git I used to just do a git pull and update the Q&A environment, but now with composer update only the dependencies get updated.
My question is, what is the SOP(standard operating procedure) for updating the core project, do I still use git, or is there a way to do it with composer?
Or am I completely doing this wrong, and should be working out of the vendors folder?
The point of Composer is that you don't need to version control the dependencies which means anything that ends up in vendor/.
The project has a composer.json and composer.lock. These are within git's control so it knows the packages and versions to use. However, the vendor/ directory should be ignored, with .gitignore. If you don't already have that set up simply add this line:
/vendor/*
You version control your other files as normal.
So the operating procedure is to use git and normal. Followed by composer update.
The advantage of this setup is that git doesn't have to bother managing potentially thousands of files (inside vendor/) that will never normally change. The only circumstance under which they'd change is if you want to start using a different version of a package, or adding new ones. Well, all of those packages/versions are defined in your composer.json (which git is monitoring for changes). All you need to do is run composer update and it will update everything in your vendor/ directory to the "right" version.
That's one of the advantages of using Composer - all developers can have a "list" of the correct packages/versions, without the need to version control all of the files in them.
Edit as per the comments below:
Note composer update should only be run in development. Use composer install when deploying to QA or production. This will install the exact versions referenced by your composer.lock file.
You keep using git for your project and composer for 3rd party libs.
I have a large web app in PHP (link in my profile), and that's how I've been doing it, and it works good.
When I have new production-ready code and it's ready to be released, I do:
git fetch && git pull
And when I want to update composer, I do:
composer -o update
I don't know if you're familiar with -o flag - it generates static autoloading maps, which makes your project load classes faster. More info here.

UserFrosting, Composer & wrong path in includeJSTop

I recently started learning UserFrosting...
I managed to successfully install highlightjs from Packagist using Composer. All went well, new folder and all required files are created in /userfrosting/vendor/components/highlightjs
However, initialize.php and it's includeJSTop() does inject the reference in a path pointing to /public_html/js while files are in /userfrosting/vendor/components/highlightjs
There is a simple solution - to copy highlightjs.js from /userfrosting/vendor/components/highlightjs to /public_html/js but I would like to know if my approach is correct. Or perhaps there is a better way where files are copied to /public_html/js as a part of Composer's install/update.
Composer is for PHP packages. highlight.js is a Javascript package, so it doesn't really make sense to load it using Composer.
There are package managers for Javascript - NPM being the most popular - but UserFrosting 0.3.1 doesn't use those out of the box (UF4 will have integrations for NPM, but that hasn't been released as of the time of this post).
Your best bet for now would indeed be to simply do a "manual install" and copy the highlight.js file to your public/js directory. In that case, you don't need to load it with Composer.

Issue with laravel composer

(don,t get angry with that)why we use composer i searched in google it says it is used for the dependencies of laravel, but why we create project in composer?cant we create it in simply in xampp/htdocs/laravel/... there as in past they does in codeigniter?explain it simply and clearly, what is the purpose of using the artisan commands, like php artisan serve that create a host address like localhost:8000 cant we go there in browser simply like localhost/laravelproject?and does composer works offline,without internet access,i mean entering those commands in cmd prompt?simply my concept is not clear with using composer with laravel, clear my concept...thanks
As google said, composer is always for dependencies, not just laravel but in any other framework or libraries, composer is used to automatically download dependencies needed for code to work.
Laravel is based on some packages that are some kind of third-party packages. When you create a project in codeigniter you copy all files needed for project. You can do this in laravel too, but you should have all files that are needed. Now you can download all files manually or just set those files and libraries in a file named composer and let composer do that for you. And even if there are dependencies for libraries that you mention for composer, composer detects them and downloads them too.
When you create laravel project with composer, you can save all files and use them for another project (as I did), and not to use composer again.
Artisan commands are just here to help you. Many of commands that are supported by artisan, are possible to be done by your hand, but artisan is here to help you.
Of course you can use xamp or wamp to host your laravel project, here serve command is another option to serve your project. You do not have to use it (as I never do).
Composer does not have dependencies and it just detects dependencies and downloads them.
Hope that helps.

How to Deploy a Cake PHP App

I wonder if someone can help me. I've been handed in a Cake PHP app that I need to 1) add minor changes 2) deploy. I've never really worked with Cake before and was wondering whether do I need to anything in order for it to work?
For instance, With a Node app, you need to install modules npm install. With a Rails app you'll likely need to install the gems bundle install.
Is there something similar with Cake? I've set the localhost server, but when I try to access the url I get all sort of errors. Some I've fixed (missing environment settings which I just override the Redis host and port). The latest one is:
{
"exception":{
"class":"MissingControllerException",
"code":404,
"message":"Controller class Controller could not be found.",
"file":"\/Library\/WebServer\/Documents\/php\/oompbe\/vendors\/cakephp\/lib\/Cake\/Routing\/Dispatcher.php",
"line":154,
"trace":[
"#0 \.../app\/webroot\/index.php(109): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))",
"#1 {main}"
]
}
}
PS: What's up with all the crazy \/\/?
PPS: Can I find out the version Cake I'm running?
CakePHP is just php. As most properly done php apps these days it comes with composer. I recommend you to read at least the basics of it's manual. Composer is an awesome tool.
git clone <repo>
cd <reponame>
composer install
If you start a new Cake application the official documentation tells you how to this as well:
composer create-project --prefer-dist cakephp/app [app_name]
If you want to automate things further composer provides you callback scripts. They'll allow you to automate tasks, basically trigger commands, after different actions. This is pretty useful to build assets after a composer update for example. I recommend you to not put lots of commands into that section but instead have dedicated script files you trigger by the callbacks.
Can I find out the version Cake I'm running?
If installed via composer it is usually in vendor/cakephp/cakephp/version.txt. Check the content of that file.

Trouble installing Omnipay via Netbeans composer extension

I am currently trying to install Omnipay into my Codeigniter project. I am stuck on windows because I do not have ssh access to the box where this needs to run on. So far I have gotten a new directory in the project root that is named "vendor" and it contains a lot of empty directories referring to Symfony (for what reason is beyond me).
Then I get a runtime exception that I need to enable the openssl extension in my php to download the necessary files and this is where I am stuck at. I don't run WAMP on my computer and I just use the php.exe I downloaded to work with netbeans.
Isn't there an easier way to get omnipay to run? Like just download the files from somewhere and plug them into my project like normal? It seems to be an aweful lot of headache to get a simple library to run in my CI project.
Please forgive my ignorance towards composer but I currently see no benefit of using it for this particular project.
You can "just download" the files here: https://github.com/omnipay/common/archive/master.zip
The problem is, Omnipay depends on Guzzle (an HTTP library), and Guzzle depends on some Symfony components. So you will spend the rest of the day downloading dependencies and making sure you have all the necessary files. That is the problem Composer solves for you.
I don't have any experience running Composer on Windows, but I would start here:
http://getcomposer.org/doc/00-intro.md#installation-windows
Using the Installer
This is the easiest way to get Composer set up on your machine.
Download and run Composer-Setup.exe, it will install the latest
Composer version and set up your PATH so that you can just call
composer from any directory in your command line.
Once you have Composer installed, you should simply be able to make a file named composer.json in your project root, with the following contents:
{
"require": {
"omnipay/omnipay": "~2.0"
}
}
Then use the Command Prompt and cd to your project's directory, and run composer update to download the Omnipay files and all their dependencies.

Categories