1
votes

based on the way to do it from FOSUserbundle, i made a vendor bundle that contains a Analytic Abstrakt class than implements an AnalyticInterface and in a src/AppBundle, i(ve got a Analytic entity that extends the vendor Analytic abstract class but that doesn't work, my entity doesn't the abstract class properties ($referer, $host, $ip, $browser, ...)

The interface:

  <?php
/**
 * Created by PhpStorm.
 * User: VanIllaSkyPE
 * Date: 01/11/2016
 * Time: 23:26
 */

namespace Gkratz\AnalyticBundle\Model;


/**
 * Interface AnalyticInterface
 * @package Gkratz\AnalyticBundle\Model
 */
interface AnalyticInterface
{
    /**
     * Set date
     *
     * @param \DateTime $date
     * @return Analytic
     */
    public function setDate($date);

    /**
     * Get date
     *
     * @return \DateTime
     */
    public function getDate();

    /**
     * Set page
     *
     * @param string $page
     * @return Analytic
     */
    public function setPage($page);

    /**
     * Get page
     *
     * @return string
     */
    public function getPage();

    /**
     * Set ip
     *
     * @param string $ip
     * @return Analytic
     */
    public function setIp($ip);

    /**
     * Get ip
     *
     * @return string
     */
    public function getIp();

    /**
     * Set host
     *
     * @param string $host
     * @return Analytic
     */
    public function setHost($host);

    /**
     * Get host
     *
     * @return string
     */
    public function getHost();

    /**
     * Set browser
     *
     * @param string $browser
     * @return Analytic
     */
    public function setBrowser($browser);

    /**
     * Get browser
     *
     * @return string
     */
    public function getBrowser();

    /**
     * Set referer
     *
     * @param string $referer
     * @return Analytic
     */
    public function setReferer($referer);

    /**
     * Get referer
     *
     * @return string
     */
    public function getReferer();

    /**
     * Set newSession
     *
     * @param boolean $newSession
     * @return Analytic
     */
    public function setNewSession($newSession);

    /**
     * Get newSession
     *
     * @return boolean
     */
    public function getNewSession();
}

The base abstract class:

<?php

/**
 * Created by PhpStorm.
 * User: VanIllaSkyPE
 * Date: 01/11/2016
 * Time: 22:30
 */

namespace Gkratz\AnalyticBundle\Model;

/**
 * Class Analytic
 * @package Gkratz\AnalyticBundle\Model
 */
abstract class Analytic implements AnalyticInterface
{
    protected $id;

    /**
     * @var \DateTime
     */
    protected $date;

    /**
     * @var string
     */
    protected $page;

    /**
     * @var string
     */
    protected $ip;

    /**
     * @var string
     */
    protected $host;

    /**
     * @var string
     */
    protected $browser;

    /**
     * @var string
     */
    protected $referer;

    /**
     *
     * @var boolean
     */
    protected $newSession;



    public function __construct()
    {
        $this->date = new \Datetime();
    }


    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set date
     *
     * @param \DateTime $date
     * @return Analytic
     */
    public function setDate($date)
    {
        $this->date = $date;

        return $this;
    }

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

    /**
     * Set page
     *
     * @param string $page
     * @return Analytic
     */
    public function setPage($page)
    {
        $this->page = $page;

        return $this;
    }

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

    /**
     * Set ip
     *
     * @param string $ip
     * @return Analytic
     */
    public function setIp($ip)
    {
        $this->ip = $ip;

        return $this;
    }

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

    /**
     * Set host
     *
     * @param string $host
     * @return Analytic
     */
    public function setHost($host)
    {
        $this->host = $host;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set referer
     *
     * @param string $referer
     * @return Analytic
     */
    public function setReferer($referer)
    {
        $this->referer = $referer;

        return $this;
    }

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

    /**
     * Set newSession
     *
     * @param boolean $newSession
     * @return Analytic
     */
    public function setNewSession($newSession)
    {
        $this->newSession = $newSession;

        return $this;
    }

    /**
     * Get newSession
     *
     * @return boolean
     */
    public function getNewSession()
    {
        return $this->newSession;
    }
}

the App analytic entity:

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gkratz\AnalyticBundle\Model\Analytic as BaseAnalytic;

/**
 * Analytic
 *
 * @ORM\Table(name="analytic")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\AnalyticRepository")
 */
class Analytic extends BaseAnalytic
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;


    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    public function __construct()
    {
        parent::__construct();
    }
}

Thank you for any response

1

1 Answers

3
votes

The abstract class Analytic defines only properties.

Analytic needs to annotate them with @ORM\Column(...) if you want to use them as DB columns.

Also see: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/inheritance-mapping.html