idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
17,900 | public function listFiles ( $ directory = null , $ recursive = false ) { return $ this -> flysystem -> listFiles ( $ directory , $ recursive ) ; } | List all the files from a directory |
17,901 | public function addHeader ( string $ name , string $ value ) : bool { $ isSet = false ; if ( ! empty ( $ name ) && ! empty ( $ value ) ) { $ this -> offsetSet ( $ name , $ value ) ; $ isSet = true ; } return $ isSet ; } | Adds a new Header . If the header already exists it is overwritten . |
17,902 | public function methodExcludedByOptions ( $ method , array $ options ) { return ( ! empty ( $ options [ 'only' ] ) && ! in_array ( $ method , ( array ) $ options [ 'only' ] ) ) || ( ! empty ( $ options [ 'except' ] ) && in_array ( $ method , ( array ) $ options [ 'except' ] ) ) ; } | Determine if the given options exclude a particular method . |
17,903 | protected function filterFailsOn ( $ filter , $ request , $ method ) { $ on = array_get ( $ filter , 'options.on' ) ; if ( is_null ( $ on ) ) return false ; if ( is_string ( $ on ) ) $ on = explode ( '|' , $ on ) ; return ! in_array ( strtolower ( $ request -> getMethod ( ) ) , $ on ) ; } | Determine if the filter fails the on constraint . |
17,904 | public static function uniqueId ( ) : string { $ rand = random_bytes ( 16 ) ; $ rand [ 6 ] = chr ( ord ( $ rand [ 6 ] ) & 0x0f | 0x40 ) ; $ rand [ 8 ] = chr ( ord ( $ rand [ 8 ] ) & 0x3f | 0x80 ) ; $ rand = str_split ( bin2hex ( $ rand ) , 4 ) ; return vsprintf ( '%s%s%s%s%s' , array_map ( function ( $ hex ) { return base_convert ( $ hex , 16 , 32 ) ; } , [ $ rand [ 0 ] . $ rand [ 1 ] , $ rand [ 2 ] , $ rand [ 3 ] , $ rand [ 4 ] , $ rand [ 5 ] . $ rand [ 6 ] . $ rand [ 7 ] ] ) ) ; } | Follow uuid v4 generation standard but remove dash and encode in base 32 Guarantee 128 bits of entropy but use ~ 20% less space compare to base 16 |
17,905 | public static function initialize ( $ group_name , $ access_token , $ opts = null ) { if ( ! is_string ( $ group_name ) || strlen ( $ group_name ) == 0 ) { throw new Exception ( "Invalid group_name" ) ; } if ( ! is_string ( $ access_token ) || strlen ( $ access_token ) == 0 ) { throw new Exception ( "Invalid access_token" ) ; } if ( isset ( self :: $ _singleton ) ) { if ( ! isset ( $ opts ) ) { $ opts = array ( ) ; } self :: $ _singleton -> options ( array_merge ( $ opts , array ( 'group_name' => $ group_name , 'access_token' => $ access_token , ) ) ) ; } else { self :: $ _singleton = self :: newRuntime ( $ group_name , $ access_token , $ opts ) ; } return self :: $ _singleton ; } | Initializes and returns the singleton instance of the Runtime . |
17,906 | public static function getInstance ( $ group_name = NULL , $ access_token = NULL , $ opts = NULL ) { if ( ! isset ( self :: $ _singleton ) ) { self :: $ _singleton = self :: newRuntime ( $ group_name , $ access_token , $ opts ) ; } return self :: $ _singleton ; } | Returns the singleton instance of the Runtime . |
17,907 | public static function newRuntime ( $ group_name , $ access_token , $ opts = NULL ) { if ( is_null ( $ opts ) ) { $ opts = array ( ) ; } if ( $ group_name != NULL ) { $ opts [ 'group_name' ] = $ group_name ; } if ( $ group_name != NULL ) { $ opts [ 'access_token' ] = $ access_token ; } return new TraceguideBase \ Client \ ClientRuntime ( $ opts ) ; } | Creates a new runtime instance . |
17,908 | public static function merge ( $ a , $ b ) { $ acon = static :: parse ( $ a ) ; $ bcon = static :: parse ( $ b ) ; if ( $ acon instanceof EmptyConstraint ) { return $ b ; } elseif ( $ bcon instanceof EmptyConstraint ) { return $ a ; } elseif ( $ acon -> matches ( $ bcon ) || $ bcon -> matches ( $ acon ) ) { return strlen ( $ a ) > strlen ( $ b ) ? $ b : $ a ; } else { return $ a . ' ' . $ b ; } } | Merges two constraints . Doesn t resolve version conflicts . |
17,909 | public function array_fields ( $ array , array $ fields ) { $ newArray = array ( ) ; foreach ( $ array as $ value ) { $ newValue = array ( ) ; foreach ( $ fields as $ key ) { if ( array_key_exists ( $ key , $ value ) ) { $ newValue [ $ key ] = $ value [ $ key ] ; } } $ newArray [ ] = $ newValue ; } return $ newArray ; } | Retorna un array con los campos indicados |
17,910 | public function json_encode_data ( $ object , array $ fields , $ options = 0 ) { $ array = $ this -> object_to_array ( $ object , $ fields ) ; return json_encode ( $ array , $ options ) ; } | Este realiza el pasaje de un objeto a json asegurando que el mismo no entre en loop . Para esto primero pasa el objeto a array en base a los campos que quiere mapear y despues lo pasa a json |
17,911 | public function json_encode_recursion ( $ object , $ recursionLevel = 1 , $ options = 0 ) { $ objects = array ( ) ; $ ocurrencias = array ( ) ; $ array = array ( ) ; if ( is_array ( $ object ) ) { $ array = $ object ; foreach ( $ array as & $ var ) { $ var = $ this -> json_encode_recursion_internal ( $ var , $ recursionLevel , $ options , $ objects , $ ocurrencias ) ; } } else { $ array = $ this -> json_encode_recursion_internal ( $ object , $ recursionLevel , $ options , $ objects , $ ocurrencias ) ; } return json_encode ( $ array , $ options ) ; } | Este metodo realiza el pasaje de un objeto Doctrine a json . Para esto indicamos el nivel de profundidad que se va a ingresar en el objeto y los objetos no cargados hasta el momento solo se mapearan su id . |
17,912 | protected function json_encode_recursion_internal ( $ object , $ recursionLevel = 1 , $ options = 0 , $ objects , $ ocurrencias ) { $ pos = array_search ( $ object , $ objects ) ; $ repeticiones = 1 ; if ( $ pos !== FALSE ) { $ ocurrencias [ $ pos ] ++ ; $ repeticiones = $ ocurrencias [ $ pos ] ; } else { $ objects [ ] = $ object ; $ ocurrencias [ ] = 1 ; } if ( $ repeticiones > $ recursionLevel ) { return FALSE ; } else { if ( method_exists ( $ object , 'jsonSerialize' ) ) { $ vars = $ object -> jsonSerialize ( ) ; foreach ( $ vars as $ key => & $ var ) { if ( is_object ( $ var ) ) { $ rta = $ this -> json_encode_recursion_internal ( $ var , $ recursionLevel , $ options , $ objects , $ ocurrencias ) ; if ( $ rta !== FALSE ) { $ var = $ rta ; } else { unset ( $ var ) ; unset ( $ vars [ $ key ] ) ; } } else if ( is_array ( $ var ) || $ var instanceof \ Traversable ) { foreach ( $ var as & $ item ) { $ item = $ this -> json_encode_recursion_internal ( $ item , $ recursionLevel , $ options , $ objects , $ ocurrencias ) ; } } } return $ vars ; } else { return $ object ; } } } | Este metodo es privado y realiza el pasaje de un objeto Doctrine a json . Para esto indicamos el nivel de profundidad que se va a ingresar en el objeto y los objetos no cargados hasta el momento solo se mapearan su id . |
17,913 | public function attach ( Registry $ registry , $ id = '' ) { if ( ! empty ( $ id ) || 0 === $ id ) { if ( ! empty ( $ this -> registries [ $ id ] ) ) { throw new RegistryException ( RegistryException :: DUPLICATE_REGISTRATION_ATTEMPT_TEXT , RegistryException :: DUPLICATE_REGISTRATION_ATTEMPT_CODE ) ; } $ this -> registries [ $ id ] = $ registry ; } else { $ this -> registries [ ] = $ registry ; } } | Adds the provided registry to the dispatcher queue . |
17,914 | public function detach ( $ id ) { if ( empty ( $ this -> registries [ $ id ] ) ) { throw new RegistryException ( RegistryException :: MODIFICATION_ATTEMPT_FAILED_TEXT , RegistryException :: MODIFICATION_ATTEMPT_FAILED_CODE ) ; } unset ( $ this -> registries [ $ id ] ) ; } | Removes the a registry from dispatcher . |
17,915 | protected function processRegistry ( $ action , Registry $ registry , $ id , array $ output , array $ args = array ( ) ) { try { $ output [ $ id ] = call_user_func_array ( array ( $ registry , $ action ) , $ args ) ; } catch ( RegistryException $ e ) { $ this -> errors [ $ id ] = $ e ; } return $ output ; } | Invokes the defined callback on the given registry . |
17,916 | public function getLastErrorMessages ( ) { $ message = '' ; if ( $ this -> hasError ( ) ) { foreach ( $ this -> errors as $ exception ) { $ message .= $ exception -> getMessage ( ) . ',' . PHP_EOL ; } } return $ message ; } | Provides the messages generated by the last occurred errors . |
17,917 | protected function fetchArray ( $ cursor = null ) { if ( ! empty ( $ cursor ) && $ cursor instanceof Statement ) { return $ cursor -> fetch ( \ PDO :: FETCH_NUM ) ; } if ( $ this -> prepared instanceof Statement ) { return $ this -> prepared -> fetch ( \ PDO :: FETCH_NUM ) ; } } | Method to fetch a row from the result set cursor as an array . |
17,918 | protected function fetchAssoc ( $ cursor = null ) { if ( ! empty ( $ cursor ) && $ cursor instanceof Statement ) { return $ cursor -> fetch ( \ PDO :: FETCH_ASSOC ) ; } if ( $ this -> prepared instanceof Statement ) { return $ this -> prepared -> fetch ( \ PDO :: FETCH_ASSOC ) ; } return null ; } | Method to fetch a row from the result set cursor as an associative array . |
17,919 | public function loadNextObject ( $ class = 'stdClass' ) { $ this -> connect ( ) ; if ( ! $ this -> executed ) { if ( ! ( $ this -> execute ( ) ) ) { return $ this -> errorNum ? null : false ; } } if ( $ row = $ this -> fetchObject ( null , $ class ) ) { return $ row ; } $ this -> freeResult ( ) ; return false ; } | Method to get the next row in the result set from the database query as an object . |
17,920 | public function escape ( $ text , $ extra = false ) { if ( is_int ( $ text ) || is_float ( $ text ) ) { return $ text ; } $ result = substr ( $ this -> connection -> quote ( $ text ) , 1 , - 1 ) ; if ( $ extra ) { $ result = addcslashes ( $ result , '%_' ) ; } return $ result ; } | Escapes a string for usage in an SQL statement . |
17,921 | public static function encode ( String $ str ) : String { return preg_replace ( array_keys ( self :: $ scriptTagChars ) , array_values ( self :: $ scriptTagChars ) , $ str ) ; } | Encode Script Tags |
17,922 | public static function decode ( String $ str ) : String { return preg_replace ( array_keys ( self :: $ scriptTagCharsDecode ) , array_values ( self :: $ scriptTagCharsDecode ) , $ str ) ; } | Decode Script Tags |
17,923 | function parseBody ( ) { $ request = $ this -> getMessageObject ( ) ; $ reqID = spl_object_hash ( $ request ) ; if ( isset ( self :: $ _parsed [ $ reqID ] ) ) return self :: $ _parsed [ $ reqID ] ; if ( $ request -> headers ( ) -> has ( 'content-type' ) ) { $ contentType = \ Poirot \ Http \ Header \ renderHeaderValue ( $ request , 'content-type' ) ; $ contentType = strtolower ( $ contentType ) ; } else { return array ( ) ; } if ( false !== $ pos = strpos ( $ contentType , ';' ) ) $ contentType = substr ( $ contentType , 0 , $ pos ) ; switch ( $ contentType ) { case 'application/json' : $ parsedData = $ this -> _parseJsonDataFromRequest ( $ request ) ; break ; case 'application/x-www-form-urlencoded' : $ parsedData = $ this -> _parseUrlEncodeDataFromRequest ( $ request ) ; break ; case strpos ( $ contentType , 'multipart' ) !== false : $ parsedData = $ this -> _parseMultipartDataFromRequest ( $ request ) ; break ; default : throw new \ Exception ( sprintf ( 'Request Body Contains No Data or Unknown Content-Type (%s).' , $ contentType ) ) ; } return self :: $ _parsed [ $ reqID ] = $ parsedData ; } | Parse Request Body Data |
17,924 | function parseQueryParams ( ) { $ request = $ this -> getMessageObject ( ) ; $ data = array ( ) ; $ url = $ request -> getTarget ( ) ; if ( $ p = parse_url ( $ url , PHP_URL_QUERY ) ) parse_str ( $ p , $ data ) ; return $ data ; } | Parse Request Query Params |
17,925 | public function getUrlAttribute ( ) { if ( $ this -> disk == 'public' ) { return url ( $ this -> storage -> url ( $ this -> path ) ) ; } return config ( 'media.download' , false ) ? url ( str_finish ( config ( 'media.download' ) , '/' ) . $ this -> id ) : null ; } | Url to file . |
17,926 | public function getFirstName ( ) : ? string { if ( ! $ this -> hasFirstName ( ) ) { $ this -> setFirstName ( $ this -> getDefaultFirstName ( ) ) ; } return $ this -> firstName ; } | Get first name |
17,927 | private function isUnixTimestamp ( $ value ) : bool { return ( string ) ( float ) $ value == ( string ) $ value && ( ( float ) $ value <= PHP_INT_MAX ) && ( ( float ) $ value >= ~ PHP_INT_MAX ) ; } | Checks whether a value is a valid UNIX timestamp |
17,928 | private function validateDateTime ( $ value ) : void { try { if ( is_a ( $ value , DateTime :: class ) || is_null ( $ value ) || $ value === 'now' ) { } else { if ( $ this -> isUnixTimestamp ( $ value ) ) { DateTime :: createFromFormat ( "U.u" , $ this -> unixTimestampAsUuFormat ( $ value ) ) ; } else { new DateTime ( $ value ) ; } } } catch ( Exception $ e ) { throw new TypeValidationException ( 'Attempted to pass non-date[time] value to date[time] type' ) ; } } | Validates a value as a nullable value that can be cast to DateTime |
17,929 | public function goSide ( $ fileName ) : parent { $ filePath = $ this -> htsl -> getFilePath ( $ fileName , dirname ( $ this -> filePath ) ) ; $ content = $ this -> htsl -> getFileContent ( $ filePath ) ; return new static ( $ this -> htsl , $ content , $ filePath ) ; } | Getting another file reference fake file of this buffer . |
17,930 | private function connect ( ) { try { $ this -> db = new \ PDO ( $ this -> dbOptions [ 'dsn' ] , $ this -> dbOptions [ 'username' ] , $ this -> dbOptions [ 'password' ] , $ this -> dbOptions [ 'driver_options' ] ) ; } catch ( \ Exception $ e ) { if ( $ this -> dbOptions [ 'debug' ] ) { throw $ e ; } else { throw new \ PDOException ( "Could not connect to database, hiding connection details." ) ; } } $ this -> db -> setAttribute ( \ PDO :: ATTR_DEFAULT_FETCH_MODE , \ PDO :: FETCH_OBJ ) ; } | Internal function for connecting to the database |
17,931 | private function checkValidity ( ) { if ( ! is_writable ( $ this -> rssFile ) ) { $ this -> valid = false ; return ; } $ stmt = $ this -> db -> prepare ( 'SELECT CREATED FROM ' . $ this -> table . ' ORDER BY CREATED DESC LIMIT 1' ) ; $ stmt -> execute ( ) ; $ res = $ stmt -> fetchAll ( ) ; if ( count ( $ res ) == 0 ) { $ this -> valid = false ; return ; } $ latestInput = strtotime ( $ res [ 0 ] -> CREATED ) ; $ rssCreated = filemtime ( $ this -> rssFile ) ; if ( $ latestInput > $ rssCreated ) { $ this -> valid = false ; } else { $ this -> valid = true ; } } | Compares RSS file created timestamp and database timestamp to judge if new RSS file is needed |
17,932 | private function createRSS ( ) { $ file = fopen ( $ this -> rssFile , "w+" ) ; $ stmt = $ this -> db -> prepare ( 'SELECT * FROM ' . $ this -> table . ' ORDER BY CREATED DESC LIMIT ?' ) ; $ stmt -> execute ( [ $ this -> newsCount ] ) ; $ res = $ stmt -> fetchAll ( ) ; $ xmlVersion = '<?xml version="1.0" encoding="UTF-8" ?>' ; $ startString = <<<EOD{$xmlVersion}<rss version="2.0"><channel> <title>{$this->feedDescription['title']}</title> <link>{$this->feedDescription['link']}</link> <description>{$this->feedDescription['description']}</description>EOD ; fwrite ( $ file , $ startString ) ; foreach ( $ res as $ post ) { $ date = date ( "D, d M y H:i:s O" , strtotime ( $ post -> CREATED ) ) ; $ string = <<<EOD <item> <title>{$post->TITLE}</title> <link>{$post->LINK}</link> <description>{$post->DESCRIPTION}</description> <pubDate>{$date}</pubDate> </item>EOD ; fwrite ( $ file , $ string ) ; } fwrite ( $ file , '</channel></rss>' ) ; } | Creates a new RSS File with information from the database . Max amount of news is configured in the initiation . |
17,933 | public function getRSS ( ) { $ this -> checkValidity ( ) ; if ( ! $ this -> valid ) { $ this -> createRSS ( ) ; } if ( $ this -> sendHeader ) { header ( 'Content-type: application/rss+xml; charset=UTF-8' ) ; } readfile ( $ this -> rssFile ) ; } | Function that should be called to receive the RSS feed . Checks if the latest RSS File is up to date if not generates a new one . |
17,934 | public static function validate ( $ result , array $ context ) { if ( ! empty ( $ context [ 'parent' ] ) ) { if ( ! ( $ result instanceof $ context [ 'parent' ] ) ) { throw new InvalidPointer ( 'Object must be an instance of ' . $ context [ 'parent' ] ) ; } } if ( ! empty ( $ context [ 'validator' ] ) ) { if ( ! Callback :: call ( $ context [ 'validator' ] , [ $ result ] ) ) { throw new InvalidPointer ( 'Object is not valid' ) ; } } return true ; } | Checks a result |
17,935 | protected function removeFromQueue ( PriorityQueueInterface $ queue , $ callabOrClassname ) { if ( is_object ( $ callabOrClassname ) ) { $ queue -> remove ( $ callabOrClassname ) ; } else { foreach ( $ queue as $ data ) { if ( is_a ( $ data [ 'data' ] , $ callabOrClassname ) ) { $ queue -> remove ( $ data [ 'data' ] ) ; } } } } | Remove callable or matching classname object from the queue |
17,936 | protected function runProcessors ( LogEntryInterface $ logEntry ) { $ queue = $ this -> getCallables ( 'processors' , $ logEntry -> getChannel ( ) ) ; foreach ( $ queue as $ data ) { call_user_func ( $ data [ 'data' ] , $ logEntry ) ; } return $ this ; } | Execute related processors on the log entry |
17,937 | protected function runHandlers ( LogEntryInterface $ logEntry ) { $ queue = $ this -> getCallables ( 'handlers' , $ logEntry -> getChannel ( ) ) ; foreach ( $ queue as $ data ) { if ( $ logEntry -> isPropagationStopped ( ) ) { break ; } if ( LogLevel :: $ levels [ $ logEntry -> getLevel ( ) ] >= LogLevel :: $ levels [ $ data [ 'extra' ] ] ) { call_user_func ( $ data [ 'data' ] , $ logEntry ) ; } } return $ this ; } | Execute related handlers on the log entry |
17,938 | public function executeAndFetch ( $ query , $ parameters = [ ] , $ castModel = null ) { $ statement = $ this -> link -> prepare ( $ query ) ; $ statement -> execute ( $ parameters ) ; $ data = $ statement -> fetch ( PDO :: FETCH_ASSOC ) ; $ statement -> closeCursor ( ) ; return ( $ castModel && $ data ? $ data : $ data ) ; } | Execute a query and fetch first row as associative array |
17,939 | public function bindExecuteAndFetch ( $ query , $ parameters = [ ] , $ castModel = null ) { $ statement = $ this -> link -> prepare ( $ query ) ; foreach ( $ parameters as $ index => $ paramProperties ) { if ( is_object ( $ paramProperties ) ) { $ paramProperties = ( array ) $ paramProperties ; } if ( is_array ( $ paramProperties ) ) { $ statement -> bindValue ( ( int ) $ index + 1 , $ paramProperties [ 'value' ] , $ paramProperties [ 'param' ] ) ; } else { $ statement -> bindValue ( ( int ) $ index + 1 , $ paramProperties ) ; } } $ statement -> execute ( ) ; $ data = $ statement -> fetch ( PDO :: FETCH_ASSOC ) ; $ statement -> closeCursor ( ) ; return ( $ castModel && $ data ? $ data : $ data ) ; } | Bind Execute a query and fetch first row as associative array |
17,940 | public function bindExecuteAndFetchAll ( $ query , $ parameters = [ ] , $ castModel = null ) { $ statement = $ this -> link -> prepare ( $ query ) ; foreach ( $ parameters as $ index => $ paramProperties ) { if ( is_object ( $ paramProperties ) ) { $ paramProperties = ( array ) $ paramProperties ; } if ( is_array ( $ paramProperties ) ) { $ statement -> bindValue ( ( int ) $ index + 1 , $ paramProperties [ 'value' ] , $ paramProperties [ 'param' ] ) ; } else { $ statement -> bindValue ( ( int ) $ index + 1 , $ paramProperties ) ; } } $ statement -> execute ( ) ; $ data = $ statement -> fetchAll ( PDO :: FETCH_ASSOC ) ; return ( $ castModel && $ data ? $ data : $ data ) ; } | Bind Execute a query and fetch all rows as associative array |
17,941 | public function getById ( $ id ) { $ id = ( int ) $ id ; $ rowSet = $ this -> getTableGateway ( ) -> select ( [ $ this -> getPrimaryKey ( ) => $ id ] ) ; $ row = $ rowSet -> current ( ) ; return $ row ; } | Get one row by it s id |
17,942 | public function fetchAll ( $ paginated = false ) { if ( $ paginated ) { $ paginatorAdapter = new DbTableGateway ( $ this -> tableGateway ) ; $ paginator = new Paginator ( $ paginatorAdapter ) ; return $ paginator ; } $ resultSet = $ this -> getTableGateway ( ) -> select ( ) ; return $ resultSet ; } | Fetch all records . |
17,943 | public function findByUri ( $ uri ) { return $ this -> routes -> first ( function ( $ route ) use ( $ uri ) { return $ route -> match ( $ uri ) ; } ) ; } | Finds the route via uri |
17,944 | public function findByName ( $ name ) { return $ this -> routes -> first ( function ( $ route ) use ( $ name ) { return $ route -> getName ( ) === $ name ; } ) ; } | Returns route by given name |
17,945 | public function group ( array $ options , \ Closure $ closure ) { $ group = new static ( null , $ options ) ; $ closure -> bindTo ( $ group ) -> __invoke ( $ group ) ; $ this -> getCollection ( ) -> addAll ( $ group -> getCollection ( ) ) ; return $ this ; } | Create a group with specific options |
17,946 | public function routable ( $ class , $ prefix = null ) { $ class = $ this -> resolveRoutableClassValue ( $ class ) ; $ router = ( new RoutableInspector ( $ class ) ) -> generateRoutables ( null , $ prefix ) ; $ this -> mergeRouter ( $ router ) ; return $ this ; } | Import all routable method for a class |
17,947 | protected function resolveNameValue ( $ name ) { if ( $ name === null ) return null ; if ( $ prefixName = $ this -> getPrefixName ( ) ) { $ name = $ prefixName . $ name ; } return $ name ; } | Result value of name |
17,948 | public function setOptions ( array $ args ) { $ this -> options = $ args += [ 'filters' => [ ] , 'name' => null , 'namespace' => null , 'prefix' => null , ] ; $ args [ 'namespace' ] && $ this -> setNamespace ( $ args [ 'namespace' ] ) ; $ args [ 'prefix' ] && $ this -> setPrefixPath ( $ args [ 'prefix' ] ) ; $ args [ 'name' ] && $ this -> setPrefixName ( $ args [ 'name' ] ) ; $ args [ 'filters' ] && $ this -> setDefaultFilters ( $ args [ 'filters' ] ) ; return $ this ; } | Set value via array options |
17,949 | public function acfLocationRulesMatch ( $ match , $ rule , $ options ) { $ post_types = get_field ( 'easy_reading_posttypes' , 'option' ) ; if ( $ post_types ) { if ( $ rule [ 'operator' ] == "==" ) { $ match = ( isset ( $ options [ 'post_type' ] ) && in_array ( $ options [ 'post_type' ] , $ post_types ) && $ options [ 'post_id' ] > 0 ) ; } elseif ( $ rule [ 'operator' ] == "!=" ) { $ match = ( isset ( $ options [ 'post_type' ] ) && ! in_array ( $ options [ 'post_type' ] , $ post_types ) && $ options [ 'post_id' ] > 0 ) ; } } return $ match ; } | Matching custom location rule |
17,950 | public function getUriWithExtraString ( string $ uri ) : String { if ( ! $ this -> queryString ) { return $ uri ; } return $ uri . '?' . implode ( '&' , $ this -> queryString ) ; } | Get uri with extra query strings |
17,951 | public function go ( $ input ) { Arguments :: define ( Boa :: readMap ( ) ) -> define ( $ input ) ; $ map = ComplexFactory :: toReadMap ( $ this -> functions ) ; if ( $ map -> member ( $ input ) ) { $ function = Maybe :: fromJust ( $ map -> lookup ( $ input ) ) ; return $ function ( ) ; } elseif ( $ map -> member ( $ this -> default ) ) { $ function = Maybe :: fromJust ( $ map -> lookup ( $ this -> default ) ) ; return $ function ( ) ; } throw new UnknownKeyException ( ) ; } | Run the flick on input . |
17,952 | public static function slugify ( $ string ) { $ string = strtolower ( preg_replace ( array ( '/[^a-zA-Z0-9 -]/' , '/[ -]+/' , '/^-|-$/' ) , array ( '' , '-' , '' ) , $ string ) ) ; $ string = ltrim ( $ string , "-" ) ; $ string = rtrim ( $ string , '-' ) ; return $ string ; } | Turn a string into a slug |
17,953 | public static function toTitleCase ( $ string ) { $ string = str_replace ( [ "_" , "-" ] , " " , $ string ) ; $ name_array = explode ( " " , $ string ) ; $ smallWords = [ 'of' , 'a' , 'the' , 'and' , 'an' , 'or' , 'nor' , 'but' , 'is' , 'if' , 'then' , 'else' , 'when' , 'at' , 'from' , 'by' , 'on' , 'off' , 'for' , 'in' , 'out' , 'over' , 'to' , 'into' , 'with' ] ; $ acronyms = Settings :: getInstance ( ) -> getAcronyms ( ) ; foreach ( $ name_array as $ index => $ value ) { if ( in_array ( $ value , $ acronyms ) === true ) { $ name_array [ $ index ] = strtoupper ( $ value ) ; } elseif ( $ index === 0 || $ index === sizeof ( $ name_array ) - 1 ) { $ name_array [ $ index ] = ucfirst ( $ value ) ; } elseif ( in_array ( $ value , $ smallWords ) === true ) { } else { $ name_array [ $ index ] = ucfirst ( $ value ) ; } } $ string = implode ( " " , $ name_array ) ; return $ string ; } | Format a string into title case |
17,954 | protected function publishRoute ( Filesystem $ filesystem , $ route ) { if ( is_null ( $ route ) ) { return ; } $ routeFile = app_path ( 'Http/routes.php' ) ; if ( $ filesystem -> exists ( $ routeFile ) && $ filesystem -> exists ( $ route ) ) { $ filesystem -> append ( $ routeFile , $ filesystem -> get ( $ route ) ) ; $ this -> line ( '<info>Append routes from</info> <comment>[' . $ route . ']</comment>' ) ; } } | Appends routes . |
17,955 | private function getProperty ( $ name ) { if ( ! Property :: exists ( $ this -> properties , $ name ) ) { throw new \ Exception ( ) ; } return Property :: get ( $ this -> properties , $ name ) ; } | Returns value of property |
17,956 | public static function getJSONErrorAsString ( ) { switch ( json_last_error ( ) ) { case JSON_ERROR_NONE : $ error = NULL ; break ; case JSON_ERROR_DEPTH : $ error = 'The maximum stack depth has been exceeded.' ; break ; case JSON_ERROR_STATE_MISMATCH : $ error = 'Invalid or malformed JSON.' ; break ; case JSON_ERROR_CTRL_CHAR : $ error = 'Control character error, possibly incorrectly encoded.' ; break ; case JSON_ERROR_SYNTAX : $ error = 'Syntax error, malformed JSON.' ; break ; case JSON_ERROR_UTF8 : $ error = 'Malformed UTF-8 characters, possibly incorrectly encoded.' ; break ; case JSON_ERROR_RECURSION : $ error = 'One or more recursive references in the value to be encoded.' ; break ; case JSON_ERROR_INF_OR_NAN : $ error = 'One or more NAN or INF values in the value to be encoded.' ; break ; case JSON_ERROR_UNSUPPORTED_TYPE : $ error = 'A value of a type that cannot be encoded was given.' ; break ; default : $ error = NULL ; break ; } return $ error ; } | returns a string representation of the last JSON error |
17,957 | public static function containsValidJSON ( $ string ) { try { $ result = json_decode ( $ string ) ; } catch ( \ Exception $ e ) { } if ( self :: getJSONError ( ) === NULL ) return true ; else return false ; } | Determines if a string contains a valid decodable JSON object . |
17,958 | protected function getSettingsMethods ( ) { if ( empty ( $ this -> settingsMethods ) ) { $ settings = $ this -> getSettingsRepository ( ) ; $ methods = get_class_methods ( $ settings ) ; $ this -> settingsMethods = array_diff ( $ methods , [ '__construct' ] ) ; } return $ this -> settingsMethods ; } | Returns all accessible methods on the associated settings repository . |
17,959 | public function Log ( $ logMessage ) { $ target = null ; if ( $ user = Sentinel :: getUser ( ) ) if ( $ user != null ) $ target = $ user -> id ; $ log = $ this -> getLogsRepository ( ) -> create ( [ 'log' => $ logMessage , 'ip' => Request :: ip ( ) , 'target' => $ target ] ) ; } | Create a log |
17,960 | public function TargettedLog ( $ logMessage , $ userTarget ) { $ log = $ this -> getLogsRepository ( ) -> create ( [ 'log' => $ logMessage , 'target' => $ userTarget , 'ip' => Request :: ip ( ) ] ) ; } | Create a log and associates it to a user |
17,961 | public function setConfigByFile ( $ name ) { $ file = "/{$name}.cfg.php" ; if ( 'production' !== FS2_ENV ) { $ file_env = "/{$name}-{FS2_ENV}.cfg.php" ; if ( file_exists ( FS2CONFIG . $ file_env ) ) { $ file = $ file_env ; } } $ config = array ( ) ; if ( file_exists ( FS2CONFIG . "/" . $ file ) ) { include ( FS2CONFIG . "/" . $ file ) ; } return $ this -> setConfigByArray ( $ config ) ; } | set multiple config entries from a config file does not change any database data |
17,962 | public function autoloadPath ( $ path ) { $ files = glob ( $ path ) ; if ( $ files && count ( $ files ) ) { foreach ( $ files as $ file ) { if ( file_exists ( $ file ) && is_dir ( $ file ) ) { $ this -> autoloadPath ( $ file . "/*" ) ; } if ( file_exists ( $ file ) && is_file ( $ file ) ) { require_once ( $ file ) ; } } } } | Autoloads all files in the given path |
17,963 | public function createView ( $ file = null ) { $ view = new View ( $ this -> getTemplatePath ( ) . '/app/views/' ) ; if ( $ file ) { $ view -> setFile ( $ file ) ; } return $ view ; } | Create a new View instance |
17,964 | public function init ( ) { $ coreViewPath = WP :: applyFilters ( 'wpmvc_core_views_path' , $ this -> getCorePath ( ) . '/Views/' ) ; $ appViewPath = WP :: applyFilters ( 'wpmvc_app_views_path' , $ this -> getTemplatePath ( ) . '/app/views/' ) ; $ theHeader = new View ( $ coreViewPath ) ; $ theBody = new View ( $ appViewPath ) ; $ theFooter = new View ( $ coreViewPath ) ; $ theHeader -> setFile ( WP :: applyFilters ( 'wpmvc_header_file' , 'header' ) ) ; $ theHeader -> setVar ( 'app' , $ this ) ; $ theFooter -> setFile ( WP :: applyFilters ( 'wpmvc_footer_file' , 'footer' ) ) ; $ theFooter -> setVar ( 'app' , $ this ) ; if ( WP :: isFrontPage ( ) || WP :: isHome ( ) ) { $ theBody -> setFile ( 'home' ) ; $ theBody -> setVar ( 'app' , $ this ) ; } else { $ postType = WP :: getQueryVar ( 'post_type' ) ; if ( WP :: is404 ( ) ) { $ theBody -> setFile ( '404' ) ; } elseif ( WP :: isSearch ( ) ) { $ theBody -> setFile ( 'search/index' ) ; } elseif ( WP :: isTax ( ) ) { $ taxonomy = WP :: getQueryVar ( 'taxonomy' ) ; $ theBody -> setFile ( sprintf ( 'taxonomy/%s/index' , $ taxonomy ) ) ; } elseif ( WP :: isTag ( ) ) { $ theBody -> setFile ( 'tag/index' ) ; } elseif ( WP :: isCategory ( ) ) { $ theBody -> setFile ( 'category/index' ) ; } elseif ( WP :: isPage ( ) ) { $ theBody -> setFile ( WP :: getCurrentPageName ( ) ) ; if ( ! $ theBody -> hasFile ( ) ) { $ theBody -> setFile ( 'page' ) ; } } elseif ( WP :: isPostTypeArchive ( ) ) { $ theBody -> setFile ( sprintf ( '%s/index' , $ postType ) ) ; } elseif ( WP :: isSingle ( ) ) { $ postType = WP :: getPostType ( ) ; $ theBody -> setFile ( sprintf ( '%s/single' , $ postType ) ) ; } } $ theBody -> setFile ( WP :: applyFilters ( 'wpmvc_body_file' , $ theBody -> getFile ( ) ) ) ; echo WP :: applyFilters ( 'wpmvc_header_output' , $ theHeader -> output ( ) ) ; echo WP :: applyFilters ( 'wpmvc_body_output' , $ theBody -> output ( ) ) ; echo WP :: applyFilters ( 'wpmvc_footer_output' , $ theFooter -> output ( ) ) ; } | Begin the routing |
17,965 | public function setTheme ( string $ theme ) { if ( ! $ this -> isPathValid ( $ theme ) ) { throw new NotFoundException ( 'The theme cannot be found.' ) ; } $ this -> validateTheme ( $ theme ) ; $ themeInfo = $ this -> getThemeInfo ( $ theme ) ; if ( array_key_exists ( 'parent' , $ themeInfo ) ) { $ this -> childTheme = $ themeInfo ; $ this -> setTheme ( $ themeInfo [ 'parent' ] ) ; } else { $ this -> theme = $ themeInfo ; } } | Sets a theme |
17,966 | private function isPathValid ( string $ theme ) : bool { if ( ! is_dir ( rtrim ( $ this -> themePath , '/' ) . '/' . $ theme ) ) { return false ; } return true ; } | Checks whether the theme directory exists |
17,967 | private function validateTheme ( string $ theme ) { if ( ! file_exists ( $ this -> themePath . '/' . $ theme . '/info.json' ) ) { throw new InvalidException ( 'The theme (`' . $ theme . '`) is missing the configuration file (`info.json`).' ) ; } try { $ themeInfo = $ this -> getThemeInfo ( $ theme ) ; } catch ( \ Throwable $ e ) { throw new InvalidException ( 'The theme\'s (`' . $ theme . '`) configuration file (`info.json`) does not contain valid json or could not be read.' ) ; } foreach ( self :: CONFIG_REQUIRED_FIELDS as $ requiredField ) { if ( ! array_key_exists ( $ requiredField , $ themeInfo ) ) { throw new InvalidException ( 'The theme\'s (`' . $ theme . '`) configuration file (`info.json`) is missing the required theme ' . $ requiredField . ' property.' ) ; } } } | Checks whether the layout of the theme directory is valid |
17,968 | public function load ( string $ file ) : string { if ( $ this -> childTheme && file_exists ( $ this -> themePath . '/' . $ this -> childTheme [ 'name' ] . $ file ) ) { $ this -> preventDirectoryTraversal ( $ this -> themePath . '/' . $ this -> childTheme [ 'name' ] , $ this -> themePath . '/' . $ this -> childTheme [ 'name' ] . $ file ) ; return $ this -> themePath . '/' . $ this -> childTheme [ 'name' ] . $ file ; } if ( ! file_exists ( $ this -> themePath . '/' . $ this -> theme [ 'name' ] . $ file ) ) { throw new NotFoundException ( 'The template file (`' . $ file . '`) could not be found in the theme.' ) ; } $ this -> preventDirectoryTraversal ( $ this -> themePath . '/' . $ this -> theme [ 'name' ] , $ this -> themePath . '/' . $ this -> theme [ 'name' ] . $ file ) ; return $ this -> themePath . '/' . $ this -> theme [ 'name' ] . $ file ; } | Loads a file from the theme |
17,969 | private function preventDirectoryTraversal ( string $ themePath , string $ filePath ) { $ themePath = realpath ( $ themePath ) ; $ filePath = realpath ( $ filePath ) ; if ( $ filePath === false || strpos ( $ filePath , $ themePath ) !== 0 ) { throw new DirectoryTraversalException ( 'Trying to load a file outside of the theme directory.' ) ; } } | Validates the file path to prevent directory traversal |
17,970 | private function throwUnlessCorrectSubclass ( $ property , $ value ) { $ typeUsedToBe = $ this -> getTypeUsedToBe ( $ property ) ; if ( $ typeUsedToBe === "object" ) { $ classUsedToBe = $ this -> getClassUsedToBe ( $ property ) ; if ( ! is_subclass_of ( $ value , $ classUsedToBe ) ) { throw new Exception ( ) ; } } } | Throw Unless Correct Subclass |
17,971 | private function throwUnlessCorrectType ( $ property , $ value ) { $ typeUsedToBe = $ this -> getTypeUsedToBe ( $ property ) ; if ( $ typeUsedToBe !== "null" ) { $ typeWantsToBe = $ this -> getTypeWantsToBe ( $ value ) ; if ( $ typeUsedToBe !== $ typeWantsToBe ) { throw new Exception ( ) ; } } } | Throw Unless Correct Type |
17,972 | public static function create ( $ attributes , $ table , $ schema = null , $ return = self :: RETURN_ID ) { if ( is_object ( $ attributes ) ) { $ attributes = ( array ) $ attributes ; } $ driver = Database :: getAdapterName ( ) ; $ query_keys = implode ( '" , "' , array_keys ( $ attributes ) ) ; $ query_parameter_string = trim ( str_repeat ( '?,' , count ( $ attributes ) ) , ',' ) ; $ query_values = array_values ( $ attributes ) ; if ( $ driver == 'postgresql' ) { foreach ( $ query_values as & $ queryValue ) { if ( is_bool ( $ queryValue ) ) { $ queryValue = ( $ queryValue ? 'true' : 'false' ) ; } } } $ query = 'INSERT INTO ' ; if ( $ schema !== null ) { $ query .= sprintf ( '"%s"."%s"' , $ schema , $ table ) ; } else { $ query .= sprintf ( '"%s"' , $ table ) ; } $ query .= sprintf ( ' ("%s") VALUES (%s)' , $ query_keys , $ query_parameter_string ) ; if ( $ return == self :: RETURN_ID ) { if ( $ driver == 'postgresql' ) { $ query .= ' RETURNING id' ; $ id = Database :: executeAndFetch ( $ query , $ query_values ) ; return $ id [ 'id' ] ; } return Database :: executeLastInsertId ( $ query , $ query_values ) ; } elseif ( $ return == self :: RETURN_RECORDS ) { if ( $ driver != 'postgresql' ) { throw new ServerExcetion ( 'RETURN_RECORDS works only with postgresql adapter' ) ; } $ query .= 'RETURNING *' ; return Database :: executeAndFetch ( $ query , $ query_values ) ; } else { return Database :: execute ( $ query , $ query_values ) ; } } | Create a new record in database |
17,973 | public function resolve ( $ resource ) { foreach ( $ this -> loaders ( ) as $ loader ) { if ( $ loader -> supports ( $ resource ) ) { return $ loader ; } } throw new LoaderException ( 'No matching loader found.' ) ; } | Resolve a loader . |
17,974 | public static function describe ( $ value ) : string { if ( is_array ( $ value ) ) { $ value = '<array>' ; } elseif ( is_object ( $ value ) || is_callable ( $ value ) || is_iterable ( $ value ) ) { $ value = sprintf ( '<%s>' , get_class ( $ value ) ) ; } else { $ value = ( string ) $ value ; if ( strlen ( $ value ) > 30 ) { $ value = substr ( $ value , 0 , - 3 ) . '...' ; } $ value = sprintf ( '"%s"' , $ value ) ; } return $ value ; } | Converts any value into a short descriptive label . |
17,975 | public function _copy ( $ srcFilePath , $ dstFilePath , $ fname = false ) { if ( $ fname ) $ fname .= "::_copy($srcFilePath, $dstFilePath)" ; else $ fname = "_copy($srcFilePath, $dstFilePath)" ; $ metaData = $ this -> _fetchMetadata ( $ srcFilePath , $ fname ) ; if ( ! $ metaData ) { return false ; } return $ this -> _protect ( array ( $ this , "_copyInner" ) , $ fname , $ srcFilePath , $ dstFilePath , $ fname , $ metaData ) ; } | Creates a copy of a file in DB + DFS |
17,976 | public function _purge ( $ filePath , $ onlyExpired = false , $ expiry = false , $ fname = false ) { if ( $ fname ) $ fname .= "::_purge($filePath)" ; else $ fname = "_purge($filePath)" ; $ sql = "DELETE FROM " . $ this -> dbTable ( $ filePath ) . " WHERE name_hash=" . $ this -> _md5 ( $ filePath ) ; if ( $ expiry !== false ) { $ sql .= " AND mtime<" . ( int ) $ expiry ; } elseif ( $ onlyExpired ) { $ sql .= " AND expired=1" ; } if ( ! $ stmt = $ this -> _query ( $ sql , $ fname ) ) { $ this -> _fail ( "Purging file metadata for $filePath failed" ) ; } if ( $ stmt -> rowCount ( ) == 1 ) { $ this -> dfsbackend -> delete ( $ filePath ) ; } return true ; } | Purges meta - data and file - data for a file entry Will only expire a single file . Use _purgeByLike to purge multiple files |
17,977 | public function _purgeByLike ( $ like , $ onlyExpired = false , $ limit = 50 , $ expiry = false , $ fname = false ) { if ( $ fname ) $ fname .= "::_purgeByLike($like, $onlyExpired)" ; else $ fname = "_purgeByLike($like, $onlyExpired)" ; $ where = " WHERE name LIKE " . $ this -> _quote ( $ like ) ; if ( $ expiry !== false ) $ where .= " AND mtime < " . ( int ) $ expiry ; elseif ( $ onlyExpired ) $ where .= " AND expired = 1" ; if ( $ limit ) $ sqlLimit = " LIMIT $limit" ; else $ sqlLimit = "" ; $ this -> _begin ( $ fname ) ; $ selectSQL = "SELECT name FROM " . $ this -> dbTable ( $ like ) . "{$where} {$sqlLimit} FOR UPDATE" ; if ( ! $ stmt = $ this -> _query ( $ selectSQL , $ fname ) ) { $ this -> _rollback ( $ fname ) ; $ this -> _fail ( "Selecting file metadata by like statement $like failed" ) ; } $ files = array ( ) ; if ( $ stmt -> rowCount ( ) == 0 ) { $ this -> _rollback ( $ fname ) ; return 0 ; } else { while ( $ row = $ stmt -> fetch ( PDO :: FETCH_ASSOC ) ) { $ files [ ] = $ row [ 'name' ] ; } } $ deleteSQL = "DELETE FROM " . $ this -> dbTable ( $ like ) . " WHERE name_hash IN " . "(SELECT name_hash FROM " . $ this -> dbTable ( $ like ) . " $where $sqlLimit)" ; if ( ! $ stmt = $ this -> _query ( $ deleteSQL , $ fname ) ) { $ this -> _rollback ( $ fname ) ; $ this -> _fail ( "Purging file metadata by like statement $like failed" ) ; } $ deletedDBFiles = $ stmt -> rowCount ( ) ; $ this -> dfsbackend -> delete ( $ files ) ; $ this -> _commit ( $ fname ) ; return $ deletedDBFiles ; } | Purges meta - data and file - data for files matching a pattern using a SQL LIKE syntax . This method should also remove the files from disk |
17,978 | public function _delete ( $ filePath , $ insideOfTransaction = false , $ fname = false ) { if ( $ fname ) $ fname .= "::_delete($filePath)" ; else $ fname = "_delete($filePath)" ; if ( $ insideOfTransaction ) { return $ this -> _deleteInner ( $ filePath , $ fname ) ; } else { return $ this -> _protect ( array ( $ this , '_deleteInner' ) , $ fname , $ filePath , $ insideOfTransaction , $ fname ) ; } } | Deletes a file from DB The file won t be removed from disk _purge has to be used for this . Only single files will be deleted to delete multiple files _deleteByLike has to be used . |
17,979 | protected function _deleteInner ( $ filePath , $ fname ) { if ( ! $ this -> _query ( "UPDATE " . $ this -> dbTable ( $ filePath ) . " SET mtime=-ABS(mtime), expired=1 WHERE name_hash=" . $ this -> _md5 ( $ filePath ) , $ fname ) ) $ this -> _fail ( "Deleting file $filePath failed" ) ; return true ; } | Callback method used by by _delete to delete a single file |
17,980 | public function _deleteByLike ( $ like , $ fname = false ) { if ( $ fname ) $ fname .= "::_deleteByLike($like)" ; else $ fname = "_deleteByLike($like)" ; return $ this -> _protect ( array ( $ this , '_deleteByLikeInner' ) , $ fname , $ like , $ fname ) ; } | Deletes multiple files using a SQL LIKE statement Use _delete if you need to delete single files |
17,981 | function _storeInner ( $ filePath , $ datatype , $ scope , $ fname ) { clearstatcache ( ) ; $ fileMTime = filemtime ( $ filePath ) ; $ contentLength = filesize ( $ filePath ) ; $ filePathHash = md5 ( $ filePath ) ; $ nameTrunk = self :: nameTrunk ( $ filePath , $ scope ) ; if ( $ this -> _insertUpdate ( $ this -> dbTable ( $ filePath ) , array ( 'datatype' => $ datatype , 'name' => $ filePath , 'name_trunk' => $ nameTrunk , 'name_hash' => $ filePathHash , 'scope' => $ scope , 'size' => $ contentLength , 'mtime' => $ fileMTime , 'expired' => ( $ fileMTime < 0 ) ? 1 : 0 ) , array ( 'datatype' , 'scope' , 'size' , 'mtime' , 'expired' ) , $ fname ) === false ) { $ this -> _fail ( "Failed to insert file metadata while storing. Possible race condition" ) ; } if ( ! $ this -> dfsbackend -> copyToDFS ( $ filePath ) ) { $ this -> _fail ( "Failed to copy FS://$filePath to DFS://$filePath" ) ; } return true ; } | Callback function used to perform the actual file store operation |
17,982 | public function _getFileList ( $ scopes = false , $ excludeScopes = false , $ limit = false , $ path = false ) { $ filePathList = array ( ) ; $ tables = array_unique ( array ( $ this -> metaDataTable , $ this -> metaDataTableCache ) ) ; foreach ( $ tables as $ table ) { $ query = 'SELECT name FROM ' . $ table ; if ( is_array ( $ scopes ) && count ( $ scopes ) > 0 ) { $ query .= ' WHERE scope ' ; if ( $ excludeScopes ) $ query .= 'NOT ' ; $ query .= "IN ('" . implode ( "', '" , $ scopes ) . "')" ; } $ stmt = $ this -> _query ( $ query , "_getFileList( array( " . implode ( ', ' , $ scopes ) . " ), $excludeScopes )" ) ; if ( ! $ stmt ) { eZDebug :: writeDebug ( 'Unable to get file list' , __METHOD__ ) ; return false ; } $ filePathList = array ( ) ; while ( $ row = $ stmt -> fetch ( PDO :: FETCH_NUM ) ) $ filePathList [ ] = $ row [ 0 ] ; unset ( $ stmt ) ; } return $ filePathList ; } | Gets the list of cluster files filtered by the optional params |
17,983 | protected function _selectOneRow ( $ query , $ fname , $ error = false , $ debug = false ) { return $ this -> _selectOne ( $ query , $ fname , $ error , $ debug , PDO :: FETCH_NUM ) ; } | Runs a select query and returns one numeric indexed row from the result If there are more than one row it will fail and exit if 0 it returns false . |
17,984 | protected function _selectOneAssoc ( $ query , $ fname , $ error = false , $ debug = false ) { return $ this -> _selectOne ( $ query , $ fname , $ error , $ debug , PDO :: FETCH_ASSOC ) ; } | Runs a select query and returns one associative row from the result . |
17,985 | public function permissionsToRegister ( ) { $ config = config ( 'acl' ) ; $ permissionPlaceholders = array_get ( $ config , 'permission_placeholders' ) ; $ additionalPermissions = array_get ( $ config , 'additional' ) ; $ permissionsToRegister = [ ] ; $ routes = array_filter ( $ this -> router -> getRoutes ( ) -> getRoutes ( ) , function ( $ route ) { return $ route -> getName ( ) and ! in_array ( $ route -> getName ( ) , AclPolicy :: getExcept ( ) ) ; } ) ; foreach ( $ routes as $ route ) { if ( array_key_exists ( $ route -> getName ( ) , $ permissionPlaceholders ) ) { $ permissionsToRegister [ $ route -> getName ( ) ] = $ permissionPlaceholders [ $ route -> getName ( ) ] ; } else { $ permissionsToRegister [ $ route -> getName ( ) ] = $ route -> getName ( ) ; } } return array_merge ( $ permissionsToRegister , $ additionalPermissions ) ; } | Retreives the permissions to be registered . |
17,986 | public function load ( $ xmlString ) { $ data = $ this -> parserXml ( $ xmlString ) ; if ( ! isset ( $ data [ 'MsgType' ] ) ) { throw new \ RuntimeException ( "can not found MsgType" ) ; } if ( WxReceive :: MSG_TYPE_EVENT == $ data [ 'MsgType' ] ) { $ parser = new Event \ Parser ( ) ; return $ parser -> load ( $ data ) ; } $ parser = new Message \ Parser ( ) ; return $ parser -> load ( $ data ) ; } | parse xml string which come from WeChat server to WxReceiveMsg or WxReceiveEvent |
17,987 | protected function parserXml ( $ xmlString ) { libxml_disable_entity_loader ( true ) ; return json_decode ( json_encode ( simplexml_load_string ( $ xmlString , 'SimpleXMLElement' , LIBXML_NOCDATA ) , true ) , true ) ; } | parse xml to array |
17,988 | public function getAttribute ( $ name = null ) { return is_null ( $ name ) ? $ this -> attributes : Arr :: get ( $ this -> attributes , $ name ) ; } | Get variables for view |
17,989 | public function setView ( $ templateName , $ page , $ action , array $ attributes = [ ] , $ extension = "phtml" ) { $ this -> setTemplate ( $ templateName ) ; $ this -> setPage ( $ page ) ; $ this -> setAction ( $ action ) ; $ this -> setAttributes ( $ attributes ) ; $ this -> setExtension ( $ extension ) ; return $ this ; } | Set parameters for view |
17,990 | public function piece ( $ filePiece ) { $ filePiece = $ this -> viewPath . "{$filePiece}.{$this->extension}" ; if ( file_exists ( $ filePiece ) ) { include $ filePiece ; } else { MbException :: registerError ( new \ Exception ( "The file {$filePiece} not found!" ) ) ; } } | Get a piece to include in the view |
17,991 | public function getTranslation ( $ lang , $ create = false ) { foreach ( $ this -> translations as $ translation ) { if ( $ lang == $ translation -> getLang ( ) ) { return $ translation ; } } if ( $ create ) { $ class = $ this -> getTranslationClass ( ) ; $ translation = new $ class ( ) ; $ translation -> setLang ( $ lang ) ; $ this -> addTranslation ( $ translation ) ; return $ translation ; } return null ; } | Returns the translation in a given language |
17,992 | public static function ofStaticMethod ( $ callable ) { if ( is_string ( $ callable ) and strpos ( $ callable , '::' ) !== false ) { $ callable = explode ( '::' , $ callable ) ; } if ( is_array ( $ callable ) and count ( $ callable ) === 2 ) { $ reflector = new \ ReflectionMethod ( $ callable [ 0 ] , $ callable [ 1 ] ) ; if ( $ reflector -> isPublic ( ) and $ reflector -> isStatic ( ) ) { $ annotations = array_merge ( Annotation :: ofClass ( $ callable [ 0 ] ) , Annotation :: ofMethod ( $ callable [ 0 ] , $ callable [ 1 ] ) ) ; return new Invokable ( $ callable , Invokable :: STATIC_METHOD , $ annotations , $ reflector ) ; } } } | Resolve if callable is static method |
17,993 | public static function ofClassMethod ( $ callable ) { if ( is_string ( $ callable ) and strpos ( $ callable , '::' ) !== false ) { $ callable = explode ( '::' , $ callable ) ; } if ( is_array ( $ callable ) and count ( $ callable ) === 2 ) { $ reflector = new \ ReflectionMethod ( $ callable [ 0 ] , $ callable [ 1 ] ) ; if ( $ reflector -> isPublic ( ) and ! $ reflector -> isStatic ( ) and ! $ reflector -> isAbstract ( ) ) { $ annotations = array_merge ( Annotation :: ofClass ( $ callable [ 0 ] ) , Annotation :: ofMethod ( $ callable [ 0 ] , $ callable [ 1 ] ) ) ; return new Invokable ( $ callable , Invokable :: CLASS_METHOD , $ annotations , $ reflector ) ; } } } | Resolve if callable is class method |
17,994 | public static function ofFunction ( $ callable ) { if ( $ callable instanceof \ Closure or ( is_string ( $ callable ) and function_exists ( $ callable ) ) ) { $ annotations = Annotation :: ofFunction ( $ callable ) ; $ reflector = new \ ReflectionFunction ( $ callable ) ; return new Invokable ( $ callable , Invokable :: CLOSURE , $ annotations , $ reflector ) ; } } | Resolve if callable is closure or function |
17,995 | public function replaceMissingAttributes ( ) { $ persistedAttributes = array ( ) ; foreach ( $ this -> getValueSet ( ) -> getValues ( ) as $ value ) { $ persistedAttributes [ ] = $ value -> getAttribute ( ) ; } $ newValues = array ( ) ; $ missingAttributes = array_diff ( $ this -> getValueSet ( ) -> getAttributes ( ) -> toArray ( ) , $ persistedAttributes ) ; foreach ( $ missingAttributes as $ attribute ) { $ valueClass = $ attribute -> getValueType ( ) ; $ value = new $ valueClass ( ) ; $ this -> getValueSet ( ) -> addValue ( $ value ) ; $ value -> setValueSet ( $ this -> getValueSet ( ) ) ; $ value -> setAttribute ( $ attribute ) ; $ newValues [ ] = $ value ; } return $ newValues ; } | Creates fake values for non - persisted attributes |
17,996 | public function getDirectoryParts ( ) : array { return $ this -> myAboveBaseLevel === 0 ? $ this -> myDirectoryParts : array_merge ( array_fill ( 0 , $ this -> myAboveBaseLevel , '..' ) , $ this -> myDirectoryParts ) ; } | Returns the directory parts . |
17,997 | private function myToString ( string $ directorySeparator , ? callable $ stringEncoder = null ) : string { return $ this -> myDirectoryToString ( $ directorySeparator , $ stringEncoder ) . $ this -> myFilenameToString ( $ stringEncoder ) ; } | Returns the path as a string . |
17,998 | private function myDirectoryToString ( string $ directorySeparator , ? callable $ stringEncoder = null ) : string { $ result = '' ; if ( $ this -> myAboveBaseLevel > 0 ) { $ result .= str_repeat ( '..' . $ directorySeparator , $ this -> myAboveBaseLevel ) ; } if ( $ this -> myIsAbsolute ) { $ result .= $ directorySeparator ; } $ result .= implode ( $ directorySeparator , $ stringEncoder !== null ? array_map ( $ stringEncoder , $ this -> myDirectoryParts ) : $ this -> myDirectoryParts ) ; if ( count ( $ this -> myDirectoryParts ) > 0 ) { $ result .= $ directorySeparator ; } return $ result ; } | Returns the directory as a string . |
17,999 | private function myFilenameToString ( ? callable $ stringEncoder = null ) : string { if ( $ this -> myFilename === null ) { return '' ; } if ( $ stringEncoder !== null ) { return $ stringEncoder ( $ this -> myFilename ) ; } return $ this -> myFilename ; } | Returns the filename as a string . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.