24 $json = file_get_contents( $jsonPath );
31 $abstractSchema = json_decode( $json,
true, 512, JSON_THROW_ON_ERROR );
32 }
catch ( JsonException $e ) {
33 throw new AbstractSchemaValidationError(
"Invalid JSON schema: " . $e->getMessage(), 0, $e );
36 $validator =
new AbstractSchemaValidator();
37 $validator->validate( $jsonPath );
39 return $abstractSchema;
45 public function generateSchema(
string $platform,
string $jsonPath ): string {
46 $abstractSchemaChange = $this->validateAndGetSchema( $jsonPath );
48 $sql = $this->makeSQLComment(
'generateSchemaSql.php', $jsonPath );
52 foreach ( $abstractSchemaChange as $table ) {
53 $schemaBuilder->addTable( $table );
55 $tableSqls = $schemaBuilder->getSql();
57 $sql .= $this->cleanupSqlArray( $platform, $tableSqls );
66 $abstractSchemaChange = $this->validateAndGetSchema( $jsonPath );
68 $sql = $this->makeSQLComment(
'generateSchemaChangeSql.php', $jsonPath );
72 $schemaChangeSqls = $schemaChangeBuilder->getSchemaChangeSql( $abstractSchemaChange );
73 if ( !$schemaChangeSqls ) {
77 $sql .= $this->cleanupSqlArray( $platform, $schemaChangeSqls );
104 string $extensionDirectory
106 $installPath = realpath( $installPath );
107 $jsonPath = realpath( $jsonPath );
108 $extensionDirectory = realpath( $extensionDirectory );
111 if ( DIRECTORY_SEPARATOR ===
'\\' ) {
112 $installPath = strtr( $installPath,
'\\',
'/' );
113 $jsonPath = strtr( $jsonPath,
'\\',
'/' );
114 $extensionDirectory = strtr( $extensionDirectory,
'\\',
'/' );
117 if ( str_starts_with( $jsonPath, $extensionDirectory ) ) {
120 $canonicalJsonPath = str_replace(
"$extensionDirectory/",
'', $jsonPath );
124 $canonicalJsonPath = explode(
'/', $canonicalJsonPath, 2 )[1];
128 $canonicalJsonPath = str_replace(
"$installPath/",
'', $jsonPath );
131 return $canonicalJsonPath;