LPH
Well-known member
This one has my head spinning.
I've decided to learn Composer. Everything loads fine except a PHP file above the src/ needs to call the \XF class.
Here is the composer.json
Here is the directory structure:
/xenword
/xenword/composer.json
/xenword/xenword.php
/xenword/assets/
/xenword/framework/
/xenword/src/ <--- namespace root
/xenword/support/
/xenword/vendor/
The main xenword.php file requires the autoload.php as well as the framework/admin-init.php. Everything loads except one part of the framework init file -- the part which has a conditional for the XF class exist. For some reason, the file in the /xenword/framework loads everything except that it cannot find the \XF.
This is the code.
Before adding composer, this code was not an issue. This is because I was starting the namespace at /xenword rather than /xenword/src/. I've been looking at the composer.json to see if there was a way to add the ability to call \XF but became very confused.
Does anyone have any suggestions on how to get the conditional to work properly?
I've decided to learn Composer. Everything loads fine except a PHP file above the src/ needs to call the \XF class.
Here is the composer.json
Code:
{
"name": "TuxReports/XenWord",
"type": "wordpress-plugin",
"description": "This configuration file is used for XenWord 2017 using Composer.",
"autoload" : {
"psr-4": {
"ProjectRoot\\" : "",
"XenWord\\": "src/"
}
}
}
Here is the directory structure:
/xenword
/xenword/composer.json
/xenword/xenword.php
/xenword/assets/
/xenword/framework/
/xenword/src/ <--- namespace root
/xenword/support/
/xenword/vendor/
The main xenword.php file requires the autoload.php as well as the framework/admin-init.php. Everything loads except one part of the framework init file -- the part which has a conditional for the XF class exist. For some reason, the file in the /xenword/framework loads everything except that it cannot find the \XF.
This is the code.
PHP:
if ( class_exists( 'XF' ) ) {
/** @var \XF\Repository\UserGroup $groupRepo */
$groupRepo = \XF::app()->repository('XF:UserGroup');
$usergroups = $groupRepo->getUserGroupTitlePairs();
return $usergroups;
}
Before adding composer, this code was not an issue. This is because I was starting the namespace at /xenword rather than /xenword/src/. I've been looking at the composer.json to see if there was a way to add the ability to call \XF but became very confused.
Does anyone have any suggestions on how to get the conditional to work properly?