__construct() public method

public __construct ( $min = null, $max = null )
コード例 #1
0
ファイル: Month.php プロジェクト: duncan3dc/dates
 /**
  * Create a new instance from a date object.
  *
  * @param DateTime $date A date within the season
  */
 public function __construct(DateTime $date)
 {
     $this->unix = $date->timestamp();
     $start = Date::mkdate($date->numeric("Y"), $date->numeric("n"), 1);
     $end = Date::mkdate($date->numeric("Y"), $date->numeric("n"), $date->numeric("t"));
     parent::__construct($start, $end);
 }
コード例 #2
0
ファイル: IntegerRange.php プロジェクト: ustrugany/12tdds
 public function __construct($lowestNumber = 0, $highestNumber = 0)
 {
     if (!is_int($lowestNumber) || !is_int($highestNumber)) {
         throw new \InvalidArgumentException('Only integer numbers are supported');
     }
     parent::__construct($lowestNumber, $highestNumber);
 }
コード例 #3
0
ファイル: Block.php プロジェクト: jaaulde/php-ipv4
 /**
  * Constructor
  *
  * @param \JAAulde\IP\V4\Address|string                               $a1 The base address with which the network and broadcast addresses of this block will be calculated. This can be an
  *                                                                        an instance of \JAAulde\IP\V4\Address, in which case the second parameter will be required, or a string in dot-notated format with optional CIDR
  *                                                                        slash prefix. If a string without CIDR slash prefix, second parameter is required. If there is a CIDR slash prefix, second parameter will be ignored.
  * @param \JAAulde\IP\V4\SubnetMask|int|string|\JAAulde\IP\V4\Address $a2 Optional depending on what was given as the first parameter. This is a subnet mask
  *                                                                        to determine the size of this block, or a CIDR prefix for calculating a subnet mask, or a second \JAAulde\IP\V4\Address instance to fit into the derived
  *                                                                        block.
  *
  * @throws Exception
  */
 public function __construct($a1, $a2 = null)
 {
     $subnetMask = null;
     if (is_string($a1)) {
         $a1parts = explode('/', $a1, 2);
         $a1sub1 = $a1parts[0];
         $a1sub2 = isset($a1parts[1]) ? $a1parts[1] : null;
         $a1 = new Address($a1sub1);
         if ($a1sub2 !== null) {
             $a2 = (int) $a1sub2;
         }
     }
     if ($a2 instanceof SubnetMask) {
         $subnetMask = $a2;
     } else {
         if ($a2 instanceof Address) {
             $a2 = SubnetMask::calculateCIDRToFit($a1, $a2);
         }
         if (is_string($a2) && count(explode('.', $a2)) === 4) {
             $subnetMask = new SubnetMask($a2);
         } elseif (is_int($a2) || is_string($a2)) {
             $subnetMask = SubnetMask::fromCIDRPrefix((int) preg_replace('/[^\\d]/', '', (string) $a2));
         }
     }
     if (!$subnetMask instanceof SubnetMask) {
         throw new \Exception(__METHOD__ . ' could not derive a subnet mask. See documentation for second param, $a2.');
     }
     $this->subnetMask = $subnetMask;
     parent::__construct(self::calculateNetworkAddress($a1, $subnetMask), self::calculateBroadcastAddress($a1, $subnetMask));
 }
コード例 #4
0
ファイル: Block.php プロジェクト: Codepoints/Unicode.php
 /**
  * create a new UnicodeBlock
  *
  * If $name is given and $r is Null, the block is looked up in the
  * database. If $r is set, the relevant items are taken from there.
  */
 public function __construct($name, $db, $r = NULL)
 {
     if ($r === NULL) {
         // performance: allow to specify range
         $query = $db->prepare("\n                SELECT name, first, last, abstract\n                FROM blocks\n                LEFT JOIN block_abstract\n                    ON blocks.name = block_abstract.block\n                WHERE replace(replace(lower(name), '_', ''), ' ', '') = ?\n                LIMIT 1");
         $query->execute([Toolkit::normalizeName($name)]);
         $r = $query->fetch(\PDO::FETCH_ASSOC);
         $query->closeCursor();
         if ($r === False) {
             throw new Exception('No block named ' . $name);
         }
     }
     $this->name = $r['name'];
     // use canonical name
     $this->limits = [$r['first'], $r['last']];
     parent::__construct(range($r['first'], $r['last']), $db);
 }