Skip to content

Commit

Permalink
change: allow set Application without initial construct
Browse files Browse the repository at this point in the history
* FIx typo method
  • Loading branch information
SonyPradana committed Jun 28, 2024
1 parent 02e78a7 commit 274a1f5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
14 changes: 7 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Php mvc with minum mvc framework. is simple and easy to use
> **Note:** This repository high inspire with `laravel\framework` and `symfony\symfony`.
## Feature
- MVC base
- MVC base
- Container (dependency injection)
- Route
- Model (database class relation)
Expand All @@ -24,15 +24,15 @@ Php mvc with minum mvc framework. is simple and easy to use
## **Built in Query Builder**
of cource we are support CRUD data base, this a sample

### Select data
### Select data
```php
DB::table('table_name')
->select(['column_1'])
->equal('column_2', 'fast_mvc')
->order("column_1", MyQuery::ORDER_ASC)
->limit(1, 10)
->all()
;
;
```
the result will show data from query,
its same with SQL query
Expand All @@ -41,7 +41,7 @@ SELECT `column_1` FROM `table_name` WHERE (`column_2` = 'fast_mvc') ORDER BY `ta
```
[🔝 Back to contents](#Feature)

### Update data
### Update data
```php
DB::table('table_name')
->update()
Expand Down Expand Up @@ -83,7 +83,7 @@ DB::table('table_name')
```
its supported cancel transation if you needed
```php
use System\Support\Facedes;
use System\Support\Facades;

PDO::transaction(function() {
DB::table('table_name')
Expand Down Expand Up @@ -114,7 +114,7 @@ create database table

[🔝 Back to contents](#Feature)

## Collection
## Collection
Array collection, handel functional array as chain method

### Create New Collection
Expand Down Expand Up @@ -189,7 +189,7 @@ class GreatConsole extends Console
```php
#!usr/bin/env php

// $argv come with default global php
// $argv come with default global php
return (new greatConsole($argv))->main();

```
Expand Down
20 changes: 14 additions & 6 deletions src/System/Support/Facades/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public function __construct(Application $app)
static::$app = $app;
}

/**
* Set facade intance.
*/
public static function setFacadeBase(Application $app): void
{
static::$app = $app;
}

/**
* Get accessor from application.
*
Expand All @@ -45,23 +53,23 @@ protected static function getAccessor()
}

/**
* Faced.
* Facade.
*
* @return mixed
*/
protected static function getFacede()
protected static function getFacade()
{
return static::getFacedeBase(static::getAccessor());
return static::getFacadeBase(static::getAccessor());
}

/**
* Faced.
* Facade.
*
* @param string|class-string $name Entry name or a class name
*
* @return mixed
*/
protected static function getFacedeBase(string $name)
protected static function getFacadeBase(string $name)
{
if (isset(static::$instance[$name])) {
return static::$instance[$name];
Expand All @@ -82,7 +90,7 @@ protected static function getFacedeBase(string $name)
*/
public static function __callStatic($name, $arguments)
{
$instance = static::getFacede();
$instance = static::getFacade();

if (!$instance) {
throw new \RuntimeException('A facade root has not been set.');
Expand Down
11 changes: 5 additions & 6 deletions tests/Support/Facades/FacadeTest.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
<?php

use PHPUnit\Framework\TestCase;
use System\Collection\Collection;
use System\Integrate\Application;
use System\Support\Facades\Facade;

final class FacadeTest extends TestCase
{
/** @test */
final public function itCanCallstatic()
{
$app = new Application(__DIR__);
$app->set(System\Time\Now::class, fn () => new System\Time\Now());
$app->set(Collection::class, fn () => new Collection(['php' => 'greate']));

require_once __DIR__ . DIRECTORY_SEPARATOR . 'Sample' . DIRECTORY_SEPARATOR . 'FacadesTestClass.php';
new FacadesTestClass($app);
Facade::setFacadeBase($app);

FacadesTestClass::year(2025);
$year = FacadesTestClass::isNextYear();

$this->assertTrue($year);
$this->assertTrue(FacadesTestClass::has('php'));
}
}
6 changes: 3 additions & 3 deletions tests/Support/Facades/Sample/FacadesTestClass.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php

use System\Collection\Collection;
use System\Support\Facades\Facade;

/**
* @method static \System\Time\Now year(int $year)
* @method static bool isNextYear()
* @method static bool has(string $key)
*/
final class FacadesTestClass extends Facade
{
protected static function getAccessor()
{
return System\Time\Now::class;
return Collection::class;
}
}

0 comments on commit 274a1f5

Please sign in to comment.