Composer - Manage library and dependency of files and program.
Download and install - https://getcomposer.org.
Directory - Go to the specific folder in Command prompt. Like C:\>cd C:\xampp\htdocs\project3\wp-content\plugins\iftekhar-plugin.
- Before Install (Optional)
- Set path (D:\xapmm\php)
- Environment Variables->System Variables->Path->New->(D:\xapmm\php)New->OK
- Check PHP status(Version)
- C:\Users\iftekhar>php -v
- Install
- https://getcomposer.org/ -> Getting Started -> Download Composer-Setup.exe.
- Finish Install.
- Write composer in command prompt and displays all composer command if successfully installed.
- If composer install isn't possible then add vendor folder in the project folder.
- Add projects with composer | Commands
- C:\>cd C:\xampp\htdocs\...\iftekhar-plugin(sample)>composer init
- Welcome to the Composer config generator , This command will guide you through creating your composer.json config.
- Package name (<vendor>/<name>) [dell_bwdb/iftekhar-plugin]:Press enter
- Description: Add Description
- Author: Press enter [automatically recognize]
- Minimum Stability: dev
- Package Type: Project
- License: MIT/GPL
- Dependencies: no(built in composer auto load)[Yes when need packages]
- Dev dependencies: no.
- Confirm generation: yes [Finished]
- Now it's generate: compose. json file.
- Add Auto loading options [For example we use Reference folder name Inc and inc is the folder]
- Add auto loader in composer.json
- After "require"{}, add-> "autoload": {
"psr-4": {"Inc\\": "./inc"} //it locates inc folder using Inc.
} - C:\>cd C:\xampp\htdocs\...\iftekhar-plugin>composer install
- Edit
- C:\>cd C:\xampp\htdocs\...\iftekhar-plugin>composer dump-atuoload
- Don't edit anything inside vendor file everything manage by json flie.
- Only one require_once after using autoload | Use in parent file (index.php or abc.php)
- if ( file_exists( dirname( __FILE__ ) . '/vendor/autoload.php' ) ) {
require_once dirname( __FILE__ ) . '/vendor/autoload.php';
} - Add "use Inc\Activate;'' line in parent file (use backward slash).
- Reference page or child page or other page
- Namespace like: namespace Inc;
- psr-4 convention: Class name (class Iftekhar{...} ) and page mane should be similar(Iftekhar.php).
No comments:
Post a Comment