I try to work with ez Components and AWS PHP SDK at the same time.
I have a file called resize.php which is just handling resizing images using the ez Components ImageTransition tools.
I queue the image for resize in Amazon AWS SQS. If I load the AWS PHP SDK and ez Components in the same file, PHP always complains about not finding the ez Components classes.
Code looks something like this:
amazonSQS.php:
require 'modules/resize.php';
require 'modules/aws/sdk.class.php';
$sqs = new AmazonSQS();
$response = $sqs->send_message($queue_url, $message);
resize.php:
function resize_image($filename) {
$settings = new ezcImageConverterSettings(
array(
//new ezcImageHandlerSettings( 'GD', 'ezcImageGdHandler' ),
new ezcImageHandlerSettings( 'ImageMagick', 'ezcImageImagemagickHandler' ),
)
);
Error message:
Fatal error: Class 'ezcImageConverterSettings' not found in /home/www.com/public_html/modules/resize.php on line 10
If I call resize.php from another PHP file which has AWS not included, it works fine.
I load ezComponents like this:
require 'ezc/Base/ezc_bootstrap.php';
It is installed as a PEAR package.
Any idea someone?
The PHP classes of Apache Zeta / eZ Components can be conveniently used from within your PHP script. You don't have to use any require or include statements for any of the Apache Zeta Components classes that you use, this is because of the integrated autoload mechanism which can locate the classes for you when you instantiate or use them otherwise.
There are three different ways of getting the autoload mechanism going:
Normal autoload, if you require a custom autoload function
Bootstrap file, if you only use Apache Zeta autoloading
SPL autoload, if you need to register several autoload functions
These 3 ways are fully documented here
Related
all. I've installed HybridAuth 3.0 and went step-by-step through the Install instructions using composer. I've used the example code and am able to get an initial HybridAuth class instantiated. However, when I continue on to the example with using the Facebook provider class, I'm getting the error, "Class 'Hybridauth\Hybridauth\Provider\Facebook' not found". I'm also using this in a Drupal 7 environment but have other classes like this that autoload just fine so I'm hopeful that little extra detail has no bearing on the problem.
I tried this both with the composer autoloader and the basic autoloader included with the library (as described in the Installation instructions). They both have the same error when attempting to find the Facebook class which is down in the /src/Provider directory. It does this for other classes as well.
That said, using the Hybridauth\Hybridauth "unified interface" works fine and is my current workaround as it allows one to work with multiple providers at one time. But I'm wondering what I'm doing wrong to not be able to load a specific provider as shown in their Introduction documentation.
This works:
// Include Composer's autoloader
include 'vendor/autoload.php';
// Import Hybridauth's namespace
use Hybridauth\Hybridauth;
// Now we may proceed and instantiate Hybridauth's classes
$instance = new Hybridauth([ /* ... */ ]);
This gives an error:
// Include Composer's autoloader
include 'vendor/autoload.php';
// Import Hybridauth's namespace
use Hybridauth\Hybridauth;
$adapter = new Hybridauth\Provider\Facebook([ /* ... */ ]);
I am developing an oAuth 2.0 server using thephpleague library provided by Alex Bilbie. But, after the initializing the authorization server, when I declare the storage classes it throws an following error.
"Fatal error: Class 'Storage\SessionStorage' not found"
Please help me to resolve this. I read your post about this problem here:- Guide me implementing Oauth2 PHP server using thephpleague library
Please let me know how can I implement the storage classes. My current code:
require_once "/../vendor/autoload.php";
$server = new \League\OAuth2\Server\AuthorizationServer;
$server->setSessionStorage(new Storage\SessionStorage);
$server->setAccessTokenStorage(new Storage\AccessTokenStorage);
$server->setClientStorage(new Storage\ClientStorage);
$server->setScopeStorage(new Storage\ScopeStorage);
$server->setAuthCodeStorage(new Storage\AuthCodeStorage);
$authCodeGrant = new \League\OAuth2\Server\Grant\AuthCodeGrant();
$server->addGrantType($authCodeGrant);
The library that you use requires implementing your own storage classes, see http://oauth2.thephpleague.com/implementing-storage-interfaces/. The class names that you use are from an example implementation https://github.com/thephpleague/oauth2-server/tree/master/examples/relational/Storage that uses Capsule as its storage backend. If you want to use Capsule as you backend, you'll need to download those example implementation classes and install https://github.com/illuminate/database.
We have existing stuff in our code base that uses dompdf (version 0.5.1)... which has no namespace.
When I include the the aws.phar, using something like
require '/path/to/aws.phar';
all of sudden, I get fatal errors
Class 'DOMPDF' not found in XXXX on line 1193
The code that is causing the error is simply a new instantiating of the class:
$dompdf = new \DOMPDF();
I am guessing this is a namespace problem, but I have no idea how to go about fixing it, since I already put the global escape in front of DOMPDF... If I comment out the require line for the phar, then everything goes back to working.
I also did open up the AWS.phar to see what is going on inside. From the code that is not obfuscated, I see that they are using the symfony class loder.
$classLoader = new Symfony\Component\ClassLoader\UniversalClassLoader();
$classLoader->registerNamespaces(array(
'Aws' => 'phar://aws.phar/src',
'Guzzle' => 'phar://aws.phar/vendor/guzzle/guzzle/src',
'Symfony\\Component\\EventDispatcher' => 'phar://aws.phar/vendor/symfony/event-dispatcher',
'Doctrine\\Common' => 'phar://aws.phar/vendor/doctrine/common/lib',
'Psr\\Log' => 'phar://aws.phar/vendor/psr/log',
'Monolog' => 'phar://aws.phar/vendor/monolog/monolog/src'
));
I tried a couple of different things also to register the dompdf with the class loader, but they all threw errors. I am guessing bc it if written without namespaces.
I have also tried loading the dompdf include config file before and after loading the phar, it seem to make no difference.
Anyone have any suggestions??
v0.5.1 of dompdf did not yet implement SPL autoloading, it registered __autoload(). This outdated method of autoloading didn't work very well because it was difficult to register more than one autoload function at a time. Plus, when using writing PHP that does use SPL autoloading the v0.5.1 autoloader will not be called. PHP SPL autoloading disables calling __autoload() (spl_autoload_register).
v0.6.0 (just released) uses SPL autoloading and should be compatible with AWS.phar. v0.6.0 is (for the most part) a drop-in replacement for v0.5.1 so you might want to try upgrading your copy of dompdf.
If that's not possible for whatever reason you could register the dompdf autoloader manually using SPL after including dompdf_config.inc.php. At a minimum you could try the following:
<?php
require_once('dompdf/dompdf_config.inc.php');
spl_autoload_register('DOMDPF_autoload');
// ...
?>
See the dompdf v0.6.0 autoload include for a more complete example.
Monolog : http://github.com/Seldaek/monolog
Symfony Class Loader : https://github.com/symfony/ClassLoader
As per the usage instructions on the Monolog site, I'm trying to load the class loader to load monolog in my php project. I cant get 'Composer' installed on my machine (firewall problems from my work machine), so I'm trying to follow the instructions on monolog and symfony sites but I'm having issues.
Here is my SAMPLE of my directory structure with my php code :
myProj/
--ClassLoader/ (symfony)
----UniversalClassLoader.php
--Monolog/
----Formatter/
----Handler/
----Processor/
----Logger.php
--myPhpFile.php
And here is my php code to attempt to 'require' monolog
require_once(realpath('ClassLoader/UniversalClassLoader.php'));
$loader = new Symfony\Component\ClassLoader\UniversalClassLoader();
$loader->register();
$loader->registerNamespace('Monolog', realpath('Monolog'));
require_once(realpath('Monolog\Logger.php')); //exception generated here! :-(
and here is the php exception I'm getting inside the Monolog\Logger.php as soon as it attempts to 'require' monolog
Interface 'Psr\Log\LoggerInterface' not found
but I cant even FIND anything that looks like a 'psr\log' namespace in the monolog code. What bits am I missing?
Psr\Log is a dependency of monolog, if you are not using Composer you'll have to track down all dependencies and it's probably not going to be fun (though for monolog there is only the psr-log package). If you really want you can find it at https://github.com/php-fig/log - but you could also try to download composer via your browser, just grab https://getcomposer.org/composer.phar
I have written a Magento module to listen for the "OrderSave" event and perform some API calls to a third party application. Most of the functionality is working great, but I needed to handle an XML response from the API and when I tried to use the PEAR XML_Unserializer class I received the following error:
Fatal error: require_once() [function.require]: Failed opening required 'XML/Parser.php' (include_path='/Users/jeremymoore/Sites/Helm/html/app/code/local:/Users/jeremymoore/Sites/Helm/html/app/code/community:/Users/jeremymoore/Sites/Helm/html/app/code/core:/Users/jeremymoore/Sites/Helm/html/lib:.:/Applications/MAMP/bin/php5/lib/php:/usr/loca/zend//share/ZendFramework/library') in /Users/jeremymoore/Sites/Helm/html/lib/PEAR/XML/Unserializer.php on line 58
My module has an Observer.php file in the model which looks starts as follows:
<?php
require_once 'lib/PEAR/XML/Serializer.php';
require_once 'lib/PEAR/XML/Unserializer.php';
require_once 'lib/Pest/PestXML.php';
Zend_Loader::registerAutoload();
class Helm_Litmos_Model_Observer
{
public function hookToOrderSaveEvent()
{
//Do API Stuff Here
}
}
The hookToOrderSaveEvent functon creates new instances of the serializer and unserializer classes. Before I added the Unserializer code, I had everything working serializing objects and making API calls. It seems that things break down when the XML_Unserializer class tries to reference Parser.php.
I'm not sure that the "require_once" method I'm using here is the appropriate way for me to include these libraries. I'm using Magento 1.4.1.1 which is currently being used on my local machine running MAMP.
Any suggestions on a better way to autoload or include these libraries for use in my module or just ideas on how to fix what I have would be appreciated.
Thanks
You can try and use Mage::getBaseDir('lib')
require_once Mage::getBaseDir('lib').'/PEAR/XML/Serializer.php';
Alan has a good article on Magento's base directories:
http://alanstorm.com/magento_base_directories