PHP code example of utopia-php / detector
1. Go to this page and download the library: Download utopia-php/detector 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/ */
utopia-php / detector example snippets
topia\Detector\Detector\Framework;
use Utopia\Detector\Detector\Packager;
use Utopia\Detector\Detector\Rendering;
use Utopia\Detector\Detector\Runtime;
use Utopia\Detector\Detector\Strategy;
// Initialise Packager Detection
$files = ['bun.lockb', 'fly.toml', 'package.json', 'remix.config.js'];
$detector = new Packager($files);
$detector
->addOption(new PNPM())
->addOption(new Yarn())
->addOption(new NPM());
$detectedPackager = $detector->detect();
$packagerName = $detectedPackager->getName();
// Initialise Runtime Detection
$detector = new Runtime(
$files,
new Strategy(Strategy::FILEMATCH), // similar for LANGUAGES and EXTENSIONS
'npm'
);
$detector
->addOption(new Node())
->addOption(new Bun())
->addOption(new Deno())
->addOption(new PHP())
->addOption(new Python())
->addOption(new Dart())
->addOption(new Swift())
->addOption(new Ruby())
->addOption(new Java())
->addOption(new CPP())
->addOption(new Dotnet());
$detectedRuntime = $detector->detect();
$runtime = $detectedRuntime->getName();
$runtimeCommands = $detectedRuntime->getCommands();
// Initialise Framework Detection
$files = ['src', 'types', 'makefile', 'components.js', 'debug.js', 'package.json', 'svelte.config.js'];
$packager = 'npm';
$detector = new Framework($files, $packager);
$detector
->addOption(new Flutter())
->addOption(new Nuxt())
->addOption(new Astro())
->addOption(new Analog())
->addOption(new Angular())
->addOption(new Remix())
->addOption(new SvelteKit())
->addOption(new Lynx())
->addOption(new NextJs());
$detectedFramework = $detector->detect();
$framework = $detectedFramework->getName();
$frameworkInstallCommand = $framework = $detectedFramework->getInstallCommand();
// Initialise Rendering Detection
$files = ['./build/server/index.js', './build/server/renderers.js'];
$framework = 'remix';
$detector = new Rendering($files, $framework);
$detector
->addOption(new SSR())
->addOption(new Static());
$detectedRendering = $detector->detect();
$rendering = $detectedRendering->getName();
bash
composer