Skip to content

Instantly share code, notes, and snippets.

@doctrinebot
Created December 13, 2015 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doctrinebot/b56b8ab1f5896695be58 to your computer and use it in GitHub Desktop.
Save doctrinebot/b56b8ab1f5896695be58 to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-411 - https://github.com/doctrine/doctrine2/issues/4904
<?php
use Doctrine\ORM\Mapping\ClassMetadataInfo;
$metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
$metadata->setPrimaryTable(array(
'name' => 'inventory_usb_generic',
'schema' => NULL,
));
$metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT);
$metadata->mapField(array(
'fieldName' => 'serial',
'type' => 'string',
'length' => '255',
'precision' => 0,
'scale' => 0,
'nullable' => true,
'unique' => false,
'columnName' => 'serial',
));
$metadata->mapField(array(
'fieldName' => 'maxpower',
'type' => 'string',
'length' => '255',
'precision' => 0,
'scale' => 0,
'nullable' => true,
'unique' => false,
'columnName' => 'maxpower',
));
$metadata->mapField(array(
'fieldName' => 'speed',
'type' => 'string',
'length' => '255',
'precision' => 0,
'scale' => 0,
'nullable' => true,
'unique' => false,
'columnName' => 'speed',
));
<?php
use Doctrine\ORM\Mapping\ClassMetadataInfo;
$metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_JOINED);
$metadata->setPrimaryTable(array(
'name' => 'private_inventory_basic',
'schema' => NULL,
));
$metadata->setDiscriminatorColumn(array(
'name' => 'discr',
'type' => 'smallint',
'length' => NULL,
'fieldName' => 'discr',
));
$metadata->setDiscriminatorMap(array(
0 => 'privateInventoryBasic',
1 => 'inventorySystem',
2 => 'inventoryBattery',
3 => 'inventoryBus',
4 => 'inventoryCache',
5 => 'inventoryCdrom',
6 => 'inventoryCpu',
7 => 'inventoryDisk',
8 => 'inventoryDisplay',
9 => 'inventoryFirmware',
10 => 'inventoryMemory',
11 => 'inventoryMemoryBank',
12 => 'inventoryMemoryController',
13 => 'inventoryMultimedia',
14 => 'inventoryNetwork',
15 => 'inventoryPciHostBridge',
16 => 'inventoryStorage',
17 => 'inventorySystem',
18 => 'inventoryUsbBus',
19 => 'inventoryUsbGeneric',
20 => 'inventoryUsbHost',
21 => 'inventoryVolume',
));
$metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT);
$metadata->mapField(array(
'fieldName' => 'id',
'type' => 'integer',
'length' => NULL,
'precision' => 0,
'scale' => 0,
'nullable' => false,
'unique' => false,
'columnName' => 'id',
'id' => true,
));
$metadata->mapField(array(
'fieldName' => 'product',
'type' => 'string',
'length' => '255',
'precision' => 0,
'scale' => 0,
'nullable' => true,
'unique' => false,
'columnName' => 'product',
));
$metadata->mapField(array(
'fieldName' => 'vendor',
'type' => 'string',
'length' => '255',
'precision' => 0,
'scale' => 0,
'nullable' => true,
'unique' => false,
'columnName' => 'vendor',
));
$metadata->mapField(array(
'fieldName' => 'version',
'type' => 'string',
'length' => '255',
'precision' => 0,
'scale' => 0,
'nullable' => true,
'unique' => false,
'columnName' => 'version',
));
$metadata->mapField(array(
'fieldName' => 'businfo',
'type' => 'string',
'length' => '255',
'precision' => 0,
'scale' => 0,
'nullable' => true,
'unique' => false,
'columnName' => 'businfo',
));
$metadata->mapField(array(
'fieldName' => 'capabilities',
'type' => 'bigint',
'length' => NULL,
'precision' => 0,
'scale' => 0,
'nullable' => true,
'unique' => false,
'columnName' => 'capabilities',
));
$metadata->mapField(array(
'fieldName' => 'num',
'type' => 'string',
'length' => '255',
'precision' => 0,
'scale' => 0,
'nullable' => true,
'unique' => false,
'columnName' => 'num',
));
$metadata->mapField(array(
'fieldName' => 'comment',
'type' => 'string',
'length' => '255',
'precision' => 0,
'scale' => 0,
'nullable' => true,
'unique' => false,
'columnName' => 'comment',
));
$metadata->mapField(array(
'fieldName' => 'physid',
'type' => 'string',
'length' => '255',
'precision' => 0,
'scale' => 0,
'nullable' => true,
'unique' => false,
'columnName' => 'physid',
));
$metadata->mapField(array(
'fieldName' => 'driver',
'type' => 'string',
'length' => '255',
'precision' => 0,
'scale' => 0,
'nullable' => true,
'unique' => false,
'columnName' => 'driver',
));
$metadata->mapField(array(
'fieldName' => 'driverversion',
'type' => 'string',
'length' => '255',
'precision' => 0,
'scale' => 0,
'nullable' => true,
'unique' => false,
'columnName' => 'driver_version',
));
$metadata->mapField(array(
'fieldName' => 'description',
'type' => 'string',
'length' => '255',
'precision' => 0,
'scale' => 0,
'nullable' => true,
'unique' => false,
'columnName' => 'description',
));
$metadata->mapField(array(
'fieldName' => 'xmlId',
'type' => 'string',
'length' => '255',
'precision' => 0,
'scale' => 0,
'nullable' => true,
'unique' => false,
'columnName' => 'xml_id',
));
$metadata->mapField(array(
'fieldName' => 'class',
'type' => 'string',
'length' => '255',
'precision' => 0,
'scale' => 0,
'nullable' => true,
'unique' => false,
'columnName' => 'class',
));
$metadata->mapField(array(
'fieldName' => 'handle',
'type' => 'string',
'length' => '16',
'precision' => 0,
'scale' => 0,
'nullable' => true,
'unique' => false,
'columnName' => 'handle',
));
$metadata->mapField(array(
'fieldName' => 'parentHandle',
'type' => 'string',
'length' => '16',
'precision' => 0,
'scale' => 0,
'nullable' => true,
'unique' => false,
'columnName' => 'parent_handle',
));
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
$metadata->mapOneToOne(array(
'fieldName' => 'hostId',
'targetEntity' => 'basicHost',
'cascade' =>
array(
'remove' => true,
'persist' => true,
'refresh' => true,
'merge' => true,
'detach' => true,
),
'mappedBy' => NULL,
'joinColumns' =>
array(
0 =>
array(
'name' => 'host_id',
'referencedColumnName' => 'id',
'unique' => false,
'nullable' => true,
'onDelete' => 'CASCADE',
'onUpdate' => 'CASCADE',
'columnDefinition' => NULL,
),
),
'orphanRemoval' => false,
));
<?php
/**
* @Entity
* @Table(name="inventory_usb_generic")
*/
class inventoryUsbGeneric extends privateInventoryBasic
{
/**
* @Column(name="serial", type="string", length=255, nullable=true)
*/
protected $serial;
/**
* @Column(name="maxpower", type="string", length=255, nullable=true)
*/
protected $maxpower;
/**
* @Column(name="speed", type="string", length=255, nullable=true)
*/
protected $speed;
/**
* Set serial
*/
public function setSerial($value)
{
$this->serial = $value;
}
/**
* Get serial
*/
public function getSerial()
{
return $this->serial;
}
/**
* Set maxpower
*/
public function setMaxpower($value)
{
$this->maxpower = $value;
}
/**
* Get maxpower
*/
public function getMaxpower()
{
return $this->maxpower;
}
/**
* Set speed
*/
public function setSpeed($value)
{
$this->speed = $value;
}
/**
* Get speed
*/
public function getSpeed()
{
return $this->speed;
}
}
<?php
/**
* @Entity
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="discr", type="smallint")
* @DiscriminatorMap({
* "0" = "privateInventoryBasic",
* "1" = "inventorySystem",
* "2" = "inventoryBattery",
* "3" = "inventoryBus",
* "4" = "inventoryCache",
* "5" = "inventoryCdrom",
* "6" = "inventoryCpu",
* "7" = "inventoryDisk",
* "8" = "inventoryDisplay",
* "9" = "inventoryFirmware",
* "10" = "inventoryMemory",
* "11" = "inventoryMemoryBank",
* "12" = "inventoryMemoryController",
* "13" = "inventoryMultimedia",
* "14" = "inventoryNetwork",
* "15" = "inventoryPciHostBridge",
* "16" = "inventoryStorage",
* "17" = "inventorySystem",
* "18" = "inventoryUsbBus",
* "19" = "inventoryUsbGeneric",
* "20" = "inventoryUsbHost",
* "21" = "inventoryVolume"
* })
* @Table(name="private_inventory_basic")
* @HasLifecycleCallbacks
*/
class privateInventoryBasic
{
static function getSearchFieldList()
{
return array('vendor', 'product', 'description', 'version');
}
/**
* @Id
* @Column(name="id", type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @Column(name="product", type="string", length=255, nullable=true)
*/
private $product;
/**
* @Column(name="vendor", type="string", length=255, nullable=true)
*/
private $vendor;
/**
* @Column(name="version", type="string", length=255, nullable=true)
*/
private $version;
/**
* @Column(name="businfo", type="string", length=255, nullable=true)
*/
private $businfo;
/**
* @Column(name="capabilities", type="bigint", nullable=true)
*/
private $capabilities;
/**
* @Column(name="num", type="string", length=255, nullable=true)
*/
private $num;
/**
* @Column(name="comment", type="string", length=255, nullable=true)
*/
private $comment;
/**
* @Column(name="physid", type="string", length=255, nullable=true)
*/
private $physid;
/**
* @Column(name="driver", type="string", length=255, nullable=true)
*/
private $driver;
/**
* @Column(name="driver_version", type="string", length=255, nullable=true)
*/
private $driverversion;
/**
* @Column(name="description", type="string", length=255, nullable=true)
*/
private $description;
/**
* @Column(name="xml_id", type="string", length=255, nullable=true)
*/
private $xmlId;
/**
* @ManyToOne(targetEntity="basicHost", cascade={"all"}, fetch="EAGER")
* @JoinColumn(name="host_id", referencedColumnName="id", onDelete="CASCADE", onUpdate="CASCADE", nullable=true)
*/
private $hostId;
private $hostIdValue;
/**
* @Column(name="class", type="string", length=255, nullable=true)
*/
private $class;
/**
* @Column(name="handle", type="string", length=16, nullable=true)
*/
private $handle;
/**
* @Column(name="parent_handle", type="string", length=16, nullable=true)
*/
private $parentHandle;
/**
* Set id
*/
public function getId()
{
return $this->id;
}
/**
* Set product
*/
public function setProduct($value)
{
$this->product = $value;
}
/**
* Get product
*/
public function getProduct()
{
return $this->product;
}
/**
* Set vendor
*/
public function setVendor($value)
{
$this->vendor = $value;
}
/**
* Get vendor
*/
public function getVendor()
{
return $this->vendor;
}
/**
* Set version
*/
public function setVersion($value)
{
$this->version = $value;
}
/**
* Get version
*/
public function getVersion()
{
return $this->version;
}
/**
* Set businfo
*/
public function setBusinfo($value)
{
$this->businfo = $value;
}
/**
* Get businfo
*/
public function getBusinfo()
{
return $this->businfo;
}
/**
* Set capabilities
*/
public function setCapabilities($value)
{
$this->capabilities = $value;
}
/**
* Get capabilities
*/
public function getCapabilities()
{
return $this->capabilities;
}
/**
* Set num
*/
public function setNum($value)
{
$this->num = $value;
}
/**
* Get num
*/
public function getNum()
{
return $this->num;
}
/**
* Set comment
*/
public function setComment($value)
{
$this->comment = $value;
}
/**
* Get comment
*/
public function getComment()
{
return $this->comment;
}
/**
* Set physid
*/
public function setPhysid($value)
{
$this->physid = $value;
}
/**
* Get physid
*/
public function getPhysid()
{
return $this->physid;
}
/**
* Set driver
*/
public function setDriver($value)
{
$this->driver = $value;
}
/**
* Get driver
*/
public function getDriver()
{
return $this->driver;
}
/**
* Set driverversion
*/
public function setDriverversion($value)
{
$this->driverversion = $value;
}
/**
* Get driverversion
*/
public function getDriverversion()
{
return $this->driverversion;
}
/**
* Set description
*/
public function setDescription($value)
{
$this->description = $value;
}
/**
* Get description
*/
public function getDescription()
{
return $this->description;
}
/**
* Set xmlId
*/
public function setXmlId($value)
{
$this->xmlId = $value;
}
/**
* Get xmlId
*/
public function getXmlId()
{
return $this->xmlId;
}
/**
* Set class
*/
public function setClass($value)
{
$this->class = $value;
}
/**
* Get class
*/
public function getClass()
{
return $this->class;
}
/**
* Set handle
*/
public function setHandle($value)
{
$this->handle = $value;
}
/**
* Get handle
*/
public function getHandle()
{
return $this->handle;
}
/**
* Set parentHandle
*/
public function setParentHandle($value)
{
$this->parentHandle = $value;
}
/**
* Get parentHandle
*/
public function getParentHandle()
{
return $this->parentHandle;
}
/**
* Set hostId
*/
public function setHostId($value)
{
if ($value)
{
// $em instanceof EntityManager
$em = Zend_Registry::get('Doctrine_Entity_Manager');
if (is_object($value))
{
$obj = $value;
} else {
$obj = $em->find('shellyHost', (int) $value);
}
if ($obj)
{
$this->hostId = $obj;
} else {
$this->hostId = null;
}
} else {
$this->hostId = null;
}
}
/**
* Get hostId
*/
public function getHostId()
{
return ((is_object($this->hostId))?$this->hostId->getId():'');
}
/**
* Get host object
*/
public function getHost()
{
return ((is_object($this->hostId))?$this->hostId:'');
}
/**
* Get HostIdValue
*/
public function getHostIdValue()
{
return ((is_object($this->hostId))?$this->hostId->getName():'');
}
/**
* Get Fields List
*/
public function getFieldsList()
{
$arr = array();
foreach ($this AS $field_name => $field_value)
{
if (!in_array($field_name, array('id', 'capabilities'))) $arr[] = $field_name;
}
return $arr;
}
/**
* Get object as array
*/
public function toArray()
{
$arr = array();
foreach ($this AS $field_name => $field_value)
{
$method_name = 'get'.ucfirst($field_name);
if (method_exists($this, $method_name))
$arr[(string) $field_name] = $this->{$method_name}($field_value);
}
return $arr;
}
/**
* Set object as array
*/
public function fromArray($arr)
{
foreach ($this AS $field_name => $field_value)
{
$method_name = 'set'.ucfirst($field_name);
if (method_exists($this, $method_name) && isset($arr[(string) $field_name]))
{
$this->{$method_name}($arr[(string) $field_name]);
}
}
return true;
}
/**
* Shelly functions
*/
/**
* Run cmd
*/
function cmd()
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment