private function CreateAccessFile() { if (!$this->connection instanceof Php\WritableClass) { throw new \Exception("The connection class should extend \\Phine\\System\\Php\\WritableClass"); } $writer = new Php\Writer(); $writer->StartPhp(); $className = 'Access'; $writer->AddNamespace($this->RootNamespace('')); $writer->StartClass($className); $writer->StartDocComment(); $writer->AddDocComment('Database connection for all table obects in this folder and subfolders'); $writer->AddDocComment(get_class($this->connection), 'var'); $writer->EndDocComment(); $writer->AddCommand('private static $connection'); $writer->StartDocComment(); $writer->AddDocComment('Database connection for all table obects in this folder and subfolders'); $writer->AddDocComment('\\' . get_class($this->connection), 'return'); $writer->EndDocComment(); $writer->StartFunction('final static function Connection'); $writer->Start_If('self::$connection == null'); $writer->AddCommand('self::$connection = ' . $this->connection->GetNewStatement()); $writer->End_If(); $writer->AddCommand('return self::$connection'); $writer->EndFunction(); $writer->StartDocComment(); $writer->AddDocComment('Sql builder for all table obects in this folder and subfolders'); $builder = new Sql\Builder($this->connection); $builderClass = '\\' . get_class($builder); $writer->AddDocComment($builderClass, 'return'); $writer->EndDocComment(); $writer->StartFunction('final static function SqlBuilder'); $writer->AddCommand('return new ' . $builderClass . '(self::Connection())'); $writer->EndFunction(); $writer->EndClass(); $this->CreateFile($className . '.php', $writer->Text()); }