PHP code example of mistralys / cyberpunk-mod-db-php

1. Go to this page and download the library: Download mistralys/cyberpunk-mod-db-php 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/ */

    

mistralys / cyberpunk-mod-db-php example snippets


use CPMDB\Mods\Collection\ModCollection;

// Create a collection instance
$collection = ModCollection::create(
    __DIR__.'/vendor', // Absolute path to the composer vendor directory
    __DIR__.'/cache', // Path to a writable directory to store cache files
    'http://127.0.0.1/your-app/vendor' // Absolute URL to the composer vendor directory
);

// Get all mods
$mods = $collection->getAll();

// Get only clothing mods
$clothing = $collection->categoryClothing()->getAll();

// Get a mod by its UUID (unique identifier, category ID + mod ID)
$catsuit = $collection->getByID('clothing.catsuit');

// Get the screenshot URL for a mod
if($catsuit->hasImage()) {
    echo '<img src"'.$catsuit->getImageURL().'">';
}

use CPMDB\Mods\Collection\ModCollection;

// Create a collection instance
$collection = ModCollection::create(
    __DIR__.'/vendor', // Absolute path to the composer vendor directory
    __DIR__.'/cache', // Path to a writable directory to store cache files
    'http://127.0.0.1/your-app/vendor' // Absolute URL to the composer vendor directory
);

// Get the item collection
$itemsCollection = $collection->getItemCollection();

// Get an item by its CET code 
$dress = $itemsCollection->getByID('nd_michiko_dress_black');

// Get the CET command to add the item in-game
$dress->getCETCommand();

use CPMDB\Mods\Collection\ModCollection;
use \CPMDB\Mods\Tags\Types\Outfit;

// Create a collection instance
$collection = ModCollection::create(
    __DIR__.'/vendor', // Absolute path to the composer vendor directory
    __DIR__.'/cache', // Path to a writable directory to store cache files
    'http://127.0.0.1/your-app/vendor' // Absolute URL to the composer vendor directory
);

// Search for "catsuit" and only get mods with the "Outfit" tag
$mods = $collection->createFilter()
    ->selectSearchTerm('catsuit')
    ->selectTag(Outfit::TAG_NAME)
    ->getMods();

use CPMDB\Mods\Collection\ModCollection;
use CPMDB\Mods\Tags\Types\Jewelry;

// Create a collection instance
$collection = ModCollection::create(
    __DIR__.'/vendor', // Absolute path to the composer vendor directory
    __DIR__.'/cache', // Path to a writable directory to store cache files
    'http://127.0.0.1/your-app/vendor' // Absolute URL to the composer vendor directory
);

// Search for the Jewelry tag to get all jewelry mod items
$mods = $collection->createItemFilter()
    ->selectTag(Jewelry::TAG_NAME)
    ->getItems();

// Use the item collection for helper methods like getting
// items by their CET code
$mods = $collection->createItemFilter()
    ->selectTag(Jewelry::TAG_NAME)
    ->getItemsAsCollection()
    ->getByItemCode('earrings_08_basic_04_kwek');

// Combine as many filter criteria as needed
$mods = $collection->createItemFilter()
    ->selectSearchTerm('earrings')
    ->selectTag(Jewelry::TAG_NAME)
    ->selectTag(Physics::TAG_NAME)
    ->getItemsAsCollection();

$cetTag = \CPMDB\Mods\Tags\Types\CyberEngineTweaks::TAG_NAME;
$clothingTag = \CPMDB\Mods\Tags\Types\Clothing::TAG_NAME;

use CPMDB\Mods\Tags\TagCollection;
use CPMDB\Mods\Tags\Types\CyberEngineTweaks;

$collection = TagCollection::getInstance();

// Get all tags
$all = $collection->getAll();

// Get a specific tag
$cet = $collection->getByID(CyberEngineTweaks::TAG_NAME);

// Additional tag meta data
echo 'Full label: '.$cet->getLabel();
echo 'Tag category: '.$cet->getCategory();

use CPMDB\Mods\Collection\DataWriter\CacheDataWriter;

CacheDataWriter::setCacheEnabled(false);
bash
php tests/performance/performance-test.php