Jump to content

Symfony PHP workflow Toolkit

Recommended Posts

I worked with small PHP scripts to write my own workflows and noticed that I often would do the same jobs with every script again, so I decided to build a little toolkit around the Symfony 4.1 Command component. It provides a way to seamless have different states for Autocompletion and an easy way to configure variables that you can use in your script (saves it to .env file).


As a proof-of-concept I wrote a movie-rating workflow in which you can rate your movie in different categories. The PHP-Code is as short as this command:

class MovieRatingCommand extends AlfredInteractiveContainerAwareCommand
    protected function configure()
            ->addArgument('category', InputArgument::OPTIONAL)
            ->addArgument('stars', InputArgument::OPTIONAL)
            ->addArgument('movie', InputArgument::OPTIONAL + InputArgument::IS_ARRAY);
    protected function initialize(InputInterface $input, OutputInterface $output)
        $stars = $this->getContainer()->getParameter('stars');
        $categories = $this->getContainer()->getParameter('categories');
        $filename = $this->getContainer()->getParameter('filename');
        $sheetname = $this->getContainer()->getParameter('sheetname');
        $tablename = $this->getContainer()->getParameter('tablename');
        $this->addArgumentsAllowedValues('stars', $stars);
        $this->addArgumentsAllowedValues('category', $categories);
        $this->addInputHandler(['category', 'stars'], function () {
            $workflow = new WorkflowResult();
            $workflow->setTitle('Insert movie name to rate');
            return [$workflow];
        $showQuestions = function ($arguments) use ($categories, $filename, $sheetname, $tablename) {
            $movie = $arguments['movie'];
            $category = $arguments['category'];
            $stars = $arguments['stars'];
            if (!is_array($stars)) {
                $result = new WorkflowResult();
                $result->setTitle('Rate ' . $movie . ' - ' . $category . ': ' . $stars . ' stars');
                $result->setSubtitle('Rate ' . $movie . ' in category "' . $category . '": ' . $stars . ' stars');
                $result->setLargetype('Rate ' . $movie . ' in category "' . $category . '": ' . $stars . ' stars');
                    'movie'       => $movie,
                    'currentdate' => (new \DateTime())->format('d.m.Y'),
                    'category'    => $category,
                    'stars'       => $stars,
                $this->workflowHelper->variable('movie', $movie);
                $this->workflowHelper->variable('currentdate', (new \DateTime())->format('d.m.Y'));
                $this->workflowHelper->variable('category', iconv("ISO-8859-1", "UTF-8", utf8_decode($category)));
                $this->workflowHelper->variable('stars', $stars);
                $this->workflowHelper->variable('filename', $filename ?: null);
                $this->workflowHelper->variable('sheetname', $sheetname ?: null);
                $this->workflowHelper->variable('tablename', $tablename ?: null);
                return [$result];
        $this->addInputHandler(['category', 'stars', 'movie'], $showQuestions);


You can find the Proof-of-concept here: https://github.com/dpeuscher/alfred-movie-rating.

The Alfred-Symfony Toolkit can be found here: https://github.com/dpeuscher/alfred-symfony-tools. You can also use this composer command to use it: 

composer req dpeuscher/alfred-symfony-tools

Thoughts, ideas, contributions are highly appreciated.




Edited by dpeuscher
update link
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...