Skip to content

Instantly share code, notes, and snippets.

@MacDada
Created June 17, 2014 23:12
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 MacDada/9459c182ac40cd35bd22 to your computer and use it in GitHub Desktop.
Save MacDada/9459c182ac40cd35bd22 to your computer and use it in GitHub Desktop.
BackupFactory
<?php
class BackupFactory
{
public function __construct($configOption1, $configOption2);
public function create(Entity $entity)
{
return new Backup($configOption1, $configOption2, $entity);
}
}
<?php
class Command
{
public function __construct(BackupFactory $backupFactory);
public function run(Entity $entity)
{
$backup = $this->backupFactory->create($entity);
try {
// work with $entity
} catch (Exception $e) {
$backup->restore();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment