12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace Gedmo\Loggable\Mapping\Driver;
- use Gedmo\Mapping\Driver\File,
- Gedmo\Mapping\Driver,
- Doctrine\Common\Persistence\Mapping\ClassMetadata,
- Gedmo\Exception\InvalidMappingException;
- /**
- * This is a yaml mapping driver for Loggable
- * behavioral extension. Used for extraction of extended
- * metadata from yaml specificaly for Loggable
- * extension.
- *
- * @author Boussekeyt Jules <jules.boussekeyt@gmail.com>
- * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
- * @package Gedmo.Loggable.Mapping.Driver
- * @subpackage Yaml
- * @link http://www.gediminasm.org
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
- class Yaml extends File implements Driver
- {
- /**
- * File extension
- * @var string
- */
- protected $_extension = '.dcm.yml';
- /**
- * {@inheritDoc}
- */
- public function validateFullMetadata(ClassMetadata $meta, array $config)
- {
- if (is_array($meta->identifier) && count($meta->identifier) > 1) {
- throw new InvalidMappingException("Loggable does not support composite identifiers in class - {$meta->name}");
- }
- }
- /**
- * {@inheritDoc}
- */
- public function readExtendedMetadata(ClassMetadata $meta, array &$config)
- {
- $yaml = $this->_loadMappingFile($this->_findMappingFile($meta->name));
- $mapping = $yaml[$meta->name];
- if (isset($mapping['gedmo'])) {
- $classMapping = $mapping['gedmo'];
- if (isset($classMapping['loggable'])) {
- $config['loggable'] = true;
- if (isset ($classMapping['loggable']['logEntryClass'])) {
- if (!class_exists($classMapping['loggable']['logEntryClass'])) {
- throw new InvalidMappingException("LogEntry class: {$classMapping['loggable']['logEntryClass']} does not exist.");
- }
- $config['logEntryClass'] = $classMapping['loggable']['logEntryClass'];
- }
- }
- }
- }
- /**
- * {@inheritDoc}
- */
- protected function _loadMappingFile($file)
- {
- return \Symfony\Component\Yaml\Yaml::load($file);
- }
- }
|