Skip to content

Instantly share code, notes, and snippets.

@christianjul
Created October 6, 2012 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianjul/3844492 to your computer and use it in GitHub Desktop.
Save christianjul/3844492 to your computer and use it in GitHub Desktop.
Simple commandcontroller and aspect to demo how to use 3rd party components - and AOP on it - in TYPO3 Flow
<?php
namespace Julle\Demo\Command;
/* *
* This script belongs to the TYPO3 Flow package "Julle.Demo". *
* *
* */
use TYPO3\Flow\Annotations as Flow;
/**
* dostuff command controller for the Julle.Demo package
*
* @Flow\Scope("singleton")
*/
class DostuffCommandController extends \TYPO3\Flow\Cli\CommandController {
/**
* A demo command
*
* This is small example of how to utilize 3rd part components in TYPO3 Flow, initializes a Monolog-Logger and reads
* it's name to the output.
*
* @param string $requiredArgument This argument is required
* @return void
*/
public function exampleCommand($requiredArgument) {
$logger = new \Monolog\Logger($requiredArgument);
$this->outputLine($logger->getName());
}
}
?>
These files are just examples, they need to be in context of a full package to be execute. You can easily create these with the TYPO3.Kickstart package.
Path of files relative to Packages/Application folder
Julle.Demo/Classes/Julle/Demo/Command/DostuffCommandController.php
EvilCorp.WorldDomination/Classes/EvilCorp/WorldDomination/Aspect/LoggerAspect.php
<?php
namespace EvilCorp\WorldDomination\Aspect;
/* *
* This script belongs to the TYPO3 Flow package "Julle.Demo". *
* *
* */
use TYPO3\Flow\Annotations as Flow;
/**
* Standard controller for the Julle.Demo package
*
* @Flow\Aspect
*/
class LoggerAspect {
/**
* @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint
* @Flow\Before("method(Monolog\Logger->__construct())")
*
* @return void
*/
public function checkLoggerName(\TYPO3\Flow\Aop\JoinPointInterface $joinpoint) {
$realname = $joinpoint->getMethodArgument('name');
$joinpoint->setMethodArgument('name','I Rule Everything! Screw your "' . $realname . '"!');
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment