예제 #1
0
 /**
  * Facade interface method
  *
  * @param   string      $name
  * @param   array       $arguments
  * @return  \SimpleHash\Container\HashContainer
  * @throws  \SimpleHash\Exception\SimpleHashException
  */
 public static function __callStatic($name, $arguments)
 {
     $factory = new HashFactory(self::getCalclatorParams($arguments));
     // Check if the requested algorithm is implemented
     if (!$factory->hasCalculator($name)) {
         throw SimpleHashException::make('Algorithm "' . $name . '" is not implemented yet!');
     }
     // Build hash container
     $getterMethod = self::getFactoryMethodName($name);
     return $factory->{$getterMethod}(self::getPlainTextString($arguments));
 }
예제 #2
0
 /**
  * Magic factory method
  *
  * @param   string      $name
  * @param   array       $arguments
  * @throws  SimpleHashException
  */
 public function __call($name, $arguments)
 {
     if ($this->isCalledGetter($name) === false) {
         throw SimpleHashException::make('Unsupported method "' . $name . '" called!');
     }
     // Initialize variables
     $plainText = $this->getPlainStringFromArguments($arguments);
     // Initialize calculator
     $calculatorClass = $this->getCalculatorName($name);
     if (!$this->calculatorExists($calculatorClass)) {
         throw SimpleHashException::make('No calclator "' . $calculatorClass . '" exists!');
     }
     $calculator = $this->initializeCalculator($calculatorClass);
     // Initialize hash container with hash string
     $container = new HashContainer();
     $container->setHashString($calculator->getHash($plainText));
     // Return hash container
     return $container;
 }
 public function testMake()
 {
     $ex = SimpleHashException::make();
     $this->assertInstanceOf('SimpleHash\\Exception\\SimpleHashException', $ex);
     $this->assertEquals('Unknown exception', $ex->getMessage());
 }