Example #1
0
 /**
  * Crea una nueva instancia con los números principal, secundario, de
  * compilación (opcional) y revisión (opcional).
  * Para comprobar si la versión es válida, usar el método isValid.
  *
  * @param int                              $major    Componente principal
  * @param int                              $minor    Componente secundario
  * @param int|string|VersionComponent|null $build    Componente de compilación
  * @param int|string|VersionComponent|null $revision Componente de revisión
  *
  * @throws InvalidArgumentException
  * */
 public function __construct($major, $minor, $build = null, $revision = null)
 {
     parent::__construct();
     unset($this->Major, $this->Minor, $this->Build, $this->Revision);
     if (!is_integer($major)) {
         $args = ['class' => typeof($this)->Name, 'name' => 'major', 'pos' => 0, 'expected' => typeof(0), 'actual' => typeof($major)];
         $msg = nml_msg('Invalid argument type.');
         $msg .= nml_msg(' "{name}" (position {pos}) must to be an instance of "{expected}"; "{actual}" given.', $args);
         $msg .= nml_msg(' Convert value or use the "{class}::parse" (static) method.', $args);
         throw new InvalidArgumentException($msg);
     }
     if (!is_integer($minor)) {
         $args = ['class' => typeof($this)->Name, 'name' => 'minor', 'pos' => 1, 'expected' => typeof(0), 'actual' => typeof($minor)];
         $msg = nml_msg('Invalid argument type.');
         $msg .= nml_msg(' "{name}" (position {pos}) must to be an instance of "{expected}"; "{actual}" given.', $args);
         $msg .= nml_msg(' Convert value or use the "{class}::parse" (static) method.', $args);
         throw new InvalidArgumentException($msg);
     }
     if ($major < 0) {
         $args = ['name' => 'major', 'pos' => 0, 'actual' => $major];
         $msg = nml_msg('Invalid argument value.');
         $msg .= nml_msg(' "{name}" (position {pos}) must to be a positive number; "{actual}" given.', $args);
         throw new InvalidArgumentException($msg);
     }
     if ($minor < 0) {
         $args = ['name' => 'minor', 'pos' => 1, 'actual' => $minor];
         $msg = nml_msg('Invalid argument value.');
         $msg .= nml_msg(' "{name}" (position {pos}) must to be a positive number; "{actual}" given.', $args);
         throw new InvalidArgumentException($msg);
     }
     $this->major = $major;
     $this->minor = $minor;
     $this->build = VersionComponent::Parse($build);
     $this->revision = VersionComponent::Parse($revision);
 }
Example #2
0
 /**
  * Gets the type of specified $obj and collect some info about itself.
  *
  * @param mixed $obj Target object.
  * */
 public function __construct($obj)
 {
     parent::__construct();
     unset($this->Namespace, $this->Name, $this->ShortName, $this->Vars, $this->Methods);
     $name = gettype($obj);
     $shortname = null;
     $namespace = null;
     $vars = null;
     $methods = null;
     $ref = null;
     switch ($name) {
         case 'object':
             $ref = new ReflectionClass($obj);
             $name = $ref->getName();
             $shortName = $ref->getShortName();
             $namespace = $ref->getNamespaceName();
             break;
         case 'resource':
             $shortName = get_resource_type($obj);
             $name = 'resource: ' . $shortName;
             $vars = [];
             $methods = [];
             break;
         default:
             $shortName = $name;
             $vars = [];
             $methods = [];
     }
     $this->name = $name;
     $this->shortName = $shortName;
     $this->namespace = $namespace;
     $this->vars = $vars;
     $this->methods = $methods;
     $this->reflectionObject = $ref;
 }
Example #3
0
 /**
  * Crea una nueva instancia de la clase Asset.
  *
  * @param string|null               $name     Nombre humano del recurso.
  * @param array|string|Version|null $versions Versión(es) del recurso.
  * @param string|null               $cdnUri   URL del recurso en un
  *   servidor CDN.
  */
 public function __construct($name = null, $versions = null, $cdnUri = null)
 {
     parent::__construct();
     unset($this->Name, $this->Versions, $this->ShortName, $this->CdnUri, $this->RootDirectory);
     if ($name == null) {
         $this->name = '';
         $this->shortName = '';
     } else {
         $this->Name = $name;
     }
     if ($this->Name == '' && $versions != null) {
         $args = ['name' => 'versions', 'pos' => 1, 'name2' => 'name', 'pos2' => 0];
         $msg = nml_msg('Invalid argument value.');
         $msg .= nml_msg(' "{name}" (position {pos}) can not be specified if "{name2}" (position {pos2}) is "null".', $args);
         throw new InvalidArgumentException($msg);
     }
     if ($versions == null) {
         $versions = array();
     }
     if (is_array($versions)) {
         $this->versions = array();
         if (count($versions) > 0) {
             $i = 0;
             foreach ($versions as $version) {
                 $v = $version;
                 if (!$v instanceof Version) {
                     try {
                         $v = Version::parse($version);
                     } catch (InvalidArgumentException $e) {
                         $args = ['name' => 'versions', 'pos' => 1, 'expected' => typeof(new Version(1, 0))->Name, 'actual' => typeof($version)->Name];
                         $msg = nml_msg('Invalid argument value.');
                         $msg .= nml_msg(' "{name}" (position {pos}) must to be an array of "{expected}" elements (or any' . ' parseable into "{expected}"); the array given has an invalid "{actual}" element.', $args);
                         throw new InvalidArgumentException($msg, 0, $e);
                     }
                 }
                 $this->versions[$i] = $v;
                 $i += 1;
             }
         }
     } else {
         // Trata de convertir $versions en un objeto Versión
         try {
             $v = Version::parse($versions);
         } catch (InvalidArgumentException $e) {
             $args = ['name' => 'versions', 'pos' => 1, 'expected' => typeof(new Version(1, 0))->Name, 'actual' => typeof($versions)->Name];
             $msg = nml_msg('Invalid argument value.');
             $msg .= nml_msg(' "{name}" (position {pos}) must to be an array of "{expected}" elements, an instance of' . ' "{expected}" or any object parseable into "{expected}"; "{actual}" given.', $args);
             throw new InvalidArgumentException($msg, 0, $e);
         }
         $this->versions = array($v);
     }
     $this->CdnUri = $cdnUri;
 }
Example #4
0
 public function __construct()
 {
     parent::__construct();
     unset($this->Count);
 }