PHP code example of vincentmi / ccm

1. Go to this page and download the library: Download vincentmi/ccm library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vincentmi / ccm example snippets



CM\Context;

$ctx =  new Context();
echo $ctx->set('a',1)->set('b',1)->reg('c','$a + $b')->fetch('c');


cd sample
php common_use.php
php index.php 
php depency_error.php //依赖错误检测


CM\Context;
$ctx = new \CCM\Context();

echo
$ctx->reg('temperature_rate' ,function($context,$level){

    $todayTemp = $context->get('todayTemp') ; // $todayTemp = fget('http://cnweathor.com/getToday')
    if($todayTemp > 30){
        return 0.2;
    }else if($todayTemp > 40){
        return 1;
    }else if($todayTemp < 25){
        return -0.8;
    }else{
        return 0;
    }
} )
    ->reg('workload_rate',function($context){
        $workload = $context->get('workload');
        $totalCheckin = $context->get('totalCheckin');
        $workloadRate = $workload/$totalCheckin;
        if( $workloadRate < 1){
            return 0.3;
        }else if($workloadRate < 0.5){
            return 0.5;
        }else if($workloadRate == 1){
            return 0;
        }else{
            return -0.2;
        }
    })
    ->reg('price' , '$org_price * (1 + $temperature_rate + $workload_rate)')
    ->set('org_price',3)
    ->set('totalCheckin',5)
    ->set('workload',isset($argv[1])? floatval($argv[1]):5)
    ->set('todayTemp',isset($argv[2])? floatval($argv[2]):25)
    ->fetch('price');

echo "\n";

configs/app.php