Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Unable to find a PHP class mapped for "logfile" #153

Open
alexbusta79 opened this issue Jan 21, 2013 · 19 comments
Open

Unable to find a PHP class mapped for "logfile" #153

alexbusta79 opened this issue Jan 21, 2013 · 19 comments

Comments

@alexbusta79
Copy link

Hello, Now I'm trying to map the entity, I'm working in ZendFramework, in the configuration I do this:

$parameters = Doctrine\OrientDB\Binding\BindingParameters::create('http://admin:admin@10.64.98.112:2480/logusers');
$orient = new Doctrine\OrientDB\Binding\HttpBinding($parameters);

$cache = new Doctrine\Common\Cache\ArrayCache();
$anotation = new  Doctrine\ODM\OrientDB\Mapper\Annotations\Reader($cache);
$mapper = new Doctrine\ODM\OrientDB\Mapper(\APPLICATION_PATH .'/data/temp',$anotation);
$mapper->setDocumentDirectories(array("C:\workspace\TravelMatic2\library\Application\Entity\Orientdb" => "Application\Entity\Orientdb"));

$manager = new Doctrine\ODM\OrientDB\Manager($mapper,$orient);
$result = $manager->find('#10:3');

I return good data but can not find the entity:

object(ArrayObject)#309 (1) {
  ["storage":"ArrayObject":private] => array(3) {
    ["exception"] => object(Doctrine\ODM\OrientDB\OClassNotFoundException)#456 (7) {
      ["message":protected] => string(48) "Unable to find a PHP class mapped for "logfile"."
      ["string":"Exception":private] => string(0) ""
      ["code":protected] => int(0)
      ["file":protected] => string(91) "C:\workspace\TravelMatic2\vendor\doctrine\orientdb-odm\src\Doctrine\ODM\OrientDB\Mapper.php"
      ["line":protected] => int(285)
      ["trace":"Exception":private] => array(10) {
        [0] => array(6) {
          ["file"] => string(91) "C:\workspace\TravelMatic2\vendor\doctrine\orientdb-odm\src\Doctrine\ODM\OrientDB\Mapper.php"
          ["line"] => int(155)
          ["function"] => string(29) "findClassMappingInDirectories"
          ["class"] => string(28) "Doctrine\ODM\OrientDB\Mapper"
          ["type"] => string(2) "->"
          ["args"] => array(1) {
            [0] => string(7) "logfile"
          }
        }

Se sapessi come risolvere grazie.

@odino
Copy link
Member

odino commented Jan 21, 2013

can you please paste your entity?

@alexbusta79
Copy link
Author

<?php

namespace Application\Entity\Orientdb;
use Doctrine\ODM\OrientDB\Mapper\Annotations as ODM;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /** 
    * @ODM\Property(type="datetime")
    */
    protected $insdatetime;

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



    /**
     * Set logdate
     *
     * @param \DateTime $logdate
     * @return Logfile
     */
    public function setLogdate($logdate)
    {
        $this->logdate = $logdate;

        return $this;
    }

    /**
     * Get logdate
     *
     * @return string 
     */
    public function getLogdate()
    {
        return $this->logdate;
    }

    /**
     * Set logtime
     *
     * @param \DateTime $logtime
     * @return Logfile
     */
    public function setLogtime($logtime)
    {
        $this->logtime = $logtime;

        return $this;
    }

    /**
     * Get logtime
     *
     * @return string 
     */
    public function getLogtime()
    {
        return $this->logtime;
    }

    /**
     * Set companyid
     *
     * @param string $companyid
     * @return Logfile
     */
    public function setCompanyid($companyid)
    {
        $this->companyid = $companyid;

        return $this;
    }

    /**
     * Get companyid
     *
     * @return string 
     */
    public function getCompanyid()
    {
        return $this->companyid;
    }

    /**
     * Set userid
     *
     * @param string $userid
     * @return Logfile
     */
    public function setUserid($userid)
    {
        $this->userid = $userid;

        return $this;
    }

    /**
     * Get userid
     *
     * @return string 
     */
    public function getUserid()
    {
        return $this->userid;
    }

    /**
     * Set travelid
     *
     * @param string $travelid
     * @return Logfile
     */
    public function setTravelid($travelid)
    {
        $this->travelid = $travelid;

        return $this;
    }

    /**
     * Get travelid
     *
     * @return string 
     */
    public function getTravelid()
    {
        return $this->travelid;
    }

    /**
     * Set operationtype
     *
     * @param integer $operationtype
     * @return Logfile
     */
    public function setOperationtype($operationtype)
    {
        $this->operationtype = $operationtype;

        return $this;
    }

    /**
     * Get operationtype
     *
     * @return string 
     */
    public function getOperationtype()
    {
        return $this->operationtype;
    }

    /**
     * Set operationdesc
     *
     * @param string $operationdesc
     * @return Logfile
     */
    public function setOperationdesc($operationdesc)
    {
        $this->operationdesc = $operationdesc;

        return $this;
    }

    /**
     * Get operationdesc
     *
     * @return string 
     */
    public function getOperationdesc()
    {
        return $this->operationdesc;
    }

    /**
     * Set program
     *
     * @param string $program
     * @return Logfile
     */
    public function setProgram($program)
    {
        $this->program = $program;

        return $this;
    }

    /**
     * Get program
     *
     * @return string 
     */
    public function getProgram()
    {
        return $this->program;
    }

    /**
     * Set ipaddress
     *
     * @param string $ipaddress
     * @return Logfile
     */
    public function setIpaddress($ipaddress)
    {
        $this->ipaddress = $ipaddress;

        return $this;
    }

    /**
     * Get ipaddress
     *
     * @return string 
     */
    public function getIpaddress()
    {
        return $this->ipaddress;
    }

    /**
     * Set osname
     *
     * @param string $osname
     * @return Logfile
     */
    public function setOsname($osname)
    {
        $this->osname = $osname;

        return $this;
    }

    /**
     * Get osname
     *
     * @return string 
     */
    public function getOsname()
    {
        return $this->osname;
    }

    /**
     * Set browser
     *
     * @param string $browser
     * @return Logfile
     */
    public function setBrowser($browser)
    {
        $this->browser = $browser;

        return $this;
    }

    /**
     * Get browser
     *
     * @return string 
     */
    public function getBrowser()
    {
        return $this->browser;
    }

    /**
     * Set screenresolutionwidth
     *
     * @param integer $screenresolutionwidth
     * @return Logfile
     */
    public function setScreenresolutionwidth($screenresolutionwidth)
    {
        $this->screenresolutionwidth = $screenresolutionwidth;

        return $this;
    }

    /**
     * Get screenresolutionwidth
     *
     * @return string 
     */
    public function getScreenresolutionwidth()
    {
        return $this->screenresolutionwidth;
    }

    /**
     * Set screenresolutionheight
     *
     * @param integer $screenresolutionheight
     * @return Logfile
     */
    public function setScreenresolutionheight($screenresolutionheight)
    {
        $this->screenresolutionheight = $screenresolutionheight;

        return $this;
    }

    /**
     * Get screenresolutionheight
     *
     * @return string 
     */
    public function getScreenresolutionheight()
    {
        return $this->screenresolutionheight;
    }

    /**
     * Set phptime
     *
     * @param float $phptime
     * @return Logfile
     */
    public function setPhptime($phptime)
    {
        $this->phptime = $phptime;

        return $this;
    }

    /**
     * Get phptime
     *
     * @return string  
     */
    public function getPhptime()
    {
        return $this->phptime;
    }

    /**
     * Set mysqltime
     *
     * @param float $mysqltime
     * @return Logfile
     */
    public function setMysqltime($mysqltime)
    {
        $this->mysqltime = $mysqltime;

        return $this;
    }

    /**
     * Get mysqltime
     *
     * @return string 
     */
    public function getMysqltime()
    {
        return $this->mysqltime;
    }

    /**
     * Set htmltime
     *
     * @param float $htmltime
     * @return Logfile
     */
    public function setHtmltime($htmltime)
    {
        $this->htmltime = $htmltime;

        return $this;
    }

    /**
     * Get htmltime
     *
     * @return string 
     */
    public function getHtmltime()
    {
        return $this->htmltime;
    }

    /**
     * Set transactionid
     *
     * @param string $transactionid
     * @return Logfile
     */
    public function setTransactionid($transactionid)
    {
        $this->transactionid = $transactionid;

        return $this;
    }

    /**
     * Get transactionid
     *
     * @return string 
     */
    public function getTransactionid()
    {
        return $this->transactionid;
    }

    /**
     * Set insuserid
     *
     * @param string $insuserid
     * @return Logfile
     */
    public function setInsuserid($insuserid)
    {
        $this->insuserid = $insuserid;

        return $this;
    }

    /**
     * Get insuserid
     *
     * @return string 
     */
    public function getInsuserid()
    {
        return $this->insuserid;
    }

    /**
     * Set insdatetime
     *
     * @param \DateTime $insdatetime
     * @return Logfile
     */
    public function setInsdatetime($insdatetime)
    {
        $this->insdatetime = $insdatetime;

        return $this;
    }

    /**
     * Get insdatetime
     *
     * @return \DateTime 
     */
    public function getInsdatetime()
    {
        return $this->insdatetime;
    }

    /**
     * Set systables
     *
     * @param string $systables
     * @return Logfile
     */
    public function setSystables($systables)
    {
        $this->systables = $systables;

        return $this;
    }

    /**
     * Get systables
     *
     * @return string 
     */
    public function getSystables()
    {
        return $this->systables;
    }

    /**
     * Set logfileid
     *
     * @param integer $logfileid
     * @return Logfile
     */
    public function setRid($rid)
    {
        $this->rid = $rid;

        return $this;
    }

    /**
     * Get logfileid
     *
     * @return string 
     */
    public function getRid()
    {
        return $this->rid;
    }
}

@nrk
Copy link
Member

nrk commented Jan 22, 2013

This commit should fix your issue, but since I cannot test it right now I pushed it into a separate issue-153 branch. Can you try again with that branch and see if it works for you after that change?

@odino
Copy link
Member

odino commented Jan 23, 2013

@alexbusta79 let us know if this solves your issue

@alexbusta79
Copy link
Author

Sorry but this does not solve the problem. You will have a test of how to map this:
$mapper->setDocumentDirectories(
array(APPLICATION_PATH ."/../library/Application/Entity/Orientdb" => "Application\Entity\Orientdb"));

I have tried different routes and not any

@nrk
Copy link
Member

nrk commented Jan 23, 2013

@alexbusta79 could you try to copy the following class, instantiate it instead of Doctrine\ODM\OrientDB\Mapper in your script, and past here the output?

class DebugMapper extends Doctrine\ODM\OrientDB\Mapper
{
    protected $trap;

    protected function findClassMappingInDirectory($OClass, $directory, $namespace)
    {
        $this->trap = stripos($OClass, 'logfile') !== false ? 'logfile' : null;

        parent::findClassMappingInDirectory($OClass, $directory, $namespace);
    }

    public function getClassByPath($file, $namespace)
    {
        $absPath    = realpath($file);
        $namespaces = explode('/', $absPath);
        $start      = false;
        $i          = 0;
        $chunk      = explode('\\', $namespace);
        $namespace  = array_shift($chunk);

        if ($this->trap && stripos($absPath, $this->trap) !== false) {
            echo "=== PATH ===\n";
            var_dump($absPath);
            echo "=== EXPLODED PATH ===\n";
            var_dump($namespaces);
            echo "=== EXPLODED NAMESPACE ===\n";
            var_dump($chunk);
            echo "==========================\n";
        }

        while ($namespaces[$i] != $namespace) {
            unset($namespaces[$i]);

            if (!array_key_exists(++$i, $namespaces)) {
                break;
            }
        }

        $className = str_replace('.php', null, array_pop($namespaces));

        return '\\'. implode('\\', $namespaces) . '\\' . $className;
    }
}

@alexbusta79
Copy link
Author

I've tried it and the result is the same error:
["message":protected] => string(48) "Unable to find a PHP class mapped for "logfile"."

@nrk
Copy link
Member

nrk commented Jan 23, 2013

@alexbusta79 the error won't go away with that extended class, what we need to be sure of is if you see any output emitted by the three var_dump() in DebugMapper::getClassByPath() when the mapper tries to find a suitable class for logfile.

That said, if you effectively can't see any output beside the exception then the only thing I can think of is that the path you are passing to setDocumentDirectories() is invalid (if the directory cannot be found, findClassMappingInDirectory() is not invoked).

Can you add a var_dump(is_dir(APPLICATION_PATH ."/../library/Application/Entity/Orientdb")); to make sure that the document directory exists?

@alexbusta79
Copy link
Author

var_dump(is_dir(APPLICATION_PATH ."/../library/Application/Entity/Orientdb"));
bool(true)

@nrk
Copy link
Member

nrk commented Jan 23, 2013

Alright one last check, could you try with this class implementation instead? It should print all the PHP files found in your document directories (recursively).

class DebugMapper extends Doctrine\ODM\OrientDB\Mapper
{
    protected function findClassMappingInDirectory($OClass, $directory, $namespace)
    {
        $finder = new \Symfony\Component\Finder\Finder();
        echo "=== $directory ====================\n";
        var_dump(iterator_to_array($finder->files()->name('*.php')->in($directory)));

        parent::findClassMappingInDirectory($OClass, $directory, $namespace);
    }
}

@nrk
Copy link
Member

nrk commented Jan 31, 2013

@alexbusta79 ping?

@alexbusta79
Copy link
Author

I still can not solve the problem !!!

@nrk
Copy link
Member

nrk commented Jan 31, 2013

@alexbusta79 I mean, we are still waiting for a reply with the output generated by using this extended mapper class, personally I'm not able to reproduce the issue.

@odino
Copy link
Member

odino commented Jan 31, 2013

...and using three question marks won't help anyone in solving the issue. There is certainly a problem in mapping class paths of entities on Windows, but since none of the three main developers of this ODM are using windows, it's hard for us to reproduce this. Having some more insights from you, as @nrk said, would be very helpful.

@alexbusta79
Copy link
Author

=== C:\workspace\TravelMatic2\application/../library/Application/Entity/Orientdb ==================== array(2) { ["C:\workspace\TravelMatic2\application/../library/Application/Entity/Orientdb\Logfile.php"]=> object(Symfony\Component\Finder\SplFileInfo)#467 (4) { ["relativePath":"Symfony\Component\Finder\SplFileInfo":private]=> string(0) "" ["relativePathname":"Symfony\Component\Finder\SplFileInfo":private]=> string(11) "Logfile.php" ["pathName":"SplFileInfo":private]=> string(88) "C:\workspace\TravelMatic2\application/../library/Application/Entity/Orientdb\Logfile.php" ["fileName":"SplFileInfo":private]=> string(11) "Logfile.php" } ["C:\workspace\TravelMatic2\application/../library/Application/Entity/Orientdb\LogfileRepository.php"]=> object(Symfony\Component\Finder\SplFileInfo)#465 (4) { ["relativePath":"Symfony\Component\Finder\SplFileInfo":private]=> string(0) "" ["relativePathname":"Symfony\Component\Finder\SplFileInfo":private]=> string(21) "LogfileRepository.php" ["pathName":"SplFileInfo":private]=> string(98) "C:\workspace\TravelMatic2\application/../library/Application/Entity/Orientdb\LogfileRepository.php" ["fileName":"SplFileInfo":private]=> string(21) "LogfileRepository.php" } }

@nrk
Copy link
Member

nrk commented Jan 31, 2013

The fact that Symfony's Finder class returns mixed directory separators in the paths is probably what's confusing the mapper by triggering some other bug in our implementation, now that I'm aware of that I can review the whole part of the mapper that translates paths to fully-qualified class names.

Thanks.

@odino
Copy link
Member

odino commented Jan 31, 2013

look here:

    public function getClassByPath($file, $namespace)
    {
        $absPath    = realpath($file);
        $namespaces = explode('/', $absPath);
        $start      = false;
        $i          = 0;
        $chunk      = explode('\\', $namespace);
        $namespace  = array_shift($chunk);

        while ($namespaces[$i] != $namespace) {
            unset($namespaces[$i]);

            if (!array_key_exists(++$i, $namespaces)) {
                break;
            }
        }

        $className = str_replace('.php', null, array_pop($namespaces));

        return '\\'. implode('\\', $namespaces) . '\\' . $className;
    }

@odino
Copy link
Member

odino commented Jan 31, 2013

@nrk the weird thing is that those are retrieved by the finder :|

@nrk
Copy link
Member

nrk commented Jan 31, 2013

@odino I'm not sure if it's weird, the sure thing is that I was going with the wrong assumption that the finder would normalize the directory separators depending on the platform which is clearly not the case. I have access to a Windows machine, I just need to configure PHP on it to debug and test things so I won't probably be able to fix this until the weekend.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants