Zend Framework and Doctrine installation using composer - php

I came here because I had some issue around the Doctrine ORM install.
I successfully installed the Zend Framework (followed by these steps) and it's works itself on my local machine.
Then I tried to install the Doctrine, (followed by these steps) , but it's doesn't work.
When I solve that problem above, I always got an another one. I tried to check every related question in this site so far (like this one) , but it's still doesn't work.
In my .json file has "minimum-stability": "dev", and I tried either ZF minimal install or advanced one (with more packages).
Here is my .json file:
I have no modification here, when I try to use the require doctrine/doctrine-orm-module:dev-master I've got an error. Also when I typed directly into the .json file, and tried to composer update it.
Every answer will be appreciated!

Related

How can I deploy static web app on Heroku

I followed instructions from an answer of a similar topic(https://stackoverflow.com/a/17531897/4388482). Well, my app is getting deployed on Heroku but it doesn't work good. I'm getting the following warning
Your project only contains an 'index.php', no 'composer.json'.
Using 'index.php' to declare app type as PHP is deprecated and may lead to unexpected behavior.
Do I need to install something maybe?
UPDATE
Project structure was initially this:
I did the following:
Installed PHP 5 and composer.
I renamed package.json to composer.json and removed package-lock.json.
Typed "composer update" command. I got "nothing to install or update" message.
Added vendor to gitignore. Pushed changes to heroku.
I got the following warnings
Your 'composer.lock' is out of date!
Composer vendor dir found in project!
The complaint that Heroku has is regarding this folder.
For the record, the contents of this folder presently are:
bootstrap
fontawesome-free
jquery-easing
jquery
What has happened here is that someone has committed dependencies to your version control, which is not good practice. It will work as is, but it is not very easy to do upgrades, especially since you cannot easily see what versions you currently do have.
There are three ways to go about this.
Decide if these are PHP dependencies, by searching Packagist. There is a Composer dependency for Bootstrap, but you would need to see if the version you are using is available (or whether you can upgrade to one that is available).
Decide if these are JavaScript dependencies, by searching NPM. I wonder if it is worth examining the contents of your package.json in case these are already covered. For what it is worth, I would generally consider these candidates for JavaScript libraries rather than PHP, but do what works for you.
Choose to leave these dependencies committed in the existing vendor folder. It will work, but it is not ideal for the reasons already stated.
In the last two cases, you could probably get away with a composer.json file thus, which you should commit to the repo:
{
"require": {
}
}
You could try a composer install after this, to see if it will generate a .lock file on an empty dependency list. If this does generate, then you should commit this also.

How to update CakePHP?

I have to update CakePHP from current, outdated version (2.7.7) to latest on 2 branch, because of PHP7 support.
While I've done numerous framework upgrades before, I found book.cakephp.org a more than a cryptic about key things which I ask here:
can it be done by replacing directoris
which directories are intended to be replaced (never edit dirs, like system in Codeigniter)
which directories are partially replaced if any
is there SQL commands that should be run?
is there other commands that should be run?
Any clue is appreciated, but 2 and 3 are of most value I guess. Thanks in advance.
Depending on how you've installed CakePHP, you either use composer to update the CakePHP core dependency:
$ composer update
or require a specific constraint/version if your current constraint doesn't allow upgrading:
$ composer require cakephp/cakephp:^2.10.3
If you're not using composer (I'd suggest to switch to using it), then you download the latest release package manually, and completely replace the /lib/Cake directory. With respect to the core, the upgrade is then complete.
Then read the migration guides to figure the possible changes that you have to apply to your application code or database schemas, and also compare the "application template" changes (/app/) to your local application and apply changes in case necessary. After this, run your test suite to ensure that everything works as expected.
With that being said, the upgrade from 2.7 to the latest 2.10 should be pretty easy, as it is said to be fully API compatible.
I recommend you to use composer to manage your framework and extensions.
With composer installed, it would be much easier to update. If you decide to use composer, let me know if you need any more help by installation, setup or update.

Laravel 5.2: Class "Illuminate\Html\HtmlServiceProvider" not found during composer installation

So I've been trying to install the LaravelCollective/Html package via composer update (already added "laravelcollective/html": "5.2.*" to the project composer.json file), but I keep getting this...
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Illuminate\Html\HtmlServiceProvider' not found
Script php artisan optimize handling the post-update-cmd event returned with error code 1
It seems I need to update app.php, but only after the install I can't get out of.
Thanks in advance.
(Oh and I'm using Windows, if that's of any importance. And yes, I did look for answers, but most were either relative to people having trouble after install or wrongly assuming they were)
So, I ended up finding the answer myself. I really dislike when I ask for help and end up not needing any, but this answer might be useful for others thinking the same way as I did.
Some answers I looked for said something about using composer dump-autoload after installation. I didn't try this step because I was fixated on the installation failing, and assumed it only worked if the install itself did. But then I decided to go with it, then retried composer update and nothing happened (maybe a sign there was nothing broken to fix). Then I edited the config/app.php file as explained on the docs and, surprisingly, it started working. I still might need to test it a little, but for now it seems nothing's broken.

Using Composer for CakePHP and dependencies: overall strategy, project structure and `.gitignore`

I would like my CakePHP project to use best practices. Currently we have our PHP dependencies checked into our project's repo, and i don't like that.
I want the project to leverage Composer, but i don't understand the proper strategy.
First, there is the official CakePHP repo:
composer.json is in the project root.
There are /vendors/ and /plugins/ and they are under .gitignore.
/app/Vendor/ and /app/Plugin/ are not ignored.
Then, there's an app-template boilerplate from FriendsOfCake:
composer.json is in the project root.
There are no /vendors/ or /plugins/.
/app/Vendor/ and /app/Plugin/ are under .gitignore.
Lastly, there's cakephp-composer, an active project. It implies that:
composer.json is in /app/.
The plugin itself is supposed to be installed by hand into /app/Plugin/.
Readme does not explain .gitignore strategy, but plugin author says that /app/Vendor/ and /app/Plugin/ should be ignored.
cakephp-composer is the weirdest thing. How am i supposed to fetch CakePHP and cakephp-composer after cloning my project?
I want to achieve the following:
My project repo contains only source code of the project itself. Any code that is versioned somewhere else, e. g. CakePHP framework and CakePHP plugins, should not appear in my repo.
After cloning my project's repo to a new location, i want to fetch all PHP dependencies, including CakePHP and its plugins, with a single Composer command. No manual downloading/cloning. The project should start working right after Composer finishes its job.
I really like the app-template boilerplate from FriendsOfCake. It looks simple and reasonable to me. So i wish my project structure were as close to app-template as possible.
I don't understand and request explanations for the following things:
Where is the folder for Composer to fetch dependencies into configured? Composer docs mention "PSR-4" and i (being a frontend dev coming from the Ruby world) don't have a slightest idea what that is.
What folders should be put under .gitignore?
Do i really need cakephp-composer? I hope that i don't!
How do i configure composer.json to fetch plugins with Composer, especially if i don't use cakephp-composer? It might be as simple as just mentioning package names under require, but how do i tell Composer whether plugins should go under app/Vendor/ and app/Plugin/? Oh, and where should they go?
How do i properly include CakePHP and CakePHP plugins fetched by Composer into my project?
For an example CakePHP plugin to be fetched by Composer, take haml. It's what i need for my frontend work and it has its own Composer dependency.
OK, there's several questions there... I'll try to answer a few.
First and foremost, you should be clear on wether you want to use CakePHP 2.X, or CakePHP 3.0. I assume since you're talking about an existing project, you mean Cake 2.X - which wasn't built with composer in mind. Cake 3.0 was built with composer in mind, so if upgrading to that is an option, I assume it'll be nicer (I haven't used 3.0 yet myself)
Here's a simplified example composer.json file from one of my projects:
{
"name": "my-project",
"require": {
"cakedc/migrations": "2.2.2",
"cakephp/debug_kit": "2.2.1",
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
"config": {
"vendor-dir": "app/Vendor/"
},
"extra": {
"installer-paths": {
"app/Plugin/Migrations": ["cakedc/migrations"],
"app/Plugin/DebugKit": ["cakephp/debug_kit"],
}
}
}
see the line "vendor-dir": "app/Vendor/" - that's where I've configured composer to put it's packages, by default, in my app/Vendor/ folder.
What goes in .gitignore... we'll come back to that.
No, you don't need this.
See the line "installer-paths": {? That's where I've configured composer to put specific CakePHP plugins in Cake's plugins dir, as opposed to the default app/Vendor/ which I mentioned in 1.
For CakePHP Plugins - see 4. For CakePHP itself, I haven't personally done it. I did try at one point and found the setup to be not playing nicely with one of my plugins, so I gave up on it. However, you should be able to use the same principals as above.
Now, coming back to 2. what should be in your .gitignore? Anything that has contents completely maintained by composer - in my case, that's app/Vendor/, and app/Plugin/. That assumes that ALL the contents of those folders is maintained by composer. If you had eg. one plugin that you'd added manually, then you couldn't ignore the whole folder - you'd have to ignore only the specific plugins installed with composer.
PS - I personally delete the root vendor/ and plugins/ folders - I don't use them at all.

How do I successfully create a project with Zend Framework and PHPUnit?

Let me just start by saying that I've posted this to multiple forums and even tried to get help on the ZF IRC channel. I've been Googling for a straight week and still no results. I've read a lot of Q's and A's on this site in the past, so I figured I'd make an account and try asking you.
(Yes, I've searched previously asked questions, but none of the answers helped me.)
I'm trying to learn how to use Zend Framework for a new project that I've joined. For compatibility reasons they are using Zend 1 (and not the newer Zend 2). I have found and followed a number of online and physical book tutorials but I've the same results over and over again.
So here goes (this are the instructions that all the tutorials give). I went to framework.zend.com and downloaded the full version of ZF 1.12.
I unzipped the contents
I moved the library folder to a safe directory where it won't be modified
I moved the contents of the bin folder to same directory as my PHP executable
I changed the include_path in my php.ini file to include the library directory
I updated my Windows PATH variable to make sure it included the path to the PHP executable
I ran
zf --help
This command worked as intended. I also successfully ran zf show version (Zend Framework Version 1.12.7).
I ran the command
zf create project myproject
Upon doing this, I receiving the following error message:
Fatal error: Class 'PHPUnit_Framework_TestCase' not found in D:\Zend\library\Zend\Test\PHPUnit\ControllerTestCase.php on line 48
That particular line in question is a class declaration that extends PHPUnit_Framework_TestCase. I don't know where PHPUnit_Framework_TestCase is defined. It is not in any of the files or directories that came in the single ZIP file that I downloaded from Zend. I even ran grep on all files and folders searching for the string "class PHPUnit_Framework_TestCase" but it printed no results.
Some have suggested that I don't have PHPUnit installed (which is obvious to me now). The part that bugs me is that absolutely none of the tutorials that I read mention anything about installing PHPUnit before hand or how to install it or what dependencies Zend has on it. Many of these were beginner tutorials that assumed you only had a basic knowledge of PHP, and it's pretty shocking to me that none even mentioned PHPUnit. If PHPUnit was that important I would think that the file I downloaded from Zend would have included it. I guess not.
So I went online again and got the PHAR file for PHPUnit, but now what? I tried putting it in multiple different directories but I still get the same error. Am I not supposed to use a PHAR file? Should I be using the actual files instead?
What do I have to do to get ZF to recognize PHPUnit, resolve this error and create my first ZF project?
Additional Info:
Windows 7, XAMPP Server (running on localhost), PHP 5.5.6
Assuming you have PHPUnit installed and it is on your include path (Bearing in mind that ZF1 only officially supports PHPUnit 3.4.x and definitely doesn't support anything above PHPUnit 3.5.x, so if you're using XAMPP you may have to downgrade PHPUnit as described here). The problem is most probably due to this commit, where the require calls for PHPUnit were stripped out in favour of using an autoloader. The ZF tool over CLI doesn't set up an autoloader though, so PHPUnit is not found because it is simply not required! To fix you can return these lines to the start of Zend/Test/PHPUnit/ControllerTestCase.php
/** #see PHPUnit_Runner_Version */
require_once 'PHPUnit/Runner/Version.php';
/**
* Depending on version, include the proper PHPUnit support
* #see PHPUnit_Autoload
*/
require_once (version_compare(PHPUnit_Runner_Version::id(), '3.5.0', '>=')) ? 'PHPUnit/Autoload.php' : 'PHPUnit/Framework.php';
It's worth noting that even with the error you mention, ZF tool should still work correctly when setting up a project, it just won't produce unit test actions (you'll have to make them yourself). If you don't want to downgrade your XAMPP PHPUnit version you should be able to add the correct version locally to your project using composer as described here.
Update Jan 2015:
Downgrading PHPUnit for XAMPP is no longer necessary as ZF1 has supported at least version 4.1 of PHPUnit since 1.12.7 (I've not tested above 4.1). This is helpful as PHPUnit has completely removed their deprecated Pear repository as of December 2014, which means you can't download versions older than 3.7 anymore anyway! (Currently XAMPP ships with PHPUnit 3.6). These days though it's probably worth chucking XAMPP for Vagrant and globally installing PHPUnit 4.1 via Composer during Vagrant provisioning.
I recommend using Composer to load both ZF and PHPUnit. Then make sure to include the Composer autoload.php file as your/in your phpunit boostrap file.
I had the same problem when I set up my laptop as a second development machine and downloaded the newest version of Zend Framework 1 (1.12.9). Whenever I tried to create a new action in a controller, I got the same error. Yet on my main computer, it worked fine.
I realized it was because the version of ZF1 I had in my php includes path was actually 1.11.11. So I went and got 1.11.14 from the ZF archives page, put it in the includes directory, and it worked fine.
Not entirely sure if this is the best way to make it work, since it is an older version, but at least it does work. And until someone actually comes on here and offers a better solution, that's what I intend to stick with.
You can create or edit a .zf.ini file in your home directory (~/.zf.ini or C:\Users\YOUR_ACCOUNT\.zf.ini on Windows)
php.include_path = "PATH_TO_THE_LIBRARY_FOLDERS_CONTAINING_ZEND_AND_PHPUnit"
basicloader.classes.0 = "PHPUnit_Framework_SelfDescribing"
basicloader.classes.1 = "PHPUnit_Framework_Test"
basicloader.classes.2 = "PHPUnit_Framework_Assert"
basicloader.classes.3 = "PHPUnit_Framework_TestCase"
If you are using Netbeans on Windows it could looks like this (you can put several library folder, just separate them with a semicolon ;) :
php.include_path = "C:\Users\romain\dev\ZendFramework-1.12.17\library;C:\Program Files\NetBeans 8.1\php\zend;C:\xampp\php\pear"
basicloader.classes.0 = "NetBeansCommandsProvider"
basicloader.classes.1 = "PHPUnit_Framework_SelfDescribing"
basicloader.classes.2 = "PHPUnit_Framework_Test"
basicloader.classes.3 = "PHPUnit_Framework_Assert"
basicloader.classes.4 = "PHPUnit_Framework_TestCase"

Categories