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))); }
/** * @return void */ public function init() { parent::init(); // sort($this->weight, SORT_DESC); // $this->weight = array_slice($this->weight, 0, // count($this->_queue->queues)); }
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; })]; }
/** * 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()); } }
/** * 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; }
public function action_callback($provider) { $strategy = Strategy::forge($provider); Strategy::login_or_register($strategy); }
public function __construct(Connection $connection) { parent::__construct($connection); $this->escapeIdentifierCharacter = '"'; }
public function init() { parent::init(); srand(); }
public function getWinner($levers) { return $this->shouldExplore($levers) ? null : parent::getWinner($levers); }
/** * Construct * @param array $elevation * @param float $epsilon [optional] */ public function __construct(array $elevation, $epsilon = 0) { parent::__construct($elevation); $this->setEpsilon($epsilon); }
/** * {@inheritdoc} */ public function isSatisfiedBy($value) { return $this->strategy->evaluate($value, ...$this->specifications); }
/** * 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')); }