-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First commit for A brief eZ Publish Symfony stack training
- Loading branch information
Jani Tarvainen
committed
Dec 9, 2014
1 parent
005bb05
commit 768dab1
Showing
9 changed files
with
159 additions
and
0 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,59 @@ | ||
<?php | ||
|
||
namespace Janit\EzXmlSitemapBundle\Controller; | ||
|
||
use Symfony\Component\HttpFoundation\Response; | ||
use eZ\Bundle\EzPublishCoreBundle\Controller; | ||
use eZ\Publish\API\Repository\Values\Content\LocationQuery; | ||
use eZ\Publish\API\Repository\Values\Content\Query; | ||
use eZ\Publish\API\Repository\Values\Content\Query\SortClause; | ||
use eZ\Publish\API\Repository\Values\Content\Query\Criterion; | ||
|
||
class DefaultController extends Controller | ||
{ | ||
|
||
public function simpleSitemapAction() | ||
{ | ||
|
||
$response = new Response(); | ||
$response->setPublic(); | ||
$response->setSharedMaxAge( 3600 ); | ||
$response->headers->set('Content-Type', 'text/xml'); | ||
|
||
$rootLocationId = $this->getConfigResolver()->getParameter( 'content.tree_root.location_id' ); | ||
|
||
$repository = $this->container->get( 'ezpublish.api.repository' ); | ||
|
||
$rootLocation = $repository->getLocationService()->loadLocation($rootLocationId); | ||
|
||
$criteria = array( | ||
new Criterion\Subtree($rootLocation->pathString), | ||
new Criterion\Visibility( Criterion\Visibility::VISIBLE ) | ||
); | ||
|
||
if ( !empty( $criterion ) ) | ||
$criteria[] = $criterion; | ||
|
||
$query = new LocationQuery( | ||
array( | ||
'criterion' => new Criterion\LogicalAnd( $criteria ) | ||
) | ||
); | ||
|
||
$query->limit = 1000; | ||
|
||
$searchService = $repository->getSearchService(); | ||
|
||
$searchResults = $searchService->findLocations($query); | ||
|
||
return $this->render( | ||
'JanitEzXmlSitemapBundle::sitemap.xml.twig', | ||
array( | ||
'searchHits' => $searchResults->searchHits, | ||
), | ||
$response | ||
); | ||
|
||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
Janit/EzXmlSitemapBundle/DependencyInjection/Configuration.php
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,29 @@ | ||
<?php | ||
|
||
namespace Janit\EzXmlSitemapBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
/** | ||
* This is the class that validates and merges configuration from your app/config files | ||
* | ||
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class} | ||
*/ | ||
class Configuration implements ConfigurationInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getConfigTreeBuilder() | ||
{ | ||
$treeBuilder = new TreeBuilder(); | ||
$rootNode = $treeBuilder->root('janit_ez_xml_sitemap'); | ||
|
||
// Here you should define the parameters that are allowed to | ||
// configure your bundle. See the documentation linked above for | ||
// more information on that topic. | ||
|
||
return $treeBuilder; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Janit/EzXmlSitemapBundle/DependencyInjection/JanitEzXmlSitemapExtension.php
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,28 @@ | ||
<?php | ||
|
||
namespace Janit\EzXmlSitemapBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\Component\DependencyInjection\Loader; | ||
|
||
/** | ||
* This is the class that loads and manages your bundle configuration | ||
* | ||
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} | ||
*/ | ||
class JanitEzXmlSitemapExtension extends Extension | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$configuration = new Configuration(); | ||
$config = $this->processConfiguration($configuration, $configs); | ||
|
||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | ||
$loader->load('services.yml'); | ||
} | ||
} |
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,9 @@ | ||
<?php | ||
|
||
namespace Janit\EzXmlSitemapBundle; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class JanitEzXmlSitemapBundle extends Bundle | ||
{ | ||
} |
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,3 @@ | ||
janit_ez_xml_sitemap: | ||
path: /sitemap.xml | ||
defaults: { _controller: JanitEzXmlSitemapBundle:Default:simpleSitemap } |
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,4 @@ | ||
services: | ||
# janit_ez_xml_sitemap.example: | ||
# class: Janit\EzXmlSitemapBundle\Example | ||
# arguments: [@service_id, "plain_value", %parameter%] |
1 change: 1 addition & 0 deletions
1
Janit/EzXmlSitemapBundle/Resources/views/Default/index.html.twig
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 @@ | ||
Hello {{ name }}! |
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,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | ||
|
||
{% for location in searchHits %} | ||
<url> | ||
<loc>{{ app.request.getSchemeAndHttpHost() ~ path( 'ez_urlalias', {'locationId': location.valueObject.id} ) }}</loc> | ||
</url> | ||
{% endfor %} | ||
</urlset> |
17 changes: 17 additions & 0 deletions
17
Janit/EzXmlSitemapBundle/Tests/Controller/DefaultControllerTest.php
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,17 @@ | ||
<?php | ||
|
||
namespace Janit\EzXmlSitemapBundle\Tests\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
|
||
class DefaultControllerTest extends WebTestCase | ||
{ | ||
public function testIndex() | ||
{ | ||
$client = static::createClient(); | ||
|
||
$crawler = $client->request('GET', '/hello/Fabien'); | ||
|
||
$this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0); | ||
} | ||
} |