Simple and Lightweight PHP Class & Methods Annotations Reader

Overview

README

GitHub tag (latest SemVer) Github Actions Status Php Version

Simple and Lightweight PHP Class & Methods Annotations Reader

Forked from eriknyk/Annotations

项目地址

安装

  • composer 命令
composer require phppkg/annotations
  • composer.json
{
    "require": {
        "phppkg/annotations": "dev-master"
    }
}
  • 直接拉取
git clone https://github.com/phppkg/annotations.git // github

使用

Sample class User.php


    /**
     * @Defaults(name="user1", lastname = "sample", age='0', address={country=USA, state=NY}, phone="000-00000000")
     * @assertResult(false)
     * @cache(collation = UTF-8)
     */
    class User
    {
        /**
         * @cache(true)
         * @type(json)
         * @limits(start=10, limit=50)
         */
        function load(){
        }

        /**
         * create a record
         *
         * @Permission(view)
         * @Permission(edit)
         * @Role(administrator)
         */
        public function create()
        {
        }
    }

Sample use.

  • get class annotations:
include 'User.php';
$annotations = new PhpPkg\Annotations\Annotations();
$result = $annotations->getClassAnnotations('User');

print_r($result);

Result:

Array
(
    [Defaults] => Array
        (
            [0] => Array
                (
                    [name] => user1
                    [lastname] => sample
                    [age] => 0
                    [address] => Array
                        (
                            [country] => USA
                            [state] => NY
                        )

                    [phone] => 000-00000000
                )

        )

    [assertResult] => Array
        (
            [0] => false
        )

    [cache] => Array
        (
            [0] => Array
                (
                    [collation] => UTF-8
                )

        )

)
  • get method annotations:
$result = $annotations->getMethodAnnotations('User', 'create');
print_r($result);

Result:

    Array
    (
        [Permission] => Array
            (
                [0] => view
                [1] => edit
            )

        [Role] => Array
            (
                [0] => administrator
            )

    )

Creating Annotated objects.

You can crate fast annotated objects.

Sample Annotated Classes.


    // Annotation.php

    abstract class Annotation
    {
        protected $data = array();

        public function __construct($args = array())
        {
            $this->data = $args;
        }

        public function set($key, $value)
        {
            $this->data[$key] = $value;
        }

        public function get($key, $default = null)
        {
            if (empty($this->data[$key])) {
                return $default;
            }

            return $this->data[$key];
        }

        public function exists($key)
        {
            return isset($this->data[$key]);
        }
    }

    // PermissionAnnotation.php
    namespace Annotation;

    class PermissionAnnotation extends Annotation
    {
    }
require dirname(__DIR__) . '/tests/boot.php';

$annotations->setDefaultAnnotationNamespace('\Annotation\\');
$result = $annotations->getMethodAnnotationsObjects('User', 'create');
print_r($result);

Result:

Array
    (
        [Permission] => Base\Annotation\PermissionAnnotation Object
            (
                [data:protected] => Array
                    (
                        [0] => view
                        [1] => edit
                    )

            )

        [Role] => Base\Annotation\RoleAnnotation Object
            (
                [data:protected] => Array
                    (
                        [2] => administrator
                    )

            )

    )

unit test

phpunit

Related

LICENSE

MIT

You might also like...
Simple-cache - PHP FIG Simple Cache PSR

PHP FIG Simple Cache PSR This repository holds all interfaces related to PSR-16. Note that this is not a cache implementation of its own. It is merely

Created simple login system and chat type website using mysql database along with php and html , css and javascript.

Created simple login system and chat type website using mysql database along with php and html , css and javascript.

Bolt is a simple CMS written in PHP. It is based on Silex and Symfony components, uses Twig and either SQLite, MySQL or PostgreSQL.

⚠️ Note - Not the latest version This is the repository for Bolt 3. Please know that Bolt 5 has been released. If you are starting a new project, plea

Modern, simple and fresh looking glass based on Bootstrap 5 and PHP 7
Modern, simple and fresh looking glass based on Bootstrap 5 and PHP 7

Modern, simple and fresh looking glass based on Bootstrap 5 and PHP 7. A looking glass is a network utility which is made user-friendly for everyone to use. It allows you to execute network related commands within a remote network, usually that of an ISP.

TinyFileManager is web based file manager and it is a simple, fast and small file manager with a single file, multi-language ready web application
TinyFileManager is web based file manager and it is a simple, fast and small file manager with a single file, multi-language ready web application

TinyFileManager is web based file manager and it is a simple, fast and small file manager with a single file, multi-language ready web application for storing, uploading, editing and managing files and folders online via web browser. The Application runs on PHP 5.5+, It allows the creation of multiple users and each user can have its own directory and a build-in support for managing text files with cloud9 IDE and it supports syntax highlighting for over 150+ languages and over 35+ themes.

Project of Simple Blog using: HTML, CSS, PHP, MYSQL, and BOOTSTRAP
Project of Simple Blog using: HTML, CSS, PHP, MYSQL, and BOOTSTRAP

Project-Stormwind Project of Simple Blog using: HTML, CSS, PHP, MYSQL, and BOOTSTRAP Functions : A personal blog about Blizzard and their work Main Th

A simple and useful blog coded with laravel & php.
A simple and useful blog coded with laravel & php.

Blog with Setup Directions npm install composer install Set database infos in the .env php artisan migrate:fresh --seed php artisan serve npm run hot

MINI is an extremely simple and easy to understand skeleton PHP application
MINI is an extremely simple and easy to understand skeleton PHP application

MINI MINI is an extremely simple and easy to understand skeleton PHP application, reduced to the max. MINI is NOT a professional framework and it does

A simple web application that demonstrates how to quickly connect to and communicate with a MariaDB database using PHP
A simple web application that demonstrates how to quickly connect to and communicate with a MariaDB database using PHP

PHP Quickstart This repository contains a simple web application that demonstrates how to quickly connect to and communicate with a MariaDB database u

Releases(v1.0.0)
Owner
PHPPkg
Some useful package for PHP
PHPPkg
An RSS reader application built with Laravel

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Ryan Chandler 4 Mar 24, 2022
Simple and lightweight OOP wrapper for PHP's low-level sockets extension (ext-sockets)

clue/socket-raw Simple and lightweight OOP wrapper for PHP's low-level sockets extension (ext-sockets). PHP offers two networking APIs, the newer stre

Christian Lück 321 Dec 15, 2022
yxorP is a PHP-based proxy application that is very lightweight and easily customizable per user needs.

Web Proxy Guzzler + SAAS(y) Cockpit (GUI Dashboard incl.). Feature Rich, Multi-tenancy, Headless, Plug & Play, Augmentation & Content Spinning Web Proxy with Caching - PHP CURL+Composer are Optional. Leveraging SAAS architecture to provide multi-tenancy, multiple threads, caching, and an article spinner service.

4D/ҵ.com Dashboards 9 Aug 14, 2022
DooTask is a lightweight open source online project task management tool that provides various document collaboration tools, online mind mapping, online flowcharting, project management, task distribution, instant IM, file management and other tools.

DooTask is a lightweight open source online project task management tool that provides various document collaboration tools, online mind mapping, online flowcharting, project management, task distribution, instant IM, file management and other tools.

kuaifan 3k Jan 5, 2023
An ultra-lightweight blogging engine, written in PHP.

简体中文, Italiano. ?? Translations wanted! Go to the wiki to find out more about translating Chyrp Lite into your language. What can Chyrp Lite do for me

Daniel Pimley 202 Jan 2, 2023
Mira - A lightweight WebUI alternative to top/htop for GNU/Linux.

Mira Mira lets you monitor your server's resource usage through a responsive WebUI. ======== Introduction Screenshots Installation Limitations Known I

Jams246 9 Mar 27, 2022
a super lightweight markdown wiki/blog/tweeting system.

laMDWiki is a super light weight blog/wiki platform running on PHP!

null 4 Dec 24, 2021
Class used for health analysis results. It returns BMI, BMR, TDEE, Pollock 7 sinfolds stats (body fat, body density, lean mass, fat mass)

php-health Class used for health analysis results. It returns BMI, BMR, TDEE, Polock 7 sinfolds stats (body fat, body density, lean mass, fat mass) Th

Vinicius Marques de Souza 2 Oct 5, 2022
A simple wrapper for PHP Intervention Library to provide a more simple interface and convenient way to convert images to webp

This package is a simple wrapper for PHP Intervention Library to provide a more simple interface and convenient way to convert images to webp - next generation format - extension, and resize them to render only needed sizes.

eyad hamza 18 Jun 28, 2022
Simple-podcast-generator - 👉 A very simple way to host your podcast files and generate the RSS Podcast feed 🎙

Podcast RSS Feed Generator A very simple way to host your podcast files and generate the RSS Podcast feed ?? ?? Contents Summary Requirements Installa

♚ PH⑦ de Soria™♛ 11 Dec 2, 2022