Last active
August 29, 2015 14:01
-
-
Save elnur/36cd4f5d28606acb2477 to your computer and use it in GitHub Desktop.
Symfony Without Bundles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jms_di_extra: | |
locations: | |
directories: "%kernel.root_dir%/../src" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doctrine: | |
# ... | |
orm: | |
auto_generate_proxy_classes: "%kernel.debug%" | |
mappings: | |
model: | |
type: annotation | |
dir: "%kernel.root_dir%/../src/Example/Model" | |
prefix: Example\Model | |
alias: Model | |
is_bundle: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
site: | |
resource: Example\Controller\UserController | |
type: annotation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
user_manager: | |
class: Example\Manager\UserManager | |
arguments: | |
- "@user_repository" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Example\Model; | |
use Doctrine\ORM\Mapping\Column; | |
use Doctrine\ORM\Mapping\Entity; | |
use Doctrine\ORM\Mapping\GeneratedValue; | |
use Doctrine\ORM\Mapping\Id; | |
/** | |
* @Entity | |
*/ | |
class User | |
{ | |
/** | |
* @Id | |
* @GeneratedValue | |
* @Column(type="bigint") | |
* | |
* @var int | |
*/ | |
private $id; | |
/** | |
* @return int | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Example\Controller; | |
use Example\Manager\UserManager; | |
use Example\Model\User; | |
use JMS\DiExtraBundle\Annotation\InjectParams; | |
use JMS\DiExtraBundle\Annotation\Service; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
/** | |
* @Service("user_controller") | |
* @Route("/user", service="user_controller") | |
*/ | |
class UserController | |
{ | |
/** | |
* @var UserManager | |
*/ | |
private $userManager; | |
/** | |
* @InjectParams | |
* | |
* @param UserManager $userManager | |
*/ | |
public function __construct(UserManager $userManager) | |
{ | |
$this->userManager = $userManager; | |
} | |
/** | |
* @Route("/{id}") | |
* | |
* @param int $id | |
* @return User | |
*/ | |
public function viewAction($id) | |
{ | |
return $this->userManager->find($id); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Example\Controller; | |
use Example\Manager\UserManager; | |
use Example\Model\User; | |
use JMS\DiExtraBundle\Annotation\InjectParams; | |
use JMS\DiExtraBundle\Annotation\Service; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
/** | |
* @Service("user_controller") | |
* @Route("/user", service="user_controller") | |
*/ | |
class UserController | |
{ | |
/** | |
* @var UserManager | |
*/ | |
private $userManager; | |
/** | |
* @InjectParams | |
* | |
* @param UserManager $userManager | |
*/ | |
public function __construct(UserManager $userManager) | |
{ | |
$this->userManager = $userManager; | |
} | |
/** | |
* @Route("/{id}") | |
* @Template | |
* | |
* @param int $id | |
* @return User | |
*/ | |
public function viewAction($id) | |
{ | |
return [ | |
'user' => $this->userManager->find($id), | |
]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Example\Manager; | |
use Example\Model\User; | |
use Example\Repository\UserRepository; | |
class UserManager | |
{ | |
/** | |
* @var UserRepository | |
*/ | |
private $userRepository; | |
/** | |
* @param UserRepository $userRepository | |
*/ | |
public function __construct(UserRepository $userRepository) | |
{ | |
$this->userRepository = $userRepository; | |
} | |
/** | |
* @param int $id | |
* @return User | |
*/ | |
public function find($id) | |
{ | |
return $this->userRepository->find($id); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Example\Manager; | |
use Example\Model\User; | |
use Example\Repository\UserRepository; | |
use JMS\DiExtraBundle\Annotation\InjectParams; | |
use JMS\DiExtraBundle\Annotation\Service; | |
/** | |
* @Service("user_manager") | |
*/ | |
class UserManager | |
{ | |
/** | |
* @var UserRepository | |
*/ | |
private $userRepository; | |
/** | |
* @InjectParams | |
* | |
* @param UserRepository $userRepository | |
*/ | |
public function __construct(UserRepository $userRepository) | |
{ | |
$this->userRepository = $userRepository; | |
} | |
/** | |
* @param int $id | |
* @return User | |
*/ | |
public function find($id) | |
{ | |
return $this->userRepository->find($id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment