Last active
November 23, 2017 12:25
-
-
Save silvioq/cb5f3dd3b3842491f3afc6fdd16cb45c to your computer and use it in GitHub Desktop.
Las interfaces más comunes para los servicios symfony
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
@logger: Psr\Log\LoggerInterface | |
@templating: Symfony\Component\Templating\EngineInterface | |
@doctrine.orm.entity_manager: Doctrine\ORM\EntityManagerInterface # implementa todas las funciones DQL | |
@doctrine.orm.entity_manager: Doctrine\Common\Persistence\ObjectManager # implementa las funciones de persistencia | |
@cache.app: Psr\Cache\CacheItemPoolInterface | |
@security.token_storage: Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface | |
@security.authorization_checker: Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface | |
@security.access.decision_manager: Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface | |
@translator: Symfony\Component\Translation\TranslatorInterface; | |
@router: Symfony\Component\Routing\RouterInterface ó Symfony\Component\Routing\Generator\UrlGeneratorInterface | |
@request_stack: Symfony\Component\HttpFoundation\RequestStack |
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
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | |
use Silvioq\Component\AdminTool\Form\EntityHiddenType; | |
deprecated => use Silvioq\ThemeLTEBundle\Form\DateType; | |
use Symfony\Component\Form\Extension\Core\Type; | |
Type\HiddenType; | |
Type\ChoiceType; | |
Type\TextType; |
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 App | |
use Psr\Cache\CacheItemPoolInterface; | |
class Algunacosa | |
{ | |
/** @var CacheItemPoolInterface */ | |
private $cache; | |
const CACHENAME_ALGUNACOSA = 'app.algunacosa'; | |
const EXPIRATION = 60 * 60 * 24; // un día | |
public function __construct( CacheItemPoolInterface $cache ) | |
{ | |
$this->cache = $cache; | |
} | |
/** | |
* @return int | |
*/ | |
public function countAlgunacosa() | |
{ | |
$item = $this->cache->getItem( self::CACHENAME_ALGUNACOSA ); | |
if( $item->isHit() ) | |
{ | |
return $item->get(); | |
} | |
else | |
{ | |
$count = $this->calculateAlgunacosa(); | |
$item | |
->set($count) | |
->expiresAfter( self::EXPIRATION ) | |
; | |
$this->cache->save($item); | |
return $count; | |
} | |
} | |
private function calculateAlgunacosa() | |
{ | |
// heavy calculation | |
} | |
} | |
// vim:sw=4 ts=4 sts=4 et |
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 Casa\AsistencialBundle\Command; | |
use Symfony\Component\Console\Command\Command; | |
use Symfony\Component\Console\Input\InputArgument; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Output\OutputInterface; | |
use Symfony\Component\Console\Style\SymfonyStyle; | |
class EjemploCommand extends Command | |
{ | |
private $servicio; | |
public function __construct( $servicio ) | |
{ | |
$this->servicio = $servicio; | |
parent::__construct(); | |
} | |
protected function configure() | |
{ | |
$this->setName( 'ejemplo:lectura:archivo' ) | |
->setDescription( 'Lectura de archivo' ) | |
->addArgument( 'file', InputArgument::REQUIRED, "Archivo a procesar" ) | |
->addOption( 'process', null, InputOption::VALUE_NONE, "Indica que debe procesarse el archivo" ) | |
; | |
} | |
protected function execute( InputInterface $input, OutputInterface $output) | |
{ | |
$file = $input->getArgument( 'file' ); | |
$process = $input->getOption( 'process' ); | |
$io = new SymfonyStyle( $input, $output ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment