I am using composer for dependency-management in a new Php-Project.
I plan to just use the autoload.php of composer to include/require the external libraries.
My problem is, that VsCode isn't able to recognize which files would get included via the autoload, and so it doesn't provide me with any intellisense/code-completion-features related to the libraries.
Does anybody have a solution/workaround for this problem, that would give me the desired features?
okay, right after posting my question, i found a simple solution, in form of an extension.
It is called intelephense. You might want to take a look at it in the marketplace:
https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client
Related
I downloaded this php api package from github
https://github.com/elastic/elasticsearch-php/tree/2.0
but I am having a hard time installing it. I unfortunately dont have permission to use the composer/auto-loader from where I work so I have to do it manually. Is there a way of doing this?
Thanks for your help.
The classes look pretty well formatted PSR-4 so you should be able to just download the directorysrc/Elasticsearch, and make a simple autoloader of your own and register it (assuming you don't already have one setup to serve classes that adhere to PSR-4).
Here's some options: http://www.php-fig.org/psr/psr-4/examples/
All the other directories seem to to be extraneous to running of the classes--for unit testing and benchmarking.
I cant seem to make go-aop-php library work for me and I have no idea why.
Basically I have go-aop-php 0.6.0 installed with composer and simple code which I ripped off from the available examples.
Here's the GIST of my code.
Attached below is the directory structure (if it's of any help):
I am running Ubuntu 14.04 with PHP 5.5. I am also wondering if I missed any dependencies for go-aop-php to operate properly.
Go! AOP is not a magic tool and can not change already loaded class to weave an aspect into it. In your case you explicitly load class via direct require_once __DIR__.'/classes/TestClass.php'; expression. After that class is already loaded and AOP won't be applied.
To fix your issue, you should use a composer for class autoloading (Go! AOP intercepts this automatically).
PS. If you will have any questions or need a support, please open an issue on GitHub instead. StackOverflow isn't a place to discuss such issues. I will be glad to help you with any issues on GitHub
I am trying to do some PDF form filling. I found this PHP library:
https://github.com/mikehaertl/php-pdftk
However, I have never installed libraries before and am not sure how to proceed. I already have pdftk installed on the server. I read about autoload, and am familiar with functions like require_once, etc, but I am really not sure how to properly go about this. Any help is appreciated!
Regards
Hard to say without seeing the project but if there are a ton of files then there is probably 1 that is using the rest as dependencies. What I mean by that is that there should be 1 file that you can require_once. See if there is a readme. That's usually my first step.
I don't know this particular library, but usually it is just enough to require_once on the library's main class.
Edit: The library uses Composer to resolve its dependencies. You could do the same: https://getcomposer.org
Can someone give me example how to use installed pear package, specifically FILE package. I'm php beginner and have never worked with pear so I'm interested in how to use any package after installation...I just call classes and functions from package it self? Second thing that interests me, can I just include downloaded package where ever I need in my files and use it?
Thanks
There are some very good examples linked to from the official File documentation, and yes you pretty much just call those functions and methods in that package from your own code.
The answer to your second question is also "Yes" :-) You can include that package in your code where-ever you need it.
I played with the zf2-tutorial successfully, but I was totally confused when trying to integrate an external library like "jpgraph". I know I must do this with autoload or servicemanager but it won't work.
The php-files of jpgraph are in the vendor/graph directory. I use a module called Jpgraph, in the controller indexAction I try:
$graph = new Graph($width,$height);
this gives me an error:
Fatal error: Class 'Jpgraph\Controller\Graph' not found in ...
the jpgraph library don't use namespaces.
i also tried this way without success
what's the best way to integrate such things?
I would be glad for every tip or help
Add the library to your composer.json and add the class with Classmap and/or the include path as phpunit does
https://github.com/sebastianbergmann/phpunit/blob/master/composer.json#L48
One option, as Maks3w pointed out, is to use Composer. If you've never heard of or used composer before it's definitely worth a look. I was surprised how easy it was to set up and use 3rd party libraries. It's also very easy to set up your own library to work with composer, and use any source controlled (git or svn) library of your own - works well with GitHub repos - just add a composer.json file.
On the other hand, you do not need to use composer to do what you want, it would make it very easy, but it may be overkill. Zend Framework 2 has a very flexible autoloader system, and although it works well with PSR-0, you can have any class autoloading sytem that you like. Take a look at the different components of Zend\Loader, in particular I think the ClassMapAutoloader will be the one to suit your needs.