당신이 Unit of Work 패턴으로 봤어 :
는 나는 당신이 체크 아웃 할 수있다이 모듈의 기준으로 생각?
다음은 실제로 시작하는 방법에 대한 근본적인 예입니다.
기본 UnitOfWork 컨테이너입니다.
class UnitOfWork
{
protected $entities = array();
protected $completed = array();
final public function addEntity(IWorkUnitEntity $entity)
{
$this->entities[] = $entity;
}
final public function execute()
{
try {
foreach ($this->entities as $entity)
{
$entity->execute();
$completed[] = $entity;
}
}
catch (UnitOfWorkRollbackException $e)
{
$this->rollbackCompleted();
}
return $this->commitAll();
}
protected function rollbackCompleted()
{
while ($entity = array_pop($this->completed))
{
$entity->rollback();
}
}
protected function commitAll()
{
try {
foreach ($this->entities as $entity)
{
$entity->commit();
}
}
catch (UnitOfWorkRollbackException $e)
{
$this->rollbackCompleted();
return false;
}
return true;
}
}
몇 엑스트라는 모두 함께 퍼팅 지금
class UnitOfWorkRollbackException extends Exception {};
interface IWorkUnitEntity
{
public function execute();
public function rollback();
}
함께 작업 개체
class FileMoverEntity implements IWorkUnitEntity
{
protected
$source
, $destination
, $newName
;
public function __construct($source, $destination, $newName = null)
{
$this->source = $source;
$this->destination = dirname($destination);
$this->newName = $newName;
}
public function execute()
{
if (is_readable($this->source) && is_writable($this->destination))
{
return true;
}
throw new UnitOfWorkRollbackException('File cannot be moved');
}
public function commit()
{
$filename = (null === $this->newName)
? basename($this->source)
: $this->newName
;
if (!rename($this->source, $this->destination . DIRECTORY_SEPARATOR . $filename))
{
throw new UnitOfWorkRollbackException('File move failed');
}
}
public function rollback()
{
// Nothing to do here since the file doesn't actually move until commit()
}
}
의 예를이를 수 있도록 도와줍니다.클라이언트 스크립트가 해당 정보에 액세스 할 수 있도록 예외가 발생 된 추적을 유지하는 등의 - -
$UoW = new UnitOfWork();
$UoW->addEntity(new FileMoverEntity('/tmp/foo', '/home/me', 'profile.jpg'));
$UoW->addEntity(new FileMoverEntity('/tmp/bar', '/root', 'profile.jpg'));
if ($UoW->execute())
{
// all operations successful
}
는 지금, 나는 여기에해야하는 몇 가지 일을하지 않았다하지만 난 당신이 아이디어를 얻을 생각합니다. 물론 모든 작업 (DB 업데이트, API 호출 등)을위한 작업 항목을 만들 수 있습니다.
트랜잭션 안전 테이블이없는 데이터베이스에 연결하는 관점에서 통찰력은 없습니다.
당신이 묘사하는 것은 정확히 어떤 거래를위한 것입니까? "고객 지원"이 의미하는 바를 이해하지 못합니까? –
내 소프트웨어 사용자가 서버에서 InnoDB를 사용할 수 있는지 여부를 모르겠다. 나는 그것이 꺼져 있다고 가정 할 필요가있다. – Workoholic