This repository has been archived by the owner on Sep 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from symfony-cmf/multilang_refactoring
[WIP] Adding support for multilang
- Loading branch information
Showing
16 changed files
with
386 additions
and
43 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
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
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,21 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Driver; | ||
|
||
/** | ||
* Drivers will (eventually) abstract all database operations | ||
* with the aim of enabling other providers such as ORM. | ||
* | ||
* @author Daniel Leech <[email protected]> | ||
*/ | ||
interface DriverInterface | ||
{ | ||
/** | ||
* Return locales for object | ||
* | ||
* @return array | ||
*/ | ||
public function getLocales($object); | ||
|
||
public function translateObject($object, $locale); | ||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Driver; | ||
|
||
use Doctrine\ODM\PHPCR\DocumentManager; | ||
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Driver\DriverInterface; | ||
|
||
/** | ||
* Abstraction driver for PHPCR-ODM | ||
* | ||
* This class will eventually encapsulate all of the PHPCR-ODM | ||
* specific logic to enable support for multiple backends. | ||
*/ | ||
class PhpcrOdmDriver implements DriverInterface | ||
{ | ||
protected $dm; | ||
|
||
public function __construct(DocumentManager $dm) | ||
{ | ||
$this->dm = $dm; | ||
} | ||
|
||
public function getLocales($document) | ||
{ | ||
if ($this->dm->isDocumentTranslatable($document)) { | ||
return $this->dm->getLocalesFor($document); | ||
} | ||
|
||
return array(); | ||
} | ||
|
||
public function translateObject($document, $locale) | ||
{ | ||
$meta = $this->dm->getMetadataFactory()->getMetadataFor(get_class($document)); | ||
$this->dm->findTranslation(get_class($document), $meta->getIdentifierValue($document), $locale); | ||
return $document; | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\PathProvider; | ||
|
||
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\PathProviderInterface; | ||
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Exception\MissingOptionException; | ||
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Exception\CouldNotFindRouteException; | ||
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack; | ||
use Symfony\Cmf\Bundle\CoreBundle\Slugifier\SlugifierInterface; | ||
use Doctrine\ODM\PHPCR\DocumentManager; | ||
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route; | ||
use Doctrine\Common\Collections\ArrayCollection; | ||
|
||
/** | ||
* Provides a ISO-639-1 locale path element based | ||
* on the locale in the context. | ||
* | ||
* @author Daniel Leech <[email protected]> | ||
*/ | ||
class LocaleProvider implements PathProviderInterface | ||
{ | ||
public function init(array $options) | ||
{ | ||
} | ||
|
||
public function providePath(RouteStack $routeStack) | ||
{ | ||
$context = $routeStack->getContext(); | ||
$locale = $context->getLocale(); | ||
|
||
if (!$locale) { | ||
throw new \RuntimeException( | ||
'LocaleProvider requires that a locale is set on the BuilderContext' | ||
); | ||
} | ||
|
||
$routeStack->addPathElements(array($locale)); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.