Models/ModelOperator.php
public function generateModelClass($className, $namespace = "Entities") {

        $className = ucfirst($className);

        if (empty($this->_structures[$className])) $this->loadStructureFiles($this->_structuresPath);
        if (empty($this->_structures[$className])) {
            throw new \Exception('There is no structure defined for ' . $className);
        }
        $clearClassName = substr($className, strrpos($className, "\\") + 1);
        $baseClassName  = 'Base' . $clearClassName;
        $baseClassPath  = $this->_storagePath . 'bases/' . $baseClassName . '.php';
        FSService::makeWritable($this->_modelsPath);
        FSService::makeWritable($this->_storagePath . 'bases/');

        $propertiesText = '';
        $methodsText    = '';
        foreach ($this->_structures[$className]['columns'] as $key => $props) {
            //$propertiesText .= ' * @property mixed ' . $key . "\n";
            $methodsText .= ' * @method mixed get' . Inflector::camelize($key) . '()' . "\n";
            $methodsText .= ' * @method ' . $clearClassName . ' set' . Inflector::camelize($key) . '($value)' . "\n";
        }
        if (!empty($this->_structures[$className]['relations'])) {
            $methodsText .= ' * @method mixed setRelatedIDs($relationName, $ids)' . "\n";
            $methodsText .= ' * @method mixed clearRelatedIDs($relationName, $ids = null)' . "\n";
            foreach ($this->_structures[$className]['relations'] as $key => $props) {
                if (empty($props['type']) || (substr($props['type'], -3) == "one")) {
                    $resultType = empty($props['model']) ? 'Model' : $props['model'];
                } else {
                    $resultType = 'ModelCollection';
                }
                $methodsText .= ' * @method mixed setRelated' . Inflector::camelize($key) . '($ids)' . "\n";
                $methodsText .= ' * @method mixed clearRelated' . Inflector::camelize($key) . '($ids = null)' . "\n";
                $methodsText .= ' * @method ' . $resultType . ' get' . Inflector::camelize($key) . '()' . "\n";
                //$propertiesText .= ' * @property ' . (isset($props['model']) ? $props['model'] : 'Model|ModelCollection') . ' ' . $key . "\n";
            }
        }
        if (!empty($propertiesText)) {
            $propertiesText = substr($propertiesText, 0, -1);
        }
        if (!empty($this->_structures[$className]['abilities'])) {
            foreach ($this->_structures[$className]['abilities'] as $abilityName => $props) {
                $abilityClass = 'Solve\Database\Models\Abilities\\' . ucfirst($abilityName) . 'Ability';
                $rf           = new \ReflectionClass($abilityClass);
                if ($comment = $rf->getDocComment()) {
                    preg_match_all('#\* @publish (.*)#i', $comment, $methods);
                    if (!empty($methods[1])) {
                        foreach ($methods[1] as $methodDescription) {
                            $methodsText .= ' * @method ' . $methodDescription . "\n";
                        }
                    }
                }
            }
        }
        if (!empty($methodsText)) {
            $methodsText = substr($methodsText, 0, -1);
        }
        //@todo event dispatcher for project name needed
        $replace           = array(
            '__BASENAME__'   => $baseClassName,
            '__NAMESPACE__'  => $namespace,
            '__NAME__'       => $className,
            '__CLEAR_NAME__' => $clearClassName,
            '__PROPERTIES__' => $propertiesText . (empty($methodsText) ? '' : "\n" . $methodsText),
            '__DATE__'       => date('d.m.Y H:i:s'),
            '__PROJECT__'    => '',
        );
        $baseClassTemplate = file_get_contents(__DIR__ . '/_baseTemplate.php');
        $baseClassTemplate = str_replace(array_keys($replace), array_values($replace), $baseClassTemplate);

        if (is_file($baseClassPath)) unlink($baseClassPath);
        if (is_file($baseClassPath)) {
            throw new \Exception('Cannot overwrite old Base class for ' . $baseClassPath);
        }
        file_put_contents($baseClassPath, $baseClassTemplate);

        chmod($baseClassPath, 0777);
        if (!is_file($this->_modelsPath . $clearClassName . '.php')) {
            $modelClassTemplate = file_get_contents(dirname(__FILE__) . '/_modelTemplate.php');
            $modelClassTemplate = str_replace(array_keys($replace), array_values($replace), $modelClassTemplate);
            FSService::makeWritable($this->_modelsPath);
            file_put_contents($this->_modelsPath . $clearClassName . '.php', $modelClassTemplate);
        }
    }
public function generateModelClass($className, $namespace = "Entities") {

        $className = ucfirst($className);

        if (empty($this->_structures[$className])) $this->loadStructureFiles($this->_structuresPath);
        if (empty($this->_structures[$className])) {
            throw new \Exception('There is no structure defined for ' . $className);
        }
        $clearClassName = substr($className, strrpos($className, "\\") + 1);
        $baseClassName  = 'Base' . $clearClassName;
        $baseClassPath  = $this->_storagePath . 'bases/' . $baseClassName . '.php';
        FSService::makeWritable($this->_modelsPath);
        FSService::makeWritable($this->_storagePath . 'bases/');

        $propertiesText = '';
        $methodsText    = '';
        foreach ($this->_structures[$className]['columns'] as $key => $props) {
            //$propertiesText .= ' * @property mixed ' . $key . "\n";
            $methodsText .= ' * @method mixed get' . Inflector::camelize($key) . '()' . "\n";
            $methodsText .= ' * @method ' . $clearClassName . ' set' . Inflector::camelize($key) . '($value)' . "\n";
        }
        if (!empty($this->_structures[$className]['relations'])) {
            $methodsText .= ' * @method mixed setRelatedIDs($relationName, $ids)' . "\n";
            $methodsText .= ' * @method mixed clearRelatedIDs($relationName, $ids = null)' . "\n";
            foreach ($this->_structures[$className]['relations'] as $key => $props) {
                if (empty($props['type']) || (substr($props['type'], -3) == "one")) {
                    $resultType = empty($props['model']) ? 'Model' : $props['model'];
                } else {
                    $resultType = 'ModelCollection';
                }
                $methodsText .= ' * @method mixed setRelated' . Inflector::camelize($key) . '($ids)' . "\n";
                $methodsText .= ' * @method mixed clearRelated' . Inflector::camelize($key) . '($ids = null)' . "\n";
                $methodsText .= ' * @method ' . $resultType . ' get' . Inflector::camelize($key) . '()' . "\n";
                //$propertiesText .= ' * @property ' . (isset($props['model']) ? $props['model'] : 'Model|ModelCollection') . ' ' . $key . "\n";
            }
        }
        if (!empty($propertiesText)) {
            $propertiesText = substr($propertiesText, 0, -1);
        }
        if (!empty($this->_structures[$className]['abilities'])) {
            foreach ($this->_structures[$className]['abilities'] as $abilityName => $props) {
                $abilityClass = 'Solve\Database\Models\Abilities\\' . ucfirst($abilityName) . 'Ability';
                $rf           = new \ReflectionClass($abilityClass);
                if ($comment = $rf->getDocComment()) {
                    preg_match_all('#\* @publish (.*)#i', $comment, $methods);
                    if (!empty($methods[1])) {
                        foreach ($methods[1] as $methodDescription) {
                            $methodsText .= ' * @method ' . $methodDescription . "\n";
                        }
                    }
                }
            }
        }
        if (!empty($methodsText)) {
            $methodsText = substr($methodsText, 0, -1);
        }
        //@todo event dispatcher for project name needed
        $replace           = array(
            '__BASENAME__'   => $baseClassName,
            '__NAMESPACE__'  => $namespace,
            '__NAME__'       => $className,
            '__CLEAR_NAME__' => $clearClassName,
            '__PROPERTIES__' => $propertiesText . (empty($methodsText) ? '' : "\n" . $methodsText),
            '__DATE__'       => date('d.m.Y H:i:s'),
            '__PROJECT__'    => '',
        );
        $baseClassTemplate = file_get_contents(__DIR__ . '/_baseTemplate.php');
        $baseClassTemplate = str_replace(array_keys($replace), array_values($replace), $baseClassTemplate);

        if (is_file($baseClassPath)) unlink($baseClassPath);
        if (is_file($baseClassPath)) {
            throw new \Exception('Cannot overwrite old Base class for ' . $baseClassPath);
        }
        file_put_contents($baseClassPath, $baseClassTemplate);

        chmod($baseClassPath, 0777);
        if (!is_file($this->_modelsPath . $clearClassName . '.php')) {
            $modelClassTemplate = file_get_contents(dirname(__FILE__) . '/_modelTemplate.php');
            $modelClassTemplate = str_replace(array_keys($replace), array_values($replace), $modelClassTemplate);
            FSService::makeWritable($this->_modelsPath);
            file_put_contents($this->_modelsPath . $clearClassName . '.php', $modelClassTemplate);
        }
    }
Generate Model file if it's not exist
@param string $className
@param string $namespace
@return void
@throws \Exception if no structure defined