idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
26,500
protected function getMetaContent ( ) { if ( $ this -> mdFile && ! file_exists ( $ this -> mdFile ) ) { throw new ArchException ( 'Wrong markdown file [' . $ this -> mdFile . ']' ) ; } if ( $ this -> mdFile && ! $ this -> getContent ( ) ) { return Container :: getMarkdown ( ) -> file ( $ this -> mdFile , $ this -> separator ) ; } else { $ txt = '' ; if ( $ this -> mdFile ) { $ txt .= file_get_contents ( $ this -> mdFile ) ; } if ( $ this -> getContent ( ) ) { $ txt .= "\n" . $ this -> getContent ( ) ; } return Container :: getMarkdown ( ) -> txt ( $ txt , $ this -> separator ) ; } }
If file and text append file and text
26,501
public function has ( $ permissions , $ all = true ) { if ( ! is_array ( $ permissions ) ) { $ permissions = ( array ) $ permissions ; } $ permissions = array_unique ( $ permissions ) ; $ filtered = [ ] ; $ usersRoles = $ this -> roles ; $ allowed = false ; $ filtered = array_where ( $ permissions , [ $ this , 'permissionFilter' ] ) ; $ filteredCount = count ( $ filtered ) ; if ( true === $ all ) { return count ( $ permissions ) === $ filteredCount ; } return 0 < $ filteredCount ; }
Does the user have the permission?
26,502
public function give ( PermissionInterface $ permission , $ level = 'allow' ) { $ current = $ this -> getPermission ( $ permission -> key ) ; if ( isset ( $ current ) ) { if ( $ current -> level === $ level ) { return true ; } $ this -> remove ( $ permission ) ; } $ this -> removeFromLocalCache ( $ permission -> key ) ; $ this -> permissions ( ) -> attach ( $ permission , compact ( 'level' ) ) ; return false === is_null ( $ this -> getPermission ( $ permission ) ) ; }
Give a permission to the user
26,503
public function remove ( PermissionInterface $ permission ) { $ this -> removeFromLocalCache ( $ permission -> key ) ; if ( ! is_null ( $ this -> getPermission ( $ permission ) ) ) { $ this -> permissions ( ) -> detach ( $ permission ) ; } return true ; }
Remove a permission from the user
26,504
public function join ( RoleInterface $ role ) { $ this -> roles ( ) -> attach ( $ role ) ; return $ this -> is ( $ role ) ; }
Join a role
26,505
public function leave ( RoleInterface $ role ) { $ this -> roles ( ) -> detach ( $ role ) ; return $ this -> isnt ( $ role ) ; }
Leave a role
26,506
protected function getValidators ( $ types ) { $ validators = array ( ) ; if ( 'image/*' == $ types ) { $ validators [ ] = array ( 'name' => 'Zend\Validator\File\IsImage' , ) ; } else if ( ! empty ( $ types ) && '*' !== $ types && '*/*' !== $ types ) { $ validators [ ] = array ( 'name' => 'Zend\Validator\File\MimeType' , 'options' => array ( 'mimeType' => $ types ) , ) ; } return $ validators ; }
Get mime - validators for a file
26,507
protected function getForm ( $ types , $ pattern ) { $ types = preg_replace ( '/\s+/' , '' , implode ( ',' , ( array ) $ types ) ) ; if ( '*/*' === $ types ) { $ types = '*' ; } if ( empty ( $ types ) ) { $ label = 'mime.sets.*' ; } else if ( strstr ( $ types , '*' ) || strstr ( $ types , ',' ) ) { $ label = 'mime.sets.' . $ types ; } else { $ label = 'mime.type.' . $ types ; } $ accept = '*' == $ types ? '*/*' : $ types ; return $ this -> getServiceLocator ( ) -> get ( 'Zork\Form\Factory' ) -> createForm ( array ( 'attributes' => array ( 'action' => '?' , 'method' => 'post' , ) , 'elements' => array ( 'types' => array ( 'spec' => array ( 'type' => 'Zork\Form\Element\Hidden' , 'name' => 'types' , 'attributes' => array ( 'value' => $ accept , ) , ) , ) , 'pattern' => array ( 'spec' => array ( 'type' => 'Zork\Form\Element\Hidden' , 'name' => 'pattern' , 'attributes' => array ( 'value' => $ pattern , ) , ) , ) , 'file' => array ( 'spec' => array ( 'type' => 'Zork\Form\Element\File' , 'name' => 'file' , 'options' => array ( 'required' => true , 'label' => $ label , 'accept' => $ accept , 'validators' => $ this -> getValidators ( $ types ) ) , ) , ) , 'upload' => array ( 'spec' => array ( 'type' => 'Zork\Form\Element\Submit' , 'name' => 'upload' , 'attributes' => array ( 'value' => 'default.upload' , ) , ) , ) , ) , ) ) ; }
Get the upload - form
26,508
public function formList ( $ entity ) { if ( $ entity = Entity :: fromYamlFile ( $ entity ) ) { $ list = new FormList ( $ entity ) ; return $ list -> view ( ) ; } else { abort ( 404 ) ; } }
Show an entity list .
26,509
public function create ( $ entity , $ record = null , $ child = null ) { if ( ! $ record && ! $ child && ( $ entityObject = Entity :: fromYamlFile ( $ entity ) ) ) { $ form = new Form ( $ entityObject , null , Session :: get ( 'errors' ) ) ; return $ form -> view ( ) ; } elseif ( ( $ parentEntity = Entity :: fromYamlFile ( $ entity ) ) && ( $ entityObject = Entity :: fromYamlFile ( $ child ) ) ) { $ parentRecord = $ parentEntity -> class :: findOrFail ( $ record ) ; $ form = new Form ( $ entityObject , null , Session :: get ( 'errors' ) , $ parentEntity , $ parentRecord ) ; return $ form -> view ( ) ; } else { abort ( 404 ) ; } }
Show the form to create a new record .
26,510
public function publish ( Request $ request , $ entity , $ record = null , $ child = null ) { if ( ! $ record && ! $ child && ( $ entityObject = Entity :: fromYamlFile ( $ entity ) ) ) { } elseif ( ( $ parentEntity = Entity :: fromYamlFile ( $ entity ) ) && ( $ entityObject = Entity :: fromYamlFile ( $ child ) ) ) { $ parentRecord = $ parentEntity -> class :: findOrFail ( $ record ) ; } else { abort ( 404 ) ; } $ this -> validate ( $ request , $ this -> validationRules ( $ entityObject -> fields ) ) ; $ record = new $ entityObject -> class ( ) ; foreach ( $ entityObject -> fields as $ field => $ options ) { $ type = ucwords ( $ options [ 'type' ] ) ; $ className = 'Jaimeeee\\Panel\\Fields\\' . $ type . '\\' . $ type . 'Field' ; if ( ! isset ( $ className :: $ ignore ) || ! $ className :: $ ignore ) { $ record -> $ field = $ request -> input ( $ field ) ; } } if ( isset ( $ entityObject -> slug [ 'field' ] ) && $ entityObject -> slug [ 'field' ] && isset ( $ entityObject -> slug [ 'column' ] ) && $ entityObject -> slug [ 'column' ] ) { $ field = $ entityObject -> slug [ 'field' ] ; $ column = $ entityObject -> slug [ 'column' ] ; $ record -> $ column = str_slug ( $ record -> $ field , isset ( $ entityObject -> slug [ 'separator' ] ) ? $ entityObject -> slug [ 'separator' ] : '-' ) ; } if ( isset ( $ parentRecord ) && $ parentRecord ) { $ row = snake_case ( class_basename ( $ parentEntity -> class ) ) . '_id' ; $ record -> $ row = $ parentRecord -> id ; } $ record -> save ( ) ; foreach ( $ entityObject -> fields as $ field => $ options ) { $ type = ucwords ( $ options [ 'type' ] ) ; $ className = 'Jaimeeee\\Panel\\Fields\\' . $ type . '\\' . $ type . 'Field' ; if ( method_exists ( $ className , 'call' ) ) { $ className :: call ( $ request , $ record , $ field , $ options ) ; } } $ record -> save ( ) ; if ( isset ( $ parentRecord ) && $ parentRecord ) { return redirect ( config ( 'panel.url' ) . '/' . $ parentEntity -> url . '/' . $ parentRecord -> id . '/' . $ entityObject -> url . '?created=1' ) ; } else { return redirect ( config ( 'panel.url' ) . '/' . $ entityObject -> url . '?created=1' ) ; } }
Submit the new record .
26,511
public function edit ( $ entity , $ id , $ child = null , $ record = null ) { if ( ! $ record && ! $ child && ( $ entityObject = Entity :: fromYamlFile ( $ entity ) ) ) { $ entityClass = $ entityObject -> class ; $ record = $ entityClass :: findOrFail ( $ id ) ; $ form = new Form ( $ entityObject , $ record , Session :: get ( 'errors' ) ) ; return $ form -> view ( ) ; } elseif ( ( $ parentEntity = Entity :: fromYamlFile ( $ entity ) ) && ( $ entityObject = Entity :: fromYamlFile ( $ child ) ) ) { $ parentRecord = $ parentEntity -> class :: findOrFail ( $ id ) ; $ entityClass = $ entityObject -> class ; $ childObject = $ entityClass :: findOrFail ( $ record ) ; $ form = new Form ( $ entityObject , $ childObject , Session :: get ( 'errors' ) , $ parentEntity , $ parentRecord ) ; return $ form -> view ( ) ; } else { abort ( 404 ) ; } }
Show the form to edit a record .
26,512
private function validationRules ( $ fields , $ edit = false ) { $ validationRules = [ ] ; foreach ( $ fields as $ name => $ options ) { if ( isset ( $ options [ 'validate' ] ) ) { $ validationRules [ $ name ] = $ options [ 'validate' ] ; if ( $ edit && isset ( $ options [ 'validateAtEdit' ] ) ) { $ validationRules [ $ name ] = $ options [ 'validateAtEdit' ] ; } if ( $ options [ 'type' ] == 'image' ) { $ rules = explode ( '|' , $ validationRules [ $ name ] ) ; if ( ! in_array ( 'image' , $ rules ) ) { $ rules [ ] = 'image' ; } $ validationRules [ $ name ] = implode ( '|' , $ rules ) ; } } } return $ validationRules ; }
Return the validation rules for each field .
26,513
function setName ( $ name ) { if ( $ this -> name !== null ) throw new \ Exception ( sprintf ( "Event with name (%s) are immutable. can`t set name (%s)." , $ this -> name , \ Poirot \ Std \ flatten ( $ name ) ) ) ; $ this -> name = ( string ) $ name ; return $ this ; }
Set Events Entitle Name
26,514
function getName ( ) { if ( $ this -> name == '' || $ this -> name === null ) { $ name = str_replace ( '\\' , '.' , get_class ( $ this ) ) ; $ this -> setName ( $ name ) ; } return $ this -> name ; }
Event Entitle Name
26,515
function collector ( $ options = null ) { if ( ! $ this -> collector ) $ this -> collector = new DataCollector ; if ( null !== $ options ) { $ this -> collector -> import ( $ options ) ; return $ this ; } return $ this -> collector ; }
Events Result Collector
26,516
function emit ( $ dataMerge = null , $ meeter = null ) { if ( $ dataMerge instanceof iMeeter ) { $ meeter = $ dataMerge ; $ dataMerge = null ; } $ Event = clone $ this ; $ Collector = $ Event -> collector ( ) ; if ( $ dataMerge !== null ) $ Collector -> import ( $ dataMerge ) ; if ( $ meeter === null ) $ meeter = $ this -> _getMeeter ( ) ; $ this -> _tmp__isEmiting = true ; $ result = null ; foreach ( clone $ this -> _listenerQueue ( ) as $ listener ) { if ( $ Event -> isStopPropagation ( ) ) break ; $ this -> _c_lastEmitted = $ listener ; $ meeter = clone $ meeter ; $ meeter -> setEventBelong ( $ Event ) ; try { $ result = $ meeter -> invokeListener ( $ listener , $ Collector ) ; } catch ( \ Exception $ e ) { if ( $ this -> failure ) return call_user_func ( $ this -> failure , $ e , $ Event ) ; throw $ e ; } if ( $ result !== null ) { if ( is_array ( $ result ) || $ result instanceof \ Traversable ) $ Collector -> import ( $ result ) ; } } $ this -> _tmp__isEmiting = false ; return $ Event ; }
Trigger Listeners Within Events
26,517
function attachListener ( $ listener , $ name = null , $ priority = 10 ) { if ( $ priority == null ) $ priority = 10 ; if ( $ this -> _tmp__isEmiting ) throw new \ RuntimeException ( 'Can`t Attach Listener While Emit Events.' ) ; if ( is_int ( $ name ) ) { $ priority = $ name ; $ name = null ; } if ( $ name === null ) { if ( is_object ( $ listener ) && ! $ listener instanceof \ Closure ) $ name = get_class ( $ listener ) ; } if ( $ name !== null ) { if ( isset ( $ this -> _c_listeners [ $ name ] ) ) throw new \ RuntimeException ( "Listener with same name ({$name}) not allowed." ) ; $ this -> _c_listeners [ $ name ] = $ listener ; } $ this -> _listenerQueue ( ) -> insert ( $ listener , $ priority ) ; return $ this ; }
Attach Listener To This Events
26,518
function findListener ( $ listener ) { if ( is_string ( $ listener ) ) return ( isset ( $ this -> _c_listeners [ $ listener ] ) ) ? $ this -> _c_listeners [ $ listener ] : false ; elseif ( is_object ( $ listener ) ) { foreach ( clone $ this -> _listenerQueue ( ) as $ l ) { if ( $ l === $ listener ) return $ listener ; } } return false ; }
Find For Listener with name or object
26,519
function detachListener ( iListener $ listener ) { $ this -> _listenerQueue ( ) -> del ( $ listener ) ; if ( in_array ( $ listener , $ this -> _c_listeners ) ) { foreach ( $ this -> _c_listeners as $ k => $ l ) { if ( $ l === $ listener ) { unset ( $ this -> _c_listeners [ $ k ] ) ; break ; } } } return $ this ; }
Detach A Listener From List
26,520
public function write ( $ content ) { if ( is_string ( $ content ) || is_numeric ( $ content ) ) { $ this -> writeString ( $ content ) ; } elseif ( is_bool ( $ content ) ) { $ this -> writeString ( $ content ? "TRUE" : "FALSE" ) ; } elseif ( is_array ( $ content ) ) { $ this -> writeString ( "Array(" . count ( $ content ) . ")" ) ; } elseif ( is_object ( $ content ) && method_exists ( $ content , "__toString" ) ) { $ this -> writeString ( strval ( $ content ) ) ; } elseif ( is_null ( $ content ) ) { $ this -> writeString ( "NULL" ) ; } elseif ( is_resource ( $ content ) ) { $ this -> writeString ( "Resource###" ) ; } else { throw new InvalidContentException ( ) ; } }
Writes The provided content to this output stream .
26,521
public static function getSpEntityIdForMultiAuth ( $ authState ) { $ idParam = '?spentityid' ; $ paramStart = strpos ( $ authState , $ idParam ) ; $ entityId = substr ( $ authState , $ paramStart ) ; $ valueStart = strpos ( $ entityId , '=' ) + 1 ; $ entityId = substr ( $ entityId , $ valueStart ) ; $ valueEnd = strpos ( $ entityId , '&' ) ; $ entityId = substr ( $ entityId , 0 , $ valueEnd ) ; $ entityId = urldecode ( urldecode ( $ entityId ) ) ; return $ entityId ; }
Gets the SP entityID out of the AuthState parameter
26,522
protected function ago ( $ time ) { $ time = time ( ) - $ time ; if ( $ time < 60 ) { return 'a moment ago' ; } $ secs = array ( 'year' => 365.25 * 24 * 60 * 60 , 'month' => 30 * 24 * 60 * 60 , 'week' => 7 * 24 * 60 * 60 , 'day' => 24 * 60 * 60 , 'hour' => 60 * 60 , 'minute' => 60 , ) ; foreach ( $ secs as $ str => $ s ) { $ d = $ time / $ s ; if ( $ d >= 1 ) { $ r = round ( $ d ) ; return sprintf ( '%d %s%s ago' , $ r , $ str , ( $ r > 1 ) ? 's' : '' ) ; } } }
Returns a crude time ago string .
26,523
protected function isInChannel ( $ server , $ channel , $ user ) { if ( ! isset ( $ this -> channels [ $ server ] [ $ channel ] ) ) { return false ; } $ names = array_keys ( $ this -> channels [ $ server ] [ $ channel ] , true , true ) ; foreach ( $ names as $ name ) { if ( ! strcasecmp ( $ name , $ user ) ) { return true ; } } return false ; }
Checks whether a given nickname is currently on a channel .
26,524
public function processKick ( UserEvent $ event , Queue $ queue ) { $ logger = $ this -> getLogger ( ) ; $ server = strtolower ( $ event -> getConnection ( ) -> getServerHostname ( ) ) ; $ params = $ event -> getParams ( ) ; $ channel = $ params [ 'channel' ] ; $ nick = $ params [ 'user' ] ; $ message = isset ( $ params [ 'comment' ] ) ? $ params [ 'comment' ] : null ; if ( $ nick == $ event -> getConnection ( ) -> getNickname ( ) ) { $ logger -> debug ( 'Removing channel' , array ( 'server' => $ server , 'channel' => $ channel ) ) ; unset ( $ this -> channels [ $ server ] [ $ channel ] ) ; return ; } $ logger -> debug ( 'Processing incoming KICK' , array ( 'server' => $ server , 'channel' => $ channel , 'nick' => $ nick , 'message' => $ message , ) ) ; unset ( $ this -> channels [ $ server ] [ $ channel ] [ $ nick ] ) ; try { $ this -> db -> fetchAssoc ( self :: SQL_UPDATE , array ( ':time' => time ( ) , ':server' => $ server , ':channel' => $ channel , ':nick' => $ nick , ':type' => self :: TYPE_KICK , ':text' => $ message , ) ) ; } catch ( \ Exception $ e ) { $ logger -> error ( $ e -> getMessage ( ) ) ; } }
Monitor channel kicks .
26,525
public function processNick ( UserEvent $ event , Queue $ queue ) { $ logger = $ this -> getLogger ( ) ; $ nick = $ event -> getNick ( ) ; if ( $ nick == $ event -> getConnection ( ) -> getNickname ( ) ) { $ logger -> debug ( 'Nickname of incoming NICK is ours, ignoring' ) ; return ; } $ server = strtolower ( $ event -> getConnection ( ) -> getServerHostname ( ) ) ; $ params = $ event -> getParams ( ) ; $ newnick = $ params [ 'nickname' ] ; $ logger -> debug ( 'Processing incoming NICK' , array ( 'server' => $ server , 'nick' => $ nick , 'newnick' => $ newnick , ) ) ; foreach ( $ this -> channels [ $ server ] as $ channel => $ users ) { if ( isset ( $ users [ $ nick ] ) ) { $ logger -> debug ( 'Processing channel nick change' , array ( 'server' => $ server , 'channel' => $ channel , 'nick' => $ nick , 'newnick' => $ newnick , ) ) ; unset ( $ this -> channels [ $ server ] [ $ channel ] [ $ nick ] ) ; $ this -> channels [ $ server ] [ $ channel ] [ $ newnick ] = true ; try { $ this -> db -> fetchAssoc ( self :: SQL_UPDATE , array ( ':time' => time ( ) , ':server' => $ server , ':channel' => $ channel , ':nick' => $ nick , ':type' => self :: TYPE_NICK , ':text' => $ newnick , ) ) ; } catch ( \ Exception $ e ) { $ logger -> error ( $ e -> getMessage ( ) ) ; } } } }
Monitor nick changes .
26,526
public function processPrivmsg ( UserEvent $ event , Queue $ queue ) { $ logger = $ this -> getLogger ( ) ; $ source = $ event -> getSource ( ) ; $ nick = $ event -> getNick ( ) ; if ( $ source === null || $ nick === null || $ source == $ nick ) { $ logger -> debug ( 'Incoming PRIVMSG not in channel, ignoring' ) ; return ; } $ server = strtolower ( $ event -> getConnection ( ) -> getServerHostname ( ) ) ; $ channel = $ source ; $ params = $ event -> getParams ( ) ; $ message = $ params [ 'text' ] ; $ logger -> debug ( 'Processing incoming PRIVMSG' , array ( 'server' => $ server , 'channel' => $ channel , 'nick' => $ nick , 'message' => $ message , ) ) ; try { $ this -> db -> fetchAssoc ( self :: SQL_UPDATE , array ( ':time' => time ( ) , ':server' => $ server , ':channel' => $ channel , ':nick' => $ nick , ':type' => self :: TYPE_PRIVMSG , ':text' => $ message , ) ) ; } catch ( \ Exception $ e ) { $ logger -> error ( $ e -> getMessage ( ) ) ; } }
Monitor channel messages .
26,527
public function processAction ( CtcpEvent $ event , Queue $ queue ) { $ logger = $ this -> getLogger ( ) ; $ source = $ event -> getSource ( ) ; $ nick = $ event -> getNick ( ) ; if ( $ source === null || $ nick === null || $ source == $ nick ) { $ logger -> debug ( 'Incoming CTCP ACTION not in channel, ignoring' ) ; return ; } $ server = strtolower ( $ event -> getConnection ( ) -> getServerHostname ( ) ) ; $ channel = $ event -> getSource ( ) ; $ params = $ event -> getCtcpParams ( ) ; $ message = $ params [ 'action' ] ; $ logger -> debug ( 'Processing incoming CTCP ACTION' , array ( 'server' => $ server , 'channel' => $ channel , 'nick' => $ nick , 'message' => $ message , ) ) ; try { $ this -> db -> fetchAssoc ( self :: SQL_UPDATE , array ( ':time' => time ( ) , ':server' => $ server , ':channel' => $ channel , ':nick' => $ nick , ':type' => self :: TYPE_ACTION , ':text' => $ message , ) ) ; } catch ( \ Exception $ e ) { $ logger -> error ( $ e -> getMessage ( ) ) ; } }
Monitor channel actions .
26,528
public function processNames ( ServerEvent $ event , Queue $ queue ) { $ special = '\[\]\\`_\^\{\|\}' ; $ server = strtolower ( $ event -> getConnection ( ) -> getServerHostname ( ) ) ; $ params = array_slice ( $ event -> getParams ( ) , 2 ) ; $ channel = array_shift ( $ params ) ; $ this -> getLogger ( ) -> debug ( 'Adding names to channel' , array ( 'server' => $ server , 'channel' => $ channel ) ) ; $ names = ( count ( $ params ) == 1 ) ? explode ( ' ' , $ params [ 0 ] ) : $ params ; foreach ( array_filter ( $ names ) as $ name ) { $ name = preg_replace ( "/^[^A-Za-z$special]+/" , '' , $ name ) ; $ this -> channels [ $ server ] [ $ channel ] [ $ name ] = true ; } }
Populate channels with names on join .
26,529
public function render ( ) { $ engine = new MarkdownEngine \ MichelfMarkdownEngine ( ) ; $ twig_loader = new Twig_Loader_Filesystem ( $ this -> template_folder ) ; $ twig = new Twig_Environment ( $ twig_loader , array ( 'cache' => $ this -> twig_cache , ) ) ; $ twig -> addExtension ( new MarkdownExtension ( $ engine ) ) ; print $ twig -> render ( 'index.html' , array ( 'title' => $ this -> title , 'description' => $ this -> description , 'source' => $ this -> source , 'sections' => $ this -> sections , 'base_path' => $ this -> base_path , 'asset_path' => $ this -> asset_path , ) ) ; }
Loads Markdown and Twig engines and renders the styleguide
26,530
private function find_sections ( ) { $ sections = array ( ) ; $ level_memory = array ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) ; $ last_section = FALSE ; preg_match_all ( '#\/\*((?:(?!\*\/).)*)\*\/#s' , $ this -> code , $ matches ) ; foreach ( $ matches [ 1 ] as $ match ) { $ section = array ( ) ; $ elements = $ this -> parse_match ( $ match ) ; if ( isset ( $ elements [ 'title' ] ) && isset ( $ elements [ 'level' ] ) ) { $ elements [ 'htag' ] = 'h6' ; $ level_depth_arr = array_filter ( explode ( '.' , $ elements [ 'level' ] ) ) ; $ level_depth = count ( $ level_depth_arr ) ; if ( isset ( $ this -> section_htags [ $ level_depth ] ) ) { $ elements [ 'htag' ] = $ this -> section_htags [ $ level_depth ] ; } $ level_memory = array_slice ( $ level_memory , 0 , $ level_depth ) ; $ level_memory = array_pad ( $ level_memory , 10 , 0 ) ; foreach ( $ level_depth_arr as $ key => $ level ) { if ( is_numeric ( $ level ) ) { $ level_memory [ $ key ] = $ level ; } else { if ( $ key > 0 && $ key + 1 == $ level_depth ) { $ level_memory [ $ key ] ++ ; } $ level_depth_arr [ $ key ] = $ level_memory [ $ key ] ; } } $ elements [ 'level' ] = implode ( '.' , $ level_depth_arr ) . '.' ; $ sections [ $ elements [ 'level' ] ] = $ elements ; $ last_section = $ elements [ 'level' ] ; } else if ( ! empty ( $ elements ) ) { foreach ( $ elements as $ element_label => $ element_value ) { $ sections [ $ last_section ] [ $ element_label ] = isset ( $ sections [ $ last_section ] [ $ element_label ] ) ? $ sections [ $ last_section ] [ $ element_label ] . "\n" . $ element_value : $ element_value ; } } } ksort ( $ sections ) ; $ this -> build_section_tree ( $ sections ) ; }
Parse the provided code for valid styleguide sections
26,531
private function build_section_tree ( $ sections ) { $ level_tree = array ( ) ; foreach ( $ sections as $ level => $ section ) { $ level_depth_arr = array_filter ( explode ( '.' , $ level ) ) ; $ level_depth = count ( $ level_depth_arr ) ; array_pop ( $ level_depth_arr ) ; $ level_parent = $ level_depth > 1 ? implode ( '.' , $ level_depth_arr ) . '.' : $ level ; $ level_tree [ $ level_depth ] [ $ level_parent ] [ $ level ] = $ section ; } foreach ( $ level_tree [ 1 ] as $ section_level => $ section ) { $ section [ $ section_level ] [ 'sub' ] = $ this -> build_section_sub_tree ( $ level_tree , 2 , $ section_level ) ; $ this -> sections += $ section ; } }
Build a nested array according to the section levels
26,532
private function build_section_sub_tree ( $ main_tree , $ tree_level , $ section_level ) { $ sub_sections = array ( ) ; if ( isset ( $ main_tree [ $ tree_level ] ) && isset ( $ main_tree [ $ tree_level ] [ $ section_level ] ) ) { $ sub_sections = $ main_tree [ $ tree_level ] [ $ section_level ] ; $ sub_tree_level = $ tree_level + 1 ; foreach ( $ sub_sections as $ sub_section_level => $ sub_section ) { $ sub_sections [ $ sub_section_level ] [ 'sub' ] = $ this -> build_section_sub_tree ( $ main_tree , $ sub_tree_level , $ sub_section_level ) ; } } return $ sub_sections ; }
Build an array of sub sections for the given section
26,533
private function parse_match ( $ match ) { $ match = trim ( $ match ) ; $ docblock = new Docblock ( $ match ) ; $ tags = $ docblock -> getTags ( ) ; $ element_values = array ( ) ; if ( $ title = $ docblock -> getShortDescription ( ) ) { if ( strpos ( $ title , '#' ) === 0 ) { return $ element_values ; } $ element_values [ 'title' ] = $ title ; } if ( $ description = $ docblock -> getLongDescription ( ) ) { $ element_values [ 'description' ] = $ description ; } foreach ( $ tags as $ tag ) { $ tag_name = $ tag -> getTagName ( ) ; $ tag_description = $ this -> clean_description ( $ tag -> getDescription ( ) ) ; switch ( $ tag_name ) { case 'code' : case 'markup' : $ element_values [ 'code_language' ] = 'markup' ; $ element_values [ 'code_render' ] = FALSE ; if ( $ tag_name == 'markup' ) { $ element_values [ 'code_render' ] = TRUE ; } if ( preg_match ( "#^\[(.*?)\]\n#s" , $ tag_description , $ code_language_match ) ) { $ element_values [ 'code_language' ] = $ code_language_match [ 1 ] ; $ tag_description = str_replace ( '[' . $ code_language_match [ 1 ] . ']' , '' , $ tag_description ) ; } $ element_values [ 'code' ] = trim ( $ tag_description ) ; break ; case 'color' : $ colorsets = array ( ) ; $ colorset_elements = explode ( "\n" , $ tag_description ) ; foreach ( $ colorset_elements as $ colorset ) { $ color_elements = explode ( '|' , $ colorset ) ; $ colors = array ( ) ; foreach ( $ color_elements as $ color ) { $ color_arr = explode ( ':' , $ color ) ; if ( count ( $ color_arr ) > 1 ) { $ colors [ ] = array ( 'name' => trim ( $ color_arr [ 0 ] ) , 'value' => trim ( $ color_arr [ 1 ] ) , ) ; } else { $ colors [ ] = array ( 'value' => $ color_arr [ 0 ] ) ; } } $ colorsets [ ] = $ colors ; } $ element_values [ 'color' ] = $ colorsets ; break ; case 'variable' : $ variables = explode ( '|' , $ tag_description ) ; $ element_values [ 'variable' ] = '- ' . implode ( ";\n- " , $ variables ) . ';' ; break ; default : $ element_values [ $ tag_name ] = $ tag_description ; break ; } } return $ element_values ; }
Find styleguide elements and their values in a comment section
26,534
private function reset ( ) { if ( $ this -> pipes !== null ) { foreach ( $ this -> pipes as $ pipe ) { fclose ( $ pipe ) ; } $ this -> pipes = null ; } if ( $ this -> process !== null ) { proc_close ( $ this -> process ) ; $ this -> process = null ; } $ this -> exitcode = null ; }
Reset the data .
26,535
public function start ( ) { if ( $ this -> isRunning ( ) ) { throw new LogicException ( 'Process is already running' ) ; } $ this -> reset ( ) ; $ cmd = $ this -> cmd ; if ( substr ( $ cmd , 0 , 4 ) == 'php ' ) { $ php = PHP_BINARY ? : PHP_BINDIR . '/php' ; $ cmd = $ php . substr ( $ cmd , 3 ) ; } $ descriptorspec = [ 0 => [ 'pipe' , 'r' ] , 1 => [ 'pipe' , 'w' ] , 2 => [ 'pipe' , 'w' ] ] ; $ options = [ 'suppress_errors' => true , 'binary_pipes' => true , ] ; $ this -> process = proc_open ( $ cmd , $ descriptorspec , $ this -> pipes , base_path ( ) , $ this -> env , $ options ) ; if ( ! is_resource ( $ this -> process ) ) { throw new RuntimeException ( 'Unable to launch a new process.' ) ; } }
Starts a background process .
26,536
public function terminate ( $ signal = 15 ) { if ( $ this -> process === null ) { return false ; } return proc_terminate ( $ this -> process , $ signal ) ; }
Terminate the process .
26,537
public function write ( $ line ) { return $ this -> pipes !== null ? fwrite ( $ this -> pipes [ 0 ] , $ line . PHP_EOL ) : false ; }
Write a line to STDIN .
26,538
public function isRunning ( ) { if ( $ this -> process === null ) { return false ; } $ status = proc_get_status ( $ this -> process ) ; if ( $ status && $ status [ 'running' ] === false && $ this -> exitcode === null ) { $ this -> exitcode = $ status [ 'exitcode' ] ; } return $ status && $ status [ 'running' ] ; }
Determine if the process is currently running .
26,539
public function getExitCode ( ) { if ( $ this -> exitcode === null && $ this -> process !== null ) { $ status = proc_get_status ( $ this -> process ) ; if ( $ status && $ status [ 'running' ] === false ) { $ this -> exitcode = $ status [ 'exitcode' ] ; } } return $ this -> exitcode ; }
Get the exit code returned by the process .
26,540
public function create ( $ orderId , $ price , $ description = '' , $ currency = 'IRR' , $ merchantCur = 'IRR' ) { $ this -> error = '' ; $ orderId = ( string ) $ orderId ; if ( ! self :: __validateString ( $ orderId , 1 , 50 ) || ! self :: __validateNumeric ( $ price , 1 , 20 ) || ! self :: __validateString ( $ description , 0 , 255 ) ) return false ; $ param = array ( "apikey" => $ this -> apiKey , "mobile" => $ this -> mobile , "description" => $ description , "orderId" => $ orderId , "merchantCur" => $ merchantCur , "currency" => $ currency , "price" => ( string ) $ price ) ; $ result = self :: __sendRequest ( 'invoice' , 'POST' , $ param ) ; if ( $ result -> code === 200 ) { if ( isset ( $ result -> response -> qr ) ) unset ( $ result -> response -> qr ) ; return $ result -> response ; } else if ( $ result -> code == 0 ) { $ this -> error = $ result -> response ; return false ; } else { if ( isset ( $ result -> response -> description ) && ! is_null ( $ result -> response -> description ) ) $ this -> error = $ result -> response -> description ; else if ( isset ( $ result -> response -> message ) && ! is_null ( $ result -> response -> message ) ) $ this -> error = $ result -> response -> message ; return false ; } }
Create the payment invoice and return the gateway url
26,541
public function check ( $ invoiceId ) { $ this -> error = '' ; if ( ! self :: __validateString ( $ invoiceId , 1 , 50 ) ) return false ; $ param = array ( "id" => $ invoiceId , "apikey" => $ this -> apiKey , "mobile" => $ this -> mobile ) ; return self :: __sendCheckRequest ( 'invoice' , $ param ) ; }
Check the payment status with invoice id
26,542
private function __sendCheckRequest ( $ path , $ param ) { $ result = self :: __sendRequest ( $ path , 'GET' , $ param ) ; if ( $ result -> code === 200 ) { if ( isset ( $ result -> response -> qr ) ) unset ( $ result -> response -> qr ) ; return $ result -> response ; } else if ( $ result -> code == 0 ) { $ this -> error = $ result -> response ; return false ; } else { if ( isset ( $ result -> response -> description ) && ! is_null ( $ result -> response -> description ) ) $ this -> error = $ result -> response -> description ; else if ( isset ( $ result -> response -> message ) && ! is_null ( $ result -> response -> message ) ) $ this -> error = $ result -> response -> message ; return false ; } }
Send Check invoice request
26,543
private function __sendRequest ( $ urlPath , $ method , $ param ) { if ( function_exists ( 'curl_version' ) ) return self :: __sendCurl ( $ urlPath , $ method , $ param ) ; else if ( ini_get ( 'allow_url_fopen' ) ) return self :: __sendFileGetContents ( $ urlPath , $ method , $ param ) ; else throw new \ Exception ( 'file_get_content and curl are disabled. you must enabled one of them' ) ; }
Send the request to payment server
26,544
private function __sendCurl ( $ urlPath , $ method , $ param ) { $ url = trim ( $ this -> apiBaseUrl , '/' ) . '/' . trim ( $ urlPath , '/' ) ; if ( $ method == 'GET' ) { $ query = http_build_query ( $ param ) ; $ url = $ url . '?' . $ query ; } $ curl = curl_init ( ) ; curl_setopt_array ( $ curl , array ( CURLOPT_URL => $ url , CURLOPT_RETURNTRANSFER => true , CURLOPT_MAXREDIRS => 10 , CURLOPT_TIMEOUT => 30 , CURLOPT_CUSTOMREQUEST => $ method , CURLOPT_POSTFIELDS => $ method == 'POST' ? json_encode ( $ param ) : '' , CURLOPT_HTTPHEADER => array ( "Cache-Control: no-cache" , "Content-Type: application/json" , ) , ) ) ; $ response = curl_exec ( $ curl ) ; $ httpCode = curl_getinfo ( $ curl , CURLINFO_HTTP_CODE ) ; $ error = curl_error ( $ curl ) ; curl_close ( $ curl ) ; return ( object ) array ( 'code' => $ httpCode , 'response' => $ error ? $ error : json_decode ( $ response ) , ) ; }
Use Curl function for Send request
26,545
private function __sendFileGetContents ( $ urlPath , $ method , $ param ) { $ url = trim ( $ this -> apiBaseUrl , '/' ) . '/' . trim ( $ urlPath , '/' ) ; if ( $ method == 'GET' ) { $ query = http_build_query ( $ param ) ; $ url = $ url . '?' . $ query ; } $ opts = array ( 'http' => array ( 'method' => $ method , 'timeout' => '30' , 'max_redirects' => '10' , 'ignore_errors' => '1' , 'header' => 'Content-type: application/json' , 'content' => $ method == 'POST' ? json_encode ( $ param ) : '' ) ) ; $ context = stream_context_create ( $ opts ) ; $ result = file_get_contents ( $ url , false , $ context ) ; $ response_header = explode ( ' ' , $ http_response_header [ 0 ] ) ; $ httpCode = ( int ) $ response_header [ 1 ] ; return ( object ) array ( 'code' => $ httpCode , 'response' => json_decode ( $ result ) , ) ; }
Use file_get_contents function for Send request
26,546
private function __validateUrl ( $ url ) { if ( empty ( $ url ) || ! is_string ( $ url ) || strlen ( $ url ) > 512 || ! preg_match ( '/^http(s)?:\/\/[a-z0-9-]+(.[a-z0-9-]+)+(:[0-9]+)?(\/.*)?$/i' , $ url ) || ! filter_var ( $ url , FILTER_VALIDATE_URL ) ) { $ this -> error = 'invalid url format' ; return false ; } return true ; }
Validate url If url is invalid throw the exception
26,547
private function __validateString ( $ string , $ minLength = 1 , $ maxLength = 0 ) { if ( ! is_string ( $ string ) ) { $ this -> error = 'parameter is not string.' ; return false ; } else if ( $ maxLength > 0 && strlen ( $ string ) > $ maxLength ) { $ this -> error = 'parameter is too long. string:' . $ string ; return false ; } else if ( strlen ( $ string ) < $ minLength ) { $ this -> error = 'parameter is too short. string:' . $ string ; return false ; } return true ; }
validate the string
26,548
private function __validateNumeric ( $ int , $ minLength = 1 , $ maxLength = 0 ) { if ( ! is_numeric ( $ int ) ) { $ this -> error = 'parameter is not number' ; return false ; } else if ( $ maxLength > 0 && strlen ( $ int ) > $ maxLength ) { $ this -> error = 'parameter is too long. number:' . $ int ; return false ; } else if ( strlen ( $ int ) < $ minLength ) { $ this -> error = 'parameter is too short. number:' . $ int ; return false ; } return true ; }
validate variable is a number or a numeric string
26,549
public function parseKeys ( $ data , $ offset ) { $ element = \ preg_quote ( $ this -> getIndex ( ) -> getElement ( ) ) ; $ attribute = \ preg_quote ( $ this -> getIndex ( ) -> getAttribute ( ) ) ; $ pregExp = '/<' . $ element . '\s([^>]*\s)?' . $ attribute . '\s*=\s*([\'"])(.+?)\2[^>]*>/si' ; \ preg_match_all ( $ pregExp , $ data , $ matches , PREG_OFFSET_CAPTURE | PREG_SET_ORDER ) ; $ keys = array ( ) ; foreach ( $ matches as $ match ) { $ keys [ ] = new FoundKey ( $ match [ 0 ] [ 1 ] , $ match [ 3 ] [ 0 ] ) ; } return $ keys ; }
Returns an array with FoundKey objects
26,550
public function getData ( $ offset ) { $ this -> parserPosition = null ; $ this -> parserLevel = 0 ; $ data = "" ; $ parser = @ \ xml_parser_create ( ) ; $ filePointer = $ this -> getIndex ( ) -> getFile ( ) -> getFilePointer ( ) ; if ( ! \ is_resource ( $ parser ) ) { $ error = \ error_get_last ( ) ; throw new ReadDataIndexException ( "Could not create a xml parser: $error[message]" ) ; } \ xml_set_element_handler ( $ parser , array ( $ this , "onStartElement" ) , array ( $ this , "onEndElement" ) ) ; \ fseek ( $ filePointer , $ offset ) ; while ( \ is_null ( $ this -> parserPosition ) && $ chunk = \ fread ( $ filePointer , $ this -> getIndex ( ) -> getFile ( ) -> getBlockSize ( ) ) ) { $ data .= $ chunk ; \ xml_parse ( $ parser , $ chunk ) ; } \ xml_parser_free ( $ parser ) ; if ( \ is_null ( $ this -> parserPosition ) ) { throw new ReadDataIndexException ( "Did not read any data" ) ; } return \ substr ( $ data , 0 , $ this -> parserPosition ) ; }
Returns the XML container which begins at the specified offset
26,551
public function onEndElement ( $ parser , $ element ) { $ this -> parserLevel -- ; if ( $ this -> parserLevel > 0 ) { return ; } if ( $ element != \ strtoupper ( $ this -> getIndex ( ) -> getElement ( ) ) ) { throw new ReadDataIndexException ( "Unexpected closing of element '$element'." ) ; } $ this -> parserPosition = \ xml_get_current_byte_index ( $ parser ) ; }
Handler for an element end event
26,552
protected function reflectCss ( FieldsetInterface $ fieldset , $ selector ) { foreach ( $ fieldset -> getFieldsets ( ) as $ subFieldset ) { if ( ! $ subFieldset instanceof Collection ) { $ this -> reflectCss ( $ subFieldset , $ selector ) ; } } foreach ( $ fieldset -> getElements ( ) as $ name => $ element ) { $ types = array_filter ( preg_split ( '/\s+/' , trim ( $ element -> getAttribute ( 'data-js-type' ) ) ) ) ; $ types [ ] = 'js.paragraph.reflectCss' ; $ element -> setAttributes ( array ( 'data-js-type' => implode ( ' ' , $ types ) , 'data-js-reflectcss-selector' => $ selector , 'data-js-reflectcss-property' => String :: decamelize ( $ name ) , ) ) ; } return $ fieldset ; }
Reflect css properties
26,553
public function getAvailableTickets ( ) { $ available = ArrayList :: create ( ) ; $ tickets = $ this -> Tickets ( ) ; foreach ( $ tickets as $ ticket ) { if ( $ ticket -> isAvailable ( ) ) { $ available -> push ( $ ticket ) ; } } return $ available ; }
Get available tickets .
26,554
public function getRemainingCapacity ( $ excludeId = null ) { if ( ! $ this -> Capacity ) { return true ; } $ bookings = $ this -> Registrations ( ) -> filter ( "Status:not" , "Canceled" ) ; if ( $ excludeId ) { $ bookings = $ bookings -> filter ( "ID:not" , $ excludeId ) ; } $ taken = $ bookings -> sum ( "Quantity" ) ; if ( $ this -> Capacity >= $ taken ) { return $ this -> Capacity - $ taken ; } return false ; }
Returns the overall number of places remaining at this event TRUE if there are unlimited places or FALSE if they are all taken .
26,555
public function registration ( $ request ) { $ id = $ request -> param ( 'ID' ) ; if ( ! ctype_digit ( $ id ) ) { return $ this -> httpError ( 404 ) ; } $ rego = EventRegistration :: get ( ) -> byID ( $ id ) ; if ( ! $ rego || $ rego -> EventID != $ this -> ID ) { return $ this -> httpError ( 404 ) ; } $ request -> shift ( ) ; $ request -> shiftAllParams ( ) ; return new EventRegistrationDetailsController ( $ this , $ rego ) ; }
Allows a user to view the details of their registration .
26,556
public function getToken ( ) { if ( isset ( $ this -> _tokens [ $ this -> _position ] ) ) { return $ this -> _tokens [ $ this -> _position ] ; } else { return null ; } }
Returns the current token on input .
26,557
protected function _formatPrefix ( $ prefix ) { if ( $ prefix == "" ) { return $ prefix ; } $ nsSeparator = ( false !== strpos ( $ prefix , '\\' ) ) ? '\\' : '_' ; return rtrim ( $ prefix , $ nsSeparator ) . $ nsSeparator ; }
Format prefix for internal use
26,558
public function getPaths ( $ prefix = null ) { if ( ( null !== $ prefix ) && is_string ( $ prefix ) ) { $ prefix = $ this -> _formatPrefix ( $ prefix ) ; if ( $ this -> _useStaticRegistry ) { if ( isset ( self :: $ _staticPrefixToPaths [ $ this -> _useStaticRegistry ] [ $ prefix ] ) ) { return self :: $ _staticPrefixToPaths [ $ this -> _useStaticRegistry ] [ $ prefix ] ; } return false ; } if ( isset ( $ this -> _prefixToPaths [ $ prefix ] ) ) { return $ this -> _prefixToPaths [ $ prefix ] ; } return false ; } if ( $ this -> _useStaticRegistry ) { return self :: $ _staticPrefixToPaths [ $ this -> _useStaticRegistry ] ; } return $ this -> _prefixToPaths ; }
Get path stack
26,559
public function clearPaths ( $ prefix = null ) { if ( ( null !== $ prefix ) && is_string ( $ prefix ) ) { $ prefix = $ this -> _formatPrefix ( $ prefix ) ; if ( $ this -> _useStaticRegistry ) { if ( isset ( self :: $ _staticPrefixToPaths [ $ this -> _useStaticRegistry ] [ $ prefix ] ) ) { unset ( self :: $ _staticPrefixToPaths [ $ this -> _useStaticRegistry ] [ $ prefix ] ) ; return true ; } return false ; } if ( isset ( $ this -> _prefixToPaths [ $ prefix ] ) ) { unset ( $ this -> _prefixToPaths [ $ prefix ] ) ; return true ; } return false ; } if ( $ this -> _useStaticRegistry ) { self :: $ _staticPrefixToPaths [ $ this -> _useStaticRegistry ] = array ( ) ; } else { $ this -> _prefixToPaths = array ( ) ; } return true ; }
Clear path stack
26,560
public function isLoaded ( $ name ) { $ name = $ this -> _formatName ( $ name ) ; if ( $ this -> _useStaticRegistry ) { return isset ( self :: $ _staticLoadedPlugins [ $ this -> _useStaticRegistry ] [ $ name ] ) ; } return isset ( $ this -> _loadedPlugins [ $ name ] ) ; }
Whether or not a Plugin by a specific name is loaded
26,561
public function getClassName ( $ name ) { $ name = $ this -> _formatName ( $ name ) ; if ( $ this -> _useStaticRegistry && isset ( self :: $ _staticLoadedPlugins [ $ this -> _useStaticRegistry ] [ $ name ] ) ) { return self :: $ _staticLoadedPlugins [ $ this -> _useStaticRegistry ] [ $ name ] ; } elseif ( isset ( $ this -> _loadedPlugins [ $ name ] ) ) { return $ this -> _loadedPlugins [ $ name ] ; } return false ; }
Return full class name for a named plugin
26,562
public function getClassPath ( $ name ) { $ name = $ this -> _formatName ( $ name ) ; if ( $ this -> _useStaticRegistry && ! empty ( self :: $ _staticLoadedPluginPaths [ $ this -> _useStaticRegistry ] [ $ name ] ) ) { return self :: $ _staticLoadedPluginPaths [ $ this -> _useStaticRegistry ] [ $ name ] ; } elseif ( ! empty ( $ this -> _loadedPluginPaths [ $ name ] ) ) { return $ this -> _loadedPluginPaths [ $ name ] ; } if ( $ this -> isLoaded ( $ name ) ) { $ class = $ this -> getClassName ( $ name ) ; $ r = new ReflectionClass ( $ class ) ; $ path = $ r -> getFileName ( ) ; if ( $ this -> _useStaticRegistry ) { self :: $ _staticLoadedPluginPaths [ $ this -> _useStaticRegistry ] [ $ name ] = $ path ; } else { $ this -> _loadedPluginPaths [ $ name ] = $ path ; } return $ path ; } return false ; }
Get path to plugin class
26,563
public function load ( $ name , $ throwExceptions = true ) { $ name = $ this -> _formatName ( $ name ) ; if ( $ this -> isLoaded ( $ name ) ) { return $ this -> getClassName ( $ name ) ; } if ( $ this -> _useStaticRegistry ) { $ registry = self :: $ _staticPrefixToPaths [ $ this -> _useStaticRegistry ] ; } else { $ registry = $ this -> _prefixToPaths ; } $ registry = array_reverse ( $ registry , true ) ; $ found = false ; if ( false !== strpos ( $ name , '\\' ) ) { $ classFile = str_replace ( '\\' , DIRECTORY_SEPARATOR , $ name ) . '.php' ; } else { $ classFile = str_replace ( '_' , DIRECTORY_SEPARATOR , $ name ) . '.php' ; } $ incFile = self :: getIncludeFileCache ( ) ; foreach ( $ registry as $ prefix => $ paths ) { $ className = $ prefix . $ name ; if ( class_exists ( $ className ) ) { $ found = true ; break ; } $ paths = array_reverse ( $ paths , true ) ; foreach ( $ paths as $ path ) { $ loadFile = $ path . $ classFile ; if ( Zend_Loader :: isReadable ( $ loadFile ) ) { include_once $ loadFile ; if ( class_exists ( $ className , false ) ) { if ( null !== $ incFile ) { self :: _appendIncFile ( $ loadFile ) ; } $ found = true ; break 2 ; } } } } if ( ! $ found ) { if ( ! $ throwExceptions ) { return false ; } $ message = "Plugin by name '$name' was not found in the registry; used paths:" ; foreach ( $ registry as $ prefix => $ paths ) { $ message .= "\n$prefix: " . implode ( PATH_SEPARATOR , $ paths ) ; } throw new Zend_Loader_PluginLoader_Exception ( $ message ) ; } if ( $ this -> _useStaticRegistry ) { self :: $ _staticLoadedPlugins [ $ this -> _useStaticRegistry ] [ $ name ] = $ className ; } else { $ this -> _loadedPlugins [ $ name ] = $ className ; } return $ className ; }
Load a plugin via the name provided
26,564
public static function setIncludeFileCache ( $ file ) { if ( null === $ file ) { self :: $ _includeFileCache = null ; return ; } if ( ! file_exists ( $ file ) && ! file_exists ( dirname ( $ file ) ) ) { throw new Zend_Loader_PluginLoader_Exception ( 'Specified file does not exist and/or directory does not exist (' . $ file . ')' ) ; } if ( file_exists ( $ file ) && ! is_writable ( $ file ) ) { throw new Zend_Loader_PluginLoader_Exception ( 'Specified file is not writeable (' . $ file . ')' ) ; } if ( ! file_exists ( $ file ) && file_exists ( dirname ( $ file ) ) && ! is_writable ( dirname ( $ file ) ) ) { throw new Zend_Loader_PluginLoader_Exception ( 'Specified file is not writeable (' . $ file . ')' ) ; } self :: $ _includeFileCache = $ file ; }
Set path to class file cache
26,565
protected static function _appendIncFile ( $ incFile ) { if ( ! file_exists ( self :: $ _includeFileCache ) ) { $ file = '<?php' ; } else { $ file = file_get_contents ( self :: $ _includeFileCache ) ; } if ( ! strstr ( $ file , $ incFile ) ) { $ file .= "\ninclude_once '$incFile';" ; file_put_contents ( self :: $ _includeFileCache , $ file ) ; } }
Append an include_once statement to the class file cache
26,566
public function execute ( QueueInterface $ queue , Message $ message ) { $ projection = $ this -> eventr -> getProjection ( $ this -> projectionName ) ; $ aggregateType = $ this -> eventr -> getAggregateType ( $ this -> aggregateType ) ; $ aggregate = $ aggregateType -> getAggregate ( $ this -> aggregateId ) ; $ projection -> handle ( $ aggregate , $ this -> event ) ; return true ; }
Execute the job A job should finish itself after successful execution using the queue methods .
26,567
public function transform ( Command $ command ) { $ block = $ this -> block -> reflector ( new \ ReflectionClass ( $ command ) ) ; $ lines = [ ] ; foreach ( $ block -> getLines ( ) as $ line ) { $ lines [ ] = $ line -> stripTag ( ) ; } list ( $ name , $ description , $ signature ) = $ lines ; $ command -> setName ( $ name ) ; $ command -> setDescription ( $ description ) ; $ command -> setDefinition ( $ this -> getDefinition ( $ signature ) ) ; }
Read the command metadata and apply it .
26,568
public function getDefinition ( $ signature ) { $ elements = $ this -> meta -> parseMany ( $ signature ) ; return \ array_map ( [ $ this -> element , 'transform' ] , $ elements ) ; }
Transform the string to a valid command definition .
26,569
public function addRole ( $ role , $ inherits = null ) { if ( is_string ( $ role ) ) { $ name = $ role ; $ role = $ this -> createRole ( $ name ) ; } elseif ( $ role instanceof RoleInterface ) { $ name = $ role -> getName ( ) ; } else { throw new \ InvalidArgumentException ( 'Role must be a string or implement RoleInterface' ) ; } if ( $ inherits ) { if ( ! is_array ( $ inherits ) ) { $ inherits = [ $ inherits ] ; } foreach ( $ inherits as $ inherit ) { $ role -> inherit ( $ this -> getRole ( $ inherit ) ) ; } } $ this -> roles [ $ name ] = $ role ; return $ role ; }
Creates a new Role to the RBAC system .
26,570
public function addPermission ( $ permission ) { if ( is_string ( $ permission ) ) { $ name = $ permission ; $ permission = $ this -> createPermission ( $ name ) ; } elseif ( $ permission instanceof PermissionInterface ) { $ name = $ permission -> getName ( ) ; } else { throw new \ InvalidArgumentException ( 'Permission must be a string or implement PermissionInterface' ) ; } $ this -> permissions [ $ name ] = $ permission ; return $ permission ; }
Adds a permission to the RBAC system .
26,571
public function revokeRole ( $ role ) { if ( $ this -> hasRole ( $ role ) ) { unset ( $ this -> roles [ $ role ] ) ; return true ; } else { return false ; } }
Revokes a role from the RBAC system .
26,572
public function getRole ( $ name ) { if ( $ this -> hasRole ( $ name ) ) { return $ this -> roles [ $ name ] ; } throw new \ InvalidArgumentException ( sprintf ( 'No role with name "%s" could be found' , $ name ) ) ; }
Returns the named role from the RBAC system .
26,573
public function revokePermission ( $ permission ) { if ( $ this -> hasPermission ( $ permission ) ) { unset ( $ this -> permissions [ $ permission ] ) ; return true ; } else { return false ; } }
Revokes a permission from the RBAC system .
26,574
public function getPermission ( $ name ) { if ( $ this -> hasPermission ( $ name ) ) { return $ this -> permissions [ $ name ] ; } throw new \ InvalidArgumentException ( sprintf ( 'No permission with name "%s" could be found' , $ name ) ) ; }
Returns the named permission from the RBAC system .
26,575
public function writeLongUTF ( $ stream ) { $ this -> writeLong ( $ this -> _mbStringFunctionsOverloaded ? mb_strlen ( $ stream , '8bit' ) : strlen ( $ stream ) ) ; $ this -> _stream .= $ stream ; }
Write a long UTF string to the buffer
26,576
public function Table ( ) { if ( $ this -> SyndicationMethod == SYNDICATION_NONE ) { $ this -> View = 'table' ; } else $ this -> View = 'all' ; $ this -> All ( ) ; }
Table layout for categories . Mimics more traditional forum category layout .
26,577
public function Discussions ( ) { $ this -> AddCssFile ( 'vanilla.css' ) ; $ this -> Menu -> HighlightRoute ( '/discussions' ) ; $ this -> AddJsFile ( 'discussions.js' ) ; $ Title = C ( 'Garden.HomepageTitle' ) ; if ( $ Title ) $ this -> Title ( $ Title , '' ) ; else $ this -> Title ( T ( 'All Categories' ) ) ; $ this -> Description ( C ( 'Garden.Description' , NULL ) ) ; Gdn_Theme :: Section ( 'CategoryDiscussionList' ) ; $ CategoryFollowToggleModule = new CategoryFollowToggleModule ( $ this ) ; $ CategoryFollowToggleModule -> SetToggle ( ) ; $ this -> DiscussionsPerCategory = C ( 'Vanilla.Discussions.PerCategory' , 5 ) ; $ DiscussionModel = new DiscussionModel ( ) ; $ this -> CategoryModel -> Watching = ! Gdn :: Session ( ) -> GetPreference ( 'ShowAllCategories' ) ; $ this -> CategoryData = $ this -> CategoryModel -> GetFull ( ) ; $ this -> SetData ( 'Categories' , $ this -> CategoryData ) ; $ this -> CategoryDiscussionData = array ( ) ; foreach ( $ this -> CategoryData -> Result ( ) as $ Category ) { if ( $ Category -> CategoryID > 0 ) $ this -> CategoryDiscussionData [ $ Category -> CategoryID ] = $ DiscussionModel -> Get ( 0 , $ this -> DiscussionsPerCategory , array ( 'd.CategoryID' => $ Category -> CategoryID , 'Announce' => 'all' ) ) ; } $ this -> AddModule ( 'NewDiscussionModule' ) ; $ this -> AddModule ( 'DiscussionFilterModule' ) ; $ this -> AddModule ( 'CategoriesModule' ) ; $ this -> AddModule ( 'BookmarkedModule' ) ; $ this -> AddModule ( $ CategoryFollowToggleModule ) ; $ this -> View = 'discussions' ; $ this -> CanonicalUrl ( Url ( '/categories' , TRUE ) ) ; $ Path = $ this -> FetchViewLocation ( 'helper_functions' , 'discussions' , FALSE , FALSE ) ; if ( $ Path ) include_once $ Path ; $ this -> Render ( ) ; }
Show all categories and few discussions from each .
26,578
public function Initialize ( ) { parent :: Initialize ( ) ; if ( ! C ( 'Vanilla.Categories.Use' ) ) Redirect ( '/discussions' ) ; if ( $ this -> Menu ) $ this -> Menu -> HighlightRoute ( '/categories' ) ; $ this -> CountCommentsPerPage = C ( 'Vanilla.Comments.PerPage' , 30 ) ; }
Highlight route .
26,579
public function Append ( Array $ List , Bool $ Keys = FALSE ) { foreach ( $ List as $ Key => $ Value ) { if ( ! $ Keys ) $ this -> Push ( $ Value ) ; else $ this -> Shove ( $ Key , $ Value ) ; } return ; }
item management api for the datastore .
26,580
public function Each ( Callable $ Function , ? Array $ Argv = NULL ) { foreach ( $ this -> Data as $ Key => & $ Value ) $ Function ( $ Value , $ Key , $ this , ... $ Argv ) ; return $ this ; }
item manipulation api for the data .
26,581
protected function toIlluminateResponse ( $ response , Exception $ e ) { $ response = new Response ( $ response -> getContent ( ) , $ response -> getStatusCode ( ) , $ response -> headers -> all ( ) ) ; $ response -> exception = $ e ; return $ response ; }
Map exception into an illuminate response .
26,582
static public function getDefaultKeyName ( Config $ conf = null ) { $ locationId = "global" ; if ( is_null ( $ conf ) ) { $ projectId = self :: getProjectId ( ) ; $ keyRingId = self :: getKeyRingId ( ) ; $ cryptoKeyId = self :: getCryptoKeyId ( ) ; } else { $ projectId = $ conf -> get ( self :: CONF_PROJECT_ID_NAME ) ; $ keyRingId = $ conf -> get ( self :: CONF_KEYRING_ID_NAME ) ; $ cryptoKeyId = $ conf -> get ( self :: CONF_KEY_ID_NAME ) ; } return self :: getKeyName ( $ projectId , $ locationId , $ keyRingId , $ cryptoKeyId ) ; }
Support passing the config object directly .
26,583
static public function encrypt ( $ plaintextFileName , $ ciphertextFileName , $ key_name = null ) { $ kms = self :: getService ( ) ; if ( is_null ( $ key_name ) ) { $ key_name = self :: getDefaultKeyName ( ) ; } $ encoded = base64_encode ( file_get_contents ( $ plaintextFileName ) ) ; $ request = new \ Google_Service_CloudKMS_EncryptRequest ( ) ; $ request -> setPlaintext ( $ encoded ) ; $ response = $ kms -> projects_locations_keyRings_cryptoKeys -> encrypt ( $ key_name , $ request ) ; file_put_contents ( $ ciphertextFileName , base64_decode ( $ response [ 'ciphertext' ] ) ) ; Util :: cmdline ( "\tSaved encrypted text to $ciphertextFileName with key $key_name" ) ; return true ; }
Takes an input file and encrypts using the KMS service and puts it to an outputfile .
26,584
static public function decrypt ( $ ciphertextFileName , Config $ config = null ) { $ kms = self :: getService ( ) ; $ name = self :: getDefaultKeyName ( $ config ) ; $ ciphertext = base64_encode ( file_get_contents ( $ ciphertextFileName ) ) ; $ request = new \ Google_Service_CloudKMS_DecryptRequest ( ) ; $ request -> setCiphertext ( $ ciphertext ) ; $ response = $ kms -> projects_locations_keyRings_cryptoKeys -> decrypt ( $ name , $ request ) ; return base64_decode ( $ response [ 'plaintext' ] ) ; }
Can receive the config singleton to be able to be used of the config class during initiation of that object .
26,585
static public function decryptJson ( $ ciphertextFileName , Config $ config = null ) { $ content = self :: decrypt ( $ ciphertextFileName , $ config ) ; $ data = json_decode ( $ content , JSON_OBJECT_AS_ARRAY ) ; Util :: isArrayOrFail ( "Encrypted secrets" , $ data ) ; return $ data ; }
Utility function to decrypt json .
26,586
static public function encryptString ( $ plaintext_string , $ key_name ) { $ kms = self :: getService ( ) ; $ base64_encoded_json = base64_encode ( $ plaintext_string ) ; $ request = new \ Google_Service_CloudKMS_EncryptRequest ( ) ; $ request -> setPlaintext ( $ base64_encoded_json ) ; $ response = $ kms -> projects_locations_keyRings_cryptoKeys -> encrypt ( $ key_name , $ request ) ; return $ response [ 'ciphertext' ] ; }
Encrypts a string and returns the base64_encoded response from KMS .
26,587
public function includeRoutesFiles ( ) { if ( Config :: get ( 'sorad.api.routes.file' ) && is_array ( Config :: get ( 'sorad.api.routes.file' ) ) ) { foreach ( Config :: get ( 'sorad.api.routes.file' ) as $ route ) { if ( is_dir ( app_path ( $ route ) ) ) { $ this -> loadRoutesFrom ( app_path ( $ route . '/' . $ this -> getRouteFileName ( ) ) ) ; } elseif ( is_file ( app_path ( $ route ) ) ) { $ this -> loadRoutesFrom ( app_path ( $ route ) ) ; } } } }
Include Routes Files
26,588
public function loadRoutesClasses ( ) { if ( Config :: get ( 'sorad.api.routes.class' ) && is_array ( Config :: get ( 'sorad.api.routes.class' ) ) ) { foreach ( Config :: get ( 'sorad.api.routes.class' ) as $ route => $ config ) { $ route = sprintf ( '\\%s' , $ route ) ; if ( class_exists ( $ route ) ) { $ route :: load ( $ config ) ; } elseif ( class_exists ( sprintf ( '%s\\%s' , $ route , $ this -> getRouteClassName ( ) ) ) ) { sprintf ( '%s\\%s' , $ route , $ this -> getRouteClassName ( ) ) :: load ( $ config ) ; } } } }
Load Routes Classes
26,589
public function addFromConfig ( array $ config ) { foreach ( $ config as $ name => $ data ) { $ params = isset ( $ data [ 'params' ] ) ? $ data [ 'params' ] : array ( ) ; $ parameters = array ( ) ; foreach ( $ params as $ nameParam => $ param ) { if ( empty ( $ params [ 'type' ] ) ) { $ params [ 'type' ] = 'string' ; } switch ( $ param [ 'type' ] ) { case 'int' : $ param [ 'type' ] = Parameter :: TYPE_INTEGER ; break ; case 'mixed' : $ param [ 'type' ] = Parameter :: TYPE_MIXED ; break ; case 'string' : $ param [ 'type' ] = Parameter :: TYPE_STRING ; break ; default : } $ parameters [ $ nameParam ] = new Parameter ( $ nameParam , $ param [ 'type' ] , ( bool ) $ param [ 'mandatory' ] ) ; } $ this -> add ( new Route ( $ name , $ data [ 'route' ] , $ data [ 'controller' ] , $ parameters ) ) ; } return $ this ; }
Add routes data from configuration file .
26,590
public function match ( $ url , $ redirect404 = true ) { $ routeFound = null ; foreach ( $ this -> routes as $ route ) { if ( ! $ route -> verify ( $ url ) ) { continue ; } $ routeFound = $ route ; break ; } if ( ! ( $ routeFound instanceof RouteInterface ) && $ redirect404 === true ) { $ routeFound = $ this -> get ( 'error404' ) ; } return $ routeFound ; }
Try to find a route that match the specified url .
26,591
public static function submit ( $ text , $ attributes = array ( ) ) { if ( isset ( $ attributes [ 'name' ] ) ) { $ name = $ attributes [ 'name' ] ; unset ( $ attributes [ 'name' ] ) ; } else { $ name = 'submit' ; } return self :: input ( 'submit' , $ name , array_merge ( array ( 'value' => $ text ) , $ attributes ) ) ; }
Creates a form submit button .
26,592
public static function checkbox ( $ name , $ value , $ attributes = array ( ) ) { $ attributes [ 'value' ] = $ value ; return self :: input ( 'checkbox' , $ name , $ attributes ) ; }
Creates a checkbox field .
26,593
public static function radio ( $ name , $ value , $ attributes = array ( ) ) { $ attributes [ 'value' ] = $ value ; return self :: input ( 'radio' , $ name , $ attributes ) ; }
Creates a radio field .
26,594
public static function select ( $ name , $ options , $ attributes = array ( ) ) { $ value = isset ( $ attributes [ 'value' ] ) ? $ attributes [ 'value' ] : null ; unset ( $ attributes [ 'value' ] ) ; $ attributes [ 'name' ] = $ name ; if ( ! isset ( $ attributes [ 'id' ] ) ) { $ attributes [ 'id' ] = $ name ; } $ select = array ( ) ; $ select [ ] = "<select " . HTML :: buildAttributes ( $ attributes ) . ">" ; foreach ( $ options as $ index => $ option ) { if ( ! is_numeric ( $ index ) ) { $ select [ ] = '<optgroup label="' . $ index . '">' ; foreach ( $ option as $ opt ) { $ select [ ] = static :: selectOption ( $ opt , $ value ) ; } $ select [ ] = '</optgroup>' ; } else { $ select [ ] = static :: selectOption ( $ option , $ value ) ; } } $ select [ ] = '</select>' ; return implode ( PHP_EOL , $ select ) ; }
Creates a select field .
26,595
public static function selectOption ( $ option , $ value ) { $ attributes = [ '' ] ; $ attributes [ ] = "value=\"{$option['value']}\"" ; if ( ( is_array ( $ value ) && in_array ( $ option [ 'value' ] , $ value ) ) || ( $ option [ 'value' ] == $ value ) ) { $ attributes [ ] = 'selected="selected"' ; } $ attributes = implode ( ' ' , $ attributes ) ; return "<option {$attributes}>{$option['label']}</option>" ; }
Return the HTML for a select option .
26,596
public static function input ( $ type , $ name , $ attributes ) { if ( ! isset ( $ attributes [ 'id' ] ) ) { $ attributes [ 'id' ] = $ name ; } if ( isset ( $ attributes [ 'value' ] ) ) { $ value = $ attributes [ 'value' ] ; } elseif ( isset ( $ _POST [ $ name ] ) ) { $ value = $ _POST [ $ name ] ; } else { $ value = '' ; } foreach ( array ( 'selected' , 'checked' ) as $ attr ) { if ( isset ( $ attributes [ $ attr ] ) and ! $ attributes [ $ attr ] ) { unset ( $ attributes [ $ attr ] ) ; } elseif ( isset ( $ attributes [ $ attr ] ) ) { $ attributes [ $ attr ] = $ attr ; } } $ attributes = array_merge ( array ( 'type' => $ type , 'name' => $ name ) , $ attributes ) ; if ( $ type == 'textarea' ) { return "<textarea " . HTML :: buildAttributes ( $ attributes ) . ">{$value}</textarea>" ; } else { if ( isset ( $ attributes [ 'checked' ] ) and ! $ attributes [ 'checked' ] ) { unset ( $ attributes [ 'checked' ] ) ; } return "<input " . HTML :: buildAttributes ( $ attributes ) . ">" ; } }
Creates a form field .
26,597
protected function _setKeys ( $ keys ) { if ( ! is_array ( $ keys ) ) { throw new Exception \ InvalidArgumentException ( 'Invalid options argument provided to filter' ) ; } foreach ( $ keys as $ type => $ key ) { if ( is_file ( $ key ) and is_readable ( $ key ) ) { $ file = fopen ( $ key , 'r' ) ; $ cert = fread ( $ file , 8192 ) ; fclose ( $ file ) ; } else { $ cert = $ key ; $ key = count ( $ this -> keys [ $ type ] ) ; } switch ( $ type ) { case 'public' : $ test = openssl_pkey_get_public ( $ cert ) ; if ( $ test === false ) { throw new Exception \ InvalidArgumentException ( "Public key '{$cert}' not valid" ) ; } openssl_free_key ( $ test ) ; $ this -> keys [ 'public' ] [ $ key ] = $ cert ; break ; case 'private' : $ test = openssl_pkey_get_private ( $ cert , $ this -> passphrase ) ; if ( $ test === false ) { throw new Exception \ InvalidArgumentException ( "Private key '{$cert}' not valid" ) ; } openssl_free_key ( $ test ) ; $ this -> keys [ 'private' ] [ $ key ] = $ cert ; break ; case 'envelope' : $ this -> keys [ 'envelope' ] [ $ key ] = $ cert ; break ; default : break ; } } return $ this ; }
Sets the encryption keys
26,598
public function setPublicKey ( $ key ) { if ( is_array ( $ key ) ) { foreach ( $ key as $ type => $ option ) { if ( $ type !== 'public' ) { $ key [ 'public' ] = $ option ; unset ( $ key [ $ type ] ) ; } } } else { $ key = [ 'public' => $ key ] ; } return $ this -> _setKeys ( $ key ) ; }
Sets public keys
26,599
public static function str_utf8_chinese_word_count ( $ str = "" ) { $ str = preg_replace ( self :: UTF8_SYMBOL_PATTERN , "" , $ str ) ; return preg_match_all ( self :: UTF8_CHINESE_PATTERN , $ str , $ arr ) ; }
count only chinese words