Creates a new Class and writes it to a file

@param GClass $gClass
@param File $file if not given the ClassFileMapper will be asked for a file
@return Webforge\Common\System\File
761561
public function create(GClass $gClass, $overwrite = FALSE, File $file = NULL) {
    $file = $file ?: $this->mapper->getFile($gClass->getFQN());
    
    $file->getDirectory()->create();

    try {
      $this->elevator->elevateParent($gClass);
    } catch (ClassFileNotFoundException $e) {
      
    } catch (\ReflectionException $e) {
      
    }
    
    try {
      $this->elevator->elevateInterfaces($gClass);
    } catch (ClassFileNotFoundException $e) {
      
    } catch (\ReflectionException $e) {
      
    }

    
    $gClass->createAbstractMethodStubs();
    
    $this->writer->write($gClass, $file, $overwrite);
    
    return $file;
  }
927313
public function setGlobPatternFromFile($file)
    {
        if (!is_file($file)) {
            $message = "Glob pattern file {$file} doesn't exist.";
            throw new NonExistentGlobPatternFile($message);
        }

        $globPatternContent = (string) file_get_contents($file);

        $globPatternLines = preg_split(
            '/\\r\\n|\\r|\\n/',
            $globPatternContent
        );

        $globPatterns = [];
        array_filter($globPatternLines, function ($line) use (&$globPatterns) {
            if (trim($line) !== '') {
                $globPatterns[] = trim($line);
            }
        });

        $globPattern = '{' . implode(',', $globPatterns) . '}*';

        try {
            $this->setGlobPattern($globPattern);

            return $this;
        } catch (InvalidGlobPattern $e) {
            $message = "Glob pattern file '{$file}' is invalid.";
            throw new InvalidGlobPatternFile($message);
        }
    }
1225996
public JavaFileObject writeClass(ClassSymbol c)
        throws IOException, PoolOverflow, StringOverflow
    {
        JavaFileObject outFile
            = fileManager.getJavaFileForOutput(CLASS_OUTPUT,
                                               c.flatname.toString(),
                                               JavaFileObject.Kind.CLASS,
                                               c.sourcefile);
        OutputStream out = outFile.openOutputStream();
        try {
            writeClassFile(out, c);
            if (verbose)
                log.printVerbose("wrote.file", outFile);
            out.close();
            out = null;
        } finally {
            if (out != null) {
                // if we are propagating an exception, delete the file
                out.close();
                outFile.delete();
                outFile = null;
            }
        }
        return outFile; // may be null if write failed
    }
490172
public function resolveClassname($file)
    {

        $splFile = new SplFileInfo($file);
        $parts   = explode('_', $splFile->getFilename());
        $strings = [];
        foreach ($parts as $part) {
            if (is_numeric($part)) {
                continue;
            }
            array_push($strings, $part);
        }
        $class = Str::studly(implode('_', $strings));
        return new $class;
    }
606829
public function setFile($file): self
    {
        $this->file = $file;

        if (is_string($file)) {
            $this->pathToFile = $file;
            $this->setFileName(pathinfo($file, PATHINFO_BASENAME));
            $this->mediaName = pathinfo($file, PATHINFO_FILENAME);

            return $this;
        }

        if ($file instanceof UploadedFile) {
            $this->pathToFile = $file->getPath().'/'.$file->getFilename();
            $this->setFileName($file->getClientOriginalName());
            $this->mediaName = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);

            return $this;
        }

        if ($file instanceof SymfonyFile) {
            $this->pathToFile = $file->getPath().'/'.$file->getFilename();
            $this->setFileName(pathinfo($file->getFilename(), PATHINFO_BASENAME));
            $this->mediaName = pathinfo($file->getFilename(), PATHINFO_FILENAME);

            return $this;
        }

        throw UnknownType::create();
    }
661417
public function file($file)
    {
        if (\in_array($file, ['global', 'system', 'local'])) {
            $this->arguments[] = '--' . $file;
        } else {
            $this->arguments[] = '--file';
            $this->arguments[] = $file;
        }
        return $this;
    }
1128479
def create_file(self, filename):
    
    self.response.write('Creating file %s\n' % filename)

    write_retry_params = gcs.RetryParams(backoff_factor=1.1)
    gcs_file = gcs.open(filename,
                        'w',
                        content_type='text/plain',
                        options={'x-goog-meta-foo': 'foo',
                                 'x-goog-meta-bar': 'bar'},
                        retry_params=write_retry_params)
    gcs_file.write('abcde\n')
    gcs_file.write('f'*1024*4 + '\n')
    gcs_file.close()
    self.tmp_filenames_to_clean_up.append(filename)
1318251
public static FileCreationState newFile(final File file) throws IOException
	{
		FileCreationState fileCreationState = FileCreationState.ALREADY_EXISTS;
		if (!file.exists())
		{
			fileCreationState = FileCreationState.FAILED;
			newParentDirectories(file);
			if (file.createNewFile())
			{
				fileCreationState = FileCreationState.CREATED;
			}
		}
		return fileCreationState;
	}
1344490
protected function _createConfiguration($file)
	{
		JLoader::register('JConfig', $file);

		// Create the JConfig object.
		$config = new JConfig;

		// Get the global configuration object.
		$registry = JFactory::getConfig();

		// Load the configuration values into the registry.
		$registry->loadObject($config);

		return $config;
	}
1256138
public static BufferedWriter createWriter(File file) throws IOException {
        OutputStream os = new FileOutputStream(file);
        if (file.getName().toLowerCase().endsWith(".gz"))
            os = new GZIPOutputStream(os);
        return new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8));
    }
323023
protected function createMigration($class)
    {
        $query = new Query;
        $migrate = $query->select(['migrationPath'])
                ->from($this->migrationTable)
                ->where(['version' => $class])
                ->one();
        $filename = DIRECTORY_SEPARATOR . $class . '.php';
        if ($migrate && file_exists($migrate['migrationPath'] . $filename)) {
            $this->migrationPath = $migrate['migrationPath'];
        }

        $file = $this->migrationPath . $filename;
        require_once($file);

        return new $class(['db' => $this->db]);
    }
981539
public static function classfile($class, $comment = false)
	{
		$ref    = new \ReflectionClass($class);
		$start  = $ref->getStartLine();
		$end    = $ref->getEndLine();
		$text   = file_get_contents($ref->getFileName());
		$text   = self::lines($text, $start, $end);
		if ($comment)
		{
			$text = preg_replace('/^\s+\*/m', ' *', $ref->getDocComment()) . PHP_EOL . $text;
		}
		return self::output($text, 'php');
	}
396511
private function generateProxyClass($class, $proxyClassName, $fileName, $file)
    {
        $methods = $this->generateMethods($class);
        $sleepImpl = $this->generateSleep($class);

        $placeholders = array(
            '<namespace>',
            '<proxyClassName>', '<className>',
            '<methods>', '<sleepImpl>'
        );

        if(substr($class->name, 0, 1) == "\\") {
            $className = substr($class->name, 1);
        } else {
            $className = $class->name;
        }

        $replacements = array(
            $this->proxyNamespace,
            $proxyClassName, $className,
            $methods, $sleepImpl
        );

        $file = str_replace($placeholders, $replacements, $file);

        file_put_contents($fileName, $file);
    }
1047321
public static function loadClassFile($file) {
		$before = array_merge(get_declared_classes(), get_declared_interfaces());
		require_once $file;
		$after = array_merge(get_declared_classes(), get_declared_interfaces());

		$diff = array_diff($after, $before);

		#class was maybe already loaded
		if(!$diff) {
			foreach(array_merge(get_declared_classes(), get_declared_interfaces()) as $class) {
				$reflector = new \ReflectionClass($class);
				if($reflector->getFileName() == realpath($file)) {
					$result = $class;
					break;
				}
			}
			if(!isset($result))
				throw new \Exception('File '.$file.' does not contain any class.');
		}
		else
			$result = array_values($diff)[count($diff)-1];

		return $result;
	}
423030
protected function writeClass(ClassGenerator $class, Filesystem $filesystem, $destinationDir)
    {
        $className = $class->getName();
        $file = new FileGenerator([
            'fileName' => $className.'.php',
            'classes' => [$class],
        ]);
        $contents = $file->generate();

        $relativePath = $destinationDir.DIRECTORY_SEPARATOR.$file->getFilename();
        if ($filesystem->has($relativePath)) {
            throw new CliException(sprintf(
                'Could not generate migration. File already exists: %s',
                $relativePath
            ));
        }

        $result = $filesystem->write($relativePath, $contents);

        return $result ? $relativePath : false;
    }
282574
public static function create($class)
    {
        try {
            $reflection = new \ReflectionClass($class);
        } catch (\ReflectionException $e) {
            return false;
        }

        $constructor = $reflection->getConstructor();

        // If there are no parameters, just return a new object.
        if (null === $constructor) {
            return new $class;
        }

        $newInstanceArgs = self::getMethodArgs($constructor);

        // Create a callable for the dataStorage
        return $reflection->newInstanceArgs($newInstanceArgs);
    }
1319221
public function add($file)
    {
        if ($file instanceof SplFileInfo) {
            throw InvalidArgumentException::create(
                sprintf(
                    '%1$s/FileBag|%1$s/File[]|%1$s/File',
                    __NAMESPACE__
                ),
                $file
            );
        }

        return parent::add($file);
    }