Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikeschinkel/userland-packages
Userland Packages — Single directory "Packages" in PHP with File-Only and Package-Only scope AND a Proof-of-Concept for a potential PHP RFC
https://github.com/mikeschinkel/userland-packages
packages php php-framework php-libraries php-library php-package-manager php-packages php-rfc php-sdk php-sdks
Last synced: 3 months ago
JSON representation
Userland Packages — Single directory "Packages" in PHP with File-Only and Package-Only scope AND a Proof-of-Concept for a potential PHP RFC
- Host: GitHub
- URL: https://github.com/mikeschinkel/userland-packages
- Owner: mikeschinkel
- License: mit
- Created: 2024-07-13T12:41:22.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-07-17T17:24:02.000Z (6 months ago)
- Last Synced: 2024-10-09T05:43:42.720Z (3 months ago)
- Topics: packages, php, php-framework, php-libraries, php-library, php-package-manager, php-packages, php-rfc, php-sdk, php-sdks
- Language: PHP
- Homepage:
- Size: 134 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Userland Packages for PHP
**NOTE: This is still in alpha/development, so is not yet production ready**.
_Userland Packages for PHP_ provide PHP developers with **working** code to group a collection of `.php` files located in a single-directory into a **_new_** concept of _"Package,"_ with full control of _**file- and package-level visibility**_ and no _build-time requirements_.
## How to Use
Assuming you have used Composer to install `UserlandPackages`, here is the simplest example I can envision:### `./main.php`
```php
greeting();// Then load French and call its salutation
$french = new French();
$french->salutation();
```
Run the above and you'll see the result being:```
World World
Bonjour le Monde
```### `./english-pkg/English.php` && `./french-pkg/French.php`
Now compare the primary class file of each _package_ and notice they have almost idenitical code besides the one exported class for each:- `English` vs.
- `French`.#### `./english-pkg/English.php`
```php
b = new A();
$this->c = new B();
}
public function greeting():void {
$this->b->greeting();
echo ' ';
$this->c->greeting();
echo "\n";
}
}
```
#### `./french-pkg/French.php`
```php
b = new A();
$this->c = new B();
}
public function salutation():void {
$this->b->salutation();
echo ' ';
$this->c->salutation();
echo "\n";
}
}
```
_Above there is also the **arbitrary** change we made to method names `greeting()` vs. `salutation()`. We did that do follow the spoken-language theme but not because we needed too. `greeting()` would have worked fine for both of them.__In fact, we could have implemented a `Greatable` interface requiring a `greeting()` method had we wanted to._
### `./english-pkg/{A,B}.php`
Now let's look at the `A.php` and `B.php` file in the `english-pkg` package. Note how both define their own same-named and _non-conflicting_ class `C`.Note the only difference between the two (2) files is what each file's `FileOnly\C->greeting()` outputs:
#### `./english-pkg/A.php`
```php
c = new C();
}
public function greeting() {
$this->c->greeting();
}
}
namespace FileOnly;
class C {
public function greeting() {
echo "Hello";
}
}
```#### `./english-pkg/B.php`
```php
c = new C();
}
public function greeting() {
$this->c->greeting();
}
}namespace FileOnly;
class C {
public function greeting() {
echo "World";
}
}
```### `./french-pkg/{A,B}.php`
Finally, we wrote the package `french-pkg` to be much simplier, just since we'd already shown all the necessary concepts.
The one remaining concept is for you to verify that we have indeed implemented using same-named classes `PackageOnly\A` and `PackageOnly\B` when compared to `english-pkg`:
### `./french-pkg/A.php`
```php