Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 187 deletions.
14 changes: 0 additions & 14 deletions .travis/run-tests.sh

This file was deleted.

7 changes: 0 additions & 7 deletions .travis/skipped-components

This file was deleted.

61 changes: 0 additions & 61 deletions .travis/tested-components

This file was deleted.

8 changes: 8 additions & 0 deletions src/BigInteger/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ public function pow($operand, $exp);
*/
public function sqrt($operand);

/**
* Get absolute value of a big integer
*
* @param string $operand
* @return string
*/
public function abs($operand);

/**
* Get modulus of a big integer
*
Expand Down
14 changes: 14 additions & 0 deletions src/BigInteger/Adapter/Bcmath.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ public function sqrt($operand)
return bcsqrt($operand);
}

/**
* Get absolute value of a big integer
*
* @param string $operand
* @return string
*/
public function abs($operand)
{
if ('-' == $operand[0]) {
return substr($operand, 1);
}
return $operand;
}

/**
* Get modulus of a big integer
*
Expand Down
12 changes: 12 additions & 0 deletions src/BigInteger/Adapter/Gmp.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ public function sqrt($operand)
return gmp_strval($result);
}

/**
* Get absolute value of a big integer
*
* @param string $operand
* @return string
*/
public function abs($operand)
{
$result = gmp_abs($operand);
return gmp_strval($result);
}

/**
* Get modulus of a big integer
*
Expand Down
46 changes: 0 additions & 46 deletions src/BigInteger/AdapterBroker.php

This file was deleted.

32 changes: 0 additions & 32 deletions src/BigInteger/AdapterLoader.php

This file was deleted.

74 changes: 74 additions & 0 deletions src/BigInteger/AdapterPluginManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Math
* @subpackage BigInteger
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Math\BigInteger;

use Zend\ServiceManager\AbstractPluginManager;

/**
* Plugin manager implementation for BigInteger adapters.
*
* Enforces that adapters retrieved are instances of
* Adapter\AdapterInterface. Additionally, it registers a number of default
* adapters available.
*
* @category Zend
* @package Zend_Math
* @subpackage BigInteger
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class AdapterPluginManager extends AbstractPluginManager
{
/**
* Default set of adapters
*
* @var array
*/
protected $invokableClasses = array(
'bcmath' => 'Zend\Math\BigInteger\Adapter\Bcmath',
'gmp' => 'Zend\Math\BigInteger\Adapter\Gmp',
);

/**
* Validate the plugin
*
* Checks that the adapter loaded is an instance of Adapter\AdapterInterface.
*
* @param mixed $plugin
* @return void
* @throws Exception\RuntimeException if invalid
*/
public function validatePlugin($plugin)
{
if ($plugin instanceof Adapter\AdapterInterface) {
// we're okay
return;
}

throw new Exception\RuntimeException(sprintf(
'Plugin of type %s is invalid; must implement %s\Adapter\AdapterInterface',
(is_object($plugin) ? get_class($plugin) : gettype($plugin)),
__NAMESPACE__
));
}
}

Loading

0 comments on commit 9a31aee

Please sign in to comment.