How to install PHP PhantomJS require packages - php

I'm trying to use PHP PhantomJS but it's require some package to run ..
I'm composer in php and when I'm trying to install dependencies on root PHP PhantomJS
composer install
says
Loading composer repositories with package information
Installing dependencies (including require-dev)
Nothing to install or update
Generating autoload files
I'm confused ... anybody can help how install package that's need to run PHP PhantomJS script?

If you downloaded it, you have everything you need without using Composer. Composer is for downloading this and other packages, but this is not the only way of getting packages. :)
Now the easiest way to use that package is to have a new clean empty directory and execute this line:
composer require jonnyw/php-phantomjs:2.*
Now magic happens, including the creation of a composer.json file, download of that package, creation of autoloading files, and then you are done.
With an otherwise empty directory you couldn't do very much, so in order to make use of that package (or others) inside your own code, go to the root directory of your code, and execute above line. The same things happen, and then you are pretty much done - apart from the fact that you need to include the autoloader file in your own code if you want to use that package.

Install PhantomJS via Composer
Use the package "jakoch/phantomjs-installer".
It installs the PhantomJS binary for Linux, Windows or Mac into the /bin folder of your project.
Simply add the following lines to your projects composer.json file:
{
"require": {
"jakoch/phantomjs-installer": "3.0.0"
},
"scripts": {
"post-install-cmd": [
"PhantomInstaller\\Installer::installPhantomJS"
],
"post-update-cmd": [
"PhantomInstaller\\Installer::installPhantomJS"
]
},
"config": {
"bin-dir": "bin"
}
}
The version number determines which version of PhantomJS is fetched.
Execute composer update or composer install

Related

Running commands after Composer package installed globally

I have created a Composer package which is designed to be installed globally, it's basically a package to spin up Docker environments for projects that I use a lot for local development. I'd like to share my package but would like to make it more user friendly.
Currently when the package is installed (with composer global require me/my-package-name), the user needs to take some extra steps:
cd into the install location and run composer install (inside the root of my package in their vendor dir)
On MacOS, users also need to run cd docker && chmod +x phpenv
Add above docker folder to their PATH
I'm trying to make this less of a pain, so I attempted to add a post package install command - composer.json:
"scripts": {
"post-package-install": [
"DannyXCII\\Environment\\Install\\Installer::postPackageInstall"
]
},
public static function postPackageInstall(): void
{
$path = dirname(__DIR__, 3);
exec("cd $path && composer install && composer update && composer dump-autoload && cd docker && chmod +x phpenv");
}
After trying and failing to get this to work when installing this globally I realise now that this script won't get called when this package is installed, only when packages are required and composer install is ran inside this package, as:
Note: Only scripts defined in the root package's composer.json are executed. If a dependency of the root package specifies its own scripts, Composer does not execute those additional scripts.
So, I believe in this case, the solution would be to add this script to the root project - so I'd need to update this script and add to the composer.json file in C:\Users\Danny\AppData\Roaming\Composer(?), as would anyone else wanting to use this - so this doesn't solve my issues regarding usability.
I have been searching and attempting to resolve this for a while but found this quite a difficult topic to search on.
Essentially, my question is: how can I run commands such as composer install inside my package after it is globally required without the user having to do so manually?
Ok so I've now solved this - so, you know how you can run composer global require laravel/installer and immediately type laravel and you'll see some help text from the command? This is the same level of convenience I wanted to achieve with my package so I decided where better to look to see how it's done?
I was thinking about this incorrectly; I don't want a vendor directory inside my globally installed package and I shouldn't ever expect commands like composer install inside my package.
I was able to remove the two blocks from above. Inside my phpenv script, where I'm looking for the autoloader from within my package, I also added an additional check, so that this will use the autoloader at C:/Users/Danny/AppData/Roaming/Composer/vendor/autoload.php if it exists - this removes the need to run composer install (one step down):
if (file_exists(dirname(__DIR__, 3) . '/autoload.php')) {
require dirname(__DIR__, 3) . '/autoload.php';
} else {
require dirname(__DIR__, 1) . '/vendor/autoload.php';
}
Assuming you have your Composer bin directory added to your path (something like C:/Users/Danny/AppData/Roaming/Composer/bin), I was able to remove the need to add the path to this package specifically by making sure that the script to execute my commands was mapped to the above bin directory. I moved my phpenv script to a bin directory in my package and then added the following to my composer.json - this removes the need to add the path to the script directory to my environment variables path:
"bin": [
"bin/phpenv"
],

Copy files from package to project root directory using composer

I'm writing a package for Packagist and I'm facing a problem with Composer. I need to copy a file from my package to the project root after install, but nothing is happening after the package installation.
After reading Composer documentation, I found that I should put a script inside the event post-install-cmd, inside the script section into composer.json file.
So, I added this to my package composer.json file
"scripts": {
"post-install-cmd": [
"php -r \"copy('vendor/myvendor/mypackage/myfile', 'myfile');\""
]
}
To install the package I'm doing
$ composer require myvendor/mypackage --dev
After the package installation everything seems fine, but the file is not being copied and no error is shown.
See https://getcomposer.org/doc/articles/scripts.md for the documentation of scripts. The most relevant part is:
Note: Only scripts defined in the root package's composer.json are
executed. If a dependency of the root package specifies its own
scripts, Composer does not execute those additional scripts.
So, you cannot define any scripts in your module. There is a bug report about that, but the maintainer of composer is not a friend of executing the scripts of dependencies

installing php app via composer

I wanted to install via composer given information like this
{
"name": "bitcoin app",
"require": {
"slim/slim": "2.2.0"
}
}
I am unable to recognize do I have to write this to a php file and upload to the server?
Composer is a PHP based dependency management system.
That's a snippet of a composer.json file used to get & manage initial dependencies, to use it you'll need to have PHP & Composer installed and then create a file called composer.json in the location you'd like to have the project created.
Once you'd done that run composer install to get the dependencies. This won't actually install an app persay, you'll still need to make that yourself.
Scotch.io has a decent beginners guide to Composer if you're uncertain about how to install it & what it's actually used for.
No. You should write this to a json file named composer.json.
Then use composer to install the package: composer install
1) First you need to create or found composer.json
2) Then write your code in this file
3) In last you have to update composer.

fuelphp Composer is not installed. Please run "php composer.phar update" in the root to install Composer

I am trying to install fuelphp.
And getting the error as
Composer is not installed. Please run "php composer.phar update" in the root to install Composer
In my xampp/php directory I run a command
php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"
But once i run php composer.phar install composer could not find a composer.json in e:\xampp\php
How can i resolve and run fuelphp successfully can anyone help.
As of 1.7.1, we no longer supply the composer.phar file in the zip. It only has a limited shelf life (30 days before it starts complaining).
Instead we suggest you install composer yourself, either locally (specific for this fuelphp installation) or globally so you only have to install it once for all your projects.
Composer is a tool for dependency management in PHP, like npm for Node.js, bundler for ruby, and others.
It reads a file called composer.json with the dependent libraries your project needs and, finally, installs (downloads) them for you.
Fuelphp can be installed using composer, but there are several packages.
So, you need to create the composer.json with all needed fuelphp packages. Open notepad, save a file with the name composer.json (be sure to save it with ".json" extension) and put this content:
{
"require": {
"fuelphp/upload": "2.0.1",
"fuelphp/event": "0.2.1",
(...)
}
}
Note you need to insert at "(...)" the others fuelphp packages and the needed versions. You can check them all at https://packagist.org/ (type fuelphp at search). Packagist is the main Composer repository.
More information about Composer at this link.
Let me know if you need more information about it.
If you are running FuelPHP 1.7, the download comes with all Composer files you need. You need to run php composer.phar install in the root directory of FuelPHP (the same directory that contains the public folder and the fuel folder.
As long as you have v1.7 (I'm not sure if earlier versions contain the files), that directory will contain composer.json and composer.phar.
In folder fuelphp-1.7 (latest), there are two files: composer.phar and composer.json you need to cd into that folder and run:
php composer.phar install
If you don't have php in your path, you should do something like:
e:\xampp\bin\php\php5.4.16\php.exe composer.phar install
Use the full path to your php.exe. Remember your current working directory should be fuelphp folder where composer.phar and composer.json are.

Install PHPUNIT with Composer

I have project on Symfony 2 and i would like use PHPUNIT on Windows 7.
On githut phpunit is:
Composer
Simply add a dependency on phpunit/phpunit to your project's composer.json file if you use Composer to manage the dependencies of your project. Here is a minimal example of a composer.json file that just defines a development-time dependency on PHPUnit 3.7:
{
"require-dev": {
"phpunit/phpunit": "3.7.*"
}
}
For a system-wide installation via Composer, you can run:
composer global require 'phpunit/phpunit=3.7.*'
Make sure you have ~/.composer/vendor/bin/ in your path.
First i use system-wide installation but i dont know when this installed.
Next i add to my composer.json require-dev.
This installed phpunit in C:/wamp/www/myproject/vendor/symfony. Next i try commands:
composer install --dev
And i can't use phpunit. In cmd.exe i enter "phpunit" and i have error:
'phpunit' is not recognized as an internal or external command operable program or batch file
How can i use phpunit? I have Windows 7, Wamp server and php 5.4.12.
When you install PHP-Unit in windows via composer, the global installation will create files in
C:\Users\YOUR_USERNAME\AppData\Roaming\Composer
To execute phpunit easily via command line you need to add path of phpunit.bat file in windows Environment Variables. For this:
Right click My Computer
Go to Properties -> Advance system settings and
Click Environment variables from the Advance tab.
Now add C:\Users\YOUR_USERNAME\AppData\Roaming\Composer\vendor\bin to the windows PATH.
You can now run the phpunit from command. Note that you may need to restart your command prompt for the changes to take effect.
The bin file of packages are put in the configured bin directory. By default, this is vendor/bin and when you use the symfony standard edition, this is the bin folder.
To execute this bin file, run ./bin/phpunit (or ./vendor/bin/phpunit when not using the Symfony Standard Edition)
Windows users have to put this in double quotes: "bin/phpunit" (or "vendor/bin/phpunit")
composer require --dev phpunit/phpunit ^7
The above example assumes, composer is already on your $PATH variable.
You composer.json should look similar to;
{
"name": "vendor_name/package_name",
"description": "This project is for practicing writing php unit tests",
"minimum-stability": "stable",
"license": "proprietary",
"authors": [
{
"name": "Umair Anwar",
"email": "umair.anwar#gmail.com"
}
],
"autoload": {
"classmap": [
"src/"
]
},
"require-dev": {
"phpunit/phpunit": "^7",
"phpunit/dbunit": "^4.0"
}
}
Easiest way to install phpunit via composer is to run from project root.
$ composer require phpunit/phpunit
What this would do is, it will create a phpunit folder inside vendor/bin
and you can run unit tests like this..
$ ./vendor/bin/phpunit
Too simple operation on Windows with composer and works for me following way:
Install composer
https://getcomposer.org/doc/00-intro.md#installation-windows Go to
your symphony folder e.g C:\wamp64\www\symfony\UserManagement where is
composer.json and run this command.
Should be register with global to not have issue $phpunit bash: phpunit: command not found
//old version is 5.7 new 6.4 or put newest version.
composer global require --dev phpunit/phpunit ^5.7
I remember futzing around with the composer dependency stuff for phpunit and never could get it to work.
Instead, from your git bash shell:
mkdir ~/bin
cd ~/bin
curl https://phar.phpunit.de/phpunit.phar > phpunit
chmod +x phpunit
exit out of bash and then start a new bash session.
And you should be good to go. You can echo $PATH to verify you have a path to ~/bin but one seems to added by default.
https://phar.phpunit.de/phpunit.phar
I also came across the same issue and find out the solution by following steps
To run PHPUnit in Windows 7 under WAMP installation
Composer Install
{
"require-dev": {
"phpunit/phpunit": "3.7.*"
}
}
Simply Set Environment Variable
The php unit will be install in a vendor dir in vendor/bin
Path : C:\wamp\www\myproject\vendor\bin;
Open a new Command Prompt
C:\Users\guny >phpunit --version
PHPUnit 3.7.30 by Sebastain Bergmann

Categories