Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Commit

Permalink
Added/Updated READMEs and LICENSEs for all modules
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoboss committed Apr 26, 2022
1 parent 238b420 commit 14ed6c4
Show file tree
Hide file tree
Showing 31 changed files with 634 additions and 11 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright 2022 Ricardo Boss
Copyright 2021-2022 Ricardo Boss

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
Expand Down
16 changes: 16 additions & 0 deletions modules/Autoloading/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
The MIT License (MIT)

Copyright 2021-2022 Ricardo Boss

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.
5 changes: 5 additions & 0 deletions modules/Autoloading/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Elephox Autoloading Module

This module is used by [Elephox] to iterate over classes in a specific namespace controlled by composer.

[Elephox]: https://github.com/elephox-dev/framework
16 changes: 16 additions & 0 deletions modules/Cache/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
The MIT License (MIT)

Copyright 2021-2022 Ricardo Boss

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.
7 changes: 7 additions & 0 deletions modules/Cache/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Elephox Cache Module

This module is used by [Elephox] to provide several caching mechanisms and interfaces to provide your own.
They comply with [PSR-6].

[Elephox]: https://github.com/elephox-dev/framework
[PSR-6]: https://www.php-fig.org/psr/psr-6/
16 changes: 16 additions & 0 deletions modules/Collection/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
The MIT License (MIT)

Copyright 2021-2022 Ricardo Boss

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.
35 changes: 26 additions & 9 deletions modules/Collection/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
PIE - PHP Iterables Enhanced
===
# Elephox Collection Module

This library (or rather module) was inspired by [C#s LINQ library](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/).

However, it is not a full-featured LINQ library. It is only a small subset of the functionality since PHP cannot fully support all the syntactic sugar.
For example the main feature of LINQ, SQL-like syntax directly in source, is not supported since it would require you to compile/transpile your code.
However, it is not a full-featured LINQ library. It is only a small subset of the functionality since user-land PHP code cannot fully support all the syntactic sugar.
For example, the main feature of LINQ, SQL-like syntax directly in source, is not supported since it would require you to compile/transpile your code, which is not in the scope of this library.

The main idea however is to provide a way to iterate over a collection of objects in a more natural way like you can do with `IEnumerable`s in C#.
The main idea, however, is to provide a way to iterate over a collection of objects in a more natural/handy way like you can do with `IEnumerable`s in C#.

## Examples

Expand All @@ -16,22 +15,40 @@ declare(strict_types=1);

use Elephox\Collection\Enumerable;

$array = [5, 2, 1, 4, 3];
$pie = Enumerable::from($array);
$data = [5, 2, 1, 4, 3];
$arr = Enumerable::from($data);

$pie->orderBy(fn (int $item) => $item)
$arr->orderBy(fn (int $item) => $item)
->select(function (int $item) {
echo $item;
});

// output: 12345


$pie->where(fn (int $item) => $item % 2 === 0)
$arr->where(fn (int $item) => $item % 2 === 0)
->select(function (int $item) {
echo $item;
});

// output: 24

echo $arr->aggregate(fn (int $acc, int $item) => $acc + $item, 0);

// output: 15
```

## Differences to C# `IEnumerable`

- PHP doesn't support generics. For now, only static analyzers like [Psalm](https://psalm.dev) can provide full type safety when working with generic collections.
- No extension methods from the `System.Data` namespace are implemented (`CopyToDataTable`)
- `Cast` wouldn't make sense in a dynamically typed language, so it is not implemented either. You can use `Enumerable::select` to change the type of the values.
- `GroupJoin` is not implemented (yet?)
- Methods ending with `OrDefault` always has `null` as the default value. You can, of course, pass your own default value.
- PHP has no default comparer for types, so we provide a `DefaultEqualityComparer` class that implements some methods to compare two values. Depending on if an order is required, `DefaultEqualityComparer::same` or `DefaultEqualityComparer::compare` is used if you don't provide a comparer function yourself.
- `LongCount` is not implemented since PHP only has one integer type
- `OfType` is not implemented since PHP doesn't have generics
- `ToHashSet`, `ToDictionary` and `ToLookup` are not implemented. Instead, you can convert an `Enumerable` to native types via `toList` and `toArray` (whereas `toArray` keeps the keys or allows you to pass a key selector function)
- `AsParallel` and `AsQueryable` are not implemented
- None of the `System.Xml` extension methods are implemented (`Ancestors`, `Descendants`, `Elements`, etc.)
- No read only or immutable interfaces or methods to get them exist (yet?)
16 changes: 16 additions & 0 deletions modules/Configuration/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
The MIT License (MIT)

Copyright 2021-2022 Ricardo Boss

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.
47 changes: 47 additions & 0 deletions modules/Configuration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Elephox Configuration Module

This module is used by [Elephox] to load configuration files and provide easy access to their values.
It was inspired by [.NETs Configuration package].

## Example

```php
<?php

use Elephox\Configuration\ConfigurationManager;
use Elephox\Configuration\Json\JsonFileConfigurationSource;

$configurationManager = new ConfigurationManager();
$configurationManager->add(new JsonFileConfigurationSource('config.json'));
$configurationManager->add(new JsonFileConfigurationSource('config.local.json', optional: true));
$configurationRoot = $configurationManager->build();

echo $configurationRoot['database:host']; // 'localhost'
echo $configurationRoot['database:port']; // 3306
echo $configurationRoot['env']; // 'local'
```

`config.json`
```json
{
"env": "production",
"database": {
"host": "production-server",
"port": 3306
}
}
```

`config.local.json`

```json
{
"env": "local",
"database": {
"host": "localhost"
}
}
```

[Elephox]: https://github.com/elephox-dev/framework
[.NETs Configuration package]: https://docs.microsoft.com/en-us/dotnet/core/extensions/configuration
16 changes: 16 additions & 0 deletions modules/Console/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
The MIT License (MIT)

Copyright 2021-2022 Ricardo Boss

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.
8 changes: 8 additions & 0 deletions modules/Console/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Elephox Console Module

This module is used by [Elephox] to provide a console application and ability to create and run commands.

For an example usage, check out the [`phox` binary] in the root of the project.

[Elephox]: https://github.com/elephox-dev/framework
[`phox` binary]: https://github.com/elephox-dev/framework/blob/develop/phox
16 changes: 16 additions & 0 deletions modules/DI/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
The MIT License (MIT)

Copyright 2021-2022 Ricardo Boss

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.
25 changes: 25 additions & 0 deletions modules/DI/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Elephox DI Module

This module is used by [Elephox] to provide a dependency injection container.
It also has mechanisms to resolve arguments for functions and callbacks.

## Example

```php
<?php

use Elephox\DI\ServiceCollection;

$container = new ServiceCollection();
$container->addSingleton(stdClass::class, stdClass::class, fn () => new stdClass());

$foo = function (stdClass $object) {
return $object;
}

$instance = $container->resolver()->callback($foo);
// $instance is an instance of stdClass
// multiple calls to $container->resolver()->callback($foo) will return the same instance, since it was added as a singleton
```

[Elephox]: https://github.com/elephox-dev/framework
16 changes: 16 additions & 0 deletions modules/Events/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
The MIT License (MIT)

Copyright 2021-2022 Ricardo Boss

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.
24 changes: 24 additions & 0 deletions modules/Events/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Elephox Events Module

This module is used by [Elephox] to provide an event bus with broadcasters and listeners.

## Example

```php
<?php

use Elephox\Events\EventBus;

$bus = new EventBus();
$subscription = $bus->subscribe('test', function ($data) {
echo 'test event: ' . $data;
});

$bus->publish('test', 'test data'); // "test event: test data"

$bus->unsubscribe($subscription);

$bus->publish('test', 'test data'); // no output
```

[Elephox]: https://github.com/elephox-dev/framework
16 changes: 16 additions & 0 deletions modules/Files/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
The MIT License (MIT)

Copyright 2021-2022 Ricardo Boss

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.
49 changes: 49 additions & 0 deletions modules/Files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Elephox Files Module

This module is used by [Elephox] to provide an abstraction layer for directories and files.
It also includes some helpers for file operations and working with paths.

## Examples

```php
<?php

use Elephox\Files\File;
use Elephox\Files\Directory;
use Elephox\Files\Path;

$file = new File('/var/tmp/file.txt');

$file->exists(); // false
$file->putContents('Hello world!');
$file->exists(); // true
$file->getContents(); // 'Hello world!'
$file->getExtension(); // 'txt'

$newParent = new Directory('/home/user/');

$newFile = $file->moveTo($newParent);

$file->exists(); // false
$newFile->exists(); // true

$newParent->getFiles()->select(fn (File $f) => $f->getPath())->toArray(); // ['/home/user/file.txt']
$newParent->getPathRelative($file->getParent()); // '../../var/tmp'

Path::join("/home/user/", "file.txt"); // '/home/user/file.txt'
Path::join("/home/user/", "../../var/tmp/file.txt"); // '/home/user/../../var/tmp/file.txt'

Path::canonicalize("/home/user\\\\../test\\dir/another//folder"); // '/home/user/../test/dir/another/folder'

Path::isRoot("/"); // true
Path::isRoot("/home/user"); // false
Path::isRoot("C:\\") // true
Path::isRoot("C:\\Windows\\System32"); // false

Path::isRooted("/home/user"); // true
Path::isRooted("home/user"); // false
Path::isRooted("C:\\Windows\\System32"); // true
Path::isRooted("..\\Users\\user\\"); // false
```

[Elephox]: https://github.com/elephox-dev/framework
16 changes: 16 additions & 0 deletions modules/Http/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
The MIT License (MIT)

Copyright 2021-2022 Ricardo Boss

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.
Loading

0 comments on commit 14ed6c4

Please sign in to comment.