tipo: modificación del cpanel y gitignore de la carpeta vendor
This commit is contained in:
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to `macroable` will be documented in this file
|
||||
|
||||
## 2.0.0 - 2021-03-26
|
||||
|
||||
- require PHP 8+
|
||||
- drop support for PHP 7.x
|
||||
- convert syntax to PHP 8
|
||||
|
||||
## 1.0.1 - 2020-11-03
|
||||
|
||||
- add support for PHP 8.0
|
||||
- drop support for PHP 7.1 and below
|
||||
|
||||
## 1.0.0 - 2017-09-16
|
||||
|
||||
- initial release
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
# Contributing
|
||||
|
||||
Contributions are **welcome** and will be fully **credited**.
|
||||
|
||||
Please read and understand the contribution guide before creating an issue or pull request.
|
||||
|
||||
## Etiquette
|
||||
|
||||
This project is open source, and as such, the maintainers give their free time to build and maintain the source code
|
||||
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
|
||||
extremely unfair for them to suffer abuse or anger for their hard work.
|
||||
|
||||
Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
|
||||
world that developers are civilized and selfless people.
|
||||
|
||||
It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
|
||||
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
|
||||
|
||||
## Viability
|
||||
|
||||
When requesting or submitting new features, first consider whether it might be useful to others. Open
|
||||
source projects are used by many developers, who may have entirely different needs to your own. Think about
|
||||
whether or not your feature is likely to be used by other users of the project.
|
||||
|
||||
## Procedure
|
||||
|
||||
Before filing an issue:
|
||||
|
||||
- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
|
||||
- Check to make sure your feature suggestion isn't already present within the project.
|
||||
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
|
||||
- Check the pull requests tab to ensure that the feature isn't already in progress.
|
||||
|
||||
Before submitting a pull request:
|
||||
|
||||
- Check the codebase to ensure that your feature doesn't already exist.
|
||||
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
|
||||
|
||||
## Requirements
|
||||
|
||||
If the project maintainer has any additional requirements, you will find them listed here.
|
||||
|
||||
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).
|
||||
|
||||
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
|
||||
|
||||
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
|
||||
|
||||
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
|
||||
|
||||
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
|
||||
|
||||
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
|
||||
|
||||
**Happy coding**!
|
||||
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Spatie bvba <info@spatie.be>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
Vendored
+135
@@ -0,0 +1,135 @@
|
||||
# A trait to dynamically add methods to a class
|
||||
|
||||
[](https://packagist.org/packages/spatie/macroable)
|
||||

|
||||
[](https://packagist.org/packages/spatie/macroable)
|
||||
|
||||
This package provides a trait that, when applied to a class, makes it possible to add methods to that class at runtime.
|
||||
|
||||
Here's a quick example:
|
||||
|
||||
```php
|
||||
$myClass = new class() {
|
||||
use Spatie\Macroable\Macroable;
|
||||
};
|
||||
|
||||
$myClass::macro('concatenate', function(... $strings) {
|
||||
return implode('-', $strings);
|
||||
});
|
||||
|
||||
$myClass->concatenate('one', 'two', 'three'); // returns 'one-two-three'
|
||||
```
|
||||
|
||||
The idea of a macroable trait and the implementation is taken from [the `macroable` trait](https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Traits/Macroable.php) of the [Laravel framework](https://laravel.com).
|
||||
|
||||
## Support us
|
||||
|
||||
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/macroable.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/macroable)
|
||||
|
||||
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
|
||||
|
||||
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
|
||||
|
||||
## Installation
|
||||
|
||||
You can install the package via composer:
|
||||
|
||||
```bash
|
||||
composer require spatie/macroable
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
You can add a new method to a class using `macro`:
|
||||
|
||||
```php
|
||||
$macroableClass = new class() {
|
||||
use Spatie\Macroable\Macroable;
|
||||
};
|
||||
|
||||
$macroableClass::macro('concatenate', function(... $strings) {
|
||||
return implode('-', $strings);
|
||||
};
|
||||
|
||||
$macroableClass->concatenate('one', 'two', 'three'); // returns 'one-two-three'
|
||||
```
|
||||
|
||||
Callables passed to the `macro` function will be bound to the `class`
|
||||
|
||||
```php
|
||||
$macroableClass = new class() {
|
||||
|
||||
protected $name = 'myName';
|
||||
|
||||
use Spatie\Macroable\Macroable;
|
||||
};
|
||||
|
||||
$macroableClass::macro('getName', function() {
|
||||
return $this->name;
|
||||
};
|
||||
|
||||
$macroableClass->getName(); // returns 'myName'
|
||||
```
|
||||
|
||||
You can also add multiple methods in one go by using a mixin class. A mixin class contains methods that return callables. Each method from the mixin will be registered on the macroable class.
|
||||
|
||||
```php
|
||||
$mixin = new class() {
|
||||
public function mixinMethod()
|
||||
{
|
||||
return function() {
|
||||
return 'mixinMethod';
|
||||
};
|
||||
}
|
||||
|
||||
public function anotherMixinMethod()
|
||||
{
|
||||
return function() {
|
||||
return 'anotherMixinMethod';
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
$macroableClass->mixin($mixin);
|
||||
|
||||
$macroableClass->mixinMethod() // returns 'mixinMethod';
|
||||
|
||||
$macroableClass->anotherMixinMethod() // returns 'anotherMixinMethod';
|
||||
```
|
||||
|
||||
## Changelog
|
||||
|
||||
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
|
||||
|
||||
## Testing
|
||||
|
||||
``` bash
|
||||
composer test
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
|
||||
|
||||
## Security
|
||||
|
||||
If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker.
|
||||
|
||||
## Postcardware
|
||||
|
||||
You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
|
||||
|
||||
Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.
|
||||
|
||||
We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).
|
||||
|
||||
## Credits
|
||||
|
||||
- [Freek Van der Herten](https://github.com/freekmurze)
|
||||
- [All Contributors](../../contributors)
|
||||
|
||||
Idea and code is taken from [the `macroable` trait](https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Traits/Macroable.php) of the [Laravel framework](https://laravel.com).
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "spatie/macroable",
|
||||
"description": "A trait to dynamically add methods to a class",
|
||||
"keywords": [
|
||||
"spatie",
|
||||
"macroable"
|
||||
],
|
||||
"homepage": "https://github.com/spatie/macroable",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Freek Van der Herten",
|
||||
"email": "freek@spatie.be",
|
||||
"homepage": "https://spatie.be",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^8.0|^9.3"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Spatie\\Macroable\\": "src"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Spatie\\Macroable\\Test\\": "tests"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "vendor/bin/phpunit"
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\Macroable;
|
||||
|
||||
use Closure;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use BadMethodCallException;
|
||||
|
||||
trait Macroable
|
||||
{
|
||||
protected static array $macros = [];
|
||||
|
||||
public static function macro(string $name, object | callable $macro): void
|
||||
{
|
||||
static::$macros[$name] = $macro;
|
||||
}
|
||||
|
||||
public static function mixin(object | string $mixin): void
|
||||
{
|
||||
$methods = (new ReflectionClass($mixin))->getMethods(
|
||||
ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED
|
||||
);
|
||||
|
||||
foreach ($methods as $method) {
|
||||
$method->setAccessible(true);
|
||||
|
||||
static::macro($method->name, $method->invoke($mixin));
|
||||
}
|
||||
}
|
||||
|
||||
public static function hasMacro(string $name): bool
|
||||
{
|
||||
return isset(static::$macros[$name]);
|
||||
}
|
||||
|
||||
public static function __callStatic($method, $parameters)
|
||||
{
|
||||
if (! static::hasMacro($method)) {
|
||||
throw new BadMethodCallException("Method {$method} does not exist.");
|
||||
}
|
||||
|
||||
$macro = static::$macros[$method];
|
||||
|
||||
if ($macro instanceof Closure) {
|
||||
return call_user_func_array(Closure::bind($macro, null, static::class), $parameters);
|
||||
}
|
||||
|
||||
return call_user_func_array($macro, $parameters);
|
||||
}
|
||||
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
if (! static::hasMacro($method)) {
|
||||
throw new BadMethodCallException("Method {$method} does not exist.");
|
||||
}
|
||||
|
||||
$macro = static::$macros[$method];
|
||||
|
||||
if ($macro instanceof Closure) {
|
||||
return call_user_func_array($macro->bindTo($this, static::class), $parameters);
|
||||
}
|
||||
|
||||
return call_user_func_array($macro, $parameters);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user