当前位置: 首页>>代码示例>>PHP>>正文


PHP IoC::make方法代码示例

本文整理汇总了PHP中IoC::make方法的典型用法代码示例。如果您正苦于以下问题:PHP IoC::make方法的具体用法?PHP IoC::make怎么用?PHP IoC::make使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IoC的用法示例。


在下文中一共展示了IoC::make方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_can_resolve_out_of_the_ioc_container

 public function test_can_resolve_out_of_the_ioc_container()
 {
     IoC::bind('foo', function () {
         return new Foo();
     });
     $this->assertInstanceOf('Foo', IoC::make('foo'));
 }
开发者ID:actank,项目名称:simple-di-container,代码行数:7,代码来源:IoCTest.php

示例2: purchaseDiscountedProduct

 public function purchaseDiscountedProduct($product, $discountPercentage)
 {
     $origPrice = $product->getPrice();
     $newPrice = $origPrice - $discountPercentage / 100 * $origPrice;
     $discountedProduct = IoC::make('Product', [$product->getName(), $newPrice]);
     $this->logger->log("Applying discount to " . $product->getName());
     $this->purchase($discountedProduct);
 }
开发者ID:elagith,项目名称:learningMaterial,代码行数:8,代码来源:PurchaseManager.php

示例3: getReview

    {
        $this->service = $service;
    }
    public function getReview(APIRequest $request, APIResponse $response)
    {
        $vars->review = $this->getPerformanceReviewService()->buildPerformanceReview($this->reviewId);
        $vars->questions = $this->getPerformanceReviewService()->buildReviewQuestions($this->reviewId);
        $vars->answers = $this->getPerformanceReviewService()->buildReviewAnswers($this->reviewId);
        echo json_encode($this->vars);
    }
    public function updateReview(APIRequest $request, APIResponse $response)
    {
        $reviewId = $request->get('id');
        try {
            //The API could use a different Request object, as long as it implements the right
            //interface.
            $reviewAnswers = new ReviewAnswersRequest($reviewId, $request->post('questions'));
        } catch (InvalidArgumentException $exception) {
            //invalid data posted.
            $response->errorCode(400);
            $response->errorMessage('You did it wrong!');
            return true;
        }
        $this->getPerformanceReviewService()->answerReviewQuestions($reviewAnswers);
        $response->successCode(200);
        return true;
    }
}
IoC::bind('DB', $db);
$api = IoC::make(ReviewServiceApi::class);
$api->getReview($request, $response);
开发者ID:jlesueur,项目名称:service-examples,代码行数:31,代码来源:ReviewServiceAPI.php

示例4: bind

//$foo = new Foo(new Bar(new Bim()));
//$foo->doSomething(); // Bim::doSomething|Bar::doSomething|Foo::doSomething
class IoC
{
    protected static $registry = [];
    public static function bind($name, callable $resolver)
    {
        static::$registry[$name] = $resolver;
    }
    public static function make($name)
    {
        if (isset(static::$registry[$name])) {
            $resolver = static::$registry[$name];
            return $resolver();
        }
        throw new Exception('Alias does not exist in the IoC registry.');
    }
}
IoC::bind('bim', function () {
    return new Bim();
});
IoC::bind('bar', function () {
    return new Bar(IoC::make('bim'));
});
IoC::bind('foo', function () {
    return new Foo(IoC::make('bar'));
});
// 从容器中取得Foo
$foo = IoC::make('foo');
$foo->doSomething();
// Bim::doSomething|Bar::doSomething|Foo::doSomething
开发者ID:breezelife0,项目名称:mycode,代码行数:31,代码来源:simple-di-container.php


注:本文中的IoC::make方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。