zend + doctrine 2 doctrine manager, where is it? - zend-framework

i see everyone using this:
Doctrine_Manager::getInstance()
when i do this, its error is:
Class 'Doctrine_Manager' not found
how do i load this ?so that i can start get instances from doctrine manager?
i want to load this:
$con = Doctrine_Manager::getInstance()->connection();
$st = $con->execute("...............");
$result = $st->fetchAll();
where can autoload this , so i can call the getInstance() function from anywhere?
thanks...

Doctrine_Manager is part of version 1.2, not 2. If you are actually using 1.2, you need to let the autoloader know to load classes under the Doctrine_ prefix.
To do so, add this to your application configuration file...
autoloaderNamespaces.Doctrine = "Doctrine_"
You also need to ensure the doctrine classes can be found on the include path. If they aren't in your "library" folder or otherwise part of the include_path directive, add this...
includePaths.Doctrine = "/path/to/Doctrine-1.2/lib"

I think you might be looking for the EntityManager?
If so, here you can find a tutorial how to configure.
Also there is a library call Bisna for integrating ZF+Doctrine2, here is a good tutorial video for configuring it

Related

TYPO3 - includelibs security

I need to include a PHP script in my TS template :
page {
10 = USER_INT
10.includeLibs = lib_confidential.php
10.userFunc = MyClass->ConfidentialRequest
}
It works perfectly but I would like to locate the lib_confidential.php outside of my website root directory (and make something like 10.includeLibs = ../lib_confidential.php). Is it possible to secure my PHP script and how to ? I thought about creating a symlink but that doesn't give any solution.
As your installation needs an update you will have to change the mechanism for including php-functions for the future.
since TYPO3 8 you need to have a class for your php functions. So the autoloader can identify the class and execute the function you need to place the class inside of an extension or declare the class to the autoloader.
Best practice would be site extension where you configure your installation, there you can havea class with all the functions you need.
examples can be found in the manual.

neo4jphp: Cannot instantiate abstract class Everyman\Neo4j\Transport

maybe a simple question but for me as starter with Neo4j a hurdle. I installed the neo4jphp with composer in the same directory as my application. Vendor-Subfolder has been created and the everyman/neo4j folder below is available. For a first test I used this code snippet from the examples:
spl_autoload_register(function ($className) {
$libPath = 'vendor\\';
$classFile = $className.'.php';
$classPath = $libPath.$classFile;
if (file_exists($classPath)) {
require($classPath);
}
});
require('vendor/autoload.php');
use everyman\Neo4j\Client,
everyman\Neo4j\Transport;
$client = new Client(new Transport('localhost', 7474));
print_r($client->getServerInfo());
I always stumple upon the error
Fatal error: Cannot instantiate abstract class Everyman\Neo4j\Transport
Googling brought me to a comment from Josh Adell stating
You can't instantiate Everyman\Neo4j\Transport, since it is an abstract class. You must instantiate Everyman\Neo4j\Transport\Curl or Everyman\Neo4j\Transport\Stream depending on your needs
So I thought I just need to alter the use-statements to
use everyman\Neo4j\Client,
everyman\Neo4j\Transport\Curl;
but this doesnt work, debugging shows, that the autoloader only get "Transport.php" instead of "everyman\Neo4j\Transport\Curl.php". For "Client.php" its still working ("vendor\everyman\Neo4j\Client.php") so I am guessing that the use-statement is wrong or the code is not able to handle an additional subfolder-structure.
Using
require('phar://neo4jphp.phar');
works fine but I read that this is deprecated and should be replaced by composer / autoload.
Anyone has a hint what to change or had the same problem?
Thanks for your time,
Balael
Curl is the default transport. You only need to instantiate your own Transport object if you want to use Stream instead of Curl. If you really want to instantiate your own Curl Transport, the easiest change to your existing code is to modify the use statement to be:
use everyman\Neo4j\Client,
everyman\Neo4j\Transport\Curl as Transport;
Also, you don't need to register your own autoload function if you are using the Composer package. vendor/autoload.php does that for you.
Thanks Josh, I was trying but it seems I still stuck somewhere. I am fine with using the default CURL - so I shrinked the code down to
require('vendor/autoload.php');
use everyman\Neo4j\Client;
$client = new Everyman\Neo4j\Client('localhost', 7474);
print_r($client->getServerInfo());`
The folder structure is main (here are the files and the composer.json with the content
{
"require": {
"everyman/Neo4j": "dev-master"
}
}
and in the subfolder "vendor" we have the "autoload.php" and the subfolder everyman with the related content. When I run the file I come out with
Fatal error: Class 'Everyman\Neo4j\Client' not found
which does not happen when I have the autoloadfunction. I guess I made a mistake somewehere - can you give me a hint?
Thanks a lot, B
Hmmm... I was just trying around and it seems the Transport CLASS is not needed in the use-statement and the class instantiation. This seems to work:
require('vendor/autoload.php');
use everyman\Neo4j\Client;
$client = new Client();
print_r($client->getServerInfo());
also valid for having a dedicated server/port:
$client = new Everyman\Neo4j\Client('localhost', 7474);
If you have more input I would be happy to learn more - thanks, all input & thoughts are very appreciated.
Balael

Laravel 4 using vendor classes

I have installed Laravel 4 after using 3, love it.
I used to be able to use the Zend framework as such:
$yt = new Zend_Gdata_YouTube();
for instance
I have used composer to install Zend and everything is installed in the Vendor folder..
Problem:
How to address the individual classes i.e. Zend Gdata etc.
I can't find any documentation on calling classes from a vendor in L4.
Any help is appreciated.
Take a look at your vendor\composer\autoload_classmap.php file. In there you will find a list of all vendor classes that are being autoloaded. I think all classes will have to be called using their full namespaced name.
E.g.
I'm using Zizaco's Entrust package. This is what it looks like in the vendor\composer\autoload_classmap.php file.
'Zizaco\\Entrust\\Entrust' => $vendorDir . /zizaco/entrust/src/Zizaco/Entrust/Entrust.php',
If I wanted to access the Entrust.php class I have to call
$en = new Zizaco\Entrust\Entrust();
Alternatively you could alias certain classes in your app\config\app.php file.
E.g.
'Ent' => 'Zizaco\Entrust\Entrust'
In your case you'll need to do something like this:
$yt = new Zend\namespace\Zend_Gdata_YouTube();

Doctrine 2 Autloading

How do set up autoloading with Doctrine 2 and Zend to load entities in the following directory structure:
Application
-Modules
--Core
---Models
----Entities
----Repositories
--CMS
---Models
----Entities
----Repositories
I want to be able to load classes using {ModuleName}\Entities{EntityName}. For example, I'd like to be able to do this to load a 'User' entity:
$em->getRepository('Core\Entities\User');
or something like this for a 'Pages' entity:
$em->getRepository('CMS\Entities\Pages');
I can set it up to load 'CMS\Models\Entities\Pages' but I'd like to be able to know how to do it without having to map directly to the directory structure. Is this possible?
I don't how you glue Zend Framework and Doctrine2 together but if you are using the popular Bisna glue (which is pretty cool) you can set-up more than one mapping directory in your application.ini. Take a closer look to the following ini settings:
resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.0.adapterClass = "Doctrine\ORM\Mapping\Driver\AnnotationDriver"
resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.0.mappingNamespace = "Core\Entities"
resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.0.mappingDirs[] = APPLICATION_PATH "/modules/Core/Entities"
resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.0.annotationReaderClass = "Doctrine\Common\Annotations\AnnotationReader"
resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.0.annotationReaderCache = default
resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.1.adapterClass = "Doctrine\ORM\Mapping\Driver\AnnotationDriver"
resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.1.mappingNamespace = "CMS\Entities"
resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.1.mappingDirs[] = APPLICATION_PATH "/modules/CMS/Entities"
resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.1.annotationReaderClass = "Doctrine\Common\Annotations\AnnotationReader"
resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.1.annotationReaderCache = default
Something like the above would be accomplish what you want. If want to be able to do this fully automatically I think you have to patch the Bisna\Doctrine\Container class. Which for instance looks to the modules defined check if there is a entities directory and add's this to the doctrine entity manager.
Bisna
If you don't have a clue what Bisna is, this is a small library which allows you to easily 'glue' Doctrine2 and Zend Framework 1 together.
By watching this video it should be easy for you to understand how to integrate Doctrine2.
http://www.zendcasts.com/unit-testing-doctrine-2-entities/2011/02/
Please be aware that the Bisna version used in the video only supports Doctrine 2.0 and not 2.1 in that case you should use this one: https://github.com/guilhermeblanco/ZendFramework1-Doctrine2

Zend Framework unknown module is interpreted as default module

i wanted to support multilingual structure for my work i used the following lines
$controller=Zend_Controller_Front::getInstance();
$router=$controller->getRouter();
$languageRouter=new Zend_Controller_Router_Route(":lang/:module/:controller/:action", array("lang"=>"en","module"=>"default","controller"=>"index","action"=>"index"),
array("lang"=>"[a-zA-Z]{2}"));
$router->addRoute("default",$languageRouter);
it works fine http://localhost/zend/public/en set the lang param to en and call default module
but the problem is that when i use url like this http://localhost/zend/public/en/anything
where anything isn't module it still show the default module how to prevent that???
after the answer of takeshin i added this function to the bootstarp file and now it works as i want it
protected function _initRoutes()
{
$routeLang=new Zend_Controller_Router_Route(':lang',array('lang'=>'en'),array('lang'=>'[a-z]{2}'));
$front = Zend_Controller_Front::getInstance() /*$this->getResource('frontcontroller')*/;
$router = $front->getRouter();
$routeDefault=new Zend_Controller_Router_Route_Module(array(),$front->getDispatcher(),$front->getRequest());
$routeLangDefault=$routeLang->chain($routeDefault);
$router->addRoute('default',$routeLangDefault);
$router->addRoute('lang',$routeLang);
}
It looks like you have overwritten default module defined in Zend Application by your custom one.
You should chain the routes instead.
The settings you are using means module will 'default' to default , if you didn't it would throw a route not found error - which should throw to appropriate error controller
I'm not sure if I unterstood this correctly, but it looks like it works fine, as it should. If you try to call non existing module, Zend Framework automatically "redirects" to the default module.