idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
57,400
private static function isPrime ( $ n ) { if ( $ n === 1 ) { return false ; } if ( $ n === 2 ) { return true ; } if ( $ n % 2 === 0 ) { return false ; } for ( $ i = 3 ; $ i <= ceil ( sqrt ( $ n ) ) ; $ i += 2 ) { if ( $ n % $ i === 0 ) { return false ; } } return true ; }
Checks if some integer is a prime number .
57,401
public function setSession ( $ varname , $ varval ) { $ this -> alteredsession = true ; $ this -> sessionvars [ $ varname ] = $ varval ; return $ this ; }
Sets a SESSION variable .
57,402
public function killSession ( $ varname ) { $ this -> alteredsession = true ; $ this -> sessionvars [ $ varname ] = null ; return $ this ; }
Clears a session variable .
57,403
public function killCookie ( $ varname ) { $ this -> alteredcookies = true ; $ this -> cookievars [ $ varname ] = null ; return $ this ; }
Clears a cookie variable .
57,404
public function getCookie ( $ varname , $ default = false ) { if ( isset ( $ this -> cookievars [ $ varname ] ) ) { return $ this -> cookievars [ $ varname ] [ 'value' ] ; } else { return $ default ; } }
Retrieves the value of a cookie variable .
57,405
function setAllCookies ( array $ cookies ) { $ cookies_max_age = $ this -> cookies_max_age ; $ this -> cookievars = array_map ( function ( $ cookieval ) use ( $ cookies_max_age ) { return array ( 'value' => $ cookieval , 'max_age' => $ cookies_max_age , ) ; } , $ cookies ) ; return $ this ; }
Sets all cookies .
57,406
public function setObjectPrototype ( $ objectPrototype ) { if ( ! is_object ( $ objectPrototype ) ) { throw new Exception \ InvalidArgumentException ( sprintf ( 'Object prototype must be an object, given "%s"' , gettype ( $ objectPrototype ) ) ) ; } $ this -> objectPrototype = $ objectPrototype ; return $ this ; }
Set the row object prototype
57,407
public function addComponent ( Component $ component ) { $ component -> setParentComponent ( $ this ) ; $ component -> setFormComponent ( $ this -> formComponent ) ; $ this -> components [ $ component -> getName ( ) ] = $ component ; $ component -> setRequestData ( is_array ( $ this -> inputData ) && array_key_exists ( $ component -> getName ( ) , $ this -> inputData ) ? $ this -> inputData [ $ component -> getName ( ) ] : null ) ; }
Connects a component with the form handler instance
57,408
public function getComponent ( $ name ) { if ( isset ( $ this -> components [ $ name ] ) === false ) throw new \ OutOfBoundsException ( 'The component with name "' . $ name . '" does not exist' ) ; return $ this -> components [ $ name ] ; }
Returns a connected component of this form handler instance selected by its name
57,409
public function enableRecoverableErrorHandling ( ) { if ( $ this -> isRecoverableErrorHandlingEnabled ( ) ) { return ; } set_error_handler ( function ( $ number , $ string , $ file , $ line ) { @ trigger_error ( null ) ; return $ this -> errorConverter -> createRecoverableErrorAndCallHandler ( $ this , $ number , $ string , $ file , $ line ) ; } ) ; $ this -> isRecoverableErrorHandlingEnabled = true ; }
Enable regular error handling .
57,410
public function addExceptionHandler ( $ handler ) { if ( ! $ handler instanceof IExceptionHandler && ! is_callable ( $ handler ) ) { throw new InvalidHandlerType ( s ( 'Exception handler must be a callable or an instance of %s.' , IExceptionHandler :: class ) ) ; } if ( is_callable ( $ handler ) ) { $ handler = $ this -> createExceptionHandler ( $ handler ) ; } $ this -> exceptionHandlers [ ] = $ handler ; }
Add an error handler for exceptions .
57,411
public function addRecoverableErrorHandler ( $ handler ) { if ( ! $ handler instanceof INativeErrorHandler && ! is_callable ( $ handler ) ) { throw new InvalidHandlerType ( s ( 'Recoverable error handler must be a callable or an instance of %s.' , INativeErrorHandler :: class ) ) ; } if ( is_callable ( $ handler ) ) { $ handler = $ this -> createNativeErrorHandler ( $ handler ) ; } $ this -> recoverableErrorHandlers [ ] = $ handler ; }
Add an error handler only recoverable native PHP errors .
57,412
public function addFatalErrorHandler ( $ handler ) { if ( ! $ handler instanceof INativeErrorHandler && ! is_callable ( $ handler ) ) { throw new InvalidHandlerType ( s ( 'Fatal error handler must be a callable or an instance of %s.' , INativeErrorHandler :: class ) ) ; } if ( is_callable ( $ handler ) ) { $ handler = $ this -> createNativeErrorHandler ( $ handler ) ; } $ this -> fatalErrorHandlers [ ] = $ handler ; }
Add an error handler for fatal native PHP errors .
57,413
final function _generateID ( ) { $ uniqStr = function ( $ length ) { $ char = "abcdefghijklmnopqrstuvwxyz0123456789" ; $ char = str_shuffle ( $ char ) ; for ( $ i = 0 , $ rand = '' , $ l = strlen ( $ char ) - 1 ; $ i < $ length ; $ i ++ ) { $ rand .= $ char { mt_rand ( 0 , $ l ) } ; } return $ rand ; } ; if ( $ this -> ID == null ) { $ class = get_called_class ( ) ; $ module = $ this -> deriveModuleNamespace ( $ class ) ; $ widget = $ this -> deriveWidgetName ( $ class ) ; $ this -> ID = ( ( $ module != '' ) ? $ this -> inflectName ( $ module ) . '_' : '' ) . $ this -> inflectName ( $ widget ) . '_' . $ uniqStr ( 5 ) ; } return $ this -> ID ; }
Return Unique ID for each widget
57,414
protected function inflectName ( $ name ) { if ( ! $ this -> inflector ) { $ this -> inflector = new Filter \ Word \ CamelCaseToDash ( ) ; } return strtolower ( $ this -> inflector -> filter ( $ name ) ) ; }
Inflect a name to a normalized value
57,415
protected function deriveModuleNamespace ( ) { $ widget = get_class ( $ this ) ; if ( ! strstr ( $ widget , '\\' ) ) return '' ; $ module = substr ( $ widget , 0 , strpos ( $ widget , '\\' ) ) ; return $ module ; }
Determine the top - level namespace of the object
57,416
protected function deriveWidgetName ( ) { $ widget = get_class ( $ this ) ; if ( strstr ( $ widget , '\\' ) ) { $ widget = substr ( $ widget , strpos ( $ widget , '\\' ) + 1 ) ; $ widget = substr ( $ widget , 0 , strrpos ( $ widget , '\\' ) ) ; } if ( strstr ( $ widget , '\\' ) ) { $ widget = substr ( $ widget , strpos ( $ widget , '\\' ) + 1 ) ; } return $ widget ; }
Determine the name of the widget
57,417
public function hookValidatorHandlers ( array & $ handlers ) { foreach ( array_keys ( $ this -> getHandlers ( ) ) as $ command_id ) { $ class = str_replace ( '_' , '' , $ command_id ) ; $ handlers [ "file_manager_$command_id" ] = array ( 'handlers' => array ( 'validate' => array ( "gplcart\\modules\\file_manager\\handlers\\validators\\$class" , "validate$class" ) ) , ) ; } $ handlers [ 'file_manager_settings' ] = array ( 'handlers' => array ( 'validate' => array ( 'gplcart\\modules\\file_manager\\handlers\\validators\\Settings' , 'validateSettings' ) ) , ) ; }
Implements hook validator . handlers
57,418
public function hookUserRolePermissions ( array & $ permissions ) { $ permissions [ 'module_file_manager' ] = gplcart_text ( 'File manager: access' ) ; foreach ( $ this -> getHandlers ( ) as $ command_id => $ command ) { $ permissions [ "module_file_manager_$command_id" ] = gplcart_text ( 'File manager: perform command @name' , array ( '@name' => $ command [ 'name' ] ) ) ; } }
Implements hook user . role . permissions
57,419
public function getFields ( ) { $ query_fields = $ this -> query [ 'fields' ] ?? '' ; if ( $ query_fields === '' ) { return [ ] ; } $ special = $ this -> getSpecialFields ( ) ; foreach ( $ special as $ key => $ value ) { $ special [ $ key ] = implode ( ',' , $ value ) ; } $ fields = array_filter ( explode ( ',' , str_replace ( array_keys ( $ special ) , $ special , $ query_fields ) ) ) ; $ message = $ this -> hasFields ( $ fields ) ; if ( $ message !== true ) { return $ message ; } return $ fields ; }
Returns quered fields
57,420
public function getList ( ) { if ( $ this -> kind === 'collection' ) { $ model_class = $ this -> model_class ; return $ model_class :: dump ( $ this -> where , $ model_class :: PRIMARY_KEY ) ; } return [ $ this -> where ] ; }
Returns a list of arrays to load models
57,421
public function getSpecialFields ( ) { $ cached = $ this -> cache [ 'special_fields' ] ?? null ; if ( $ cached !== null ) { return $ cached ; } $ model = $ this -> model_class ; $ special = [ 'PRIMARY_KEY' => $ model :: PRIMARY_KEY , 'AUTO_INCREMENT' => ( array ) $ model :: AUTO_INCREMENT , 'STAMP_COLUMNS' => $ model :: STAMP_COLUMNS , 'OPTIONAL_COLUMNS' => $ model :: OPTIONAL_COLUMNS , 'FOREIGN_KEYS' => array_keys ( $ model :: FOREIGN_KEYS ) , 'SOFT_DELETE' => ( array ) $ model :: SOFT_DELETE , ] ; $ this -> cache [ 'special_fields' ] = $ special ; return $ special ; }
Returns map of special fields
57,422
public function hasFields ( array $ fields ) { try { $ this -> model_class :: checkUnknownColumn ( $ fields ) ; } catch ( UnknownColumnException $ e ) { return "Resource '$this->name' " . explode ( ' ' , $ e -> getMessage ( ) , 2 ) [ 1 ] ; } return true ; }
Checks if Resource has all fields passed
57,423
public function environment ( $ environment = Scheme :: BASE ) { if ( func_num_args ( ) !== 0 ) { $ this -> environment = $ environment ; Event :: signal ( 'core.environment.change' , array ( $ environment , & $ this ) ) ; return $ this ; } return $ this -> environment ; }
Change current system working environment or receive current system enviroment if no arguments are passed .
57,424
public function cached ( $ cacheLife = 3600 , $ accessibility = 'public' ) { static $ cached ; if ( ! isset ( $ cached ) or $ cached !== true ) { header ( 'Expires: ' . gmdate ( 'D, d M Y H:i:s T' , time ( ) + $ cacheLife ) ) ; header ( 'Cache-Control: ' . $ accessibility . ', max-age=' . $ cacheLife ) ; header ( 'Pragma: cache' ) ; $ cached = true ; } }
Generate special response header triggering caching mechanisms
57,425
public function generateTemplate ( & $ templateHtml ) { $ headHtml = "\n" . '<base href="' . url ( ) -> base ( ) . '">' ; $ headHtml .= "\n" . '<script type="text/javascript">var __SAMSONPHP_STARTED = new Date().getTime();</script>' ; $ headHtml .= "\n" . '<!--[if lt IE 9]>' ; $ headHtml .= "\n" . '<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>' ; $ headHtml .= "\n" . '<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>' ; $ headHtml .= "\n" . '<![endif] ; $ templateHtml = str_ireplace ( '<head>' , '<head>' . $ headHtml , $ templateHtml ) ; $ templateHtml = str_ireplace ( '</html>' , '</html>' . __SAMSON_COPYRIGHT , $ templateHtml ) ; return $ templateHtml ; }
Insert generic html template tags and data
57,426
public function start ( $ default ) { Event :: fire ( 'core.started' ) ; $ this -> template ( $ this -> template_path ) ; $ securityResult = true ; $ result = false ; if ( $ securityResult ) { Event :: signal ( 'core.routing' , array ( & $ this , & $ result , $ default ) ) ; } if ( ! isset ( $ result ) || $ result === false ) { $ result = Event :: signal ( 'core.e404' , array ( url ( ) -> module , url ( ) -> method ) ) ; } $ output = '' ; if ( ! $ this -> async && ( $ result !== false ) ) { $ data = $ this -> active -> toView ( ) ; $ output = $ this -> render ( $ this -> template_path , $ data ) ; Event :: fire ( 'core.rendered' , array ( & $ output ) ) ; } echo $ output ; Event :: fire ( 'core.ended' , array ( & $ output ) ) ; }
Start SamsonPHP framework .
57,427
public function render ( $ view , $ data = array ( ) ) { if ( is_array ( $ data ) ) { extract ( $ data ) ; } ob_start ( ) ; $ templateView = $ view ; if ( locale ( ) != SamsonLocale :: DEF ) { $ templateView = str_replace ( __SAMSON_VIEW_PATH , __SAMSON_VIEW_PATH . locale ( ) . '/' , $ templateView ) ; } switch ( $ this -> render_mode ) { case self :: RENDER_STANDART : if ( file_exists ( $ templateView ) ) { include ( $ templateView ) ; } elseif ( file_exists ( $ view ) ) { include ( $ view ) ; } else { throw ( new ViewPathNotFound ( $ view ) ) ; } break ; case self :: RENDER_VARIABLE : $ views = & $ GLOBALS [ '__compressor_files' ] ; if ( isset ( $ views [ $ templateView ] ) ) { eval ( ' ?>' . $ views [ $ templateView ] . '<?php ' ) ; } elseif ( isset ( $ views [ $ view ] ) ) { eval ( ' ?>' . $ views [ $ view ] . '<?php ' ) ; } else { throw ( new ViewPathNotFound ( $ view ) ) ; } break ; } $ html = ob_get_contents ( ) ; ob_end_clean ( ) ; Event :: fire ( 'core.render' , array ( & $ html , & $ data , & $ this -> active ) ) ; return $ html ; }
Render file to a buffer .
57,428
public function composer ( $ dependencyFilePath = null ) { $ this -> active = new VirtualModule ( $ this -> system_path , $ this -> map , $ this , 'local' ) ; return $ this ; }
Load system from composer . json
57,429
private function chargeNew ( $ capture ) { return dfc ( $ this , function ( $ capture ) { $ fc = $ this -> fCharge ( ) ; if ( $ needPreorder = $ fc -> needPreorder ( ) ) { $ preorderParams = pPreorder :: request ( $ this ) ; df_sentry_extra ( $ this , 'Preorder Params' , $ preorderParams ) ; $ fc -> preorderSet ( fPreorder :: s ( $ this ) -> create ( $ preorderParams ) ) ; } $ p = pCharge :: request ( $ this , $ capture ) ; df_sentry_extra ( $ this , 'Request Params' , $ p ) ; $ result = $ fc -> create ( $ p ) ; if ( $ this -> isCard ( ) ) { $ cf = CardFormatter :: s ( $ this , $ fc -> card ( $ result ) ) ; $ this -> iiaAdd ( $ cf -> ii ( ) ) ; } $ this -> transInfo ( $ result , $ p + ( ! $ needPreorder ? [ ] : [ 'df_preorder' => $ preorderParams ] ) ) ; $ needRedirect = $ this -> redirectNeeded ( $ result ) ; $ i = $ this -> ii ( ) ; $ i -> setTransactionId ( $ this -> e2i ( $ fc -> id ( $ result ) , $ needRedirect ? $ this -> transPrefixForRedirectCase ( ) : ( $ capture ? Ev :: T_CAPTURE : Ev :: T_AUTHORIZE ) ) ) ; $ i -> setIsTransactionClosed ( $ capture && ! $ needRedirect ) ; if ( $ needRedirect ) { $ i -> addTransaction ( T :: TYPE_PAYMENT ) ; } return $ result ; } , func_get_args ( ) ) ; }
2016 - 12 - 28
57,430
public static function stripFileExtension ( $ string , $ asArray = false ) { $ regexp = "|\.\w{1,5}$|" ; $ new = preg_replace ( $ regexp , "" , $ string ) ; $ suf = substr ( $ string , strlen ( $ new ) + 1 ) ; if ( $ asArray == true ) { return array ( 'location' => $ new , 'suffix' => $ suf ) ; } else { return $ new ; } }
strips the file extension
57,431
public static function extractHtmlPart ( $ html , $ filter = false ) { if ( $ filter ) { $ startTag = "<{$filter}>" ; $ endTag = "</{$filter}>" ; } else { $ startTag = "<body>" ; $ endTag = "</body>" ; } $ startPattern = ".*" . $ startTag ; $ endPattern = $ endTag . ".*" ; $ noheader = eregi_replace ( $ startPattern , "" , $ html ) ; $ cleanPart = eregi_replace ( $ endPattern , "" , $ noheader ) ; return $ cleanPart ; }
returns the html between the body tags if filter is set then it will return the html between the specified tags
57,432
public static function replaceTag ( $ tag , $ replacement , $ content , $ attributes = null ) { $ content = preg_replace ( "/<{$tag}.*?>/" , "<{$replacement} {$attributes}>" , $ content ) ; $ content = preg_replace ( "/<\/{$tag}>/" , "</{$replacement}>" , $ content ) ; return $ content ; }
note that this does not transfer any of the attributes
57,433
protected function getWireshellErrorMessage ( $ wireshellOutput ) { $ message = $ wireshellOutput ; return $ message ; $ match = null ; if ( preg_match ( "/\[[A-Za-z]+Exception\](.+)\R\R/s" , $ message , $ match ) ) { $ message = $ match [ 1 ] ; $ message = substr ( $ message , 0 , strpos ( $ message , PHP_EOL . PHP_EOL ) ) ; $ message = trim ( $ message ) ; $ message = implode ( PHP_EOL , array_map ( function ( $ line ) { return trim ( $ line ) ; } , explode ( PHP_EOL , $ message ) ) ) ; } return $ message ; }
Process wireshell error output . Extracts error message if possible .
57,434
public function attach ( ActionEventDispatcher $ events ) { $ this -> trackHandler ( $ events -> attachListener ( MessageDispatch :: ROUTE , array ( $ this , 'onRouteMessage' ) , 100 ) ) ; }
Attach to CommandBus or EventBus route event
57,435
public function disposition ( $ file ) { $ type = ResponseHeaderBag :: DISPOSITION_ATTACHMENT ; return $ this -> foundation -> headers -> makeDisposition ( $ type , $ file ) ; }
Create the proper Content - Disposition header .
57,436
public function send ( ) { $ this -> cookies ( ) ; $ this -> foundation -> prepare ( Request :: foundation ( ) ) ; $ this -> foundation -> send ( ) ; }
Send the headers and content of the response to the browser .
57,437
public function render ( ) { if ( str_object ( $ this -> content ) ) { $ this -> content = $ this -> content -> __toString ( ) ; } else { $ this -> content = ( string ) $ this -> content ; } $ this -> foundation -> setContent ( $ this -> content ) ; return $ this -> content ; }
Convert the content of the Response to a string and return it .
57,438
protected function cookies ( ) { $ ref = new \ ReflectionClass ( 'Symfony\Component\HttpFoundation\Cookie' ) ; foreach ( Cookie :: $ jar as $ name => $ cookie ) { $ config = array_values ( $ cookie ) ; $ this -> headers ( ) -> setCookie ( $ ref -> newInstanceArgs ( $ config ) ) ; } }
Set the cookies on the HttpFoundation Response .
57,439
public function header ( $ name , $ value ) { $ this -> foundation -> headers -> set ( $ name , $ value ) ; return $ this ; }
Add a header to the array of response headers .
57,440
public function getTargetIdFor ( int $ sourceId ) : int { if ( ! array_key_exists ( $ sourceId , $ this -> map ) ) { throw new \ RuntimeException ( 'Not mapped' ) ; } return $ this -> map [ $ sourceId ] ; }
Obtain the target id for the passed source .
57,441
public function getSourceIdFor ( int $ targetId ) : int { if ( ! array_key_exists ( $ targetId , $ this -> mapInverse ) ) { throw new \ RuntimeException ( 'Not mapped' ) ; } return $ this -> mapInverse [ $ targetId ] ; }
Obtain the source id for the passed target .
57,442
public function getMainFromSource ( int $ sourceId ) : int { if ( ! array_key_exists ( $ sourceId , $ this -> sourceMap ) ) { throw new \ RuntimeException ( 'Not mapped' ) ; } return $ this -> sourceMap [ $ sourceId ] ; }
Obtain the main id from a source id .
57,443
public function getMainFromTarget ( int $ target ) : int { if ( ! array_key_exists ( $ target , $ this -> targetMap ) ) { throw new \ RuntimeException ( 'Not mapped' ) ; } return $ this -> targetMap [ $ target ] ; }
Obtain the main id from a target id .
57,444
public function combineSourceAndTargetMaps ( ) : void { $ this -> analyzeMap ( ) ; foreach ( $ this -> targetMap as $ targetId => $ mainId ) { if ( ! array_key_exists ( $ mainId , $ this -> sourceMapInverse ) ) { continue ; } $ sourceId = $ this -> sourceMapInverse [ $ mainId ] ; $ this -> map [ $ sourceId ] = $ targetId ; $ this -> mapInverse [ $ targetId ] = $ sourceId ; } }
Create the combined map from source and target .
57,445
public function analyzeMap ( ) : void { $ this -> analyzeDuplicates ( 'source' , $ this -> sourceLanguage , $ this -> sourceMap , $ this -> sourceMapInverse ) ; $ this -> analyzeDuplicates ( 'target' , $ this -> targetLanguage , $ this -> targetMap , $ this -> targetMapInverse ) ; foreach ( $ this -> targetMap as $ targetId => $ mainId ) { if ( ! array_key_exists ( $ mainId , $ this -> sourceMapInverse ) ) { $ this -> logger -> warning ( 'No source for target found. ' . '{targetLanguage}: {targetId} => {mainLanguage}: {mainId} <= {sourceLanguage}: ?' , [ 'sourceLanguage' => $ this -> sourceLanguage , 'mainLanguage' => $ this -> mainLanguage , 'targetLanguage' => $ this -> targetLanguage , 'targetId' => $ targetId , 'mainId' => $ mainId , 'msg_type' => 'no_source_for_target' , 'class' => \ get_class ( $ this ) , ] ) ; } } }
Analyze the map for common mistakes .
57,446
protected function analyzeDuplicates ( string $ mapName , string $ language , array $ map , array $ inverse ) : void { if ( \ count ( $ inverse ) !== \ count ( $ map ) ) { $ diff = array_diff ( array_keys ( $ map ) , array_values ( $ inverse ) ) ; foreach ( $ diff as $ mapId ) { $ mainId = $ map [ $ mapId ] ; $ multiple = [ ] ; foreach ( $ map as $ checkMapId => $ checkMainId ) { if ( $ checkMainId === $ mainId ) { $ multiple [ ] = $ checkMapId ; } } $ this -> logger -> warning ( ucfirst ( $ mapName ) . ' map {mainLanguage} => {language}: multiple elements map to {mainId}: ' . implode ( ', ' , $ multiple ) , [ 'language' => $ language , 'mainLanguage' => $ this -> mainLanguage , 'mainId' => $ mainId , 'multiple' => $ multiple , 'msg_type' => 'multiple_mapping_in_' . $ mapName , 'class' => \ get_class ( $ this ) , ] ) ; } } }
Analyze duplicates in the mapping of a table .
57,447
public function refresh ( String $ url = NULL , Int $ time = 0 , Array $ data = NULL , Bool $ exit = false ) { $ this -> location ( $ url , $ time , $ data , $ exit , __FUNCTION__ ) ; }
Page refresh .
57,448
public function deleteData ( $ data ) : Bool { if ( is_array ( $ data ) ) foreach ( $ data as $ v ) { unset ( $ _SESSION [ $ this -> fix . $ v ] ) ; } else { unset ( $ _SESSION [ $ this -> fix . $ data ] ) ; } return true ; }
Redirect delete data
57,449
public function getExtractorsForTable ( string $ tableName ) : array { if ( ! isset ( $ this -> tableExtractors [ $ tableName ] ) ) { return [ ] ; } $ extractors = [ ] ; foreach ( $ this -> tableExtractors [ $ tableName ] as $ tableExtractor ) { if ( ! $ this -> extractorContainer -> has ( $ tableExtractor ) ) { throw new \ RuntimeException ( 'Could not get extractor ' . $ tableExtractor ) ; } $ extractors [ ] = $ extractor = $ this -> extractorContainer -> get ( $ tableExtractor ) ; $ this -> logger -> debug ( 'Adding extractor ' . $ extractor -> name ( ) ) ; } return $ extractors ; }
Get the extractors for the passed table .
57,450
public function addSessionFlashBagMessage ( $ type , $ message , $ translationDomain = 'messages' ) { if ( false !== $ translationDomain ) { $ message = $ this -> get ( 'translator' ) -> trans ( $ message , [ ] , $ translationDomain ) ; } $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( $ type , $ message ) ; return $ this ; }
Add FlashBag Message
57,451
public function savedObject ( $ type , $ object , $ message = 'flash_bag.success.default' , $ fragment = null ) { $ objectRouter = $ this -> get ( "bg_object_routing.object_router" ) ; $ this -> addSessionFlashBagMessage ( self :: SESSION_FLASH_BAG_SUCCESS , $ message ) ; $ url = $ objectRouter -> generate ( $ type , $ object ) ; if ( null !== $ fragment ) { $ url = sprintf ( '%s#%s' , $ url , $ fragment ) ; } return $ this -> redirect ( $ url ) ; }
Saved with Object Routing
57,452
public function deniedObject ( $ type , $ object , $ message = 'flash_bag.error.default' ) { $ objectRouter = $ this -> get ( "bg_object_routing.object_router" ) ; $ this -> addSessionFlashBagMessage ( self :: SESSION_FLASH_BAG_ERROR , $ message ) ; return $ this -> redirect ( $ objectRouter -> generate ( $ type , $ object ) ) ; }
Denied with Object Routing
57,453
final public function find ( $ css_selector ) { $ find = NULL ; $ doc = new \ PHPTools \ PHPHtmlDom \ PHPHtmlDom ; if ( ! ! $ doc -> importHTML ( $ this -> list_html ) ) { $ find = $ doc -> e ( $ css_selector ) ; } return $ find ; }
Este metodo permite obtener otros elementos internos .
57,454
final public function each ( $ func ) { foreach ( $ this -> elements as $ inx => $ val ) { call_user_func ( $ func , $ inx , $ val ) ; } return $ this ; }
Este metodo permite aplicar una funcion a la lista de los elementos
57,455
final public function eq ( $ inx ) { return isset ( $ this -> elements [ $ inx ] ) ? $ this -> elements [ $ inx ] : NULL ; }
Este metoodo permite obtener un elemento espesifico de la lista .
57,456
public function setIncludePath ( $ includePath ) { if ( ! file_exists ( $ includePath ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Path "%s" declared as namespace\'s "%s" include path does not exist!' , $ includePath , $ this -> getNamespace ( ) ) ) ; } if ( ! is_dir ( $ includePath ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Path "%s" declared as namespace\'s "%s" include path is not a directory!' , $ includePath , $ this -> getNamespace ( ) ) ) ; } $ this -> _includePath = realpath ( $ includePath ) ; return $ this ; }
Sets the base include path for all class files in the namespace of this class loader .
57,457
public function setFailureFlag ( $ failureFlag ) { if ( ! in_array ( $ failureFlag , array ( self :: FAIL_GRACEFULLY , self :: FAIL_WITH_ERROR ) ) ) { throw new \ InvalidArgumentException ( 'The failure flag of an SplClassLoader instance must be one of class "FAIL_" constants!' ) ; } $ this -> _failureFlag = $ failureFlag ; return $ this ; }
Sets the failure flag of the namespace loader .
57,458
public function resolveFileName ( $ className ) { if ( null === $ this -> getNamespace ( ) || $ this -> getNamespace ( ) . $ this -> getNamespaceSeparator ( ) === substr ( $ className , 0 , strlen ( $ this -> getNamespace ( ) . $ this -> getNamespaceSeparator ( ) ) ) ) { $ fileName = '' ; $ namespace = '' ; if ( false !== ( $ lastNsPos = strripos ( $ className , $ this -> getNamespaceSeparator ( ) ) ) ) { $ namespace = substr ( $ className , 0 , $ lastNsPos ) ; $ className = substr ( $ className , $ lastNsPos + 1 ) ; $ fileName = str_replace ( $ this -> getNamespaceSeparator ( ) , DIRECTORY_SEPARATOR , $ namespace ) . DIRECTORY_SEPARATOR ; } $ fileName .= str_replace ( '_' , DIRECTORY_SEPARATOR , $ className ) . $ this -> getFileExtension ( ) ; return ( $ this -> getIncludePath ( ) !== null ? $ this -> getIncludePath ( ) . DIRECTORY_SEPARATOR : '' ) . $ fileName ; } return null ; }
Constructs the file path of a class .
57,459
public function classFileExists ( $ classFile ) { if ( file_exists ( $ classFile ) ) { return true ; } foreach ( explode ( PATH_SEPARATOR , get_include_path ( ) ) as $ path ) { if ( file_exists ( $ path ) && file_exists ( $ path . DIRECTORY_SEPARATOR . $ classFile ) ) { return true ; } } return false ; }
Checks if the given class file exists .
57,460
private static function mysqltcsCheck ( Mysqltcs $ mysqltcs ) { if ( $ mysqltcs == null || ! ( $ mysqltcs instanceof Mysqltcs ) ) { throw new MysqltcsException ( "mysqltcs passed is not an instance of Mysqltcs" ) ; } if ( ! $ mysqltcs -> isConnected ( ) ) { throw new MysqltcsException ( "mysqltcs passed is not connected" ) ; } }
throw exception if mysqltcs passed is not valid
57,461
public function insert ( $ fields , $ values , $ from = "" ) { $ from = $ this -> fromCheck ( $ from , true ) ; $ this -> mysqltcs -> executeQuery ( "INSERT INTO $from ($fields) VALUES " . self :: insertValues ( $ values ) . ";" ) ; }
Insert a row or multiple rows
57,462
public function getList ( $ select , $ where , $ order = "" , $ from = "" , $ quotes = null ) { if ( $ order ) return $ this -> getListAdvanced ( $ select , $ where , " ORDER BY " . $ order , $ from , $ quotes ) ; else return $ this -> getListAdvanced ( $ select , $ where , $ order , $ from , $ quotes ) ; }
This method make a select and return the results as a associative matrix you can make a simple select in one or in more tables you can make a select with order or not . This is a less powerful method than getListAdvanced
57,463
public function update ( array $ values , $ where , $ from = "" , $ quotes = null ) { $ from = $ this -> fromCheck ( $ from , $ quotes ) ; $ set = self :: updateSet ( $ values ) ; $ this -> mysqltcs -> executeQuery ( "UPDATE $from SET $set WHERE $where;" ) ; return $ this -> mysqltcs -> getAffectedRows ( ) ; }
make an SQL update
57,464
private static function updateSet ( array $ values ) { $ ret = "" ; foreach ( $ values as $ key => $ value ) $ ret .= $ key . "=" . $ value . ", " ; $ ret = substr ( $ ret , 0 , - 2 ) ; return $ ret ; }
return the SQL string for set
57,465
public function doValidation ( ) : bool { $ res = $ this -> validate ( ) ; if ( $ res ) { $ this -> status = self :: ERROR ; } return $ res ; }
Kicks of the validation and sets the status accordingly
57,466
public function validatePlugin ( $ plugin ) { if ( ! $ plugin instanceof ModelInterface ) { throw new Exception \ InvalidPluginException ( sprintf ( 'Model of type %s is invalid; must implement "%s"' , ( is_object ( $ plugin ) ? get_class ( $ plugin ) : gettype ( $ plugin ) ) , ModelInterface :: class ) ) ; } }
Validate the plugin Checks that the model loaded is an instance of ModelInterface .
57,467
private function fetchArticlesFrom ( int $ pageId , array & $ map , int $ mainPage ) : void { $ this -> logger -> debug ( 'Mapping articles from page ' . $ pageId ) ; $ articles = $ this -> database -> getArticlesByPid ( $ pageId ) ; if ( empty ( $ articles ) ) { if ( \ in_array ( $ pageType = $ this -> pageMap -> getTypeFor ( $ pageId ) , [ 'error_403' , 'error_404' , 'forward' , 'redirect' , 'root' ] ) ) { return ; } $ this -> logger -> notice ( 'Page {id} has no articles.' , [ 'id' => $ pageId , 'pageType' => $ pageType , 'msg_type' => 'page_no_articles' ] ) ; return ; } if ( $ pageId === $ mainPage ) { foreach ( $ articles as $ index => $ article ) { $ articleId = ( int ) $ article [ 'id' ] ; $ map [ $ articleId ] = $ articleId ; } return ; } foreach ( $ articles as $ index => $ article ) { $ mainId = ( int ) $ article [ 'languageMain' ] ; $ articleId = ( int ) $ article [ 'id' ] ; if ( empty ( $ mainId ) ) { if ( 0 === ( $ mainId = $ this -> determineMapFor ( $ index , $ article [ 'inColumn' ] , $ mainPage ) ) ) { $ this -> logger -> warning ( 'Article {id} in page {page} has no fallback set and unable to determine automatically. ' . 'Article skipped.' , [ 'id' => $ articleId , 'page' => ( int ) $ article [ 'pid' ] , 'msg_type' => 'article_no_fallback' ] ) ; continue ; } $ this -> logger -> warning ( 'Article {id} (index: {index}) has no fallback set, expect problems, I guess it is {guessed}' , [ 'id' => $ articleId , 'index' => $ index , 'guessed' => $ mainId , 'msg_type' => 'article_fallback_guess' ] ) ; } $ map [ $ articleId ] = $ mainId ; } }
Fetch articles from a page .
57,468
protected function determineMapFor ( int $ index , string $ column , int $ mainPage ) : int { $ mainSiblings = $ this -> database -> getArticlesByPid ( $ mainPage , $ column ) ; return isset ( $ mainSiblings [ $ index ] ) ? ( int ) $ mainSiblings [ $ index ] [ 'id' ] : 0 ; }
Determine the mapping of an article by its index in the list of the main page articles .
57,469
public function getName ( $ option = null ) { if ( empty ( $ option ) ) { $ option = $ this -> getOptions ( ) ; } $ name = $ option -> getName ( ) ; if ( empty ( $ name ) ) { throw new \ Exception ( 'Empty name' ) ; } return $ name ; }
Returns active Option name . Used to auto - generate options and entity names
57,470
public function getOptions ( ) { if ( null === $ this -> options ) { $ routeMatch = $ this -> getEvent ( ) -> getRouteMatch ( ) ; $ privilege = $ routeMatch -> getParam ( 'xelax_admin_privilege' ) ; if ( empty ( $ privilege ) ) { throw new Exception ( 'XelaxAdmin\Router\ListRoute route required' ) ; } $ options = $ this -> getServiceLocator ( ) -> get ( 'XelaxAdmin\ListControllerOptions' ) ; $ activeOption = null ; $ parts = explode ( '/' , $ privilege ) ; $ action = array_pop ( $ parts ) ; foreach ( $ parts as $ part ) { if ( array_key_exists ( $ part , $ options ) ) { $ activeOption = $ options [ $ part ] ; $ options = $ activeOption -> getChildOptions ( ) ; } else { throw new Exception ( "Active ListControllerOptions not found" ) ; } } if ( empty ( $ activeOption ) ) { throw new Exception ( "Active ListControllerOptions not found" ) ; } $ this -> options = $ activeOption ; } return $ this -> options ; }
Gets active controllerOptions depending on the RouteMatch
57,471
protected function getAll ( ) { $ em = $ this -> getEntityManager ( ) ; $ entityClass = $ this -> getEntityClass ( ) ; if ( empty ( $ this -> getParentControllerOptions ( ) ) ) { $ items = $ em -> getRepository ( $ entityClass ) -> findAll ( ) ; } else { $ parentId = $ this -> getEvent ( ) -> getRouteMatch ( ) -> getParam ( $ this -> getParentControllerOptions ( ) -> getIdParamName ( ) ) ; $ items = $ em -> getRepository ( $ entityClass ) -> findBy ( array ( $ this -> getOptions ( ) -> getParentAttributeName ( ) => $ parentId ) ) ; } return $ items ; }
Returns list of all items to show in list view . Overwrite to add custom filters
57,472
protected function getForm ( $ name = null , $ option = null ) { if ( ! $ name ) { $ name = $ this -> getName ( ) ; } $ frmCls = $ this -> getFormClass ( $ option ) ; $ form = $ this -> getServiceLocator ( ) -> get ( 'FormElementManager' ) -> get ( $ frmCls ) ; return $ form ; }
Returns form used for both edit and create . Overwrite getEditForm or getCreateForm to use different forms for these views
57,473
public static function getDataUriFromUploadedFile ( UploadedFile $ file ) { return sprintf ( 'data:%s;base64,%s' , $ file -> getMimeType ( ) , base64_encode ( file_get_contents ( $ file -> getPathname ( ) ) ) ) ; }
Get Base64 Encoded Data Uri
57,474
public static function getResponseFromDataUri ( $ dataUri ) { $ mimeType = substr ( $ dataUri , 5 , strpos ( $ dataUri , ';' ) - 5 ) ; $ content = base64_decode ( substr ( $ dataUri , strpos ( $ dataUri , ',' ) + 1 ) ) ; return new Response ( $ content , Response :: HTTP_OK , [ 'Content-Type' => $ mimeType , ] ) ; }
Get Response From DataUri
57,475
public static function getFiles ( $ folder , $ excludeFolders = self :: INCLUDE_FOLDERS ) { $ files = [ ] ; if ( false === is_dir ( $ folder ) ) { return [ ] ; } $ handle = opendir ( $ folder ) ; while ( false !== ( $ entry = readdir ( $ handle ) ) ) { if ( true === in_array ( $ entry , self :: getDirSymbols ( ) ) ) { continue ; } if ( self :: EXCLUDE_FOLDERS === $ excludeFolders && true === is_dir ( sprintf ( '%s/%s' , $ folder , $ entry ) ) ) { continue ; } $ files [ ] = $ entry ; } closedir ( $ handle ) ; return $ files ; }
Get Files and folders
57,476
public static function getFolderAsArray ( $ root ) { if ( false === is_dir ( $ root ) ) { return null ; } $ result = [ ] ; $ folderContent = scandir ( $ root ) ; $ dirChecks = [ true , false , ] ; foreach ( $ dirChecks as $ dirCheck ) { foreach ( $ folderContent as $ entry ) { if ( true === in_array ( $ entry , self :: getDirSymbols ( ) ) ) { continue ; } $ path = sprintf ( '%s/%s' , $ root , $ entry ) ; if ( $ dirCheck === is_dir ( $ path ) ) { $ result [ $ entry ] = self :: getFolderAsArray ( $ path ) ; } } } return $ result ; }
Get Folders and Files recursive
57,477
public static function proxy ( FutureInterface $ future , callable $ onFulfilled = null , callable $ onRejected = null , callable $ onProgress = null ) { return new FutureResponse ( $ future -> then ( $ onFulfilled , $ onRejected , $ onProgress ) , [ $ future , 'wait' ] , [ $ future , 'cancel' ] ) ; }
Returns a FutureResponse that wraps another future .
57,478
public function getNextPossibleIdInContext ( Node $ node ) { if ( ! isset ( $ this -> idList [ $ node -> id ] ) ) { return $ node -> id ; } $ newId = false ; $ id = $ node -> id ; for ( $ i = 0 ; $ newId == false ; $ i ++ ) { $ newId = rtrim ( $ id , $ node -> keyDelimiter ) . Node :: MULTIPLE_ID_ENTRY_DELIMITER . "$i{$node->keyDelimiter}" ; if ( $ id > 100 ) { throw new \ Exception ( 'Are you crazy? 1000 child elements with the same ID ?' ) ; } } return $ newId ; }
this method will iterate over all sibl
57,479
public function moveNode ( Node $ node , Node $ parent ) { $ node -> setParent ( $ parent ) -> updateId ( ) ; $ this -> idList [ $ node -> id ] = $ node ; return $ this ; }
move the node within the current schema
57,480
public function getById ( $ id ) { if ( isset ( $ this -> idList [ $ id ] ) ) { return $ this -> idList [ $ id ] ; } return null ; }
gets a node by its unique id
57,481
public function getByIdFuzzy ( $ key ) { if ( ! $ key ) { return null ; } $ resultSet = new \ SplDoublyLinkedList ( ) ; foreach ( $ this -> idList as $ id => $ node ) { if ( strpos ( $ id , "{$node->keyDelimiter}{$key}{$node->keyDelimiter}" ) !== false ) { $ resultSet -> push ( $ node ) ; } } return $ resultSet ; }
fuzzy search option based on the id - > it s a strpos comparison so every hit is returned
57,482
public function getLastByKey ( $ key ) { if ( ! isset ( $ this -> keyList [ $ key ] ) ) { return null ; } return $ this -> keyList [ $ key ] -> top ( ) ; }
walks through the child nodes
57,483
public static function getCollectors ( ) { $ collectorClassList = ClassMapGenerator :: createMap ( base_path ( ) . '/vendor/abuseio' ) ; $ collectorClassListFiltered = array_where ( array_keys ( $ collectorClassList ) , function ( $ value , $ key ) { if ( strpos ( $ value , 'AbuseIO\Collectors\\' ) !== false ) { return $ value ; } return false ; } ) ; $ collectors = [ ] ; $ collectorList = array_map ( 'class_basename' , $ collectorClassListFiltered ) ; foreach ( $ collectorList as $ collector ) { if ( ! in_array ( $ collector , [ 'Factory' , 'Collector' ] ) ) { $ collectors [ ] = $ collector ; } } return $ collectors ; }
Get a list of installed AbuseIO collectors and return as an array
57,484
public static function create ( $ requiredName ) { $ collectors = Factory :: getCollectors ( ) ; foreach ( $ collectors as $ collectorName ) { if ( $ collectorName === ucfirst ( $ requiredName ) ) { $ collectorClass = 'AbuseIO\\Collectors\\' . $ collectorName ; if ( config ( "collectors.{$collectorName}.collector.enabled" ) === true ) { return new $ collectorClass ( ) ; } else { Log :: info ( 'AbuseIO\Collectors\Factory: ' . "The collector {$collectorName} has been disabled and will not be used." ) ; } } } Log :: info ( 'AbuseIO\Collectors\Factory: ' . "The collector {$requiredName} is not present on this system" ) ; return false ; }
Create and return a Collector object and it s configuration
57,485
protected function askAssignment ( ) { $ this -> assignments = $ this -> fetchAssignments ( ) ; $ names = collect ( $ this -> assignments ) -> pluck ( 'name' ) -> toArray ( ) ; $ default = array_search ( $ this -> currentAssignment ( ) , $ names ) ; $ selected = $ this -> choice ( 'Assignment?' , $ names , $ default ) ; return $ this -> findAssignmentByName ( $ selected ) -> id ; }
Ask assignment .
57,486
protected function findAssignmentByName ( $ name ) { $ assignmentFound = collect ( $ this -> assignments ) -> filter ( function ( $ assignment ) use ( $ name ) { return $ assignment -> name == $ name ; } ) -> first ( ) ; if ( $ assignmentFound ) return $ assignmentFound ; return null ; }
Find assignment by name .
57,487
public static function type ( String $ file , $ element = NULL ) { if ( ! is_file ( $ file ) ) { return false ; } $ return = mime_content_type ( $ file ) ; if ( $ element === NULL ) { return $ return ; } return explode ( '/' , $ return ) [ $ element ] ?? false ; }
Mime Content Type
57,488
public function execute ( array $ parameters = [ ] , $ force = false ) { if ( $ force === true || $ this -> checkBuildConditions ( ) ) { $ this -> builder -> setParameters ( $ parameters ) ; $ this -> build ( ) ; } return $ this -> instance ; }
Execute the resolver and return the instance
57,489
protected function checkBuildConditions ( ) { if ( $ this -> shared === false ) { return true ; } if ( ! is_object ( $ this -> instance ) || null === $ this -> instance ) { return true ; } return false ; }
Check if the required build conditions are met
57,490
public function index ( ) { $ openedTickets = Ticket :: where ( 'user_id' , '=' , Auth :: id ( ) ) -> where ( 'open' , true ) -> orderBy ( 'updated_at' , 'desc' ) -> get ( ) ; $ closedTickets = Ticket :: where ( 'user_id' , '=' , Auth :: id ( ) ) -> where ( 'open' , false ) -> orderBy ( 'updated_at' , 'desc' ) -> get ( ) ; return view ( 'laralum_tickets::public.index' , [ 'openedTickets' => $ openedTickets , 'closedTickets' => $ closedTickets ] ) ; }
Display the tickets in laralum administration .
57,491
public function update ( Request $ request , Ticket $ ticket ) { $ this -> authorize ( 'publicUpdate' , $ ticket ) ; $ this -> validate ( $ request , [ 'subject' => 'required|max:255' , ] ) ; $ ticket -> update ( [ 'subject' => $ request -> subject , ] ) ; return redirect ( ) -> route ( 'laralum_public::tickets.show' , [ 'ticket' => $ ticket -> id ] ) -> with ( 'success' , __ ( 'laralum_tickets::general.updated' , [ 'id' => $ ticket -> id ] ) ) ; }
Update tickets on laralum administration .
57,492
public function open ( Ticket $ ticket ) { $ this -> authorize ( 'publicStatus' , $ ticket ) ; $ ticket -> update ( [ 'open' => true , ] ) ; return redirect ( ) -> route ( 'laralum_public::tickets.index' ) -> with ( 'success' , __ ( 'laralum_tickets::general.reopened' , [ 'id' => $ ticket -> id ] ) ) ; }
Open ticket .
57,493
public function close ( Ticket $ ticket ) { $ this -> authorize ( 'publicStatus' , $ ticket ) ; $ ticket -> update ( [ 'open' => false , ] ) ; return redirect ( ) -> route ( 'laralum_public::tickets.index' ) -> with ( 'success' , __ ( 'laralum_tickets::general.closed' , [ 'id' => $ ticket -> id ] ) ) ; }
Close ticket .
57,494
public function confirmDestroy ( Ticket $ ticket ) { $ this -> authorize ( 'delete' , $ ticket ) ; return view ( 'laralum::pages.confirmation' , [ 'method' => 'DELETE' , 'message' => __ ( 'laralum_tickets::general.sure_del_ticket' , [ 'id' => $ ticket -> id ] ) , 'action' => route ( 'laralum::tickets.destroy' , [ 'ticket' => $ ticket -> id ] ) , ] ) ; }
View for cofirm delete ticket .
57,495
public function destroy ( Ticket $ ticket ) { $ this -> authorize ( 'delete' , $ ticket ) ; $ ticket -> deleteMessages ( ) ; $ ticket -> delete ( ) ; return redirect ( ) -> route ( 'laralum::tickets.index' ) ; }
Delete ticket .
57,496
public function create ( Description $ description ) { return new CategoryEntity ( new Identifier ( $ description -> getMandatoryProperty ( 'id' ) ) , $ description -> getMandatoryProperty ( 'name' ) , $ this -> getIconUrl ( $ description ) , ( bool ) $ description -> getOptionalProperty ( 'primary' , false ) ) ; }
Create a category from a description .
57,497
private function getIconUrl ( Description $ description ) { $ icon = $ description -> getMandatoryProperty ( 'icon' ) ; return sprintf ( '%s%s%s' , $ icon -> getMandatoryProperty ( 'prefix' ) , '88' , $ icon -> getMandatoryProperty ( 'suffix' ) ) ; }
Get the icon url .
57,498
protected function parseSuppliedTimezone ( $ timezone ) { if ( $ timezone instanceof \ DateTimeZone or is_null ( $ timezone ) ) { return $ timezone ; } try { $ timezone = new \ DateTimeZone ( $ timezone ) ; } catch ( Exception $ error ) { throw new \ InvalidArgumentException ( 'The supplied timezone [' . $ timezone . '] is not supported.' ) ; } return $ timezone ; }
Parse a supplied timezone .
57,499
protected function modifyDays ( $ amount , $ invert = false ) { $ interval = new \ DateInterval ( "P{$amount}D" ) ; $ this -> modifyFromInterval ( $ interval , $ invert ) ; return $ this ; }
Modify by an amount of days .