Skip to content

Commit a02c57e

Browse files
authored
Merge pull request #1 from soderlind/add/namespace
Add namespace
2 parents 743b36f + 3ee706b commit a02c57e

36 files changed

+3288
-3996
lines changed

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,21 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on Keep a Changelog and adheres to Semantic Versioning.
66

7+
8+
## [1.2.0] - 2025-10-10
9+
### Removed
10+
- Dropped all legacy global class aliases (previous `class_alias` guards) now that backward compatibility is not required.
11+
- Removed deprecated `includes/` directory and emptied legacy interface stubs.
12+
- Removed legacy job_type inference variants (e.g. email_job, Email_Job, image_processing_job, api_sync_job); only canonical keys `email`, `image_processing`, `api_sync` are accepted now.
13+
- Removed bootstrap fallback to legacy global `Sync_Worker` (namespaced worker is now required).
14+
- Deleted development-only `debug.php` script (replaced by internal diagnostics via `Redis_Queue_Manager::diagnostic()`).
15+
### Changed
16+
- Codebase now exclusively uses namespaced classes; no global fallbacks remain.
17+
- Documentation updated to remove legacy references (includes/ directory, global class name variants) and reflect canonical job type usage only.
18+
719
## [1.0.2] - 2025-10-10
820
### Added
9-
- GitHub updater integration and release workflows (`.github/workflows/*`, `includes/class-github-plugin-updater.php`).
21+
- GitHub updater integration and release workflows (`.github/workflows/*`, `class-github-plugin-updater.php`).
1022
- Funding configuration (`.github/FUNDING.yml`).
1123
- Expanded root README with direct links to documentation set.
1224
- Composer metadata: enriched description & keywords.

README.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,61 @@ Made with ❤️ by [Per Søderlind](https://soderlind.com)
317317

318318
---
319319

320-
For detailed usage, advanced features, troubleshooting, and performance tuning visit the [Usage guide](docs/usage.md). Additional topics: [Scaling](docs/scaling.md), [Maintenance](docs/maintenance.md).
320+
For detailed usage, advanced features, troubleshooting, and performance tuning visit the [Usage guide](docs/usage.md). Additional topics: [Scaling](docs/scaling.md), [Maintenance](docs/maintenance.md).
321+
322+
## Namespacing & Backward Compatibility (Refactor Notes)
323+
324+
As of the latest refactor, all core classes have been migrated to the `Soderlind\\RedisQueueDemo` namespace and autoloaded via Composer PSR-4. Legacy global class names (`Redis_Queue_Demo`, `Redis_Queue_Manager`, `Job_Processor`, `Sync_Worker`, `REST_Controller`, `Admin_Interface`, job classes, etc.) are still available through `class_alias` so existing integrations that referenced the old globals continue to work without modification.
325+
326+
Removed legacy duplicate files:
327+
```
328+
admin/class-admin-interface.php
329+
api/class-rest-controller.php
330+
workers/class-sync-worker.php
331+
```
332+
Their logic now lives in:
333+
```
334+
src/Admin/Admin_Interface.php
335+
src/API/REST_Controller.php
336+
src/Workers/Sync_Worker.php
337+
```
338+
339+
Helper functions (`redis_queue_demo()`, `redis_queue_enqueue_job()`, `redis_queue_process_jobs()`) remain unchanged for ergonomics.
340+
341+
If you previously required or included specific legacy files manually, you should remove those `require` statements—Composer autoload now handles class loading.
342+
343+
### Migrating Custom Integrations
344+
345+
If you instantiated legacy classes directly, both of the following are now equivalent:
346+
```php
347+
$manager = new Redis_Queue_Manager(); // legacy global (still works)
348+
$manager = new \Soderlind\RedisQueueDemo\Core\Redis_Queue_Manager(); // namespaced
349+
```
350+
351+
Custom job classes should adopt the namespace pattern and be placed under `src/YourNamespace/` with an appropriate `composer.json` autoload mapping, or hooked via the `redis_queue_demo_create_job` filter returning a namespaced job instance.
352+
353+
### Why This Change?
354+
355+
1. Autoload performance & structure clarity.
356+
2. Avoiding global symbol collisions.
357+
3. Easier extension via modern PHP tooling.
358+
4. Future unit test isolation.
359+
360+
If you encounter any missing class errors after upgrading, clear WordPress object/opcode caches and run:
361+
```bash
362+
composer dump-autoload -o
363+
```
364+
365+
Please report any backward compatibility regressions in the issue tracker.
366+
367+
### Admin Interface Inlining (UI Unchanged)
368+
369+
The legacy `admin/class-admin-interface.php` file was fully inlined into the namespaced `src/Admin/Admin_Interface.php` to remove manual `require` calls. To preserve the exact markup/CSS hooks, the original page layouts were ported as partial templates under:
370+
```
371+
src/Admin/partials/
372+
dashboard-inline.php
373+
jobs-inline.php
374+
test-inline.php
375+
settings-inline.php
376+
```
377+
These are loaded internally by the namespaced class; you should not include them directly. If you previously overrode or filtered admin output, existing selectors and element structures remain stable.

includes/class-github-plugin-updater.php renamed to class-github-plugin-updater.php

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,20 @@
66
/**
77
* Generic WordPress Plugin GitHub Updater
88
*
9-
* A reusable class for handling WordPress plugin updates from GitHub repositories
10-
* using the plugin-update-checker library.
9+
* Moved from includes/ to plugin root in version 1.0.0.
1110
*
1211
* @package Soderlind\WordPress
1312
* @version 1.0.0
14-
* @author Per Soderlind
15-
* @license GPL-2.0+
1613
*/
1714
class GitHub_Plugin_Updater {
18-
/**
19-
* @var string GitHub repository URL
20-
*/
2115
private $github_url;
22-
23-
/**
24-
* @var string Branch to check for updates
25-
*/
2616
private $branch;
27-
28-
/**
29-
* @var string Regex pattern to match the plugin zip file name
30-
*/
3117
private $name_regex;
32-
33-
/**
34-
* @var string The plugin slug
35-
*/
3618
private $plugin_slug;
37-
38-
/**
39-
* @var string The main plugin file path
40-
*/
4119
private $plugin_file;
42-
43-
/**
44-
* @var bool Whether to enable release assets
45-
*/
4620
private $enable_release_assets;
4721

48-
/**
49-
* Constructor
50-
*
51-
* @param array $config Configuration array with the following keys:
52-
* - github_url: GitHub repository URL (required)
53-
* - plugin_file: Main plugin file path (required)
54-
* - plugin_slug: Plugin slug for updates (required)
55-
* - branch: Branch to check for updates (default: 'main')
56-
* - name_regex: Regex pattern for zip file name (optional)
57-
* - enable_release_assets: Whether to enable release assets (default: true if name_regex provided)
58-
*/
5922
public function __construct( $config = array() ) {
60-
// Validate required parameters
6123
$required = array( 'github_url', 'plugin_file', 'plugin_slug' );
6224
foreach ( $required as $key ) {
6325
if ( empty( $config[ $key ] ) ) {
@@ -74,13 +36,9 @@ public function __construct( $config = array() ) {
7436
? $config[ 'enable_release_assets' ]
7537
: ! empty( $this->name_regex );
7638

77-
// Initialize the updater
7839
add_action( 'init', array( $this, 'setup_updater' ) );
7940
}
8041

81-
/**
82-
* Set up the update checker using GitHub integration
83-
*/
8442
public function setup_updater() {
8543
try {
8644
$update_checker = PucFactory::buildUpdateChecker(
@@ -91,29 +49,16 @@ public function setup_updater() {
9149

9250
$update_checker->setBranch( $this->branch );
9351

94-
// Enable release assets if configured
9552
if ( $this->enable_release_assets && ! empty( $this->name_regex ) ) {
9653
$update_checker->getVcsApi()->enableReleaseAssets( $this->name_regex );
9754
}
98-
9955
} catch (\Exception $e) {
100-
// Log error if WordPress debug is enabled
10156
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
10257
error_log( 'GitHub Plugin Updater Error: ' . $e->getMessage() );
10358
}
10459
}
10560
}
10661

107-
/**
108-
* Create updater instance with minimal configuration
109-
*
110-
* @param string $github_url GitHub repository URL
111-
* @param string $plugin_file Main plugin file path
112-
* @param string $plugin_slug Plugin slug
113-
* @param string $branch Branch name (default: 'main')
114-
*
115-
* @return GitHub_Plugin_Updater
116-
*/
11762
public static function create( $github_url, $plugin_file, $plugin_slug, $branch = 'main' ) {
11863
return new self( array(
11964
'github_url' => $github_url,
@@ -123,17 +68,6 @@ public static function create( $github_url, $plugin_file, $plugin_slug, $branch
12368
) );
12469
}
12570

126-
/**
127-
* Create updater instance for plugins with release assets
128-
*
129-
* @param string $github_url GitHub repository URL
130-
* @param string $plugin_file Main plugin file path
131-
* @param string $plugin_slug Plugin slug
132-
* @param string $name_regex Regex pattern for release assets
133-
* @param string $branch Branch name (default: 'main')
134-
*
135-
* @return GitHub_Plugin_Updater
136-
*/
13771
public static function create_with_assets( $github_url, $plugin_file, $plugin_slug, $name_regex, $branch = 'main' ) {
13872
return new self( array(
13973
'github_url' => $github_url,

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,10 @@
2626
"support": {
2727
"issues": "https://github.com/soderlind/redis-queue-demo/issues"
2828
},
29-
"require": {}
29+
"require": {},
30+
"autoload": {
31+
"psr-4": {
32+
"Soderlind\\RedisQueueDemo\\": "src/"
33+
}
34+
}
3035
}

design.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,7 @@ redis-queue-demo/
299299
├── redis-queue-demo.php # Main plugin file
300300
├── uninstall.php # Cleanup on plugin removal
301301
├── includes/ # Core functionality
302-
│ ├── class-redis-queue-manager.php
303302
│ ├── class-queue-worker.php
304-
│ ├── class-job-processor.php
305303
│ └── interfaces/
306304
│ ├── interface-queue-job.php
307305
│ └── interface-job-result.php

docs/extending-jobs.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This guide explains how to create custom background jobs by extending the base a
44

55
## Core Concepts
66

7+
Important: The plugin now exclusively uses namespaced classes and only canonical job type identifiers you define (e.g. `email`, `image_processing`, `api_sync`, or your custom strings). Legacy/global class name variants (like `Email_Job`, `email_job`) are not auto-mapped.
8+
79
A job represents a unit of work executed asynchronously by a worker. Each job class encapsulates:
810

911
- A unique job type identifier (string)

docs/usage.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,30 @@ curl -X POST "https://yoursite.com/wp-json/redis-queue/v1/jobs" \
8585

8686
### Creating & Enqueuing Jobs
8787
```php
88-
$redis_queue = redis_queue_demo();
88+
use Soderlind\RedisQueueDemo\Jobs\Email_Job;
8989

9090
$email_job = new Email_Job([
91-
'email_type' => 'single',
92-
'to' => 'user@example.com',
93-
'subject' => 'Welcome!',
94-
'message' => 'Welcome to our site!'
91+
'email_type' => 'single',
92+
'to' => 'user@example.com',
93+
'subject' => 'Welcome!',
94+
'message' => 'Welcome to our site!'
9595
]);
9696

9797
$email_job->set_priority(10);
9898
$email_job->set_queue_name('emails');
9999

100-
$job_id = $redis_queue->queue_manager->enqueue($email_job);
100+
$job_id = redis_queue_demo()->get_queue_manager()->enqueue( $email_job );
101101
```
102102

103103
### Processing Jobs Manually
104104
```php
105+
use Soderlind\RedisQueueDemo\Workers\Sync_Worker;
106+
105107
$worker = new Sync_Worker(
106-
$redis_queue->queue_manager,
107-
$redis_queue->job_processor
108+
redis_queue_demo()->get_queue_manager(),
109+
redis_queue_demo()->get_job_processor()
108110
);
109-
$results = $worker->process_jobs(['default', 'emails'], 5);
111+
$results = $worker->process_jobs( [ 'default', 'emails' ], 5 );
110112
```
111113

112114
### Custom Job Skeleton

0 commit comments

Comments
 (0)