idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
10,200
public function add_blade ( ) { $ blade = new Snap_Blade ( Theme_Utils :: get_active_theme_path ( Config :: get ( 'theme.templates_directory' ) ) , Theme_Utils :: get_active_theme_path ( \ trailingslashit ( Config :: get ( 'theme.cache_directory' ) ) . 'templates' ) , Config :: get ( 'blade.development_mode' ) ? BladeOne :: MODE_SLOW : BladeOne :: MODE_FAST ) ; if ( Config :: get ( 'blade.file_extension' ) !== $ blade -> getFileExtension ( ) ) { $ blade -> setFileExtension ( Config :: get ( 'blade.file_extension' ) ) ; } $ blade -> setInjectResolver ( function ( $ namespace ) { return Container :: get ( $ namespace ) ; } ) ; $ this -> set_auth_callbacks ( $ blade ) ; $ this -> add_directives ( $ blade ) ; $ this -> add_wp_directives ( $ blade ) ; Container :: add_instance ( $ blade ) ; Container :: alias ( Snap_Blade :: class , 'blade' ) ; }
Creates the Snap_blade instance and adds to service container .
10,201
private function add_directives ( $ blade ) { $ blade -> directive ( 'simplemenu' , function ( $ expression ) { \ preg_match ( '/\( *(.*) * as *([^\)]*)/' , $ expression , $ matches ) ; $ iteratee = \ trim ( $ matches [ 1 ] ) ; $ iteration = \ trim ( $ matches [ 2 ] ) ; $ init_loop = "\$__currentLoopData = \Snap\Utils\Menu_Utils::get_nav_menu($iteratee); \$this->addLoop(\$__currentLoopData);" ; $ iterate_loop = '$this->incrementLoopIndices(); $loop = $this->getFirstLoop();' ; return "<?php {$init_loop} foreach(\$__currentLoopData as {$iteration}): {$iterate_loop} ?>" ; } ) ; $ blade -> directive ( 'endsimplemenu' , function ( ) { return '<?php endforeach; $this->popLoop(); $loop = $this->getFirstLoop(); ?>' ; } ) ; $ blade -> directive ( 'partial' , function ( $ input ) { $ input = $ this -> trim_input ( $ input ) ; $ input = \ str_replace ( 'partials.\'' , 'partials.' , '\'partials.' . $ input ) ; return '<?php echo $this->runChild(' . $ input . '); ?>' ; } ) ; $ blade -> directive ( 'posttypepartial' , function ( ) { return '<?php global $post; echo $this->runChild(\'partials.post-type.\' . \get_post_type(), [\'post\' => $post]); ?>' ; } ) ; $ blade -> directive ( 'paginate' , function ( $ input = [ ] ) { $ input = $ input ?? '[]' ; return ' <?php $pagination = \Snap\Services\Container::resolve( \Snap\Templating\Pagination::class, [ \'args\' => ' . $ this -> trim_input ( $ input ) . ', ] ); echo $pagination->get(); ?>' ; } ) ; $ blade -> directive ( 'loop' , function ( $ input ) { $ input = $ this -> trim_input ( $ input ) ; $ init_loop = '$__loop_query = $wp_query;' ; if ( ! empty ( $ input ) ) { $ init_loop = '$__loop_query = ' . $ input . ';' ; } $ init_loop .= '$__currentLoopData = $__loop_query->posts; $this->addLoop($__currentLoopData); global $post;' ; $ iterate_loop = '$this->incrementLoopIndices(); $loop = $this->getFirstLoop();' ; return "<?php {$init_loop} while (\$__loop_query->have_posts()): \$__loop_query->the_post(); {$iterate_loop} ?>" ; } ) ; $ blade -> directive ( 'endloop' , function ( ) { return '<?php endwhile; ?>' ; } ) ; }
Add custom directives to blade .
10,202
private function add_wp_directives ( $ blade ) { $ blade -> directive ( 'wphead' , function ( ) { return '<?php wp_head(); ?>' ; } ) ; $ blade -> directive ( 'wpfooter' , function ( ) { return '<?php wp_footer(); ?>' ; } ) ; $ blade -> directive ( 'sidebar' , function ( $ input ) { return "<?php dynamic_sidebar({$this->trim_input($input)}); ?>" ; } ) ; $ blade -> directive ( 'action' , function ( $ input ) { return "<?php do_action({$this->trim_input($input)}); ?>" ; } ) ; $ blade -> directive ( 'thecontent' , function ( ) { return "<?php the_content(); ?>" ; } ) ; $ blade -> directive ( 'theexcerpt' , function ( ) { return "<?php the_excerpt(); ?>" ; } ) ; $ blade -> directive ( 'navmenu' , function ( $ input ) { return "<?php wp_nav_menu({$this->trim_input($input)}); ?>" ; } ) ; $ blade -> directive ( 'searchform' , function ( ) { return "<?php get_search_form(); ?>" ; } ) ; $ blade -> directive ( 'setpostdata' , function ( $ input ) { return '<?php setup_postdata($GLOBALS[\'post\'] =& ' . $ this -> trim_input ( $ input ) . '); ?>' ; } ) ; $ blade -> directive ( 'resetpostdata' , function ( ) { return '<?php wp_reset_postdata(); ?>' ; } ) ; }
Add custom directives for WordPress functions to blade .
10,203
public function create ( $ id , array $ attributes ) { $ typeModelName = $ this -> getTypeModelName ( ) ; $ nodeType = $ typeModelName :: findOrFail ( $ id ) ; $ nodeField = $ nodeType -> addField ( $ attributes ) ; $ this -> builderService -> buildField ( $ nodeField -> getName ( ) , $ nodeField -> getType ( ) , $ nodeField -> isIndexed ( ) , $ nodeType -> getName ( ) , $ nodeType ) ; return $ nodeField ; }
Creates a node field
10,204
public function destroy ( $ id ) { $ modelName = $ this -> getModelName ( ) ; $ nodeField = $ modelName :: findOrFail ( $ id ) ; $ nodeField -> delete ( ) ; $ this -> builderService -> destroyField ( $ nodeField -> getName ( ) , $ nodeField -> nodeType -> getName ( ) , $ nodeField -> nodeType ) ; return $ nodeField ; }
Destroys a node field
10,205
public function splitDefinition ( InputDefinition $ definition ) { $ ret = array ( new InputDefinition ( ) , new InputDefinition ( ) ) ; foreach ( $ definition -> getArguments ( ) as $ arg ) { $ ret [ 0 ] -> addArgument ( $ arg ) ; $ ret [ 1 ] -> addArgument ( $ arg ) ; } foreach ( $ definition -> getOptions ( ) as $ opt ) { $ ret [ $ this -> isHiddenOption ( $ opt ) ? 1 : 0 ] -> addOption ( $ opt ) ; } return $ ret ; }
Splits the definition in an internal and public one the latter representing whatever is shown to the user the former representing the options that are hidden .
10,206
public function addRenderer ( $ name , $ renderer , $ overwrite = false ) { if ( isset ( $ this -> renderers [ $ name ] ) && ! $ overwrite ) { throw new InvalidArgumentException ( "Renderer with name '$name' is already registered." ) ; } unset ( $ this -> renderers [ $ name ] ) ; if ( is_string ( $ renderer ) && ! class_exists ( $ renderer ) ) { throw new InvalidArgumentException ( "Renderer class '$renderer' doesn't exist." ) ; } $ this -> renderers [ $ name ] = $ renderer ; return $ this ; }
Ads renderer with given name
10,207
public function getRenderer ( $ name ) { if ( $ name === null ) { if ( $ this -> defaultRenderer !== null ) { $ name = $ this -> defaultRenderer ; } else if ( count ( $ this -> renderers ) > 0 ) { $ name = key ( $ this -> renderers ) ; } } if ( ! isset ( $ this -> renderers [ $ name ] ) ) { throw new InvalidArgumentException ( "Renderer with name '$name' doesn't exist." ) ; } if ( is_string ( $ this -> renderers [ $ name ] ) ) { $ renderer = new $ this -> renderers [ $ name ] ( ) ; $ reflection = ClassType :: from ( $ renderer ) ; if ( ! $ reflection -> isSubclassOf ( 'Smf\Menu\Renderer\IRenderer' ) ) { throw new InvalidArgumentException ( "Renderer class '{$this->renderers[$name]}' is not subclass of Smf\\Menu\\Renderer\\IRenderer" ) ; } $ this -> renderers [ $ name ] = $ renderer ; } return $ this -> renderers [ $ name ] ; }
Returns instance of the renderer
10,208
protected function getFiles ( ) { $ this -> mirrorDir ( ) ; $ this -> prepareMirrorDir ( ) ; $ this -> printTaskInfo ( 'Retrieving files to package.' ) ; $ mirrorFinder = new Finder ( ) ; $ mirrorFinder -> ignoreDotFiles ( false ) ; $ add = [ ] ; $ mirrorFinder -> in ( $ this -> tmpDir ) -> depth ( 0 ) ; foreach ( $ mirrorFinder as $ file ) { $ add [ substr ( $ file -> getRealPath ( ) , strlen ( realpath ( $ this -> tmpDir ) ) + 1 ) ] = $ file -> getRealPath ( ) ; } return $ add ; }
Get the files and directories to package .
10,209
protected function mirrorDir ( ) { if ( ! $ this -> useTmpDir ) { $ this -> tmpDir = $ this -> dir ; return ; } $ this -> tmpDir = md5 ( time ( ) ) ; if ( file_exists ( $ this -> tmpDir ) ) { $ this -> fs -> remove ( $ this -> tmpDir ) ; } $ this -> printTaskInfo ( sprintf ( 'Creating temporary directory %s.' , $ this -> tmpDir ) ) ; $ this -> fs -> mkdir ( $ this -> tmpDir ) ; $ tmpRealPath = realpath ( $ this -> tmpDir ) ; $ directoryIterator = new \ RecursiveDirectoryIterator ( $ this -> dir , \ RecursiveDirectoryIterator :: SKIP_DOTS ) ; $ recursiveIterator = new \ RecursiveIteratorIterator ( $ directoryIterator , \ RecursiveIteratorIterator :: SELF_FIRST ) ; $ filterIterator = new \ CallbackFilterIterator ( $ recursiveIterator , function ( $ current ) use ( $ tmpRealPath ) { return strpos ( $ current -> getRealPath ( ) , $ tmpRealPath ) !== 0 ; } ) ; $ this -> printTaskInfo ( sprintf ( 'Mirroring directory %s to temporary directory %s.' , $ this -> dir , $ tmpRealPath ) ) ; foreach ( $ filterIterator as $ item ) { if ( strpos ( $ item -> getRealPath ( ) , $ tmpRealPath ) === 0 ) { continue ; } if ( is_link ( $ item ) ) { if ( $ item -> getRealPath ( ) !== false ) { $ this -> fs -> symlink ( $ item -> getLinkTarget ( ) , $ this -> tmpDir . DIRECTORY_SEPARATOR . $ filterIterator -> getSubPathName ( ) ) ; } continue ; } if ( $ item -> isDir ( ) ) { $ this -> fs -> mkdir ( $ this -> tmpDir . DIRECTORY_SEPARATOR . $ filterIterator -> getSubPathName ( ) ) ; continue ; } $ this -> fs -> copy ( $ item , $ this -> tmpDir . DIRECTORY_SEPARATOR . $ filterIterator -> getSubPathName ( ) ) ; } }
Mirror the directory to a temp directory .
10,210
protected function prepareMirrorDir ( ) { $ this -> printTaskInfo ( sprintf ( 'Preparing directory %s.' , $ this -> tmpDir ) ) ; if ( empty ( $ this -> ignoreFileNames ) ) { return ; } $ files = new Finder ( ) ; $ files -> in ( $ this -> tmpDir ) ; $ files -> ignoreDotFiles ( false ) ; $ files -> files ( ) ; foreach ( $ this -> ignoreFileNames as $ fileName ) { $ files -> name ( $ fileName ) ; } $ this -> fs -> remove ( $ files ) ; }
Removes files that should not be packaged from the mirrored directory .
10,211
public static function fd ( $ object , $ type = 'log' ) { $ types = array ( 'log' , 'debug' , 'info' , 'warn' , 'error' , 'assert' ) ; if ( ! \ in_array ( $ type , $ types , true ) ) { $ type = 'log' ; } $ data = json_encode ( $ object ) ; echo '<script type="text/javascript">console.' . $ type . '(' . $ data . ');</script>' ; }
Display a var dump in firebug console
10,212
public function parse ( ) { $ p = 0 ; do { $ p = $ this -> scanner -> position ( ) ; $ this -> consumeData ( ) ; } while ( $ this -> carryOn ) ; }
Begin parsing .
10,213
public function setTextMode ( $ textmode , $ untilTag = null ) { $ this -> textMode = $ textmode & ( HTML5_Elements :: TEXT_RAW | HTML5_Elements :: TEXT_RCDATA ) ; $ this -> untilTag = $ untilTag ; }
Set the text mode for the character data reader .
10,214
protected function consumeData ( ) { $ this -> characterReference ( ) ; $ this -> tagOpen ( ) ; $ this -> eof ( ) ; $ this -> characterData ( ) ; return $ this -> carryOn ; }
Consume a character and make a move . HTML5 8 . 2 . 4 . 1
10,215
protected function characterData ( ) { if ( $ this -> scanner -> current ( ) === false ) { return false ; } switch ( $ this -> textMode ) { case HTML5_Elements :: TEXT_RAW : return $ this -> rawText ( ) ; case HTML5_Elements :: TEXT_RCDATA : return $ this -> rcdata ( ) ; default : $ tok = $ this -> scanner -> current ( ) ; if ( strspn ( $ tok , "<&" ) ) { return false ; } return $ this -> text ( ) ; } }
Parse anything that looks like character data .
10,216
protected function text ( ) { $ tok = $ this -> scanner -> current ( ) ; if ( $ tok === false ) { return false ; } if ( $ tok === "\00" ) { $ this -> parseError ( "Received null character." ) ; } $ this -> buffer ( $ tok ) ; $ this -> scanner -> next ( ) ; return true ; }
This buffers the current token as character data .
10,217
protected function rawText ( ) { if ( is_null ( $ this -> untilTag ) ) { return $ this -> text ( ) ; } $ sequence = '</' . $ this -> untilTag . '>' ; $ txt = $ this -> readUntilSequence ( $ sequence ) ; $ this -> events -> text ( $ txt ) ; $ this -> setTextMode ( 0 ) ; return $ this -> endTag ( ) ; }
Read text in RAW mode .
10,218
protected function rcdata ( ) { if ( is_null ( $ this -> untilTag ) ) { return $ this -> text ( ) ; } $ sequence = '</' . $ this -> untilTag . '>' ; $ txt = '' ; $ tok = $ this -> scanner -> current ( ) ; while ( $ tok !== false && ! ( $ tok == '<' && ( $ this -> sequenceMatches ( $ sequence ) || $ this -> sequenceMatches ( strtoupper ( $ sequence ) ) ) ) ) { if ( $ tok == '&' ) { $ txt .= $ this -> decodeCharacterReference ( ) ; $ tok = $ this -> scanner -> current ( ) ; } else { $ txt .= $ tok ; $ tok = $ this -> scanner -> next ( ) ; } } $ this -> events -> text ( $ txt ) ; $ this -> setTextMode ( 0 ) ; return $ this -> endTag ( ) ; }
Read text in RCDATA mode .
10,219
protected function eof ( ) { if ( $ this -> scanner -> current ( ) === false ) { $ this -> flushBuffer ( ) ; $ this -> events -> eof ( ) ; $ this -> carryOn = false ; return true ; } return false ; }
If the document is read emit an EOF event .
10,220
protected function tagOpen ( ) { if ( $ this -> scanner -> current ( ) != '<' ) { return false ; } $ this -> flushBuffer ( ) ; $ this -> scanner -> next ( ) ; return $ this -> markupDeclaration ( ) || $ this -> endTag ( ) || $ this -> processingInstruction ( ) || $ this -> tagName ( ) || $ this -> parseError ( "Illegal tag opening" ) || $ this -> characterData ( ) ; }
Emit a tagStart event on encountering a tag .
10,221
protected function markupDeclaration ( ) { if ( $ this -> scanner -> current ( ) != '!' ) { return false ; } $ tok = $ this -> scanner -> next ( ) ; if ( $ tok == '-' && $ this -> scanner -> peek ( ) == '-' ) { $ this -> scanner -> next ( ) ; $ this -> scanner -> next ( ) ; return $ this -> comment ( ) ; } elseif ( $ tok == 'D' || $ tok == 'd' ) { return $ this -> doctype ( '' ) ; } elseif ( $ tok == '[' ) { return $ this -> cdataSection ( ) ; } $ this -> parseError ( "Expected <!--, <![CDATA[, or <!DOCTYPE. Got <!%s" , $ tok ) ; $ this -> bogusComment ( '<!' ) ; return true ; }
Look for markup .
10,222
protected function endTag ( ) { if ( $ this -> scanner -> current ( ) != '/' ) { return false ; } $ tok = $ this -> scanner -> next ( ) ; if ( ! ctype_alpha ( $ tok ) ) { $ this -> parseError ( "Expected tag name, got '%s'" , $ tok ) ; if ( $ tok == "\0" || $ tok === false ) { return false ; } return $ this -> bogusComment ( '</' ) ; } $ name = strtolower ( $ this -> scanner -> charsUntil ( "\n\f \t>" ) ) ; $ this -> scanner -> whitespace ( ) ; if ( $ this -> scanner -> current ( ) != '>' ) { $ this -> parseError ( "Expected >, got '%s'" , $ this -> scanner -> current ( ) ) ; $ this -> scanner -> charsUntil ( '>' ) ; } $ this -> events -> endTag ( $ name ) ; $ this -> scanner -> next ( ) ; return true ; }
Consume an end tag . 8 . 2 . 4 . 9
10,223
protected function tagName ( ) { $ tok = $ this -> scanner -> current ( ) ; if ( ! ctype_alpha ( $ tok ) ) { return false ; } $ name = strtolower ( $ this -> scanner -> charsWhile ( ":_-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ) ) ; $ attributes = array ( ) ; $ selfClose = false ; try { do { $ this -> scanner -> whitespace ( ) ; $ this -> attribute ( $ attributes ) ; } while ( ! $ this -> isTagEnd ( $ selfClose ) ) ; } catch ( HTML5_Parser_Exception $ e ) { $ selfClose = false ; } $ mode = $ this -> events -> startTag ( $ name , $ attributes , $ selfClose ) ; if ( $ selfClose ) { $ this -> events -> endTag ( $ name ) ; } elseif ( is_int ( $ mode ) ) { $ this -> setTextMode ( $ mode , $ name ) ; } $ this -> scanner -> next ( ) ; return true ; }
Consume a tag name and body . 8 . 2 . 4 . 10
10,224
protected function isTagEnd ( & $ selfClose ) { $ tok = $ this -> scanner -> current ( ) ; if ( $ tok == '/' ) { $ this -> scanner -> next ( ) ; $ this -> scanner -> whitespace ( ) ; if ( $ this -> scanner -> current ( ) == '>' ) { $ selfClose = true ; return true ; } if ( $ this -> scanner -> current ( ) === false ) { $ this -> parseError ( "Unexpected EOF inside of tag." ) ; return true ; } $ this -> parseError ( "Unexpected '%s' inside of a tag." , $ this -> scanner -> current ( ) ) ; return false ; } if ( $ this -> scanner -> current ( ) == '>' ) { return true ; } if ( $ this -> scanner -> current ( ) === false ) { $ this -> parseError ( "Unexpected EOF inside of tag." ) ; return true ; } return false ; }
Check if the scanner has reached the end of a tag .
10,225
protected function attribute ( & $ attributes ) { $ tok = $ this -> scanner -> current ( ) ; if ( $ tok == '/' || $ tok == '>' || $ tok === false ) { return false ; } if ( $ tok == '<' ) { $ this -> parseError ( "Unexepcted '<' inside of attributes list." ) ; $ this -> scanner -> unconsume ( ) ; throw new HTML5_Parser_Exception ( "Start tag inside of attribute." ) ; } $ name = strtolower ( $ this -> scanner -> charsUntil ( "/>=\n\f\t " ) ) ; if ( strlen ( $ name ) == 0 ) { $ this -> parseError ( "Expected an attribute name, got %s." , $ this -> scanner -> current ( ) ) ; $ name = $ this -> scanner -> current ( ) ; $ this -> scanner -> next ( ) ; } $ isValidAttribute = true ; if ( preg_match ( "/[\x1-\x2C\\/\x3B-\x40\x5B-\x5E\x60\x7B-\x7F]/u" , $ name ) ) { $ this -> parseError ( "Unexpected characters in attribute name: %s" , $ name ) ; $ isValidAttribute = false ; } else if ( preg_match ( "/^[0-9.-]/u" , $ name ) ) { $ this -> parseError ( "Unexpected character at the begining of attribute name: %s" , $ name ) ; $ isValidAttribute = false ; } $ this -> scanner -> whitespace ( ) ; $ val = $ this -> attributeValue ( ) ; if ( $ isValidAttribute ) { $ attributes [ $ name ] = $ val ; } return true ; }
Parse attributes from inside of a tag .
10,226
protected function attributeValue ( ) { if ( $ this -> scanner -> current ( ) != '=' ) { return null ; } $ this -> scanner -> next ( ) ; $ this -> scanner -> whitespace ( ) ; $ tok = $ this -> scanner -> current ( ) ; switch ( $ tok ) { case "\n" : case "\f" : case " " : case "\t" : return null ; case '"' : case "'" : $ this -> scanner -> next ( ) ; return $ this -> quotedAttributeValue ( $ tok ) ; case '>' : $ this -> parseError ( "Expected attribute value, got tag end." ) ; return null ; case '=' : case '`' : $ this -> parseError ( "Expecting quotes, got %s." , $ tok ) ; return $ this -> unquotedAttributeValue ( ) ; default : return $ this -> unquotedAttributeValue ( ) ; } }
Consume an attribute value . 8 . 2 . 4 . 37 and after .
10,227
protected function quotedAttributeValue ( $ quote ) { $ stoplist = "\f" . $ quote ; $ val = '' ; $ tok = $ this -> scanner -> current ( ) ; while ( strspn ( $ tok , $ stoplist ) == 0 && $ tok !== false ) { if ( $ tok == '&' ) { $ val .= $ this -> decodeCharacterReference ( true ) ; $ tok = $ this -> scanner -> current ( ) ; } else { $ val .= $ tok ; $ tok = $ this -> scanner -> next ( ) ; } } $ this -> scanner -> next ( ) ; return $ val ; }
Get an attribute value string .
10,228
protected function bogusComment ( $ leading = '' ) { $ comment = $ leading ; $ tok = $ this -> scanner -> current ( ) ; do { $ comment .= $ tok ; $ tok = $ this -> scanner -> next ( ) ; } while ( $ tok !== false && $ tok != '>' ) ; $ this -> flushBuffer ( ) ; $ this -> events -> comment ( $ comment . $ tok ) ; $ this -> scanner -> next ( ) ; return true ; }
Consume malformed markup as if it were a comment . 8 . 2 . 4 . 44
10,229
protected function comment ( ) { $ tok = $ this -> scanner -> current ( ) ; $ comment = '' ; if ( $ tok == '>' ) { $ this -> parseError ( "Expected comment data, got '>'" ) ; $ this -> events -> comment ( '' ) ; $ this -> scanner -> next ( ) ; return true ; } if ( $ tok == "\0" ) { $ tok = HTML5_Parser_UTF8Utils :: FFFD ; } while ( ! $ this -> isCommentEnd ( ) ) { $ comment .= $ tok ; $ tok = $ this -> scanner -> next ( ) ; } $ this -> events -> comment ( $ comment ) ; $ this -> scanner -> next ( ) ; return true ; }
Read a comment .
10,230
protected function isCommentEnd ( ) { if ( $ this -> scanner -> current ( ) === false ) { $ this -> parseError ( "Unexpected EOF in a comment." ) ; return true ; } if ( $ this -> scanner -> current ( ) != '-' ) { return false ; } if ( $ this -> scanner -> next ( ) == '-' && $ this -> scanner -> peek ( ) == '>' ) { $ this -> scanner -> next ( ) ; return true ; } $ this -> scanner -> unconsume ( 1 ) ; return false ; }
Check if the scanner has reached the end of a comment .
10,231
protected function quotedString ( $ stopchars ) { $ tok = $ this -> scanner -> current ( ) ; if ( $ tok == '"' || $ tok == "'" ) { $ this -> scanner -> next ( ) ; $ ret = $ this -> scanner -> charsUntil ( $ tok . $ stopchars ) ; if ( $ this -> scanner -> current ( ) == $ tok ) { $ this -> scanner -> next ( ) ; } else { $ this -> parseError ( "Expected %s, got %s" , $ tok , $ this -> scanner -> current ( ) ) ; } return $ ret ; } return false ; }
Utility for reading a quoted string .
10,232
protected function cdataSection ( ) { if ( $ this -> scanner -> current ( ) != '[' ) { return false ; } $ cdata = '' ; $ this -> scanner -> next ( ) ; $ chars = $ this -> scanner -> charsWhile ( 'CDAT' ) ; if ( $ chars != 'CDATA' || $ this -> scanner -> current ( ) != '[' ) { $ this -> parseError ( 'Expected [CDATA[, got %s' , $ chars ) ; return $ this -> bogusComment ( '<![' . $ chars ) ; } $ tok = $ this -> scanner -> next ( ) ; do { if ( $ tok === false ) { $ this -> parseError ( 'Unexpected EOF inside CDATA.' ) ; $ this -> bogusComment ( '<![CDATA[' . $ cdata ) ; return true ; } $ cdata .= $ tok ; $ tok = $ this -> scanner -> next ( ) ; } while ( ! $ this -> sequenceMatches ( ']]>' ) ) ; $ this -> scanner -> consume ( 3 ) ; $ this -> events -> cdata ( $ cdata ) ; return true ; }
Handle a CDATA section .
10,233
protected function processingInstruction ( ) { if ( $ this -> scanner -> current ( ) != '?' ) { return false ; } $ tok = $ this -> scanner -> next ( ) ; $ procName = $ this -> scanner -> getAsciiAlpha ( ) ; $ white = strlen ( $ this -> scanner -> whitespace ( ) ) ; if ( strlen ( $ procName ) == 0 || $ white == 0 || $ this -> scanner -> current ( ) == false ) { $ this -> parseError ( "Expected processing instruction name, got $tok" ) ; $ this -> bogusComment ( '<?' . $ tok . $ procName ) ; return true ; } $ data = '' ; while ( ! ( $ this -> scanner -> current ( ) == '?' && $ this -> scanner -> peek ( ) == '>' ) ) { $ data .= $ this -> scanner -> current ( ) ; $ tok = $ this -> scanner -> next ( ) ; if ( $ tok === false ) { $ this -> parseError ( "Unexpected EOF in processing instruction." ) ; $ this -> events -> processingInstruction ( $ procName , $ data ) ; return true ; } } $ this -> scanner -> next ( ) ; $ this -> scanner -> next ( ) ; $ this -> events -> processingInstruction ( $ procName , $ data ) ; return true ; }
Handle a processing instruction .
10,234
protected function readUntilSequence ( $ sequence ) { $ buffer = '' ; $ first = substr ( $ sequence , 0 , 1 ) ; while ( $ this -> scanner -> current ( ) !== false ) { $ buffer .= $ this -> scanner -> charsUntil ( $ first ) ; if ( $ this -> sequenceMatches ( $ sequence ) || $ this -> sequenceMatches ( strtoupper ( $ sequence ) ) ) { return $ buffer ; } $ buffer .= $ this -> scanner -> current ( ) ; $ this -> scanner -> next ( ) ; } $ this -> parseError ( "Unexpected EOF during text read." ) ; return $ buffer ; }
Read from the input stream until we get to the desired sequene or hit the end of the input stream .
10,235
protected function sequenceMatches ( $ sequence ) { $ len = strlen ( $ sequence ) ; $ buffer = '' ; for ( $ i = 0 ; $ i < $ len ; ++ $ i ) { $ buffer .= $ this -> scanner -> current ( ) ; if ( $ this -> scanner -> current ( ) === false ) { $ this -> scanner -> unconsume ( $ i ) ; return false ; } $ this -> scanner -> next ( ) ; } $ this -> scanner -> unconsume ( $ len ) ; return $ buffer == $ sequence ; }
Check if upcomming chars match the given sequence .
10,236
protected function flushBuffer ( ) { if ( $ this -> text === '' ) { return ; } $ this -> events -> text ( $ this -> text ) ; $ this -> text = '' ; }
Send a TEXT event with the contents of the text buffer .
10,237
protected function parseError ( $ msg ) { $ args = func_get_args ( ) ; if ( count ( $ args ) > 1 ) { array_shift ( $ args ) ; $ msg = vsprintf ( $ msg , $ args ) ; } $ line = $ this -> scanner -> currentLine ( ) ; $ col = $ this -> scanner -> columnOffset ( ) ; $ this -> events -> parseError ( $ msg , $ line , $ col ) ; return false ; }
Emit a parse error .
10,238
protected function decodeCharacterReference ( $ inAttribute = false ) { if ( $ this -> scanner -> current ( ) != '&' ) { return false ; } $ tok = $ this -> scanner -> next ( ) ; $ entity = '' ; $ start = $ this -> scanner -> position ( ) ; if ( $ tok == false ) { return '&' ; } if ( strspn ( $ tok , static :: WHITE . "&<" ) == 1 ) { return '&' ; } if ( $ tok == '#' ) { $ tok = $ this -> scanner -> next ( ) ; if ( $ tok == 'x' || $ tok == 'X' ) { $ tok = $ this -> scanner -> next ( ) ; $ hex = $ this -> scanner -> getHex ( ) ; if ( empty ( $ hex ) ) { $ this -> parseError ( "Expected &#xHEX;, got &#x%s" , $ tok ) ; $ this -> scanner -> unconsume ( 2 ) ; return '&' ; } $ entity = HTML5_Parser_CharacterReference :: lookupHex ( $ hex ) ; } else { $ numeric = $ this -> scanner -> getNumeric ( ) ; if ( $ numeric === false ) { $ this -> parseError ( "Expected &#DIGITS;, got &#%s" , $ tok ) ; $ this -> scanner -> unconsume ( 2 ) ; return '&' ; } $ entity = HTML5_Parser_CharacterReference :: lookupDecimal ( $ numeric ) ; } } else { $ cname = $ this -> scanner -> getAsciiAlpha ( ) ; $ entity = HTML5_Parser_CharacterReference :: lookupName ( $ cname ) ; if ( $ entity == null ) { $ this -> parseError ( "No match in entity table for '%s'" , $ entity ) ; } } $ tok = $ this -> scanner -> current ( ) ; if ( $ tok == ';' ) { $ this -> scanner -> next ( ) ; return $ entity ; } if ( $ inAttribute ) { $ this -> scanner -> unconsume ( $ this -> scanner -> position ( ) - $ start ) ; return '&' ; } $ this -> parseError ( "Expected &ENTITY;, got &ENTITY%s (no trailing ;) " , $ tok ) ; return '&' . $ entity ; }
Decode a character reference and return the string .
10,239
public static function splitName ( $ class ) { $ pos = strrpos ( $ class , '\\' ) ; if ( $ pos === false ) { return [ null , $ class ] ; } else { return [ substr ( $ class , 0 , $ pos ) , substr ( $ class , $ pos + 1 ) ] ; } }
Splits class name to namespace and class name
10,240
public function getParameter ( $ key , $ default = null ) { $ value = $ this -> getUrl ( ) -> getQuery ( ) -> get ( $ key ) ; if ( $ value === null ) { $ value = $ this -> getData ( ) -> get ( $ key , $ default ) ; } return $ value ; }
Retrieve a value from url query or message body .
10,241
protected function setDefaults ( ) { if ( $ this -> getAccept ( ) === null ) { $ this -> setDefaultAccept ( ) ; } if ( $ this -> getContentType ( ) === null ) { $ this -> setDefaultContentType ( ) ; } }
Use this as hook to extend your custom request .
10,242
public function getImports ( ) { $ imports = [ ] ; $ tokens = token_get_all ( file_get_contents ( $ this -> file ) ) ; reset ( $ tokens ) ; $ token = '' ; while ( $ token !== false ) { $ token = next ( $ tokens ) ; if ( ! is_array ( $ token ) ) { continue ; } if ( $ token [ 0 ] === T_USE ) { $ stmt = $ this -> parseUseStatement ( $ tokens ) ; $ imports += $ stmt ; } elseif ( $ token [ 0 ] === T_CLASS ) { break ; } } return $ imports ; }
Gets all imported classes
10,243
public function compile ( Buffer $ buffer ) { parent :: compile ( $ buffer ) ; if ( substr ( $ this -> getName ( ) , 0 , 1 ) !== '_' ) { $ buffer -> writeln ( 'try {' ) -> indent ( 1 ) -> writeln ( '$z->addCommand(' ) -> indent ( 1 ) -> write ( 'new \Zicht\Tool\Command\TaskCommand(' ) -> asPhp ( $ this -> getName ( ) ) -> raw ( ', ' ) -> asPhp ( $ this -> getArguments ( true ) ) -> raw ( ', ' ) -> asPhp ( $ this -> getOptions ( ) ) -> raw ( ', ' ) -> asPhp ( $ this -> taskDef [ 'flags' ] ) -> raw ( ', ' ) -> asPhp ( $ this -> getHelp ( ) ? $ this -> getHelp ( ) : "(no help available for this task)" ) -> raw ( ')' ) -> eol ( ) -> indent ( - 1 ) -> writeln ( ');' ) -> indent ( - 1 ) -> writeln ( '} catch (\Exception $e) {' ) -> indent ( 1 ) -> writeln ( 'throw new \Zicht\Tool\Container\ConfigurationException("Error while initializing task \'' . $ this -> getName ( ) . '\'", 0, $e);' ) -> indent ( - 1 ) -> writeln ( '}' ) ; } }
Compiles the task initialization code into the buffer .
10,244
public function execute ( ProjectDescriptor $ project ) { $ rootPackageDescriptor = new PackageDescriptor ( ) ; $ rootPackageDescriptor -> setName ( '\\' ) ; $ project -> getIndexes ( ) -> set ( 'packages' , new Collection ( ) ) ; $ project -> getIndexes ( ) -> packages [ '\\' ] = $ rootPackageDescriptor ; foreach ( $ project -> getFiles ( ) as $ file ) { $ this -> addElementsOfTypeToPackage ( $ project , array ( $ file ) , 'files' ) ; $ this -> addElementsOfTypeToPackage ( $ project , $ file -> getConstants ( ) -> getAll ( ) , 'constants' ) ; $ this -> addElementsOfTypeToPackage ( $ project , $ file -> getFunctions ( ) -> getAll ( ) , 'functions' ) ; $ this -> addElementsOfTypeToPackage ( $ project , $ file -> getClasses ( ) -> getAll ( ) , 'classes' ) ; $ this -> addElementsOfTypeToPackage ( $ project , $ file -> getInterfaces ( ) -> getAll ( ) , 'interfaces' ) ; $ this -> addElementsOfTypeToPackage ( $ project , $ file -> getTraits ( ) -> getAll ( ) , 'traits' ) ; } }
Compiles a packages index on the project and create all Package Descriptors necessary .
10,245
protected function addElementsOfTypeToPackage ( ProjectDescriptor $ project , array $ elements , $ type ) { foreach ( $ elements as $ element ) { $ packageName = '' ; $ packageTags = $ element -> getTags ( ) -> get ( 'package' ) ; if ( $ packageTags instanceof Collection ) { $ packageTag = $ packageTags -> getIterator ( ) -> current ( ) ; if ( $ packageTag instanceof TagDescriptor ) { $ packageName = $ packageTag -> getDescription ( ) ; } } $ subpackageCollection = $ element -> getTags ( ) -> get ( 'subpackage' ) ; if ( $ subpackageCollection instanceof Collection && $ subpackageCollection -> count ( ) > 0 ) { $ subpackageTag = $ subpackageCollection -> getIterator ( ) -> current ( ) ; if ( $ subpackageTag instanceof TagDescriptor ) { $ packageName .= '\\' . $ subpackageTag -> getDescription ( ) ; } } $ packageIndexName = '\\' . ltrim ( $ packageName , '\\' ) ; if ( ! isset ( $ project -> getIndexes ( ) -> packages [ $ packageIndexName ] ) ) { $ this -> createPackageDescriptorTree ( $ project , $ packageName ) ; } $ package = $ project -> getIndexes ( ) -> packages [ $ packageIndexName ] ; $ element -> setPackage ( $ package ) ; $ getter = 'get' . ucfirst ( $ type ) ; $ collection = $ package -> $ getter ( ) ; $ collection -> add ( $ element ) ; } }
Adds the given elements of a specific type to their respective Package Descriptors .
10,246
private function requiresTfa ( ResponseInterface $ response ) { return substr ( $ response -> getStatusCode ( ) , 0 , 1 ) === '4' && $ response -> hasHeader ( self :: TFA_HEADER ) ; }
Check whether the response requires two - factor authentication .
10,247
public function unsetCookie ( $ name , $ path = '/' ) { setcookie ( $ name , '' , time ( ) - 86400 , '/' , '' , 0 ) ; if ( isset ( $ _COOKIE ) && isset ( $ _COOKIE [ $ name ] ) ) { unset ( $ _COOKIE [ $ name ] ) ; } if ( isset ( $ this -> request -> cookie [ $ name ] ) ) { unset ( $ this -> request -> cookie [ $ name ] ) ; } }
Unsets a cookie value by setting it to expire
10,248
public function sendError ( $ error_num , $ err_str = '' ) { if ( empty ( $ err_str ) ) { switch ( $ error_num ) { case 400 : $ err_str = 'Bad Request' ; break ; case 401 : $ err_str = 'Unauthorized' ; break ; case 403 : $ err_str = 'Forbidden' ; break ; case 404 : $ err_str = 'Not Found' ; break ; case 405 : $ err_str = 'Method Not Allowed' ; break ; case 410 : $ err_str = 'Gone' ; break ; case 415 : $ err_str = 'Unsupported Media Type' ; break ; case 500 : $ err_str = 'Internal Server Error' ; break ; case 501 : $ err_str = 'Not Implemented' ; break ; } } $ this -> sendHeader ( "HTTP/1.0 $error_num $err_str" ) ; }
Send an http error header
10,249
public function requireBasicAuth ( $ check_auth = '' , $ realm = 'Please enter your username and password' ) { $ authorized = false ; if ( ! isset ( $ _SERVER [ 'PHP_AUTH_USER' ] ) ) { header ( 'WWW-Authenticate: Basic realm="' . $ realm . '"' ) ; header ( 'HTTP/1.0 401 Unauthorized' ) ; echo 'You must authenticate to continue' ; } else { if ( is_callable ( $ check_auth ) ) { $ authorized = $ check_auth ( $ _SERVER [ 'PHP_AUTH_USER' ] , $ _SERVER [ 'PHP_AUTH_PW' ] ) ; } if ( ! $ authorized ) { session_unset ( ) ; unset ( $ _SERVER [ 'PHP_AUTH_USER' ] ) ; return $ this -> requireBasicAuth ( $ check_auth , $ realm ) ; } } return $ authorized ; }
Added option for requesting basic auth . ONLY USE OVER SSL
10,250
public function autoload ( array $ autoloads , $ provider , $ options = [ ] ) { foreach ( $ autoloads as $ name => $ alias ) { if ( is_int ( $ name ) ) { $ name = $ alias ; } if ( empty ( $ name ) ) { throw new \ InvalidArgumentException ( "Cannot not autoload empty service" ) ; } if ( ! empty ( $ options [ 'prefix' ] ) ) { $ alias = $ options [ 'prefix' ] . ucfirst ( $ alias ) ; } $ shared = true ; if ( isset ( $ options [ 'shared' ] ) ) { if ( is_array ( $ options [ 'shared' ] ) ) { $ shared = in_array ( $ name , $ options [ 'shared' ] ) ; } else { $ shared = $ options [ 'shared' ] ; } } elseif ( isset ( $ options [ 'instances' ] ) ) { $ shared = ! in_array ( $ name , $ options [ 'instances' ] ) ; } $ this -> set ( $ alias , function ( ) use ( $ name , $ provider ) { if ( ! is_object ( $ provider ) ) { $ provider = $ this -> getShared ( $ provider ) ; } return $ provider -> provide ( $ name , func_get_args ( ) ) ; } , $ shared ) ; } return $ this ; }
mark autoload service definition from service provider
10,251
public function load ( $ provider , $ options = null ) { if ( ! is_object ( $ provider ) ) { $ provider = $ this -> getShared ( $ provider ) ; } $ names = $ provider -> getNames ( ) ; if ( isset ( $ options [ 'aliases' ] ) ) { $ services = $ this -> createServiceAliases ( $ names , $ options [ 'aliases' ] ) ; unset ( $ options [ 'aliases' ] ) ; } else { $ services = $ names ; } return $ this -> autoload ( $ services , $ provider , $ options ) ; }
load all service definition from service provider
10,252
private static function get_file ( ) : string { if ( null === self :: $ path ) { if ( \ defined ( 'BBN_DATA_PATH' ) ) { self :: $ path = BBN_DATA_PATH ; } else { self :: $ path = __DIR__ . '/' ; } } return self :: $ path . 'plugins/appui-cron/appui-observer.txt' ; }
Returns the observer txt file s full path .
10,253
private function _get_id ( string $ request , $ params ) : ? string { if ( $ this -> check ( ) ) { if ( $ params ) { return $ this -> db -> select_one ( 'bbn_observers' , 'id' , [ 'id_string' => $ this -> _get_id_string ( $ request , $ params ) ] ) ; } return $ this -> db -> get_one ( " SELECT id FROM bbn_observers WHERE `request` LIKE ? AND `params` IS NULL AND `public` = 1" , $ request ) ; } return null ; }
Returns the ID of an observer with public = 1 and with similar request and params .
10,254
private function _get_id_from_user ( string $ request , $ params ) : ? string { if ( $ this -> id_user && $ this -> check ( ) ) { $ sql = ' SELECT `o`.`id` FROM bbn_observers AS `o` LEFT JOIN bbn_observers AS `ro` ON `o`.`id_alias` = `ro`.`id` WHERE `o`.`id_user` = ? AND ( ( `o`.`request` LIKE ? AND `o`.`params` ' . ( $ params ? 'LIKE ?' : 'IS NULL' ) . ' ) OR ( `ro`.`request` LIKE ? AND `ro`.`params` ' . ( $ params ? 'LIKE ?' : 'IS NULL' ) . ' ) )' ; $ args = [ hex2bin ( $ this -> id_user ) , $ request , $ request ] ; if ( $ params ) { array_splice ( $ args , 2 , 0 , $ params ) ; array_push ( $ args , $ params ) ; } return $ this -> db -> get_one ( $ sql , $ args ) ; } return null ; }
Returns the ID of an observer for the current user and with similar request and params .
10,255
private function _update_next ( $ id ) : bool { $ id_alias = $ this -> db -> select_one ( 'bbn_observers' , 'id_alias' , [ 'id' => $ id ] ) ; return $ this -> db -> query ( <<<MYSQL UPDATE bbn_observers SET next = NOW() + INTERVAL frequency SECOND WHERE id = ?MYSQL , hex2bin ( $ id_alias ? : $ id ) ) ? true : false ; }
Sets the time of next execution in the observer s main row .
10,256
public function check_result ( $ id ) { if ( $ d = $ this -> get ( $ id ) ) { $ t = new bbn \ util \ timer ( ) ; $ t -> start ( ) ; $ res = $ this -> _exec ( $ d [ 'request' ] , $ d [ 'params' ] ) ; $ duration = ( int ) ceil ( $ t -> stop ( ) * 1000 ) ; if ( $ res !== $ d [ 'result' ] ) { $ this -> db -> update ( 'bbn_observers' , [ 'result' => $ res , 'duration' => $ duration ] , [ 'id' => $ id ] ) ; return false ; } return true ; } }
Confronts the current result with the one kept in database .
10,257
public function add ( array $ cfg ) : ? string { if ( $ this -> id_user && ( null !== $ cfg [ 'request' ] ) && $ this -> check ( ) ) { $ t = new bbn \ util \ timer ( ) ; $ t -> start ( ) ; if ( is_string ( $ cfg [ 'request' ] ) ) { $ params = self :: sanitize_params ( $ cfg [ 'params' ] ?? [ ] ) ; $ request = trim ( $ cfg [ 'request' ] ) ; } else if ( is_array ( $ cfg [ 'request' ] ) ) { $ params = null ; $ request = $ cfg [ 'request' ] ; } else { return null ; } $ res = $ this -> _exec ( $ request , $ params ) ; $ duration = ( int ) ceil ( $ t -> stop ( ) * 1000 ) ; if ( is_array ( $ request ) ) { $ request = json_encode ( $ request ) ; } $ id_alias = $ this -> _get_id ( $ request , $ params ) ; if ( ! $ id_alias && ! empty ( $ cfg [ 'public' ] ) && $ this -> db -> insert ( 'bbn_observers' , [ 'request' => $ request , 'params' => $ params ? : null , 'name' => $ cfg [ 'name' ] ?? null , 'duration' => $ duration , 'id_user' => null , 'public' => 1 , 'result' => $ res ] ) ) { $ id_alias = $ this -> db -> last_id ( ) ; } if ( $ id_obs = $ this -> _get_id_from_user ( $ request , $ params ) ) { $ this -> check_result ( $ id_obs ) ; return $ id_obs ; } else if ( $ id_alias ) { if ( $ this -> db -> insert ( 'bbn_observers' , [ 'id_user' => $ this -> id_user , 'public' => 0 , 'id_alias' => $ id_alias , 'next' => null , 'result' => $ res ] ) ) { return $ this -> db -> last_id ( ) ; } } else { if ( $ this -> db -> insert ( 'bbn_observers' , [ 'request' => $ request , 'params' => $ params ? : null , 'name' => $ cfg [ 'name' ] ?? null , 'duration' => $ duration , 'id_user' => $ this -> id_user , 'public' => 0 , 'result' => $ res ] ) ) { return $ this -> db -> last_id ( ) ; } } } return null ; }
Adds a new observer and returns its id or the id of an existing one .
10,258
public function user_delete ( $ id ) : int { if ( property_exists ( $ this , 'user' ) && $ this -> check ( ) ) { return $ this -> db -> delete ( 'bbn_observers' , [ 'id' => $ id , 'id_user' => $ this -> user ] ) ; } return 0 ; }
Deletes the given observer for the current user
10,259
protected function applyFormats ( $ data ) { if ( $ this -> getOptions ( ) -> getOutputFormatters ( ) ) { foreach ( $ this -> getOptions ( ) -> getOutputFormatters ( ) as $ formatter ) { if ( $ formatter instanceof FormatterInterface ) { $ data = $ formatter -> format ( $ data ) ; } elseif ( is_callable ( $ formatter ) ) { $ data = $ formatter ( $ data , $ this -> serviceManager ) ; } } } return $ data ; }
Apply formatter using the formatters in the order they were defined
10,260
public function redirectToRoute ( $ route , array $ parameters = [ ] , $ status = 302 ) { return new RedirectResponse ( $ this [ 'url_generator' ] -> generate ( $ route , $ parameters ) , $ status ) ; }
Redirects the user to route with the given parameters .
10,261
public function forward ( $ uri , $ method , array $ parameters = [ ] ) { $ request = Request :: create ( $ uri , $ method , $ parameters ) ; return $ this -> handle ( $ request , HttpKernelInterface :: SUB_REQUEST ) ; }
Forward the request to another controller by the URI .
10,262
public function forwardToRoute ( $ route , $ method , array $ parameters = [ ] ) { return $ this -> forward ( $ this [ 'url_generator' ] -> generate ( $ route , $ parameters ) , $ method ) ; }
Forward the request to another controller by the route name .
10,263
private function fixControlStructure ( Tokens $ tokens , $ index ) { if ( ! $ tokens [ $ index - 1 ] -> isWhitespace ( ) || $ tokens [ $ index - 1 ] -> isWhitespace ( $ this -> singleLineWhitespaceOptions ) ) { $ tokens -> ensureWhitespaceAtIndex ( $ index - 1 , 1 , ' ' ) ; } }
Fixes whitespaces around braces of a control structure .
10,264
private function getControlStructureTokens ( ) { static $ tokens = null ; if ( null === $ tokens ) { $ tokens = [ T_IF , T_ELSEIF , T_FOR , T_FOREACH , T_WHILE , T_DO , T_CATCH , T_SWITCH , T_DECLARE , ] ; } return $ tokens ; }
Gets the name of control structure tokens .
10,265
public function addTab ( $ tabId , $ tab ) { parent :: addTab ( $ tabId , $ tab ) ; if ( $ this -> _tabs [ $ tabId ] instanceof Mage_Core_Block_Abstract && $ this -> _tabs [ $ tabId ] -> getParentBlock ( ) === null ) { $ this -> append ( $ this -> _tabs [ $ tabId ] ) ; } return $ this ; }
Add new tab
10,266
public function buildSourceTableMigration ( $ name ) { $ path = $ this -> getMigrationPath ( $ name ) ; $ migration = $ this -> getTableMigrationName ( $ name ) ; $ contents = view ( '_hierarchy::migrations.table' , [ 'table' => source_table_name ( $ name ) , 'migration' => $ migration ] ) -> render ( ) ; $ this -> write ( $ path , $ contents ) ; return $ this -> getMigrationClassPath ( $ migration ) ; }
Builds a source table migration
10,267
public function destroySourceTableMigration ( $ name , array $ fields ) { $ path = $ this -> getMigrationPath ( $ name ) ; $ this -> delete ( $ path ) ; foreach ( $ fields as $ field ) { $ this -> destroyFieldMigrationForTable ( $ field , $ name ) ; } }
Destroy a source table migration
10,268
public function buildFieldMigrationForTable ( $ name , $ type , $ indexed , $ tableName ) { $ path = $ this -> getMigrationPath ( $ tableName , $ name ) ; $ migration = $ this -> getTableFieldMigrationName ( $ name , $ tableName ) ; $ contents = view ( '_hierarchy::migrations.field' , [ 'field' => $ name , 'table' => source_table_name ( $ tableName ) , 'migration' => $ migration , 'type' => $ this -> getColumnType ( $ type ) , 'indexed' => $ indexed ] ) -> render ( ) ; $ this -> write ( $ path , $ contents ) ; return $ this -> getMigrationClassPath ( $ migration ) ; }
Builds a field migration for a table
10,269
public function destroyFieldMigrationForTable ( $ name , $ tableName ) { $ path = $ this -> getMigrationPath ( $ tableName , $ name ) ; $ this -> delete ( $ path ) ; }
Destroys a field migration for a table
10,270
public function getTableFieldMigrationName ( $ name , $ tableName ) { return sprintf ( MigrationBuilder :: PATTERN_FIELD , ucfirst ( $ name ) , ucfirst ( $ tableName ) ) ; }
Returns the migration name for a field in table
10,271
public function getMigrationPath ( $ table , $ field = null ) { $ name = is_null ( $ field ) ? $ this -> getTableMigrationName ( $ table ) : $ this -> getTableFieldMigrationName ( $ field , $ table ) ; return sprintf ( $ this -> getBasePath ( ) . '/%s.php' , $ name ) ; }
Returns the path for the migration
10,272
public function getMigrationClassPathByKey ( $ table , $ field = null ) { $ name = is_null ( $ field ) ? $ this -> getTableMigrationName ( $ table ) : $ this -> getTableFieldMigrationName ( $ field , $ table ) ; return $ this -> getMigrationClassPath ( $ name ) ; }
Returns the migration class path by key
10,273
public function getColumnType ( $ type ) { if ( array_key_exists ( $ type , $ this -> typeMap ) ) { return $ this -> typeMap [ $ type ] ; } return $ this -> defaultType ; }
Returns the column type for key
10,274
public function addPrefix ( $ prefix , $ paths ) { if ( ! $ prefix ) { foreach ( ( array ) $ paths as $ path ) { $ this -> fallbackDirs [ ] = $ path ; } return ; } if ( isset ( $ this -> prefixes [ $ prefix ] ) ) { $ this -> prefixes [ $ prefix ] = array_merge ( $ this -> prefixes [ $ prefix ] , ( array ) $ paths ) ; } else { $ this -> prefixes [ $ prefix ] = ( array ) $ paths ; } }
Registers a set of classes
10,275
public function findPackages ( $ name , $ version ) { $ packages = array ( ) ; foreach ( $ this -> repositories as $ repository ) { $ packages = array_merge ( $ packages , $ repository -> findPackages ( $ name , $ version ) ) ; } return $ packages ; }
Searches for all packages matching a name and optionally a version in managed repositories .
10,276
public function createRepository ( $ type , $ config ) { if ( ! isset ( $ this -> repositoryClasses [ $ type ] ) ) { throw new \ InvalidArgumentException ( 'Repository type is not registered: ' . $ type ) ; } $ class = $ this -> repositoryClasses [ $ type ] ; return new $ class ( $ config , $ this -> io , $ this -> config , $ this -> eventDispatcher ) ; }
Returns a new repository for a specific installation type .
10,277
public function actionIndex ( ) { $ searchModel = Yii :: createObject ( AuthenticationSearch :: className ( ) ) ; $ dataProvider = $ searchModel -> search ( Yii :: $ app -> request -> get ( ) ) ; return $ this -> render ( 'index' , [ 'searchModel' => $ searchModel , 'dataProvider' => $ dataProvider , ] ) ; }
Lists all Authentication models .
10,278
public function resolve ( $ toResolve ) { if ( \ is_callable ( $ toResolve ) ) { return $ toResolve ; } if ( ! \ is_string ( $ toResolve ) ) { $ this -> assertCallable ( $ toResolve ) ; } if ( preg_match ( self :: CALLABLE_PATTERN , $ toResolve , $ matches ) ) { $ resolved = $ this -> resolveCallable ( $ matches [ 1 ] , $ matches [ 2 ] ) ; $ this -> assertCallable ( $ resolved ) ; return $ resolved ; } $ resolved = $ this -> resolveCallable ( $ toResolve ) ; $ this -> assertCallable ( $ resolved ) ; return $ resolved ; }
Resolve toResolve into a closure that that the router can dispatch .
10,279
protected function respondTransformer ( $ data , $ code , TransformerAbstract $ transformer , array $ headers = [ ] ) { if ( $ data === null ) { return $ this -> respond ( [ 'data' => [ ] ] , $ code , $ headers ) ; } if ( $ data instanceof LengthAwarePaginator ) { $ resource = new Collection ( $ data -> items ( ) , $ transformer ) ; return $ this -> respond ( [ 'meta' => [ 'total' => $ data -> total ( ) , 'perPage' => $ data -> perPage ( ) , 'currentPage' => $ data -> currentPage ( ) , 'lastPage' => $ data -> lastPage ( ) , 'link' => \ URL :: current ( ) ] , 'params' => $ this -> processor -> getProcessedFields ( ) , 'data' => $ this -> getSerializer ( ) -> createData ( $ resource ) -> toArray ( ) ] , $ code , $ headers ) ; } elseif ( $ data instanceof LaravelCollection ) { $ resource = new Collection ( $ data , $ transformer ) ; return $ this -> respond ( [ 'data' => $ this -> getSerializer ( ) -> createData ( $ resource ) -> toArray ( ) ] , $ code , $ headers ) ; } else { $ resource = new Item ( $ data , $ transformer ) ; return $ this -> respond ( $ this -> getSerializer ( ) -> createData ( $ resource ) -> toArray ( ) , $ code , $ headers ) ; } }
Return transformed response in json format
10,280
protected function respondWithSuccess ( $ data , TransformerAbstract $ transformer = null , array $ headers = [ ] ) { if ( $ transformer ) { return $ this -> respondTransformer ( $ data , SymfonyResponse :: HTTP_OK , $ transformer , $ headers ) ; } return $ this -> respondWithSimpleSuccess ( $ data ) ; }
Return success response in json format
10,281
protected function respondWithError ( $ message = 'Bad Request' , $ code = SymfonyResponse :: HTTP_BAD_REQUEST , array $ headers = [ ] ) { return abort ( $ code , $ message , $ headers ) ; }
Return server error response in json format
10,282
final protected function next ( ServerRequestInterface $ request , RequestHandlerInterface $ handler ) : ResponseInterface { if ( $ this -> _next ) { return $ this -> _next -> process ( $ request , $ handler ) ; } return $ handler -> handle ( $ request ) ; }
Pass request to the next middleware . If there are no next middleware it will pass the request to the handler
10,283
public function parse ( $ currentRoute , $ permit ) { $ route = $ permit [ 'route' ] ; $ count = count ( $ route ) ; if ( $ count == 0 ) { return false ; } foreach ( $ route as $ key => $ value ) { if ( isset ( $ currentRoute [ $ key ] ) ) { $ values = ( is_array ( $ value ) ) ? $ value : array ( $ value ) ; foreach ( $ values as $ k => $ v ) { if ( $ currentRoute [ $ key ] == $ v ) { $ count -- ; } } } } return $ count == 0 ; }
Parses the passed route against a rule
10,284
public function execute ( $ route , $ title , $ url = null , $ options = array ( ) , $ confirmMessage = false ) { if ( empty ( $ route [ 'rules' ] ) ) { return $ this -> Html -> link ( $ title , $ url , $ options , $ confirmMessage ) ; } if ( isset ( $ route [ 'rules' ] [ 'deny' ] ) ) { return ( $ route [ 'rules' ] [ 'deny' ] == true ) ? null : $ this -> Html -> link ( $ title , $ url , $ options , $ confirmMessage ) ; } if ( ! isset ( $ route [ 'rules' ] [ 'auth' ] ) ) { return $ this -> Html -> link ( $ title , $ url , $ options , $ confirmMessage ) ; } if ( is_bool ( $ route [ 'rules' ] [ 'auth' ] ) ) { $ isAuthed = $ this -> Session -> read ( "{$this->settings['path']}.{$this->settings['check']}" ) ; if ( $ route [ 'rules' ] [ 'auth' ] == true && ! $ isAuthed ) { return ; } if ( $ route [ 'rules' ] [ 'auth' ] == false && $ isAuthed ) { return ; } return $ this -> Html -> link ( $ title , $ url , $ options , $ confirmMessage ) ; } $ count = count ( $ route [ 'rules' ] [ 'auth' ] ) ; if ( $ count == 0 ) { return $ this -> Html -> link ( $ title , $ url , $ options , $ confirmMessage ) ; } if ( ( $ user = $ this -> Session -> read ( "{$this->settings['path']}" ) ) == false ) { return ; } foreach ( $ route [ 'rules' ] [ 'auth' ] as $ field => $ value ) { if ( strpos ( $ field , '.' ) !== false ) { $ field = '/' . str_replace ( '.' , '/' , $ field ) ; } if ( $ field [ 0 ] == "/" ) { $ values = ( array ) Set :: extract ( $ field , $ user ) ; foreach ( $ value as $ condition ) { if ( in_array ( $ condition , $ values ) ) { $ count -- ; } } } else { if ( $ user [ $ field ] == $ value ) { $ count -- ; } } } return ( $ count != 0 ) ? null : $ this -> Html -> link ( $ title , $ url , $ options , $ confirmMessage ) ; }
Executes the route based on it s rules
10,285
public function store ( $ id , $ data , $ attributes = array ( ) ) { $ metaStorage = $ this -> getMetaDataStorage ( ) ; $ metaStorage -> lock ( ) ; $ metaData = $ this -> getMetaData ( $ metaStorage ) ; foreach ( $ this -> storageStack as $ storageConf ) { call_user_func ( array ( $ this -> properties [ 'options' ] -> replacementStrategy , 'store' ) , $ storageConf , $ metaData , $ id , $ data , $ attributes ) ; } $ metaStorage -> storeMetaData ( $ metaData ) ; $ metaStorage -> unlock ( ) ; }
Stores data in the cache stack .
10,286
private function getMetaData ( ezcCacheStackMetaDataStorage $ metaStorage ) { $ metaData = $ metaStorage -> restoreMetaData ( ) ; if ( $ metaData === null ) { $ metaData = call_user_func ( array ( $ this -> properties [ 'options' ] -> replacementStrategy , 'createMetaData' ) ) ; } return $ metaData ; }
Returns the meta data to use .
10,287
public function restore ( $ id , $ attributes = array ( ) , $ search = false ) { $ metaStorage = $ this -> getMetaDataStorage ( ) ; $ metaStorage -> lock ( ) ; $ metaData = $ this -> getMetaData ( $ metaStorage ) ; $ item = false ; foreach ( $ this -> storageStack as $ storageConf ) { $ item = call_user_func ( array ( $ this -> properties [ 'options' ] -> replacementStrategy , 'restore' ) , $ storageConf , $ metaData , $ id , $ attributes , $ search ) ; if ( $ item !== false ) { if ( $ this -> properties [ 'options' ] -> bubbleUpOnRestore ) { $ this -> bubbleUp ( $ id , $ attributes , $ item , $ storageConf , $ metaData ) ; } break ; } } $ metaStorage -> storeMetaData ( $ metaData ) ; $ metaStorage -> unlock ( ) ; return $ item ; }
Restores an item from the stack .
10,288
public function delete ( $ id = null , $ attributes = array ( ) , $ search = false ) { $ metaStorage = $ this -> getMetaDataStorage ( ) ; $ metaStorage -> lock ( ) ; $ metaData = $ metaStorage -> restoreMetaData ( ) ; $ deletedIds = array ( ) ; foreach ( $ this -> storageStack as $ storageConf ) { $ deletedIds = array_merge ( $ deletedIds , call_user_func ( array ( $ this -> properties [ 'options' ] -> replacementStrategy , 'delete' ) , $ storageConf , $ metaData , $ id , $ attributes , $ search ) ) ; } $ metaStorage -> storeMetaData ( $ metaData ) ; $ metaStorage -> unlock ( ) ; return array_unique ( $ deletedIds ) ; }
Deletes an item from the stack .
10,289
private function getMetaDataStorage ( ) { $ metaStorage = $ this -> options -> metaStorage ; if ( $ metaStorage === null ) { $ metaStorage = reset ( $ this -> storageStack ) -> storage ; if ( ! ( $ metaStorage instanceof ezcCacheStackMetaDataStorage ) ) { throw new ezcBaseValueException ( 'metaStorage' , $ metaStorage , 'ezcCacheStackMetaDataStorage' , 'top of storage stack' ) ; } } return $ metaStorage ; }
Returns the meta data storage to be used .
10,290
public function countDataItems ( $ id = null , $ attributes = array ( ) ) { $ sum = 0 ; foreach ( $ this -> storageStack as $ storageConf ) { $ sum += $ storageConf -> storage -> countDataItems ( $ id , $ attributes ) ; } return $ sum ; }
Counts how many items are stored fulfilling certain criteria .
10,291
public function getRemainingLifetime ( $ id , $ attributes = array ( ) ) { foreach ( $ this -> storageStack as $ storageConf ) { $ lifetime = $ storageConf -> storage -> getRemainingLifetime ( $ id , $ attributes ) ; if ( $ lifetime > 0 ) { return $ lifetime ; } } return 0 ; }
Returns the remaining lifetime for the given item ID .
10,292
public function pushStorage ( ezcCacheStackStorageConfiguration $ storageConf ) { if ( isset ( $ this -> storageIdMap [ $ storageConf -> id ] ) ) { throw new ezcCacheStackIdAlreadyUsedException ( $ storageConf -> id ) ; } if ( in_array ( $ storageConf -> storage , $ this -> storageIdMap , true ) ) { throw new ezcCacheStackStorageUsedTwiceException ( $ storageConf -> storage ) ; } array_unshift ( $ this -> storageStack , $ storageConf ) ; $ this -> storageIdMap [ $ storageConf -> id ] = $ storageConf -> storage ; }
Add a storage to the top of the stack .
10,293
public function popStorage ( ) { if ( count ( $ this -> storageStack ) === 0 ) { throw new ezcCacheStackUnderflowException ( ) ; } $ storageConf = array_shift ( $ this -> storageStack ) ; unset ( $ this -> storageIdMap [ $ storageConf -> id ] ) ; return $ storageConf ; }
Removes a storage from the top of the stack .
10,294
public function create_request ( $ par_array ) { $ request = $ this -> addChild ( $ this -> doc -> documentElement , "request" , $ this -> request_url ( ) ) ; foreach ( $ par_array as $ key => $ value ) { $ request -> setAttribute ( $ key , $ value ) ; } }
Create an OAI request node .
10,295
public function create_resumpToken ( $ token , $ expirationdatetime , $ num_rows , $ cursor = null ) { $ resump_node = $ this -> addChild ( $ this -> verbNode , "resumptionToken" , $ token ) ; if ( isset ( $ expirationdatetime ) ) { $ resump_node -> setAttribute ( "expirationDate" , $ expirationdatetime ) ; } $ resump_node -> setAttribute ( "completeListSize" , $ num_rows ) ; $ resump_node -> setAttribute ( "cursor" , $ cursor ) ; }
If there are too many records request could not finished a resumpToken is generated to let harvester know
10,296
public function detectAccessDenied ( MvcEvent $ event ) { $ response = $ event -> getResponse ( ) ; if ( $ response -> getStatusCode ( ) == 403 ) { $ event -> setError ( 'Access Denied' ) ; $ event -> stopPropagation ( true ) ; } }
If response status code is 403 set error state and stop event propagation
10,297
public function injectAccessDeniedViewModel ( MvcEvent $ event ) { $ this -> config ( $ event ) ; $ result = $ event -> getResult ( ) ; if ( $ result instanceof ResponseInterface ) { return ; } $ response = $ event -> getResponse ( ) ; if ( $ response -> getStatusCode ( ) != 403 ) { return ; } $ model = new ViewModel ( ) ; $ model -> setTemplate ( $ this -> template ) ; if ( $ this -> renderLayout == true ) { $ layout = $ event -> getViewModel ( ) ; $ layout -> addChild ( $ model ) ; } else { $ model -> setTerminal ( true ) ; $ event -> setViewModel ( $ model ) ; } }
Inject access denied View Model is response status is 403
10,298
protected function config ( MvcEvent $ event ) { $ appConfig = $ event -> getApplication ( ) -> getServiceManager ( ) -> get ( 'config' ) ; $ config = array_key_exists ( self :: CONFIG_KEY , $ appConfig ) ? $ appConfig [ self :: CONFIG_KEY ] : array ( ) ; if ( array_key_exists ( 'template' , $ config ) ) { $ this -> setTemplate ( $ config [ 'template' ] ) ; } if ( array_key_exists ( 'renderLayout' , $ config ) ) { $ this -> setRenderLayout ( $ config [ 'renderLayout' ] ) ; } }
Set configuration options from application configuration
10,299
public static function keyValue ( $ list , $ keyProperty = null , $ valueProperty = null ) { $ index = array ( ) ; foreach ( $ list as $ i ) { if ( $ keyProperty ) { if ( ! $ valueProperty ) { throw new \ InvalidArgumentException ( "Must set value property if setting key property" ) ; } $ index [ $ i -> $ keyProperty ] = $ i -> $ valueProperty ; } else { $ key = current ( $ i ) ; next ( $ i ) ; $ value = current ( $ i ) ; $ index [ $ key ] = $ value ; } } return $ index ; }
Create a one - dimensional associative array from a list of objects or a list of 2 - tuples .