Beispiel #1
0
 /**
  * Check if resource is empty
  *
  * @param resource $resource The resource
  *
  * @return bool
  */
 public static function isEmpty($resource)
 {
     if (!self::isValid($resource) && null !== $resource) {
         return false;
     }
     return String::isEmpty($resource);
 }
Beispiel #2
0
 public static function parameterValidation($file)
 {
     if (!(String::isEmpty($file, $trim = TRUE) === FALSE)) {
         return -1;
     }
     return getimagesize(new File($file)) ? TRUE : -2;
 }
Beispiel #3
0
    /**
     * Initializes a new File Object from parent and child or just parent.
     */
    public function __construct($parent = "", $child = "") {
        $parent = new String($parent);
        $child = new String($child);
        
        if($parent->isEmpty())
            throw new Exception("File path cannot be empty.");
            
        if($parent->isEmpty() && $child->isEmpty())
            throw new Exception("File path cannot be empty.");

        if($parent->substring(-1) == $this::seperatorChar && !$child->isEmpty())
            $this->path = $parent . $child;
        else if(!$child->isEmpty())
            $this->path = $parent . $this::seperatorChar . $child;
        else
            $this->path = $parent;
	}
Beispiel #4
0
 /**
  * Private method which normalizes email argument validation throughout all of the 
  * contained methods of this class.
  * @param String $email
  * @return Int -1 Given argument is not a string
  * @return Int -2 Given argument is empty
  * @return boolean TRUE argument is a valid email
  * @return boolean FALSE $email argument is an invalid email
  */
 public static function parameterValidation($email)
 {
     if (!String::isString($email)) {
         return -1;
     }
     if (String::isEmpty($email, $useTrim = TRUE)) {
         return -2;
     }
     $addressDomain = substr($email, strpos($email, '@') + 1);
     $mxRecords = array();
     if (!getmxrr($addressDomain, $mxRecords)) {
         return -3;
     }
     return filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE ? -4 : TRUE;
 }
Beispiel #5
0
 /**
  *Checks if a class has a method named $method (boolean mode)
  *
  *@param String $name class name
  *@param String $method method to be checked 
  *@param Mixed  $filters, a set of filters to check for class attributes such as public,
  *					private, abstract, final, etc. You can specify a string such as "abstract"
  *					or you can specify a set of filters in an Array like structure
  *					for instance, specifying $filters to  Array('static','public') 
  *					would check for a method named $method that is both static AND public.
  *					Note: This is affected according to the mode you specify, 
  *					which is by default "all", meaning that every filter you specify
  *					must be present in the given method.
  *
  *@param String	$mode mode can be any of "all", "any" or "some". The default mode is "all"
  *
  *					"all" mode: the method must contain ALL and *ONLY* the parameters that you 
  *					specify in the $filters argument. If it contains extra attributes it will be
  *					considered as invalid.
  *
  *					"any" mode: the method must contain at least ONE of the parameters specified
  *					in $filters. Extra attributes don't matter.
  *
  *					"some" mode: the method must contain all of the attributes specified in
  *					$filters, but if it contains any other attribute it's still considered 
  *					valid.
  *					
  *					is necessary to exist in the given method for it to be TRUE.
  *					
  *					
  *@param String $msg Exception message if any
  *@param Int $exCode Exception code
  *
  *@return Int -6 if $filters are not null and an empty string was entered
  *@return Int -7 if $filters are an array but the array elements are not strings or it's empty
  *@return Int -8 ONLY if specified filters are empty
  *@return Int -9 ONLY if an invalid filter was specified
  *@return Int -10 Method doesn't exists
  *@return boolean TRUE if the class has a method named $method
  *@return boolean FALSE if the class doesn't has a method named $method
  *
  *@see self::parameterValidation for other return values
  */
 public static function hasMethod($name, $method, $filters = NULL, $mode = "all")
 {
     $validModes = array('all', 'any', 'some');
     $stdValidation = self::parameterValidation($name, $method);
     //something went wrong
     if (!($stdValidation === TRUE)) {
         return $stdValidation;
     }
     $rc = new \ReflectionClass($name);
     //If no filters where specified, then check if the given class has a given method
     //and thats it! We don't need further checking if the user hasn't specified any filters.
     if (is_null($filters)) {
         return $rc->hasMethod($method);
     }
     //Check if specified $filters are invalid
     if (is_string($filters)) {
         if (String::isEmpty($filters)) {
             return -6;
         }
     }
     //If it's an array but the array is not made of strings
     if (!is_null(Vector::isArray($filters)) && !Vector::isMadeOfStrings($filters)) {
         return -7;
     }
     if (is_string($filters)) {
         $filters = array($filters);
     }
     $mode = strtolower($mode);
     //Specified $mode is invalid (not one of all,any or some)
     if (String::isEmpty($mode) || !in_array($mode, $validModes)) {
         return -7;
     }
     //Check if entered filters are not empty
     if (empty($filters)) {
         return -8;
     }
     //Check if entered filters are valid
     foreach ($filters as $filter) {
         $filter = sprintf('IS_%s', strtoupper($filter));
         //If an invalid filter is detected, then return -9
         if (!self::hasConstant('\\ReflectionMethod', $filter)) {
             return -9;
         }
     }
     //Fetch all class methods
     $methods = $rc->getMethods();
     $found = FALSE;
     foreach ($methods as $m) {
         //If the current method is not equal to the selected one then continue
         //with the next element in the array
         if ($m->name !== $method) {
             continue;
         }
         $found = TRUE;
         break;
     }
     //Method not found
     if (!$found) {
         return -8;
     }
     //Get all method modifiers (public, abstract, private, final, etc)
     $modifiers = \Reflection::getModifierNames($m->getModifiers());
     switch ($mode) {
         case "any":
             foreach ($filters as $f) {
                 if (in_array($f, $modifiers)) {
                     return TRUE;
                 }
             }
             return FALSE;
             break;
         case "some":
             $count = 0;
             foreach ($modifiers as $mod) {
                 if (in_array($mod, $filters)) {
                     $count++;
                 }
             }
             return $count == sizeof($filters);
             break;
         case "all":
             foreach ($modifiers as $mod) {
                 if (!in_array($mod, $filters)) {
                     return FALSE;
                 }
             }
             return TRUE;
             break;
     }
 }
Beispiel #6
0
 /**
  * Convert a string to an array
  *
  * @param string $string    The string
  * @param string $delimiter The delimiter
  *
  * @return array
  */
 public static function explode($string, $delimiter)
 {
     if (!String::isValid($string) || String::isEmpty($string)) {
         return false;
     }
     return explode($delimiter, $string);
 }
Beispiel #7
0
 /**
  * Validates that an array like structure is made of strings
  * @param Mixed $array
  * @param boolean $nonEmpty whether or not the strings contained inside the array can be empty
  * @return boolean TRUE
  * @return Mixed Index position where the failure condition has been found.
  */
 public static function isMadeOfStrings($array, $nonEmpty = TRUE)
 {
     $stdValidation = self::parameterValidation($array);
     if (!($stdValidation === TRUE)) {
         return $stdValidation;
     }
     foreach ($array as $key => $val) {
         if (is_object($val)) {
             if (!Object::hasMethod($val, "__toString")) {
                 return $key;
             }
             //print the object
             $val = sprintf('%s', $val);
         }
         if ($nonEmpty && String::isEmpty($val)) {
             return $key;
         }
     }
     return TRUE;
 }
Beispiel #8
0
 /**
  * Generate random number
  *
  * @param int $min Minimum value
  * @param int $max Maximum value
  *
  * @return int
  */
 public static function random($min, $max = null)
 {
     if (String::isEmpty($max) || $max > getrandmax()) {
         $max = getrandmax();
     }
     return rand($min, $max);
 }
Beispiel #9
0
 /**
  * Sets the requested Exchange server version
  * @param string $version
  * @return null
  * @throws zibo\ZiboException when the provided version is empty
  */
 protected function setVersion($version)
 {
     if ($version === null) {
         $version = self::DEFAULT_VERSION;
     } elseif (String::isEmpty($version)) {
         throw new ZiboException('Provided version is empty');
     }
     $this->version = $version;
 }
Beispiel #10
0
 public function testIsEmpty()
 {
     $o = new String(self::MULTI_LINE);
     $this->assertFalse($o->isEmpty());
     $o = new String('');
     $this->assertTrue($o->isEmpty());
 }
Beispiel #11
0
$database = new Database();
// initialize class
$database->connect();
// connect to db
LookbookDatabase::$database = $database;
// pass database accessor
//email-redirect.php?email=mrjesuserwinsuarez@gmail.com&action=private-beta&redirect=TRUE
//email-redirect.php?&email=mrjesuserwinsuarez@gmail.com&action=signup&redirect=TRUE
//email-redirect.php?&email=mrjesuserwinsuarez@gmail.com&action=remove&redirect=TRUE
//email-redirect.php?&email=mrjesuserwinsuarez@gmail.com&action=open&redirect
//email-redirect.php?&email=mrjesuserwinsuarez@gmail.com&action=Recieved Invitation&redirect
// $action      = 'signup';
// $id          = 1;
// $email       = '*****@*****.**';
//other initialized
$defaultLink = 'http://fashionsponge.com/';
$action = String::isEmpty($_GET['action'], '');
$email = String::isEmpty($_GET['email'], '');
$redirect = String::isEmpty($_GET['redirect'], FALSE);
$qid = !empty($_GET['qid']) ? $_GET['qid'] : 0;
$fname = LookbookDatabase::getFullNameByEmail($email);
//notification send to admin when email clicked action
$to = Program::$adminEmail;
//'mrjesuserwinsuarez@gmail.com,pecotrain1@gmail.com';
$subject = 'invited person clicked the email content ' . $action;
$body = 'Email: ' . $email . "\n" . 'First Name: ' . $fname . "\n" . ' Action: ' . $action;
$from = $email;
$title = 'FS ' . $action;
echo "<div style='display:none' >";
Program::emailInvitationClickedSaveActivityAndRedirectLocation($defaultLink, $action, $redirect, $to, $subject, $body, $from, $title, $qid, $email);
echo "</div>";
 private function scanTemporaryUploadPath(Io_Path $path_, $subPath_ = '')
 {
     if (false === String::isEmpty($subPath_) && false === String::endsWith($subPath_, '/')) {
         $subPath_ .= '/';
     }
     foreach ($path_ as $entry) {
         if ($entry->isDot()) {
             continue;
         }
         if ($entry->isFile()) {
             $this->stashFile($entry->asFile(), $subPath_);
         } else {
             if ($entry->isDirectory()) {
                 $this->scanTemporaryUploadPath($entry, $subPath_ . $entry->getName());
             }
         }
     }
     $path_->delete(true);
 }
Beispiel #13
0
 public function testIsEmpty()
 {
     $string = new String();
     $this->assertTrue($string->isEmpty());
 }