- Created separate MoneyFlix project directory - Copied Node.js redirector from production server - Added CRM PHP code (Redirects module, Core classes, Config, Routes, Views) - Created comprehensive documentation (README_MONEYFLIX.md) - Added sync script to keep CRM code updated (sync-from-crm.sh) - Configured .gitignore for Node.js and PHP - Set up proper project structure for multi-client isolation This separates MoneyFlix from the main CRM to avoid confusion between different client systems and provides a dedicated environment for MoneyFlix-specific development and maintenance.
222 lines
5.6 KiB
PHP
222 lines
5.6 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Core;
|
|
|
|
/**
|
|
* Classe utilitária para gerar paths de assets
|
|
* Garante consistência e facilita mudanças futuras
|
|
*/
|
|
class AssetPath
|
|
{
|
|
/**
|
|
* Base path para assets
|
|
*/
|
|
private static string $basePath = '/assets';
|
|
|
|
/**
|
|
* Gerar path para CSS
|
|
*/
|
|
public static function css(string $file): string
|
|
{
|
|
return self::$basePath . '/css/' . ltrim($file, '/');
|
|
}
|
|
|
|
/**
|
|
* Gerar path para JavaScript
|
|
*/
|
|
public static function js(string $file): string
|
|
{
|
|
return self::$basePath . '/js/' . ltrim($file, '/');
|
|
}
|
|
|
|
/**
|
|
* Gerar path para imagens
|
|
*/
|
|
public static function image(string $file): string
|
|
{
|
|
return self::$basePath . '/images/' . ltrim($file, '/');
|
|
}
|
|
|
|
/**
|
|
* Gerar path para fontes
|
|
*/
|
|
public static function font(string $file): string
|
|
{
|
|
return self::$basePath . '/fonts/' . ltrim($file, '/');
|
|
}
|
|
|
|
/**
|
|
* Gerar path para libs (bibliotecas externas)
|
|
*/
|
|
public static function lib(string $file): string
|
|
{
|
|
return self::$basePath . '/libs/' . ltrim($file, '/');
|
|
}
|
|
|
|
/**
|
|
* Gerar path para JSON
|
|
*/
|
|
public static function json(string $file): string
|
|
{
|
|
return self::$basePath . '/json/' . ltrim($file, '/');
|
|
}
|
|
|
|
/**
|
|
* Gerar path para lordicon
|
|
*/
|
|
public static function lordicon(string $file): string
|
|
{
|
|
return self::$basePath . '/lordicon/' . ltrim($file, '/');
|
|
}
|
|
|
|
/**
|
|
* Gerar path para lang (traduções)
|
|
*/
|
|
public static function lang(string $file): string
|
|
{
|
|
return self::$basePath . '/lang/' . ltrim($file, '/');
|
|
}
|
|
|
|
/**
|
|
* Gerar path para SCSS
|
|
*/
|
|
public static function scss(string $file): string
|
|
{
|
|
return self::$basePath . '/scss/' . ltrim($file, '/');
|
|
}
|
|
|
|
/**
|
|
* Gerar path genérico
|
|
*/
|
|
public static function path(string $path): string
|
|
{
|
|
return self::$basePath . '/' . ltrim($path, '/');
|
|
}
|
|
|
|
/**
|
|
* Definir base path (útil para testes ou configurações especiais)
|
|
*/
|
|
public static function setBasePath(string $path): void
|
|
{
|
|
self::$basePath = rtrim($path, '/');
|
|
}
|
|
|
|
/**
|
|
* Obter base path atual
|
|
*/
|
|
public static function getBasePath(): string
|
|
{
|
|
return self::$basePath;
|
|
}
|
|
|
|
/**
|
|
* Verificar se asset existe
|
|
*/
|
|
public static function exists(string $path): bool
|
|
{
|
|
$fullPath = $_SERVER['DOCUMENT_ROOT'] . self::path($path);
|
|
return file_exists($fullPath);
|
|
}
|
|
|
|
/**
|
|
* Obter timestamp do asset para cache busting
|
|
*/
|
|
public static function version(string $path): string
|
|
{
|
|
$fullPath = $_SERVER['DOCUMENT_ROOT'] . self::path($path);
|
|
|
|
if (file_exists($fullPath)) {
|
|
return '?v=' . filemtime($fullPath);
|
|
}
|
|
|
|
return '';
|
|
}
|
|
|
|
/**
|
|
* Gerar path com version para cache busting
|
|
*/
|
|
public static function versioned(string $path): string
|
|
{
|
|
return self::path($path) . self::version($path);
|
|
}
|
|
|
|
/**
|
|
* Gerar path para bundle principal
|
|
*/
|
|
public static function bundle(): string
|
|
{
|
|
return self::js('app.bundle.js') . self::version('js/app.bundle.js');
|
|
}
|
|
|
|
/**
|
|
* Gerar path para CSS principal
|
|
*/
|
|
public static function stylesheet(): string
|
|
{
|
|
return self::css('app.bundle.css') . self::version('css/app.bundle.css');
|
|
}
|
|
|
|
/**
|
|
* Get the latest JS bundle (app.*.js ou public.*.js), com cache estática.
|
|
* @param string $type 'app' ou 'public'
|
|
* @return string Caminho relativo para o bundle
|
|
*/
|
|
public static function getLatestJsBundle(string $type = 'app'): string
|
|
{
|
|
static $cache = [];
|
|
if (isset($cache[$type])) {
|
|
return $cache[$type];
|
|
}
|
|
$jsDir = defined('PUBLIC_PATH') ? PUBLIC_PATH . '/assets/js/' : $_SERVER['DOCUMENT_ROOT'] . '/assets/js/';
|
|
$pattern = $jsDir . $type . '.*.js';
|
|
$files = glob($pattern);
|
|
if (!empty($files)) {
|
|
usort($files, function($a, $b) { return filemtime($b) - filemtime($a); });
|
|
$cache[$type] = '/assets/js/' . basename($files[0]);
|
|
return $cache[$type];
|
|
}
|
|
// Fallbacks
|
|
if ($type === 'public' && file_exists($jsDir . 'public.bundle.js')) {
|
|
$cache[$type] = '/assets/js/public.bundle.js';
|
|
return $cache[$type];
|
|
}
|
|
if (file_exists($jsDir . 'app.bundle.js')) {
|
|
$cache[$type] = '/assets/js/app.bundle.js';
|
|
return $cache[$type];
|
|
}
|
|
$cache[$type] = '';
|
|
return '';
|
|
}
|
|
|
|
/**
|
|
* Get the vendor bundle path (vendor.*.js)
|
|
* @return string Caminho relativo para o vendor bundle
|
|
*/
|
|
public static function getVendorBundle(): string
|
|
{
|
|
static $cache = null;
|
|
if ($cache !== null) {
|
|
return $cache;
|
|
}
|
|
|
|
$jsDir = defined('PUBLIC_PATH') ? PUBLIC_PATH . '/assets/js/' : $_SERVER['DOCUMENT_ROOT'] . '/assets/js/';
|
|
$pattern = $jsDir . 'vendor.*.js';
|
|
$files = glob($pattern);
|
|
|
|
if (!empty($files)) {
|
|
usort($files, function($a, $b) { return filemtime($b) - filemtime($a); });
|
|
$cache = '/assets/js/' . basename($files[0]);
|
|
return $cache;
|
|
}
|
|
|
|
// Fallback
|
|
if (file_exists($jsDir . 'vendor.bundle.js')) {
|
|
$cache = '/assets/js/vendor.bundle.js';
|
|
return $cache;
|
|
}
|
|
|
|
$cache = '';
|
|
return '';
|
|
}
|
|
}
|