This package was destilled from legacy code!
You better do not want it to use this in production.
$ composer require germania-kg/categories
MySQL: This package requires a MySQL tables categories which you can install using germania_categories.sql
in sql/
directory.
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();
?>
- Since PSR 11 is now standard, container-interop should be retired. Discuss at issue #1.
Also see full issues list.
$ git clone https://github.com/GermaniaKG/Categories.git
$ cd Categories
$ composer install
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