<commit_before><?php

namespace Phansible\Controller;

use Flint\Controller\Controller;
use Phansible\Application;
use Phansible\Model\VagrantBundle;
use Phansible\Renderer\PlaybookRenderer;
use Phansible\Renderer\TemplateRenderer;
use Phansible\Renderer\VagrantfileRenderer;
use Phansible\Renderer\VarfileRenderer;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
 * @package Phansible
 */
class BundleController extends Controller
{
    protected $phpPackages = [];

    public function indexAction(Request $request, Application $app)
    {
        $vagrant = new VagrantBundle($this->get('ansible.path'));
        $this->setPhpPackages($request->get('phppackages', array()));

        /** Get Inventory */
        $inventory = $this->getInventory($request);

        /** Get Vagrantfile */
        $vagrantfile = $this->getVagrantfile($request);

        /** Get Playbook */
        $playbook = $this->getPlaybook($request);

        $this->setupMysql($playbook, $request);
        $this->setupComposer($playbook, $request);
        $this->setupXDebug($playbook, $request);

        /** Configure Variable files - common */
        $box = $this->getBox($vagrantfile->getBoxName());

        $playbook->createVarsFile('common', [
                'php_ppa'      => $request->get('phpppa'),
                'doc_root'     => $request->get('docroot'),
                'sys_packages' => $request->get('syspackages', array()),
                'timezone'     => $request->get('timezone'),
                'dist'         => $box['deb'],
                'php_packages' => $this->getPhpPackages()
        ]);

        $playbook->addRole('phpcommon');

        $vagrant->setRenderers($playbook->getVarsFiles());
        $vagrant->addRenderer($playbook);
        $vagrant->addRenderer($vagrantfile);
        $vagrant->addRenderer($inventory);

        $tmpName = 'bundle_' . time();
        $zipPath = sys_get_temp_dir() . "/$tmpName.zip";

        if ($vagrant->generateBundle($zipPath, $playbook->getRoles())) {

            return $this->outputBundle($zipPath, $app, $vagrantfile->getName());

        } else {

            return new Response('An error occurred.');
        }
    }

    /**
     * @param PlaybookRenderer $playbook
     * @param Request $request
     */
    public function setupMysql(PlaybookRenderer $playbook, Request $request)
    {
        /** Databases */
        if ($request->get('database-status')) {
            $playbook->addRole('mysql');

            $mysqlVars = new VarfileRenderer('mysql');<commit_msg>remove else in favor of just return<commit_after><?php

namespace Phansible\Controller;

use Flint\Controller\Controller;
use Phansible\Application;
use Phansible\Model\VagrantBundle;
use Phansible\Renderer\PlaybookRenderer;
use Phansible\Renderer\TemplateRenderer;
use Phansible\Renderer\VagrantfileRenderer;
use Phansible\Renderer\VarfileRenderer;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
 * @package Phansible
 */
class BundleController extends Controller
{
    protected $phpPackages = [];

    public function indexAction(Request $request, Application $app)
    {
        $vagrant = new VagrantBundle($this->get('ansible.path'));
        $this->setPhpPackages($request->get('phppackages', array()));

        /** Get Inventory */
        $inventory = $this->getInventory($request);

        /** Get Vagrantfile */
        $vagrantfile = $this->getVagrantfile($request);

        /** Get Playbook */
        $playbook = $this->getPlaybook($request);

        $this->setupMysql($playbook, $request);
        $this->setupComposer($playbook, $request);
        $this->setupXDebug($playbook, $request);

        /** Configure Variable files - common */
        $box = $this->getBox($vagrantfile->getBoxName());

        $playbook->createVarsFile('common', [
                'php_ppa'      => $request->get('phpppa'),
                'doc_root'     => $request->get('docroot'),
                'sys_packages' => $request->get('syspackages', array()),
                'timezone'     => $request->get('timezone'),
                'dist'         => $box['deb'],
                'php_packages' => $this->getPhpPackages()
        ]);

        $playbook->addRole('phpcommon');

        $vagrant->setRenderers($playbook->getVarsFiles());
        $vagrant->addRenderer($playbook);
        $vagrant->addRenderer($vagrantfile);
        $vagrant->addRenderer($inventory);

        $tmpName = 'bundle_' . time();
        $zipPath = sys_get_temp_dir() . "/$tmpName.zip";

        if ($vagrant->generateBundle($zipPath, $playbook->getRoles())) {

            return $this->outputBundle($zipPath, $app, $vagrantfile->getName());
        }

        return new Response('An error occurred.');
    }

    /**
     * @param PlaybookRenderer $playbook
     * @param Request $request
     */
    public function setupMysql(PlaybookRenderer $playbook, Request $request)
    {
        /** Databases */
        if ($request->get('database-status')) {
            $playbook->addRole('mysql');

            $mysqlVars = new VarfileRenderer('mysql');
{'fraction_non_alphanumeric': 0.15432338115548663, 'fraction_numerical': 0.0, 'mean_word_length': 2.801768607221813, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6531724', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1487, 'n_words': 246}