idx
int64
0
60.3k
question
stringlengths
99
4.85k
target
stringlengths
5
718
49,800
public function setForm ( ControlCollection $ form = null ) : Control { $ this -> control -> setForm ( $ form ) ; return parent :: setForm ( $ form ) ; }
Set control form .
49,801
public function distance ( Geo $ other ) { if ( $ other === $ this ) { return 0.0 ; } else { return self :: DEG_KM * rad2deg ( acos ( ( sin ( deg2rad ( $ this -> latitude ) ) * sin ( deg2rad ( $ other -> latitude ) ) ) + ( cos ( deg2rad ( $ this -> latitude ) ) * cos ( deg2rad ( $ other -> latitude ) ) * cos ( deg2rad ...
Uses the Haversine formula to calculate kilometer point distance .
49,802
public function getIndexedDocuments ( ) { $ db = $ this -> getSearchDbHandle ( ) ; $ sql = ' SELECT count(DISTINCT documentPath) AS indexedDocuments FROM term_frequency ' ; if ( ! $ stmt = $ db -> query ( $ sql ) ) { $ errorInfo = $ db -> errorInfo ( ) ; $ errorMsg = $ errorInfo [ 2 ] ; throw new \ RuntimeExcept...
Returns the amount of distinct documents that are currently in the search index .
49,803
private function queryTokens ( ) { $ tokens = $ this -> getTokens ( ) ; $ queryNorm = $ this -> getQueryNorm ( $ tokens ) ; $ results = array ( ) ; foreach ( $ tokens as $ token ) { $ results [ $ token ] = $ this -> getResultsForToken ( $ token , $ queryNorm ) ; } return $ results ; }
Queries each token present in the Tokenizer and returns SearchResult objects for the found documents
49,804
private function getSearchSuggestions ( ) { $ tokens = $ this -> getTokens ( ) ; $ allResults = array ( ) ; foreach ( $ tokens as $ token ) { $ allResults = $ this -> getSearchSuggestion ( $ token , $ allResults ) ; } return $ allResults ; }
Uses the levenshtein algorithm to determine the term that is closest to the token that was input for the search
49,805
private function getTokens ( ) { $ tokenVector = array ( 'query' => array ( ) , ) ; $ tokenVector [ 'query' ] = $ this -> tokenizer -> getTokenVector ( ) ; $ tokens = $ this -> applyFilters ( $ tokenVector ) ; if ( ! empty ( $ tokens ) ) { $ tokens = array_keys ( $ tokens [ 'query' ] ) ; } return $ tokens ; }
Retrieves all tokens from the tokenizer
49,806
public function delete ( ) { if ( count ( $ this ) == 0 ) { return ; } $ ids = $ this -> getPrimaryKeyList ( ) ; $ hitman = new $ this -> className ( ) ; $ hitman -> in ( $ hitman -> getPrimaryKey ( ) , $ ids ) -> delete ( ) ; }
Functions to operate on all elements of the ResultSet at once
49,807
public function update ( $ data ) { if ( count ( $ this ) == 0 ) { return ; } $ ids = $ this -> getPrimaryKeyList ( ) ; $ updater = new $ this -> className ( ) ; $ updater -> in ( $ updater -> getPrimaryKey ( ) , $ ids ) -> update ( $ data ) ; }
Update all entries in this ResultSet with the same values
49,808
public function getPrimaryKeyList ( ) { $ ids = [ ] ; if ( count ( $ this ) > 0 ) { foreach ( $ this as $ row ) { $ ids [ ] = $ row -> getPrimaryKeyValue ( ) ; } } return $ ids ; }
Returns an array of all primary keys contained in the ResultSet
49,809
private static function parse ( string $ headers ) : array { $ header = [ ] ; $ matches = [ ] ; preg_match_all ( '=^(.[^: ]+): ([^\r\n]*)=m' , $ headers , $ matches , PREG_SET_ORDER ) ; foreach ( $ matches as $ line ) { $ header [ $ line [ 1 ] ] = $ line [ 2 ] ; } return $ header ; }
parses given header string and returns a list of headers
49,810
public function append ( $ headers ) : self { if ( is_string ( $ headers ) ) { $ append = self :: parse ( $ headers ) ; } elseif ( is_array ( $ headers ) ) { $ append = $ headers ; } elseif ( $ headers instanceof self ) { $ append = $ headers -> headers ; } else { throw new \ InvalidArgumentException ( 'Given headers m...
appends given headers
49,811
public function put ( string $ key , $ value ) : self { if ( ! is_scalar ( $ value ) ) { throw new \ InvalidArgumentException ( 'Argument 2 passed to ' . __METHOD__ . ' must be an instance of a scalar value.' ) ; } $ this -> headers [ $ key ] = ( string ) $ value ; return $ this ; }
creates header with value for key
49,812
public function remove ( string $ key ) : self { if ( isset ( $ this -> headers [ $ key ] ) == true ) { unset ( $ this -> headers [ $ key ] ) ; } return $ this ; }
removes header with given key
49,813
public function putCookie ( array $ cookieValues ) : self { $ cookieValue = '' ; foreach ( $ cookieValues as $ key => $ value ) { $ cookieValue .= $ key . '=' . urlencode ( $ value ) . ';' ; } $ this -> put ( 'Cookie' , $ cookieValue ) ; return $ this ; }
creates header for cookie
49,814
public function putAuthorization ( string $ user , string $ password ) : self { $ this -> put ( 'Authorization' , 'BASIC ' . base64_encode ( $ user . ':' . $ password ) ) ; return $ this ; }
creates header for authorization
49,815
public function putDate ( int $ timestamp = null ) : self { if ( null === $ timestamp ) { $ date = gmdate ( 'D, d M Y H:i:s' ) ; } else { $ date = gmdate ( 'D, d M Y H:i:s' , $ timestamp ) ; } $ this -> put ( 'Date' , $ date . ' GMT' ) ; return $ this ; }
adds a date header
49,816
public function getTypeOfChildProperty ( $ targetType , $ propertyName , PropertyMappingConfigurationInterface $ configuration ) { $ specificTargetType = $ this -> objectContainer -> getImplementationClassName ( $ targetType ) ; if ( Core :: get ( ) -> classExists ( $ specificTargetType ) ) { $ propertyTags = $ this ->...
Will check the type of the given class property if reflection gives no result the parent function is called .
49,817
public static function build ( array $ constructorArguments = array ( ) , $ additionalProperties = array ( ) ) { $ constructorDefaults = array ( 'message' => null , 'code' => null , 'previous' => null ) ; $ constructorArguments = array_merge ( $ constructorDefaults , $ constructorArguments ) ; $ message = self :: prepa...
Helper method to prepare all but the most complex exceptions
49,818
public function __isset ( string $ name ) { if ( $ this -> hasWritableProperty ( $ name , $ setterName ) ) { return true ; } return parent :: __isset ( $ name ) ; }
Magic isset implementation .
49,819
public function hasWritableProperty ( string $ name , & $ setterName ) : bool { if ( \ in_array ( $ name , $ this -> ignoreSetProperties ) ) { return false ; } $ setterName = 'set' . \ ucfirst ( $ name ) ; return \ method_exists ( $ this , $ setterName ) ; }
Returns if a property with the defined name exists for write access .
49,820
public static function getInstanceByPath ( $ path , $ cacheDir = '' ) { $ instance = new self ( ) ; $ instance -> pathFile = $ path ; if ( ! empty ( $ cacheDir ) ) { $ instance -> setCacheDir ( $ cacheDir ) ; $ instance -> setCachePath ( ) ; } $ instance -> readImage ( ) ; return $ instance ; }
Creates a new image from file or URL .
49,821
public static function getInstanceByCreate ( $ width , $ height ) { $ instance = new self ( ) ; $ instance -> width = ( int ) $ width ; $ instance -> height = ( int ) $ height ; $ instance -> createImage ( ) ; return $ instance ; }
Creates a new image in memory .
49,822
public function merge ( Image $ srcImage , $ dstX , $ dstY , $ strategy = self :: MERGE_SCALE_SRC ) { if ( ! is_resource ( $ this -> image ) || ! is_resource ( $ srcImage -> image ) ) { throw new \ RuntimeException ( 'Attempt to merge image data using an invalid image resource.' ) ; } switch ( $ strategy ) { case self ...
Copies the given Image image stream into the image stream of the active instance using a scaling strategy .
49,823
public function mergeAlpha ( Image $ srcImage , $ dstX , $ dstY , $ alpha = 127 ) { if ( ! is_resource ( $ this -> image ) || ! is_resource ( $ srcImage -> image ) ) { throw new \ RuntimeException ( 'Attempt to merge image data using an invalid image resource.' ) ; } $ percent = 100 - min ( max ( round ( ( $ alpha / 12...
Copies the given Image image stream into the image stream of the active instance while applying the given alpha transparency .
49,824
public function render ( ) { if ( ! is_resource ( $ this -> image ) ) { throw new \ RuntimeException ( 'Attempt to render invalid resource as image.' ) ; } header ( 'Content-type: image/png' ) ; imagepng ( $ this -> image , null , 9 , PNG_ALL_FILTERS ) ; return $ this ; }
Outputs the image stream to the browser .
49,825
protected function setCacheDir ( $ path ) { if ( ! is_dir ( $ path ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Cache directory at %s could not be found' , $ path ) ) ; } if ( ! is_readable ( $ path ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Cache directory at %s is not readable' , $ path ) ) ; ...
Sets the path to the cache directory .
49,826
protected function isCached ( ) { $ cacheTime = self :: CACHE_TIME * 60 ; if ( ! is_file ( $ this -> pathCache ) ) { return false ; } $ cachedTime = filemtime ( $ this -> pathCache ) ; $ cacheAge = $ this -> time - $ cachedTime ; return $ cacheAge < $ cacheTime ; }
Checks if the image file exists in the cache .
49,827
protected function readImage ( ) { $ path = $ this -> pathFile ; if ( ! empty ( $ this -> pathCache ) ) { if ( ! $ this -> isCached ( ) ) { $ this -> writeCache ( ) ; } if ( $ this -> isCached ( ) ) { $ path = $ this -> pathCache ; } } $ read = @ getimagesize ( $ path ) ; if ( false === $ read ) { throw new \ RuntimeEx...
Reads the image file .
49,828
protected function createImage ( ) { $ this -> image = @ imagecreatetruecolor ( $ this -> width , $ this -> height ) ; $ this -> mimeType = 'image/png' ; $ this -> modified = time ( ) ; }
Creates a new true color image .
49,829
protected function Init ( ) { $ this -> repeater = ContentRepeater :: Schema ( ) -> ByContent ( $ this -> content ) ; $ this -> current = $ this -> tree -> FirstChildOf ( $ this -> item ) ; $ this -> isEmpty = ! $ this -> current ; return parent :: Init ( ) ; }
Initializes the repeater frontend module
49,830
protected function NextChild ( ) { $ item = $ this -> current ; $ this -> current = $ this -> tree -> NextOf ( $ item ) ; return $ item ; }
Gets the next child
49,831
public static function prepareAliases ( array $ defaultAliasConfig , array $ aliasArray ) : array { $ factory = new static ( $ defaultAliasConfig ) ; foreach ( $ aliasArray as $ name => $ config ) { $ name = ( string ) $ name ; $ aliasArray [ $ name ] = $ factory -> createAlias ( $ name , $ config ) ; } return $ aliasA...
Prepares aliases config in proper view .
49,832
public static function install ( $ request , $ object ) { $ spa = Tenant_SpaService :: installFromRepository ( $ object -> id ) ; return Tenant_Shortcuts_SpaManager ( $ spa ) -> apply ( $ spa , 'create' ) ; }
Install an spa
49,833
public static function getPossibleValues ( ) : array { if ( ( static :: $ possibleValues [ static :: class ] ?? null ) === null ) { static :: $ possibleValues [ static :: class ] = [ ] ; try { $ reflectionClass = new \ ReflectionClass ( static :: class ) ; } catch ( \ ReflectionException $ reflectionException ) { throw...
Overload this by basic array with listed constants . Taking them via Reflection is not the fastest way .
49,834
public function getMolecule ( string $ canonicalSMILE ) { $ this -> operations = new Operations ( ) ; $ atoms = array ( ) ; $ this -> operations -> addBranches ( $ canonicalSMILE , $ atoms ) ; $ this -> operations -> addLoopBonds ( $ atoms ) ; $ this -> operations -> atomsToCanonicalSMILE ( $ atoms ) ; $ factoryType = ...
FactoryClient constructor .
49,835
public static function sortBy ( $ array , $ sortByKeys , $ sorters , $ orders = [ ] ) { if ( is_string ( $ sortByKeys ) ) { $ sortByKeys = explode ( '.' , $ sortByKeys ) ; } $ sortByKeys = array_values ( ( array ) $ sortByKeys ) ; $ sorters = array_values ( ( array ) $ sorters ) ; uasort ( $ array , function ( $ a , $ ...
Sort by multiple keys
49,836
public static function groupBy ( $ array , $ groupBy = "id" ) { return static :: reduce ( $ array , function ( $ arr , $ item ) use ( $ groupBy ) { if ( is_closure ( $ groupBy ) ) { $ value = $ groupBy ( $ item ) ; } else { $ value = pisc \ upperscore \ def ( $ item , $ groupBy ) ; } if ( isset ( $ arr [ $ value ] ) ) ...
Group an array of objects by an attribute of an object or the result of a closure
49,837
public static function type ( $ array ) { $ last_key = - 1 ; $ type = 'index' ; foreach ( $ array as $ key => $ val ) { if ( ! is_int ( $ key ) || $ key < 0 ) { return 'assoc' ; } if ( $ type !== 'sparse' ) { if ( $ key !== $ last_key + 1 ) { $ type = 'sparse' ; } $ last_key = $ key ; } } return $ type ; }
Find whether the array is indexed or an associative array If it is indexed find if its sparse or not
49,838
public function start ( ) { if ( ! $ this -> started ) { if ( PHP_SAPI !== 'cli' ) { if ( ( PHP_VERSION_ID >= 50400 && session_status ( ) === PHP_SESSION_ACTIVE ) || ( PHP_VERSION_ID < 50400 && session_id ( ) ) ) { throw new \ RuntimeException ( 'Failed to start the session: Session already started.' ) ; } if ( headers...
start session and load session data into SessionDataBag
49,839
private function setSaveHandler ( ) { if ( PHP_VERSION_ID >= 50400 ) { $ this -> storageEngine = new NativeSessionWrapper ( ) ; if ( ! session_set_save_handler ( $ this -> storageEngine , FALSE ) ) { throw new \ RuntimeException ( 'Could not set session save handler.' ) ; } } }
set custom save handler for PHP 5 . 4 +
49,840
public function getRedirects ( ) { $ redirects = $ this -> repository -> redirects ; if ( $ redirects === null ) { $ redirects = array ( ) ; } usort ( $ redirects , array ( $ this , 'cmp' ) ) ; return $ redirects ; }
Get all redirects
49,841
public function addRedirect ( $ postValues ) { $ redirectObject = RedirectsFactory :: createRedirectFromPostValues ( $ postValues ) ; $ redirects = $ this -> repository -> redirects ; $ redirects [ ] = $ redirectObject ; $ this -> repository -> redirects = $ redirects ; $ this -> save ( ) ; }
Add a new redirect
49,842
public function getRedirectBySlug ( $ slug ) { $ redirects = $ this -> repository -> redirects ; foreach ( $ redirects as $ redirect ) { if ( $ redirect -> slug == $ slug ) { return $ redirect ; } } return null ; }
Get a redirect by it s slug
49,843
public function saveRedirect ( $ slug , $ postValues ) { $ redirectObject = RedirectsFactory :: createRedirectFromPostValues ( $ postValues ) ; $ redirects = $ this -> repository -> redirects ; foreach ( $ redirects as $ key => $ redirect ) { if ( $ redirect -> slug == $ slug ) { $ redirects [ $ key ] = $ redirectObjec...
Save a redirect by it s slug
49,844
public function deleteRedirectBySlug ( $ slug ) { $ redirects = $ this -> repository -> redirects ; foreach ( $ redirects as $ key => $ redirect ) { if ( $ redirect -> slug == $ slug ) { unset ( $ redirects [ $ key ] ) ; } } $ redirects = array_values ( $ redirects ) ; $ this -> repository -> redirects = $ redirects ; ...
Delete a redirect by it s slug
49,845
private function createTokenNode ( $ tokenName , $ defaultClass , $ tokenInterface , $ defaultTtl ) { $ builder = new TreeBuilder ( ) ; $ node = $ builder -> root ( $ tokenName ) ; $ node -> addDefaultsIfNotSet ( ) -> children ( ) -> integerNode ( 'ttl' ) -> defaultValue ( $ defaultTtl ) -> end ( ) -> scalarNode ( 'cla...
Create a token configuration node .
49,846
protected static function isInsideJailDir ( $ path ) { $ jailDir = __DIR__ . '/' . self :: $ jailDir ; return strpos ( realpath ( $ path ) , realpath ( $ jailDir ) ) !== false ; }
Compare users selected path with jaildir path
49,847
protected static function isWhitelisted ( $ file ) { if ( ! is_array ( self :: $ whitelist ) || count ( self :: $ whitelist ) === 0 ) { return true ; } foreach ( self :: $ whitelist as $ fileName ) { if ( strpos ( $ file , $ fileName ) ) { return true ; } } return false ; }
Compare users selected filename against whitelist
49,848
protected static function parseUrl ( $ url ) { $ url = isset ( $ url ) ? $ url : "//$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ; $ url = parse_url ( $ url ) ; $ url [ 'browse' ] = './' ; if ( array_key_exists ( 'browse' , self :: $ requestMethod ) && ! empty ( self :: $ requestMethod [ 'browse' ] ) ) { $ url [ 'browse' ...
Pare URL into array
49,849
public static function get_all_locations ( ) { $ menus = [ ] ; $ locations = get_nav_menu_locations ( ) ; foreach ( $ locations as $ location => $ menu_id ) { $ menus [ $ location ] = [ ] ; $ menu_items = wp_get_nav_menu_items ( $ menu_id ) ; $ menu_items = is_array ( $ menu_items ) ? $ menu_items : [ ] ; foreach ( $ m...
Returns an array of menu locations with the assigned menu in each .
49,850
public static function getFirePHP ( $ options = null ) { if ( ! isset ( self :: $ _FirePHP ) || ! empty ( $ options ) ) { if ( ! class_exists ( '\FirePHP' ) ) { throw new THEDEBUGException ( "FirePHP not available" ) ; } if ( ! isset ( self :: $ _FirePHP ) ) { ob_start ( ) ; } if ( ! empty ( $ options ) ) { \ FB :: set...
Retrieve an instance of FirePHP
49,851
public static function getChromePHP ( ) { if ( ! isset ( self :: $ _ChromePHP ) ) { self :: $ _ChromePHP = X \ THEDEBUG \ ChromePhp :: getInstance ( ) ; } return self :: $ _ChromePHP ; }
Retrieve an instance of ChromePHP
49,852
public static function debug ( $ variable ) { if ( ! self :: $ _enabled ) { return ; } if ( self :: $ ensureByGet && ! isset ( $ _GET [ 'debug' ] ) ) { return ; } $ debug = new THEDEBUG \ ADEBUG ( func_get_args ( ) ) ; $ debug -> put ( ) ; return $ variable ; }
Create an ADEBUG object and put it .
49,853
public static function diebug ( ) { if ( ! self :: $ _enabled ) { return ; } if ( self :: $ ensureByGet && ! isset ( $ _GET [ 'debug' ] ) ) { return ; } $ args = func_get_args ( ) ; $ debug = new THEDEBUG \ ADEBUG ( $ args ) ; if ( ! empty ( $ args ) ) { $ debug -> put ( ) ; } $ debug -> variable = 'Script got murdered...
The Killer debug the passed variable die!
49,854
public static function getDebugObject ( $ variable ) { if ( ! self :: $ _enabled ) { return ; } if ( self :: $ ensureByGet && ! isset ( $ _GET [ 'debug' ] ) ) { return ; } return new THEDEBUG \ ADEBUG ( func_get_args ( ) ) ; }
Just return the ADEBUG instance for later usage .
49,855
public static function deprecate ( $ alternative = '' , $ continue = true ) { if ( ! self :: $ _enabled ) { return ; } if ( self :: $ ensureByGet && ! isset ( $ _GET [ 'debug' ] ) ) { return ; } $ debug = new THEDEBUG \ ADEBUG ( ) ; $ scope = $ debug -> getScope ( ) ; if ( $ scope -> type === 'global' ) { return ; } $ ...
Flag a function as deprecated by placing this method inside it .
49,856
public static function count ( $ message = '' ) { if ( ! self :: $ _enabled ) { return ; } if ( self :: $ ensureByGet && ! isset ( $ _GET [ 'debug' ] ) ) { return ; } $ debug = new THEDEBUG \ ADEBUG ( array ( 1 ) ) ; $ ID = $ debug -> getID ( ) ; if ( isset ( self :: $ counts [ $ ID ] ) ) { unset ( $ debug ) ; self :: ...
Count how often this line is visited and put the debug at the end of the script .
49,857
private static function traverse ( $ name , $ type , $ tmp_name , $ error , $ size , Dictionary $ dict , $ path ) { if ( is_array ( $ name ) ) { $ keys = array_keys ( $ name ) ; foreach ( $ keys as $ key ) { $ new_path = $ path ; $ new_path [ ] = $ key ; if ( ! array_key_exists ( $ key , $ name ) || ! array_key_exists ...
Helper function to recursively traverse the uploaded files array .
49,858
public function baseURL ( $ path = '' ) { if ( is_null ( $ this -> baseURL ) ) { $ self = $ _SERVER [ 'PHP_SELF' ] ; $ server = $ _SERVER [ 'HTTP_HOST' ] . rtrim ( str_replace ( strstr ( $ self , 'index.php' ) , '' , $ self ) , '/' ) ; if ( ( ! empty ( $ _SERVER [ 'HTTPS' ] ) && $ _SERVER [ 'HTTPS' ] != 'off' ) || ! em...
Return the baseURL
49,859
protected function determineRedirectURL ( ) { $ this -> redirectURL = trim ( $ this -> getRoutedParameter ( 'url' ) ) ; if ( empty ( $ this -> redirectURL ) ) { $ this -> setNotReady ( "Invalid or missing redirect `url` parameter." , null , 404 ) ; } }
Determine redirect url
49,860
protected function determineRedirectType ( ) { $ this -> redirectType = intval ( $ this -> getRoutedParameter ( 'type' , $ this -> redirectType ) ) ; if ( ! in_array ( $ this -> redirectType , [ 301 , 302 ] ) ) { $ this -> setNotReady ( "Invalid redirect type specified." , null , 404 ) ; } }
Determine redirect type
49,861
protected function validateRedirectURL ( ) { if ( ! filter_var ( $ this -> redirectURL , FILTER_VALIDATE_URL ) ) { if ( ! preg_match ( '#^/[a-zA-Z0-9_/.-]*#' , $ this -> redirectURL ) ) { $ this -> setNotReady ( "Invalid redirect URL entered." , null , 404 ) ; return ; } } }
Validate redirect URL
49,862
protected function buildOutputObject ( ) { $ output = new \ Slab \ Controllers \ Response ( static :: DEFAULT_REDIRECT_RESOLVER , $ this -> data , $ this -> redirectType , $ this -> displayHeaders ) ; return $ output ; }
Build the output object
49,863
static function getDatabase ( $ link ) { if ( $ link instanceof \ PDO ) { $ class = 'Pdo' ; } elseif ( $ link instanceof \ Zend \ Db \ Adapter \ Adapter ) { $ class = 'ZendDb2' ; } elseif ( $ link instanceof \ Zend_Db_Adapter_Abstract ) { $ class = 'ZendDb' ; } elseif ( $ link instanceof \ MDB2_Driver_Common ) { $ clas...
Factory method to create database interface
49,864
private function prepareContent ( $ content ) { $ this -> content = $ content ; if ( ! ( $ this -> content instanceof StreamInterface ) ) { $ this -> content = Stream :: factory ( $ this -> content ) ; } elseif ( $ this -> content instanceof MultipartBody ) { if ( ! $ this -> hasHeader ( 'Content-Disposition' ) ) { $ d...
Prepares the contents of a POST file .
49,865
private function prepareDefaultHeaders ( ) { if ( ! $ this -> hasHeader ( 'Content-Disposition' ) ) { $ this -> headers [ 'Content-Disposition' ] = sprintf ( 'form-data; name="%s"; filename="%s"' , $ this -> name , basename ( $ this -> filename ) ) ; } if ( ! $ this -> hasHeader ( 'Content-Type' ) ) { $ this -> headers...
Applies default Content - Disposition and Content - Type headers if needed .
49,866
public function getLicense ( ) { if ( $ this -> _license === null ) { $ this -> _license = $ this -> take ( 'package' ) -> getLicense ( ) ; } return $ this -> _license ; }
Get license .
49,867
protected function extractDefaultValues ( $ pattern ) { $ regex = '~\{([a-zA-Z][a-zA-Z0-9_]*+)[^\}]*(=[a-zA-Z0-9._]++)\}~' ; if ( preg_match_all ( $ regex , $ pattern , $ matches , \ PREG_SET_ORDER ) ) { $ srch = $ repl = $ vals = [ ] ; foreach ( $ matches as $ m ) { $ srch [ ] = $ m [ 0 ] ; $ repl [ ] = str_replace ( ...
Extract default values from the pattern
49,868
private function setCommonTemplateParameters ( ) { $ this -> setTemplateParameter ( 'application' , APPLICATION ) ; $ this -> setTemplateParameter ( 'area' , AREA ) ; $ this -> setTemplateParameter ( 'subject' , $ this -> name ) ; $ this -> setTemplateParameter ( 'language' , LANGUAGE ) ; $ this -> setTemplateParameter...
Sets common template parameters
49,869
protected function buildTemplateFunctions ( ) { $ this -> templateEngine -> addFunction ( 'pathToArea' , function ( $ language = false ) { return implode ( '/' , $ this -> buildPathToArea ( $ language ) ) . '/' ; } ) ; $ this -> templateEngine -> addFunction ( 'pathToSubject' , function ( $ language = false ) { return ...
Builds functions used into templates
49,870
protected function renderTemplate ( $ path = false ) { if ( ! $ this -> templateEngine ) { throw new \ Exception ( 'template engine not injected' ) ; } if ( ! $ path ) { $ path = sprintf ( '%s/%s/%s' , AREA , $ this -> name , $ this -> action ) ; } $ this -> setCommonTemplateParameters ( ) ; $ html = $ this -> template...
Renders template and writes output to HTTP stream
49,871
public function _async_attachment_images ( $ atts , $ attachment , $ size ) { if ( ! $ this -> _is_async_attachment_images ( ) ) { return $ atts ; } $ atts [ 'data-src' ] = $ atts [ 'src' ] ; $ atts [ 'src' ] = wp_get_attachment_image_url ( $ attachment -> ID , 'wppso-minimum-thumbnail' ) ; if ( isset ( $ atts [ 'srcse...
Aync loading of attachment images
49,872
public function _async_content_images ( $ content ) { if ( ! $ this -> _is_async_content_images ( ) ) { return $ content ; } if ( ! preg_match_all ( '/<img [^>]+>/' , $ content , $ matches ) ) { return $ content ; } $ selected_images = [ ] ; foreach ( $ matches [ 0 ] as $ image ) { if ( false === strpos ( $ image , ' d...
Aync loading of content images
49,873
protected function _add_data_src_to_content_image ( $ image , $ image_id ) { return preg_replace_callback ( '@(<img decoding="async"[^>]*?) src="([^"]+?)"([^>]*?>)@m' , function ( $ matches ) use ( $ image_id ) { return sprintf ( '%s src="%s" data-src="%s" %s' , $ matches [ 1 ] , wp_get_attachment_image_url ( $ image_i...
Add data - src to content image
49,874
protected function _add_data_srcset_to_content_image ( $ image , $ image_id ) { return preg_replace_callback ( '@(<img decoding="async"[^>]*?)srcset="([^"]+?)"([^>]*?>)@m' , function ( $ matches ) use ( $ image_id ) { return sprintf ( '%s srcset="" data-srcset="%s" %s' , $ matches [ 1 ] , $ matches [ 2 ] , $ matches [ ...
Add data - srcset to content image
49,875
public function createFormForModel ( string $ classname , DAO $ dao ) { if ( ! is_a ( $ classname , Model :: class , true ) ) throw new \ InvalidArgumentException ( "Not a valid Model class provided" ) ; $ form = new Form ( $ classname ) ; $ refl = new ReflectionClass ( $ classname ) ; $ fields = $ this -> getAnnotated...
Create a form based on a database model
49,876
public function createFormForObject ( string $ formclass ) { if ( ! is_a ( $ formclass , BaseForm :: class , true ) ) throw new \ InvalidArgumentException ( "Not a valid BaseForm class provided" ) ; $ form = new Form ( $ formclass ) ; $ refl = new \ ReflectionClass ( $ formclass ) ; $ field_validators = $ formclass :: ...
Create a form using reflection on a POPO .
49,877
protected function addFormValidators ( ReflectionClass $ refl , array $ additional_validators , Form $ form ) { $ classdoc = $ refl -> getDocComment ( ) ; if ( ! empty ( $ classdoc ) ) { $ classdoc = new DocComment ( $ classdoc ) ; foreach ( $ classdoc -> getAnnotations ( 'validator' ) as $ validator ) { if ( ! is_a ( ...
Add validators for the whole form
49,878
protected function getAnnotatedFields ( ReflectionClass $ class , array $ field_validators ) { $ properties = $ class -> getProperties ( ReflectionProperty :: IS_PUBLIC ) ; $ fields = [ ] ; foreach ( $ properties as $ prop ) { $ name = $ prop -> getName ( ) ; $ comment = $ prop -> getDocComment ( ) ; if ( $ comment ===...
Iterate over all properties and add their values to the form
49,879
protected function bindValue ( FormElement $ element , ReflectionClass $ refl , $ instance ) { $ name = $ element -> getName ( true ) ; if ( substr ( $ name , 0 , 1 ) === "_" ) return ; $ value = $ element -> getValue ( ) ; $ method_name = "set" . strtoupper ( substr ( $ name , 0 , 1 ) ) . substr ( $ name , 1 ) ; if ( ...
Set a value from a form to an instance of a class
49,880
private function buildUrl ( $ path ) { $ key = $ this -> patrol -> getApiKey ( ) ; $ secret = $ this -> patrol -> getApiSecret ( ) ; $ base = $ this -> patrol -> apiBase ; $ url = $ base . '/' . $ path . '?key=' . $ key . '&secret=' . $ secret ; if ( $ this -> method === "get" && ! is_null ( $ this -> payload ) ) { $ q...
Takes a path and builds the URL with the given key and secret
49,881
public static function compare ( $ known , $ user ) { if ( strlen ( $ known ) !== strlen ( $ user ) ) { return false ; } $ result = 0 ; $ knownLength = strlen ( $ known ) ; for ( $ i = 0 ; $ i < $ knownLength ; $ i ++ ) { $ result |= ord ( $ known [ $ i ] ) ^ ord ( $ user [ $ i ] ) ; } return $ result == 0 ; }
Compares two strings securely .
49,882
public function _run ( ) { if ( defined ( "NOT_FOUND" ) ) { ( new Controller ( ) ) -> load -> error ( 404 ) ; } if ( Configer :: manualRoute ( ) ) { $ router = Router :: getInstance ( $ this -> segments ) ; Configer :: loadRoutes ( ) ; try { if ( $ action = $ router -> run ( ) ) { if ( is_array ( $ action ) ) { $ class...
Here we go ...
49,883
protected function setIfDefined ( $ object , $ field ) { $ propertyAccessor = $ this -> getPropertyAccessor ( ) ; if ( ! $ this -> _has ( $ field ) ) { return $ propertyAccessor -> isReadable ( $ object , $ field ) ? $ propertyAccessor -> getValue ( $ object , $ field ) : null ; } $ propertyAccessor -> setValue ( $ obj...
Define given field on given object if accessible
49,884
public function addLocalVariable ( $ localVariable ) { $ varName = $ localVariable ; if ( strpos ( $ varName , '$' ) === 0 ) { $ varName = substr ( $ localVariable , 1 ) ; } if ( in_array ( $ varName , $ this -> localVariables ) === false ) { $ this -> localVariables [ ] = $ varName ; } }
Add a local variable so that any usage of it doesn t trigger trying to fetch it from the ViewModel
49,885
public static function getNamespace ( $ namespaceClass ) { if ( is_object ( $ namespaceClass ) === true ) { $ namespaceClass = get_class ( $ namespaceClass ) ; } $ lastSlashPosition = mb_strrpos ( $ namespaceClass , '\\' ) ; if ( $ lastSlashPosition !== false ) { return mb_substr ( $ namespaceClass , 0 , $ lastSlashPos...
Get the name space part of a fully namespaced class . Returns empty string if the class had no namespace part .
49,886
public static function getClassName ( $ namespaceClass ) { $ lastSlashPosition = mb_strrpos ( $ namespaceClass , '\\' ) ; if ( $ lastSlashPosition !== false ) { return mb_substr ( $ namespaceClass , $ lastSlashPosition + 1 ) ; } return $ namespaceClass ; }
Get the class part of a fully namespaced class name
49,887
public function ensureDirectoryExists ( $ outputFilename ) { $ directoryName = dirname ( $ outputFilename ) ; @ mkdir ( $ directoryName , 0755 , true ) ; if ( file_exists ( $ directoryName ) === false ) { throw new JigException ( "Directory $directoryName does not exist and could not be created" ) ; } }
ensureDirectoryExists by creating it with 0755 permissions and throwing an exception if it does not exst after that mkdir call .
49,888
public function create ( ) { $ slug = $ this -> getParameter ( 'value' ) ; $ allowSlashes = StringUtils :: strToBool ( $ this -> getParameter ( 'allowSlashes' ) ) ; return SlugUtils :: createSlug ( $ slug , $ allowSlashes ) ; }
Returns a slug for the specified parameter
49,889
public function mailer ( ) { if ( is_null ( $ this -> mailerInstance ) ) { $ mailer = new Mailer ( ViewFactory :: i ( ) , $ this -> swiftMailer ( ) ) ; if ( $ queue = UniversalBuilder :: resolve ( 'queue.connection' ) ) $ mailer -> setQueue ( $ queue ) ; $ from = Config :: get ( 'mail.from' ) ; if ( is_array ( $ from )...
mailer . mailer
49,890
public function withDataCell ( string $ tableDataCellClassName ) : TableColumnFieldDefiner { if ( ! is_subclass_of ( $ tableDataCellClassName , TableDataCell :: class , true ) ) { throw InvalidArgumentException :: format ( 'Invalid class supplied to %s: expecting subclass of %s, %s given' , __METHOD__ , TableDataCell :...
Defines the cell class for the table .
49,891
public function put ( $ key , $ value , $ duration , $ localOnly = false ) { return parent :: put ( $ key , $ value , $ this -> cacheExpiration ) ; }
Writes the cache value to all of our cache stores
49,892
public static function boot ( ) { parent :: boot ( ) ; self :: saving ( function ( $ model ) { return $ model -> beforeSave ( ) ; } ) ; self :: saved ( function ( $ model ) { return $ model -> afterSave ( ) ; } ) ; self :: deleting ( function ( $ model ) { return $ model -> beforeDelete ( ) ; } ) ; self :: deleted ( fu...
Setup the model events
49,893
public function save ( array $ options = array ( ) , $ force = false ) { if ( $ force || $ this -> validate ( ) ) { return $ this -> performSave ( $ options ) ; } else { return false ; } }
Persist the model to the DB if it s valid
49,894
protected function performSave ( array $ options ) { $ this -> purgeAttributes ( ) ; $ this -> saved = true ; return parent :: save ( $ options ) ; }
Save the model on the database
49,895
protected function validate ( ) { $ rules = $ this -> mergeRules ( ) ; if ( empty ( $ rules ) ) return true ; $ data = $ this -> attributes ; $ validator = Validator :: make ( $ data , $ rules ) ; $ success = $ validator -> passes ( ) ; if ( $ success ) { if ( $ this -> validationErrors -> count ( ) > 0 ) { $ this -> v...
Validate the model by the defined rules
49,896
private function mergeRules ( ) { $ rules = static :: $ rules ; $ output = array ( ) ; if ( empty ( $ rules ) ) { return $ output ; } if ( $ this -> exists ) { $ merged = ( isset ( $ rules [ 'update' ] ) ) ? array_merge_recursive ( $ rules [ 'save' ] , $ rules [ 'update' ] ) : $ rules [ 'save' ] ; } else { $ merged = (...
Return a single array with the rules for the action required
49,897
protected function purgeAttributes ( ) { $ attributes = $ this -> getPurgeAttributes ( ) ; if ( ! empty ( $ attributes ) ) { foreach ( $ attributes as $ attribute ) { unset ( $ this -> attributes [ $ attribute ] ) ; } } }
Purge the attributes that are not a field on the database table to prevent error during the save
49,898
public function getList ( array $ data = array ( ) ) { $ sql = 'SELECT b.*, u.name AS user_name' ; if ( ! empty ( $ data [ 'count' ] ) ) { $ sql = 'SELECT COUNT(b.backup_id)' ; } $ sql .= ' FROM backup b LEFT JOIN user u ON(b.user_id = u.user_id) WHERE b.backup_id > 0' ; $ where = arra...
Returns an array of backups or counts them
49,899
public function add ( array $ data ) { $ result = null ; $ this -> hook -> attach ( 'module.backup.add.before' , $ data , $ result , $ this ) ; if ( isset ( $ result ) ) { return $ result ; } $ version = null ; if ( isset ( $ data [ 'version' ] ) ) { $ version = $ data [ 'version' ] ; } if ( $ this -> exists ( $ data [...
Adds a backup to the database