Namespacing with Strauss
Using Strauss
Strauss is used for namespacing the Client to prevent conflicts with other plugins or themes that are using TrustedLogin. We recommend installing via the strauss.phar
method.
1. Install Strauss
Install Strauss. Strauss is used for namespacing the Client to prevent conflicts with other plugins or themes that are using TrustedLogin. We recommend installing via the strauss.phar
method.
cd
into your plugin or theme directory- Run
curl -o strauss.phar -L -C - https://github.com/BrianHenryIE/strauss/releases/latest/download/strauss.phar
Using PHP-Scoper
If you prefer to use PHP-Scoper, you can follow the instructions on the PHP-Scoper page.
2. Install the TrustedLogin Client SDK
- Run
composer require trustedlogin/client:dev-main
to install the TrustedLogin Client SDK - Run
composer require scssphp/scssphp --dev
to installscssphp
as a dev dependency. This is used to generate and namespace the CSS used by TrustedLogin. If you already havescssphp
installed, or are using an alternative way to namespace the CSS, skip this step. - Update your
composer.json
file to integrate with Strauss. Follow the instructions as detailed in the Strauss documentation for namespacing your plugin and theme. See example below.
[...]
"require": {
"trustedlogin/client": "dev-main"
},
"require-dev": {
"brianhenryie/strauss": "dev-master",
"scssphp/scssphp": "^v1.11.0"
},
"autoload": {
"classmap": [
"vendor"
]
},
"extra": {
"strauss": {
"target_directory": "vendor-namespaced",
"namespace_prefix": "ProBlockBuilder\\",
"classmap_prefix": "ProBlockBuilder_",
"classmap_output": true,
"packages": [
"trustedlogin/client"
]
}
},
"scripts": {
"strauss": [
"@php strauss.phar"
],
"trustedlogin": [
"@php vendor/bin/build-sass --namespace=ProBlockBuilder"
],
"post-install-cmd": [
"@strauss",
"@trustedlogin"
],
"post-update-cmd": [
"@strauss",
"@trustedlogin"
]
}
[...]
3. Run composer update
Run composer update
to update your dependencies. Strauss should generate a vendor-namespaced/
directory. If it doesn't, you may need to run composer install
first.
4. Include the autoloader
When using Composer, you likely already have added an autoloader to your code using something like require_once 'vendor/autoload.php';
. If not, do so:
require_once 'vendor/autoload.php';
If you set classmap_output
to false
in the Strauss configuration, you will need to include the autoloader in your code. If using the sample configuration above, the autoloader would be located at vendor-namepaced/autoload.php
and the code would be:
// For a plugin or theme:
include_once trailingslashit( dirname( __FILE__ ) ) . 'vendor-namespaced/autoload.php';