Skip to content

Commit

Permalink
Merge pull request #3 from krissss/2-call-to-undefined-method-illumin…
Browse files Browse the repository at this point in the history
…atecontainercontainerrunningunittests
  • Loading branch information
krissss authored Sep 4, 2023
2 parents d7963ba + d9e86a7 commit e57647d
Show file tree
Hide file tree
Showing 2 changed files with 235 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Command/IdeHelperModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Composer\ClassMapGenerator\ClassMapGenerator;
use Illuminate\Console\Concerns\ConfiguresPrompts;
use Illuminate\Config\Repository;
use Illuminate\Container\Container;
use Illuminate\Filesystem\Filesystem;
use Kriss\WebmanEloquentIdeHelper\Wrapper\LaravelContainerWrapper;

function base_path($path = '')
{
Expand All @@ -23,9 +25,14 @@ public function __construct()
{
parent::__construct(new Filesystem());

$container = new Container();
$container->instance('config', $this->loadConfig());
$this->setLaravel($container);
$laravel = new Container();
if (trait_exists(ConfiguresPrompts::class)) {
// 为了解决 ConfiguresPrompts 中通过 $this->laravel->runningUnitTests() 的问题
// https://github.com/krissss/webman-eloquent-ide-helper/issues/2
$laravel = new LaravelContainerWrapper($laravel);
}
$laravel->instance('config', $this->loadConfig());
$this->setLaravel($laravel);
}

private function loadConfig()
Expand Down
225 changes: 225 additions & 0 deletions src/Wrapper/LaravelContainerWrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
<?php

namespace Kriss\WebmanEloquentIdeHelper\Wrapper;

use Closure;
use Illuminate\Container\Container;

final class LaravelContainerWrapper implements \Illuminate\Contracts\Container\Container
{
private Container $container;

public function __construct(Container $container)
{
$this->container = $container;
}

public function __call($name, $arguments)
{
if ($name === 'runningUnitTests') {
return false;
}

return $this->container->{$name}(...$arguments);
}

/**
* @inheritDoc
*/
public function bound($abstract)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function alias($abstract, $alias)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function tag($abstracts, $tags)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function tagged($tag)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function bind($abstract, $concrete = null, $shared = false)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function bindMethod($method, $callback)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function bindIf($abstract, $concrete = null, $shared = false)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function singleton($abstract, $concrete = null)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function singletonIf($abstract, $concrete = null)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function scoped($abstract, $concrete = null)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function scopedIf($abstract, $concrete = null)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function extend($abstract, Closure $closure)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function instance($abstract, $instance)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function addContextualBinding($concrete, $abstract, $implementation)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function when($concrete)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function factory($abstract)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function flush()
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function make($abstract, array $parameters = [])
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function call($callback, array $parameters = [], $defaultMethod = null)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function resolved($abstract)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function beforeResolving($abstract, Closure $callback = null)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function resolving($abstract, Closure $callback = null)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function afterResolving($abstract, Closure $callback = null)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function get(string $id)
{
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function has(string $id): bool
{
return $this->__call(__FUNCTION__, func_get_args());
}
}

0 comments on commit e57647d

Please sign in to comment.