Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
release
/vendor/*
/vendor-prefixed/*
phpunit.xml
.phpunit.result.cache
/dist
Expand Down Expand Up @@ -51,5 +52,8 @@ tests/cypress/videos
tests/cypress/reports
.wp-env.override.json

# Strauss
bin/strauss.phar

# docs
wp-hooks-docs/docs/01.get-started/05.CHANGELOG.md
Empty file added bin/.gitkeep
Empty file.
20 changes: 17 additions & 3 deletions classifai.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,31 @@ function classifai_define( $name, $value ) {
* @return bool True or false if autoloading was successful.
*/
function classifai_autoload() {
if ( file_exists( CLASSIFAI_PLUGIN_DIR . '/vendor/autoload.php' ) ) {
require_once CLASSIFAI_PLUGIN_DIR . '/vendor/autoload.php';

return true;
// Track if the autoloader was loaded.
$loaded = false;

// Load the prefixed vendor autoloader (contains AWS SDK and all other dependencies)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So currently this function will return true if the autoload file is loaded properly. Now that we are introducing another autoload file, I think we'll need additional changes here to ensure both are loaded properly and show an error message if not.

Something like this (untested):

function classifai_autoload() {
	$loaded = false;

	// Load the prefixed vendor autoloader (contains AWS SDK and all other dependencies)
	if ( file_exists( CLASSIFAI_PLUGIN_DIR . '/vendor-prefixed/autoload.php' ) ) {
		require_once CLASSIFAI_PLUGIN_DIR . '/vendor-prefixed/autoload.php';
		$loaded = true;
	}

	// Load the main vendor autoloader (contains plugin classes and other dependencies)
	if ( $loaded && file_exists( CLASSIFAI_PLUGIN_DIR . '/vendor/autoload.php' ) ) {
		require_once CLASSIFAI_PLUGIN_DIR . '/vendor/autoload.php';
	} else {
		$loaded = false;
	}

	if ( ! $loaded ) {
		error_log( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
			sprintf( 'Warning: Composer not setup in %s', CLASSIFAI_PLUGIN_DIR )
		);

		return false;
	}

	return true;
}

if ( file_exists( CLASSIFAI_PLUGIN_DIR . '/vendor-prefixed/autoload.php' ) ) {

require_once CLASSIFAI_PLUGIN_DIR . '/vendor-prefixed/autoload.php';

// Set the loaded flag to true.
$loaded = true;
}

// Load the main vendor autoloader (contains plugin classes and other dependencies)
if ( $loaded && file_exists( CLASSIFAI_PLUGIN_DIR . '/vendor/autoload.php' ) ) {
require_once CLASSIFAI_PLUGIN_DIR . '/vendor/autoload.php';
} else {
error_log( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
sprintf( 'Warning: Composer not setup in %s', CLASSIFAI_PLUGIN_DIR )
);

return false;
}

return $loaded;
}

/**
Expand Down
25 changes: 23 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,18 @@
"lint": "phpcs -s . --runtime-set testVersion 7.4-",
"lint-fix": "phpcbf .",
"phpstan": "phpstan analyse --memory-limit=2048M -v",
"pre-autoload-dump": "Aws\\Script\\Composer\\Composer::removeUnusedServices"
"pre-autoload-dump": "Aws\\Script\\Composer\\Composer::removeUnusedServices",
"prefix-namespaces": [
"sh -c 'test -f ./bin/strauss.phar || curl -o bin/strauss.phar -L -C - https://github.com/BrianHenryIE/strauss/releases/latest/download/strauss.phar'",
"php -d memory_limit=2048M -d max_execution_time=300 bin/strauss.phar",
"@composer dump-autoload"
],
"post-install-cmd": [
"@prefix-namespaces"
],
"post-update-cmd": [
"@prefix-namespaces"
]
},
"minimum-stability": "dev",
"config": {
Expand All @@ -56,6 +67,16 @@
"extra": {
"aws/aws-sdk-php": [
"Polly"
]
],
"strauss": {
"target_directory": "vendor-prefixed",
"namespace_prefix": "ClassifaiVendor\\",
"classmap_prefix": "ClassifaiVendor_",
"packages": [
"aws/aws-sdk-php"
],
"delete_vendor_packages": true,
"update_call_sites": false
}
}
}
Loading
Loading