/*!
Write PHP schema definition to file using PHP array structures.

\param filename
334862
function writeArraySchemaFile( $filename, $params = array() )
    {
        $params = array_merge( array( 'schema' => true,
                                      'data' => false,
                                      'offset' => false,
                                      'limit' => false ),
                               $params );
        $includeSchema = $params['schema'];
        $includeData = $params['data'];
        $fp = @fopen( $filename, 'w' );
        if ( $fp )
        {
            $schema = $this->schema( $params );
            fputs( $fp, '<?' . 'php' . "\n" );
            if ( $includeSchema )
            {
                fputs( $fp, "// This array contains the database schema\n" );
                if ( isset( $schema['_info'] ) )
                {
                    // push the _info member at bottom of array
                    $info = $schema['_info'];
                    unset( $schema['_info'] );
                    $schema['_info'] = $info;
                }
                fputs( $fp, '$schema = ' . var_export( $schema, true ) . ";\n" );
            }
            if ( $includeData )
            {
                $data = $this->data( $schema, false, array( 'offset' => $params['offset'], 'limit' => $params['limit'] ) );
                fputs( $fp, "// This array contains the database data\n" );
                if ( isset( $data['_info'] ) )
                {
                    // push the _info member at bottom of array
                    $info = $data['_info'];
                    unset( $data['_info'] );
                    $data['_info'] = $info;
                }
                fputs( $fp, '$data = ' . var_export( $data, true ) . ";\n" );
            }
            fputs( $fp, "\n" . '?>' );
            fclose( $fp );
            return true;
        }
        else
        {
            return false;
        }
    }
1242873
public function saveFile($filename, array $params = [])
    {
        $fp = fopen($filename, 'w');
        fwrite($fp, $this->xmlString($params));
        fclose($fp);

        return $this;
    }
617910
function generateSchemaFile( $schema, $params = array() )
    {
        $sql = '';

        $i = 0;
        foreach ( $schema as $table => $tableDef )
        {
            // Skip the info structure, this is not a table
            if ( $table == '_info' )
                continue;

            if ( $i > 0 )
                $sql .= "\n\n";
            $sql .= $this->generateTableSchema( $table, $tableDef, $params );
            ++$i;
        }

        return $sql;
    }
66084
public function write($fileName=null)
    {
        $this->_resetFileName($fileName);

        ksort($this->data);
        $output = array();

        foreach ($this->data as $path => $hash) {
            array_push($output, "$hash $path\n");
        }

        writeFileText(
            $this->fileName,
            $this->fileEncoding,
            implode('', $output)
        );
    }
366484
function buildSchema(jsObj, key) {
  if (jsObj === undefined) return null;

  var type = typeOf(jsObj);
  switch (type) {
    case "array":
      {
        let schema = {
          type: "list",
          detail: buildSchema(jsObj[0])
        };
        key && (schema.name = key);
        return schema;
      }
    case "object":
      {
        let schema = {
          type: "map",
          detail: []
        };
        key && (schema.name = key);
        let keys = Object.keys(jsObj);
        for (var i in keys) {
          let key = keys[i];
          if (jsObj[key] !== undefined) {
            schema.detail.push(buildSchema(jsObj[key], key));
          }
        }
        return schema;
      }
    case "null":
    case "string":
    case "number":
    case "date":
    case "boolean":
      {
        let schema = {
          type: type
        };
        key && (schema.name = key);
        return schema;
      }
    default:
      throw Error("Unacceptable type : " + type);
  }
}
97011
public static void writeSchema(String outputPath, Schema schema, JavaSparkContext sc) throws IOException {
        writeStringToFile(outputPath, schema.toString(), sc);
    }
440291
function FileArray (schema) {
  var fileArray = [];

  /**
   * Internal stuff. Use at your own risk!
   *
   * @private
   */
  fileArray[__internal] = {
    /**
     * A reference to the {@link Schema} object
     */
    schema: schema,
  };

  // Return an array that "inherits" from FileArray
  return assign(fileArray, FileArray.prototype);
}
192437
public function saveToFile($FileName = null)
    {
        if (! is_null($FileName)) {
            $this->FileName = $FileName;
        }

        if (($this->_openSHPFile(true)) && ($this->_openSHXFile(true)) && ($this->_createDBFFile())) {
            $this->_saveHeaders();
            $this->_saveRecords();
            $this->_closeSHPFile();
            $this->_closeSHXFile();
            $this->_closeDBFFile();
        } else {
            return false;
        }
    }
202957
def write filename, options={}
      extension = file_extension(filename)
      send("write_to_#{extension}".to_sym, filename, options)
    end
1201017
public function loadSchema($filename)
    {
        if (!file_exists($filename)) {
            throw new FileNotFoundException($filename);
        }

        $xml = simplexml_load_file($filename);

        $tables = $this->loadTables($xml->xpath('//table'));
        return new Schema($tables);
    }
938760
function write($file,array $data=NULL) {
		if (!$this->dir || $this->lazy)
			return count($this->data[$file]=$data);
		$fw=\Base::instance();
		switch ($this->format) {
			case self::FORMAT_JSON:
				$out=json_encode($data,JSON_PRETTY_PRINT);
				break;
			case self::FORMAT_Serialized:
				$out=$fw->serialize($data);
				break;
		}
		return $fw->write($this->dir.'/'.$file,$out);
	}
7403
public function save($fileName = null)
	{
		$file = fopen(empty($fileName) ? $this->fileName : $fileName,'w');
		flock($file,LOCK_EX);
		foreach($this->data as $section => $data)
		{
			fwrite($file, '[' . $section . ']' . PHP_EOL);
			foreach($data as $key => $value)
			{
				fwrite($file, $key . '=' . $value . PHP_EOL);
			}
		}
		fclose($file);
	}
123881
public function setSchemaByName($schema_name = null)
    {
        if (! $schema_name) {
            $schema_name = $this->namespace;
        }
        if (strpos($schema_name, '.') === false) {
            $schema_name = (String) $this->db . '.' . $schema_name;
        }

        // Check formats
        if ($this->client->schema_format === 'php') {
            $schema_file = $this->client->schema_dir . '/' . $schema_name . '.php';
            if (file_exists($schema_file)) {
                $schema = include $schema_file;
                if (! is_array($schema)) {
                    throw new \Exception('Possible PHP syntax error in ' . $schema_file);
                }
            }
        } elseif ($this->client->schema_format === 'json') {
            $schema_file = $this->client->schema_dir . '/' . $schema_name . '.json';
            if (file_exists($schema_file)) {
                $json_string = file_get_contents($schema_file);
                $schema = json_decode($json_string, true);
                if (empty($schema)) {
                    throw new \Exception('Possible JSON parse error in ' . $schema_file);
                }
            }
        } else {
            throw new \Exception('Unknown schema format: ' . $this->client->schema_format);
        }

        // Assign Schema
        if (! empty($schema)) {
            $this->setSchema($schema);
        }

    }
290845
function writeUpgradeFile( $differences, $filename, $params = array() )
    {
        $params = array_merge( array( 'schema' => true,
                                      'data' => false,
                                      'allow_multi_insert' => false,
                                      'diff_friendly' => false ),
                               $params );
        $fp = @fopen( $filename, 'w' );
        if ( $fp )
        {
            fputs( $fp, $this->generateUpgradeFile( $differences, $params ) );
            fclose( $fp );
            return true;
        }
        else
        {
            return false;
        }
    }
263230
static function write($file, $data)
	{
		$content = "";
		foreach($data as $key => $value)
		{
			if(is_array($value))
			{
				for($i=0; $i<count($value); $i++)
					$content .= $key."[] = \"".addslashes($value[$i])."\"\n";
			}
			elseif($value)
				$content .= $key." = \"".addslashes($value)."\"\n";
			else
				$content .= $key." = \n";
		}

		bors_function_include('fs/file_put_contents_lock');
		file_put_contents_lock($file, $content);
	}
1152657
private function replaceParam($name, $value, &$schema)
    {
        $schema = str_replace(
            sprintf('##!%s!##', $name),
            $value,
            $schema
        );
    }
1147546
public function createSchema($outputPathAndFilename = null)
    {
        $schemaTool = new SchemaTool($this->entityManager);
        $allMetaData = $this->entityManager->getMetadataFactory()->getAllMetadata();
        if ($outputPathAndFilename === null) {
            $schemaTool->createSchema($allMetaData);
        } else {
            $createSchemaSqlStatements = $schemaTool->getCreateSchemaSql($allMetaData);
            file_put_contents($outputPathAndFilename, implode(PHP_EOL, $createSchemaSqlStatements));
        }
    }