Difference between revisions of "Composer and NPM"
Bradymiller (talk | contribs) |
Bradymiller (talk | contribs) (→Forum) |
||
Line 179: | Line 179: | ||
=Forum= | =Forum= | ||
:*[https:// | :*[https://community.open-emr.org/t/composer/8001 Composer] |
Revision as of 08:26, 18 March 2018
Overview
Introduction
Composer provide two key functions for OpenEMR:
- A command line tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
- An autoloader of libraries including OpenEMR classes.
End Goal
- Centralize and organize all PHP libraries/dependencies into a single directory.
- Use Composer to collect and organize the PHP libraries/dependencies.
- Migrate all the PHP libraries/dependencies.
- Setup composer to use autoloading(with end goal of PSR-4).
- Centralize and organize all PHP libraries/dependencies into a single directory.
More Details
- Composer creates a vendor directory in the root folder. This is where all the external dependencies are kept.
- Commit the vendor directory to the codebase initially until we get composer to work with demo and build scripts.
- The workaround is to add a
.gitignore
line that removes all .git directories within your vendor directory. So add this line to the .gitignore file at the same level ascomposer.json
andvendor/vendor name/.git
- The workaround is to add a
- Get the demo and build scripts to bring in composer dependencies and package them up and test.
- Make sure documentation on how to use composer is up to date and developers are aware of upcoming changes
- Once this is done we can remove vendor directory from the codebase
Installation
Windows
This is the easiest way to get Composer set up on your machine.
The installer will download composer for you and set up your PATH environment variable so you can simply call composer
from any directory.
Download and run Composer-Setup.exe - it will install the latest composer version whenever it is executed.
See: https://getcomposer.org/doc/00-intro.md/
To test your installation, open up your favourite Command Line Interface (CLI) and run:
composer
And you should get output similar to this:
______ / ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/ Composer version 1.1.2 2016-05-31 19:48:11 Usage: command [options] [arguments] Options: -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question --profile Display timing and memory usage information --no-plugins Whether to disable plugins. -d, --working-dir=WORKING-DIR If specified, use the given directory as working directory. -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Linux & MacOS
The first step is to download Composer, which will effectively create a Phar (PHP Archive) file called composer.phar. From your terminal, run the following command:
curl -sS https://getcomposer.org/installer | php
The resulting file will be called composer.phar, a PHP Archive that can be executed directly via PHP. However, in our case, we want Composer to be accessible globally by simply typing composer
. To do this, move it to /usr/bin/ and create an alias:
sudo mv composer.phar /usr/local/bin/ vim ~/.bash_profile
Add this to your .bash_profile. It may be empty or non-existent, so go ahead and create it:
alias composer="php /usr/local/bin/composer.phar"
Now, relaunch your terminal and you'll be able to access Composer simply by calling composer
See: https://www.abeautifulsite.net/installing-composer-on-os-x
To test your installation, open up your favourite Command Line Interface (CLI) and run:
composer
And you should get output similar to this:
______ / ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/ Composer version 1.1.2 2016-05-31 19:48:11 Usage: command [options] [arguments] Options: -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question --profile Display timing and memory usage information --no-plugins Whether to disable plugins. -d, --working-dir=WORKING-DIR If specified, use the given directory as working directory. -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Usage
- clone the OpenEMR development version from github: https://github.com/openemr/openemr.git
git clone https://github.com/openemr/openemr.git
- Once it’s done run the following command to move into the OpemEMR root directory and checkout the master branch.
cd openemr git checkout master
In order to work with Composer a project must have a composer.json file within its root directory. If you take a look at the file you’ll see a list of OpenEMR package dependencies.
- require: a list of packages (and versions) required by OpenEMR. OpenEMR will not install if any of those package dependencies are not met.
- require-dev: a list of packages required by OpenEMR for development.
To run Composer for the first time and install your packages simply run:
composer install
When Composer has finished its install you’ll be ready to install OpenEMR.
Be aware that development requirements are always installed by default, Composer doesn’t magically know when it is being run on your production server. If you want to exclude development requirements you will need to run:
composer install --no-dev
Dependencies to migrate
Always included
- ADODB - adodb/adodb-php (COMPLETED)
- On 3/10/18 added a manual fix to this to avoid a very annoying php warning that is called numerous times in PHP 7.2. The fix was taken from adodb master branch (still not released, so expect the next package upgrade will have it; should check and make sure on package upgrade in future; commit for this was here: https://github.com/openemr/openemr/commit/961260ffb48910744507a02d9fa19267275a2c8e)
- html2pdf - spipu/html2pdf (also need to include setasign/fpdi-tcpdf) (PENDING REMOVAL - migrating to mPDF)
- TCPDF - tecnickcom/tcpdf (PENDING REMOVAL - migrating to mPDF)
- FPDF - setasign/fpdf (UNABLE to do this since there is a needed minor modification to work with PDF_Label; there is no way around this since certain variables are set as protected and the prior version of FPDF that would work is not compatible with PHP7)(only plan to use FPDF for PDF_Label anyways, so not a huge deal)(is stored at library/classes/fpdf)
- FPDI - setasign/fpdi (COMPLETED; this was brought in by mPDF; will try to remove other copy when get rid of html2pdf/TCPDF stuff)
- Smarty - smarty/smarty (COMPLETED)
- adLDAP - adldap/adldap (REMOVED - no longer used)
- JSON (Old JSON Wrapper, maybe replace with hampel/json?) (REMOVED- Using built in php function)
- pdf-php - rospdf/pdf-php (COMPLETED)
- phpseclib - phpseclib/phpseclib (COMPLETED)
- phpmailer - phpmailer/phpmailer (COMPLETED)
- Zend - zendframework/zendframework "2.4.9", (COMPLETED)
- Phenx - phenx/php-font-lib "0.4", (dompdf dependency) (COMPLETED)
- Phenx - phenx/php-svg-lib "0.1", (dompdf dependency) (COMPLETED)
- DomPDF - dompdf/dompdf "0.7.0", (COMPLETED)
- Doctrine - doctrine/common "2.5.0", (Doctrine CouchDB Dependency) (COMPLETED)
- Doctrine - doctrine/couchdb "1.0.*@dev" (COMPLETED) **NOTE** double check .git folder is not included after running build.xml or PHING
- Doctrine - doctrine/orm "2.5.5", (COMPLETED) (Added in OpenEMR 5.0.1) (requires PHP 5.4+)
- adLDAP2 - adldap2/adldap2 "7.0.4", (COMPLETED) (Added in OpenEMR 5.0.1) (requires PHP 5.6.0+)
- mPDF - mpdf/mpdf "6.1.3", (COMPLETED) (requires PHP 5.4+)
- twig - twig/twig "1.33.*" (COMPLETED)
- http-foundation - symfony/http-foundation "2.8.*" (COMPLETED)
- yaml - symfony/yaml "2.8.*" (COMPLETED)
- htmlpurifier - ezyang/htmlpurifier "4.9.3" (Sherwin plans to use to html escape editors that need to allow html code)
- phpspreadsheet - phpoffice/phpspreadsheet "1.0.0" (Sherwin plans to use this; note Kim was planning to use a prior deprecated package phpoffice/phpexcel for allscripts rx module and will instead need to use phpspreadsheet now)
- knp-snappy - knplabs/knp-snappy "^0.5.0" (COMPLETED)
- stripe-php - stripe/stripe-php (Sherwin requested this for incorporating payment collection via stripe)
Optional
- openemr/wkhtmltopdf-openemr - Used by institutional billing (ub04) to create the pdf's. Very large (240MB) so unable to include in main codebase. Install via following command in the openemr directory:
- composer require openemr/wkhtmltopdf-openemr
Global
- This section is for developers, and these are packages that should be installed globally:
- phing/phing (this is used by mechanism for cleaning out stuff when bring in new composer/bower packages)
Migrating
- Add package/vendor to the composer.json file
- run
composer install
- (if this isn't bringing in requested package, then will need to remove the composer.lock file before running the command)
- Remove unused files(if they are present) from the installed package (eg. git, .gitignore, tests, docs) - You must update build.xml to include directory(s). This step will require a composer global install of phing and then use the path to phing below in the call.
- Windows - From the command line run
call vendor/bin/phing vendor-clean
- Linux - From the command line run
./vendor/bin/phing vendor-clean
- (btw, if need to clean up public/assets for bower stuff, then run
./vendor/bin/phing assets-clean
)
- (btw, if need to clean up public/assets for bower stuff, then run
- Windows - From the command line run
- run
composer dump-autoload -o
Autoloader
Ongoing Work
- Working on using the autoloader to modernize the OpenEMR codebase. Steps:
- Place the central libraries that are always called in OpenEMR into the autoloader. (COMPLETED)
- Place the OpenEMR classes into the classmap autoloader.(IN PROGRESS)
- Done with library/classes with following exceptions that plan to work on:
- Prescription.class.php, /ClinicalTypes, /rulesets, and /smtp.
- Convert libraries into classes and also bring these in via the classmap autoloader.
- Above steps will allow then to do the following:
- Remove globals from within classes.
- Write phpunit tests.
- Place new "modernized" OpenEMR classes into the PSR-4 autoloader.(IN PROGRESS)
Update Autoloader
- If updating classes within OpenEMR to work with the autoloader, then just need to run the following command:
- run
composer dump-autoload -o
- run