I'm trying to implement Amazon WebServices PHP SDK into my Zend 1 project, but it seems to fail loading the classes.
I have got the library into library/Eplan/AmazonCloudSearch and after investigation it seems that in order to be able to load the namespace I need to call the registerNamespace method from Zend_Loader_Autoloader::getInstance() so I've got this on the top of the autoloader (I also tried to put it in the bootstrap without luck):
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace("Aws");
Namespaces of the AWS library are like this: Aws\namespace
The errors I get are like Warning: include_once(Aws/Common/Aws.php): failed to open stream: No such file or directory in /srv/www_nfs_desarrollo/vhosts/desarrollo.techmaker.net/httpdocs/library/Zend/Loader.php on line 134
Autoloader full code: http://pastebin.com/gS9mcntK
I've been the full day struggling my head trying to solve this without luck, any ideas?
In order to use $autoloader->registerNamespace('Aws'), the AWS lib you seek must be on your PHP include path, which probably includes your ./library directory. Instead, you have the AWS lib buried down in ./library/Eplan/AmazonCloudSearch, which almost certainly is not on your PHP include_path.
Try moving the AWS library up two levels, directly into the ./library directory.
You can autoload using your application.ini file using following code.
autoloaderNamespaces[] = "Aws"
Related
I'm working on a native PHP project. Using terminal in the root I added 2 github libraries and they get saved in the vendor folder. In a sub folder in the root in a PHP file I add
use nadar\quill\Lexer;
$lexer = new Lexer($row['reply']);
echo $lexer->render();
But I get
Uncaught Error: Class 'nadar\quill\Lexer' not found in /home/USER/public_html/production/filename.php:469
I tried another library and get the same error Cannot find the class. How to solve this? Tis is the first library url: https://github.com/nadar/quill-delta-parser
Every file where you need classes loaded by the autoloader need to include the autoload file. Otherwise, these classes are unknown by the interpreter.
Add this to the beginning of your file:
require __DIR__ . '/vendor/autoload.php';
I want to use the following AntiXSS library in one PHP file. It is my first time using Composer, but I followed their installation steps and I installed it successfully. I downloaded the library through Composer, updated it and Composer created the vendor/ folder in my directory with the necessary files.
Now I added the following require 'vendor/autoload.php' into my PHP file. I created a new AntiXSS class but I obtain the following error:
Class AntiXSS not found in my directory on line 3.
I tried to use an absolute path instead of vendor/autoload.php but it isn't working yet and I don't know if I should do something more.
Best regards
The class is located in the voku\helper namespace. Use new \voku\helper\AntiXSS() to instantiate it or use use imports to import the namespace.
See php.net for more information about namespaces.
I'm hoping someone can spot what I've forgotten to do. Here are my steps:
Downloaded and unpacked the ZendFramework-2.3.5 into /usr/share.
Updated include_path in my php.ini file to include '/usr/share/ZendFramework-2.3.5/library' per the INSTALL.md, and restarted Apache to confirm the path is set (now ".:/usr/share/php:/usr/share/ZendFramework-2.3.5/library").
Created a test script in my web document root (using the class 'CamelCaseToUnderscore' as an example):
use Zend\Filter\Word\CamelCaseToUnderscore;
$filter = new CamelCaseToUnderscore();
echo $filter->filter('BigsAndLittles');
...and I get the fatal error "class 'zend\filter\word\camelcasetoseparator' not found".
In order to do use Zend classes like this, do I need to do some additional configuration or create an autoloader or something to find them? Seems like this should have worked. If I include the CamelCaseToUnderscore.php file in a require_once statement, then I get a fatal error that it's parent class doesn't exist (CamelCaseToSeparator.php). What am I missing?
You can use require 'Zend/Mvc/Application.php' to test if your include path is correct, but you will need an autoloader:
http://framework.zend.com/manual/current/en/modules/zend.loader.standard-autoloader.html.
You can find an example here (lines 18-20):
https://github.com/zendframework/zf2/blob/master/demos/Zend/Feeds/consume-feed.php
I strongly suggest using composer as it will save you a lot of time troubleshooting your include paths, but it also allows you manage version better. It makes it easier for other developers and to deploy your code.
Starting with composer is very easy, just install it and create composer.json:
https://getcomposer.org/doc/01-basic-usage.md#composer-json-project-setup
Run:
composer require zendframework/zendframework
Composer will download all libraries to vendor folder and will generate an autoloader, all you have to do is to include
require 'vendor/autoload.php';
https://getcomposer.org/doc/01-basic-usage.md#autoloading
Most popular PHP frameworks use composer for managing dependencies:
https://github.com/zendframework/zf2/blob/master/composer.json
https://github.com/symfony/symfony/blob/2.7/composer.json
When trying to implement this framework I ran into a issue with the directory. When I attemt to use this Zend i end up with
Interface 'Zend\Mail\Storage\Folder\FolderInterface' not found in /home/content/54/9595754/html/zend/library/Zend/Mail/Storage/Imap.php
In the index.php file where I try to display the emails. I use an:
set_include_path
include require_once('Imap.php');
The contents of Imap.php looks like:
namespace Zend\Mail\Storage;
use Zend\Mail;
use Zend\Mail\Protocol;
class Imap extends AbstractStorage implements Folder\FolderInterface, Writable\WritableInterface
So what would i need to add to the Imap.php so that it dosent look inside this directory for the file.
I know understand that I need to try to implement a file in order for the framework to understand the directory they are in however when i try to implement an autoloader I get an error see example below.
require_once '../../../library/Zend/Loader/Autoloader.php';
Yields
require_once(Zend/Loader.php) [function.require-once]: failed to open stream:
No such file or directory in /home/content/54/9595754/html/zend/library/Zend/
Loader/Autoloader.php
Zend framework 2 and most other modern frameworks rely on autoloading for class loading.
You have only required the Imap class but not the dependent interfaces. That's why you get this fatal error.
I'd suggest you setup autoloading in your application. For an example how to set this up you can have a look into init_autoloader.php from the ZendSkeletonApplication.
I want to be able to use SimplePie on Yii.
I'm using the 1.3-dev version of simplepie
I created a "vendors" folder, put all I had in the .tar.gz in a simplepie subfolder.
Then i add this lines at the beginning of my controller
Yii::import('application.vendors.SimplePie.*');
require_once 'SimplePieAutoloader.php';
spl_autoload_unregister(array('YiiBase','autoload'));
spl_autoload_register(array('SimplePie_Autoloader','autoload'));
spl_autoload_register(array('YiiBase','autoload'));
But when I try to use it, I get this error:
include(SimplePie_Core.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory
C:\wamp\www\yii\fr\framework\YiiBase.php(418)
Any ideas why I get this error?
edit: i took the compiled version of simplepie and everything works like a charm
I think (not looked into it fully) that the Simple Pie library follows PSR-0 for class and file names. In which case you should be able to register its path and Yii's autoloader will know how to autoload it. Try adding the following to config.php;
Yii::setPathOfAlias('SimplePie', '/path/to/vendor/');
The second argument needs to point to the root folder of the library e.g. if your path is like this /var/lib/yiiproject/vendor/simplepie/lib/SimplePie then the register the path /var/lib/yiiproject/vendor/simplepie/lib
This yii widget use SimplePie
http://www.yiiframework.com/extension/yii-feed-widget/