Loading a Zend 2 Authentication Adapter - php

I'm writing a custom authentication adapter in Zend Framework 2.
module/Application/src/Application/Auth/Adapter/Auth_Adapter.php -
namespace Application\Auth;
use Zend\Authentication\Adapter\AdapterInterface;
use Zend\Authentication\Result;
class Auth_Adapter implements AdapterInterface {
...
Not sure what I'm doing wrong, but no classes can seem to find my new adapter. I've tried moving it into an autoloaded path (the Application/Controller directory) with no luck either.

Im assuming your namespaces are invalid. Given the path "module/Application/src/Application/Auth/Adapter/Auth_Adapter.php"
Try:
namespace Application\Auth\Adapter;

Related

laravel 5 Class implements Iterator

I am trying to integrate an existing library into Laravel5 which itself is not namespaced and uses its own classes in subfolders using require.
I have placed it at 'app/API/libname/mainlibclass.php'.
with sibling directory at 'app/API/libname/toolkit' which contains the classes the library uses.
Calling from a Laravel controller I am unable to create the class using a require statement (correct?) before
$objectinstance=new Mainlibclass();
so in the main Laravel app I have
use app/API/libname/Mainlibclass
then later the usual
$objectinstance=new Mainlibclass();
In the existing library and each of its own used classes I set
namespace app/API/libname
and 'use' where needed.
I now have no class not found but one of the files uses 'implements Iterator' - I am getting error Interface 'App\API\libname\Iterator' not found.
Try adding \ in front of that so it looks like this:
class ABC implements \Iterator {
Edit:
I think it would be better practice to keep external non-psr-4/0 libraries untouched (for easier update if needed in future) and outside of app/ directory.
You could use composer classmap autoload feature for this.

Adding PHP namespaces into an existing ZF1 application

I'm trying to integrate PHP namespaces into an existing Zend Framework project (v1.12). When I add namespacing at the top of a working controller, it doesn't work anymore and the application throws an Invalid controller class error. Here's my controller definition :
namespace MyProject\Controller;
use MyProject\Controller\MyRestController;
class MyFooController extends MyRestController
{
}
and the init method within the Bootstrap.php:
protected function _initAutoload()
{
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('MyProject');
return $autoloader;
}
Just a guess (have not used ZF for quite some time): Zend will not accept any class as a controller, just those extended from the framework's base controller class. As you don't extend from the frameworks base controller class you see the error.
If that is the reason, take care you initially extended from the base framework controller class or you implemented the needed interface.
namespace MyProject\Controller;
class MyRestController extendes Zend_Framework_Base_Controller_Class_Name_Here
{
...
p.s. the use MyProject\Controller\MyRestController; looks superfluous as that class is in that namespace already. Let's review your code:
namespace MyProject\Controller;
This sets the namespace of the file. That means, non-FQCN will resolve into it. For example:
new MyRestController();
Resolves to the following FQCN:
new MyProject\Controller\MyRestController
Which - oha! - is exactly what you wrote in use:
use MyProject\Controller\MyRestController;
Which means, that this use clause is superfluous, the extend in:
class MyFooController extends MyRestController
Would go to it anyway at first. Because it's the same namespace.
I am facing similar problem now. For me this looks like that Zend cannot properly resolve namespaced controller name. So when I put for example IndexController into namespace \Basic\Controller, it will be not loaded because Zend want to load \IndexController class, which does not exist.
I am thinking about extending standard zend router class, which has method getControllerName.
Then I can set this in bootstrap by:
$router = new \My\Namespaced\Router();
$front = Zend_Controller_Front::getInstance();
$front->setRouter($router);
I didn't tried that code yet but this should work.

symfony2 bundle class not getting autoloaded

I have a class that I want symfony2 to autoload so I can reference it from inside one of my registered services (I do not want to use the service container for this class). I dropped it into src/{Vendor}/{BundleName}/Services but I'm getting a class not found exception.
Do I have to explicitly request that that directory gets autoloaded in autoload.php?
There's got to be a better way.
I don't understand why you won't put this class in your bundle?
src/{BundleNamespace}/MyClass.php
or
src/{BundleNamespace/MyClass/MyClass.php
If you want your class to be bundle independant, then put it in it's own bundle library:
src/MyLibrary/MyClass.php
You can now use
MyLibrary\MyClass()
The src directory is the fallback in the autoloader, so you wont need to explicitly declare its namespace there, however you will need to comply with PSR-0
The namespace for my custom class was not correct. If you're putting a file in src/{VENDOR}/{BundleName}/Services, you must use namespace {VENDOR}{BundleName}\Services

CakePHP and namespaces?

Is there a way to put your own code into namespaces using cakephp? The following very simple controller class works fine.
class Customer extends \AppModel {
var $name = 'Customer';
}
However, if I add
namespace foo\bar;
cakephp can't find the controller anymore. Is there some way to tell cake in which namespace it should look for controllers?
I am using cakephp 1.3 and php 5.3.
I don't think there is. CakePHP looks for classes like PostsController or BlogController, not foo\bar\PostsController. Maybe you can tell CakePHP in what folder to look for those classes (probably), but then it will still be looking for unnamepsaced class names.
Why would you want this in a framework that doesn't use namespaces?
Why not give up the App::import() in cakephp 1.3. Replace it with the include_once().
I got my customize vendor classes defined under a namespace works fine. Just to prevent the collision of the custom class name with the official one.

Using PHP 5.3 namespaces (Doctrine2) with Zend Framework classes

i am having a situation where my doctrine model, Post, is in the namespace Application\Entities and i want to try to implement Zend_Acl_Resource_Interface. i get the error
Fatal error: Interface
'Application\Entities\Zend_Acl_Resource_Interface'
not found in
D:\Projects\Websites\php\ZendFram
ework\LearningZF\library\Application\Entities\Post.php
on line 8
namespace Application\Entities;
use DoctrineExtensions\NestedSet\Node;
/**
* #Entity #Table(name="posts")
*/
class Post implements Node, Zend_Acl_Resource_Interface {
update
if i try
class Post implements Node, \Zend_Acl_Resource_Interface {
Fatal error: Interface
'Zend_Acl_Resource_Interface' not
found in
D:\Projects\Websites\php\ZendFramework\LearningZF\library\Application\Entities\Post.php on
line 8
Are you using the ZF 2.0 branch or the stable one, e.g. 1.10? Is your autoloader setup to load classes with the ZF naming scheme?
You can use the Conversion tool the ZF devs used to convert ZF to using namespaces:
http://github.com/ralphschindler/PHPTools
http://blog.calevans.com/2010/03/27/zends-new-namespace-converter/
As far as I remember Zend Framework does not uses namespaces (until 2.x comes out anyway) so it's classes are in global namespace. Try class Post implements Node, \Zend_Acl_Resource_Interface {
i am going to put this as an answer, so i can mark this qn as answered if noone have any other answers, its actually a workaround i used. i am not too sure why it worked exactly, or rather why the Zend autoloader failed
i added the require_once to include Zend_Acl_Resource_Interface
namespace Application\Entities;
use DoctrineExtensions\NestedSet\Node;
require_once "Zend/Acl/Resource/Interface.php";
/**
* #Entity #Table(name="posts")
*/
class Post implements Node, \Zend_Acl_Resource_Interface {
i think a better fix will be to conversion tool in #Gordon's answer. but i cant fix all the errors i get with "unclean" conversion yet. paths are broken.

Categories