PHP code example of humanmade / asset-manager-framework

1. Go to this page and download the library: Download humanmade/asset-manager-framework 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/ */

    

humanmade / asset-manager-framework example snippets


use AssetManagerFramework\{
	ProviderRegistry
	Provider,
	MediaList,
	MediaResponse,
	Image
};

class KittenProvider extends Provider {

	public function get_id() {
		return 'kittens';
	}

	public function get_name() {
		return __( 'Place Kitten' );
	}

	protected function request( array $args ) : MediaResponse {
		$kittens = [
			500 => 'Boop',
			600 => 'Fuzzy',
			700 => 'Paws',
		];
		$items = [];

		foreach ( $kittens as $id => $title ) {
			$item = new Image( $id, 'image/jpeg' );
			$item->set_url( sprintf(
				'https://placekitten.com/%1$d/%1$d',
				$id
			) );
			$item->set_title( $title );
			$item->set_width( $id );
			$item->set_height( $id );

			$items[] = $item;
		}

		return new MediaResponse(
			new MediaList( ...$items ),
			count( $kittens ), // Total number of available results.
			count( $kittens )  // Number of items requested per page.
		);
	}

}

add_action( 'amf/register_providers', function ( ProviderRegistry $provider_registry ) {
	$provider_registry->register( new KittenProvider() );
} );

add_filter( 'amf/provider', function ( Provider $provider ) {
	if ( $provider->get_id() !== 'kittens' ) {
		return $provider;
	}

	return new DecoratingProvider( $provider );
} );