idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
18,300 | final public function extendPropertyModel ( $ dataModel = array ( ) , $ objectType = "object" ) { $ this -> propertyModel = array_merge ( $ this -> propertyModel , $ dataModel ) ; $ this -> setObjectType ( $ objectType ) ; return $ this ; } | Extends the parent data model Allows the current object to use parent object properties |
18,301 | final public function definePropertyModel ( $ dataModel = array ( ) , $ objectType = "object" ) { $ this -> propertyModel = $ dataModel ; $ this -> setObjectType ( $ objectType ) ; return $ this ; } | Creates a completely new data model . Any Properties not explicitly described for this object will be ignored |
18,302 | final public function defineValueGroup ( $ valueGroup = NULL ) { $ this -> valueGroup = ! empty ( $ valueGroup ) ? trim ( $ valueGroup ) . "_" : NULL ; if ( ! empty ( $ valueGroup ) ) { return $ this -> setObjectType ( trim ( $ valueGroup ) ) ; } } | Defines a sub table for value data ; |
18,303 | public function IP2City ( $ ip ) { $ baidu_IP_url = 'http://api.map.baidu.com/location/ip?ak=bsa3LH1GT1jhOep5N7Uz950xtTQWvp9I&ip=' . $ ip . '&coor=bd09ll' ; $ client = new Client ( ) ; $ json = $ client -> get ( $ baidu_IP_url ) -> getBody ( ) ; return json_decode ( $ json , true ) ; } | IP to City |
18,304 | public function oneToMany ( $ id , $ name , $ img , $ gender ) { $ ids = explode ( ',' , $ id ) ; $ names = explode ( ',' , $ name ) ; $ imgs = explode ( ',' , $ img ) ; $ genders = explode ( ',' , $ gender ) ; for ( $ i = 0 ; $ i < count ( $ names ) ; $ i ++ ) { $ male = "" ; if ( $ genders [ $ i ] == 1 ) $ male = " class=\"shop-staff-male\" " ; echo "<a href=\"/staff/show/" . $ ids [ $ i ] . "\"" . $ male . ">" . $ names [ $ i ] . "</a>" ; } } | 1 to many |
18,305 | public function getConfigList ( $ list ) { $ records = Conf :: where ( 'config.list' , $ list ) -> leftJoin ( 'config as p' , 'config.parent_id' , '=' , 'p.id' ) -> orderBy ( 'config.parent_id' ) -> select ( 'config.id' , 'config.parent_id' , 'config.text' , 'p.text as pre_text' ) -> get ( ) ; $ out = [ ] ; $ parent_id = [ ] ; if ( ! count ( $ records ) ) return $ out ; foreach ( $ records as $ row ) { $ mix = $ row -> pre_text == '' || $ row -> pre_text == null ? $ row -> text : $ row -> pre_text . ' : ' . $ row -> text ; $ out = array_add ( $ out , $ row -> id , $ mix ) ; if ( ! in_array ( $ row -> parent_id , $ parent_id ) ) array_push ( $ parent_id , $ row -> parent_id ) ; } foreach ( $ out as $ key => $ value ) { if ( in_array ( $ key , $ parent_id ) ) array_forget ( $ out , $ key ) ; } return $ out ; } | get config items |
18,306 | public function removeForBillingToAllAddresses ( $ actorId ) { $ qb = $ this -> getQueryBuilder ( ) -> update ( ) -> set ( 'a.forBilling' , 0 ) -> where ( 'a.actor = :actor' ) -> setParameter ( 'actor' , $ actorId ) ; $ qb -> getQuery ( ) -> execute ( ) ; } | Remove the forBilling field to all addresses of the given actor |
18,307 | public function complete ( $ params ) { $ requestParams = $ this -> initRequestParams ( 'complete' , $ params ) ; $ this -> request ( 'complete' , $ requestParams ) ; return empty ( $ this -> error ) ; } | Complete authorization payment |
18,308 | public function refund ( $ params ) { $ requestParams = $ this -> initRequestParams ( 'refund' , $ params ) ; $ this -> request ( 'refund' , $ requestParams ) ; return empty ( $ this -> error ) ; } | Refund for complete or sale payments |
18,309 | public function callback ( array $ params = null ) { $ this -> cleanup ( ) ; if ( null === $ params ) { if ( ! empty ( $ _POST ) ) { $ params = $ _POST ; } } if ( empty ( $ params ) || empty ( $ params [ 'term' ] ) || empty ( $ params [ 'sign' ] ) || empty ( $ params [ 'type' ] ) ) { throw new GatewayException ( 'Input params is failure' ) ; } $ type = $ params [ 'type' ] ; if ( ! isset ( self :: $ customParams [ $ type ] ) ) { throw new GatewayException ( 'Undefined type value' ) ; } $ sign = $ this -> sign ( $ type , $ params ) ; if ( $ sign !== $ params [ 'sign' ] ) { throw new GatewayException ( 'Signature check fail' ) ; } $ this -> rawResponse = http_build_url ( $ params ) ; $ this -> response = ( object ) $ params ; if ( $ this -> response -> rc !== '00' ) { $ this -> error = array ( 'type' => self :: C_ERROR_PROCESSING , 'message' => $ this -> response -> message , ) ; } return empty ( $ this -> error ) ; } | Parse callback request |
18,310 | private function initRequestParams ( $ type , $ params ) { $ list = self :: $ customParams ; if ( ! isset ( $ list [ $ type ] ) ) { throw new GatewayException ( 'Undefined request type' ) ; } $ list = $ list [ $ type ] ; $ requestParams = array ( ) ; foreach ( $ list as $ key ) { if ( ! empty ( $ params [ $ key ] ) ) { $ requestParams [ $ key ] = trim ( $ params [ $ key ] ) ; } } foreach ( Config :: getAll ( ) as $ key => $ value ) { if ( in_array ( $ type , array ( 'complete' , 'refund' ) ) && in_array ( $ key , array ( 'callbackUrl' , 'callbackEmail' , 'shopUrl' ) ) ) { continue ; } $ requestParams [ $ key ] = $ value ; } $ requestParams = $ this -> convert ( $ requestParams ) ; if ( $ type !== 'callback' ) { $ requestParams [ 'time' ] = time ( ) ; } $ requestParams [ 'sign' ] = $ this -> sign ( $ type , $ requestParams ) ; return $ requestParams ; } | Generate params for http query |
18,311 | private function convert ( $ requestParams ) { $ convertedParams = array ( ) ; $ convertList = self :: $ convertRequestParams ; if ( isset ( $ convertList [ 'term' ] ) ) { $ convertList = array_flip ( $ convertList ) ; } foreach ( $ requestParams as $ key => $ value ) { if ( isset ( $ convertList [ $ key ] ) ) { $ convertedParams [ $ convertList [ $ key ] ] = $ value ; } } return $ convertedParams ; } | Reverse gateway and human names |
18,312 | protected function getErrorMessage ( $ nCode , $ strMessage = null ) { $ strReturn = 'Failure: ' ; if ( null !== $ this -> strResourcePath ) { $ strReturn = 'Path: "' . $ this -> strResourcePath . '" ' ; } $ strReturn .= 'Name: "' . $ this -> strResourceName . '"' ; $ strReturn .= ' Code: ' ; switch ( $ nCode ) { case self :: FAILURE_IO : $ strReturn .= 'General IO Error' ; break ; case self :: FAILURE_NOT_WRITEABLE : $ strReturn .= 'not writeable' ; break ; case self :: FAILURE_NOT_READABLE : $ strReturn .= 'not readable' ; break ; case self :: FAILURE_NOT_FOUND : $ strReturn .= 'not found' ; break ; default : $ strReturn .= ( string ) $ nCode ; break ; } if ( null !== $ strMessage ) { $ strReturn .= ' with message: "' . $ strMessage . '"' ; } return $ strReturn ; } | Builds and returns an error message for this exception . |
18,313 | public function submit ( LongLog $ longLog ) { $ curl = curl_init ( $ this -> getEndpointUrl ( ) . '/project/log' ) ; curl_setopt ( $ curl , CURLOPT_HTTPHEADER , [ 'Content-Type: application/json' , ] ) ; curl_setopt ( $ curl , CURLOPT_TIMEOUT , $ this -> getTimeout ( ) ) ; curl_setopt ( $ curl , CURLOPT_SSL_VERIFYHOST , false ) ; curl_setopt ( $ curl , CURLOPT_SSL_VERIFYPEER , false ) ; curl_setopt ( $ curl , CURLOPT_POST , true ) ; curl_setopt ( $ curl , CURLOPT_POSTFIELDS , json_encode ( $ this -> getRequestBody ( $ longLog ) ) ) ; curl_exec ( $ curl ) ; $ statusCode = ( int ) curl_getinfo ( $ curl , CURLINFO_HTTP_CODE ) ; curl_close ( $ curl ) ; return $ statusCode === 201 ; } | Send log to API |
18,314 | public function setProjectToken ( $ token ) { if ( ! $ token ) { throw new InvalidArgumentException ( 'Project token required' ) ; } elseif ( strlen ( $ token ) !== 32 ) { throw new InvalidArgumentException ( 'Project token must be 32 characters length' ) ; } $ this -> projectToken = $ token ; return $ this ; } | Set project token |
18,315 | public static function typed ( string $ type , iterable $ input = [ ] ) : Vector { $ resolver = Resolver :: typed ( $ type ) ; return new static ( $ input , $ resolver ) ; } | Vector named constructor . |
18,316 | public function loadConfig ( $ file ) { $ options = [ ] ; try { $ loader = new PhpConfig ( ) ; $ options = $ loader -> read ( $ file ) ; } catch ( \ Exception $ e ) { Log :: warning ( $ e -> getMessage ( ) ) ; } $ this -> config ( 'options' , $ options ) ; } | Load a config file containing editor options . |
18,317 | protected function _format ( $ varname , $ objectname , $ data ) { $ format = $ this -> $ varname ; $ replaceData = str_ireplace ( array_keys ( $ format ) , array_values ( $ format ) , $ data ) ; $ this -> $ objectname = $ this -> _slashes ( $ replaceData ) ; } | Protected Time Format |
18,318 | protected function classFile ( $ className ) { $ classFile = preg_replace ( '#[_\\\]#' , '/' , $ className ) . '.php' ; foreach ( $ this -> _paths as $ path ) { $ classPath = "$path/$classFile" ; if ( file_exists ( $ classPath ) ) { return $ classPath ; } } } | Returns the class file for a particular class name |
18,319 | public function loadClass ( $ className ) { if ( class_exists ( $ className , false ) || interface_exists ( $ className , false ) ) { return false ; } if ( $ classFile = $ this -> classFile ( $ className ) ) { require $ classFile ; return true ; } return false ; } | SPL autoload function loads a class file based on the class name . |
18,320 | public function includePaths ( $ path ) { $ paths = is_array ( $ path ) ? $ path : array ( $ path ) ; $ this -> _paths = array_merge ( $ paths , $ this -> _paths ) ; return $ this ; } | Prepends one or more items to the include path of the class loader and the php include path . |
18,321 | public function export ( ) { $ systemPaths = explode ( PATH_SEPARATOR , get_include_path ( ) ) ; set_include_path ( implode ( PATH_SEPARATOR , array_merge ( $ systemPaths , $ this -> _paths ) ) ) ; return $ this ; } | Exports the classloader path into the PHP system include path |
18,322 | protected function getValue ( ) { if ( ! $ this -> trigger ( CachePool :: EVENT_GET_BEFORE ) ) { $ this -> setHit ( false ) ; return null ; } $ this -> strval = $ this -> pool -> getDriver ( ) -> get ( $ this -> key ) ; if ( ! $ this -> trigger ( CachePool :: EVENT_GET_AFTER ) ) { $ this -> setHit ( false ) ; $ this -> set ( null ) ; } return $ this -> postGetValue ( ) ; } | Get value from the cache pool |
18,323 | protected function hasHit ( ) { if ( ! $ this -> trigger ( CachePool :: EVENT_HAS_BEFORE ) ) { return $ this -> setHit ( false ) ; } $ meta = $ this -> pool -> getDriver ( ) -> has ( $ this -> key ) ; if ( isset ( $ meta [ 'expire' ] ) ) { $ this -> expire = $ meta [ 'expire' ] ; } else { return $ this -> setHit ( false ) ; } if ( ! $ this -> trigger ( CachePool :: EVENT_HAS_AFTER ) ) { return $ this -> setHit ( false ) ; } return $ this -> setHit ( true ) ; } | Get hit status from driver |
18,324 | protected function getPlaceHolders ( $ message ) { if ( false === strpos ( $ message , '{' ) ) { return [ ] ; } $ matches = [ ] ; $ pattern = '~\{([^\}]+)\}~' ; if ( preg_match_all ( $ pattern , $ message , $ matches ) ) { return array_combine ( $ matches [ 1 ] , $ matches [ 0 ] ) ; } return [ ] ; } | Get placeholders in array |
18,325 | protected function replaceWith ( $ name , $ placeholder , array & $ context ) { if ( isset ( $ context [ $ name ] ) ) { return $ this -> getString ( $ context [ $ name ] ) ; } $ first = explode ( '.' , $ name ) [ 0 ] ; if ( false !== strpos ( $ name , '.' ) && isset ( $ context [ $ first ] ) ) { return $ this -> getSubPart ( $ name , $ placeholder , $ context [ $ first ] ) ; } return $ placeholder ; } | Replace with values from the context array |
18,326 | protected function getObjectString ( $ object ) { if ( $ object instanceof \ Exception ) { return 'EXCEPTION: ' . $ object -> getMessage ( ) ; } elseif ( method_exists ( $ object , '__toString' ) ) { return ( string ) $ object ; } else { return 'OBJECT: ' . get_class ( $ object ) ; } } | Get string representation of an object |
18,327 | protected function getSubPart ( $ name , $ placeholder , $ data ) { list ( , $ second ) = explode ( '.' , $ name , 2 ) ; $ arr = ( array ) $ data ; if ( isset ( $ arr [ $ second ] ) ) { return $ arr [ $ second ] ; } return $ placeholder ; } | Get user . name type of result only support 2 level |
18,328 | public function getValueAttribute ( $ name , $ value = null ) { if ( strpos ( $ name , '[]' ) !== false ) { $ name = str_replace ( '[]' , '' , $ name ) ; } if ( $ this -> hasOldInput ( ) ) { return $ this -> getOldInput ( $ name ) ; } if ( $ this -> hasModelValue ( $ name ) ) { return $ this -> getModelValue ( $ name ) ; } return $ value ; } | Get value from an attribute . |
18,329 | public function wpEditor ( $ name , $ value = null , $ options = array ( ) ) { ob_start ( ) ; $ value = $ this -> getValueAttribute ( $ name , $ value ) ; $ value = $ this -> html -> decode ( $ value ) ; wp_editor ( $ value , $ name , $ options = array ( ) ) ; $ wpEditor = ob_get_contents ( ) ; ob_end_clean ( ) ; return $ wpEditor ; } | Create a WordPress Editor . |
18,330 | public function radio ( $ name , $ value = null , $ checked = null , $ options = array ( ) ) { if ( is_null ( $ value ) ) { $ value = $ name ; } return $ this -> checkable ( 'radio' , $ name , $ value , $ checked , $ options ) ; } | Create a radio button input field . |
18,331 | protected function checkable ( $ type , $ name , $ value , $ checked , $ options ) { $ checked = $ this -> getCheckedState ( $ type , $ name , $ value , $ checked ) ; if ( $ checked ) { $ options [ 'checked' ] = 'checked' ; } return $ this -> input ( $ type , $ name , $ value , $ options ) ; } | Create a checkable input field . |
18,332 | public function hook ( ) { wp_enqueue_script ( 'jquery' ) ; add_action ( 'wp_head' , array ( $ this , 'printToken' ) ) ; add_action ( 'admin_head' , array ( $ this , 'printToken' ) ) ; add_action ( 'wp_footer' , array ( $ this , 'printAjaxHeader' ) ) ; add_action ( 'admin_footer' , array ( $ this , 'printAjaxHeader' ) ) ; } | Hook required script to WordPress . |
18,333 | public function post ( Request $ request ) { $ email = Arr :: get ( $ this -> getContentAsArray ( $ request ) , 'email' ) ; $ user = $ this -> userService -> findByEmail ( $ email ) ; if ( ! $ user ) { return $ this -> createNotFoundResponse ( ) ; } $ token = $ this -> userService -> findTokenBy ( [ 'user_id' => $ user -> getId ( ) , 'token_type_id' => TokenEntity :: TYPE_RESET_PASSWORD , [ 'expires' , '>' , time ( ) + 5 * 60 ] , ] ) ; if ( ! $ token ) { $ token = $ this -> userService -> createUserToken ( [ 'user_id' => $ user -> getId ( ) , 'token_type_id' => TokenEntity :: TYPE_RESET_PASSWORD , 'expires' => strtotime ( '+1 day' , time ( ) ) , ] ) ; } $ this -> resetPasswordView -> setUserToken ( $ token ) ; $ email = $ this -> emailService -> createFromArray ( [ 'recipient_email' => $ user -> getEmail ( ) , 'subject' => 'Reset Your Password' , 'message' => ( string ) $ this -> resetPasswordView , ] ) ; $ this -> emailService -> enqueueSendEmailJob ( $ email ) ; return $ this -> create204Response ( 204 , '' ) ; } | Send reset password email |
18,334 | public function put ( Request $ request ) { $ token = Arr :: get ( $ this -> getContentAsArray ( $ request ) , 'token' ) ; $ token = $ this -> userService -> findTokenBy ( [ 'token' => $ token , 'token_type_id' => TokenEntity :: TYPE_RESET_PASSWORD , ] ) ; if ( ! $ token ) { return $ this -> createNotFoundResponse ( ) ; } if ( $ token -> getExpires ( ) < time ( ) ) { return $ this -> createNotFoundResponse ( ) ; } $ user = $ this -> userService -> findById ( $ token -> getUserId ( ) ) ; if ( ! $ user ) { return $ this -> createNotFoundResponse ( ) ; } $ password = Arr :: get ( $ this -> getContentAsArray ( $ request ) , 'password' ) ; if ( ! $ password ) { return $ this -> createErrorResponse ( [ 'password' => [ 'EMPTY' ] ] , 422 ) ; } $ this -> userService -> resetPassword ( $ user , $ password ) ; $ this -> userService -> deleteToken ( $ token ) ; return $ this -> userArrayWithoutPassword ( $ user ) ; } | Reset password using token and new password |
18,335 | public function initFeaturedSkills ( $ overrideExisting = true ) { if ( null !== $ this -> collFeaturedSkills && ! $ overrideExisting ) { return ; } $ this -> collFeaturedSkills = new ObjectCollection ( ) ; $ this -> collFeaturedSkills -> setModel ( '\gossi\trixionary\model\Skill' ) ; } | Initializes the collFeaturedSkills collection . |
18,336 | public function getFeaturedSkillsJoinMultipleOf ( Criteria $ criteria = null , ConnectionInterface $ con = null , $ joinBehavior = Criteria :: LEFT_JOIN ) { $ query = ChildSkillQuery :: create ( null , $ criteria ) ; $ query -> joinWith ( 'MultipleOf' , $ joinBehavior ) ; return $ this -> getFeaturedSkills ( $ query , $ con ) ; } | If this collection has already been initialized with an identical criteria it returns the collection . Otherwise if this Picture is new it will return an empty collection ; or if this Picture has previously been saved it will retrieve related FeaturedSkills from storage . |
18,337 | private function wrapEntry ( $ entry , $ fileMimeType ) { $ wrappedEntry = "--{$this->_boundaryString}\r\n" ; $ wrappedEntry .= "Content-Type: application/atom+xml\r\n\r\n" ; $ wrappedEntry .= $ entry ; $ wrappedEntry .= "\r\n--{$this->_boundaryString}\r\n" ; $ wrappedEntry .= "Content-Type: $fileMimeType\r\n\r\n" ; return new Zend_Gdata_MimeBodyString ( $ wrappedEntry ) ; } | Sandwiches the entry body into a MIME message |
18,338 | public function read ( $ bytesRequested ) { if ( $ this -> _currentPart >= count ( $ this -> _parts ) ) { return FALSE ; } $ activePart = $ this -> _parts [ $ this -> _currentPart ] ; $ buffer = $ activePart -> read ( $ bytesRequested ) ; while ( strlen ( $ buffer ) < $ bytesRequested ) { $ this -> _currentPart += 1 ; $ nextBuffer = $ this -> read ( $ bytesRequested - strlen ( $ buffer ) ) ; if ( $ nextBuffer === FALSE ) { break ; } $ buffer .= $ nextBuffer ; } return $ buffer ; } | Read a specific chunk of the the MIME multipart message . |
18,339 | public function validate ( $ subject ) : bool { $ propertyNames = \ array_keys ( $ subject ) ; foreach ( $ propertyNames as $ propertyName ) { $ nodeValidator = new NodeValidator ( $ this -> schema [ 'propertyNames' ] , $ this -> rootSchema ) ; if ( ! $ nodeValidator -> validate ( $ propertyName ) ) { return false ; } } return true ; } | Validates subject against propertyNames |
18,340 | public function execute ( $ command ) { $ commandClass = get_class ( $ command ) ; $ mappings = $ this -> getMappings ( ) ; $ this -> checkIfCommandExistsInMappings ( $ commandClass , $ mappings ) ; $ handlerClass = array_get ( $ mappings , $ commandClass ) ; try { return $ this -> getContainer ( ) -> make ( $ handlerClass ) -> handle ( $ command ) ; } catch ( ReflectionException $ e ) { throw new CommandNotInstantiableException ( $ handlerClass . ' is not instantiable.' ) ; } } | Dispatch a command on the dispatcher . |
18,341 | public function get ( string $ route , $ handler ) : Route { return $ this -> createRoute ( Method :: GET , $ route , $ handler ) ; } | Add route matched with GET method . Shortcut for createRoute function with preset GET method . |
18,342 | public function post ( string $ route , $ handler ) : Route { return $ this -> createRoute ( Method :: POST , $ route , $ handler ) ; } | Add route matched with POST method . Shortcut for createRoute function with preset POST method . |
18,343 | public function delete ( string $ route , $ handler ) : Route { return $ this -> createRoute ( Method :: DELETE , $ route , $ handler ) ; } | Add route matched with DELETE method . Shortcut for createRoute function with preset DELETE method . |
18,344 | public function put ( string $ route , $ handler ) : Route { return $ this -> createRoute ( Method :: PUT , $ route , $ handler ) ; } | Add route matched with PUT method . Shortcut for createRoute function with preset PUT method . |
18,345 | public function any ( string $ route , $ handler ) : Route { return $ this -> createRoute ( Method :: ANY , $ route , $ handler ) ; } | Add route which will be matched to any method . Shortcut for createRoute function with preset ANY method . |
18,346 | public function loadPreference ( $ name , $ index = null , $ includeExpired = false ) { foreach ( $ this -> getPreferences ( ) as $ pref ) { if ( ( $ pref -> getName ( ) == $ name ) && ( $ pref -> getIx ( ) === $ index ) ) { if ( $ includeExpired || ! $ pref -> getExpiresAt ( ) || ( $ pref -> getExpiresAt ( ) > new \ DateTime ( ) ) ) return $ pref ; return false ; } } return false ; } | Return the entity object of the named preference |
18,347 | public function hasPreference ( $ name , $ index = null , $ includeExpired = false ) { return $ this -> getPreference ( $ name , $ index , $ includeExpired ) ; } | Does the named preference exist or not? |
18,348 | public function getPreference ( $ name , $ index = null , $ includeExpired = false ) { $ pref = $ this -> loadPreference ( $ name , $ index , $ includeExpired ) ; if ( ! $ pref ) return false ; return $ pref -> getValue ( ) ; } | Get the named preference s VALUE |
18,349 | public function setPreference ( $ name , $ value , $ expires = null , $ index = null ) { $ pref = $ this -> loadPreference ( $ name , $ index ) ; if ( is_int ( $ expires ) ) $ expires = new \ DateTime ( date ( 'Y-m-d H:i:s' , $ expires ) ) ; elseif ( is_string ( $ expires ) ) $ expires = new \ DateTime ( $ expires ) ; if ( $ pref ) { $ pref -> setValue ( $ value ) ; $ pref -> setExpiresAt ( $ expires ) ; $ pref -> setIx ( $ index ) ; return $ this ; } $ pref = $ this -> _createPreferenceEntity ( $ this ) ; $ pref -> setName ( $ name ) ; $ pref -> setValue ( $ value ) ; $ pref -> setCreatedAt ( new \ DateTime ( ) ) ; $ pref -> setExpiresAt ( $ expires ) ; $ pref -> setIx ( $ index ) ; \ D2EM :: persist ( $ pref ) ; return $ this ; } | Set or update a preference |
18,350 | public function addIndexedPreference ( $ name , $ value , $ expires = null , $ max = 0 ) { $ highest = - 1 ; $ count = 0 ; foreach ( $ this -> getPreferences ( ) as $ pref ) { if ( $ pref -> getName ( ) == $ name ) { $ count ++ ; if ( $ pref -> getIx ( ) > $ highest ) $ highest = $ pref -> getIx ( ) ; } } if ( $ max && ( $ count >= $ max ) ) throw new IndexLimitException ( 'Requested maximum number of indexed preferences reached' ) ; if ( is_array ( $ value ) ) { foreach ( $ value as $ v ) $ this -> setPreference ( $ name , $ value , $ expires , ++ $ highest ) ; } else { $ this -> setPreference ( $ name , $ value , $ expires , ++ $ highest ) ; } return $ this ; } | Add an indexed preference |
18,351 | public function cleanExpiredPreferences ( $ asOf = null , $ name = null ) { $ count = 0 ; if ( $ asOf === null ) $ asOf = new \ DateTime ( ) ; elseif ( is_int ( $ asOf ) ) $ asOf = new \ DateTime ( date ( 'Y-m-d H:i:s' , $ asOf ) ) ; elseif ( is_string ( $ asOf ) ) $ asOf = new \ DateTime ( $ asOf ) ; foreach ( $ this -> getPreferences ( ) as $ pref ) { if ( $ name && ( $ pref -> getName ( ) != $ name ) ) continue ; if ( $ pref -> getExpiresAt ( ) && ( $ pref -> getExpiresAt ( ) < $ asOf ) ) { $ count ++ ; $ this -> getPreferences ( ) -> removeElement ( $ pref ) ; \ D2EM :: remove ( $ pref ) ; } } return $ count ; } | Clean expired preferences |
18,352 | public function deletePreference ( $ name , $ index = null ) { $ count = 0 ; foreach ( $ this -> getPreferences ( ) as $ pref ) { if ( ( $ pref -> getName ( ) == $ name ) && ( ( $ index === null ) || ( $ pref -> getIx ( ) == $ index ) ) ) { $ count ++ ; $ this -> getPreferences ( ) -> removeElement ( $ pref ) ; \ D2EM :: remove ( $ pref ) ; } } return $ count ; } | Delete the named preference |
18,353 | public function expungePreferences ( ) { return \ D2EM :: createQuery ( 'delete \\Entities\\' . $ this -> _getPreferenceClassName ( ) . ' up where up.' . $ this -> _getShortClassname ( ) . ' = ?1' ) -> setParameter ( 1 , $ this ) -> execute ( ) ; } | Deletes all preferences . |
18,354 | public function getIndexedPreference ( $ name , $ withIndex = false , $ ignoreExpired = true ) { $ values = [ ] ; foreach ( $ this -> getPreferences ( ) as $ pref ) { if ( $ pref -> getName ( ) == $ name ) { if ( $ ignoreExpired && $ pref -> getExpiresAt ( ) && ( $ pref -> getExpiresAt ( ) < new \ DateTime ( ) ) ) continue ; if ( $ withIndex ) $ values [ $ pref -> getIx ( ) ] = [ 'index' => $ pref -> getIx ( ) , 'value' => $ pref -> getValue ( ) ] ; else $ values [ $ pref -> getIx ( ) ] = $ pref -> getValue ( ) ; } } ksort ( $ values , SORT_NUMERIC ) ; return $ values ; } | Get indexed preferences as an array |
18,355 | public function getAssocPreference ( $ name , $ index = null , $ ignoreExpired = true ) { $ values = [ ] ; foreach ( $ this -> getPreferences ( ) as $ pref ) { if ( strpos ( $ pref -> getName ( ) , $ name ) === 0 ) { if ( ( $ index === null ) || ( $ pref -> getIx ( ) == $ index ) ) { if ( ! $ ignoreExpired && $ pref -> getExpiresAt ( ) && ( $ pref -> getExpiresAt ( ) < new \ DateTime ( ) ) ) continue ; if ( strpos ( $ pref -> getName ( ) , '.' ) !== false ) $ key = substr ( $ pref -> getName ( ) , strlen ( $ name ) + 1 ) ; if ( $ key ) { $ key = $ pref -> getIx ( ) . '.' . $ key ; $ values = $ this -> _processKey ( $ values , $ key , $ pref -> getValue ( ) ) ; } else { $ values [ $ pref -> getIx ( ) ] = $ pref -> getValue ( ) ; } } } } if ( $ values === [ ] ) return false ; return $ values ; } | Get associative preferences as an array . |
18,356 | public function name ( $ data ) { if ( is_object ( $ data ) && isset ( $ data -> type ) ) { return $ data -> value ; } if ( $ data === '*' ) { return '*' ; } if ( is_array ( $ data ) ) { foreach ( $ data as $ i => $ dataItem ) { $ data [ $ i ] = $ this -> name ( $ dataItem ) ; } return $ data ; } return ( string ) $ data ; } | Imitation of DboSource method . |
18,357 | public function getLog ( $ sorted = false , $ clear = true ) { if ( $ sorted ) { $ log = sortByKey ( $ this -> _requestsLog , 'took' , 'desc' , SORT_NUMERIC ) ; } else { $ log = $ this -> _requestsLog ; } if ( $ clear ) { $ this -> _requestsLog = array ( ) ; } return array ( 'log' => $ log , 'count' => count ( $ log ) , 'time' => array_sum ( Hash :: extract ( $ log , '{n}.took' ) ) ) ; } | Get the query log as an array . |
18,358 | protected function _registerLog ( Model $ model , & $ queryData , $ took , $ numRows ) { if ( ! Configure :: read ( ) ) { return ; } $ this -> _requestsLog [ ] = array ( 'query' => $ this -> _pseudoSelect ( $ model , $ queryData ) , 'error' => '' , 'affected' => 0 , 'numRows' => $ numRows , 'took' => round ( $ took , 3 ) ) ; } | Generate a log registry |
18,359 | protected function _pseudoSelect ( Model $ model , & $ queryData ) { $ out = '(symbolic) SELECT ' ; if ( empty ( $ queryData [ 'fields' ] ) ) { $ out .= '*' ; } elseif ( $ queryData [ 'fields' ] ) { $ out .= 'COUNT(*)' ; } else { $ out .= implode ( ', ' , $ queryData [ 'fields' ] ) ; } $ out .= ' FROM ' . $ model -> alias ; if ( ! empty ( $ queryData [ 'conditions' ] ) ) { $ out .= ' WHERE' ; foreach ( $ queryData [ 'conditions' ] as $ id => $ condition ) { if ( empty ( $ condition ) ) { continue ; } if ( is_array ( $ condition ) ) { $ condition = '(' . implode ( ', ' , $ condition ) . ')' ; if ( strpos ( $ id , ' ' ) === false ) { $ id .= ' IN' ; } } if ( is_string ( $ id ) ) { if ( strpos ( $ id , ' ' ) !== false ) { $ condition = $ id . ' ' . $ condition ; } else { $ condition = $ id . ' = ' . $ condition ; } } if ( preg_match ( '/^(\w+\.)?\w+ /' , $ condition , $ matches ) ) { if ( ! empty ( $ matches [ 1 ] ) && substr ( $ matches [ 1 ] , 0 , - 1 ) !== $ model -> alias ) { continue ; } } $ out .= ' (' . $ condition . ') &&' ; } $ out = substr ( $ out , 0 , - 3 ) ; } if ( ! empty ( $ queryData [ 'order' ] [ 0 ] ) ) { $ out .= ' ORDER BY ' . implode ( ', ' , $ queryData [ 'order' ] ) ; } if ( ! empty ( $ queryData [ 'limit' ] ) ) { $ out .= ' LIMIT ' . ( ( $ queryData [ 'page' ] - 1 ) * $ queryData [ 'limit' ] ) . ', ' . $ queryData [ 'limit' ] ; } return $ out ; } | Generate a pseudo select to log |
18,360 | public function addConnection ( array $ config , $ name = 'default' ) { $ this -> connectionResolver -> addConnection ( $ this -> make ( $ config ) , $ name ) ; return $ this ; } | Register a connection . |
18,361 | protected function createSingleConnection ( array $ config ) { $ connector = $ this -> createConnector ( $ config ) -> connect ( $ config ) ; return $ this -> createConnection ( $ connector , $ config ) ; } | Create a single API connection instance . |
18,362 | public function handle ( $ msg ) { if ( ! $ msg instanceof JobMessage ) { if ( $ this -> logger ) { $ this -> logger -> info ( 'No more message' ) ; } return false ; } return $ this -> handleMsg ( $ msg ) ; } | Handle msg after its execution . If we need to create a new msg to continue execution or stop here |
18,363 | public function addSkills ( $ id , $ data ) { $ model = $ this -> get ( $ id ) ; if ( $ model === null ) { return new NotFound ( [ 'message' => 'Reference not found.' ] ) ; } try { $ this -> doAddSkills ( $ model , $ data ) ; } catch ( ErrorsException $ e ) { return new NotValid ( [ 'errors' => $ e -> getErrors ( ) ] ) ; } $ this -> dispatch ( ReferenceEvent :: PRE_SKILLS_ADD , $ model , $ data ) ; $ this -> dispatch ( ReferenceEvent :: PRE_SAVE , $ model , $ data ) ; $ rows = $ model -> save ( ) ; $ this -> dispatch ( ReferenceEvent :: POST_SKILLS_ADD , $ model , $ data ) ; $ this -> dispatch ( ReferenceEvent :: POST_SAVE , $ model , $ data ) ; if ( $ rows > 0 ) { return Updated ( [ 'model' => $ model ] ) ; } return NotUpdated ( [ 'model' => $ model ] ) ; } | Adds Skills to Reference |
18,364 | public function addVideos ( $ id , $ data ) { $ model = $ this -> get ( $ id ) ; if ( $ model === null ) { return new NotFound ( [ 'message' => 'Reference not found.' ] ) ; } try { $ this -> doAddVideos ( $ model , $ data ) ; } catch ( ErrorsException $ e ) { return new NotValid ( [ 'errors' => $ e -> getErrors ( ) ] ) ; } $ this -> dispatch ( ReferenceEvent :: PRE_VIDEOS_ADD , $ model , $ data ) ; $ this -> dispatch ( ReferenceEvent :: PRE_SAVE , $ model , $ data ) ; $ rows = $ model -> save ( ) ; $ this -> dispatch ( ReferenceEvent :: POST_VIDEOS_ADD , $ model , $ data ) ; $ this -> dispatch ( ReferenceEvent :: POST_SAVE , $ model , $ data ) ; if ( $ rows > 0 ) { return Updated ( [ 'model' => $ model ] ) ; } return NotUpdated ( [ 'model' => $ model ] ) ; } | Adds Videos to Reference |
18,365 | public function updateSkills ( $ id , $ data ) { $ model = $ this -> get ( $ id ) ; if ( $ model === null ) { return new NotFound ( [ 'message' => 'Reference not found.' ] ) ; } try { $ this -> doUpdateSkills ( $ model , $ data ) ; } catch ( ErrorsException $ e ) { return new NotValid ( [ 'errors' => $ e -> getErrors ( ) ] ) ; } $ this -> dispatch ( ReferenceEvent :: PRE_SKILLS_UPDATE , $ model , $ data ) ; $ this -> dispatch ( ReferenceEvent :: PRE_SAVE , $ model , $ data ) ; $ rows = $ model -> save ( ) ; $ this -> dispatch ( ReferenceEvent :: POST_SKILLS_UPDATE , $ model , $ data ) ; $ this -> dispatch ( ReferenceEvent :: POST_SAVE , $ model , $ data ) ; if ( $ rows > 0 ) { return Updated ( [ 'model' => $ model ] ) ; } return NotUpdated ( [ 'model' => $ model ] ) ; } | Updates Skills on Reference |
18,366 | public function updateVideos ( $ id , $ data ) { $ model = $ this -> get ( $ id ) ; if ( $ model === null ) { return new NotFound ( [ 'message' => 'Reference not found.' ] ) ; } try { $ this -> doUpdateVideos ( $ model , $ data ) ; } catch ( ErrorsException $ e ) { return new NotValid ( [ 'errors' => $ e -> getErrors ( ) ] ) ; } $ this -> dispatch ( ReferenceEvent :: PRE_VIDEOS_UPDATE , $ model , $ data ) ; $ this -> dispatch ( ReferenceEvent :: PRE_SAVE , $ model , $ data ) ; $ rows = $ model -> save ( ) ; $ this -> dispatch ( ReferenceEvent :: POST_VIDEOS_UPDATE , $ model , $ data ) ; $ this -> dispatch ( ReferenceEvent :: POST_SAVE , $ model , $ data ) ; if ( $ rows > 0 ) { return Updated ( [ 'model' => $ model ] ) ; } return NotUpdated ( [ 'model' => $ model ] ) ; } | Updates Videos on Reference |
18,367 | protected function doAddVideos ( Reference $ model , $ data ) { $ errors = [ ] ; foreach ( $ data as $ entry ) { if ( ! isset ( $ entry [ 'id' ] ) ) { $ errors [ ] = 'Missing id for Video' ; } else { $ related = VideoQuery :: create ( ) -> findOneById ( $ entry [ 'id' ] ) ; $ model -> addVideo ( $ related ) ; } } if ( count ( $ errors ) > 0 ) { return new ErrorsException ( $ errors ) ; } } | Interal mechanism to add Videos to Reference |
18,368 | protected function doUpdateSkills ( Reference $ model , $ data ) { SkillReferenceQuery :: create ( ) -> filterByReference ( $ model ) -> delete ( ) ; $ errors = [ ] ; foreach ( $ data as $ entry ) { if ( ! isset ( $ entry [ 'id' ] ) ) { $ errors [ ] = 'Missing id for Skill' ; } else { $ related = SkillQuery :: create ( ) -> findOneById ( $ entry [ 'id' ] ) ; $ model -> addSkill ( $ related ) ; } } if ( count ( $ errors ) > 0 ) { throw new ErrorsException ( $ errors ) ; } } | Internal update mechanism of Skills on Reference |
18,369 | protected function doUpdateVideos ( Reference $ model , $ data ) { VideoQuery :: create ( ) -> filterByReference ( $ model ) -> delete ( ) ; $ errors = [ ] ; foreach ( $ data as $ entry ) { if ( ! isset ( $ entry [ 'id' ] ) ) { $ errors [ ] = 'Missing id for Video' ; } else { $ related = VideoQuery :: create ( ) -> findOneById ( $ entry [ 'id' ] ) ; $ model -> addVideo ( $ related ) ; } } if ( count ( $ errors ) > 0 ) { throw new ErrorsException ( $ errors ) ; } } | Internal update mechanism of Videos on Reference |
18,370 | public static function get ( $ key ) { $ exists = ( isset ( $ _SESSION [ $ key ] ) ) ? true : false ; if ( ! $ exists ) return $ exists ; else return $ _SESSION [ $ key ] ; } | This method returns a session data by key |
18,371 | public function setAccountNumber ( $ accountNumber ) { $ this -> accountNumber = ( string ) $ accountNumber ; $ this -> lastFour = substr ( ( string ) $ accountNumber , - 4 ) ; } | Set Account Number |
18,372 | protected function generateGetAll ( ResourceConfiguration $ config ) { $ that = $ this ; $ this -> slim -> get ( $ this -> baseRoute ( $ config ) , function ( ) use ( $ that ) { $ that -> executeRoute ( 'index' , func_get_args ( ) ) ; } ) ; } | Generates the index route . |
18,373 | protected function generateGetSingle ( ResourceConfiguration $ config ) { $ that = $ this ; $ this -> slim -> get ( "{$this->baseRoute($config)}/:id" , function ( ) use ( $ that ) { $ that -> executeRoute ( 'show' , func_get_args ( ) ) ; } ) ; } | Generates the show route . |
18,374 | protected function generatePost ( ResourceConfiguration $ config ) { $ that = $ this ; $ this -> slim -> post ( $ this -> baseRoute ( $ config ) , function ( ) use ( $ that ) { $ that -> executeRoute ( 'create' , func_get_args ( ) ) ; } ) ; } | Generates the create route . |
18,375 | protected function generatePut ( ResourceConfiguration $ config ) { $ that = $ this ; $ this -> slim -> put ( "{$this->baseRoute($config)}/:id" , function ( ) use ( $ that ) { $ that -> executeRoute ( 'update' , func_get_args ( ) ) ; } ) ; } | Generates the update route . |
18,376 | protected function generateDelete ( ResourceConfiguration $ config ) { $ that = $ this ; $ this -> slim -> delete ( "{$this->baseRoute($config)}/:id" , function ( ) use ( $ that ) { $ that -> executeRoute ( 'delete' , func_get_args ( ) ) ; } ) ; } | Generates the delete route . |
18,377 | protected function parentRoutesFor ( ResourceConfiguration $ config ) { if ( $ config -> getParent ( ) ) { $ parentConfig = $ this -> configuration -> resourceConfigurationFor ( $ config -> getParent ( ) ) ; return $ this -> parentRoutesFor ( $ parentConfig ) . "/{$config->getParent()}/:{$config->getParent()}_id" ; } } | Gets the parents routes for a given child resource . |
18,378 | public function findAll ( ) { $ repos = array ( ) ; foreach ( $ this -> repository -> findAll ( ) as $ repo ) { $ this -> loadPackagistInfos ( $ repo ) ; $ repos [ ] = $ repo ; } return $ repos ; } | Find all repos |
18,379 | public function loadExtraInfos ( Repo $ repo ) { try { $ this -> scrutinizerLoader -> load ( $ repo ) ; $ this -> travisLoader -> load ( $ repo ) ; $ this -> versionEyeLoader -> load ( $ repo ) ; } catch ( \ Exception $ e ) { print_r ( $ e -> getMessage ( ) ) ; } } | Load infos from travis & scrutinizer |
18,380 | public function loadPackagistInfos ( Repo $ repo ) { try { $ this -> composerReader -> load ( $ repo -> getSlug ( ) ) ; if ( $ this -> composerReader -> has ( 'name' ) ) { $ repo -> setPackagistSlug ( $ this -> composerReader -> get ( 'name' ) ) ; } if ( $ this -> composerReader -> has ( 'authors' ) ) { $ repo -> setAuthors ( $ this -> composerReader -> get ( 'authors' ) ) ; } if ( $ this -> composerReader -> has ( 'require' ) ) { $ repo -> setDependencies ( $ this -> composerReader -> get ( 'require' ) ) ; } } catch ( \ Exception $ e ) { } } | Load packagist infos by reading composer json file |
18,381 | protected function loadRepo ( Repo $ repo = null ) { if ( null == $ repo ) { return null ; } $ this -> loadExtraInfos ( $ repo ) ; $ this -> loadPackagistInfos ( $ repo ) ; return $ repo ; } | Load repo infos |
18,382 | public function isExists ( Repo $ repo ) { $ anotherRepo = $ this -> findBySlug ( $ repo -> getSlug ( ) ) ; return ( $ anotherRepo != null && $ repo -> getId ( ) != $ anotherRepo -> getId ( ) ) ; } | Checks if slug exist |
18,383 | public static function isPossiblePathTraversalAttack ( $ path ) { $ virtualBase = '/' . md5 ( microtime ( true ) . '/' . mt_rand ( ) ) ; $ virtualPath = $ virtualBase . '/' . ltrim ( $ path , '/' ) ; return ! FileUtil :: isBasePath ( $ virtualPath , $ virtualBase ) ; } | Returns true if the given path will leave the root directory |
18,384 | public function setTitlePosition ( $ position ) { $ allowedValues = array ( "in" , "out" , "none" ) ; if ( ! in_array ( $ position , $ allowedValues ) ) { throw new \ Exception ( "Invalid position: " . $ position ) ; } $ this -> m_options [ 'titlePosition' ] = $ position ; } | Set the position of the title . |
18,385 | private function toArray ( $ obj ) { $ arr = array ( ) ; if ( is_array ( $ obj ) ) { foreach ( $ obj as $ value ) { $ arr [ ] = $ this -> toArray ( $ value ) ; } } else if ( is_object ( $ obj ) ) { $ arObj = ( array ) $ obj ; foreach ( $ arObj as $ key => $ value ) { $ attribute = str_replace ( get_class ( $ obj ) , "" , $ key ) ; if ( is_object ( $ value ) || is_array ( $ value ) ) { $ value = $ this -> toArray ( $ value ) ; } else { $ arr [ $ attribute ] = $ this -> utf8_encode_all ( $ value ) ; } } } else { $ arr = $ this -> utf8_encode_all ( $ obj ) ; } return $ arr ; } | Convierte un objeto a notacion json . |
18,386 | public function index ( ViewListener $ listener ) { $ form = $ this -> presenter -> form ( ) ; return $ listener -> show ( compact ( 'form' ) ) ; } | shows module tester default index action |
18,387 | public function prepare ( array $ data = null ) { $ response = [ ] ; $ code = 200 ; try { if ( ! isset ( $ data [ 'module' ] ) or empty ( $ data [ 'module' ] ) ) { throw new Exception \ InvalidArgumentException ( 'Unable to start tests. No module has been selected.' ) ; } $ selected = array_keys ( $ data [ 'module' ] ) ; $ tests = app ( 'antares.memory' ) -> make ( 'tests' ) -> all ( ) ; $ active = app ( 'antares.memory' ) -> get ( "extensions.active" ) ; foreach ( $ tests as $ name => $ test ) { if ( in_array ( $ test [ 'id' ] , $ selected ) ) { $ fullName = isset ( $ active [ $ test [ 'component' ] ] ) ? $ active [ $ test [ 'component' ] ] [ 'full_name' ] : 'Foundation' ; $ response [ ] = [ 'cid' => $ test [ 'id' ] , 'message' => "Currently testing {$name} in {$fullName}." ] ; } } } catch ( \ Exception $ ex ) { Log :: warning ( $ ex ) ; $ code = 400 ; $ response [ ] = [ 'error' => $ ex -> getMessage ( ) ] ; } return Response :: json ( $ response , $ code ) ; } | build sepcification data before real test |
18,388 | public function run ( ProcessListener $ listener , array $ data ) { try { if ( empty ( $ data ) ) { throw new Exception \ InvalidArgumentException ( 'Invalid method arguments.' ) ; } $ validator = null ; $ values = null ; if ( isset ( $ data [ 'cid' ] ) ) { $ model = MemoryTests :: findOrNew ( $ data [ 'cid' ] ) ; $ params = unserialize ( $ model -> value ) ; $ validator = new $ params [ 'validator' ] ; $ values = ! empty ( $ params [ 'controls' ] ) ? $ params [ 'controls' ] : array_get ( $ params , 'data' ) ; } if ( isset ( $ data [ 'validator' ] ) ) { $ validator = new $ data [ 'validator' ] ; $ values = $ data ; } $ response = $ validator ( $ values ) -> getResponse ( ) ; $ return = view ( 'antares/tester::admin.partials._messages' ) -> with ( [ 'response' => $ response ] ) ; } catch ( \ Exception $ e ) { Log :: emergency ( $ e ) ; $ return = view ( 'antares/tester::admin.partials._error' ) -> with ( [ 'message' => $ e -> getMessage ( ) , 'code' => $ e -> getCode ( ) ] ) ; } return $ listener -> render ( $ return ) ; } | run validation of partial module configuration |
18,389 | public function setVector ( $ vector ) { if ( empty ( $ vector ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Cvss vector "%s" is not valid.' , $ vector ) ) ; } if ( ! preg_match ( '/^' . self :: $ vectorHead . '.*/mi' , $ vector ) ) { throw new \ InvalidArgumentException ( ( sprintf ( 'Cvss vector "%s" is not valid. Must start with "%s"' , $ vector , self :: $ vectorHead ) ) ) ; } $ this -> vectorInputs = self :: parseVector ( $ vector ) ; $ resolver = $ this -> getInputLevelConfiguration ( ) ; $ this -> vectorLevels = $ resolver -> resolve ( $ this -> vectorInputs ) ; $ this -> calculate ( ) ; } | Parse CVSS vector |
18,390 | protected function getSeverity ( $ score ) { foreach ( $ this -> severityRatingScale as $ level => $ options ) { if ( $ score >= $ options [ 'min_range' ] && $ score <= $ options [ 'max_range' ] ) { return $ level ; } } return null ; } | Get severity for the given score |
18,391 | public function getOverallScore ( ) { if ( $ this -> environmentalScore != $ this -> baseScore ) { return $ this -> environmentalScore ; } elseif ( $ this -> temporalScore != $ this -> baseScore ) { return $ this -> temporalScore ; } else { return $ this -> baseScore ; } } | Get overall score |
18,392 | public function getVector ( $ omitUndefined = true ) { $ metrics = [ ] ; foreach ( $ this -> vectorInputs as $ name => $ value ) { if ( $ value != 'X' || ! $ omitUndefined ) { $ metrics [ $ name ] = $ value ; } } return self :: buildVector ( $ metrics ) ; } | Get full vector |
18,393 | static function buildVector ( $ inputs ) { $ inputs = array_merge ( array ( 'CVSS' => self :: VERSION ) , $ inputs ) ; return implode ( self :: $ metricSeparator , array_map ( function ( $ k , $ v ) { return sprintf ( '%1$s%3$s%2$s' , strtoupper ( $ k ) , strtoupper ( $ v ) , self :: $ valueSeparator ) ; } , array_keys ( $ inputs ) , $ inputs ) ) ; } | Build CVSS vector for the given inputs |
18,394 | function Insert ( $ model ) { $ this -> OpenTransaction ( ) ; $ data = clone $ model ; $ table = $ this -> getTableName ( $ data ) ; if ( is_object ( $ data ) ) ModelState :: ModelTreatment ( $ data ) ; $ data = ( array ) $ data ; ksort ( $ data ) ; $ camposNomes = implode ( '`, `' , array_keys ( $ data ) ) ; $ camposValores = ':' . implode ( ', :' , array_keys ( $ data ) ) ; $ sth = $ this -> prepare ( "INSERT INTO $table (`$camposNomes`) VALUES ($camposValores)" ) ; foreach ( $ data as $ key => $ value ) { $ tipo = ( is_int ( $ value ) ) ? \ PDO :: PARAM_INT : \ PDO :: PARAM_STR ; $ sth -> bindValue ( ":$key" , $ value , $ tipo ) ; } try { $ sth -> execute ( ) ; } catch ( \ Exception $ e ) { echo $ e -> getMessage ( ) ; } $ primaryKey = ModelState :: GetPrimary ( $ model ) ; if ( ! empty ( $ primaryKey ) ) $ model -> $ primaryKey = $ this -> lastInsertId ( ) ; return $ this -> lastInsertId ( ) ; } | Insere dados no banco atraves de uma model mapeada |
18,395 | public function Update ( $ model , array $ campos = null ) { $ this -> OpenTransaction ( ) ; $ data = clone $ model ; if ( is_object ( $ data ) ) ModelState :: ModelTreatment ( $ data ) ; $ primaryKey = ModelState :: GetPrimary ( $ model ) ; if ( $ primaryKey == null ) throw new OwlException ( "Classe nao contem PK" ) ; $ table = $ this -> getTableName ( $ data ) ; $ data = ( array ) $ data ; $ novosDados = NULL ; if ( $ campos == null ) $ campos = array_keys ( $ data ) ; foreach ( $ campos as $ key ) { $ novosDados .= "`$key`=:$key," ; } $ novosDados = rtrim ( $ novosDados , ',' ) ; $ sth = $ this -> prepare ( "UPDATE $table SET $novosDados WHERE $primaryKey = '" . $ model -> $ primaryKey . "'" ) ; foreach ( $ campos as $ key ) { $ tipo = ( is_int ( $ model -> $ key ) ) ? \ PDO :: PARAM_INT : \ PDO :: PARAM_STR ; $ sth -> bindValue ( ":$key" , $ model -> $ key , $ tipo ) ; } try { $ sth -> execute ( ) ; $ model = $ this -> GetById ( $ table , $ model -> $ primaryKey ) ; } catch ( \ Exception $ e ) { echo $ e -> getMessage ( ) ; } } | Atualiza os dados no banco atraves de uma model mapeada |
18,396 | public function substr ( $ start , $ length = null ) { $ str = mb_substr ( $ this -> value , $ start , $ length ) ; return static :: make ( $ str ) ; } | Get substring from the current string |
18,397 | public function validate ( $ operation , $ model ) { $ model = is_array ( $ model ) ? $ model : $ model -> getAttributes ( ) ; $ rules = $ this -> model -> rules ( $ operation == 'update' ? array_keys ( $ model ) : null , $ operation ) ; $ rules = $ this -> interpolateValidationRules ( $ rules , $ model ) ; $ validator = Validator :: make ( $ model , $ rules ) ; $ messages = [ ] ; if ( $ validator -> fails ( ) ) { $ messages = $ validator -> messages ( ) -> all ( ) ; } foreach ( $ this -> validations as $ validationMethod ) { if ( $ message = $ this -> { $ validationMethod } ( $ model ) ) { $ messages [ ] = $ message ; } } if ( count ( $ messages ) ) { throw App :: make ( 'sedp-mis.base-repository.validationException' , $ messages ) ; } } | Validate model attributes before saving . Throw an exception when validation fails . |
18,398 | protected function interpolateValidationRules ( $ rules , $ model ) { foreach ( $ rules as & $ rule ) { $ attrs = last ( chars_within ( $ rule , [ '{' , '}' ] ) ) ; foreach ( $ attrs as $ attr ) { $ rule = str_replace ( '{' . $ attr . '}' , is_null ( $ model [ $ attr ] ) && $ attr == $ this -> model -> getKeyName ( ) ? 'NULL' : $ model [ $ attr ] , $ rule ) ; } } return $ rules ; } | Interpolate model attribute values on validation rules . |
18,399 | public function getAddress ( $ include_country = false ) { $ string = '' ; if ( $ v = $ this -> getAddressLine1 ( ) ) $ string .= $ v . ', ' ; if ( $ v = $ this -> getAddressLine2 ( ) ) $ string .= $ v . ', ' ; if ( $ v = $ this -> getAddressLine3 ( ) ) $ string .= $ v . ', ' ; $ string .= $ this -> getCityStateZip ( ) ; if ( $ include_country ) $ string .= $ this -> getCountryCode ( ) ; return $ string ; } | Get address string |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.