Esempio n. 1
0
 public function Where($where)
 {
     $array = $this->array;
     $new = new ArrayHelper();
     foreach ($array as $key => $element) {
         if ($where($element, $key)) {
             $new->Add($element);
         }
     }
     return $new;
 }
Esempio n. 2
0
 /**
  *This method returns the first row match in a query.
  *@param null
  *@return \MySQLResponseObject
  *@throws This method does not throw an error
  */
 public function first()
 {
     //get the limit clause value
     $limit = $this->limits;
     //get the offset value
     $limitOffset = $this->offset;
     //set the limit to 1
     $this->limit(1);
     //get all
     $all = $this->all();
     //get the first
     $first = ArrayUtility::first($all->result_array())->get();
     //if limit is defined
     if ($limit) {
         //set the limit property
         $this->limits = $limit;
     }
     //if limit offset is set
     if ($limitOffset) {
         //set the offset
         $this->offset = $limitOffset;
     }
     //get the response object instance
     $this->responseObject->setResultArray($first);
     //return the full response object
     return $this->responseObject;
 }
Esempio n. 3
0
 /**
  *This method sets the url string request parameters for this input string
  *
  *@param sting $value The new value to add to the parameters array
  *@param bool True|False Flag to indicated whether the additional value is to be prepended or appended
  *@return Object \UrlParser
  */
 public function setParameters($value = null, $appendParameter = true)
 {
     //check if the $urlComponentsArray has more than two element
     $this->parameters = count($this->urlComponentsArray) > 2 ? ArrayHelper::slice($this->urlComponentsArray, 2)->get() : array();
     //check if there is an additonal parameter to add to parameters array
     if ($value !== null) {
         //check if this parameter is to be prepended or appended
         if ($appendParameter === true) {
             //append
             $this->parameters[] = $value;
         } else {
             //prepend
             array_unshift($this->parameters, $value);
         }
     }
     //return this class instance
     return $this;
 }
 /**
  *This method new list info into the database
  *@param null
  *@return void
  */
 public function postManagenew()
 {
     echo "<pre>";
     print_r(ArrayHelper::clean(Input::get())->get());
     exit;
 }
Esempio n. 5
0
 /**
  *This method sets the value of the method name
  *
  *@param null
  *@return Object \RouteParser
  */
 public function setMethod()
 {
     //check if method metadata is null
     if (is_null($this->methodMetaData)) {
         //if there was no method metaData check if there are names url param keys  in the controller name
         $requestParamKeys = ArrayHelper::parts($this->urlParameterSeparator, $this->controller)->clean()->trim()->get();
         //check if there are parameter found
         if (count($requestParamKeys) > 1) {
             //set the new value of the controller
             $this->controller = $requestParamKeys[0];
             //set a value for the methodMetaData
             $this->methodMetaDataArray = $requestParamKeys;
         }
         //there is no method frm the routes, get the route from the UrlParser instance
         $this->method = $this->UrlParserObjectInstance->getMethod();
         return $this;
     } else {
         //get the methodMetaDataArray
         $methodMetaDataArray = ArrayHelper::parts($this->urlParameterSeparator, $this->methodMetaData)->clean()->trim()->get();
         //put this in a try...catch block to enhance error handlign
         try {
             if (count($methodMetaDataArray) > 0) {
                 //set the value of the method property
                 $this->method = $methodMetaDataArray[0];
                 //check if the value of method from url parse is not null
                 if ($this->UrlParserObjectInstance->getMethod() !== null) {
                     //if the method name can be got from the methodMetaData, then lets prepend the value of method to the urlParser parameters
                     $this->UrlParserObjectInstance->setParameters($this->UrlParserObjectInstance->getMethod(), false);
                 }
                 //set the methodMetaDataArray property
                 $this->methodMetaDataArray = $methodMetaDataArray;
                 //returnt this class instance
                 return $this;
             } else {
                 //throw an exception
                 throw new RouteException(get_class(new RouteException()) . " : The method name specified after this named route " . $this->routeName . " => " . $this->controller . "@" . $this->methodMetaData . " is invalid format", 1);
             }
         } catch (RouteException $RouteExceptionObjectInstance) {
             //display the error message
             $RouteExceptionObjectInstance->errorShow();
         }
     }
 }
Esempio n. 6
0
 /**
  *This method sets the value of the request parameter
  *
  *@param null
  *@return Object \RouteParser
  */
 public function setParameters()
 {
     //set the requestParamKeys
     $this->requestParamKeys = count($this->methodMetaDataArray) > 1 ? ArrayHelper::slice($this->methodMetaDataArray, 1)->get() : array();
     //check if the requestParamKeys contain values
     if (count($this->requestParamKeys) > 0) {
         //get the url parameter from the UrlParserObjectInstance
         $requestParamValues = $this->UrlParserObjectInstance->getParameters();
         //get the number of keys
         $requestParamKeysLen = count($this->requestParamKeys);
         //check if the keys are more than then values
         if ($requestParamKeysLen >= count($requestParamValues)) {
             //padd the $requestParamValues with null values
             $requestParamValues = array_pad($requestParamValues, $requestParamKeysLen, null);
             //combine the two arrays into one
             $requestParams = array_combine($this->requestParamKeys, $requestParamValues);
             //populate the Input Class data
             Input::setGet()->setPost()->setUrl($requestParams);
             //return this object instance
             return $this;
         } else {
             //split the array to only remain with the number defined inthe keys
             $requestParamValues = ArrayHelper::slice($requestParamValues, 0, $requestParamKeysLen)->get();
             //combine the two arrays into one
             $requestParams = array_combine($this->requestParamKeys, $requestParamValues);
             //populate the Input Class data
             Input::setGet()->setPost()->setUrl($requestParams);
             //return this object instance
             return $this;
         }
     } else {
         //populate the Input Class data
         Input::setUrl($this->UrlParserObjectInstance->getParameters())->setGet()->setPost();
         //return this object instance
         return $this;
     }
 }
Esempio n. 7
0
 private function BuildJoin($type, $join, $on, $on2)
 {
     if ($this->join == null && StringHelper::Contains($on, ".")) {
         $this->as = " AS " . ArrayHelper::getFirstElement(explode(".", $on));
     }
     $as = "";
     if (StringHelper::Contains($on2, ".")) {
         $as = " AS " . ArrayHelper::getFirstElement(explode(".", $on2));
     }
     if ($join instanceof Select) {
         if ($join->join != null) {
             $this->join .= " " . $type . " JOIN ( ";
             $this->join .= " " . $join->getQuery();
             $this->join .= ")" . $as . " ON " . $on . " = " . $on2;
         } else {
             $this->join .= " " . $type . " JOIN " . $join->type . $as . " ON " . $on . " = " . $on2;
         }
         $this->Where($join->where);
     } else {
         if (is_string($join)) {
             $this->join .= " " . $type . " JOIN " . $join . $as . " ON " . $on . " = " . $on2;
         } else {
             throw new UnitOfWorkException("Tipo não válido");
         }
     }
 }