Autoloader issue with Zend - php

I'm new to Zend and am currently trying to use Swift Mailer as my messaging system. However, I keep getting this error:
Fatal error: Class 'Adviser\Controller\Swift_Message' not found
I did some research and thought it might be an autoloader issue. So I added the following two lines:
$autoloader = new StandardAutoloader();
$autoloader->registerNamespace('Swift_','/Applications/MAMP/htdocs/zsa/Swift-4.3.0/lib/classes/Swift');
I'm still getting the error. I've also set the path accordingly to "swift_required.php"
require_once '/Applications/MAMP/htdocs/zsa/Swift-4.3.0/lib/swift_required.php';
Any thoughts on how to fix this?

It looks like Swift is not namespaced, so you should use $autoloader->registerPrefix instead if available.
Using http://getcomposer.org/ is a good option too.

Related

Issue with the implementation of the simplesamlphp library into my web application

I tried to implement the simplesamlphp library into my web application. But when I call the requireAuth() function I get a PHP fatal error message. Uncaught Exception: Loader: Illegal character in filename.....
It seems like he can't resolve the Class SimpleSAML\Module\saml\Auth\Source\SP
But I don't know why.
Does anyone have a idea how to fix this?
I already deleted the whole simplesamlphp installation and reinstalled it.
I use the following code:
require 'var/www/simplesamlphp/lib/_autoload.php';
$lAuthSrc = new \SimpleSAML\Auth\Simple('default-sp');
if (!$lAuthSrc->isAuthenticated()) {
$lAuthSrc->requireAuth();
}
$lAttributes = $lAuthSrc -> getAttributes();
foreach($lAttributes as $lAttribute) {
print_r($lAttribute);
}
Some additional informations:
The configured authentication source test works fine. If I login via the configured authentication source, everything works fine and I don't get any error messages (the requireAuth() function don't get called in this case).
I use the latest version of simplesamlphp v.1.18.3
If you need any more information, please let me know.
Honestly it looks like your path is messed up on the require... are you sure you should be using:
require 'var/www/simplesamlphp/lib/_autoload.php';
and not
require '/var/www/simplesamlphp/lib/_autoload.php';
Do you really have a 'var/www' subdirectory relative to the location of the script? That looks wrong to me. If you include that first / before var it makes that path absolute to the typical install location for SSP.
Thank you all for your help. I discovered this morning the issue. The issue was the autoloader which I use for my own application. I registered the application autoloader in another file which gets executed before the code you see above. And simplesamlphp uses some conditions like:
if (!class_exists($className))
And beacuse I registered my application autoloader before the function class_exists checked if the class exists in my application. In my application I don't use namespaces and this was the issue.
To fix this issue, I unregistered my application autoloader before using the simplesamlphp code and registered the autoloader again after the simplesamlphp code.
I hope this will save some of you headaches.

Symfony console component, class not found

I'm using the console component without Symfony standard edition and I'm working on my application.php file. When I run it it says:
Fatal error: Class 'GenerateTableCommand' not found in D:\ConnectCommand\vendor\application.php on line 10
My code:
<?php
require __DIR__.'\autoload.php';
use Symfony\Component\Console\Application;
$application = new Application();
$application->add(new GenerateTableCommand());
$application->run();
?>
My repository can be found here if needed: https://github.com/guuse/ConnectCommand
Any help is greatly appreciated.
First of all there's no \GenerateTableCommand, as stated in the error message.
This class is under AppBundle\Command namespace, so it's full name is AppBundle\Command\GenerateTableCommand.
You should add use statement at the beggining:
use AppBundle\Command\GenerateTableCommand;
Anyway, you'll probably encounter further issues with loading this class, since you do not really have any autoloaders for your custom code, so PHP won't be able to load this class.
Also mixing 3rd party code with your own (in vendor directory) is not a good idea.

google-api-php-client's autoloader deprecated

As a test, I ran one line of code in PHP to implement the PHP Client Library.
indexTest.php
<?php
require_once realpath(dirname(__FILE__).'/google-api-php-client/autoload.php');
return;
I get this error:
Deprecated: google-api-php-client's autoloader was moved to src/Google/autoload.php in 1.1.3. This redirect will be removed in 1.2. Please adjust your code to use the new location. in C:\Users\NoName\Documents\academic-being-90217\google-api-php-client\autoload.php on line 25
What do I need to do to fix this?
Quick Fix:
require_once realpath(dirname(__FILE__).'/google-api-php-client/src/Google/autoload.php');
Google need to update their documentation on the API. (I spent quite a while getting myself in a fuddle recently, trying to get it working using their documentation).
What is you final aim on using the API? Is it just for Login? If you need any help with it, I'll be more than happy to talk you through anything that isn't working as it should be

Fatal error: Class 'NexmoMessage' not found

I'm using this library to implement the Nexmo SMS service on my server. I required the library using Composer like so:
"require" : {
"prawnsalad/nexmo": "dev-master"
}
which I found here and followed the instructions included in the README like so:
require 'vendor/autoload.php';
use NexmoMessage;
$phone = '123456789';
$sms = new NexmoMessage(NEXMO_KEY, NEXMO_SECRET);//defined in another file
$sms->sendText($phone, 'from', "yo");//$phone is a valid number in actual case
However I keep getting the error in the title of this question. I see that Composer has imported the library successfully and I see the class and constructor for NexmoMessage, yet for some reason this error keeps happening no matter what I do. I'm not sure if this is due to an issue with the library or with how I'm using Composer. I've never had an issue with Composer in the past so I'm boggled why this is happening here. Thanks
Well, that library states that it supports PSR-4, which means they absolutely MUST use PHP namespaces, but they don't. That last commit 8 months ago https://github.com/prawnsalad/Nexmo-PHP-lib/commit/8e422c4f8f43c52acb70ebd5f9e7c6ff81a1f352 broke the autoloading. And nobody noticed up to today.
You can easily tell by looking at the source code: There is no namespace being used.
Your best action now would be to fix this issue and send a pull request! Github allows to edit files in the browser! Second best action would be to create an issue and let the authors know.

Class 'Zend_Search_Lucene' not found

A big beginner of Zend-framework on PHP calls, I could include it on Netbeans IDE. Now I'm trying to use it to achieve a Lucene indexer and searcher using Zend_Lucene, I followed the getting started of the official site, unfortunately they explain the whole thing with just few words. Anyway, I copied pasted this $index = Zend_Search_Lucene::create($indexPath);, but I got a message onto this line saying: Fatal error: Class 'Zend_Search_Lucene' not found in C:\wamp\www\witswork\luceneTry.php
means that the function still unknown, maybe, some files need to be copied on my project folder but really I'm running out of ideas right now.
Accept my regards,
dany90.
You need to load the php file which contains the Zend_Search_Lucene class first. One option is to load your/path/to/library/Zend/Search/Lucene.php:
require_once 'my/path/to/library/Zend/Search/Lucene.php';
$index = new Zend_Search_Lucene::create($indexPath);
This class loads all its dependencies, so you don't need to worry about that.
Another option is to use the autoloader of Zend, Zend_Loader_Autoloader. This class is a singleton and registers itself with spl_autoload() when you retrieve it for the first time:
$autoloader = Zend_Loader_Autoloader::getInstance();
$index = new Zend_Search_Lucene::create($indexPath);
After the autoloader is loaded, you just can use Zend_Search_Lucene without the require_once() call. In the manual of Zend Framework you can find more information about the autoloader.

Categories