SitemapCommandController.php 935 Bytes
Newer Older
Dominique Feyer's avatar
Dominique Feyer committed
1 2 3
<?php
namespace Ttree\Neos\Sitemap\Command;

4 5
use Ttree\Neos\Sitemap\Domain\Model\SitemapDefinition;
use Ttree\Neos\Sitemap\Service\SitemapBuilder;
Dominique Feyer's avatar
Dominique Feyer committed
6 7 8 9 10 11 12 13
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Cli\CommandController;
use TYPO3\Flow\Utility\Files;

class SitemapCommandController extends CommandController {

    /**
     * @Flow\Inject
14
     * @var SitemapBuilder
Dominique Feyer's avatar
Dominique Feyer committed
15
     */
16
    protected $sitemapBuilder;
Dominique Feyer's avatar
Dominique Feyer committed
17 18 19 20 21 22 23

    /**
     * @param string $siteNodeName
     * @param string $baseUrl
     * @param string $preset
     */
    public function generateCommand($siteNodeName, $baseUrl, $preset = 'default') {
24 25
        $definition = new SitemapDefinition($siteNodeName, $baseUrl, $preset);
        $sitemap = $this->sitemapBuilder->build($definition);
Dominique Feyer's avatar
Dominique Feyer committed
26

27
        $pathAndFilename = $definition->getPath();
Dominique Feyer's avatar
Dominique Feyer committed
28 29 30 31 32
        Files::createDirectoryRecursively(dirname($pathAndFilename));
        file_put_contents($pathAndFilename, (string)$sitemap);
    }

}