Installation Add the package via Composer:
composer require asoc/dadatata
Publish the config (if needed) with:
php artisan vendor:publish --provider="AStateOfCode\Dadatata\DadatataServiceProvider"
First Use Case: Metadata Extraction
Extract metadata from a file (e.g., example.mp3):
use AStateOfCode\Dadatata\File;
use AStateOfCode\Dadatata\Extractors\MetadataExtractor;
$file = new File('path/to/example.mp3');
$metadata = (new MetadataExtractor())->extract($file);
// Output metadata (e.g., duration, bitrate, etc.)
dd($metadata);
Key Classes to Know
File: Represents a file with path, MIME type, and metadata.Extractor: Base class for metadata/MIME extraction (e.g., MetadataExtractor, MimeTypeExtractor).Filter: Base class for transformations (e.g., ImageResizeFilter, PdfConvertFilter).Pipeline: Chains filters for sequential processing.Define a Pipeline Chain filters for a multi-step transformation (e.g., ODT → PDF → Thumbnail):
use AStateOfCode\Dadatata\Pipeline;
use AStateOfCode\Dadatata\Filters\PdfConvertFilter;
use AStateOfCode\Dadatata\Filters\ImageThumbnailFilter;
$pipeline = new Pipeline();
$pipeline->add(new PdfConvertFilter()) // ODT → PDF
->add(new ImageThumbnailFilter()); // PDF → Thumbnail
$result = $pipeline->process($file);
Conditional Filtering
Use file categories (e.g., Image, Document) to dynamically apply filters:
$mimeExtractor = new MimeTypeExtractor();
$category = $mimeExtractor->getCategory($file);
if ($category === 'Image') {
$pipeline->add(new ImageResizeFilter(800, 600));
}
CLI Tool Integration
Leverage built-in wrappers (e.g., FFmpeg, Unoconv) for heavy lifting:
use AStateOfCode\Dadatata\Tools\FFmpeg;
$ffmpeg = new FFmpeg();
$duration = $ffmpeg->getDuration($file);
Laravel Integration
DadatataCommand for CLI tasks.use AStateOfCode\Dadatata\Jobs\ProcessFilePipeline;
ProcessFilePipeline::dispatch($file)->onQueue('media');
Custom Extractors/Filters Extend base classes to support new tools or formats:
class CustomExtractor extends Extractor {
public function extract(File $file) {
// Custom logic (e.g., call external tool)
}
}
Tool Dependencies
$PATH. Configure paths in config/dadatata.php:
'tools' => [
'ffmpeg' => '/usr/local/bin/ffmpeg',
'unoconv' => '/usr/bin/unoconv',
],
Tool::isAvailable() to check if a tool is installed.File Handling
File::delete() or Laravel’s Storage facade.Pipeline Failures
try-catch to handle tool failures:
try {
$result = $pipeline->process($file);
} catch (ToolException $e) {
Log::error("Pipeline failed: " . $e->getMessage());
return back()->withError('Processing failed');
}
Metadata Inconsistencies
MetadataExtractor + MimeTypeExtractor) for robustness:
$metadata = (new MetadataExtractor())->extract($file);
$mime = (new MimeTypeExtractor())->getMimeType($file);
Performance
$cacheKey = "metadata_{$file->getPath()}";
$metadata = Cache::remember($cacheKey, now()->addHours(1), function() use ($file) {
return (new MetadataExtractor())->extract($file);
});
Testing
Mockery to test filters without calling system tools:
$mockFFmpeg = Mockery::mock('AStateOfCode\Dadatata\Tools\FFmpeg');
$this->app->instance('AStateOfCode\Dadatata\Tools\FFmpeg', $mockFFmpeg);
Extending the Package
WebPResizeFilter) by extending Filter.Debugging
'debug' => env('DADATATA_DEBUG', false),
Log::debug() for troubleshooting.Laravel Storage
Storage facade to read/write files:
$filePath = Storage::disk('public')->path('uploads/example.mp3');
$file = new File($filePath);
How can I help you explore Laravel packages today?