dualmedia/common
Shared interfaces and reusable logic for DualMedia packages. Typically installed as an internal dependency rather than directly. Provides common contracts and helpers used across the DualMedia ecosystem.
Installation Add to your project via Composer (though the README warns against direct inclusion):
composer require dualmedia/common
Best practice: Only include this via a private package or monorepo dependency if you're building a DualMedia ecosystem.
First Use Case
Check the src/Contracts directory for shared interfaces (e.g., EntityInterface, RepositoryInterface). Example:
use DualMedia\Common\Contracts\EntityInterface;
class User implements EntityInterface {
public function getId(): string { ... }
}
Where to Look First
src/Contracts/: Core interfaces (e.g., RepositoryInterface, ServiceInterface).src/Traits/: Reusable logic (e.g., Uuids, Timestamps).src/Exceptions/: Shared exception hierarchy.Interface Adoption Extend shared interfaces to enforce consistency across services:
class ProductRepository implements \DualMedia\Common\Contracts\RepositoryInterface {
public function findById(string $id): ?EntityInterface { ... }
}
Trait Utilization Use traits for boilerplate (e.g., UUID handling):
use DualMedia\Common\Traits\Uuids;
class Order {
use Uuids;
protected string $id;
}
Exception Handling Catch base exceptions and rethrow domain-specific ones:
try {
$repository->delete($id);
} catch (\DualMedia\Common\Exceptions\NotFoundException $e) {
abort(404);
}
register():
$this->app->bind(
\DualMedia\Common\Contracts\RepositoryInterface::class,
\App\Repositories\ProductRepository::class
);
public function __construct(private RepositoryInterface $repository) {}
RepositoryInterface) in unit tests.Direct Usage Warning The package is designed for internal DualMedia use. Avoid direct dependency unless you’re part of their ecosystem.
PHP 8.3+ Requirement
Ensure your project meets the >=8.3 PHP version constraint.
Interface Rigidity
Overly strict interfaces (e.g., EntityInterface::getId() returning string) may require workarounds for legacy systems.
getId(): string).\DualMedia\Common\Exceptions\BaseException for domain-specific errors:
class InvalidOrderException extends BaseException {}
generateUuid()) for custom logic:
use DualMedia\Common\Traits\Uuids;
class CustomOrder {
use Uuids {
generateUuid as private generateCustomUuid;
}
public function generateUuid(): string { ... }
}
class LoggingRepository implements RepositoryInterface {
public function __construct(private RepositoryInterface $decorated) {}
public function findById(string $id): ?EntityInterface {
Log::info("Finding ID: {$id}");
return $this->decorated->findById($id);
}
}
config/services.php).How can I help you explore Laravel packages today?