PHP code example of tourze / operation-system-enum

1. Go to this page and download the library: Download tourze/operation-system-enum 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/ */

    

tourze / operation-system-enum example snippets


use Tourze\OperationSystemEnum\Platform;

// Get all platform cases
$platforms = Platform::cases();

// Get platform by value
$platform = Platform::from('WINDOWS');

// Get platform with fallback
$platform = Platform::tryFrom('INVALID'); // returns null

// Get platform label
echo Platform::WINDOWS->getLabel(); // "Windows"
echo Platform::ANDROID->getLabel(); // "安卓"

use Tourze\OperationSystemEnum\Platform;

// Mixed input support with compatibility
$platform = Platform::mixFrom('mac');     // returns Platform::MACOS
$platform = Platform::mixFrom('darwin');  // returns Platform::MACOS
$platform = Platform::mixFrom('win');     // returns Platform::WINDOWS
$platform = Platform::mixFrom('win32');   // returns Platform::WINDOWS

// Convert to array format
$data = Platform::WINDOWS->toArray();
// Returns: ['value' => 'WINDOWS', 'label' => 'Windows']

// Generate select options for frontend
$options = Platform::genOptions();
// Returns array of ['label' => '...', 'text' => '...', 'value' => '...', 'name' => '...']