Git Product home page Git Product logo

Comments (18)

tomcyr avatar tomcyr commented on July 27, 2024

Hi,
I used OrientDB-odm with Symfony2 and I did it this way:

  1. I created Service called OrientDBService:
namespace ConceptIt\SmartShopperBundle\Services;

use ConceptIt\SmartShopperBundle\Domain;
use Doctrine\OrientDB\Binding\HttpBinding;
use Doctrine\ODM\OrientDB\Mapper;
use Doctrine\ODM\OrientDB as ODM;
use Doctrine\ODM\OrientDB\Manager;

class OrientDBService 
{
    protected $binding;
    protected $mapper;
    protected $manager;

    public function __construct(Mapper $mapper, HttpBinding $binding, Manager $manager)
    {
        $this->mapper = $mapper;
        $this->binding = $binding;
        $this->manager = $manager;
    }

    public function getBinding()
    {
        return $this->binding;
    }

    protected function getMapper()
    {
        return $this->mapper;
    }

    public function getManager()
    {
        return $this->manager;
    }

    public function getRepository($name)
    {
        return $this->getManager()->getRepository($name);
    }

    public function save(\StdClass $object)
    {

    }
}
  1. My Resources/config/services.yml file:
services:
  orientdb.binding.parameters:
    class: Doctrine\OrientDB\Binding\BindingParameters
    arguments:
      host:     %orientdb_host%
      port:     %orientdb_port%
      username: %orientdb_user%
      password: %orientdb_password%
      database: %orientdb_dbname%
  orientdb.binding:
    class: Doctrine\OrientDB\Binding\HttpBinding
    arguments:
      parameters: @orientdb.binding.parameters
  odm:
    class: Doctrine\ODM\OrientDB\Manager
    arguments:
      mapper: @odm.mapper
      binding: @orientdb.binding
  odm.mapper:
    class: Doctrine\ODM\OrientDB\Mapper
    arguments:
      documentProxyDirectory: %orientdb_proxy_dir%
      annotationReader: @odm.annotationreader
    calls:
      - [setDocumentDirectories, [ %orientdb_domain_dir% : %orientdb_domain_namespace% ] ]
  odm.annotationreader:
    class: Doctrine\ODM\OrientDB\Mapper\Annotations\Reader
    arguments:
      cacheReader: @cache.array
  cache.array:
    class: Doctrine\Common\Cache\ArrayCache

  conceptit.orientdb:
    class: ConceptIt\SmartShopperBundle\Services\OrientDBService
    arguments: 
      mapper: @odm.mapper
      binding: @orientdb.binding
      manager: @odm
  1. My parameters.yml
parameters:
    orientdb_host: 127.0.0.1
    orientdb_port: 2480
    orientdb_dbname: smartshopper
    orientdb_user: user
    orientdb_password: password
    orientdb_proxy_dir: %kernel.root_dir%/cache
    orientdb_domain_dir: %kernel.root_dir%/../src/ConceptIt/SmartShopperBundle/Entity
    orientdb_domain_namespace: ConceptIt\SmartShopperBundle\Entity
  1. I used my orientddb service:
$manager = $this->container->get('conceptit.orientdb')->getManager();

I hope this helps.

from orientdb-odm.

odino avatar odino commented on July 27, 2024

thanks @tomcyr!

this might help as well!

from orientdb-odm.

introfini avatar introfini commented on July 27, 2024

Thanks for the help, really appreciate it!

I think I'm almost there the, it already connects to the database but I get this error:

Unable to find a PHP class mapped for "Product".
500 Internal Server Error - OClassNotFoundException

It seems the proxy classes aren't being generated in the documentProxyDirectory.

is there something that I need to add to the app/autoload.php file in Symfony?

@tomcyr I'm adapting from your bundle https://github.com/tomcyr/OrientDbBundle

from orientdb-odm.

tomcyr avatar tomcyr commented on July 27, 2024

@introfini can You show Your Entity class with namespaces ?? And Your code how You use Your Entity ??

from orientdb-odm.

introfini avatar introfini commented on July 27, 2024

Hi @tomcyr!

This is just test adapted code taken from here http://odino.org/starting-to-play-with-the-doctrine-orientdb-odm/.

First I tried using your Bundle but I got the same error, then I started all again from the above tutorial and got the same error again. For what I can see (I'm really new with Symfony and Doctrine) the proxy classes aren't being generated in the cache directory.

My Entity class: Product.php

<?php 

namespace Genehome\OrientDBBundle\Entity;
use Doctrine\ODM\OrientDB\Mapper\Annotations as ODM;

/**
* @ODM\Document(class="product")
*/
class Product
{
    /**
     * @ODM\Property(name="@rid", type="string")
     */
    protected $rid;

    /**
     * @ODM\Property(type="string")
     */
    protected $email;

    /**
     * @ODM\Property(type="string", notnull="false")
     */
    protected $nick;

    /**
     * @ODM\Property(type="linklist")
     */
    protected $addresses;

    /**
     * Returns the nickname of the user, or his email if he has no nick set.
     * 
     * @return string
     */
    public function getNick()
    {
        return $this->nick ?: $this->getEmail();
    }

    public function setNick($nick)
    {
        $this->nick = $nick;
    }

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }

    public function getAddresses()
    {
        return $this->addresses;
    }

    public function setAddresses($adresses)
    {
        $this->addresses = $addresses;
    }

    public function getRid()
    {
        return $this->rid;
    }

    public function setRid($rid)
    {
        $this->rid = $rid;
    }
}

My controller

namespace Genehome\OrientDBBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Genehome\OrientDBBundle\Entity\Product;
use Doctrine\ODM\OrientDB\Manager;



class DefaultController extends Controller
{
    public function indexAction($name)
    {
        $product       = new Product();

        $manager    = $this->get('odm');
        $repository = $manager->getRepository('Genehome\OrientDBBundle\Entity\Product');
        $product = $repository->findAll();

        return new Response($product);
    }
}

My services.yml

services:
  orientdb.binding.parameters:
    class: Doctrine\OrientDB\Binding\BindingParameters
    arguments:
      host:     127.0.0.1
      port:     2480
      username: admin
      password: admin
      database: GratefulDeadConcerts
  orientdb.binding:
    class: Doctrine\OrientDB\Binding\HttpBinding
    arguments:
      parameters: @orientdb.binding.parameters
  odm:
    class: Doctrine\ODM\OrientDB\Manager
    arguments:
      mapper: @odm.mapper
      binding: @orientdb.binding
  odm.mapper:
    class: Doctrine\ODM\OrientDB\Mapper
    arguments:
      documentProxyDirectory: %kernel.root_dir%/cache
      annotationReader: @odm.annotationreader
    calls:
      - [setDocumentDirectories, [ %kernel.root_dir%/../src/Genehome/OrientDBBundle/Entity/ : "Genehome\OrientDBBundle\Entity" ] ]
  odm.annotationreader:
    class: Doctrine\ODM\OrientDB\Mapper\Annotations\Reader
    arguments:
      cacheReader: @cache.array
  cache.array:
    class: Doctrine\Common\Cache\ArrayCache

from orientdb-odm.

tomcyr avatar tomcyr commented on July 27, 2024

Maybe the problem is in service.yml
change:

- [setDocumentDirectories, [ %kernel.root_dir%/../src/Genehome/OrientDBBundle/Entity/ : "Genehome\OrientDBBundle\Entity" ] ]

into:

- [setDocumentDirectories, [ %kernel.root_dir%/../src/Genehome/OrientDBBundle/Entity : "Genehome\OrientDBBundle\Entity" ] ]

from orientdb-odm.

introfini avatar introfini commented on July 27, 2024

No, no luck :-(
Thanks @tomcyr

from orientdb-odm.

tomcyr avatar tomcyr commented on July 27, 2024

Hmm... Maybe if You try run Your app in app_dev.php the error will be more readable ??
Please try url: http://yourHost/app_dev.php instead of app.php and paste an error.

from orientdb-odm.

odino avatar odino commented on July 27, 2024

the error means that there is no class mapped to hydrate that specific entity, which means it cant find the entity classes, as @tomcyr pointed out. I found another configuration Im using on a Sf2 projects and it looks like:

  odm.mapper:
    class: Doctrine\ODM\OrientDB\Mapper
    arguments:
      documentProxyDirectory: %kernel.root_dir%/cache/
      annotationReader: @odm.annotation_reader
    calls:
      - [setDocumentDirectories, [ %kernel.root_dir%/../src/Vendor/Entity/ : "Vendor\Entity" ] ]

which is kinda the same that you're using but works here :) can you try to see where the ODM it's looking for entity classes var dumping here?

from orientdb-odm.

introfini avatar introfini commented on July 27, 2024

@odino the $class variable doesn't get any value there. I followed the path that creates the variable and got to getClassByPath function where it fails.

The problem that I found is that here the explode '/' on the path doesn't work (because I'm on Windows?). If I change that to $namespaces = explode('\\', $absPath); things get better because the proxy classes are created (they weren't before) on the cache directory but now I think I'm missing a "use" somewhere:

New error:

Attempted to load class "Product" from namespace "Doctrine\OrientDB\Proxy\Genehome\OrientDBBundle\Entity" in C:\wamp\www\Symfony2\vendor\doctrine\orientdb-odm\src\Doctrine\ODM\OrientDB\Mapper.php line 219. Do you need to "use" it from another namespace?
500 Internal Server Error - ClassNotFoundException

Thanks!

from orientdb-odm.

tomcyr avatar tomcyr commented on July 27, 2024

Hmm... I think that is Windows problem... @introfini can you try:

$repository = $manager->getRepository('\Genehome\OrientDBBundle\Entity\Product');

the Product class is loaded from bad namespace:
"Doctrine\OrientDB\Proxy\Genehome\OrientDBBundle\Entity" not "Genehome\OrientDBBundle\Entity"

from orientdb-odm.

odino avatar odino commented on July 27, 2024

oh wow crazy :) I honestly never checked the build on windows, if you can debug it that would be super-helpful!

from orientdb-odm.

mastacash avatar mastacash commented on July 27, 2024

Hi
I was running in exact the same issues working on a windows machine. I cannot fix the bug but at least I can tell where it is located and to get it work again I changed:

Doctrine\ODM\OrientDB\Mapper.php (line 381):

        $namespaces = explode('//', $absPath);

to...

        $namespaces = explode('\\', $absPath);

Doctrine\ODM\OrientDB\Mapper.php (line 218):
Changed...

        $proxyClass = $this->getProxyClass($class);

to...

        $proxyClass = $class;

Hope it helps!

from orientdb-odm.

odino avatar odino commented on July 27, 2024

hey @mastacash would you be able to send a PR with the fix? I can totally see why the first line would need to be fixed but Im not sure about the 2nd one, what is the error if you only apply the first fix?

from orientdb-odm.

mastacash avatar mastacash commented on July 27, 2024

Hi odino
I did some debugging and it is exactly related to the same issue as reported in #153, the fact that Symfony's Finder class returns mixed directory separators when working in a windows environment. Basically the Proxy files are failing when calling the class_exists(...) function in the Mapper class.
Unfortunately I have no idea how to fix this except switching to a Linux environment ;)

from orientdb-odm.

odino avatar odino commented on July 27, 2024

ok maybe we can replace the separators with DIRECTORY_SEPARATOR, can you try?

from orientdb-odm.

mastacash avatar mastacash commented on July 27, 2024

What is missing for windows is the path of the proxy classes in the $classMapper, instead of the path it was always 0.
By adding the following line to the composer.json file I fixed the problem:

    "autoload": {
        "psr-0": {
            "": "src/",
            "SymfonyStandard": "app/",
            "Doctrine\\OrientDB\\Proxy": "app/cache/"
        }
    },

Don't forget to run composer install after changing.

In addtion, I figured out that the requested changes with the DIRECTORY_SEPARATOR are already available in the #153 branch. I run all the test successful.

from orientdb-odm.

odino avatar odino commented on July 27, 2024

Ok! :)

from orientdb-odm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.