PHPackages                             alex-foleon/service-library-catalog-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. alex-foleon/service-library-catalog-php

ActiveService[Utility &amp; Helpers](/categories/utility)

alex-foleon/service-library-catalog-php
=======================================

Library catalog

v0.1.0(5y ago)011MITPHPPHP ~7.4

Since Dec 24Pushed 5y ago1 watchersCompare

[ Source](https://github.com/alex-foleon/service-library-catalog-php)[ Packagist](https://packagist.org/packages/alex-foleon/service-library-catalog-php)[ Docs](https://github.com/alex-foleon/service-library-catalog-php)[ RSS](/packages/alex-foleon-service-library-catalog-php/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (11)Versions (5)Used By (0)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c1f173f7667714e15f0a11fc6d86b69425abae71b61d0d6fbb20e4d469cf1ff4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c65782d666f6c656f6e2f736572766963652d6c6962726172792d636174616c6f672d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alex-foleon/service-library-catalog-php)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/2bbea3b93199a0e1b0d2fa2273e9b5446c3db14cd1a5aa3c931ff8443b421462/68747470733a2f2f7472617669732d63692e636f6d2f616c65782d666f6c656f6e2f736572766963652d6c6962726172792d636174616c6f672d7068702e7376673f6272616e63683d6d61696e)](https://www.travis-ci.com/github/alex-foleon/service-library-catalog-php)[![Coverage Status](https://camo.githubusercontent.com/92b6cccfa010953a8ab6e30ec5a21e6d0250c806181f1bfed98058d32ecf6eb9/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f616c65782d666f6c656f6e2f736572766963652d6c6962726172792d636174616c6f672d7068702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/alex-foleon/service-library-catalog-php/code-structure)[![Quality Score](https://camo.githubusercontent.com/8a518e9090984f1262b5ddb05bf79b3cebc439d8f7b7e326e3cbd192462725a0/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f616c65782d666f6c656f6e2f736572766963652d6c6962726172792d636174616c6f672d7068702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/alex-foleon/service-library-catalog-php)

service-library-catalog-php
===========================

[](#service-library-catalog-php)

Assignment
----------

[](#assignment)

Build a tiny REST API and use this to build 2 resources. Books and Authors.

GET: /book/:id Expect a book with the author

GET: /author/:id Expect an author with all his books

POST: /author/ Create an author

POST: /book Create a book and add an author to it.

Ideas, developing
-----------------

[](#ideas-developing)

- **Repositories**: Implements storing in PDO (Mysql) and caching in Redis, configurable with envs (see: docker-compose.override.yml). Tests use Sqlite and redis-mock. The idea is App caches Book with/without its Author and Author with/without his/her books. When client adds new book, Author's cache invalidates.
- **Catalogue**: the Service that manages all these Repositories.
- [Authentication](#Authentication): App has Auth interface and implementation of supporting Bearer Auth. Other implementations can be added also.
- **Authorization**: Interface and simple implementation of ACL: guests can read, users can add Books (but not Authors), admin can add Books and Authors.
- [Api endpoints](#Endpoints): Specs for HTTP endpoints.
- **Transformers and Hydrators**: App has its own "Serializer" which helps encode/decode entities for storing in some repository (document-oriented). Basic transformers for representing data in HTTP-response.
- **Controllers**: V1 implements basic json REST, we can add more versions to support other protocols.

Used Libraries
--------------

[](#used-libraries)

- **php-di/php-di**: DI container implementation;
- **predis/predis**: Redis client;
- **rakit/validation**: Library for validation of incoming requests;
- **nikic/fast-route**: PHP routing (the foundation of thephpleague/route);
- **nyholm/psr7** and **laminas/laminas-httphandlerrunner**: PSR7 implementation (HTTP requests and responses);
- **laminas/laminas-permissions-acl**: Classical ZF ACL implementation.

Installation
------------

[](#installation)

To let dockerization's network work on the local machine plz add to your /etc/hosts:

```
    127.0.0.1 host.docker.internal
```

And then:

```
    ### Download
    composer create-project alex-foleon/service-library-catalog-php:^0.1 catalogue --prefer-dist --ignore-platform-reqs
    cd catalogue
    ### Prepare default dockerization
    cp docker-compose.override.yml.dist docker-compose.override.yml
    docker-compose up -d

    ### Create database
    docker exec -it rds-library bash -c "mysql -uroot -pmy-secret-pw -e \"create database catalogue CHARACTER SET utf8 COLLATE utf8_general_ci\""
    ### Start migrations
    docker exec -it service-catalogue-php bash -c "./scripts/migrate.sh"
    ### Check system works
    curl -i http://127.0.0.1:8080/api/v1/healthcheck
```

After that App should work via

Testing
-------

[](#testing)

```
    docker exec -it service-catalogue-php bash -c "composer test"
```

Test coverage is more than [90%](https://scrutinizer-ci.com/g/alex-foleon/service-library-catalog-php/code-structure). More tests should be implemented, but it takes time. Code quality is [~9.8](https://scrutinizer-ci.com/g/alex-foleon/service-library-catalog-php).

Authentication
--------------

[](#authentication)

App has simple Auth-service. Client should provide base64 encoded token to "Authorization" HTTP-header. Token should have the next json-structure:

```
{
  "secret": "some-secret",
  "payload": "roleId:clientId"
}
```

For example:

```
{"secret": "some-secret", "payload": "user:184"}
```

There are 3 roles in the App: **guest**, **user** and **admin**. No matter what ID is used as App doesn't has users repository.

You can use next encoded tokens which work for default env:

- Guest: eyJzZWNyZXQiOiJzdXBlcl9kdXBlcl9zZWN1cml0eSIsInBheWxvYWQiOiJndWVzdDozIn0=
- User: eyJzZWNyZXQiOiJzdXBlcl9kdXBlcl9zZWN1cml0eSIsInBheWxvYWQiOiJ1c2VyOjQifQ==
- Admin: eyJzZWNyZXQiOiJzdXBlcl9kdXBlcl9zZWN1cml0eSIsInBheWxvYWQiOiJhZG1pbjo1In0=
- Alien: eyJzZWNyZXQiOiJzdXBlcl9kdXBlcl9zZWN1cml0eSIsInBheWxvYWQiOiJhbGllbjo2In0= (should be denied)

Using admin example:

```
    curl -i -H "Authorization: Bearer eyJzZWNyZXQiOiJzdXBlcl9kdXBlcl9zZWN1cml0eSIsInBheWxvYWQiOiJhZG1pbjo1In0=" http://127.0.0.1:8080/api/v1/author/1
```

Endpoints
---------

[](#endpoints)

1. Create the Author.

**POST** /author

```
{
    "name": "Charles Dickens",
    "birthdate": "1812-02-07",
    "deathdate": "1870-06-09",
    "biography": "Born in Portsmouth, Dickens left school to work in a factory when his father was incarcerated in a debtors' prison. Despite his lack of formal education, he edited a weekly journal for 20 years, wrote 15 novels, five novellas, hundreds of short stories and non-fiction articles, lectured and performed readings extensively, was an indefatigable letter writer, and campaigned vigorously for children's rights, education, and other social reforms. ",
    "summary": "Charles John Huffam Dickens FRSA (/ˈdɪkɪnz/; 7 February 1812 – 9 June 1870) was an English writer and social critic. He created some of the world's best-known fictional characters and is regarded by many as the greatest novelist of the Victorian era.[1] His works enjoyed unprecedented popularity during his lifetime, and by the 20th century, critics and scholars had recognised him as a literary genius. His novels and short stories are still widely read today."
}
```

Response: \[200\]

```
{
    "id": "1",
    "name": "Charles Dickens",
    "birthdate": "1812-02-07",
    "deathdate": "1870-06-09",
    "biography": "Born in Portsmouth, Dickens left school to work in a factory when his father was incarcerated in a debtors' prison. Despite his lack of formal education, he edited a weekly journal for 20 years, wrote 15 novels, five novellas, hundreds of short stories and non-fiction articles, lectured and performed readings extensively, was an indefatigable letter writer, and campaigned vigorously for children's rights, education, and other social reforms. ",
    "summary": "Charles John Huffam Dickens FRSA (/ˈdɪkɪnz/; 7 February 1812 – 9 June 1870) was an English writer and social critic. He created some of the world's best-known fictional characters and is regarded by many as the greatest novelist of the Victorian era.[1] His works enjoyed unprecedented popularity during his lifetime, and by the 20th century, critics and scholars had recognised him as a literary genius. His novels and short stories are still widely read today."
}
```

2. Create the book.

**POST** /book

```
{
    "title": "Dombey and Son",
    "summary": "Dombey and Son is a novel by English author Charles Dickens. It follows the fortunes of a shipping firm owner, who is frustrated at the lack of a son to follow him in his footsteps; he initially rejects his daughter’s love before eventually becoming reconciled with her before his death. ",
    "authorId": 1
}
```

Response: \[200\]

```
{
    "id": "1",
    "title": "Dombey and Son",
    "summary": "Dombey and Son is a novel by English author Charles Dickens. It follows the fortunes of a shipping firm owner, who is frustrated at the lack of a son to follow him in his footsteps; he initially rejects his daughter’s love before eventually becoming reconciled with her before his death. "
}
```

3. Read the author.

**GET** /author/ID

Response: \[200\]

```
{
    "id": "1",
    "name": "Charles Dickens",
    "birthdate": "1812-02-07",
    "deathdate": "1870-06-09",
    "biography": "Born in Portsmouth, Dickens left school to work in a factory when his father was incarcerated in a debtors' prison. Despite his lack of formal education, he edited a weekly journal for 20 years, wrote 15 novels, five novellas, hundreds of short stories and non-fiction articles, lectured and performed readings extensively, was an indefatigable letter writer, and campaigned vigorously for children's rights, education, and other social reforms. ",
    "summary": "Charles John Huffam Dickens FRSA (/ˈdɪkɪnz/; 7 February 1812 – 9 June 1870) was an English writer and social critic. He created some of the world's best-known fictional characters and is regarded by many as the greatest novelist of the Victorian era.[1] His works enjoyed unprecedented popularity during his lifetime, and by the 20th century, critics and scholars had recognised him as a literary genius. His novels and short stories are still widely read today.",
    "books": [
        {
            "id": "1",
            "title": "Dombey and Son",
            "summary": "Dombey and Son is a novel by English author Charles Dickens. It follows the fortunes of a shipping firm owner, who is frustrated at the lack of a son to follow him in his footsteps; he initially rejects his daughter’s love before eventually becoming reconciled with her before his death. "
        }
    ]
}
```

4. Read the book.

**GET** /book/ID

Response: \[200\]

```
{
    "id": "1",
    "title": "Dombey and Son",
    "summary": "Dombey and Son is a novel by English author Charles Dickens. It follows the fortunes of a shipping firm owner, who is frustrated at the lack of a son to follow him in his footsteps; he initially rejects his daughter’s love before eventually becoming reconciled with her before his death. ",
    "author": {
        "id": "1",
        "name": "Charles Dickens",
        "birthdate": "1812-02-07",
        "deathdate": "1870-06-09",
        "biography": "Born in Portsmouth, Dickens left school to work in a factory when his father was incarcerated in a debtors' prison. Despite his lack of formal education, he edited a weekly journal for 20 years, wrote 15 novels, five novellas, hundreds of short stories and non-fiction articles, lectured and performed readings extensively, was an indefatigable letter writer, and campaigned vigorously for children's rights, education, and other social reforms. ",
        "summary": "Charles John Huffam Dickens FRSA (/ˈdɪkɪnz/; 7 February 1812 – 9 June 1870) was an English writer and social critic. He created some of the world's best-known fictional characters and is regarded by many as the greatest novelist of the Victorian era.[1] His works enjoyed unprecedented popularity during his lifetime, and by the 20th century, critics and scholars had recognised him as a literary genius. His novels and short stories are still widely read today."
    }
}
```

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 65% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2016d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/93508a19a49bee85a639d929afb125a6822a3d7be216379c67b2d9cf3f93e77e?d=identicon)[Mr. Anon](/maintainers/Mr.%20Anon)

---

Top Contributors

[![oitimon](https://avatars.githubusercontent.com/u/23586404?v=4)](https://github.com/oitimon "oitimon (13 commits)")[![alex-foleon](https://avatars.githubusercontent.com/u/76563221?v=4)](https://github.com/alex-foleon "alex-foleon (7 commits)")

---

Tags

alex-foleonservice-library-catalog-php

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/alex-foleon-service-library-catalog-php/health.svg)

```
[![Health](https://phpackages.com/badges/alex-foleon-service-library-catalog-php/health.svg)](https://phpackages.com/packages/alex-foleon-service-library-catalog-php)
```

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[flarum/core

Delightfully simple forum software.

201.4M2.3k](/packages/flarum-core)[filegator/filegator

Filegator

3.0k1.1k](/packages/filegator-filegator)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[infinum/eightshift-libs

WordPress libs developed by Eightshift team to use in modern WordPress.

63125.5k3](/packages/infinum-eightshift-libs)[drupal-code-builder/drupal-code-builder

Code generator for Drupal

27253.3k1](/packages/drupal-code-builder-drupal-code-builder)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
