germania-kg/categories

1.2.0 2023-01-09 14:36 UTC

This package is auto-updated.

Last update: 2024-12-09 18:47:41 UTC


README

This package was destilled from legacy code!
You better do not want it to use this in production.

Packagist PHP version Tests

Installation with Composer

$ composer require germania-kg/categories

MySQL: This package requires a MySQL tables categories which you can install using germania_categories.sql in sql/ directory.

Usage

While the Categories class is a simple storage, PdoCategories reads all downloads from the database. They both implement the PSR-11 ContainerInterface as well as its container-interop antecessor, IteratorAggregate and SPL's Countable.

<?php
use Germania\Categories\Categories;
use Germania\Categories\PdoCategories;
use Germania\Categories\Category;

//
// 1. Simple usage:
//
$categories = new Categories( );

$cat = new Category;
$cat->setSlug( 'cars' );
$categories->push( $cat );


//
// 2. Or, get all from PDO datebase:
//
$categories = new PdoCategories( $pdo );


//
// Check on ID and retrieve
//
$check = $categories->has( 42 );
$my_cat = $categories->get( 42 );

echo $my_cat->getSlug();
?>

Issues

Also see full issues list.

Development

$ git clone https://github.com/GermaniaKG/Categories.git
$ cd Categories
$ composer install

Unit tests

Either copy phpunit.xml.dist to phpunit.xml and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:

$ composer test
# or
$ vendor/bin/phpunit