https://github.com/needle-project/common
Library with re-usable common functionalities
https://github.com/needle-project/common
array-helper array-in-depth-search camelcase-to-snakecase error-to-exception php
Last synced: about 1 year ago
JSON representation
Library with re-usable common functionalities
- Host: GitHub
- URL: https://github.com/needle-project/common
- Owner: needle-project
- License: mit
- Created: 2017-02-05T10:53:14.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-02-11T14:27:20.000Z (about 6 years ago)
- Last Synced: 2025-02-01T16:09:17.644Z (about 1 year ago)
- Topics: array-helper, array-in-depth-search, camelcase-to-snakecase, error-to-exception, php
- Language: PHP
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://www.codacy.com/app/needle-project/common?utm_source=github.com&utm_medium=referral&utm_content=needle-project/common&utm_campaign=Badge_Grade)
[](https://insight.sensiolabs.com/projects/dd95850e-8bed-4efe-a7fd-719f439cf570)
[](https://scrutinizer-ci.com/g/needle-project/common/?branch=master)
[](https://scrutinizer-ci.com/g/needle-project/common/?branch=master)
[](https://scrutinizer-ci.com/g/needle-project/common/build-status/master)
[](https://travis-ci.org/needle-project/common)
# README
## What is Common?
Common is a library packed with small re-usable utilities and helpers.
## Requirments
For larger usage, minimum version is PHP 5.5
## Instalation
```
composer require "needle-project/common"
```
## Content
1. WordType convertor - Converts string to `camelCase`, `PascalCase` or `snake_case`
2. ArrayHelper - searches if an array has a key in depth and retrieves the value
3. Error to Exception - convert php errors to Exceptions
4. ClassFinder - Searches for classes of a certain type.
### 1. WordType convertor
Converts a set of strings of typographical conventions between them.
It handles `camelCase`, `PascalCase` and `snake_case`.
**Usage**
```
[
'level2' => [
'level3' => 'A value'
]
]
];
$helper = new ArrayHelper();
if ($helper->hasKeysInDepth($searchIn, $searchFor)) {
echo $helper->getValueFromDepth($searchIn, $searchFor);
// A value
}
```
### 3. Error to Exception
Converts a PHP error to an Exception.
Error level constans are the PHP's default ones that can be found [here](http://php.net/manual/ro/function.error-reporting.php "here").
```
convertErrorsToExceptions(E_ALL, CustomException::class);
try {
print(a);
} catch (\Exception $e) {
echo get_class($e) . "\n";
echo $e->getMessage();
}
// restore the previous state of error handling
$convertor->restoreErrorHandler();
```
### 4. ClassFinder
Searches for a class of a certain sub-type.
```
findClasses();
print_r($foundClasses);
php test.php
// Array
// (
// [0] => Fixture\Path\ClassList\BazClass
// [1] => Fixture\Path\ClassList\GodClass
// [2] => Fixture\Path\FooClass
// )
```
## Contribute
Feel free to contribute:
- State ideeas
- Open pull request with improvements/bug-fixes