I've new to composer and I searched a few hours on the internet to find a solution for my problem, I've found one but can't get it to work so it's probably me.
I'm starting a new project with zend framework 1.12.3 and some extra vendors like doctrine. I don't mind that doctrine, phpunit, ... are installed in the default /vendor (or if I set another) but I rather have Zend on library/Zend instead of vendor/zendframework/....
I'm new to composer so I could've missed something.
Original:
{
"name": "Awesome",
"require": {
"zendframework/zendframework1": "1.12.3",
"doctrine/orm": "2.3.4",
"doctrine/dbal": "2.3.4"
},
"require-dev": {
"phpunit/phpunit": "3.7.21",
"mockery/mockery": "dev-master#dev"
}
}
I also tried it with https://github.com/composer/installers
{
"name": "Awesome",
"require": {
"composer/installers": "~1.0"
"zendframework/zendframework1": "1.12.3",
"doctrine/orm": "2.3.4",
"doctrine/dbal": "2.3.4"
},
"require-dev": {
"phpunit/phpunit": "3.7.21",
"mockery/mockery": "dev-master#dev"
},
"extra": {
"installer-paths": {
"library/Zend": ["zendframework/zendframework1"]
}
}
}
If it's a too big hastle to do it I can install zend locally so that's not a problem but it would be nice to do it with composer at once.
As explained in the comments, its not possible to install different packages in different(custom) locations.
the installer-paths does not work, as the zend package is not of a supported type (I think this works only for wordpress packages)
For your problem this is not a real problem. Zend Server sure does nothing special, only because the libraries are placed in this specific place. Also they had enough time to fix things for composer, if they really had some.
But, even if its not a solution for placing the Zend framework in this specific place, its possible to have multiple composer.json in different directories. You only need to add both autoload.php files. Thats no problem, as composer supports autoloading for multiple usage as this.
Related
I'm trying to figure out how to let my users upload files in my Google App Engine app. I'm following the instructions here: https://cloud.google.com/appengine/docs/standard/php/googlestorage/user_upload
It starts with:
use google\appengine\api\cloud_storage\CloudStorageTools;
However, that package doesn't exist in any of the vendor directories I've got and I can't figure out what I need to add to my composer.json in order to get this code.
I've got code in other places in my project that will use Google\Cloud\Storage\StorageClient; but that is a different code base and it doesn't contain the CloudStorageTools::createUploadUrl() function which is what I'm trying to get access to.
Here is what my composer.json contains:
{
"require": {
"mailgun/mailgun-php": "^2.6",
"php-http/guzzle6-adapter": "^1.1",
"php-http/message": "^1.6",
"google/cloud-storage": "^1.9",
"google/cloud-debugger": "^0.14.2",
"ext-stackdriver_debugger": "*"
},
"name": "",
"description": ""
}
You need to add google/appengine-php-sdk to your composer.json.
composer require google/appengine-php-sdk
I updated my composer.json file to include dbunit:
"require-dev": {
"phpunit/phpunit": "^7",
"phpunit/dbunit": "^1"
},
I ran composer and it updated my installation to include dbunit (I already had PHPUnit).
But when I tried to add the TestCaseTrait namespace to my test the IDE claims it can't find that namespace.
use PHPUnit\Framework\TestCase; <----- this works great
use PHPUnit\DbUnit\TestCaseTrait; <----- error that namespace doesn't exist
Am I missing a step?
I was able to reproduce your problem with this in my composer.json:
"phpunit/dbunit": "^1"
By increasing the version to ^4, the namespace is no longer unfindable. Keep this in mind, if you didn't already know about the composer json schema:
The caret will update you to the most recent major version (the first number).
^1.2.3 will match any 1.x.x release including 1.3.0, but will hold off on 2.0.0.
Here's the working composer.json I used:
{
"require-dev": {
"phpunit/phpunit": "^7",
"phpunit/dbunit": "^4"
}
}
I downloaded the Text-Statistics ZIP master from Github and extracted and renamed the folder to stats on /Library/WebServer/Documents/stats. Then I used cd /Library/WebServer/Documents/stats and composer update and all dependencies built on /Library/WebServer/Documents/stats as well. When I go to http://localhost/stats/ in my browser, it shows as follows:
This is my first time to install a project on my localhost directory which uses composer. Shall I create an index.php to see how the codes work? Below you can also see the composer.json file:
{
"name": "textstatistics",
"description": "PHP package to measure the readability of text according to various algorithms.",
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "4.2.*"
},
"autoload": {
"psr-0" : {
"DaveChild\\TextStatistics" : "src"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"suggest": {
"ext-bcmath": "More accurate floating point calculations.",
"ext-mbstring": "Handle multi-byte text properly."
}
}
The package you 'installed' is a toolbox and meant to be used inside your project. It has no index.php since that would be useless, what would it have to show?
You should add it to an existing project by running composer require davechild/textstatistics from your project's root directory.
Composer exists so you do not have to download the package, and it's dependencies, yourself (like you did with the zip). It will also generate your autoload file so you do not have to bother about requiring or loading those classes. And it is especially useful when you want to update your dependencies (just run composer update)
This is completely unrelated to github or composer. It looks like this project is not a web application, because I don't see a bootstrap file (something like index.php). This means there is nothing which makes sense to call from a webserver context.
I took a short look at the projects github page. PHP Text Statistics is a library that will be used in other projects, but it's not a standalone tool, or application.
I am using the Fuel PHP SDK for Marketing Cloud and there are some changes I'd like to make. Since I am also using Heroku, the repository is refreshed on every git push I make.
I need to modify a few files, but since the repo is refreshed on every push, my changes will get overwritten. Is there a way to copy these files into my own repo, declare that as a dependency after the other repo, and override the files in the main repo with my updated files?
For example, the file I want to update is named ET_Get.php. I could update it directly, but then it will be overwritten on every push. I want to duplicate that file out, make some changes, and I want the repo to use that file, not the repo's own file.
My composer.json looks like this
{
"require": {
"salesforce-mc/fuel-sdk-php": "1.3.0",
"guzzlehttp/guzzle": "~6.0",
"ext-soap": "*",
"php": "7.1.28",
"ext-mcrypt": "*",
"twig/twig": "^2.0",
"firebase/php-jwt":">=5.0.0"
},
"autoload": {
"psr-4": {
"FuelSdk\\": "custom-classes",
"Pardot\\": "custom-classes"
}
}
}
So I was thinking I could just create my own repo after the salesforce-mc repo, and have my files override those.
{
"require": {
"salesforce-mc/fuel-sdk-php": "1.3.0",
"salesforce-mc/custom": "1.0",
"guzzlehttp/guzzle": "~6.0",
"ext-soap": "*",
"php": "7.1.28",
"ext-mcrypt": "*",
"twig/twig": "^2.0",
"firebase/php-jwt":">=5.0.0"
},
"autoload": {
"psr-4": {
"FuelSdk\\": "custom-classes",
"Pardot\\": "custom-classes"
}
}
}
Is this possible? It doesn't have to be a separate repo. Any way that I can simply have my own overrides would be fine.
I know I could fork the repo, and use my fork as a dependency, but that seems like overkill...
You can make the call server side using a library such as cURL
Which will work fine if it's an API that responds with some json or xml.
If their page renders something like a html thank you page, you would have to parse that to ensure it worked and then render your own.
If that's the case and you are making a GET call to ExactTargets site, then you could probably just do a header redirect.
If you do have to POST data, then you could also render a new form that is just a "Submit" button, that contains all the data in hidden fields. It would basically be the same as if you submitted to them to begin with.
Hope that helps
This turned out to be exactly what I needed.
https://mnapoli.fr/overriding-dependencies-with-composer/
Use forked repo on github via composer as dependency
All I had to do was fork the original repo, make my changes, then use my repo in the composer.json like below:
{
"require": {
"salesforce-mc/fuel-sdk-php": "1.3.0",
"guzzlehttp/guzzle": "~6.0",
"ext-soap": "*",
"php": "7.1.28",
"ext-mcrypt": "*",
"twig/twig": "^2.0",
"firebase/php-jwt":">=5.0.0"
},
"repositories":[
{
"type":"git",
"url": "https://github.com/user/forked-project.git"
}
],
"autoload": {
"psr-4": {
"FuelSdk\\": "custom-classes",
"Pardot\\": "custom-classes"
}
}
}
My profesionnal network block internet access. Some month ago I download the Silex framework from an archive (which contains composer.json file) and the composer.phar one's, then I transfer them on my desktop throught HDD.
My composer.json that I customized:
{
"name": "user/silex",
"require": {
"silex/silex": "1.2"
, "twig/twig": ">=1.8,<2.0-dev"
, "doctrine/dbal": "2.2.*"
, "symfony/security": "~2.3"
, "symfony/security": "~2.3"
},
"autoload": {
"psr-4": {
"Portal\\": "src/"
}
}
}
It works fine, my autoload customization too.
Today I want to add the monolog/monolog package, so I manually import it from an other computer.
I place it into my vendor folder, I add the following line to my composer.json file:
, "monolog/monolog": ">=1.0.0"
I run on the console:
php composer.phar dumpautoload
It outputs:
Generating autoload files
Then it stop without error, but the monolog namespace doesn't appear into my /vendor/composer/autoload_*.php files.
What did I miss?
Thanks to edmondscommerce's comment I found the solution:
I update my main composer.json file with an artifact respository (and I disable the packagist one):
{
"name": "user/silex",
"repositories": [
{
"type": "artifact",
"url": "artifact/"
}, {
"packagist": false
}
], "require": {
"silex/silex": "1.2"
, "twig/twig": ">=1.8,<2.0-dev"
, "monolog/monolog": "1.*"
, "doctrine/dbal": "2.2.*"
, "symfony/security": "~2.3"
},
"autoload": {
"psr-4": {
"Portal\\": "src/"
}
}
}
Then I put a folder called artifact according to the url put in the composer.json file.
I create into this folder a zip called monolog-monolog-1.8.zip with the library I want to add.
Then just launch a composer update command!
Be carefull, zip's root must contain a composer.json file, and this composer.json file must contain a version!
If you do not want to create a custom repository, you can also run composer install (or composer update) on a copy that is on a network-connected computer. Then you can copy over the newly added and extracted component into the vendor folder on the machine without internet access. Note that you also need to copy vendor/composer/installed.json to let composer know that the new package has been installed. Once you have copied all these files, you can run composer install on the machine without internet access and it will not try to install anything and dump autoload files.