Esempio n. 1
0
 /**
  * Check path existance & readability
  *
  * @param  string $path
  * @throws NotFoundException if $path not found
  * @throws RuntimeException if $path not readable
  * @access protected
  * @static
  */
 protected static function checkPath($path)
 {
     if (!file_exists($path)) {
         throw new NotFoundException(Message::get(Message::MSG_PATH_NOTFOUND, $path), Message::MSG_PATH_NOTFOUND);
     }
     if (!is_readable($path)) {
         throw new RuntimeException(Message::get(Message::MSG_PATH_NONREADABLE, $path), Message::MSG_PATH_NONREADABLE);
     }
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  */
 public function setShareable($scope = '')
 {
     // this $scope has shareable already or $this is a shareable
     if (static::hasShareable($scope) || $this->isShareable() !== false) {
         throw new RuntimeException(Message::get(Message::MSG_SHAREABLE_FAIL, $scope), Message::MSG_SHAREABLE_FAIL);
     }
     $this->shared_in = $scope;
     self::$shareables[get_class($this)][$scope] = $this;
     return $this;
 }
Esempio n. 3
0
 /**
  * Read, parse & return contents from the $path
  *
  * @param  string $path
  * @param  string $type force this type
  * @return mixed
  * @throws NotFoundException if $path not found
  * @throws RuntimeException if something goes wrong
  * @access public
  * @since  2.0.16 added $type param
  * @static
  */
 public static function readFile($path, $type = '')
 {
     $suffix = $type ?: substr($path, strpos($path, '.') + 1);
     if (!static::isSupported($suffix)) {
         throw new RuntimeException(Message::get(Message::MSG_PATH_TYPE_UNKNOWN, $suffix), Message::MSG_PATH_TYPE_UNKNOWN);
     }
     /* @var ReaderInterface $class */
     $class = static::getNameSpace() . '\\' . ucfirst($suffix) . 'Reader';
     return $class::readFile($path);
 }
Esempio n. 4
0
 /**
  * Set object properties
  *
  * @param  array $properties
  * @access public
  * @since  2.0.24 added
  * @api
  */
 public final function setProperties(array $properties = [])
 {
     foreach ($properties as $name => $value) {
         if (property_exists($this, $name)) {
             $this->{$name} = $value;
         } else {
             trigger_error(Message::get(Message::MSG_PROPERTY_UNKNOWN, $name, get_class($this)), E_USER_WARNING);
         }
     }
 }
Esempio n. 5
0
 /**
  * {@inheritDoc}
  */
 public function addExtension(ExtensionInterface $ext, $forceOverride = false)
 {
     foreach ($ext->methodsAvailable() as $method) {
         if (isset($this->extension_methods[$method]) && !$forceOverride) {
             throw new LogicException(Message::get(Message::MSG_EXTENSION_METHOD, $method), Message::MSG_EXTENSION_METHOD);
         }
         $this->extension_methods[$method] = $ext;
     }
     $ext->boot($this);
     return $this;
 }
Esempio n. 6
0
 /**
  * {@inheritDoc}
  */
 public function getDelegator($recursive = false)
 {
     if ($this->hasDelegator()) {
         $dele = $this->delegator;
         if ($this->isRecursiveDelegator($recursive, $dele)) {
             return $dele->getDelegator($recursive);
         }
         return $dele;
     }
     throw new NotFoundException(Message::get(Message::MSG_DELEGATOR_UNKNOWN, get_called_class()), Message::MSG_DELEGATOR_UNKNOWN);
 }
Esempio n. 7
0
 /**
  * Throw exception if looped
  *
  * @param  int $loop loop counter
  * @param  string $name reference name
  * @throws RuntimeException if loop found
  * @access protected
  * @since  2.0.6
  */
 protected function checkReferenceLoop($loop, $name)
 {
     if ($loop > 20) {
         throw new RuntimeException(Message::get(Message::MSG_REF_LOOP, $name), Message::MSG_REF_LOOP);
     }
 }
Esempio n. 8
0
 /**
  * Finalized constructor to prevent instantiation.
  *
  * @access public
  * @final
  */
 public final function __construct()
 {
     throw new RuntimeException(Message::get(Message::MSG_CLASS_STATIC, get_called_class()), Message::MSG_CLASS_STATIC);
 }