Use PEAR-Package inside Symfony - php

I am writing an PHPUnit WebTestCase for a Symfony repository. In some tests I want to print out time measurements. For that case I found the PEAR Console\Table package. Via Composer I get it installed, but how can I use it within my test?
The Console_Table.php doesn't have a namespace. So I think I could not use
use Console\Table;
or?
So when I must use the require_once statement, which is the right relativ path, when Composer installed the Table.php into vendor/pear/console_table/.
At this point I would say I am really new to PHP.
Thanks for your replies.

Ok,
I get it. absalon.valdes was right. $table = \Console_Table(); is the solution.
Important was to do a clean build of the project in Eclipse. After that, the compiler recognizes the class.
My bad.
Thanks.

Related

VsCode PHP-Intellisense using composer and autoload.php

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

Symfony CLI commands and Compiler pass

I just want to know how to get all my commands Symfony services into my compiler pass ?
Is there a mean to find services by implemented interfaces ? Or perhaps i have to tag them all ?
Thanks,
KL.
You should tag them all. There is no way to retreive services which are instance of some expected class/interface.
Anyway, you can just get all, iterate over them, and filter only those which extends your interface. But it's much slower, and the most awful way to do it.
I hope I understood you question correctly. If you're trying to get all commands defined in your application then:
$kernel = $this->container->get('kernel');
$application = new Application($kernel);
$commands = $application->all('doctrine');
var_dump($commands);die;
This example with a fresh symfony install you can fetch all doctrine commands. Just replace 'doctrine' with your commands prefix.
Take a look in \Symfony\Bundle\FrameworkBundle\Console\Application especially registerCommands method. I'm using latest version Symfony 3.2.4

go-aop-php wont work even with simple setup

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

How to use PHP classes from 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

How to include external library in Zend Framework 2?

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.

Categories