Skip to content

Instantly share code, notes, and snippets.

@DavertMik
Created March 15, 2012 01:30
Show Gist options
  • Save DavertMik/2041039 to your computer and use it in GitHub Desktop.
Save DavertMik/2041039 to your computer and use it in GitHub Desktop.
Slicework with Symfony2

Slivework is a new metaframework which aims to share functinality through different PHP frameworks. It takes business logic from controller to service classes. The service layer leaves all http processing to current framework and moves all business into it. Controllers are forbidden to access database directly, all db operations is passed to service. Sliceworks uses Doctrine ORM + ODM.

Slicework in Symfony 2

  1. Each slice is a Symfony2 bundle

src/Slicework/UserBundle/ src/Slicework/UserMessagingBundle/ src/Slicework/UserInvitesBundle/ ....

Directory structure

- Dependency

- Slice
-- UserService

- Repository

- Entitiy
-- model
-- model
-- model
  1. Each independent slice is installed in this bundle by symfony command.

./app/sf slice:install UserMessaging

  1. Schema should be updated

  2. Each Slice can be extended in any other bundle MyBundle/Slice/UserService < Slicework/Slice/UserService

  3. In controller you can use a service.

<?php 

class PageController {

		protected $service
	

		function createAction($name, $body) {
			$this->service = $this->container->get('slice.page_service');
			$page_id = $this->service
				->doBefore(function($page) { $page->setCreatedBy('user'); })
				->doAfterUpdateAuthorProfile($user)
				->create($name, $body);

			return $this->render('AcmeHelloBundle:Hello:index.html.twig', array('page' => $this->service->fetch($page_id)));				
	}

}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment