<?php
namespace Skymark\UtilitiesBundle\Extension\Twig;
use Skymark\UtilitiesBundle\Tools\UriDiscovery;
use Skymark\UtilitiesBundle\Generic\PathableInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Skymark\UtilitiesBundle\Tools\HTMLFactory;
class UriExtension extends \Twig_Extension implements \Twig\Extension\GlobalsInterface
{
private static $uriDiscovery = null;
public function setUriDiscovery(UriDiscovery $uriDiscovery)
{
// called many times !
//s33 still? .. optimize
// error_log( "UriExtension: setUriDiscovery called." );
self::$uriDiscovery = $uriDiscovery;
}
public static function uriDiscovery($context, PathableInterface $object)
{
return self::$uriDiscovery->discoverUri($object, $context);
}
public static function uriLink($context, PathableInterface $target, $title, $linkAttributes = array())
{
$linkAttributes['href'] = self::$uriDiscovery->discoverUri($target, $context);
return HTMLFactory::tag('a', $linkAttributes, false, $title);
}
public function getGlobals()
{
//s33 is this correct?
// also causes the err
// print_r( $uriDiscovery);
// $defaultUriInformation = self::$uriDiscovery->getGlobalDefaultUriInformation();
$p1 = self::$uriDiscovery;
// error_log("getGlobalDefaultUriInformation() = " . $p1->getGlobalDefaultUriInformation() );
// error_log( "said i was a string .. $p1 ?" );
// $defaultUriInformation = $p1->getGlobalDefaultUriInformation();
// actually, it is
// error_log(" 1604 - maybe getGlobalDefaultUriInformation really isnt used?? ");
return array(
'root_domain' => 'the.root.domain' // implode('.', $defaultUriInformation['domain'])
);
}
public function getName()
{
return 'uris';
}
public function getFunctions()
{
return array(
'uri' => new \Twig_Function_Function(
'\Skymark\UtilitiesBundle\Extension\Twig\UriExtension::uriDiscovery',
array('needs_context' => true)
),
'link' => new \Twig_Function_Function(
'\Skymark\UtilitiesBundle\Extension\Twig\UriExtension::uriLink',
array('needs_context' => true)
)
);
}
}