Exemple #1
0
 public function mapAttachments($fieldName)
 {
     parent::mapAttachments($fieldName);
     $this->reflFields[$fieldName] = $this->reflClass->getProperty($fieldName);
 }
 /**
  * Stores the association mapping.
  *
  * @param AssociationMapping $assocMapping
  */
 protected function _storeAssociationMapping(AssociationMapping $assocMapping)
 {
     parent::_storeAssociationMapping($assocMapping);
     // Store ReflectionProperty of mapped field
     $sourceFieldName = $assocMapping->sourceFieldName;
     $refProp = $this->reflClass->getProperty($sourceFieldName);
     $refProp->setAccessible(true);
     $this->reflFields[$sourceFieldName] = $refProp;
 }
Exemple #3
0
    /**
     * Generated and write entity class to disk for the given ClassMetadataInfo instance
     *
     * @param ClassMetadataInfo $metadata
     * @param string            $outputDirectory
     * @throws \RuntimeException
     * @return void
     */
    public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory)
    {
        //Shopware fix. Here we check the shopware model mappings to set the correct namespace for the passed meta data.
        if (array_key_exists($metadata->name, $this->tableMappings)) {
            $name = $metadata->name;
            $metadata->name = $this->tableMappings[$name]['namespace'] . '\\' . $this->tableMappings[$name]['name'];
            $metadata->namespace = $this->tableMappings[$name]['namespace'];

            //all shopware attributes tables has an @OneToOne association.
            if (strpos($metadata->getTableName(), '_attributes') !== false) {
                foreach ($metadata->associationMappings as &$mapping) {
                    $mapping['type'] = 1;
                    $mapping['inversedBy'] = 'attribute';
                }
            }
        }

        $outputDirectory = rtrim($outputDirectory, '/');
        $path = $outputDirectory . '/' . str_replace('\\', DIRECTORY_SEPARATOR, $metadata->name) . $this->_extension;
        $dir = dirname($path);

        if (!is_dir($dir)) {
            mkdir($dir, 0777, true);
        }
        $this->_isNew = !file_exists($path) || (file_exists($path) && $this->_regenerateEntityIfExists);

        if (!$this->_isNew) {
            $this->_parseTokensInEntityFile(file_get_contents($path));
        } else {
            $this->_staticReflection[$metadata->name] = array('properties' => array(), 'methods' => array());
        }

        if ($this->_backupExisting && file_exists($path)) {
            $backupPath = dirname($path) . DIRECTORY_SEPARATOR . basename($path) . "~";
            if (!copy($path, $backupPath)) {
                throw new \RuntimeException("Attempt to backup overwritten entity file but copy operation failed.");
            }
        }
        // If entity doesn't exist or we're re-generating the entities entirely
        if ($this->_isNew) {
            $code = $this->generateEntityClass($metadata);
            file_put_contents($path, $code);
            // If entity exists and we're allowed to update the entity class
        } else {
            if (!$this->_isNew && $this->_updateEntityIfExists) {
                $code = $this->generateUpdatedEntityClass($metadata, $path);
                file_put_contents($path, $code);
            }
        }
    }