Skip to content

Commit cf4ee85

Browse files
author
Mario Borna Mjertan
committed
Improve namespaces article
1 parent 38f3eb1 commit cf4ee85

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

website/docs/basics/namespaces.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ title: Namespaces
55

66
[![docs-source](https://img.shields.io/badge/source-eightshift--libs-blue?style=for-the-badge&logo=php&labelColor=2a2a2a)](https://github.com/infinum/eightshift-libs)
77

8-
> PHP part of this project lives in `EightshiftLibs` namespace.
8+
> The PHP codebase of this project lives in `EightshiftLibs` namespace.
99
10-
Because WordPress lives in a global namespace, we had to provide the way for your project to be unique. That is why we implemented [**Imposter**](https://github.com/infinum/imposter-plugin) script inside `composer.json`. Imposter adds a namespace prefix on all the packages inside the `vendor` folder that uses namespacing.
10+
Because WordPress lives in a global namespace, we had to provide the way for your project to be unique. That is why we implemented [**Imposter**](https://github.com/infinum/imposter-plugin) in `composer.json`. Imposter adds a namespace prefix to all the packages inside the `vendor` folder that use namespacing.
1111

12-
You can change the vendor prefix in your `composer.json` file. But if you do this, make sure you delete the `vendor` folder before running the command to install the composer packages again with the `composer install` command.
12+
You can change the vendor prefix in your `composer.json` file. If you do this, make sure you delete the `vendor` folder and re-run `composer install`.
1313

14+
Using the default setup, your project will have the namespace you defined in the setup process.
1415

16+
However, let's say you change your `composer.json` file to contain this snippet:
1517
```json
1618
"autoload": {
1719
"psr-4": {
@@ -25,14 +27,16 @@ You can change the vendor prefix in your `composer.json` file. But if you do thi
2527
}
2628
```
2729

28-
For example, with the default setup, your project will have the namespace you defined in the setup process. But let's say you have the structure from the previous example:
29-
3030
- Your current namespace is: `CustomProject`.
31-
- Namespace for all packages used from Eightshift libs is `EightshiftBoilerplateVendor\CustomProject`.
32-
- Also, every package you additionally install will follow the same convention: `EightshiftBoilerplateVendor\SomePackageNamespace`.
31+
- Namespace for Eightshift Libs becomes: `EightshiftBoilerplateVendor\EightshiftLibs`.
32+
- Every package you additionally install will follow the same convention: `EightshiftBoilerplateVendor\SomePackageNamespace`.
3333

34-
**To sum it up**: you don't need to change the default vendor prefix if you only run one theme or one plugin with Eightshift Boilerplate. But if you have multiple Eightshift Boilerplate powered themes or plugins installed, please change the vendor prefix on each of the projects.
34+
**To sum it up**: you don't need to change the default vendor prefix if you only run one theme or one plugin with Eightshift Development Kit. If you have multiple Eightshift Development Kit-powered themes or plugins installed, please change the vendor prefix on each of the projects.
3535

3636
### Important note
3737

38-
If you are installing additional composer packages make sure that they don't have any inline namespace usage. All `use` keys must be defined in the top of the files. Imposter plugin is not able to resolve this and it will throw and fatal error. To fix this ether create a PR on the package and fix this for everyone, or you can exclude this package from imposter script. Keep in mind that can have some unexpected side effects that we can't predict.
38+
If you are installing additional composer packages, make sure that they don't have any inline namespace usage. All referenced classes should be imported with `use` statements, which must be defined at the top of files.
39+
40+
The Imposter plugin is not able to replace inline namespaces, which will cause issues with classname resolution and result in a fatal error getting thrown.
41+
42+
To fix these issues, either create a PR on the package and fix this for everyone, or exclude this package from imposter script. Keep in mind that can have some unexpected side effects that we can't predict.

0 commit comments

Comments
 (0)