Skip to content

Instantly share code, notes, and snippets.

@pumatertion
Last active August 29, 2015 13:57
Show Gist options
  • Save pumatertion/9763893 to your computer and use it in GitHub Desktop.
Save pumatertion/9763893 to your computer and use it in GitHub Desktop.
<?php
// i wished something like this would work
$serializable = new SerializableDto();
$serializable->setFoo('Acme.Foo')->setBar(1)->setBaz(array('product1', '11.00 €', 'UPS'));
$order = new SerializableDtoOwner();
$order->setSerializableDto($serializable);
$this->persistenceManager->add($order);
$this->persistenceManager->persistAll();
?>
<?php
/* *
* This script belongs to the TYPO3 Flow framework. *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License, either version 3 *
* of the License, or (at your option) any later version. *
* *
* The TYPO3 project - inspiring people to share! *
* */
namespace BLEICKER\ArtManager\Structure\Domain\Model;
use TYPO3\Flow\Utility\Arrays;
/**
* Class SerializableDto
*
* @package BLEICKER\ArtManager\Structure\Domain\Model
*/
class SerializableDto implements \Serializable {
/**
* @var string
*/
protected $foo;
/**
* @var integer
*/
protected $bar;
/**
* @var array
*/
protected $baz;
public function __construct() {
$this->baz = array();
}
/**
* @param integer $bar
* @return $this
*/
public function setBar($bar) {
$this->bar = $bar;
return $this;
}
/**
* @return integer
*/
public function getBar() {
return $this->bar;
}
/**
* @param array $baz
* @return $this
*/
public function setBaz(array $baz) {
$this->baz = $baz;
return $this;
}
/**
* @return array
*/
public function getBaz() {
return $this->baz;
}
/**
* @param string $foo
* @return $this
*/
public function setFoo($foo) {
$this->foo = $foo;
return $this;
}
/**
* @return string
*/
public function getFoo() {
return $this->foo;
}
/**
* (PHP 5 &gt;= 5.1.0)
* String representation of object
*
* @link http://php.net/manual/en/serializable.serialize.php
* @return string the string representation of the object or null
*/
public function serialize() {
return serialize(
array(
'foo' => $this->getFoo(),
'foo' => $this->getBar(),
'baz' => $this->getBaz()
)
);
}
/**
* (PHP 5 &gt;= 5.1.0)
* Constructs the object
*
* @link http://php.net/manual/en/serializable.unserialize.php
* @param string $serialized <p>
* The string representation of the object.
* </p>
* @return void
*/
public function unserialize($serialized) {
$mappingDate = unserialize($serialized);
$this->setFoo(Arrays::getValueByPath($mappingDate, 'foo'));
$this->setFoo(Arrays::getValueByPath($mappingDate, 'bar'));
$this->setFoo(Arrays::getValueByPath($mappingDate, 'baz'));
}
}
?>
<?php
/* *
* This script belongs to the TYPO3 Flow framework. *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License, either version 3 *
* of the License, or (at your option) any later version. *
* *
* The TYPO3 project - inspiring people to share! *
* */
namespace BLEICKER\ArtManager\Structure\Domain\Model;
use TYPO3\Flow\Annotations as Flow;
use Doctrine\ORM\Mapping as ORM;
/**
* Class SerializableDtoOwner
*
* @package BLEICKER\ArtManager\Structure\Domain\Model
* @Flow\Entity
*/
class SerializableDtoOwner {
/**
* @var SerializableDto
* @ORM\Column(type="object")
*/
protected $serializableDto;
/**
* @param SerializableDto $serializableDto
* @return $this
*/
public function setSerializableDto(SerializableDto $serializableDto) {
$this->serializableDto = $serializableDto;
return $this;
}
/**
* @return SerializableDto
*/
public function getSerializableDto() {
return $this->serializableDto;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment