Skip to content

Instantly share code, notes, and snippets.

@pumatertion
Created March 7, 2014 10:12
Show Gist options
  • Save pumatertion/9408942 to your computer and use it in GitHub Desktop.
Save pumatertion/9408942 to your computer and use it in GitHub Desktop.
<?php
/* *
* This script belongs to the TYPO3 Flow package "BLEICKER.ArtManager.Structure". *
* *
* */
namespace BLEICKER\ArtManager\Structure\Domain\Model;
use TYPO3\Flow\Annotations as Flow;
use Doctrine\ORM\Mapping as ORM;
/**
* @Flow\Entity
*/
class Artist {
/**
* @var string
* @ORM\Id
* @ORM\Column(length=40)
*/
protected $id;
/**
* @var string
* @ORM\Id
* @ORM\Column(length=40)
*/
protected $workspace;
/**
* @param string $id
* @param string $workspace
*/
public function __construct($id, $workspace) {
$this->id = $id;
$this->workspace = $workspace;
}
/**
* @return string
*/
public function getId() {
return $this->id;
}
/**
* @return string
*/
public function getWorkspace() {
return $this->workspace;
}
}
<?php
/* *
* This script belongs to the TYPO3 Flow package "BLEICKER.ArtManager.Structure". *
* *
* */
namespace BLEICKER\ArtManager\Structure\Domain\Model;
use TYPO3\Flow\Annotations as Flow;
use Doctrine\ORM\Mapping as ORM;
/**
* @Flow\Entity
*/
class Artwork {
/**
* @var string
* @ORM\Id
* @ORM\Column(length=40)
*/
protected $id;
/**
* @var string
* @ORM\Id
* @ORM\Column(length=40)
*/
protected $workspace;
/**
* @var Artist
* @ORM\ManyToOne
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="ArtistId", referencedColumnName="id"),
* @ORM\JoinColumn(name="WorkspaceId", referencedColumnName="workspace")
* })
*/
protected $artist;
/**
* @param string $id
* @param string $workspace
*/
public function __construct($id, $workspace, Artist $artist) {
$this->id = $id;
$this->workspace = $workspace;
$this->artist = $artist;
}
/**
* @return string
*/
public function getId() {
return $this->id;
}
/**
* @return string
*/
public function getWorkspace() {
return $this->workspace;
}
/**
* @return Artist
*/
public function getArtist() {
return $this->artist;
}
}
?>
<?php
namespace BLEICKER\ArtManager\Structure\Command;
/* *
* This script belongs to the TYPO3 Flow package "BLEICKER.ArtManager.Structure".*
* *
* */
use BLEICKER\ArtManager\Structure\Domain\Model\Artwork;
use BLEICKER\ArtManager\Structure\Domain\Model\Artist;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Persistence\PersistenceManagerInterface;
/**
* @Flow\Scope("singleton")
*/
class TestCommandController extends \TYPO3\Flow\Cli\CommandController {
/**
* @var PersistenceManagerInterface
* @Flow\Inject
*/
protected $persistenceManager;
/**
* @return void
*/
public function createCommand() {
$artist = new Artist('foo', 'Acme.Foo');
$this->persistenceManager->add($artist);
$artwork = new Artwork('bar', 'Acme.Foo', $artist);
$this->persistenceManager->add($artwork);
$this->persistenceManager->persistAll();
}
/**
* @return void
*/
public function fetchCommand() {
$clientEntity = $this->persistenceManager->getObjectByIdentifier(array('id' => 'foo', 'workspace' => 'Acme.Foo'), 'BLEICKER\ArtManager\Structure\Domain\Model\Artist');
\TYPO3\Flow\var_dump($clientEntity, __CLASS__ . '#' . __LINE__, FALSE, TRUE);
$artwork = $this->persistenceManager->getObjectByIdentifier(array('id' => 'bar', 'workspace' => 'Acme.Foo'), 'BLEICKER\ArtManager\Structure\Domain\Model\Artwork');
\TYPO3\Flow\var_dump($artwork, __CLASS__ . '#' . __LINE__, FALSE, TRUE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment