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 );
101 public static function normalizePath(
string $jsonPath,
string $IP,
string $extensionDirectory ): string {
102 $installPath = realpath(
$IP );
103 $jsonPath = realpath( $jsonPath );
104 $extensionDirectory = realpath( $extensionDirectory );
107 if ( DIRECTORY_SEPARATOR ===
'\\' ) {
108 $installPath = strtr( $installPath,
'\\',
'/' );
109 $jsonPath = strtr( $jsonPath,
'\\',
'/' );
110 $extensionDirectory = strtr( $extensionDirectory,
'\\',
'/' );
113 if ( str_starts_with( $jsonPath, $extensionDirectory ) ) {
116 $canonicalJsonPath = str_replace(
"$extensionDirectory/",
'', $jsonPath );
120 $canonicalJsonPath = explode(
'/', $canonicalJsonPath, 2 )[1];
124 $canonicalJsonPath = str_replace(
"$installPath/",
'', $jsonPath );
127 return $canonicalJsonPath;