idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
26,400 | protected function setLocalCache ( FilesystemInterface $ filesystem , string $ absoluteFilePath , $ content ) : FunctionsInterface { $ this -> set ( 'localCacheFilePath' , $ this -> get ( 'localCacheDirectory' ) . '/' . sha1 ( Config :: APPLICATION_KEY ) . '/' . sha1 ( $ absoluteFilePath ) . '.' . $ this -> getFileExtension ( $ absoluteFilePath ) ) ; $ filesystem -> write ( $ this -> get ( 'localCacheFilePath' ) , ( string ) $ content ) ; return $ this ; } | Cache a local file to disk . |
26,401 | protected function _checkType ( $ value , $ type ) { if ( $ value === null && $ type != 'bool' ) { return true ; } switch ( $ type ) { case 'int' : $ reducer = function ( $ result , $ value ) { if ( ! is_int ( $ value ) ) { $ result = false ; } return $ result ; } ; break ; case 'float' : $ reducer = function ( $ result , $ value ) { if ( ! is_float ( $ value ) ) { $ result = false ; } return $ result ; } ; break ; case 'bool' : $ reducer = function ( $ result , $ value ) { if ( ! is_bool ( $ value ) ) { $ result = false ; } return $ result ; } ; break ; default : ExceptionHandler :: notice ( "Invalid property type $type" ) ; return false ; } if ( is_array ( $ value ) ) { $ result = array_reduce ( $ value , $ reducer , true ) ; } else { $ result = $ reducer ( true , $ value ) ; } return $ result ; } | Check the type of the provided value . |
26,402 | protected function _parseMarker ( $ marker , $ parameter , $ brace ) { $ brace = strtolower ( $ brace ) ; $ result = [ 'uid' => md5 ( uniqid ( $ parameter , true ) ) , 'force-type' => null , 'identifier' => false ] ; if ( $ marker == '#' ) { assert ( '$brace == \'\'' ) ; $ brace = 'int' ; } elseif ( $ marker == '$' ) { assert ( '$brace == \'\'' ) ; $ brace = 'identifier' ; } switch ( $ brace ) { case 'int' : case 'float' : case 'bool' : $ result [ 'force-type' ] = $ brace ; break ; case 'ident' : case 'identifier' : $ result [ 'identifier' ] = true ; break ; default : if ( $ brace != '' ) { throw new InvalidSyntaxException ( "Invalid type-hint '$brace' encountered" ) ; } } if ( $ parameter == '' ) { throw new InvalidSyntaxException ( 'Invalid parameter name' ) ; } $ result [ 'parameter' ] = $ parameter ; return $ result ; } | Parse the contents of a QueryBuilder marker . |
26,403 | public function compose ( SQL $ SQL ) { $ tokens = [ ] ; $ query_string = '' ; foreach ( $ this -> _values as $ name => $ value ) { $ this -> _checkParameter ( $ name , $ value ) ; assert ( 'is_array($this->_parameters[$name])' ) ; $ prepared_value = $ this -> _prepareValue ( $ value , $ SQL , $ this -> _parameters [ $ name ] [ 'identifier' ] ) ; $ tokens [ $ this -> _parameters [ $ name ] [ 'uid' ] ] = $ prepared_value ; } foreach ( $ this -> _query as $ query_part ) { list ( $ token , $ value ) = explode ( ' ' , $ query_part , 2 ) ; switch ( $ token ) { case 'P' : if ( isset ( $ tokens [ $ value ] ) ) { $ query_string .= $ tokens [ $ value ] ; } break ; case 'T' : $ query_string .= $ value ; break ; default : ExceptionHandler :: notice ( "Invalid token $token" ) ; } } return $ query_string ; } | Composes the query present in this QueryBuilder instance . |
26,404 | protected function _prepareValue ( $ value , SQL $ SQL , $ identifier = false ) { assert ( '!(!is_string($value) && $identifier)' ) ; if ( is_string ( $ value ) ) { if ( strtoupper ( $ value ) == 'NULL' ) { $ value = 'NULL' ; } elseif ( $ identifier ) { $ quote = self :: IDENTIFIER_QUOTE ; $ value = str_replace ( $ quote , $ quote . $ quote , $ value ) ; $ value = $ quote . $ value . $ quote ; } else { $ value = '\'' . $ SQL -> escapeString ( $ value ) . '\'' ; } } elseif ( is_int ( $ value ) ) { $ value = ( string ) $ value ; } elseif ( is_float ( $ value ) ) { $ value = ( string ) $ value ; assert ( '!preg_match(\'/[^\d.e+\-]/i\', $value)' ) ; $ value = preg_replace ( '/[^\d.e+\-]/i' , '' , $ value ) ; } elseif ( is_bool ( $ value ) ) { $ value = ( string ) ( ( int ) $ value ) ; } elseif ( $ value === null ) { $ value = 'NULL' ; } elseif ( is_array ( $ value ) ) { $ is_string = null ; $ callback = function ( $ value ) use ( $ SQL , & $ is_string ) { assert ( 'is_string($value) || is_int($value)' ) ; if ( ! is_int ( $ value ) ) $ value = ( string ) $ value ; assert ( '$is_string === null || is_string($value) === $is_string' ) ; if ( is_string ( $ value ) ) $ is_string = true ; return $ SQL -> escapeString ( $ value ) ; } ; array_map ( $ callback , $ value ) ; $ value = implode ( ',' , $ value ) ; if ( $ is_string ) $ value = "'{$value}'" ; } elseif ( is_object ( $ value ) ) { $ value = '\'' . $ SQL -> escapeString ( serialize ( $ value ) ) . '\'' ; } else { throw new QueryBuilderException ( 'Data of type "' . gettype ( $ value ) . '" cannot be used in an SQL-query' ) ; } return $ value ; } | Prepares a variable to be inserted into an SQL Query . |
26,405 | public function execute ( SQL $ SQL , $ return_set = false , $ buffered = true ) { $ query_string = $ this -> compose ( $ SQL ) ; $ this -> reset ( ) ; return $ SQL -> Query ( $ query_string , $ return_set , $ buffered ) ; } | Execute the query and reset the object s state . |
26,406 | public function loadClassMetadata ( LoadClassMetadataEventArgs $ class ) { $ metaData = $ class -> getClassMetadata ( ) ; $ adoptees = $ this -> collector -> getAdoptees ( $ metaData -> name ) ; foreach ( $ adoptees as $ discriminator => $ adoptee ) { $ metaData -> discriminatorMap [ $ discriminator ] = $ adoptee ; } } | Handle LoadClassMetadataEvents to inject adoptees . |
26,407 | public static function toNative ( $ callback ) { if ( ! is_array ( $ callback ) ) { return self :: getNative ( $ callback ) ; } if ( ! array_key_exists ( '0' , $ callback ) ) { return self :: getFromDict ( $ callback ) ; } if ( ! array_key_exists ( 2 , $ callback ) ) { return self :: getNative ( $ callback ) ; } return self :: getFromList ( $ callback ) ; } | Separates a native callback and bound arguments |
26,408 | public static function bindInstance ( $ instance , $ methodName , $ args = null ) { $ helper = new self ( ) ; return $ helper -> createClosure ( $ methodName , $ args ) -> bindTo ( $ instance , get_class ( $ instance ) ) ; } | Binds an instance with its method |
26,409 | public static function bindStatic ( $ className , $ methodName , $ args = null ) { if ( empty ( $ args ) ) { $ args = null ; } $ native = [ $ className , $ methodName ] ; $ callback = function ( ) use ( $ native , $ args ) { $ a = func_get_args ( ) ; if ( $ args !== null ) { $ a = array_merge ( $ a , $ args ) ; } return call_user_func_array ( $ native , $ a ) ; } ; return $ callback -> bindTo ( null , $ className ) ; } | Binds a class with its static method |
26,410 | public static function find ( $ usernameOrId , string $ password = "" ) { self :: check ( ) ; if ( is_numeric ( $ usernameOrId ) ) { $ bean = R :: load ( 'user' , $ usernameOrId ) ; } else { $ userdbname = setup :: getValidation ( "username" ) ; if ( $ password != "" ) { $ pwdbname = setup :: getValidation ( "password" ) ; $ bean = R :: findOne ( 'user' , ' ' . $ userdbname . ' = ? AND ' . $ pwdbname . ' = ? ' , [ $ usernameOrId , setup :: doHash ( $ password ) ] ) ; } else { $ bean = R :: findOne ( 'user' , ' ' . $ userdbname . ' = ? ' , [ $ usernameOrId ] ) ; } } if ( ! is_null ( $ bean ) ) { return new self ( "" , $ bean ) ; } return false ; } | find a user |
26,411 | public static function guest ( ) : user { self :: check ( ) ; $ userdbname = setup :: getValidation ( "username" ) ; return new self ( "" , R :: findOne ( 'user' , ' ' . $ userdbname . ' = ? ' , [ "guest" ] ) ) ; } | return a guest user |
26,412 | public function setRole ( string $ role ) { $ this -> user -> role = role :: get ( $ role ) ; R :: store ( $ this -> user ) ; } | set role of user |
26,413 | private function filter ( string $ class ) : bool { foreach ( $ this -> patterns as $ pattern ) { if ( preg_match ( $ pattern , $ class ) === 1 ) { return false ; } } return true ; } | Return whether the given class name is not matching any pattern . |
26,414 | public function getSourceCode ( $ initialIdent = 4 ) { $ file = explode ( PHP_EOL , file_get_contents ( $ this -> getFileName ( ) ) ) ; $ funcOpenLine = $ file [ $ this -> getStartLine ( ) - 1 ] ; $ funcOpenLine = rtrim ( substr ( $ funcOpenLine , strpos ( $ funcOpenLine , 'function' ) ) ) ; $ funcCloseLine = $ file [ $ this -> getEndLine ( ) - 1 ] ; $ funcCloseLine = ltrim ( substr ( $ funcCloseLine , 0 , strpos ( $ funcCloseLine , '}' ) + 1 ) ) ; $ source = $ funcOpenLine . $ this -> getContents ( $ initialIdent , false ) . $ funcCloseLine ; return $ source ; } | Get source code of closure |
26,415 | public function getContents ( $ initialIdent = 4 , $ trimFirstAndLastLineBreak = true ) { $ file = explode ( PHP_EOL , file_get_contents ( $ this -> getFileName ( ) ) ) ; $ startLine = $ this -> getStartLine ( ) ; $ endLine = $ this -> getEndLine ( ) - 1 ; $ contents = PHP_EOL ; $ subStrStart = false ; while ( $ startLine < $ endLine ) { $ line = $ file [ $ startLine ] ; if ( ! $ subStrStart ) { $ numberOfWhiteSpace = strspn ( $ line , ' ' ) ; $ subStrStart = $ numberOfWhiteSpace - $ initialIdent ; } $ contents .= substr ( rtrim ( $ line ) , $ subStrStart ) . PHP_EOL ; $ startLine ++ ; } if ( $ trimFirstAndLastLineBreak ) { $ contents = ltrim ( rtrim ( $ contents , PHP_EOL ) , PHP_EOL ) ; } return $ contents ; } | Get contents of closure |
26,416 | public static function hide ( $ script , $ openTag , $ closeTag ) { $ data = Strings :: splite ( $ script , $ openTag ) ; $ output = $ data [ 0 ] ; for ( $ i = 1 ; $ i < Collection :: count ( $ data ) ; $ i ++ ) { $ output .= '' ; $ next = Strings :: splite ( $ data [ $ i ] , $ closeTag ) ; $ output .= '' ; for ( $ j = 1 ; $ j < Collection :: count ( $ next ) ; $ j ++ ) { if ( $ j == ( Collection :: count ( $ next ) - 1 ) ) { $ output .= $ next [ $ j ] ; } else { $ output .= $ next [ $ j ] . $ closeTag ; } } } return $ output ; } | To hide de comment that user write . |
26,417 | private function search_term ( $ table , $ colname , $ term ) { $ searchio = $ this -> readdb ( $ table , $ colname ) ; $ returnrows = array ( ) ; foreach ( $ searchio as $ drowname => $ drowval ) { if ( empty ( $ term ) || count ( $ term ) < 1 ) { continue ; } $ termcounter = $ this -> matches ( $ drowval , $ term ) ; if ( $ termcounter > 0 ) { $ returnrows [ $ drowname ] = $ termcounter ; } } return $ returnrows ; } | Will be return as array contains row key = > how many time matched |
26,418 | public function add ( $ table , $ rowArr ) { $ editId = $ this -> rows ( $ table ) ; if ( $ this -> edit_id != null ) { $ editId = $ this -> edit_id ; } foreach ( $ this -> cols [ $ table ] as $ colname ) { $ this -> rows [ $ table ] [ $ colname ] [ $ editId ] = $ rowArr [ $ colname ] ; } return $ editId ; } | Add new row |
26,419 | public function edit ( $ table , $ rowArr , $ id ) { $ this -> edit_id = $ id ; $ this -> add ( $ table , $ rowArr ) ; } | Edit to exists row |
26,420 | public function save ( ) { foreach ( $ this -> cols as $ table => $ prkey ) { foreach ( $ prkey as $ prkey_ ) { if ( strlen ( $ prkey_ ) < 3 ) { continue ; } $ this -> writedb ( $ table , $ prkey_ ) ; } $ this -> rows [ $ table ] [ 'index' ] = $ this -> indexData [ $ table ] ; try { $ this -> writedb ( $ table , 'index' ) ; } catch ( Exception $ aa ) { return false ; } } return true ; } | running one more time . |
26,421 | public function check ( $ table , $ colname , $ val ) { $ oldvals = $ this -> readdb ( $ table , $ colname ) ; if ( $ oldvals && is_array ( $ oldvals ) ) { $ oldvals = array_flip ( $ oldvals ) ; } if ( isset ( $ oldvals [ $ val ] ) ) { return true ; } return false ; } | Return as boolean |
26,422 | public function index ( ) { $ this -> Crud -> on ( 'beforePaginate' , function ( Event $ event ) { $ query = $ this -> Users -> find ( 'search' , $ this -> request -> query ) ; $ query = $ query -> select ( [ 'id' , 'username' ] ) ; $ event -> subject -> query = $ query ; } ) ; $ this -> Crud -> execute ( ) ; } | Currently used as a search function uses username as the param |
26,423 | public function add ( ) { $ this -> Crud -> on ( 'afterSave' , function ( Event $ event ) { if ( $ event -> subject -> created ) { $ token = [ 'id' => $ event -> subject -> entity -> id , 'exp' => time ( ) + 60 * 60 * 24 * 7 , ] ; $ this -> set ( 'data' , [ 'id' => $ event -> subject -> entity -> id , 'token' => JWT :: encode ( $ token , Security :: salt ( ) ) ] ) ; $ this -> Crud -> action ( ) -> config ( 'serialize.data' , 'data' ) ; } $ signupEvent = new Event ( 'Users.afterSignup' , $ event -> subject ( ) ) ; $ this -> eventManager ( ) -> dispatch ( $ signupEvent ) ; } ) ; return $ this -> Crud -> execute ( ) ; } | Regular register method now also returns a token upon registration token expiration is set for 1 week |
26,424 | public function token ( ) { $ user = $ this -> Auth -> identify ( ) ; if ( ! $ user ) { throw new UnauthorizedException ( 'Invalid username or password' ) ; } $ token = [ 'id' => $ user [ 'id' ] , 'exp' => time ( ) + 60 * 60 * 24 * 7 ] ; $ this -> set ( [ 'success' => true , 'data' => [ 'token' => JWT :: encode ( $ token , Security :: salt ( ) ) ] , '_serialize' => [ 'success' , 'data' ] ] ) ; } | Tries to authentify user based on POST data and returns a private token |
26,425 | public function guess ( $ path ) { $ ext = strtolower ( pathinfo ( $ path , PATHINFO_EXTENSION ) ) ; if ( isset ( $ this -> extensions [ $ ext ] ) ) { return $ this -> extensions [ $ ext ] ; } return $ this -> parent -> guess ( $ path ) ; } | Guesses the mime type of the file with the given path . |
26,426 | public function addServer ( $ host , $ port = 11211 , $ weight = 0 ) { $ key = $ this -> getServerKey ( $ host , $ port , $ weight ) ; if ( isset ( $ this -> server [ $ key ] ) ) { $ this -> resultCode = Memcached :: RES_FAILURE ; $ this -> resultMessage = 'Server duplicate.' ; return false ; } else { $ this -> server [ $ key ] = array ( 'host' => $ host , 'port' => $ port , 'weight' => $ weight , ) ; $ this -> connect ( ) ; return true ; } } | Add a serer to the server pool |
26,427 | public function addServers ( $ servers ) { foreach ( ( array ) $ servers as $ svr ) { $ host = array_shift ( $ svr ) ; $ port = array_shift ( $ svr ) ; if ( is_null ( $ port ) ) { $ port = 11211 ; } $ weight = array_shift ( $ svr ) ; if ( is_null ( $ weight ) ) { $ weight = 0 ; } $ this -> addServer ( $ host , $ port , $ weight ) ; } return true ; } | Add multiple servers to the server pool |
26,428 | protected function connect ( ) { $ rs = false ; foreach ( ( array ) $ this -> server as $ svr ) { $ error = 0 ; $ errstr = '' ; $ rs = @ fsockopen ( $ svr [ 'host' ] , $ svr [ 'port' ] , $ error , $ errstr ) ; if ( $ rs ) { $ this -> socket = $ rs ; } else { $ key = $ this -> getServerKey ( $ svr [ 'host' ] , $ svr [ 'port' ] , $ svr [ 'weight' ] ) ; $ s = "Connect to $key error:" . PHP_EOL . " [$error] $errstr" ; error_log ( $ s ) ; } } if ( is_null ( $ this -> socket ) ) { $ this -> resultCode = Memcached :: RES_FAILURE ; $ this -> resultMessage = 'No server avaliable.' ; return false ; } else { $ this -> resultCode = Memcached :: RES_SUCCESS ; $ this -> resultMessage = '' ; return true ; } } | Connect to memcached server |
26,429 | public function get ( $ key , $ cache_cb = null , $ cas_token = null ) { $ keyString = $ this -> getKey ( $ key ) ; $ this -> writeSocket ( "get $keyString" ) ; $ s = $ this -> readSocket ( ) ; if ( is_null ( $ s ) || 'VALUE' != substr ( $ s , 0 , 5 ) ) { $ this -> resultCode = Memcached :: RES_FAILURE ; $ this -> resultMessage = 'Get fail.' ; return false ; } else { $ s_result = '' ; $ s = $ this -> readSocket ( ) ; while ( 'END' != $ s ) { $ s_result .= $ s ; $ s = $ this -> readSocket ( ) ; } $ this -> resultCode = Memcached :: RES_SUCCESS ; $ this -> resultMessage = '' ; return unserialize ( $ s_result ) ; } } | Retrieve an item |
26,430 | public function getOption ( $ option ) { if ( isset ( $ this -> option [ $ option ] ) ) { $ this -> resultCode = Memcached :: RES_SUCCESS ; $ this -> resultMessage = '' ; return $ this -> option [ $ option ] ; } else { $ this -> resultCode = Memcached :: RES_FAILURE ; $ this -> resultMessage = 'Option not seted.' ; return false ; } } | Get a memcached option value |
26,431 | public function set ( $ key , $ val , $ expt = 0 ) { $ valueString = serialize ( $ val ) ; $ keyString = $ this -> getKey ( $ key ) ; $ this -> writeSocket ( "set $keyString 0 $expt " . strlen ( $ valueString ) ) ; $ s = $ this -> writeSocket ( $ valueString , true ) ; if ( 'STORED' == $ s ) { $ this -> resultCode = Memcached :: RES_SUCCESS ; $ this -> resultMessage = '' ; return true ; } else { $ this -> resultCode = Memcached :: RES_FAILURE ; $ this -> resultMessage = 'Set fail.' ; return false ; } } | Store an item |
26,432 | public function increment ( $ key , $ offset = 1 , $ initial_value = 0 , $ expiry = 0 ) { if ( ( $ prevVal = $ this -> get ( $ key ) ) ) { if ( ! is_numeric ( $ prevVal ) ) { return false ; } $ newVal = $ prevVal + $ offset ; } else { $ newVal = $ initial_value ; } $ this -> set ( $ key , $ newVal , $ expiry ) ; return $ newVal ; } | Increment numeric item s value |
26,433 | public function actionFix ( $ root = null ) { $ files = $ this -> findFiles ( $ root ) ; $ nFilesTotal = 0 ; $ nFilesUpdated = 0 ; foreach ( $ files as $ file ) { $ contents = file_get_contents ( $ file ) ; $ sha = sha1 ( $ contents ) ; $ lines = preg_split ( '/(\r\n|\n|\r)/' , $ contents ) ; $ this -> fixFileDoc ( $ lines , $ file ) ; $ newContent = implode ( "\n" , $ lines ) ; if ( $ sha !== sha1 ( $ newContent ) ) { $ nFilesUpdated ++ ; } file_put_contents ( $ file , $ newContent ) ; $ nFilesTotal ++ ; } $ this -> stdout ( "\nParsed $nFilesTotal files.\n" ) ; $ this -> stdout ( "Updated $nFilesUpdated files.\n" ) ; } | Fix some issues with PHPdoc in files . |
26,434 | protected function prefillHeader ( ) { if ( $ this -> requiresAuthorization ( ) && ! empty ( $ this -> getAuthorizationHeader ( ) ) ) { $ this -> headers [ 'Authorization' ] = $ this -> getAuthorizationHeader ( ) ; } return $ this ; } | Pre - fills the request header with some default values as required . |
26,435 | public function addBodyParam ( string $ name , $ value , bool $ overwrite = false ) { $ keyExists = array_key_exists ( $ name , $ this -> body ) ; if ( $ keyExists && ! $ overwrite ) { return $ this ; } if ( is_null ( $ value ) ) { if ( $ keyExists ) { unset ( $ this -> body [ $ name ] ) ; } return $ this ; } if ( is_null ( $ value ) ) { unset ( $ this -> query [ $ name ] ) ; return $ this ; } $ this -> body [ $ name ] = $ value ; return $ this ; } | Adds a parameter to the body of the request . |
26,436 | public function addMultipartParam ( string $ name , $ content , string $ filename = null , bool $ overwrite = false ) { if ( array_key_exists ( $ name , $ this -> multipart ) && ! $ overwrite ) { return $ this ; } $ part = [ 'name' => $ name , 'contents' => $ content ] ; if ( ! empty ( $ filename ) ) { $ part [ 'filename' ] = $ filename ; } $ this -> multipart [ ] = $ part ; return $ this ; } | Adds some multipart data to the request body . |
26,437 | public function send ( string $ method , Client $ httpClient , array $ path = [ ] ) : DorcasResponse { $ this -> prefillHeader ( ) ; $ this -> prefillBody ( ) ; if ( strtolower ( $ method ) !== 'get' ) { $ this -> validate ( ) ; } $ uri = static :: getRequestUrl ( $ path ) ; $ url = $ uri -> getScheme ( ) . '://' . $ uri -> getAuthority ( ) . $ uri -> getPath ( ) ; try { $ options = [ ] ; if ( ! empty ( $ this -> headers ) ) { $ options [ RequestOptions :: HEADERS ] = $ this -> headers ; } if ( ! empty ( $ uri -> getQuery ( ) ) ) { $ options [ RequestOptions :: QUERY ] = parse_query_parameters ( $ uri -> getQuery ( ) ) ; } if ( strtolower ( $ method ) !== 'get' ) { if ( ! empty ( $ this -> multipart ) ) { foreach ( $ this -> body as $ key => $ value ) { $ this -> multipart [ ] = [ 'name' => $ key , 'contents' => $ value ] ; } $ options [ RequestOptions :: MULTIPART ] = $ this -> multipart ; } elseif ( static :: isJsonRequest ( ) && ! empty ( $ this -> body ) ) { $ options [ RequestOptions :: JSON ] = $ this -> body ; } elseif ( ! empty ( $ this -> body ) ) { $ options [ RequestOptions :: FORM_PARAMS ] = $ this -> body ; } } $ response = $ httpClient -> request ( $ method , $ url , $ options ) ; return new DorcasResponse ( ( string ) $ response -> getBody ( ) ) ; } catch ( BadResponseException $ e ) { return new DorcasResponse ( ( string ) $ e -> getResponse ( ) -> getBody ( ) , $ e -> getResponse ( ) -> getStatusCode ( ) , $ e -> getRequest ( ) ) ; } catch ( ConnectException $ e ) { return new DorcasResponse ( '{"status": "error", "data": "' . $ e -> getMessage ( ) . '"}' , 0 ) ; } } | Sends a HTTP request . |
26,438 | public function validate ( $ logger ) { $ original = $ logger ; if ( is_callable ( $ logger ) ) { $ logger = $ logger ( $ this -> container ) ; } if ( $ logger instanceof LoggerInterface ) { return $ original ; } return function ( $ app ) { return new NullLogger ( ) ; } ; } | Validates the configured logger . If no logger is configured or if the configured logger isn t PSR - 3 compliant an instance of NullLogger will be used instead . |
26,439 | protected function buildVersion ( $ asset ) { $ version = $ this -> getVersion ( ) ; if ( is_callable ( $ version ) ) { $ version = $ version ( $ this -> getBasePath ( ) . $ asset , $ this ) ; } return $ version ; } | Build the version of the asset . If callable is given the arguments are full filename and this instance |
26,440 | protected function buildCompileDirectory ( ) { $ directory = $ this -> getBasePath ( ) . '/' . $ this -> getCompileDirectory ( ) ; if ( ! is_dir ( $ directory ) ) mkdir ( $ directory , 0777 , true ) ; return $ directory ; } | Build the directory name of the compile . If directory not exists it s created . |
26,441 | public static function createFromConfig ( array $ config ) { $ manager = static :: createEmptyFromConfig ( $ config ) ; $ manager -> addCollection ( new CssCollection ) -> addCollection ( new JavascriptCollection ) ; return $ manager ; } | Creates and configure a manager instance via array options |
26,442 | public static function createEmptyFromConfig ( array $ config ) { $ manager = new self ( ) ; if ( isset ( $ config [ 'base_uri' ] ) ) { $ manager -> setBaseUri ( $ config [ 'base_uri' ] ) ; } if ( isset ( $ config [ 'path' ] ) ) { $ manager -> setBasePath ( $ config [ 'path' ] ) ; } if ( isset ( $ config [ 'path_aliases' ] ) && is_array ( $ config [ 'path_aliases' ] ) ) { foreach ( $ config [ 'path_aliases' ] as $ alias => $ path ) { $ manager -> addPathAlias ( $ alias , $ path ) ; } } if ( isset ( $ config [ 'compiled' ] ) ) { $ manager -> setCompileDirectory ( $ config [ 'compiled' ] ) ; } if ( isset ( $ config [ 'version' ] ) ) { $ manager -> setVersion ( $ config [ 'version' ] ) ; } return $ manager ; } | Creates and configure a empty manager instance via array options |
26,443 | public function url ( $ asset ) { $ url = $ this -> parsePathAlias ( $ asset , false ) ; return $ this -> buildUrl ( $ url ) ; } | Create an url to a any asset . Is a way to use images with this class |
26,444 | public function recover ( ) { if ( ! $ this -> isRecoverable ( ) ) { throw new Exception \ BadMethodCallException ( sprintf ( "Object of class %s isn't recoverable" , get_class ( $ this ) ) ) ; } if ( $ this -> isDeleted ( ) ) { $ this -> runCallbacks ( 'recover' , function ( ) { $ this -> directUpdate ( static :: deletedAtAttribute ( ) , static :: deletedAtEmptyValue ( ) ) ; $ this -> reload ( ) ; } ) ; } return true ; } | Recovers a deleted object by setting the DELETED_AT_ATTRIBUTE to null . If the object is not deleted no action is taken . If the object isn t recoverable however an exception is thrown . recover callbacks are ran if the record is recovered . Note that the attribute is directly updated in the database so no save or update callbacks are ran . Also any change made to the model is discarted as it is reloaded . |
26,445 | protected function deleteRecord ( array $ options = [ ] ) { $ this -> runCallbacks ( 'delete' , function ( ) { if ( ! $ this -> deletedAt ( ) ) { $ this -> directUpdate ( static :: deletedAtAttribute ( ) , static :: deletedAtValue ( ) ) ; $ this -> reload ( ) ; } } ) ; return true ; } | Soft - deletes the record . If the record is already deleted no action is taken . The delete callbacks are ran if the record is deleted . Like in recover the attribute is directly updated in the database so no save or update callbacks are ran and any change made to the model is discarted as it is reloaded . |
26,446 | protected function destroyRecord ( array $ options = [ ] ) { return $ this -> runCallbacks ( 'destroy' , function ( ) { if ( static :: persistence ( ) -> delete ( $ this ) ) { $ this -> isDestroyed = true ; return true ; } return false ; } ) ; } | Removes the record from the database . The destroy callbacks are ran . |
26,447 | public function convert ( string $ outputFile , string $ format , array $ params = array ( ) ) : ExportResult { try { $ this -> getVerb ( ) -> setOutputFile ( $ outputFile ) -> setFormat ( $ format ) -> setParameters ( $ params ) ; $ result = self :: getCommand ( ) -> execute ( $ this -> getVerb ( ) ) ; if ( ! $ result -> isSuccess ( ) ) { if ( $ result -> hasException ( ) ) { throw $ result -> getException ( ) ; } throw new \ RuntimeException ( 'Unknown error: ' , $ result -> getExitCode ( ) ) ; } return $ result ; } catch ( \ Exception $ e ) { throw new ConverterException ( 'Conversion failed' , ErrorCodes :: EXECUTION_FAILURE , $ e ) ; } } | Convert a file |
26,448 | public static function getCommand ( ) : Command { if ( is_null ( self :: $ exec ) ) { self :: $ exec = new Command ( ) ; } return self :: $ exec ; } | Get the command singleton |
26,449 | public function combine ( array $ keys = null , array $ values = null ) { return array_combine ( $ keys ? : $ this -> members , $ values ? : $ this -> members ) ; } | pass null to the component for members to use |
26,450 | public function registerRequestFilter ( array & $ globalConfig , string $ requestFilterClass ) { if ( ! isset ( $ moduleConfig [ self :: CONFIG_FILTERS_REQUEST ] ) ) { $ moduleConfig [ self :: CONFIG_FILTERS_REQUEST ] = [ ] ; } $ globalConfig [ $ this -> getModuleKey ( ) ] [ self :: CONFIG_FILTERS_REQUEST ] [ ] = $ requestFilterClass ; } | Register a filter for a PSR - 7 request . The filter must implement the RequestFilter interface . |
26,451 | public function registerResponseFilterClass ( array & $ globalConfig , string $ responseFilterClass ) { if ( ! isset ( $ moduleConfig [ self :: CONFIG_FILTERS_RESPONSE ] ) ) { $ moduleConfig [ self :: CONFIG_FILTERS_RESPONSE ] = [ ] ; } $ globalConfig [ $ this -> getModuleKey ( ) ] [ self :: CONFIG_FILTERS_RESPONSE ] [ ] = $ responseFilterClass ; } | Register a filter for a PSR - 7 response . The filter must implement the ResponseFilter interface . |
26,452 | public function registerRoutingResponseFilterClass ( array & $ globalConfig , string $ routingResponseFilterClass ) { if ( ! isset ( $ moduleConfig [ self :: CONFIG_FILTERS_ROUTING_RESPONSE ] ) ) { $ moduleConfig [ self :: CONFIG_FILTERS_ROUTING_RESPONSE ] = [ ] ; } $ globalConfig [ $ this -> getModuleKey ( ) ] [ self :: CONFIG_FILTERS_ROUTING_RESPONSE ] [ ] = $ routingResponseFilterClass ; } | Register a filter for the routing response response . The filter must implement the RoutingResponseFilter interface . |
26,453 | private function makeFilters ( array $ filterSpecification , DependencyInjectionContainer $ dic ) : array { $ filters = [ ] ; foreach ( $ filterSpecification as $ requestFilterClass ) { $ filters [ ] = $ dic -> make ( $ requestFilterClass ) ; } return $ filters ; } | Create an array of filter objects from an array of filter class names . |
26,454 | public function actionGenerate ( ) { $ passwordList = \ App :: $ domain -> tool -> password -> generate ( ) ; $ text = implode ( SPC , $ passwordList ) ; Output :: line ( ) ; Output :: pipe ( 'Generated passwords' ) ; Output :: autoWrap ( $ text ) ; Output :: pipe ( ) ; Output :: line ( ) ; } | Generate random password list |
26,455 | public static function crop ( $ txt , int $ maxChars = 20 , string $ etc = '...' ) : string { $ txt = ( string ) $ txt ; if ( mb_strlen ( $ txt , self :: ENCODING ) > $ maxChars ) { return mb_substr ( $ txt , 0 , $ maxChars - mb_strlen ( $ etc , self :: ENCODING ) , self :: ENCODING ) . $ etc ; } return $ txt ; } | Crop a string with a ... if too long |
26,456 | public static function phoneFormat ( $ phoneNumber ) : string { if ( ! $ phoneNumber ) { return ( string ) $ phoneNumber ; } $ prefix = trim ( $ phoneNumber ) [ 0 ] == '+' ; $ value = preg_replace ( '/[^0-9]/' , '' , ( string ) $ phoneNumber ) ; $ valueLen = mb_strlen ( $ value , self :: ENCODING ) ; if ( $ prefix && $ valueLen == 11 ) { $ pattern [ ] = '/([0-9][0-9])([0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])/' ; $ replace [ ] = '$1 ($2) $3 $4 $5 $6' ; } else if ( $ prefix && $ valueLen == 12 && $ value [ 2 ] == 0 ) { $ pattern [ ] = '/([0-9][0-9]).([0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])/' ; $ replace [ ] = '$1 ($2) $3 $4 $5 $6' ; } elseif ( $ valueLen == 12 ) { $ pattern [ ] = '/^([0-9][0-9][0-9])([0-9][0-9][0-9])([0-9][0-9][0-9])([0-9][0-9][0-9])$/' ; $ replace [ ] = '$1 $2 $3 $4 $5' ; } elseif ( $ valueLen == 11 ) { $ pattern [ ] = '/^([0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/' ; $ replace [ ] = '$1 $2 $3 $4' ; } elseif ( $ valueLen == 10 ) { $ pattern [ ] = '/^([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/' ; $ replace [ ] = '$1 $2 $3 $4 $5' ; } elseif ( $ valueLen == 9 ) { $ pattern [ ] = '/^([0-9][0-9][0-9])([0-9][0-9][0-9])([0-9][0-9][0-9])$/' ; $ replace [ ] = '$1 $2 $3' ; } elseif ( $ valueLen == 8 ) { $ pattern [ ] = '/^([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/' ; $ replace [ ] = '$1 $2 $3 $4' ; } elseif ( $ valueLen == 7 ) { $ pattern [ ] = '/^([0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])$/' ; $ replace [ ] = '$1 $2 $3' ; } elseif ( $ valueLen == 6 ) { $ pattern [ ] = '/^([0-9][0-9])([0-9][0-9])([0-9][0-9])$/' ; $ replace [ ] = '$1 $2 $3' ; } if ( ! isset ( $ pattern ) ) { return ( $ prefix ? '+' : '' ) . $ value ; } return ( $ prefix ? '+' : '' ) . trim ( preg_replace ( $ pattern , $ replace , $ value ) ) ; } | Format a phone number |
26,457 | public static function ucPhrase ( $ str ) : string { $ str = mb_strtolower ( self :: cleanPhrase ( $ str ) , self :: ENCODING ) ; $ names = explode ( ' ' , $ str ) ; array_walk ( $ names , 'self::ucFirstTouch' ) ; $ names = explode ( '-' , implode ( ' ' , $ names ) ) ; array_walk ( $ names , 'self::ucFirstTouch' ) ; return implode ( '-' , $ names ) ; } | jean - albert dupont - > Jean - Albert Dupont |
26,458 | public static function percentageFormat ( $ value , bool $ withSymbol = true , int $ precision = 0 ) : string { $ percentValue = round ( ( float ) $ value , $ precision ) ; return $ percentValue . ( $ withSymbol ? ' %' : '' ) ; } | Round and add the % symbol |
26,459 | public static function formatDate ( DateTime $ date , $ locale = null , bool $ short = false ) { $ locale = $ locale ?? 'fr' ; $ localDates = [ 'fr' => $ short ? 'd/m/y' : 'd/m/Y' , 'en' => $ short ? 'd/m/y' : 'd/m/Y' , 'en_US' => $ short ? 'm/d/y' : 'm/d/Y' ] ; return ( string ) $ date -> format ( $ localDates [ $ locale ] ) ; } | Format a date with the specified locale |
26,460 | public static function formatDateTime ( DateTime $ date , $ locale = null , string $ mask = null , bool $ short = false ) : string { $ locale = $ locale ?? 'fr' ; if ( $ mask === null ) { $ localDates = [ 'fr' => $ short ? __ ( "d/m/y H:i" ) : __ ( "d/m/Y H:i" ) , 'en' => $ short ? __ ( "d/m/y H:i" ) : __ ( "d/m/Y H:i" ) , 'en_US' => $ short ? __ ( "m/d/y H:i" ) : __ ( "m/d/Y H:i" ) ] ; $ mask = $ localDates [ $ locale ] ; } return ( string ) $ date -> format ( $ mask ) ; } | Format a datetime with the specified locale |
26,461 | public static function camelCase ( $ word , bool $ ucFirstWord = true ) : string { static $ words = [ ] ; if ( ! isset ( $ words [ $ word ] ) ) { $ words [ $ word ] = str_replace ( ' ' , '' , ucwords ( strtr ( $ word , '_' , ' ' ) ) ) ; if ( ! $ ucFirstWord ) { substr_replace ( $ words [ $ word ] , $ word { 0 } , 0 , 1 ) ; } } return $ words [ $ word ] ; } | some_phrase = > SomePhrase |
26,462 | public static function fromCamelCaseToLower ( $ word , string $ separator = '-' ) : string { $ str = '' ; $ active = false ; $ word = ( string ) $ word ; for ( $ i = 0 ; $ i <= mb_strlen ( $ word ) ; $ i ++ ) { $ char = mb_substr ( $ word , $ i , 1 , self :: ENCODING ) ; $ str .= ( $ active && $ char >= 'A' && $ char <= 'Z' ? $ separator : '' ) . mb_strtolower ( $ char ) ; $ active = $ char !== ' ' ; } return $ str ; } | CamelCase - > camel - case |
26,463 | public static function transliterate ( $ txt ) { if ( $ txt === null ) { return null ; } return strtolower ( \ Patchwork \ Utf8 :: toAscii ( ( string ) $ txt ) ) ; } | Transliteration for a search engine |
26,464 | public static function formatSiret ( $ value ) : string { $ value = ( string ) ( int ) $ value ; if ( ! self :: isSiret ( $ value ) ) { return '' ; } return preg_replace ( '/^([0-9]{3})([0-9]{3})([0-9]{3})([0-9]{5})$/' , '$1 $2 $3 $4' , $ value ) ; } | Format a siret number with 14 digits |
26,465 | public static function siretToSiren ( $ siret , bool $ format = false ) : string { $ value = ( string ) ( int ) $ siret ; if ( ! self :: isSiret ( $ value ) ) { return '' ; } return $ format ? preg_replace ( '/^([0-9]{3})([0-9]{3})([0-9]{3})([0-9]{5})$/' , '$1 $2 $3' , $ value ) : substr ( $ value , 0 , 9 ) ; } | Extract french siren from siret |
26,466 | public static function formatTvaIntra ( $ value ) { $ value = self :: toUpper ( trim ( str_replace ( ' ' , '' , $ value ) ) ) ; return preg_replace ( '/^([A-Z]{2})([0-9]{2})([0-9]{3})([0-9]{3})([0-9]{3})$/' , '$1 $2 $3 $4 $5' , $ value ) ; } | Intracom TVA formatting |
26,467 | public function encode ( $ data ) { if ( ! ( $ data instanceof \ Plinker \ Core \ Exception \ Server ) && isset ( $ data [ 'params' ] ) && is_array ( $ data [ 'params' ] ) ) { foreach ( $ data [ 'params' ] as $ key => $ param ) { if ( is_object ( $ param ) && ( $ param instanceof \ Closure ) ) { $ data [ 'params' ] [ $ key ] = new SerializableClosure ( $ param ) ; } } } $ data = serialize ( $ data ) ; return [ "data" => $ this -> encrypt ( $ data , $ this -> config [ "secret" ] ) , "token" => hash_hmac ( "sha256" , $ data , $ this -> config [ "secret" ] ) ] ; } | Sign and encrypt into payload array . |
26,468 | public function decode ( $ data ) { $ data [ "data" ] = $ this -> decrypt ( $ data [ "data" ] , $ this -> config [ "secret" ] ) ; if ( hash_hmac ( "sha256" , $ data [ "data" ] , $ this -> config [ "secret" ] ) == $ data [ "token" ] ) { return unserialize ( $ data [ "data" ] ) ; } else { throw new \ Exception ( 'Failed to verify payload' ) ; } } | Decrypt verify and unserialize payload . |
26,469 | public function listen ( $ event , callable $ handler ) { if ( empty ( $ this -> handlers [ $ event ] ) ) { $ this -> handlers [ $ event ] = [ ] ; } $ this -> handlers [ $ event ] [ ] = $ handler ; } | Specify an event listener for a project . |
26,470 | protected function trigger ( $ event , ... $ arguments ) { if ( ! empty ( $ this -> handlers [ $ event ] ) ) { foreach ( $ this -> handlers [ $ event ] as $ handler ) { call_user_func_array ( $ handler , $ arguments ) ; } } } | Trigger a particular event . |
26,471 | public function triggerOrderCompleted ( GatewayInterface $ gateway , OrderInterface $ order ) { $ this -> trigger ( self :: ON_ORDER_COMPLETED , $ gateway , $ order ) ; } | Trigger product order completed . |
26,472 | public function triggerSubscriptionDeactivated ( GatewayInterface $ gateway , SubscriptionInterface $ subscription , CancelationInterface $ cancelation ) { $ this -> trigger ( self :: ON_SUBSCRIPTION_DEACTIVATED , $ gateway , $ subscription , $ cancelation ) ; } | Trigger an event when subscription is deactivated . |
26,473 | public function triggerSubscriptionCustomActivated ( SubscriptionInterface $ subscription , $ note ) { $ this -> trigger ( self :: ON_SUBSCRIPTION_CUSTOM_ACTIVATED , $ subscription , $ note ) ; } | Trigger an event when account is activated manually . |
26,474 | public function triggerSubscriptionExpired ( SubscriptionInterface $ subscription , $ note ) { $ this -> trigger ( self :: ON_SUBSCRIPTION_EXPIRED , $ subscription , $ note ) ; } | Trigger an event when account subscription is expired . |
26,475 | public function unserialize ( $ data ) { $ ar = unserialize ( $ data ) ; $ this -> protectedProperties = array_keys ( get_object_vars ( $ this ) ) ; $ this -> setFlags ( $ ar [ 'flag' ] ) ; $ this -> exchangeArray ( $ ar [ 'storage' ] ) ; $ this -> setIteratorClass ( $ ar [ 'iteratorClass' ] ) ; foreach ( $ ar as $ k => $ v ) { switch ( $ k ) { case 'flag' : $ this -> setFlags ( $ v ) ; break ; case 'storage' : $ this -> exchangeArray ( $ v ) ; break ; case 'iteratorClass' : $ this -> setIteratorClass ( $ v ) ; break ; case 'protectedProperties' : continue ; default : $ this -> __set ( $ k , $ v ) ; } } } | Unserialize an ArrayObject |
26,476 | public function update ( AbstractEntity $ entity ) { if ( $ this -> updatedTimestampColumn ) { $ entity -> exchangeArray ( [ $ this -> updatedTimestampColumn => time ( ) ] ) ; } if ( $ this -> updatedDatetimeColumn ) { $ entity -> exchangeArray ( [ $ this -> updatedDatetimeColumn => date ( 'Y-m-d H:i:s' ) ] ) ; } $ this -> updateRow ( $ entity ) ; return $ entity ; } | Update the given entity in the database . |
26,477 | public function getRelatedForeignKey ( ) { if ( null == $ this -> relatedForeignKey ) { $ name = $ this -> getParentTableName ( ) ; $ this -> relatedForeignKey = "{$this->normalizeFieldName($name)}_id" ; } return $ this -> relatedForeignKey ; } | Gets the related foreign key |
26,478 | public function getRelationTable ( ) { if ( is_null ( $ this -> relationTable ) ) { $ parentTable = $ this -> getParentTableName ( ) ; $ table = $ this -> getEntityDescriptor ( ) -> getTableName ( ) ; $ names = [ $ parentTable , $ table ] ; asort ( $ names ) ; $ first = array_shift ( $ names ) ; $ tableName = $ this -> normalizeFieldName ( $ first ) ; array_unshift ( $ names , $ tableName ) ; $ this -> relationTable = implode ( '_' , $ names ) ; } return $ this -> relationTable ; } | Gets the related table |
26,479 | public function add ( EntityAdded $ event ) { $ entity = $ event -> getEntity ( ) ; $ collection = $ event -> getCollection ( ) ; $ this -> deleteRelation ( $ entity , $ collection ) ; $ repository = $ this -> getParentRepository ( ) ; $ adapter = $ repository -> getAdapter ( ) ; $ value = $ collection -> parentEntity ( ) -> getId ( ) ; Sql :: createSql ( $ adapter ) -> insert ( $ this -> getRelationTable ( ) ) -> set ( [ "{$this->getRelatedForeignKey()}" => $ entity -> getId ( ) , "{$this->getForeignKey()}" => $ value ] ) -> execute ( ) ; } | Saves the relation row upon entity add |
26,480 | public function remove ( EntityRemoved $ event ) { $ entity = $ event -> getEntity ( ) ; $ collection = $ event -> getCollection ( ) ; $ this -> deleteRelation ( $ entity , $ collection ) ; } | Deletes the relation row upon entity remove |
26,481 | protected function deleteRelation ( EntityInterface $ entity , EntityCollectionInterface $ collection ) { $ repository = $ this -> getParentRepository ( ) ; $ adapter = $ repository -> getAdapter ( ) ; $ parts = explode ( '\\' , $ this -> getEntityDescriptor ( ) -> className ( ) ) ; $ entityName = lcfirst ( array_pop ( $ parts ) ) ; $ parts = explode ( '\\' , $ this -> getParentEntityDescriptor ( ) -> className ( ) ) ; $ relatedName = lcfirst ( array_pop ( $ parts ) ) ; $ value = $ collection -> parentEntity ( ) -> getId ( ) ; Sql :: createSql ( $ adapter ) -> delete ( $ this -> getRelationTable ( ) ) -> where ( [ "{$this->getRelatedForeignKey()} = :{$relatedName} AND {$this->getForeignKey()} = :{$entityName}" => [ ":{$relatedName}" => $ entity -> getId ( ) , ":{$entityName}" => $ value ] ] ) -> execute ( ) ; return $ this ; } | Removes existing relations |
26,482 | protected function addJoinTable ( Select $ query ) { $ relationTable = $ this -> getRelationTable ( ) ; $ table = $ this -> getParentTableName ( ) ; $ pmk = $ this -> getParentPrimaryKey ( ) ; $ rfk = $ this -> getRelatedForeignKey ( ) ; $ query -> join ( $ relationTable , "rel.{$rfk} = {$table}.{$pmk}" , null , 'rel' ) ; return $ this ; } | Adds the join table to the query |
26,483 | public function groupBy ( $ fields , $ direction = false ) { $ this -> groupBy -> addFields ( $ fields , $ direction ) ; return $ this ; } | Sets the group by fields for the query . |
26,484 | public function having ( $ field , $ condition = false , $ operator = '=' ) { if ( func_num_args ( ) >= 2 ) { $ this -> having -> addCondition ( $ field , $ condition , $ operator ) ; } else { $ this -> having -> addCondition ( $ field ) ; } return $ this ; } | Sets the having conditions for the query . |
26,485 | public function union ( self $ query , $ type = '' ) { $ this -> union -> addQuery ( $ query , $ type ) ; return $ this ; } | Unions another select query with this query . |
26,486 | public function getAction ( $ key ) { $ mediaStorageManager = $ this -> get ( 'open_orchestra_media_file.manager.storage' ) ; $ fileContent = $ mediaStorageManager -> getFileContent ( $ key ) ; $ finfo = finfo_open ( FILEINFO_MIME ) ; $ mimetype = finfo_buffer ( $ finfo , $ fileContent ) ; finfo_close ( $ finfo ) ; $ response = new Response ( ) ; $ response -> headers -> set ( 'Content-Type' , $ mimetype ) ; $ response -> headers -> set ( 'Content-Length' , strlen ( $ fileContent ) ) ; $ response -> setContent ( $ fileContent ) ; $ response -> setPublic ( ) ; $ response -> setMaxAge ( 2629743 ) ; $ date = new \ DateTime ( ) ; $ date -> modify ( '+' . $ response -> getMaxAge ( ) . ' seconds' ) ; $ response -> setExpires ( $ date ) ; return $ response ; } | Send a media stored via the UploadedFileManager |
26,487 | protected function resetProperties ( ) { $ this -> effect = 'fade' ; $ this -> titleTag = 'h4' ; $ this -> button = [ ] ; $ this -> attr = [ ] ; $ this -> title = null ; $ this -> body = null ; $ this -> footer = null ; $ this -> html = '' ; } | reset properties of modal |
26,488 | protected function buildButton ( ) { list ( $ content , $ attr ) = $ this -> button ; $ mid = $ this -> attr [ 'id' ] ; $ attr = $ this -> escaper -> attr ( array_merge_recursive ( $ attr , [ 'type' => 'button' , 'data-toggle' => 'modal' , 'data-target' => "#{$mid}" ] ) ) ; $ this -> html .= $ this -> indent ( 0 , "<button $attr>" ) ; $ this -> html .= $ this -> indent ( 1 , $ content ) ; $ this -> html .= $ this -> indent ( 0 , '</button>' ) ; } | build modal launch button |
26,489 | protected function buildHeader ( ) { $ close = '<button type="button" class="close" data-dismiss="modal" ' . 'aria-label="Close"><span aria-hidden="true">×</span></button>' ; $ tag = $ this -> titleTag ; $ tid = $ this -> attr [ 'id' ] . '-label' ; $ ttl = $ this -> title ; $ title = "<${tag} class=\"modal-title\" id=\"$tid\">{$ttl}</{$tag}>" ; $ this -> html .= $ this -> indent ( 3 , '<div class="modal-header">' ) ; $ this -> html .= $ this -> indent ( 4 , $ close ) ; $ this -> html .= $ this -> indent ( 4 , $ title ) ; $ this -> html .= $ this -> indent ( 3 , '</div>' ) ; } | build modal header |
26,490 | protected function buildBody ( ) { $ this -> html .= $ this -> indent ( 3 , '<div class="modal-body">' ) ; $ this -> html .= $ this -> indent ( 4 , $ this -> body ) ; $ this -> html .= $ this -> indent ( 3 , '</div>' ) ; } | build modal body |
26,491 | protected function buildFooter ( ) { if ( ! $ this -> footer ) { return ; } $ this -> html .= $ this -> indent ( 3 , '<div class="modal-footer">' ) ; $ this -> html .= $ this -> indent ( 4 , $ this -> footer ) ; $ this -> html .= $ this -> indent ( 3 , '</div>' ) ; } | build modal footer if set |
26,492 | public function setButton ( $ content , array $ attr = [ ] ) { if ( is_array ( $ content ) ) { $ attr = $ content [ 1 ] ; $ content = $ content [ 0 ] ; } $ this -> button = [ $ content , $ attr ] ; return $ this ; } | set button properties |
26,493 | public function setSpec ( array $ spec ) { foreach ( $ spec as $ key => $ value ) { $ method = 'set' . ucfirst ( $ key ) ; if ( method_exists ( $ this , $ method ) ) { $ this -> $ method ( $ value ) ; } } return $ this ; } | set modal specs . Call setters based on array . |
26,494 | public static function create ( array $ config = [ ] ) { $ container = new Container ( ) ; foreach ( self :: $ booleanSetters as $ key => $ method ) { if ( isset ( $ config [ $ key ] ) ) { $ container -> $ method ( ( bool ) $ config [ $ key ] ) ; } } foreach ( self :: $ arraySetters as $ key => $ method ) { if ( isset ( $ config [ $ key ] ) && is_array ( $ config [ $ key ] ) ) { foreach ( $ config [ $ key ] as $ name => $ value ) { $ container -> $ method ( $ name , $ value ) ; } } } if ( isset ( $ config [ Container :: CONFIG_ENTRIES ] ) && is_array ( $ config [ Container :: CONFIG_ENTRIES ] ) ) { self :: createEntries ( $ container , $ config [ Container :: CONFIG_ENTRIES ] ) ; } return $ container ; } | Static factory method to create a new container |
26,495 | protected static function createEntries ( Container $ container , array $ entries ) { $ defaultShared = $ container -> isSharedByDefault ( ) ; foreach ( $ entries as $ entry ) { foreach ( self :: $ requiredEntryKeys as $ key ) { if ( ! isset ( $ entry [ $ key ] ) ) { $ message = sprintf ( 'Missing required entry key "%s" in "%s".' , $ key , __METHOD__ ) ; throw new Exception \ InvalidArgumentException ( $ message ) ; } } if ( ! in_array ( $ entry [ ContainerInterface :: CONFIG_ENTRY_TYPE ] , self :: $ entryTypes ) ) { throw new Exception \ InvalidArgumentException ( sprintf ( 'Value "%s" for "%s" is not valid; it must be one of "%s" in "%s".' , $ entry [ ContainerInterface :: CONFIG_ENTRY_TYPE ] , $ key , implode ( ', ' , self :: $ types ) , __METHOD__ ) ) ; } $ shared = isset ( $ entry [ ContainerInterface :: CONFIG_ENTRY_SHARED ] ) ? ( bool ) $ entry [ ContainerInterface :: CONFIG_ENTRY_SHARED ] : $ defaultShared ; $ container -> add ( $ entry [ ContainerInterface :: CONFIG_ENTRY_NAME ] , $ entry [ ContainerInterface :: CONFIG_ENTRY_VALUE ] , $ entry [ ContainerInterface :: CONFIG_ENTRY_TYPE ] , $ shared ) ; } } | Create entries . |
26,496 | public static function parser ( ParserInterface $ parser = null ) { if ( $ parser ) { static :: $ parser = $ parser ; } elseif ( ! static :: $ parser ) { static :: $ parser = new Annotation \ KeyValuePairParser ; } return static :: $ parser ; } | Load annotation parser |
26,497 | public static function cache ( CacheInterface $ cache = null ) { if ( $ cache ) { static :: $ cache = $ cache ; } elseif ( ! static :: $ cache ) { static :: $ cache = new Annotation \ EphemeralCache ; } return static :: $ cache ; } | Load annotation cache strategy |
26,498 | public static function ofClass ( $ class , $ key = null ) { $ reflector = is_object ( $ class ) ? new \ ReflectionObject ( $ class ) : new \ ReflectionClass ( $ class ) ; if ( ! static :: cache ( ) -> hasClass ( $ reflector -> getName ( ) ) ) { $ annotations = static :: parser ( ) -> parse ( $ reflector -> getDocComment ( ) ) ; static :: cache ( ) -> storeClass ( $ reflector -> getName ( ) , $ annotations ) ; } else { $ annotations = static :: cache ( ) -> getClass ( $ reflector -> getName ( ) ) ; } if ( $ key ) { return isset ( $ annotations [ $ key ] ) ? $ annotations [ $ key ] : null ; } return $ annotations ; } | Parse class annotations |
26,499 | public function renderText ( $ text , bool $ escape = true ) : string { if ( $ escape ) { $ text = $ this -> esc ( $ text ) ; } return ( string ) Container :: getMarkdown ( ) -> text ( ( string ) $ text ) ; } | Render text content |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.