All Projects → rexlabsio → enum-php

rexlabsio / enum-php

Licence: MIT license
Enumeration implementation for PHP

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to enum-php

Rescope
Rescope is a tool geared towards pentesters and bugbounty researchers, that aims to make life easier when defining scopes for Burp Suite and OWASP ZAP.
Stars: ✭ 156 (+246.67%)
Mutual labels:  enumeration
Phpenums
🔩 Provides enumerations for PHP & frameworks integrations
Stars: ✭ 194 (+331.11%)
Mutual labels:  enumeration
Adcollector
A lightweight tool to quickly extract valuable information from the Active Directory environment for both attacking and defending.
Stars: ✭ 238 (+428.89%)
Mutual labels:  enumeration
Dirsearch
A Go implementation of dirsearch.
Stars: ✭ 164 (+264.44%)
Mutual labels:  enumeration
Intrec Pack
Intelligence and Reconnaissance Package/Bundle installer.
Stars: ✭ 177 (+293.33%)
Mutual labels:  enumeration
Bscan
an asynchronous target enumeration tool
Stars: ✭ 207 (+360%)
Mutual labels:  enumeration
Jalesc
Just Another Linux Enumeration Script: A Bash script for locally enumerating a compromised Linux box
Stars: ✭ 152 (+237.78%)
Mutual labels:  enumeration
ActiveDirectoryEnumeration
Enumerate AD through LDAP with a collection of helpfull scripts being bundled
Stars: ✭ 127 (+182.22%)
Mutual labels:  enumeration
Crithit
Takes a single wordlist item and tests it one by one over a large collection of websites before moving onto the next. Create signatures to cross-check vulnerabilities over multiple hosts.
Stars: ✭ 182 (+304.44%)
Mutual labels:  enumeration
Crosslinked
LinkedIn enumeration tool to extract valid employee names from an organization through search engine scraping
Stars: ✭ 223 (+395.56%)
Mutual labels:  enumeration
Pspy
Monitor linux processes without root permissions
Stars: ✭ 2,470 (+5388.89%)
Mutual labels:  enumeration
Raccoon
A high performance offensive security tool for reconnaissance and vulnerability scanning
Stars: ✭ 2,312 (+5037.78%)
Mutual labels:  enumeration
Dirstalk
Modern alternative to dirbuster/dirb
Stars: ✭ 210 (+366.67%)
Mutual labels:  enumeration
Asnlookup
Leverage ASN to look up IP addresses (IPv4 & IPv6) owned by a specific organization for reconnaissance purposes, then run port scanning on it.
Stars: ✭ 163 (+262.22%)
Mutual labels:  enumeration
Ntlmrecon
Enumerate information from NTLM authentication enabled web endpoints 🔎
Stars: ✭ 252 (+460%)
Mutual labels:  enumeration
Powershell Red Team
Collection of PowerShell functions a Red Teamer may use to collect data from a machine
Stars: ✭ 155 (+244.44%)
Mutual labels:  enumeration
Fdsploit
File Inclusion & Directory Traversal fuzzing, enumeration & exploitation tool.
Stars: ✭ 199 (+342.22%)
Mutual labels:  enumeration
wordlists
Aggregated wordlist pulled from commonly used tools for discovery, enumeration, fuzzing, and exploitation.
Stars: ✭ 94 (+108.89%)
Mutual labels:  enumeration
reosploit
A Tool that Finds, Enumerates, and Exploits Reolink Cameras.
Stars: ✭ 89 (+97.78%)
Mutual labels:  enumeration
Activereign
A Network Enumeration and Attack Toolset for Windows Active Directory Environments.
Stars: ✭ 210 (+366.67%)
Mutual labels:  enumeration

Warning If you are using PHP 8.1 or higher, we recommend you use native php enums in place of this package.

We may release some maintenance patches but support for this package is otherwise being discontinued.

Feel free to fork our code and adapt it to your needs.

Enum PHP Library

License: MIT Build Status Code Coverage Packagist

Overview

This library provides an Enum / Enumeration implementation for PHP.

Why use this library

  • Very simple to implement and use.
  • Complex can optionally be mapped by providing a map() method.
  • Allows type-hinting when passing enumerated values between methods and classes.

Usage

First create a new class that extends \Rexlabs\Enum\Enum and do the following;

  1. Declare your constants
  2. Optional: provide a map() method:

Example

<?php

namespace Rexlabs\Enum\Readme;

use Rexlabs\Enum\Enum;

/**
 * Class City
 *
 * @package Rexlabs\Enum\Readme
 *
 * @method static static BRISBANE()
 * @method static static MELBOURNE()
 * @method static static SYDNEY()
 */
class City extends Enum
{
    const BRISBANE = 'Brisbane';
    const MELBOURNE = 'Melbourne';
    const SYDNEY = 'Sydney';
    
    // OPTIONAL - Provide a map() method if you would like to
    // map additional data, which will be available from the ->value() method
    public static function map(): array 
    {
        return [
            self::BRISBANE => ["state"=>"QLD", "population"=>""],
            self::MELBOURNE => ["state"=>"VIC", "population"=>"5m"],
            self::SYDNEY => ["state"=>"NSW", "population"=>"5m"],
        ];
    }
    
}

// Static access
echo City::BRISBANE;                 // "Brisbane"
echo City::MELBOURNE;                // "Melbourne"
City::names();                       // (array)["BRISBANE", "BRISBANE", "SYDNEY"]
City::keys();                        // (array)["Brisbane", "Melbourne", "Sydney"]
City::keyForName('BRISBANE');        // "Brisbane"
City::nameForKey('Melbourne');       // "MELBOURNE"
City::isValidKey('Sydney');          // (boolean)true
City::isValidKey('Paris');           // (boolean)false
               
// Getting an instance - all return a City instance.
$city = City::BRISBANE();                   
$city = City::instanceFromName('BRISBANE'); 
$city = City::instanceFromKey('Brisbane');

// Working with an instance
$city->name();                       // "BRISBANE"
$city->key();                        // "Brisbane"
$city->value()['population'];        // null - no value mapped
$city->is(City::BRISBANE);           // (boolean)true
$city->is(City::BRISBANE());         // (boolean)true
$city->is(City::SYDNEY());           // (boolean)false
$city->isNot(City::SYDNEY());        // (boolean)true
$city->isAnyOf([City::BRISBANE()]);  // (boolean)true
$city->isNoneOf([City::BRISBANE()]); // (boolean)false

// Or ...
City::SYDNEY()->key();               // "Sydney"
City::SYDNEY()->value();             // (array)["state"=>"NSW", "population"=>"5m"] 

Dependencies

  • PHP 7.0 or above.

Installation

To install in your project:

composer require rexlabs/enum

Type-hinting

Now you can type-hint your Enum object as a dependency:

<?php
function announceCity(City $city) {
    echo "{$city->key()} is located in {$city->value()["state"]}, population: {$city->value()["population"]}\n";
}

// Get a new instance
announceCity(City::SYDNEY());      // "Sydney is located in NSW, population: 5m"

Instance Methods

Each instance of Enum provides the following methods:

name()

Returns the constant name.

$enum->name();

key()

Returns the value/key assigned to the constant in the const MY_CONST = 'key' declaration.

$enum->key();

value()

Returns the value (if-any) that is mapped (in the array returned by map()). If no value is mapped, then this method returns null.

$enum->value();

is(Enum|string $compare)

Returns true if this instance is the same as the given constant key or enumeration instance.

$enum->is(City::SYDNEY);       // Compare to constant key
$enum->is(City::SYDNEY());     // Compare to instance

__toString()

The __toString() method is defined to return the constant name.

(string)City::SYDNEY();      // "SYDNEY"

Static Methods

map()

Returns an array which maps the constant keys to a value. This method can be optionally implemented in a sub-class. The default implementation returns an array of keys mapped to null.

instances()

Returns an array of Enum instances.

keys()

Returns an array of constant keys.

values()

Returns an array of values defined in map(). If map() is not implemented then an array of null values will be returned.

names()

Returns an array of all the constant names declared with the class.

namesAndKeys()

Returns an associative array of CONSTANT_NAME => key, for all the constant names declared within the class.

keyForName(string $name)

Returns the key for the given constant name.

nameForKey(string $key)

Returns the constant name for the given key (the inverse of keyForName).

valueForKey(string $key)

Returns the value (or null if not mapped) for the given key (as declared in the map() method).

keyForValue(mixed $value)

Returns the key for the given value (as declared in the map() method).

Note: If duplicate values are contained within the map() method then only the first key will be returned.

instanceFromName($name)

Create instance of this Enum from the given constant name.

instanceFromKey($key)

Create instance of this Enum from the given key.

isValidKey(string $key)

Returns true if the given key exists.

isValidName(string $name)

Returns true if the given constant name (case-sensitive) has been declared in the class.

requireValidKey(string $key)

Throws a \Rexlabs\Enum\Exceptions\InvalidKeyException if the given key does NOT exist.

Tests

To run tests:

composer tests

To run coverage report:

composer coverage

Coverage report is output to ./tests/report/index.html

Contributing

Contributions are welcome, please submit a pull-request or create an issue. Your submitted code should be formatted using PSR-1/PSR-2 standards.

About

  • Author: Jodie Dunlop
  • License: MIT
  • Copyright (c) 2018 Rex Software Pty Ltd
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].