idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
44,200 | function delete_custom_field ( ) { global $ wpdb ; check_admin_referer ( 'delete_custom_field' ) ; if ( isset ( $ _GET [ 'custom_field_id' ] ) ) { $ id = ( int ) $ _GET [ 'custom_field_id' ] ; if ( is_int ( $ id ) ) { $ sql = $ wpdb -> prepare ( "DELETE FROM " . MF_TABLE_CUSTOM_FIELDS . " WHERE id = %d" , $ id ) ; $ wpdb -> query ( $ sql ) ; } } wp_safe_redirect ( add_query_arg ( 'field_deleted' , 'true' , wp_get_referer ( ) ) ) ; } | Delete Custom Field |
44,201 | protected function provideAPIRoutes ( ) { $ routes = Cache :: rememberForever ( 'provideAPIRoutes' , function ( ) { $ router = app ( Router :: class ) ; $ routes = [ ] ; foreach ( $ router -> getRoutes ( ) as $ collection ) { foreach ( $ collection -> getRoutes ( ) as $ route ) { $ temp = & $ routes ; if ( $ routeName = $ route -> getName ( ) ) { foreach ( explode ( '.' , $ routeName ) as $ key ) { $ temp = & $ temp [ $ key ] ; } $ temp = preg_replace ( '/{(\w+)}/' , ':$1' , $ route -> uri ( ) ) ; } } } return $ routes [ 'api' ] ; } ) ; JavaScript :: put ( [ 'api' => $ routes ] ) ; } | Provide all api routes as javascript variables . |
44,202 | public static function fromEnvironment ( ) : UriInterface { parse_str ( $ _SERVER [ 'QUERY_STRING' ] ?? '' , $ query ) ; $ uri = ( new static ( ) ) -> withScheme ( ( isset ( $ _SERVER [ 'HTTPS' ] ) === true && $ _SERVER [ 'HTTPS' ] !== 'off' ) ? 'https' : 'http' ) -> withHost ( $ _SERVER [ 'HTTP_HOST' ] ) -> withPort ( ( int ) $ _SERVER [ 'SERVER_PORT' ] ) -> withPath ( strtok ( $ _SERVER [ 'REQUEST_URI' ] , '?' ) ) -> withQuery ( $ query ) ; if ( array_key_exists ( 'PHP_AUTH_USER' , $ _SERVER ) === true ) { $ uri = $ uri -> withUser ( $ _SERVER [ 'PHP_AUTH_USER' ] ) ; } if ( array_key_exists ( 'PHP_AUTH_PW' , $ _SERVER ) === true ) { $ uri = $ uri -> withPass ( $ _SERVER [ 'PHP_AUTH_PW' ] ) ; } return $ uri ; } | Create URI from environment variables . |
44,203 | protected function analyzeResponseErrors ( ) { $ content = $ this -> content ; if ( $ content && property_exists ( $ content , 'errors' ) ) { $ this -> setErrors ( $ content , 'errors' ) ; } elseif ( $ content && property_exists ( $ content , 'ERROR' ) ) { $ this -> setError ( 'Unknown' , $ content -> ERROR ) ; } $ this -> throwExceptions ( ) ; } | Analyze errors from response |
44,204 | protected function setErrors ( $ response , $ key ) { foreach ( $ response -> { $ key } as $ error ) { $ this -> setError ( $ error -> code , $ error -> description ) ; } } | Set errors from response |
44,205 | public function setError ( $ code , $ description ) { $ error = new stdClass ; $ error -> code = $ code ; $ error -> description = $ description ; $ this -> errors [ ] = $ error ; } | Set a error |
44,206 | protected function throwExceptions ( ) { $ status = $ this -> getStatusCode ( ) ; switch ( $ status ) { case 400 : throw new ValidationException ( $ this ) ; break ; case 401 : throw new UnauthorizedException ( $ this ) ; break ; case 404 : throw new ResourceNotFoundException ( $ this ) ; break ; default : break ; } if ( $ status >= 400 && $ status < 500 ) { throw new ClientRequestException ( $ this , 'Whoops looks like something went wrong' ) ; } elseif ( $ status >= 500 ) { throw new ServerRequestException ( $ this ) ; } } | Throw request exceptions |
44,207 | public function getResults ( ) { $ key = $ this -> dataKey ; $ content = $ this -> content ; if ( is_object ( $ content ) && property_exists ( $ content , $ key ) ) { return new Collection ( $ content -> { $ key } ) ; } elseif ( is_array ( $ content ) ) { return new Collection ( $ content ) ; } return $ content ; } | Return response content |
44,208 | protected static function registerRelations ( ) { if ( ! static :: $ relations ) { $ supported = [ HasOne :: class => HasOneWrapper :: class , BelongsTo :: class => BelongsToWrapper :: class , BelongsToMany :: class => BelongsToManyWrapper :: class , HasMany :: class => HasManyWrapper :: class , ] ; static :: $ relations = Collection :: make ( [ ] ) ; foreach ( $ supported as $ rel => $ wrapperName ) { static :: $ relations [ $ rel ] = [ 'className' => $ wrapperName , ] ; } } } | const AFTER = AFTER ; |
44,209 | public function createActiveItem ( $ text , $ title = '' ) { $ breadcrumb = new BreadcrumbObject ( ) ; $ breadcrumb -> setText ( $ text ) ; $ breadcrumb -> setActive ( true ) ; if ( $ title ) { $ breadcrumb -> setTitle ( $ title ) ; } $ this -> breadcrumbs [ ] = $ breadcrumb ; return $ breadcrumb ; } | Creates an active breadcrumb object and adds it to the crumbs list . |
44,210 | public function createItem ( $ text , $ href , $ title = '' ) { $ breadcrumb = new BreadcrumbObject ( ) ; $ breadcrumb -> setText ( $ text ) ; $ breadcrumb -> setHref ( $ href ) ; if ( $ title ) { $ breadcrumb -> setTitle ( $ title ) ; } $ this -> breadcrumbs [ ] = $ breadcrumb ; return $ breadcrumb ; } | Creates an breadcrumb object with link and adds it to the crumbs list . |
44,211 | final public function get_user_array ( Array $ additional_fields = array ( ) ) { $ user = array ( 'email' => $ this -> get_email ( ) , 'screen_name' => $ this -> get_screen_name ( ) , 'groups' => $ this -> get_groups ( ) , ) ; $ additional_fields = array_merge ( $ this -> config [ 'additional_fields' ] , $ additional_fields ) ; foreach ( $ additional_fields as $ af ) { if ( is_callable ( array ( $ this , $ method = 'get_' . $ af ) ) ) { $ user [ $ af ] = $ this -> $ method ( ) ; } } return $ user ; } | Return user info in an array always includes email & screen_name Additional fields can be requested in the first param or set in config all additional fields must have their own method get_ + fieldname |
44,212 | public function member ( $ group , $ driver = null , $ user = null ) { $ user = $ user ? : $ this -> get_user_id ( ) ; if ( $ driver === null ) { foreach ( \ Auth :: group ( true ) as $ g ) { if ( $ g -> member ( $ group , $ user ) ) { return true ; } } return false ; } return \ Auth :: group ( $ driver ) -> member ( $ group , $ user ) ; } | Verify Group membership |
44,213 | public function hash_password ( $ password ) { return base64_encode ( $ this -> hasher ( ) -> pbkdf2 ( $ password , \ Config :: get ( 'auth.salt' ) , \ Config :: get ( 'auth.iterations' , 10000 ) , 32 ) ) ; } | Default password hash method |
44,214 | public function hasher ( ) { is_null ( $ this -> hasher ) and $ this -> hasher = new \ PHPSecLib \ Crypt_Hash ( ) ; return $ this -> hasher ; } | Returns the hash object and creates it if necessary |
44,215 | public function groups ( $ driver = null ) { $ result = array ( ) ; if ( $ driver === null ) { foreach ( \ Auth :: group ( true ) as $ group ) { method_exists ( $ group , 'groups' ) and $ result = \ Arr :: merge ( $ result , $ group -> groups ( ) ) ; } } else { $ result = \ Auth :: group ( $ driver ) -> groups ( ) ; } return $ result ; } | Returns the list of defined groups |
44,216 | public function roles ( $ driver = null ) { $ result = array ( ) ; if ( $ driver === null ) { foreach ( \ Auth :: acl ( true ) as $ acl ) { method_exists ( $ acl , 'roles' ) and $ result = \ Arr :: merge ( $ result , $ acl -> roles ( ) ) ; } } else { $ result = \ Auth :: acl ( $ driver ) -> roles ( ) ; } return $ result ; } | Returns the list of defined roles |
44,217 | public function remember_me ( $ user_id = null ) { if ( $ user_id === null and isset ( $ this -> user [ 'id' ] ) ) { $ user_id = $ this -> user [ 'id' ] ; } if ( static :: $ remember_me and $ user_id ) { static :: $ remember_me -> set ( 'user_id' , $ user_id ) ; return true ; } return false ; } | Set a remember - me cookie for the passed user id or for the current logged - in user if no id was given |
44,218 | public function doPostRequest ( string $ url , array $ data , array $ headers = [ ] , bool $ closeConnection = true ) { $ this -> setUrl ( $ url ) -> setPostMethod ( ) -> setPostFields ( $ data ) -> setMustReturnTransfer ( ) -> setHttpHeader ( $ headers ) -> execute ( true , $ closeConnection ) ; $ this -> _call ( $ this -> callback ?? function ( FluentCurl $ instance ) { } , $ this ) ; return $ this ; } | Wraps all the post functionality into a single method . |
44,219 | private function _checkAcl ( ) { $ aclConfig = Agl :: app ( ) -> getConfig ( 'core-layout/modules/' . $ this -> _module . '#' . $ this -> _view . '#action#' . $ this -> _action . '/acl' ) ; if ( $ aclConfig === NULL ) { $ aclConfig = Agl :: app ( ) -> getConfig ( 'core-layout/modules/' . $ this -> _module . '#' . $ this -> _view . '/acl' ) ; } if ( $ aclConfig === NULL ) { $ aclConfig = Agl :: app ( ) -> getConfig ( 'core-layout/modules/' . $ this -> _module . '/acl' ) ; } if ( $ aclConfig !== NULL ) { $ auth = Agl :: getAuth ( ) ; $ acl = Agl :: getSingleton ( Agl :: AGL_CORE_POOL . '/auth/acl' ) ; if ( ! $ acl -> isAllowed ( $ auth -> getRole ( ) , $ aclConfig ) ) { $ acl -> requestLogin ( ) ; } } return true ; } | Check if the current user can trigger the action with its Acl configuration . |
44,220 | public function route ( ) { $ content = $ this -> _controller -> { $ this -> _actionMethod } ( ) ; if ( $ this -> _controller -> isJson ( ) ) { Request :: setHeader ( Request :: HEADER_JSON ) ; echo json_encode ( $ content ) ; } else { echo $ content ; } } | Route the request by invoking the corresponding controller and method . |
44,221 | private function sendRequest ( $ url , $ params , $ post = 1 , $ headers = array ( 'Accept: application/json, text/javascript, */*; q=0.01' , 'Content-Type=application/x-www-form-urlencoded' ) ) { $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , $ url ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 ) ; if ( null !== $ params ) curl_setopt ( $ ch , CURLOPT_POSTFIELDS , http_build_query ( $ params , null , '&' ) ) ; curl_setopt ( $ ch , CURLOPT_POST , $ post ) ; curl_setopt ( $ ch , CURLOPT_HEADER , 1 ) ; if ( isset ( $ this -> token ) ) { $ headers [ ] = 'Authorization: ' . $ this -> token ; } curl_setopt ( $ ch , CURLOPT_HTTPHEADER , $ headers ) ; curl_setopt ( $ ch , CURLOPT_VERBOSE , 0 ) ; curl_setopt ( $ ch , CURLOPT_FOLLOWLOCATION , 1 ) ; curl_setopt ( $ ch , CURLOPT_CONNECTTIMEOUT , 10 ) ; curl_setopt ( $ ch , CURLOPT_COOKIEJAR , $ this -> cacheFolder . "/cookies.txt" ) ; curl_setopt ( $ ch , CURLOPT_COOKIEFILE , $ this -> cacheFolder . "/cookies.txt" ) ; curl_setopt ( $ ch , CURLOPT_USERAGENT , "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/41.0.2272.76 Chrome/41.0.2272.76 Safari/537.36" ) ; curl_setopt ( $ ch , CURLOPT_REFERER , $ this -> baseUrl ) ; $ response = curl_exec ( $ ch ) ; $ header_size = curl_getinfo ( $ ch , CURLINFO_HEADER_SIZE ) ; $ header = substr ( $ response , 0 , $ header_size ) ; $ body = substr ( $ response , $ header_size ) ; $ last_url = curl_getinfo ( $ ch , CURLINFO_EFFECTIVE_URL ) ; $ info = curl_getinfo ( $ ch ) ; curl_close ( $ ch ) ; return array ( 'body' => $ body , 'header' => $ header , 'url' => $ last_url ) ; } | Send a request using cURL |
44,222 | private function queryString ( $ params ) { $ querystring = '?' ; foreach ( $ params as $ k => $ v ) { $ querystring .= $ k . '=' . urlencode ( $ v ) . '&' ; } return substr ( $ querystring , 0 , - 1 ) ; } | Convert an associative array into get parameters |
44,223 | private function saveToken ( ) { $ fd = fopen ( $ this -> cacheFolder . "/token.txt" , 'w' ) ; fwrite ( $ fd , $ this -> token ) ; fclose ( $ fd ) ; } | Save token into a file |
44,224 | private function loadToken ( ) { if ( file_exists ( $ this -> cacheFolder . "/token.txt" ) ) { $ fd = fopen ( $ this -> cacheFolder . "/token.txt" , 'r' ) ; $ this -> token = fgets ( $ fd ) ; fclose ( $ fd ) ; } else { $ this -> connect ( ) ; } } | Load token from a file |
44,225 | public function connect ( ) { $ request = $ this -> sendRequest ( $ this -> baseUrl . "/auth" , array ( 'username' => $ this -> login , 'password' => $ this -> password ) , 2 ) ; $ response = json_decode ( $ request [ 'body' ] , true ) ; if ( array_key_exists ( 'error' , $ response ) ) { throw new \ Exception ( 'Erreur ' . $ response [ 'code' ] . ' : ' . $ response [ 'error' ] ) ; } else { $ this -> token = $ response [ 'token' ] ; $ this -> saveToken ( ) ; } } | Connect to the T411 website to save the token key |
44,226 | public function search ( $ query , $ params = array ( ) ) { if ( ! isset ( $ params [ 'cid' ] ) ) $ params [ 'cid' ] = '433' ; if ( ! isset ( $ params [ 'offset' ] ) ) $ params [ 'offset' ] = '0' ; if ( ! isset ( $ params [ 'limit' ] ) ) $ params [ 'limit' ] = '200' ; $ request = $ this -> sendRequest ( $ this -> baseUrl . "/torrents/search/" . urlencode ( $ query . '*' ) . $ this -> queryString ( $ params ) , null , 0 ) ; $ response = json_decode ( $ request [ 'body' ] , true ) ; if ( array_key_exists ( 'error' , $ response ) ) { if ( $ response [ 'code' ] == 201 || $ response [ 'code' ] == 202 ) { $ this -> connect ( ) ; return $ this -> search ( $ query , $ params ) ; } throw new \ Exception ( 'Erreur ' . $ response [ 'code' ] . ' : ' . $ response [ 'error' ] ) ; } else { $ torrents = array ( ) ; if ( intval ( $ response [ 'total' ] ) > 0 ) { foreach ( $ response [ 'torrents' ] as $ torrent ) { $ torrents [ ] = array_merge ( $ torrent , array ( 'url' => 'http://www.t411.in/torrents/' . $ torrent [ 'rewritename' ] , 'id' => intval ( $ torrent [ 'id' ] ) , 'seeders' => intval ( $ torrent [ 'seeders' ] ) , 'leechers' => intval ( $ torrent [ 'leechers' ] ) , 'comments' => intval ( $ torrent [ 'comments' ] ) , 'size' => intval ( $ torrent [ 'size' ] ) , 'times_completed' => intval ( $ torrent [ 'times_completed' ] ) , 'owner' => intval ( $ torrent [ 'owner' ] ) , 'isVerified' => ( boolean ) intval ( $ torrent [ 'isVerified' ] ) , ) ) ; } } return $ torrents ; } } | Perform a search on T411 website |
44,227 | public function downloadTorrent ( $ id , $ path = '' ) { $ request = $ this -> sendRequest ( $ this -> baseUrl . "/torrents/download/" . $ id , null , 0 ) ; $ response = json_decode ( $ request [ 'body' ] , true ) ; if ( NULL === $ response ) { preg_match ( '/filename="(.*?)"/i' , $ request [ 'header' ] , $ filename ) ; $ file = fopen ( $ path . '/' . $ filename [ 1 ] , 'w+' ) ; fwrite ( $ file , $ request [ 'body' ] ) ; fclose ( $ file ) ; } else { if ( array_key_exists ( 'error' , $ response ) ) { if ( $ response [ 'code' ] == 201 || $ response [ 'code' ] == 202 ) { $ this -> connect ( ) ; return $ this -> downloadTorrent ( $ id , $ path ) ; } throw new \ Exception ( 'Erreur ' . $ response [ 'code' ] . ' : ' . $ response [ 'error' ] ) ; } } } | Download the . torrent from ID |
44,228 | private function _constructVar ( $ sContent , $ aConfVars , $ sVarTemplate ) { foreach ( $ aConfVars as $ mKey => $ mOne ) { if ( is_array ( $ mOne ) ) { $ sContent .= $ sVarTemplate . '[\'' . $ mKey . '\'] = array(); ' ; $ sContent = $ this -> _constructVar ( $ sContent , $ mOne , $ sVarTemplate . '[\'' . $ mKey . '\']' ) ; } else { $ sContent .= $ sVarTemplate . '[\'' . $ mKey . '\'] = "' . $ mOne . '"; ' ; } } return $ sContent ; } | constructor of var on recursive mode |
44,229 | protected function getSourceElement ( ) : ? XmlElement { $ list = $ this -> node -> getElementsByTagNameNS ( XliffFile :: XLIFF_NS , 'source' ) ; if ( $ list -> length && $ element = $ list -> item ( 0 ) ) { return $ element ; } return null ; } | Fetch the target element . |
44,230 | public static function isJson ( $ input ) : bool { $ test = json_decode ( $ input ) ; return ( $ test instanceof \ stdClass || \ is_array ( $ test ) ) ; } | Check if input value is valid JSON |
44,231 | public function processText ( string $ text ) : string { $ text = str_replace ( "<br>" , "" , $ text ) ; $ text = str_replace ( "<br/>" , "" , $ text ) ; $ text = str_replace ( "<br />" , "" , $ text ) ; $ text = str_replace ( "\n" , "<br>" , $ text ) ; $ text = str_replace ( "\t" , " " , $ text ) ; return preg_replace ( $ this -> pattern , $ this -> replace , $ text ) ; } | Process text - > convert BBCode to HTML |
44,232 | protected function serverSocketRequest ( ) { $ base = function_exists ( 'lzf_compress' ) ? self :: REQUEST_SOCKET_LZF : self :: REQUEST_SOCKET_NON_LZF ; $ url = sprintf ( "%s%s/%d" , $ this -> clientApiConfig -> getEndpoint ( ) , $ base , $ this -> clientApiConfig -> getProjectId ( ) ) ; $ data = array ( 'key' => $ this -> clientApiConfig -> getKey ( ) , 'secret' => $ this -> clientApiConfig -> getSecret ( ) , ) ; return $ this -> postClient -> call ( $ url , $ data ) ; } | Request to server a socket if okay server returns with the url and port opened . |
44,233 | protected function send ( $ msg ) { $ msg .= PHP_EOL ; return $ this -> socket -> write ( $ msg , strlen ( $ msg ) ) ; } | Atomic send of a string trough the socket . |
44,234 | public static function copy ( $ value ) { if ( \ is_object ( $ value ) ) { if ( \ is_callable ( $ value ) ) { return \ Closure :: bind ( $ value , null ) ; } return clone $ value ; } return $ value ; } | Makes a deep copy of any given value |
44,235 | public static function propertiesExist ( $ obj ) { for ( $ i = 1 , $ l = \ func_num_args ( ) - 1 ; $ i <= $ l ; ++ $ i ) { if ( ! \ property_exists ( $ obj , \ func_get_arg ( $ i ) ) ) { return false ; } } return true ; } | Checks if the given properties exists in the specified object |
44,236 | protected function getDescribedCommand ( $ args ) { $ this -> describedCommand = $ command = $ this -> getParent ( ) ; foreach ( $ args as $ arg ) { $ command = $ command -> getChild ( $ arg ) ; if ( ! $ command ) { throw new CommandNotFoundException ( sprintf ( 'Command: "%s" not found.' , implode ( ' ' , $ args ) ) , $ this -> describedCommand , $ arg ) ; } $ this -> describedCommand = $ command ; } return $ command ; } | Get the command we want to describe . |
44,237 | public function doProcess ( ) { $ command = 'nohup ' . $ this -> command . ' > /dev/null 2>&1 & echo $!' ; exec ( $ command , $ pross ) ; $ this -> pid = ( int ) $ pross [ 0 ] ; } | do the process in background |
44,238 | private function getValue ( $ value ) { if ( $ this -> isBoolean ( $ value ) ) { return ( strtolower ( $ value ) === 'true' ) ; } elseif ( $ this -> isInteger ( $ value ) ) { return ( int ) $ value ; } elseif ( $ this -> isNumber ( $ value ) ) { return ( float ) $ value ; } return $ value ; } | Get value prepared for Json data structure |
44,239 | public function clear ( ) : void { $ this -> value = null ; $ this -> defaultValue = null ; $ this -> lenght = - 1 ; $ this -> type = MDataType :: UNKNOWN ; $ this -> name = null ; } | Clears the value of the field and sets it to NULL . |
44,240 | public function isValidHash ( ) : Bool { $ hash = $ _POST [ 'HASHPARAMS' ] ; $ hashEx = explode ( ':' , $ hash ) ; $ real = NULL ; foreach ( $ hashEx as $ part ) { if ( ! empty ( $ _POST [ $ part ] ) ) { $ real .= $ _POST [ $ part ] ; } } return $ real === $ _POST [ 'HASHPARAMSVAL' ] && $ _POST [ 'HASH' ] === base64_encode ( pack ( 'H*' , sha1 ( $ real . $ _POST [ 'storeKey' ] ) ) ) ; } | Is valid hash |
44,241 | public function homeAction ( Request $ request ) { if ( ! $ this -> get ( 'security.authorization_checker' ) -> isGranted ( 'IS_AUTHENTICATED_REMEMBERED' ) ) { $ request -> getSession ( ) -> set ( '_ekyna.login_success.target_path' , 'fos_user_profile_show' ) ; return $ this -> redirect ( $ this -> generateUrl ( 'fos_user_security_login' ) ) ; } return $ this -> redirect ( $ this -> generateUrl ( 'fos_user_profile_show' ) ) ; } | Home action . |
44,242 | public static function group ( $ group , \ Closure $ closure ) { self :: $ group = $ group ; call_user_func ( $ closure , self :: getInstance ( ) ) ; self :: $ group = null ; } | Appending route entries to group . |
44,243 | public function api ( $ match , $ apiController , $ kwargs = [ ] , $ methods = null ) { if ( is_string ( $ methods ) ) { $ methods = array ( $ methods ) ; } if ( ! is_array ( $ kwargs ) ) { $ kwargs = [ ] ; } if ( $ methods === null ) { $ methods = [ 'GET' , 'POST' , 'PUT' , 'DELETE' , 'PATCH' ] ; } $ methods = array_map ( 'strtoupper' , $ methods ) ; if ( $ match === '' ) { throw new RouterException ( 'Your API route must contain a first match field when registering!' ) ; } if ( substr ( $ match , 0 , 1 ) !== '/' ) { $ match = '/' . $ match ; } foreach ( $ methods as $ method ) { switch ( $ method ) { case 'GET' : $ this -> get ( $ match , $ apiController , array_merge ( $ kwargs , [ 'api_method' => 'list' ] ) ) ; $ this -> get ( $ match . '/(!?)' , $ apiController , array_merge ( $ kwargs , [ 'api_method' => 'retrieve' ] ) ) ; break ; case 'POST' : $ this -> post ( $ match , $ apiController , array_merge ( $ kwargs , [ 'api_method' => 'create' ] ) ) ; break ; case 'PUT' : $ this -> put ( $ match . '/(!?)' , $ apiController , array_merge ( $ kwargs , [ 'api_method' => 'update' ] ) ) ; break ; case 'PATCH' : $ this -> patch ( $ match . '/(!?)' , $ apiController , array_merge ( $ kwargs , [ 'api_method' => 'partialUpdate' ] ) ) ; break ; case 'DELETE' : $ this -> delete ( $ match . '/(!?)' , $ apiController , array_merge ( $ kwargs , [ 'api_method' => 'destroy' ] ) ) ; break ; } } } | Register an API entity class with a base match . |
44,244 | public function get ( $ match , $ callback , $ kwargs = [ ] ) { $ this -> addRoute ( new Route ( $ match , 'GET' , $ callback , self :: $ group , $ kwargs ) ) ; } | Add route for GET method . |
44,245 | public function before ( $ callback , $ group = null , $ methods = array ( ) ) { $ methods = array_map ( 'strtoupper' , $ methods ) ; if ( $ group === null ) { if ( self :: $ group !== null ) { $ group = self :: $ group ; } else { $ group = 'global' ; } } $ this -> addMiddleware ( new Middleware ( $ callback , 'before' , $ methods , $ group ) ) ; } | Add before middleware . |
44,246 | public function addFrom ( string $ address , ? string $ name = null ) : Message { $ this -> from [ ] = [ 'address' => $ address , 'name' => $ name ] ; return $ this ; } | Adds a From address |
44,247 | public function addTo ( string $ address , ? string $ name = null ) : Message { $ this -> to [ ] = [ 'address' => $ address , 'name' => $ name ] ; return $ this ; } | Adds a To address |
44,248 | public function addReplyTo ( string $ address , ? string $ name = null ) : Message { $ this -> replyTo [ ] = [ 'address' => $ address , 'name' => $ name ] ; return $ this ; } | Adds a Reply - To address |
44,249 | public function addCc ( string $ address , ? string $ name = null ) : Message { $ this -> cc [ ] = [ 'address' => $ address , 'name' => $ name ] ; return $ this ; } | Adds a CC address |
44,250 | public function addBcc ( string $ address , ? string $ name = null ) : Message { $ this -> bcc [ ] = [ 'address' => $ address , 'name' => $ name ] ; return $ this ; } | Adds a BCC address |
44,251 | public function addContent ( string $ content , string $ contentType , ? string $ charset = null ) : Message { $ charset = $ charset ? : $ this -> getCharset ( ) ; $ this -> content [ ] = [ 'content' => $ content , 'content_type' => $ contentType , 'charset' => $ charset ] ; return $ this ; } | Adds a content part |
44,252 | public function setSender ( string $ address , ? string $ name = null ) : Message { $ this -> sender = [ 'address' => $ address , 'name' => $ name ] ; return $ this ; } | Sets the sender |
44,253 | public function setMaxLineLength ( int $ maxLineLength ) : Message { $ maxLineLength = ( int ) abs ( $ maxLineLength ) ; if ( $ maxLineLength > 998 ) { $ maxLineLength = 998 ; } $ this -> maxLineLength = $ maxLineLength ; return $ this ; } | Sets the max line length |
44,254 | public static function getPossibleValues ( ) : array { return [ self :: POST , self :: PUT , self :: PATCH , self :: DELETE , self :: GET , ] ; } | Get the possible values of action method |
44,255 | protected function guardAgainstString ( $ data , $ dataName = 'Argument' , $ exceptionClass = 'Zend\Stdlib\Exception\InvalidArgumentException' ) { if ( ! is_numeric ( $ data ) ) { $ message = sprintf ( "%s must be a numeric, [%s] given" , $ dataName , is_object ( $ data ) ? get_class ( $ data ) : gettype ( $ data ) ) ; throw new $ exceptionClass ( $ message ) ; } } | Verify that the data is an int |
44,256 | public function cardNumber ( $ value ) : bool { if ( ! is_string ( $ value ) || strlen ( $ value ) < 12 ) { return false ; } $ result = 0 ; $ odd = strlen ( $ value ) % 2 ; preg_replace ( '/[^0-9]+/' , '' , $ value ) ; for ( $ i = 0 ; $ i < strlen ( $ value ) ; ++ $ i ) { $ result += $ odd ? $ value [ $ i ] : ( ( $ value [ $ i ] * 2 > 9 ) ? $ value [ $ i ] * 2 - 9 : $ value [ $ i ] * 2 ) ; $ odd = ! $ odd ; } return ( $ result % 10 == 0 ) ? true : false ; } | Check credit card passed by Luhn algorithm . |
44,257 | public function match ( $ value , string $ field , bool $ strict = false ) : bool { if ( $ strict ) { return $ value === $ this -> getValidator ( ) -> getValue ( $ field , null ) ; } return $ value == $ this -> getValidator ( ) -> getValue ( $ field , null ) ; } | Check if value matches value from another field . |
44,258 | protected function createErrorResponse ( $ content = 'Unknown Error' , $ code = 500 ) { $ data = [ 'message' => $ content ] ; $ response = $ this -> createJsonResponse ( $ data , $ code ) ; return $ response ; } | Create and return an error response with a standard format |
44,259 | protected function createSimpleResponse ( $ code = 500 , $ content = 'Unknown error' ) { $ response = new Response ; $ response -> setStatusCode ( $ code ) -> setContent ( $ content ) ; return $ response ; } | Create and return an error response object |
44,260 | protected function createConstraintViolationResponse ( ConstraintViolationListInterface $ violationList ) { $ errors = $ this -> validationErrorFormatter -> groupViolationsByField ( $ violationList ) ; return $ this -> createJsonResponse ( [ 'errors' => $ errors ] , 422 ) ; } | Create a response for constraint violations |
44,261 | public function getTotalCodeCoverage ( ) { $ totalStatements = 0 ; $ totalCoveredStatements = 0 ; foreach ( $ this -> getFiles ( ) as $ file ) { $ totalStatements += $ file -> getStatements ( ) ; $ totalCoveredStatements += $ file -> getCoveredStatements ( ) ; } foreach ( $ this -> getPackages ( ) as $ package ) { foreach ( $ package -> getFiles ( ) as $ file ) { $ totalStatements += $ file -> getStatements ( ) ; $ totalCoveredStatements += $ file -> getCoveredStatements ( ) ; } } return ( $ totalCoveredStatements == 0 ? 0 : \ round ( ( $ totalCoveredStatements / $ totalStatements ) * 100 ) ) ; } | Return total code coverage in percent . |
44,262 | public function getMaximumCRAPIndex ( ) { $ maximumCRAP = 0 ; foreach ( $ this -> getFiles ( ) as $ file ) { foreach ( $ file -> getLines ( ) as $ line ) { if ( $ line -> getType ( ) == CloverLine :: TYPE_METHOD ) { if ( $ line -> getCrap ( ) > $ maximumCRAP ) { $ maximumCRAP = $ line -> getCRAP ( ) ; } } } } foreach ( $ this -> getPackages ( ) as $ package ) { foreach ( $ package -> getFiles ( ) as $ file ) { foreach ( $ file -> getLines ( ) as $ line ) { if ( $ line -> getType ( ) == CloverLine :: TYPE_METHOD ) { if ( $ line -> getCrap ( ) > $ maximumCRAP ) { $ maximumCRAP = $ line -> getCRAP ( ) ; } } } } } return $ maximumCRAP ; } | Return the maximum C . R . A . P . index |
44,263 | public function existRequestData ( $ name ) { return Request :: IsPostMethod ( ) ? $ this -> existFormData ( $ name ) : $ this -> existParameter ( $ name ) ; } | CURRENT REQUEST data |
44,264 | public function exchangeArray ( $ collection ) { if ( ! is_array ( $ collection ) && ! ( $ collection instanceof Traversable ) ) { throw new Exception \ InvalidArgumentException ( sprintf ( 'Expected argument "array" or "Traversable"; "%s" given' , gettype ( $ collection ) . ( is_object ( $ collection ) ? '(' . get_class ( $ collection ) . ')' : '' ) ) ) ; } if ( $ collection instanceof Traversable ) { $ collection = ArrayUtils :: iteratorToArray ( $ collection ) ; } foreach ( $ collection as $ key => $ value ) { $ this -> set ( $ key , $ value ) ; } } | Sets a whole new array replacement . |
44,265 | public function get ( $ index ) { if ( null === $ index ) { throw new Exception \ InvalidArgumentException ( 'The specified key name is null' ) ; } if ( ! $ this -> has ( $ index ) ) { throw new Exception \ OutOfBoundsException ( sprintf ( 'Index "%s" is out of bounds' , $ index ) ) ; } return $ this -> collections [ $ index ] ; } | Returns the element at the specified key name in this class . |
44,266 | public function has ( $ key ) { if ( null === $ key ) { throw new Exception \ InvalidArgumentException ( 'The specified key name is null' ) ; } if ( ! is_scalar ( $ key ) ) { throw new Exception \ InvalidArgumentException ( 'The specified key name must be a scalar' ) ; } return array_key_exists ( $ key , $ this -> collections ) ; } | Whether this contains the given name . More formally returns true if and only if this contains at least one element . |
44,267 | public function exists ( Closure $ predicate ) { foreach ( $ this -> collections as $ key => $ element ) { if ( $ predicate ( $ key , $ element ) ) { return true ; } } return false ; } | Tests for the existence of an element that satisfies the given predicate . |
44,268 | public function merge ( $ collection ) { if ( ! is_array ( $ collection ) && ! ( $ collection instanceof Traversable ) ) { throw new Exception \ InvalidArgumentException ( sprintf ( 'Expected argument "array" or "Traversable"; "%s" given' , gettype ( $ collection ) . ( is_object ( $ collection ) ? '(' . get_class ( $ collection ) . ')' : '' ) ) ) ; } foreach ( $ collection as $ key => $ value ) { if ( $ this -> has ( $ key ) ) { if ( is_int ( $ key ) ) { $ this -> append ( $ value ) ; } else { if ( $ value instanceof CollectionInterface ) { $ value = $ value -> toArray ( ) ; if ( $ this -> collections [ $ key ] instanceof CollectionInterface ) { $ value = $ this -> collections [ $ key ] -> merge ( $ value ) ; } else { $ value = new static ( $ value ) ; } } $ this -> set ( $ key , $ value ) ; } } else { if ( $ value instanceof CollectionInterface ) { $ value = new static ( $ value -> toArray ( ) ) ; } $ this -> set ( $ key , $ value ) ; } } return $ this ; } | Merge another Collection with this one . |
44,269 | public function toArray ( $ recursive = true ) { $ results = [ ] ; $ collections = $ this -> collections ; if ( $ recursive ) { foreach ( $ collections as $ key => $ value ) { if ( $ value instanceof CollectionInterface ) { $ results [ $ key ] = $ value -> toArray ( $ recursive ) ; } else { $ results [ $ key ] = $ value ; } } } else { foreach ( $ collections as $ key => $ value ) { $ results [ $ key ] = $ value ; } } return $ results ; } | Get the array representation of this object . |
44,270 | public function update ( $ setting , $ value ) { if ( $ this -> db -> update ( $ this -> table_config , array ( 'value' => $ value ) , array ( 'setting' => $ setting ) ) ) { $ this -> set ( $ setting , $ value ) ; } return $ this ; } | Set a setting in the database |
44,271 | public static function options ( $ options , $ selected = [ ] ) : string { $ html = '' ; $ selected = array_flip ( $ selected ) ; foreach ( $ options as $ value => $ name ) { $ html .= is_array ( $ name ) ? self :: tag ( 'optgroup' , [ 'label' => $ value ] , self :: options ( $ name , $ selected ) ) : self :: tag ( 'option' , [ 'value' => $ value ] + ( isset ( $ selected [ $ value ] ) ? [ 'selected' => 'selected' ] : [ ] ) , $ name ) ; } return $ html ; } | Render select options |
44,272 | private function updatePeakMemoryUsage ( ) { $ memory = memory_get_peak_usage ( ) ; if ( $ memory > $ this -> peakMemoryUsage ) { $ this -> peakMemoryUsage = $ memory ; $ this -> setParameter ( 'Memory/PeakMemoryUsage' , $ memory ) ; if ( extension_loaded ( 'newrelic' ) ) { newrelic_custom_metric ( 'Custom/PeakMemoryUsage' , $ memory ) ; } } } | Check if this transaction generated a bigger peak usage then the previous transaction . If so report it . |
44,273 | private function checkRequired ( array $ options , array $ keys ) { $ missing = array_keys ( array_diff_key ( array_flip ( $ keys ) , $ options ) ) ; if ( ! empty ( $ missing ) ) { throw CommandException :: missingOptions ( $ missing ) ; } } | Check that the given options contain all required keys . |
44,274 | public function & createOption ( $ optgroup = '' ) : Option { $ option = $ this -> factory -> create ( 'Form\Option' ) ; $ this -> addOption ( $ option , $ optgroup ) ; return $ option ; } | Creates an Option object and returns it |
44,275 | public function & newOption ( $ value = null , $ inner = null , bool $ selected = false , string $ optgroup = '' ) : Option { $ option = $ this -> factory -> create ( 'Form\Option' ) ; if ( isset ( $ value ) ) { $ option -> setValue ( $ value ) ; } if ( isset ( $ inner ) ) { $ option -> setInner ( $ inner ) ; } if ( $ selected == true ) { $ option -> isSelected ( ) ; } $ this -> addOption ( $ option , $ optgroup ) ; return $ option ; } | Add an Option object to the options array |
44,276 | public function addOption ( Option $ option , string $ optgroup = '' ) : Select { if ( empty ( $ optgroup ) ) { $ this -> options [ ] = $ option ; } else { $ this -> options [ $ optgroup ] [ ] = $ option ; } return $ this ; } | Add an html option object to the optionlist |
44,277 | private function buildOption ( Option $ option ) : string { if ( ! $ option -> getSelected ( ) && in_array ( $ option -> getValue ( ) , $ this -> value ) ) { $ option -> isSelected ( ) ; } return $ option -> build ( ) ; } | Builds otion element |
44,278 | private function loadClients ( array $ clients , ContainerBuilder $ container ) { foreach ( $ clients as $ name => $ clientConfig ) { $ clientId = sprintf ( 'phlexible_elastica.client.%s' , $ name ) ; $ clientDef = new DefinitionDecorator ( 'phlexible_elastica.client_prototype' ) ; $ clientDef -> replaceArgument ( 0 , $ clientConfig ) ; $ logger = $ clientConfig [ 'connections' ] [ 0 ] [ 'logger' ] ; if ( false !== $ logger ) { $ clientDef -> addMethodCall ( 'setLogger' , array ( new Reference ( $ logger ) ) ) ; } $ clientDef -> addTag ( 'phlexible_elastica.client' ) ; $ container -> setDefinition ( $ clientId , $ clientDef ) ; $ this -> clients [ $ name ] = array ( 'id' => $ clientId , 'reference' => new Reference ( $ clientId ) , ) ; } } | Loads the configured clients . |
44,279 | private function loadIndexes ( array $ indexes , ContainerBuilder $ container ) { foreach ( $ indexes as $ name => $ index ) { $ indexId = sprintf ( 'phlexible_elastica.index.%s' , $ name ) ; $ indexName = isset ( $ index [ 'index_name' ] ) ? $ index [ 'index_name' ] : $ name ; $ indexDef = new DefinitionDecorator ( 'phlexible_elastica.index_prototype' ) ; $ indexDef -> replaceArgument ( 0 , $ indexName ) ; $ indexDef -> addTag ( 'phlexible_elastica.index' , array ( 'name' => $ name , ) ) ; if ( method_exists ( $ indexDef , 'setFactory' ) ) { $ indexDef -> setFactory ( array ( new Reference ( 'phlexible_elastica.client' ) , 'getIndex' ) ) ; } else { $ indexDef -> setFactoryService ( 'phlexible_elastica.client' ) ; $ indexDef -> setFactoryMethod ( 'getIndex' ) ; } if ( isset ( $ index [ 'client' ] ) ) { $ client = $ this -> getClient ( $ index [ 'client' ] ) ; if ( method_exists ( $ indexDef , 'setFactory' ) ) { $ indexDef -> setFactory ( array ( $ client , 'getIndex' ) ) ; } else { $ indexDef -> setFactoryService ( 'phlexible_elastica.client' ) ; $ indexDef -> setFactoryMethod ( 'getIndex' ) ; } } $ container -> setDefinition ( $ indexId , $ indexDef ) ; $ reference = new Reference ( $ indexId ) ; $ this -> indexConfigs [ $ name ] = array ( 'elasticsearch_name' => $ indexName , 'reference' => $ reference , 'name' => $ name , 'settings' => $ index [ 'settings' ] , 'type_prototype' => isset ( $ index [ 'type_prototype' ] ) ? $ index [ 'type_prototype' ] : array ( ) , 'use_alias' => $ index [ 'use_alias' ] , ) ; } } | Loads the configured indexes . |
44,280 | private function getClient ( $ clientName ) { if ( ! array_key_exists ( $ clientName , $ this -> clients ) ) { throw new InvalidArgumentException ( sprintf ( 'The elastica client with name "%s" is not defined' , $ clientName ) ) ; } return $ this -> clients [ $ clientName ] [ 'reference' ] ; } | Returns a reference to a client given its configured name . |
44,281 | public function addRoute ( $ httpMethod , $ route , $ handler ) { parent :: addRoute ( $ httpMethod , $ route , $ handler ) ; if ( substr ( $ route , - 1 ) === '/' ) { parent :: addRoute ( $ httpMethod , substr ( $ route , 0 , - 1 ) , new RouteHandler ( function ( ) { $ url = tiga_url ( $ this -> request -> getPathInfo ( ) . '/' ) ; $ response = \ Tiga \ Framework \ Response \ ResponseFactory :: redirect ( $ url ) ; $ response -> sendHeaders ( ) ; die ( ) ; } ) ) ; } else { $ route .= '/' ; parent :: addRoute ( $ httpMethod , $ route , new RouteHandler ( function ( ) { $ url = rtrim ( tiga_url ( $ this -> request -> getPathInfo ( ) ) , '/' ) ; $ response = \ Tiga \ Framework \ Response \ ResponseFactory :: redirect ( $ url ) ; $ response -> sendHeaders ( ) ; die ( ) ; } ) ) ; } } | Add trailing slash route or add route without trailing slash so both work . |
44,282 | public static function cosineSimilarity ( array $ vector_a , array $ vector_b , $ length_a = null , $ length_b = null ) { $ sum = 0 ; $ sum_a_sq = ( $ length_a === null ? 0.0 : ( float ) $ length_a ) ; $ sum_b_sq = ( $ length_b === null ? 0.0 : ( float ) $ length_b ) ; foreach ( $ vector_a as $ key => $ value ) { if ( isset ( $ vector_b [ $ key ] ) ) $ sum += ( $ value * $ vector_b [ $ key ] ) ; if ( $ length_a === null ) $ sum_a_sq += pow ( $ value , 2 ) ; } if ( $ length_a === null ) $ sum_a_sq = sqrt ( $ sum_a_sq ) ; if ( $ length_b === null ) { foreach ( $ vector_b as $ key => $ value ) { $ sum_b_sq += pow ( $ value , 2 ) ; } $ sum_b_sq = sqrt ( $ sum_b_sq ) ; } $ division = $ sum_b_sq * $ sum_a_sq ; if ( $ division == 0 ) { return 0 ; } else { $ result = $ sum / $ division ; return $ result ; } } | Compute similarity between two vectors . |
44,283 | public function save ( ) { if ( $ this -> exists ( ) ) { $ query = new Query ( static :: table ( ) ) ; $ query -> update ( $ this -> getData ( ) , $ this -> getIdentifyCondition ( ) ) ; return $ query -> execute ( ) ; } else { $ query = new Query ( static :: table ( ) ) ; $ query -> insert ( $ this -> getData ( ) ) ; if ( $ query -> execute ( ) ) $ this -> from_db = true ; return $ query -> success ( ) ; } } | altrimenti la update |
44,284 | public function erase ( ) { if ( $ this -> exists ( ) ) { $ query = new Query ( static :: table ( ) ) ; $ query -> delete ( ) -> where ( $ this -> getIdentifyCondition ( ) ) ; if ( $ query -> execute ( ) ) $ this -> clear ( ) ; return $ query -> success ( ) ; } return false ; } | esegue la rimozione dell elemento dal db |
44,285 | public static function schema ( ) { $ classname = get_called_class ( ) ; if ( ! array_key_exists ( $ classname , self :: $ schemas ) ) { $ schema = new SchemaBuilder ( static :: table ( ) ) ; static :: define ( $ schema ) ; self :: $ schemas [ $ classname ] = $ schema ; } return self :: $ schemas [ $ classname ] ; } | produce lo schema del modello |
44,286 | public function pipe ( CommandMessage $ message ) : void { $ filter = $ this -> stack -> pop ( ) ; $ filter -> process ( $ message , [ $ this , 'pipe' ] ) ; } | Pipes command message to the next filter |
44,287 | public function setRoutePrefixes ( $ routeNamePrefix , $ routePatternPrefix ) { $ this -> setRouteNamePrefix ( $ routeNamePrefix ) ; $ this -> setRoutePatternPrefix ( $ routePatternPrefix ) ; return $ this ; } | Sets the route name and pattern prefixes . |
44,288 | public function setActionOption ( $ actionName , $ optionName , $ optionValue ) { $ this -> getAction ( $ actionName ) -> setOption ( $ optionName , $ optionValue ) ; return $ this ; } | Shortcut for setting options to actions . |
44,289 | protected function getDatabaseConfig ( ) { if ( $ this -> app -> config ( ) [ 'use_cache' ] ) { $ key = 'rails.ar.dbconfig' ; if ( $ dbConfig = $ this -> app -> getService ( 'rails.cache' ) -> read ( $ key ) ) { return $ dbConfig ; } } $ connections = $ this -> getDatabaseConnections ( ) ; if ( ! $ connections ) { return [ [ ] , null , null ] ; } $ config = $ this -> app -> config ( ) ; if ( $ config [ 'active_record' ] [ 'allow_profiler' ] === null ) { $ allowProfiler = ( $ config [ 'environment' ] == 'production' || $ config [ 'environment' ] == 'test' ) ; } else { $ allowProfiler = ( bool ) $ config [ 'active_record' ] [ 'allow_profiler' ] ; } $ options = [ 'allowProfiler' => $ allowProfiler ] ; if ( isset ( $ connections [ $ config [ 'environment' ] ] ) ) { $ defaultConnction = $ config [ 'environment' ] ; } elseif ( isset ( $ connections [ 'default' ] ) ) { $ defaultConnction = 'default' ; } else { $ defaultConnction = key ( $ connections ) ; } $ dbConfig = [ $ connections , $ defaultConnction , $ options ] ; if ( $ this -> app -> config ( ) [ 'use_cache' ] ) { $ this -> app -> getService ( 'rails.cache' ) -> write ( $ key , $ dbConfig ) ; } return $ dbConfig ; } | Get database configuration |
44,290 | protected function getDatabaseConnections ( ) { $ configFile = $ this -> findDatabaseFile ( ) ; if ( ! $ configFile ) { return false ; } switch ( substr ( $ configFile , - 3 ) ) { case 'php' : $ connections = require $ configFile ; break ; case 'yml' : $ connections = Yaml :: readFile ( $ configFile ) ; break ; } return $ connections ; } | Get database connections Gets the configuration from the database file . |
44,291 | public static function getCurrentMonthDaysRange ( $ keyFormat = 'Y-m-d' , $ interval = '1 day' ) { $ start = Carbon :: now ( ) -> subMonth ( 1 ) -> setTime ( 0 , 0 ) ; $ end = Carbon :: now ( ) -> setTime ( 23 , 59 , 59 ) ; $ range = new Collection ; foreach ( new DatePeriod ( $ start , DateInterval :: createFromDateString ( $ interval ) , $ end ) as $ period ) { $ range -> put ( $ period -> format ( $ keyFormat ) , $ period ) ; } return compact ( 'start' , 'end' , 'range' ) ; } | Get current month s days range . |
44,292 | protected function runWithCustomDispatcher ( Request $ request ) { list ( $ class , $ method ) = explode ( '@' , $ this -> action [ 'uses' ] ) ; $ dispatcher = $ this -> container -> make ( 'illuminate.route.dispatcher' ) ; return $ dispatcher -> dispatch ( $ this , $ request , $ class , $ method ) ; } | Send the request and route to a custom dispatcher for handling . |
44,293 | public function actionIndex ( $ option = null ) { $ option = Question :: displayWithQuit ( 'Select operation' , [ 'Update' , 'Delete' ] , $ option ) ; $ project = env ( 'project' ) ; if ( $ option == 'u' ) { $ projectInput = Question :: displayWithQuit ( 'Select project' , [ 'common' , $ project ] ) ; $ project = $ projectInput == 'c' ? 'common' : $ project ; $ result = Environments :: update ( $ project ) ; Output :: arr ( $ result , 'Result' ) ; } elseif ( $ option == 'd' ) { $ projectInput = Question :: displayWithQuit ( 'Select project' , [ 'common' , $ project ] ) ; $ project = $ projectInput == 'c' ? 'common' : $ project ; $ result = Environments :: delete ( $ project ) ; Output :: arr ( $ result , 'Result' ) ; } } | Manage project initialization files |
44,294 | protected static function detectDevice ( ) { $ detect = new MobileDetect ( ) ; self :: $ detectCode = array ( ) ; self :: $ detectCode [ 'tablet' ] = $ detect -> isTablet ( ) ; self :: $ detectCode [ 'mobile' ] = $ detect -> isMobile ( ) && ! $ detect -> isTablet ( ) ; self :: $ detectCode [ 'desktop' ] = ! self :: $ detectCode [ 'tablet' ] && ! self :: $ detectCode [ 'mobile' ] ; self :: $ detectCode [ 'device' ] = 'desktop' ; foreach ( $ detect -> getRules ( ) as $ name => $ regex ) { if ( $ detect -> { 'is' . $ name } ( ) ) { self :: $ detectCode [ 'device' ] = $ name ; break ; } } } | Permet l identification de la plate - forme |
44,295 | private function uniqueSlug ( $ bean , $ property_name , $ slug ) { $ other = \ R :: findOne ( $ bean -> getMeta ( 'type' ) , $ property_name . ' = ? ' , [ $ slug ] ) ; if ( $ other ) { if ( $ other -> id == $ bean -> id ) { return true ; } else { return false ; } } else { return true ; } } | Checks if the slug of a bean is unique |
44,296 | private function makeSlug ( $ bean , $ property_name , $ slug_string ) { $ string = $ this -> neatTrim ( $ slug_string , 100 ) ; $ slug = $ this -> slugify ( $ string ) ; if ( $ this -> uniqueSlug ( $ bean , $ property_name , $ slug ) ) { return $ slug ; } else { return $ this -> makeSlug ( $ bean , $ property_name , $ slug . '-' . uniqid ( ) ) ; } } | Returns a unique slug for a bean with a maximum of 100 characters with complete words . |
44,297 | public function realpath ( $ path ) { $ path = str_replace ( '\\' , '/' , rtrim ( $ path , '/' ) ) ; if ( $ path [ 0 ] != '/' && ( strlen ( $ path ) < 2 || $ path [ 1 ] != ':' ) ) { $ path = getcwd ( ) . '/' . $ path ; } $ parts = explode ( '/' , $ path ) ; $ path = [ ] ; foreach ( $ parts as $ part ) { if ( $ part == '..' ) { array_pop ( $ path ) ; } else if ( $ part != '.' ) { array_push ( $ path , $ part ) ; } } return implode ( '/' , $ path ) ; } | Makes the path absolute and removes . and .. directories from it . |
44,298 | public function glob ( $ pattern ) { $ matched = [ ] ; $ pattern = $ this -> realpath ( $ pattern ) ; $ pattern = '@^' . str_replace ( [ '\*' , '\?' ] , [ '[^\\\/]*' , '.' ] , preg_quote ( $ pattern ) ) . '$@' ; foreach ( array_keys ( $ this -> files ) as $ path ) { if ( preg_match ( $ pattern , $ path ) ) $ matched [ ] = $ path ; } return $ matched ; } | Equivalent to PHP glob function . |
44,299 | public function isFile ( $ path ) { $ node = $ this -> at ( $ path ) ; return null !== $ node && 'file' === $ node -> type ; } | Equivalent to PHP is_file function . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.