I juste want to have the possibility to use the class of this library but after 2 hours impossible :
So how to use the Zend Framework 2.1 with his autoloader to just use class of this library and not create a ZF project?
I have try everything with the classmap_generator, inlude_path... i haven't any error but it still return me :
Could not find action class? Could not find version class!
Thanks you.
You can install individual Zend Framework modules via composer, which will take care of most of this for you:
composer.json
{
"require": {
"zendframework/zend-http": "2.*"
},
"repositories": [
{
"type": "composer",
"url": "http://packages.zendframework.com/"
}
],
"minimum-stability": "dev"
}
this should take care of any autlloading for you. Composer would generate an autoloader which you would just include in your app:
require 'vendor/autoload.php';
there's a load of composer examples out there:
https://packages.zendframework.com/#composer
http://net.tutsplus.com/tutorials/php/easy-package-management-with-composer/
Since ZF2 components are decoupled and focused on a specific task, one class often uses another to do its business. Simply including a single class file is usually not sufficient.
As a result, ZF2 definitely requires some autoloading. But you don't have to use the ZF2 autoloader.
If you have no autoloading already in place in your app, then it's actually pretty easy to add:
Make sure the path to the Zend library is on your include_path.
Register a standard PSR-0-compliant autoloader using spl_autoload_register()
Something like:
spl_autoload_register(function($class)){
$file = str_replace('\\', '/', $class) . '.php';
$resolvedFile = stream_resolve_include_path($file);
if (file_exists($resolvedFile)) {
include $resolvedFile;
return $class;
}
});
If you already have an autoloader for your application, then I'd be quite surprised if it was not PSR-0-compliant. As before, make sure that the Zend library is on the include_path.
Even if the Zend library is not on your include path, you can create a custom autoloader that is aware of where in your filesystem the library is based.
In all cases, usage of the desired class is then:
$myinstance = new \Zend\Component\Class();
With the correct autoloading in place - however you choose to go about it - this class can use any other Zend classes that it needs to go about its business.
After many search, i have install composer. But i'm not very happy of this solution cause it touch my system.
Here is my procedure, i still say that ZF documentation is very poor.
Install ZEND FRAMEWORK WITH COMPOSER
1) Allow whitelist
suhosin.executor.include.whitelist = phar
In file : nano /etc/php5/cli/conf.d/suhosin.ini
2) Download of composer
Apt-get install curl
curl -sS https://getcomposer.org/installer | php
3) Move composer
mv composer.phar /usr/local/bin/composer
4) Copy the composer.json
Copy composer.json (From zend framework archive) a my root folder application
5) Composer install
Execute where the composer.json is
Now you will have a folder named "vendor" in your app folder, to use in your php code :
include("vendor/autoload.php");
new Zend\Mail\Storage\Pop3(...);
And now it work for me.
Bug allowed memory size :
php -r "echo ini_get('memory_limit').PHP_EOL;"
change to 1024M
nano /etc/php5/cli/php.ini
/etc/init.d/apache2 restart
Failed to clone http://github.com/zendframework/Component_ZendStdlib.git, git was not found,
Install GIT
Apt-get install git
Just register the namespace in your autoloader.
if you are using composer then add include_once '<path to vendor dir>/autoload.php'; on top of your php file
Related
I am looking to implement the framework amphp/thread, with Symfony3, which I ve read about in this article (https://www.mullie.eu/parallel-processing-multi-tasking-php/).
I'd looked at the setting process on the git page: https://github.com/amphp/thread.
I've followed the checklist:
PHP5.5+ = OK Php 5.5.12
pecl/pthread = OK I did install it as explained on Windows8
Now, 3rd task on the checklist, I have the installation of the framework itself (amphp/thread) left to do.
I am a bit confuse, because it is not an "official" Symfony bundle. So I don't think I can put it under [my_symfony_project]/vendor/ and refer to it in the file [my_symfony_project]/app/AppKernel.php. So how do one do in this case:
Do one put the directory of the library under the root directory [my_symfony_project]?
And afterwards, how can one refer to it in the Symphony class/file, should I write: "use amphp/thread" between the namespace declaration of my Symfony file and the class code itself?
You can simply install the library with composer, as example launching this command from the root of your project:
>php composer.phar require amphp/thread
And use it in your code directly: the composer process generate the correct autoloader for you. No necessary add to the list of the Symfony2 bundle (is not a bundle).
Hope this help
You will need to install the package by adding the following to your composer.json file:
"require": {
"amphp/thread": "0.8.1"
}
Then run "composer install" on your server.
I'm new to Composer and in my current project I would like to install a bunch of PHP libraries like:
Doctrine
Security Library (Which i have no idea but looking for in CodeIgniter)
Bootstrap layout libraries and other when necessary
For that matter , I would like to use Composer based library management in my application,
and i get confused that if i have to include composer.phar on my project directory or not.
since i have it on my environment path and I can run Composer form command line .
How can integrate the above libraries into my codeigniter application then..
Appreciate your toughs!
The composer.phar file is an executable and it should not be committed. What it actually does is that it looks in your composer.json file and there you can declare some more dependencies (libraries for example) and their version:
{
"require": {
"doctrine/orm": "*"
}
}
The version in this case is declared with "*" so Composer will get the latest version. This is very useful if there are more people on the project, to make sure all of them have the same version of dependencies installed (so the composer.json file must be committed).
If you run "composer.phar update" on the other hand, this will get the latest version of all dependencies, no matter the version placed in composer.json and updates the lock file with the new versions.
First of all, I had already installed and configured zend framework 2 in include_path of php.ini. But when I was installed zend framework skeleton application using composer install then it do some process and then again download whole zend framework 2 in to 'vendor' directory (which is automatically created in my application directory).
Please help me that why composer again download and install whole framework and why it do not use already installed copy?
The short answer is that composer is designed to install dependencies on a per application level rather than globally. So all dependencies specified in the composer.json file will be pulled in to your project's vendor folder. This will happen even if you happen to have a certain dependency installed globally on your system.
Composer does not look at your environment - it looks at the dependancies that have been specified by the packages.
However, you can control how these dependancies are satisfied.
As a result you will need a method to demonstrate to composer that the dependancies are being met.
For example - if you install Zend using PEAR - you can tell Composer to look for the pear package rather than downloading it.
e.g.
{
"repositories": [
{
"type": "pear",
"url": "http://pear2.php.net"
}
],
"require": {
"zend/zend": "*",
}
}
I want to use Slim for PHP in my project for the first time.
The manual says:
Install composer in your project:
curl -s https://getcomposer.org/installer | php
Create a composer.json file in your project root:
{
"require": {
"slim/slim": "2.*"
}
}
Install via composer:
php composer.phar install
Add this line to your application’s index.php file:
<?php
require 'vendor/autoload.php';
I'm afraid, I don't get it. Where should the commands "curl" and "php" be used? I only access my webspace through Filezilla. How can I then apply such a command?
What do those steps do anyway? Sadly, the manual is not helpful at all.
See http://www.slimframework.com/install:
MANUAL INSTALL
Download and extract the Slim Framwork into your project directory and require it in your application’s index.php file. You’ll also need to register Slim’s autoloader.
<?php
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
And there are links to zip-files.
If you're getting started on slim i'd definitely suggest that you get a good IDE that will guide you through the whole process. When I started the slim framework, I came across an IDE by jetbrains called PHPStorm. It makes everything so easy by doing most of the stuff you listed for you...
download and install PHPStorm https://www.jetbrains.com/phpstorm/download/
download and install Composer https://getcomposer.org/download/ so PHPStorm can use it.
get to the part where you start PHPStorm.
go to File > new Project > Composer Project and follow the motions.
It'll create all the files you listed. Then all you have to do is look and learn what it all means.
Composer is basically a package manager, you basically open a cmd and navigate to the place you want to create you PHP Slim application and type some composer commands to install package files in that folder. Composer then gets the packages and puts them in a directory called 'vendor' in that project folder of yours.
{
"require": {
"slim/slim": "2.*"
}
}
that's basically a config file that either you or composer will create in the same file also.
I see there is already a question but it did not answer the question
How can I install a composer package into the /src dir?
How can I install a bundle in the /src directory?
Reason I would like to do this is for development and deployment, so
I don't have to check in Symfony's base code into my subversion repo
I could use Composer to deploy
Looking over the Composer docs some more I did come across this:
http://getcomposer.org/doc/04-schema.md#config
vendor-dir: Defaults to vendor. You can install dependencies into a
different directory if you want to.
Could I set this at a Bundle level? or is this for the overall install?
https://github.com/composer/composer/blob/master/res/composer-schema.json
I know this is late, but in case anyone is searching for an answer that I painstakingly (hours and hours) found: vendor-dir
The documentation says:
By setting this var you can make composer install the dependencies into a directory other than vendor
Example:
{
"config": {
"vendor-dir": "website/password/vendor/"
}
}
From this doc and this doc
Again, hope to save anyone else a couple hours.
{
"extra": {
"installer-paths": {
"sites/example.com/modules/{$name}": ["vendor/package"]
}
}
}
Read more.
If you find composer's custom installers too complex or rigid, and you can plan what types of systems you will be deploying to, you might consider using post-install scripts.
Here's an example that creates a symlink from a package installed under vendors to the location where it might be expected:
"scripts": {
"post-install-cmd": [
"test -d vendor/foo/bar && ln -s ../vendor/foo/bar lib/bar"
]
}
This will create a symlink at lib/bar/ pointing to vendor/foo/bar/.
I have implemented this composer plugin to install packages into user (custom) defined folders you can just include it in your composer.json, follow the example and tell me if you have more questions :)
https://github.com/mnsami/composer-custom-directory-installer
composer-custom-directory-installer
A composer plugin, to install differenty types of composer packages in custom directories outside the default composer default installation path which is in the vendor folder.
This is not another composer-installer library for supporting non-composer package types i.e. application .. etc. This is only to add the flexability of installing composer packages outside the vendor folder. This package only supports composer package types,
https://getcomposer.org/doc/04-schema.md#type
The type of the package. It defaults to library.
Package types are used for custom installation logic. If you have a package that needs some special logic, you can define a custom type. This could be a symfony-bundle, a wordpress-plugin or a typo3-module. These types will all be specific to certain projects, and they will need to provide an installer capable of installing packages of that type.
How to use
Include the composer plugin into your composer.json require section::
"require":{
"php": ">=5.3",
"mnsami/composer-custom-directory-installer": "1.1.*",
"monolog/monolog": "*"
}
In the extra section define the custom directory you want to the package to be installed in::
"extra":{
"installer-paths":{
"./monolog/": ["monolog/monolog"]
}
by adding the installer-paths part, you are telling composer to install the monolog package inside the monolog folder in your root directory.
As an added new feature, we have added more flexibility in defining your download directory same like the composer/installers, in other words you can use variables like {$vendor} and {$name} in your installer-path section:
"extra": {
"installer-paths": {
"./customlibs/{$vendor}/db/{$name}": ["doctrine/orm"]
}
}
the above will manage to install the doctrine/orm package in the root folder of your project, under customlibs.
Note
Composer type: project is not supported in this installer, as packages with type project only make sense to be used with application shells like symfony/framework-standard-edition, to be required by another package.