So I want to use third party library form my project. This library calls "blockchainApi" and is stored in application/third_party/ dir.
so in my model I just use:
require_once APPPATH . '/third_party/blockchainApi/Blockchain.php';
$Blockchain = new \Blockchain\Blockchain(PAYMENTS_BTC_API_CODE);
and its load normal, but when I try to reach method from this class, it returns me error, method:
$response = $Blockchain->Receive->generate($data['wallet'], $data['callback_url']);
error:
Fatal error: Class 'Blockchain\Create\Create' not found in <..>blockchainApi/Blockchain.php on line 65
so the problem is:
this not working... so how to fix it?
I believe this guide is the best thing for you. And you will have a chance to use composer.
https://philsturgeon.uk/blog/2012/05/composer-with-codeigniter/
This is happening due to PSR-4 standards and not having an autoloader for namespaces
Edit:
From what I see here (link) you will probably need composer.
It is preferable to find a machine with linux. On terminal move to an empty folder run the following command:
curl -sS https://getcomposer.org/installer | php
Then you will have inside your folder a composer.phar file.
After that you create a composer.json file and inside you write:
{
"name": "project",
"description": "",
"license": "MIT",
"authors"
"require": {
"php" : ">=5.3.0",
"blockchain/blockchain" : "1.*"
},
"require-dev": {
}
}
Then run
composer.phar update
Then upload inside you project folder
- vendor (folder)
- composer.lock
- composer.json
Inside you index.php include the autoloader
include_once './vendor/autoload.php'
Optionally to run composer from everywhere by simply typing composer copy composer.phar to your local bin
cp composer.phar /usr/local/bin/composer
Then instead of composer.phar you can do:
composer update
Related
I'm trying to install the clickatell php library after this instruction:
https://github.com/arcturial/clickatell
But so far i was only able to install composer.
They say: this library uses composer and can be acquired using the following in your composer.json file.
{
"require": {
"arcturial/clickatell": "*"
}
}
So I have to add this to the composer json file? Then require the json file in my php script? I've no idea what to do next. Any help would be great.
When you are in your project root, run the following:
create a composer.json file with the following contents:
{
"name": "your/project",
"description": "project description",
"require": {
"arcturial/clickatell": "*"
}
}
php -r "readfile('https://getcomposer.org/installer');" | php
This will download a file called composer.phar
php composer.phar install
This will install the dependencies you specified in your composer.json file. Once complete, your project will now have a folder called "vendor".
Include the "vendor/autoload.php" file in your script
require_once __DIR__ . '/vendor/autoload.php';
...
Now you should be able to use the library as specified in the documentation.
I'm trying to install composer in terminal by entering this command:
php composer.phar install
it starts to install required packages but I'm getting this error type:
[RuntimeException]
Could not scan for classes inside "app/commands" which does not appear to be a file nor a folder
How can I overcome this issue?
Usually this happens when you have some corrupted files or any composer update has crashed or interrupted.
To solve, just delete the vendor folders and run
composer install
When you install Laravel it creates a
app/commands
folder. Looks like it's not there. Just create it or remove from composer.json:
"classmap": [
"app/commands", /// <--- this line
],
And run
composer update
artisan dump-autoload
The last one is similar to composer dump-autoload, but it does some Laravel stuff too.
If you don't have any commands you don't really need it. If you plan to create artisan commands, create that folder and it should work.
I had the same problem. In my case, I noticed that there was no app/commands folder in my laravel install. I created the commands folder and composer dump-autoload was working again!
You should be able to solve this issue by simply running:
rm -rf vendor/autoload.php vendor/autoload_runtime.php vendor/composer && composer install
This cleans up the corrupted files without having to remove the entire vendor folder or cleaning up the global cache.
As others have mentioned, this usually happens if you interrupt a running Composer (e.g., Ctrl+C during composer update). But it does not corrupt all of the files, only the composer internals – which the command above then removes.
This is an older question with valid answers, but somebody might find this helpful.
My problem was that I've had App instead of app in my directory path. Maybe this will help someone.
I am Xampp user on Windows 10. I try all of the above methods but none of them work for me. I fixed my problem with this method, and Hopefully, it will help others.
Create a directory C:\bin
Append ;C:\bin to your PATH environment variable (related help)
Download https://phar.phpunit.de/phpunit-5.7.phar and save the file as C:\bin\phpunit.phar
Open a command line (e.g., press Windows+R » type cmd » ENTER)
Create a wrapping batch script (results in C:\bin\phpunit.cmd):
C:\Users\username> cd C:\bin
C:\bin> echo #php "%~dp0phpunit.phar" %* > phpunit.cmd
C:\bin> exit
Open a new command line and confirm that you can execute PHPUnit from any path:
C:\Users\username> phpunit --version
PHPUnit x.y.z by Sebastian Bergmann and contributors.
This method solves my problem. Hope It will save your day too.
I had the same issue. For me it happened after I deleted a class dir and forgot to update composer.json.
The fix was simply updating the classmap array in composer.json
I think it happens because composer cache error. Try to clear its cache:
composer clearcache
then run the installer again
composer create-project --prefer-dist laravel/laravel blog
It generally happens when composer is unable to autoload classmap. Check whether the location to the file or folder is correct.
This happens due to your composer.lock file.
For instance in my case I was getting:
Could not scan for classes inside ".../vendor/drupal/core-composer-scaffold/PEAR/" which does not appear to be a file nor a folder
That directory indeed did not exist. However, search for 'PEAR' inside of your composer.lock... 'app/commands' in this case- and you will find the modules definition:
{
"name": "drupal/core-composer-scaffold",
"version": "8.9.11",
"source": {
"type": "git",
"url": "https://github.com/drupal/core-composer-scaffold.git",
"reference": "c902d07cb49ef73777e2b33a39e54c2861a8c81d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/drupal/core-composer-scaffold/zipball/c902d07cb49ef73777e2b33a39e54c2861a8c81d",
"reference": "c902d07cb49ef73777e2b33a39e54c2861a8c81d",
"shasum": ""
},
"require": {
"php": ">=4.4.0"
},
"require-dev": {
"phpunit/phpunit": "*"
},
"type": "class",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"classmap": [
"PEAR/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"."
],
"license": [
"BSD-2-Clause"
],
"authors": [
{
"name": "Helgi Thormar",
"email": "dufuz#php.net"
},
{
"name": "Greg Beaver",
"email": "cellog#php.net"
}
],
"description": "The PEAR Exception base class.",
"homepage": "https://github.com/pear/PEAR_Exception",
"keywords": [
"exception"
],
"time": "2019-12-10T10:24:42+00:00"
},
Our important piece is:
"autoload": {
"classmap": [
"PEAR/"
]
},
Composer is attempting to autoload from that directory, which is why you get a composer crash- that directory doesn't exist. Likely the same thing in your case of 'app/commands'.
Remove the entire package from your composer.lock- which for clarity is the longer code posting above. Then rerun your 'composer require' for that package. Example: composer require drupal/core-composer-scaffold.
In my case I needed a specific version, the default would give me version 9, I needed 8. My command was composer require drupal/core-composer-scaffold:^8.
Once this is done your composer install will run without a hitch.
Here is another debugging idea:
I accidentally added the vendor/ folder to my repository which then got deployed.
After removing it from the repository, the error message
composer RuntimeException Could not scan for classes inside polyfill-php80/Resources/stubs which does not appear to be a file nor a folder
disappeared.
in most of cases it is happen because of copy or cloning so try to remove or rename VENDOR folder from the magento installation and rerun "composer install".
In my case, I was installing wordpress plugins by composer, especially yoast (wordpress-seo) and woocommerce from packagist.org. I changed the sources to wpackagist and it started to work ok:
"require": {
"wpackagist-plugin/wordpress-seo": "dev-trunk",
"wpackagist-plugin/woocommerce": "dev-trunk"
}
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
i install composer for windows using this link http://getcomposer.org/download/ > http://getcomposer.org/Composer-Setup.exe
my web server is WAMP php 5.4 with openssl enabled.
i created composer.json with this code
{
"require": {
"doctrine/orm": "*"
}
}
and run with this code in .php file
<?php
// bootstrap.php
// Include Composer Autoload (relative to project root).
require_once "vendor/autoload.php";
and i got error Warning: require_once(vendor/autoload.php): failed to open stream
how to get composer's autoload.php?
why composer does not generate it?
how to use doctrine without composer?
Did you actually look to see if a vendor/autoload.php was created?
Did composer throw any error messages? Unless you got an error then I'm willing to bet that a vendor/autoload files was made. Is there anything in vendor?
I'm guessing that your bootstrap.php is not in your root directory (same directory as composer.json). If so you need to adjust the path in your require statement.
Remove the autoload part from your composer.json, then run composer install
This will generate an updated autoload object, good luck!
"autoload": {
"classmap": [
"..."
]
}
I've set up two projects, an 'init' and a library, which is required by the init. They both have PSR-0 autoloads set, but the autoload values from the library are not added to the vendor/composer/autoload_namespaces.php in the init project.
Sample composer.json from the Library:
{
"name": "lxp/library",
"description": "A test library",
"autoload": {
"psr-0": {
"LXP\\Library": "src/"
}
}
}
Sample composer.json from the project that requires that library:
{
"name": "lxp/init",
"name": "A test init",
"autoload": {
"psr-0": {
"LXP\\Init": "src/"
}
},
"repositories": [
{
"type": "composer",
"url": "http://satis.repo.redacted/"
}
],
"require": {
"lxp/library": "dev-master"
}
}
The library contains the class LXP\Library\Something in the file src/LXP/Library/Something.php.
The project that requires the library contains the class LXP\Init\Now in the file src/LXP/Init/Now.php.
When running composer install in the 'init' project, it downloads the library project and puts it in vendor correctly, but vendor/composer/autoload_namespaces.php doesn't contain the library's autoload information, only that of the current project.
What am I doing wrong? If I run dump-autoload in the library project then the autoload_namespaces.php file is correct, and a quick bootstrap script confirms that it does indeed pick up the class.
EDIT - This is a problem with the satis-generated packages.json. To fix it, I had to add the autoload information from the library's composer.json into the json file I supply to satis, which seems like an unnecessary duplication and so I'm probably doing it wrong. Is there a single place that autoload information can be stored for satis libraries? For example, can satis read the composer.json files that exist in the libraries it scans?
EDIT #2 - Satis does not read the composer.jsons from repositories specified as 'package' type. This is obvious in hindsight, because 'package' is used for libraries that do not have a composer.json, and is a way to wrap composer-like dependency management around them.
Changing the satis.json's repository to 'vcs' type meant that the composer.json was read, and the information (including the autoload specification) was parsed and stored in the packages.json.
#Seldaek - thank you for suggesting that my satis config was the problem, and I hope that this clarifies satis / composer behaviour for anyone else in my position.
I see two possible mistakes you may have done that would cause this:
You forgot to update your satis repo so the autoload config for lxp/init is not up to date in there
You are running composer install from a lock file, and that means composer just reads the info from the composer.lock file and does not update package metadata to the latest version available in satis. To solve this you should run composer update instead.
Try composer dump-autoload command.
It depends how you installing your library via Composer. For example, when downloading it as package type (same I believe with composer type), Composer never reads the composer.json file, so instead you should use vcs or git type. See: GH-6846.
Here is composer.json which should work:
{
"require": {
"lxp/library": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "http://satis.repo.redacted/"
}
]
}
Then run: composer install.
For troubleshooting, try running:
composer dump-autoload -o -vvv.
composer diagnose -vvv