PHP code example of helsingborg-stad / wputilservice

1. Go to this page and download the library: Download helsingborg-stad/wputilservice library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

helsingborg-stad / wputilservice example snippets


use WpService\NativeWpService;
use WpUtilService\WpUtilService;

$wpService = new NativeWpService();
$wpUtilService = new WpUtilService($wpService);

$wpUtilService
    ->enqueue(__DIR__)
    ->on('wp_enqueue_scripts', 20)
    ->add('main.js', ['jquery'])
    ->with()->translation(
        'objectName',
        ['localization_a' => __('Test', 'testdomain')]
    )->and()->data(
        'objectName', 
        ['id' => 1]
    );

$wpUtilService
    ->enqueue(__DIR__)
    ->add('main.js', ['jquery'])
    ->with('translation', 'objectName', ['localization_a' => __('Test', 'testdomain')])
    ->and('data', 'objectName', ['id' => 1]);

$wpUtilService
    ->enqueue(__DIR__)
    ->add('main.js', ['jquery'])
    ->with('translation', 'objectName', ['localization_a' => __('Test', 'testdomain')])
    ->with('data', 'objectName', ['id' => 1]);

$wpUtilService
    ->enqueue(__DIR__)
    ->add('main.js', ['jquery'])
    ->with('data', 'objectName', ['id' => 1]);
    ->add('main.css')
    ->add('styleguide.css');

$enqueue = $wpUtilService->enqueue(__DIR__); 
$enqueue->add('main.js', ['jquery']); 
$enqueue->add('main.css'); 

$cacheBustManager = new CacheBustManager();


src/
├─ WpUtilService.php          # Main service (facade)
├─ Traits/
│  ├─ Enqueue.php             # Trait for enqueue feature
│  ├─ Translation.php         # Trait for translation feature
├─ Features/
│  ├─ EnqueueManager.php      # Manager class for enqueue
│  ├─ TranslationManager.php  # Manager class for translation
│  ├─ CacheBuster.php         # Optional helper
├─ Contracts/
   ├─ Enqueue.php             # Interface
   ├─ Translation.php         # Interface