This repository has been archived by the owner on Dec 5, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from liip/varnish_invalidate_command
Varnish invalidate command
- Loading branch information
Showing
6 changed files
with
132 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace Liip\CacheControlBundle\Command; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
use Psr\Log\LoggerInterface; | ||
use Psr\Log\NullLogger; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
|
||
|
||
/** | ||
* Importing zips to cooperatives mapping | ||
*/ | ||
class InvalidateVarnishCommand extends ContainerAwareCommand | ||
{ | ||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
/** | ||
* Configures the current command. | ||
* | ||
* @return void | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('liip:cache-control:varnish:invalidate') | ||
->setDescription('Clear cached entries from Varnish servers') | ||
->addArgument( | ||
'path', | ||
InputArgument::OPTIONAL, | ||
'What URLs do you want to invalidate? (default: .)' | ||
); | ||
} | ||
|
||
/** | ||
* Executes the current command. | ||
* | ||
* @param InputInterface $input Input | ||
* @param OutputInterface $output Output | ||
* | ||
* @return void | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$container = $this->getContainer(); | ||
|
||
$this->logger = $container->get('logger'); | ||
$helper = $this->getContainer()->get('liip_cache_control.varnish'); | ||
|
||
$path = $input->getArgument('path'); | ||
if (!$path) { | ||
$path = "."; | ||
} | ||
$this->getLogger()->notice('Starting clearing varnish with path: "' . $path .'"'); | ||
|
||
$helper->invalidatePath($path); | ||
|
||
$this->getLogger()->notice('Done clearing varnish'); | ||
} | ||
|
||
/** | ||
* Returns the logger | ||
* | ||
* @return LoggerInterface | ||
*/ | ||
protected function getLogger() | ||
{ | ||
if (null == $this->logger) { | ||
$this->logger = new NullLogger(); | ||
} | ||
|
||
return $this->logger; | ||
} | ||
} |
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
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
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
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
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