$process->run();
$process->mustRun();
php -i
в консоле и так:$process = new \Symfony\Component\Process\Process("php -i");
$process->run();
return new Response($process->getOutput());
/**
* @Route("/cpanel/{p}", defaults={"p" = "start"})
* @Template()
*/
public function cpanelAction($p=null, Request $r){
return array("p"=>$p);
}
class SomeService
/**
* @var \Symfony\Bundle\FrameworkBundle\Templating\EngineInterface
*/
private $templating;
public function __construct(EngineInterface $templating)
{
$this->templating = $templating;
}
public function doSome()
{
$template = $this->templating->render('AppBundle::foo.html.twig', array(
'foo' => 'bar'
));
}
services:
app.service.foo:
class: %app.service.foo.class%
arguments:
- @templating
entity_managers:
default:
dql:
string_functions:
GROUP_CONCAT: DoctrineExtensions\Query\Mysql\GroupConcat
symfony.com/doc/current/cookbook/controller/servic...
В настройках роута надо заменитьdefaults: { _controller: TestTestBundle:Test:index }
наdefaults: { _controller: test:indexAction }
$builder
->add(
$builder->create('destination', 'text', array(
'attr' => array(
'class' => 'select_station'
)
))
->addModelTransformer(new EntityToStringTransformer(
$options['em'],
'Acme\DemoBundle\Entity\Station',
'id'
)
)
)
;
defaults: { _controller: TestTestBundle:Test:index }
defaults: { _controller: test:indexAction }
interface VotableInterface
{
public function setRating($rating);
}
class Object implements VotableInterface
{
/**
* @ORM\Column(type="integer")
*/
private $rating;
public function setRating($rating)
{
$this->rating = $rating;
}
public function getRating()
{
return $this->rating;
}
}
class VoteListener
{
public function postPersist(LifecycleEventArgs $event)
{
$vote = $event->getEntity();
if (!$vote instanceof Vote) {
return;
}
/**
* @var Object $entity
*/
$entity = $vote->getEntityObject();
if (!$entity instanceof VotableInterface) {
// Exception
}
$entity->setRating($entity->getRating() + $vote->getValue());
// Update $entity
}
}
{{ object_path(entity) }}
$compiledRoute = $route->compile();
$variables = $compiledRoute->getVariables();
$parameters = array();
if (!empty($variables)) {
foreach ($variables as $variable) {
$parameters[$variable] = $this->getObjectProperty($object, $variable);
}
}
return $this->router->generate($name, $parameters);
{{ object_path('route_name', entity) }}
Все необходимые параметры возьмутся из модели. Удобно для CRUD getRequest()
и getDoctrine()
$this->getDoctrine()->getManager()->getRepository('...')
сам пока не решил. class LogListener implements EventSubscriber
{
private $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function getSubscribedEvents()
{
return array(Events::postUpdate, Events::postPersist, Events::preRemove);
}
public function postUpdate(LifecycleEventArgs $eventArgs)
{
$this->log($eventArgs, Log::ACTION_UPDATE);
}
public function postPersist(LifecycleEventArgs $eventArgs)
{
$this->log($eventArgs, Log::ACTION_PERSIST);
}
public function preRemove(LifecycleEventArgs $eventArgs)
{
$this->log($eventArgs, Log::ACTION_REMOVE);
}
private function log(LifecycleEventArgs $eventArgs, $action)
{
$token = $this->container->get('security.context')->getToken();
if (!$token) {
return;
}
$user = $token->getUser();
if (!($user instanceof User)) {
return;
}
$entity = $eventArgs->getEntity();
if ($entity instanceof Log) {
return;
}
$request = $this->container->get('request');
$log = new Log();
$log->setAction($action);
$log->setUser($user);
$log->setIp($request->server->get('REMOTE_ADDR'));
$log->setEntityClass(get_class($entity));
$log->setEntityId($entity->getId());
$em = $this->container->get('doctrine')->getEntityManager();
$meta = $em->getClassMetadata(get_class($log));
$conn = $em->getConnection();
foreach ($meta->getReflectionProperties() as $fieldName => $reflProp) {
if (!$meta->isIdentifier($fieldName)) {
$columns[] = $fieldName;
$values[] = ':' . $fieldName;
}
}
$insertSql = 'INSERT INTO ' . $meta->getQuotedTableName($conn->getDatabasePlatform())
. ' (' . implode(', ', $columns) . ') '
. 'VALUES (' . implode(', ', $values) . ')';
$stmt = $conn->prepare($insertSql);
$fields = $meta->getFieldNames();
$association = $meta->getAssociationNames();
foreach ($meta->getReflectionProperties() as $fieldName => $reflProp) {
if (!$meta->isIdentifier($fieldName)) {
$value = $reflProp->getValue($log);
if (in_array($fieldName, $fields)) {
$mapping = $meta->getFieldMapping($fieldName);
$stmt->bindValue($meta->getColumnName($fieldName), $value, $mapping['type']);
} else if (in_array($fieldName, $association)) {
$classMeta = $em->getClassMetadata($meta->getAssociationTargetClass($fieldName));
list($classId) = $classMeta->getIdentifier();
$mapping = $classMeta->getFieldMapping($classId);
$associationIdProperty = $classMeta->getReflectionProperty($classId);
$associationValue = $associationIdProperty->getValue($value);
$stmt->bindValue($meta->getColumnName($fieldName), $associationValue, $mapping['type']);
} else {
throw new \Exception('Exception in log listener');
}
}
}
$stmt->execute();
}
}