3

I know that there are similar topics on the website. But I couldn't find a solution for my problem.

I'm searching to add a Alfresco Php SDK library to my symfony project. I'm using Symfony 2.2. I tried several methods of integration but no one worked. I couldn't find the library in Composer repository either.

The last method that I tried was to add library manual in composer.

The library doesn't respect PSR-0 normes neither PEAR. So I tried to extend the classes and add namespaces to them.

Folder structure:

vendor
  |_ /alfresco
        |_ /lib
            |_ /Alfresco
                   |_ /Service
                   |_ Alfresco.php

Alfresco.php file ... Not sure if I did it correctly :

<?php
#vendor/alfresco/lib/Alfresco/Alfresco.php

namespace  Alfresco\Service;

/**
 * class Alfresco_Association
 */
require_once 'Service/Association.php';
class Alfresco_Association extends Association {}

/**
 * class Alfresco_BaseObject
 */
require_once 'Service/BaseObject.php';
class Alfresco_BaseObject extends BaseObject {}

/**
 * class Alfresco_ChildAssociation
 */

require_once 'Service/ChildAssociation.php';
class Alfresco_ChildAssociation extends ChildAssociation {}

/**
 * class Alfresco_ContentData
 */
require_once 'Service/ContentData.php';
class Alfresco_ContentData extends ContentData {}

...
...

After that I added a path in to composer.json :

#composer.json
...

"autoload": {
        "psr-0": { 
            "": "src/",
            "Alfresco": "vendor/alfresco/lib"
        }

...

Controller :

#src/Acme/DemoBundle/Controller/DemoController.php
...
...
use Alfresco\Service;

class DemoController extends Controller
{
...

/**
 * @Route("/hello/{name}", name="_demo_hello")
 * @Template()
 */
public function helloAction($name)
{
    $name=new \Alfresco\Service\Alfresco_Repository();
    return array('name' => $name);
}

...

The result is that I have an error :

FatalErrorException: Error: Class 'Alfresco\Service\Alfresco_Repository' not found in ...
j0k
  • 22,600
  • 28
  • 79
  • 90
ReiRoku
  • 31
  • 5
  • Did you dumped a new autoloader with `php composer.phar dump-autoload`? But not sure, if the autoloader will find your Alfresco.php.. – Emii Khaos May 20 '13 at 10:58
  • No I didn't. But after your response I tried it, no changes :(. – ReiRoku May 20 '13 at 11:03
  • why not fork original library and add improvements there? – Inoryy May 20 '13 at 11:12
  • As said, I think your `Alfresco.php` won't get loaded. If your access the class, the autoloader searches for a `Alfresco_Repository.php` under the `Service/` dir. – Emii Khaos May 20 '13 at 11:13
  • @Pazi Ok I see. I changed the namespace just to namespace Alfresco; And there were some changes when I call the class it appeares in list. But unfortunatly there is the same error : FatalErrorException: Error: Class 'Alfresco\Alfresco_Repository' not found in – ReiRoku May 20 '13 at 11:27
  • @Inori I'm sorry, but I'm not a native english speaker therefore I don't understand all things. Could you explain more, what do you mean under fork, please? – ReiRoku May 20 '13 at 11:28
  • Copy the library and develop it instead of sending patches to the original. This is useful when you need large changes to the API of library (PSR-0 support), which maintainer will probably refuse to implement to avoid compability breaks for current users. – Inoryy May 20 '13 at 11:58
  • As for what you're trying to do now - it will not work either way as `Alfresco.php` is not loaded. I don't think you can fix this problem without ugly hacks (i.e. globally requiring `Alfresco.php` before any code is executed), which is why I suggested a fork – Inoryy May 20 '13 at 12:02
  • @Inori Thank you for your explanation. Just to be sure, you mean to add namespaces directly in to library classes instead of extends classes (Alfresco.php)? – ReiRoku May 20 '13 at 12:52
  • Do you really have to use the PHP SDK? As you will see on the Google Code project, it has not been updated in some time and the Apache Chemistry project (http://chemistry.apache.org) provides a much better client library for performing content operations via CMIS. – Will Abson May 20 '13 at 14:15
  • :D It is a little bit weird, because I tried **Inori** solution yesterday and it didn't worked. But now I redid it and dumped a new autoloader as **Pazi** said and Voilà it works :D There was another probleme with a class that was extended from SoapClient, but I figured out. Just had to add backslash(\) before SoapClient. (...extends \SoapClient...). I would like to thank you for your help, guys! I was struggling on this problem for several days. Thank you very much! I would like to commit your both responses as the best if it is possible. – ReiRoku May 20 '13 at 14:21
  • @WillAbson Thank you for your response and information. It is true that the PHP SDK isn't realy supported since few years. And I'm not realy to have to use it. It's just that I didn't found any other libraries that were functionally. Therefore, thank you for your tips. I will give a try to it. ;) – ReiRoku May 20 '13 at 14:30

0 Answers0