Exemplo n.º 1
0
 public function resolveArgument(Strategy $strategy)
 {
     foreach ($this->arguments as $argument) {
         if ($strategy->supportsArgument($argument)) {
             return $argument;
         }
     }
     throw new \RuntimeException(sprintf("Cannot resolve argument for strategy %s. Please make sure you registered all valid arguments", get_class($strategy)));
 }
Exemplo n.º 2
0
 /**
  * @return void
  */
 public function init()
 {
     parent::init();
     //        sort($this->weight, SORT_DESC);
     //        $this->weight = array_slice($this->weight, 0,
     //                count($this->_queue->queues));
 }
Exemplo n.º 3
0
 public function getStrategies()
 {
     return [Strategy::create('random', function ($context, $options) {
         return mt_rand(0, 1) < 0.5;
     }), Strategy::create('percent', function ($context, $options) {
         return mt_rand(0, 100) < $options['thresold'];
     }), Strategy::create('distribute', function ($context, $options) {
         if (!isset($options['distribution']) || !is_array($options['distribution'])) {
             throw new \RuntimeException(sprintf("Missing configuration array 'distribution' for the distribute strategy."));
         }
         $distribution = $options['distribution'];
         $thresoldMap = array();
         $previousValue = 0;
         foreach ($distribution as $name => $value) {
             $thresoldMap[$name] = $value + $previousValue;
             $previousValue = $thresoldMap[$name];
         }
         $randomPercent = mt_rand(0, 100);
         $previousThresold = 0;
         foreach ($thresoldMap as $name => $thresold) {
             if ($previousThresold <= $randomPercent && $randomPercent < $thresold) {
                 return $name;
             }
             $previousThresold = $thresold;
         }
         return $name;
     })];
 }
Exemplo n.º 4
0
 /**
  * Get authorization code from callback and fetch user access_token and
  * other information
  *
  * @access  public
  * @param   string      $provider
  * @return  Response
  * @throws  Strategy\Exception
  */
 public function action_callback($provider = null)
 {
     // if provider data is somehow empty, it might not came from a
     // provider.
     if (empty($provider)) {
         return \Response::error('404');
     }
     try {
         $strategy = Strategy::make($provider);
         return Strategy::login_or_register($strategy);
     } catch (Strategy\Exception $e) {
         return $this->action_error($provider, $e->getMessage());
     }
 }
Exemplo n.º 5
0
 /**
  * Copy & Paste Detection (CPD).
  *
  * @param  Iterator|array $files     List of files to process
  * @param  integer        $minLines  Minimum number of identical lines
  * @param  integer        $minTokens Minimum number of identical tokens
  * @return CodeCloneMap   Map of exact clones found in the list of files
  */
 public function copyPasteDetection($files, $minLines = 5, $minTokens = 70)
 {
     $result = new CodeCloneMap();
     if ($this->output !== NULL) {
         $bar = new \ezcConsoleProgressbar($this->output, count($files));
         print "Processing files\n";
     }
     foreach ($files as $file) {
         $this->strategy->processFile($file, $minLines, $minTokens, $result);
         if ($this->output !== NULL) {
             $bar->advance();
         }
     }
     if ($this->output !== NULL) {
         print "\n\n";
     }
     return $result;
 }
Exemplo n.º 6
0
 public function action_callback($provider)
 {
     $strategy = Strategy::forge($provider);
     Strategy::login_or_register($strategy);
 }
Exemplo n.º 7
0
 public function __construct(Connection $connection)
 {
     parent::__construct($connection);
     $this->escapeIdentifierCharacter = '"';
 }
Exemplo n.º 8
0
 public function init()
 {
     parent::init();
     srand();
 }
Exemplo n.º 9
0
 public function getWinner($levers)
 {
     return $this->shouldExplore($levers) ? null : parent::getWinner($levers);
 }
Exemplo n.º 10
0
 /**
  * Construct
  * @param array $elevation
  * @param float $epsilon [optional]
  */
 public function __construct(array $elevation, $epsilon = 0)
 {
     parent::__construct($elevation);
     $this->setEpsilon($epsilon);
 }
Exemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function isSatisfiedBy($value)
 {
     return $this->strategy->evaluate($value, ...$this->specifications);
 }
Exemplo n.º 12
0
 /**
  * Create the LightOpenId instance.
  * @param string $provider The provider name, in our case openid
  */
 public function __construct($provider)
 {
     parent::__construct($provider);
     $this->openid = new \LightOpenID(\Input::server('HTTP_HOST'));
 }