idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
22,600 | public function findTable ( $ id = null , array $ relations = array ( ) ) { return new Accessor \ Table \ TableAccessor ( $ id , $ relations , $ this -> con ) ; } | Find table element . |
22,601 | public function store ( Request $ request , Installer $ processor ) { return $ processor -> store ( $ this , $ request -> all ( ) ) ; } | Create an adminstrator . |
22,602 | public static function fromEndpoint ( Endpoint $ endpoint ) { return static :: generateKey ( strtolower ( $ endpoint -> getRegion ( ) -> getDomain ( ) ) . $ endpoint -> getUrl ( ) ) ; } | Generate cache key from an Endpoint . |
22,603 | public function addLuceneIndexAction ( ) { $ moduleName = $ this -> params ( ) -> fromRoute ( 'moduleName' , null ) ; $ pageId = $ this -> params ( ) -> fromRoute ( 'pageid' , null ) ; $ excludes = $ this -> params ( ) -> fromRoute ( 'expageid' , null ) ; $ status = '' ; $ searchIndex = $ this -> getServiceLocator ( ) -> get ( 'MelisSearch' ) ; if ( $ moduleName && $ pageId ) { $ tmpexPageIds = explode ( ';' , $ excludes ) ; $ exPageIds = [ ] ; foreach ( $ tmpexPageIds as $ id ) { if ( $ id ) { $ exPageIds [ ] = $ id ; } } $ moduleDirectory = null ; if ( is_dir ( $ _SERVER [ 'DOCUMENT_ROOT' ] . self :: MELIS_SITES . $ moduleName ) ) { $ moduleDirectory = $ _SERVER [ 'DOCUMENT_ROOT' ] . self :: MELIS_SITES ; } elseif ( is_dir ( $ _SERVER [ 'DOCUMENT_ROOT' ] . self :: VENDOR . $ moduleName ) ) { $ moduleDirectory = $ _SERVER [ 'DOCUMENT_ROOT' ] . self :: VENDOR ; } $ status = $ searchIndex -> createIndex ( $ moduleName , $ pageId , $ exPageIds , $ moduleDirectory ) ; } $ view = new ViewModel ( ) ; $ view -> setTerminal ( true ) ; $ view -> status = $ status ; return $ view ; } | This creates lists of index with the content of every page ID that has been crawled by this function . |
22,604 | public function getValue ( $ name ) { return ( isset ( $ this -> options [ 'params' ] [ $ name ] ) ) ? $ this -> options [ 'params' ] [ $ name ] : null ; } | Get filter field value |
22,605 | public function run ( $ query ) { $ options = $ this -> options ; if ( $ this -> hasActiveFilters ( ) ) { foreach ( $ options [ 'params' ] as $ param => $ value ) { $ query -> where ( function ( $ query ) use ( $ options , $ param , $ value ) { $ options [ 'filters' ] [ $ param ] ( $ query , $ value ) ; } ) ; } } $ this -> options [ 'params' ] = $ options [ 'params' ] ; if ( $ options [ 'save' ] ) { $ _SESSION [ $ options [ 'save' ] ] = $ options [ 'params' ] ; } return $ query ; } | Apply filter on query |
22,606 | public function start ( ) : int { $ pathToServerScript = $ this -> config [ 'server_path' ] ; if ( ! file_exists ( $ pathToServerScript ) ) { throw new ControlException ( 'Server script not found. Check server_path in your config file.' ) ; } $ serverPid = $ this -> getServerPid ( ) ; if ( $ serverPid !== 0 ) { return $ serverPid ; } $ phpPath = $ this -> config [ 'php_path' ] ; $ startupCommand = escapeshellcmd ( $ phpPath . ' ' . $ pathToServerScript ) . ' > /dev/null 2>&1 &' ; exec ( $ startupCommand ) ; $ pid = $ this -> getServerPid ( ) ; if ( empty ( $ pid ) ) { throw new ControlException ( 'Could not start server. (Empty Pid)' ) ; } return $ pid ; } | Starts Server instance as a background process . |
22,607 | public function stop ( ) : bool { $ serverPid = $ this -> getServerPid ( ) ; if ( $ serverPid === 0 ) { return true ; } $ response = $ this -> sendCommand ( 'stop' ) ; if ( $ response !== 'ok' ) { throw new ControlException ( 'Shutdown failed.' ) ; } return true ; } | Sends shutdown command to Angela instance . |
22,608 | public function restart ( ) : int { $ pid = $ this -> getServerPid ( ) ; if ( empty ( $ pid ) ) { return $ this -> start ( ) ; } $ stopped = $ this -> stop ( ) ; if ( $ stopped !== true ) { throw new ControlException ( 'Error while stopping current Angela process.' ) ; } return $ this -> start ( ) ; } | Restarts Angela processes . |
22,609 | public function status ( ) : array { $ serverPid = $ this -> getServerPid ( ) ; if ( empty ( $ serverPid ) ) { throw new ControlException ( 'Angela not currently running.' ) ; } $ response = $ this -> sendCommand ( 'status' ) ; if ( empty ( $ response ) ) { throw new ControlException ( 'Error fetching status. (Incorrect response)' ) ; } return json_decode ( $ response , true ) ; } | Checks worker status of Angela instance . |
22,610 | public function flushQueue ( ) : bool { $ serverPid = $ this -> getServerPid ( ) ; if ( empty ( $ serverPid ) ) { throw new ControlException ( 'Angela not currently running.' ) ; } $ response = $ this -> sendCommand ( 'flush_queue' ) ; if ( $ response !== 'ok' ) { throw new ControlException ( 'Error flushing queue. (Incorrect response)' ) ; } return true ; } | Flushes all job queue in server instance . |
22,611 | public function kill ( ) : bool { $ serverPid = $ this -> getServerPid ( ) ; if ( ! empty ( $ serverPid ) ) { $ this -> killProcessById ( $ serverPid ) ; } $ workerPids = [ ] ; foreach ( $ this -> config [ 'pool' ] as $ poolName => $ poolConfig ) { $ pids = $ this -> getPidsByPath ( $ poolConfig [ 'worker_file' ] ) ; if ( empty ( $ pids ) ) { continue ; } $ workerPids = array_merge ( $ workerPids , $ pids ) ; } if ( empty ( $ workerPids ) ) { return true ; } foreach ( $ workerPids as $ pid ) { $ this -> killProcessById ( $ pid ) ; } return true ; } | Tries to kill all Angela related processes . |
22,612 | protected function getPidByPath ( string $ path ) : int { $ procInfo = [ ] ; $ cliOutput = [ ] ; exec ( 'ps x | grep ' . $ path , $ cliOutput ) ; foreach ( $ cliOutput as $ line ) { $ line = trim ( $ line ) ; if ( empty ( $ line ) ) { continue ; } if ( strpos ( $ line , 'grep' ) !== false ) { continue ; } $ procInfo = preg_split ( '#\s+#' , $ line ) ; break ; } if ( empty ( $ procInfo ) ) { return 0 ; } return ( int ) $ procInfo [ 0 ] ; } | Tries to estimate PID by given path . |
22,613 | protected function getPidsByPath ( string $ path ) : array { $ pids = [ ] ; $ cliOutput = [ ] ; exec ( 'ps x | grep ' . $ path , $ cliOutput ) ; foreach ( $ cliOutput as $ line ) { $ line = trim ( $ line ) ; if ( empty ( $ line ) ) { continue ; } if ( strpos ( $ line , 'grep' ) !== false ) { continue ; } $ procInfo = preg_split ( '#\s+#' , $ line ) ; array_push ( $ pids , ( int ) $ procInfo [ 0 ] ) ; } return $ pids ; } | Tries to estimate all PIDs by given path . |
22,614 | protected function sendCommand ( string $ command ) : string { try { $ client = new Client ; $ client -> addServer ( $ this -> config [ 'sockets' ] [ 'client' ] ) ; $ response = $ client -> sendCommand ( $ command ) ; $ client -> close ( ) ; return $ response ; } catch ( ClientException $ e ) { return 'error' ; } } | Sends a control command to Angela main process using socket connection . |
22,615 | protected function checkType ( $ value , $ type , $ nullable = false ) { if ( gettype ( $ value ) === $ type ) { return true ; } return $ nullable && null === $ value ; } | Check if a value is in the specified type . |
22,616 | public function validateArgument ( $ argname , $ value , $ type , $ nullable = false ) { if ( ! $ this -> checkType ( $ value , $ type , $ nullable ) ) { throw new OperationArgumentException ( sprintf ( 'Method %s() expects $%s to be %s, %s given.' , $ this -> operation , $ argname , $ type , gettype ( $ value ) ) ) ; } } | Validate an argument . |
22,617 | public function validateArrayArgument ( $ argname , array $ value , $ type , $ nullable = false ) { foreach ( $ value as $ element ) { if ( ! $ this -> checkType ( $ element , $ type , $ nullable ) ) { throw new OperationArgumentException ( sprintf ( 'Method %s() expects all of $%s elements to be %s, found %s.' , $ this -> operation , $ argname , $ type , gettype ( $ element ) ) ) ; } } } | Validate elements in an argument in the type of array . |
22,618 | public function & get ( $ argname ) { if ( $ this -> has ( $ argname ) ) { return $ this -> values [ $ argname ] ; } throw new OutOfRangeException ( sprintf ( 'Argument %s does not exist.' , $ argname ) ) ; } | Get reference of an argument . |
22,619 | public function setValue ( & $ value ) { if ( 'append' == $ this -> operation ) { $ this -> validateArgument ( 'value' , $ value , 'string' ) ; } return $ this -> set ( 'value' , $ value ) ; } | Set the reference of the argument value . |
22,620 | protected function createNewToken ( CanResetPassword $ user ) { $ email = $ user -> getEmailForPasswordReset ( ) ; $ value = str_shuffle ( sha1 ( $ email . spl_object_hash ( $ this ) . microtime ( true ) ) ) ; return hash_hmac ( 'sha1' , $ value , $ this -> hashKey ) ; } | Create a new token for the user . |
22,621 | public function deleteExpired ( ) { $ expired = Carbon :: now ( ) -> subSeconds ( $ this -> expires ) ; $ this -> makeDelete ( ) -> where ( 'o.createdAt < :expired' ) -> setParameter ( 'expired' , $ expired ) -> getQuery ( ) -> execute ( ) ; } | Delete expired reminders . |
22,622 | public function cell ( $ cell , array $ data = [ ] , array $ options = [ ] ) { $ parts = explode ( '::' , $ cell ) ; if ( count ( $ parts ) === 2 ) { list ( $ cell , $ action ) = [ $ parts [ 0 ] , $ parts [ 1 ] ] ; } else { list ( $ cell , $ action ) = [ $ parts [ 0 ] , 'display' ] ; } $ className = Application :: className ( $ cell , 'View/' . self :: VIEW_TYPE_CELL ) ; $ class = new $ className ( $ data ) ; return $ class -> { $ action } ( $ options ) ; } | Load a cell |
22,623 | public function element ( $ name , array $ data = [ ] ) { $ view = new View ( ) ; $ view -> type ( self :: VIEW_TYPE_ELEMENT ) ; $ view -> set ( array_merge ( $ this -> viewVars , $ data ) ) ; return $ view -> render ( $ name ) ; } | Load an element |
22,624 | protected function viewContent ( $ type , $ view ) { $ ext = pathinfo ( $ view , PATHINFO_EXTENSION ) ; $ view = ( $ ext === '' ) ? $ view . '.php' : $ view ; foreach ( $ this -> paths as $ path ) { $ path .= $ type . DIRECTORY_SEPARATOR ; if ( $ this -> context ( ) && file_exists ( $ path . trim ( $ this -> context ( ) , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . $ view ) ) { $ viewPath = $ path . trim ( $ this -> context ( ) , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . $ view ; break ; } if ( file_exists ( $ path . $ view ) ) { $ viewPath = $ path . $ view ; break ; } } if ( ! isset ( $ viewPath ) ) { throw new \ RuntimeException ( 'Unable to find the ' . $ view ) ; } ob_start ( ) ; include ( $ viewPath ) ; $ content = ob_get_contents ( ) ; ob_end_clean ( ) ; return $ content ; } | Render a view content |
22,625 | protected function initializeProductMediaGallery ( array $ attr ) { $ value = $ attr [ MemberNames :: VALUE ] ; $ attributeId = $ attr [ MemberNames :: ATTRIBUTE_ID ] ; if ( $ entity = $ this -> loadProductMediaGallery ( $ attributeId , $ value ) ) { return $ this -> mergeEntity ( $ entity , $ attr ) ; } return $ attr ; } | Initialize the product media gallery with the passed attributes and returns an instance . |
22,626 | protected function initializeProductMediaGalleryValueToEntity ( array $ attr ) { $ valueId = $ attr [ MemberNames :: VALUE_ID ] ; $ entityId = $ attr [ MemberNames :: ENTITY_ID ] ; if ( $ this -> loadProductMediaGalleryValueToEntity ( $ valueId , $ entityId ) ) { return ; } return $ attr ; } | Initialize the product media gallery value to entity with the passed attributes and returns an instance . |
22,627 | protected function parseAuthenticationConfiguration ( array $ auth ) : array { $ driver = $ auth [ 'defaults' ] [ 'guard' ] ?? null ; $ guard = $ auth [ 'guards' ] [ $ driver ] ?? [ 'driver' => 'session' , 'provider' => 'users' , ] ; $ provider = $ auth [ 'providers' ] [ $ guard [ 'provider' ] ] ?? [ 'driver' => 'eloquent' , 'model' => User :: class , ] ; return \ compact ( 'guard' , 'provider' ) ; } | Resolve auth configuration . |
22,628 | public function setOptimizeFor ( \ google \ protobuf \ FileOptions \ OptimizeMode $ value = null ) { $ this -> optimize_for = $ value ; } | Set optimize_for value |
22,629 | public function doFilter ( $ text , $ filters ) { $ callbacks = [ 'bbcode' => 'bbcode2html' , 'clickable' => 'makeClickable' , 'shortcode' => 'shortCode' , 'markdown' => 'markdown' , 'nl2br' => 'nl2br' , 'purify' => 'purify' , ] ; if ( is_array ( $ filters ) ) { $ filter = $ filters ; } else { $ filters = strtolower ( $ filters ) ; $ filter = preg_replace ( '/\s/' , '' , explode ( ',' , $ filters ) ) ; } foreach ( $ filter as $ key ) { if ( ! isset ( $ callbacks [ $ key ] ) ) { throw new Exception ( "The filter '$filters' is not a valid filter string due to '$key'." ) ; } $ text = call_user_func_array ( [ $ this , $ callbacks [ $ key ] ] , [ $ text ] ) ; } return $ text ; } | Call each filter . |
22,630 | public function setFilterConfig ( $ filter , $ config ) { if ( ! $ this -> hasFilter ( $ filter ) ) { throw new Exception ( "No such filter '$filter' exists." ) ; } $ this -> config [ $ filter ] = $ config ; } | Set configuration for a certain filter . |
22,631 | public function getFilterConfig ( $ filter ) { if ( ! $ this -> hasFilter ( $ filter ) ) { throw new Exception ( "No such filter '$filter' exists." ) ; } return isset ( $ this -> config [ $ filter ] ) ? $ this -> config [ $ filter ] : [ ] ; } | Get configuration for a certain filter . |
22,632 | private function addToFrontmatter ( $ matter ) { if ( empty ( $ matter ) || ! is_array ( $ matter ) ) { return $ this ; } if ( is_null ( $ this -> current -> frontmatter ) ) { $ this -> current -> frontmatter = [ ] ; } $ this -> current -> frontmatter = array_merge ( $ this -> current -> frontmatter , $ matter ) ; return $ this ; } | Add array items to frontmatter . |
22,633 | public function parse ( $ text , $ filter ) { $ this -> current = new \ stdClass ( ) ; $ this -> current -> frontmatter = [ ] ; $ this -> current -> text = $ text ; foreach ( $ filter as $ key ) { $ this -> parseFactory ( $ key ) ; } $ this -> current -> text = $ this -> getUntilStop ( $ this -> current -> text ) ; return $ this -> current ; } | Call each filter and return array with details of the formatted content . |
22,634 | public function addExcerpt ( $ current ) { list ( $ excerpt , $ hasMore ) = $ this -> getUntilMore ( $ current -> text ) ; $ current -> excerpt = $ excerpt ; $ current -> hasMore = $ hasMore ; } | Add excerpt as short version of text if available . |
22,635 | private function extractFrontMatter ( $ text , $ startToken , $ stopToken ) { $ tokenLength = strlen ( $ startToken ) ; $ start = strpos ( $ text , $ startToken ) ; if ( $ start !== false && $ start !== 0 ) { if ( $ text [ $ start - 1 ] !== "\n" ) { $ start = false ; } } $ frontmatter = null ; if ( $ start !== false ) { $ stop = strpos ( $ text , $ stopToken , $ tokenLength - 1 ) ; if ( $ stop !== false && $ text [ $ stop - 1 ] === "\n" ) { $ length = $ stop - ( $ start + $ tokenLength ) ; $ frontmatter = substr ( $ text , $ start + $ tokenLength , $ length ) ; $ textStart = substr ( $ text , 0 , $ start ) ; $ text = $ textStart . substr ( $ text , $ stop + $ tokenLength ) ; } } return [ $ text , $ frontmatter ] ; } | Extract front matter from text . |
22,636 | public function jsonFrontMatter ( $ text ) { list ( $ text , $ frontmatter ) = $ this -> extractFrontMatter ( $ text , "{{{\n" , "}}}\n" ) ; if ( ! empty ( $ frontmatter ) ) { $ frontmatter = json_decode ( $ frontmatter , true ) ; if ( is_null ( $ frontmatter ) ) { throw new Exception ( "Failed parsing JSON frontmatter." ) ; } } return [ "text" => $ text , "frontmatter" => $ frontmatter ] ; } | Extract JSON front matter from text . |
22,637 | public function yamlFrontMatter ( $ text ) { list ( $ text , $ frontmatter ) = $ this -> extractFrontMatter ( $ text , "---\n" , "...\n" ) ; if ( ! empty ( $ frontmatter ) ) { $ frontmatter = $ this -> yamlParse ( "---\n$frontmatter...\n" ) ; } return [ "text" => $ text , "frontmatter" => $ frontmatter ] ; } | Extract YAML front matter from text . |
22,638 | public function yamlParse ( $ text ) { if ( function_exists ( "yaml_parse" ) ) { $ parsed = yaml_parse ( $ text ) ; if ( $ parsed === false ) { throw new Exception ( "Failed parsing YAML frontmatter." ) ; } return $ parsed ; } if ( method_exists ( "Symfony\Component\Yaml\Yaml" , "parse" ) ) { $ parsed = \ Symfony \ Component \ Yaml \ Yaml :: parse ( $ text ) ; return $ parsed ; } if ( function_exists ( "spyc_load" ) ) { $ parsed = spyc_load ( $ text ) ; return $ parsed ; } throw new Exception ( "Could not find support for YAML." ) ; } | Extract YAML front matter from text use one of several available implementations of a YAML parser . |
22,639 | public function getTitleFromFirstH1 ( $ text ) { $ matches = [ ] ; $ title = null ; if ( preg_match ( "#<h1.*?>(.*)</h1>#" , $ text , $ matches ) ) { $ title = strip_tags ( $ matches [ 1 ] ) ; } return $ title ; } | Get the title from the first H1 . |
22,640 | public function getTitleFromFirstHeader ( $ text ) { $ matches = [ ] ; $ title = null ; if ( preg_match ( "#<h[1-6].*?>(.*)</h[1-6]>#" , $ text , $ matches ) ) { $ title = strip_tags ( $ matches [ 1 ] ) ; } return $ title ; } | Get the title from the first header . |
22,641 | public function purify ( $ text ) { $ config = \ HTMLPurifier_Config :: createDefault ( ) ; $ config -> set ( "Cache.DefinitionImpl" , null ) ; $ purifier = new \ HTMLPurifier ( $ config ) ; return $ purifier -> purify ( $ text ) ; } | Format text according to HTML Purifier . |
22,642 | public function markdown ( $ text ) { $ text = \ Michelf \ MarkdownExtra :: defaultTransform ( $ text ) ; $ text = \ Michelf \ SmartyPantsTypographer :: defaultTransform ( $ text , "2" ) ; return $ text ; } | Format text according to Markdown syntax . |
22,643 | public function getRelationQuery ( Builder $ query , Builder $ parent , $ columns = [ '*' ] ) { $ query = parent :: getRelationQuery ( $ query , $ parent , $ columns ) ; return $ query -> where ( $ this -> morphType , $ this -> morphClass ) ; } | Get the relationship query . |
22,644 | public function choose ( $ val , $ isMultiple = null ) { $ arguments = array ( json_encode ( $ val ) ) ; if ( null !== $ isMultiple ) { $ arguments [ ] = ( bool ) $ isMultiple ? 'true' : 'false' ; } $ this -> con -> executeStep ( sprintf ( '_sahi._setSelected(%s, %s)' , $ this -> getAccessor ( ) , implode ( ', ' , $ arguments ) ) ) ; } | Choose option in select box . |
22,645 | public function setFile ( $ path ) { $ this -> con -> executeStep ( sprintf ( '_sahi._setFile(%s, %s)' , $ this -> getAccessor ( ) , json_encode ( $ path ) ) ) ; } | Emulate setting filepath in a file input . |
22,646 | public function dragDrop ( AbstractAccessor $ to ) { $ this -> con -> executeStep ( sprintf ( '_sahi._dragDrop(%s, %s)' , $ this -> getAccessor ( ) , $ to -> getAccessor ( ) ) ) ; } | Drag n Drop current element onto another . |
22,647 | public function dragDropXY ( $ x , $ y , $ relative = null ) { $ arguments = array ( $ x , $ y ) ; if ( null !== $ relative ) { $ arguments [ ] = ( bool ) $ relative ? 'true' : 'false' ; } $ this -> con -> executeStep ( sprintf ( '_sahi._dragDropXY(%s, %s)' , $ this -> getAccessor ( ) , implode ( ', ' , $ arguments ) ) ) ; } | Drag n Drop current element into X Y . |
22,648 | public function keyPress ( $ charInfo , $ combo = null ) { $ this -> con -> executeStep ( sprintf ( '_sahi._keyPress(%s, %s)' , $ this -> getAccessor ( ) , $ this -> getKeyArgumentsString ( $ charInfo , $ combo ) ) ) ; } | Simulate keypress event . |
22,649 | public function setValue ( $ val ) { $ this -> con -> executeStep ( sprintf ( '_sahi._setValue(%s, %s)' , $ this -> getAccessor ( ) , json_encode ( $ val ) ) ) ; } | Set text value . |
22,650 | public function getAttr ( $ attr ) { $ attributeValue = $ this -> con -> evaluateJavascript ( sprintf ( '%s.getAttribute(%s)' , $ this -> getAccessor ( ) , json_encode ( $ attr ) ) ) ; if ( $ attributeValue === false ) { return '' ; } return $ attributeValue ; } | Return attribute value . |
22,651 | private function getKeyArgumentsString ( $ charInfo , $ combo ) { $ arguments = json_encode ( $ charInfo ) ; if ( null !== $ combo ) { $ arguments .= ', ' . json_encode ( $ combo ) ; } return $ arguments ; } | Return Key arguments string . |
22,652 | public function setSecret ( $ secret ) { if ( ! $ secret instanceof Seed ) { $ secret = new Seed ( $ secret ) ; } $ this -> secret = $ secret ; return $ this ; } | Set the shared secret |
22,653 | protected static function truncateHash ( $ hash ) { $ offset = ord ( $ hash [ 19 ] ) & 0xf ; $ value = ( ord ( $ hash [ $ offset + 0 ] ) & 0x7f ) << 24 ; $ value |= ( ord ( $ hash [ $ offset + 1 ] ) & 0xff ) << 16 ; $ value |= ( ord ( $ hash [ $ offset + 2 ] ) & 0xff ) << 8 ; $ value |= ( ord ( $ hash [ $ offset + 3 ] ) & 0xff ) ; return $ value ; } | Extract 4 bytes from a hash value |
22,654 | protected static function counterToString ( $ counter ) { $ temp = '' ; while ( $ counter != 0 ) { $ temp .= chr ( $ counter & 0xff ) ; $ counter >>= 8 ; } return substr ( str_pad ( strrev ( $ temp ) , 8 , "\0" , STR_PAD_LEFT ) , 0 , 8 ) ; } | Convert an integer counter into a string of 8 bytes |
22,655 | private function checkBackups ( SymfonyStyle $ io , array $ backups ) { $ plugins = $ this -> getContainer ( ) -> get ( 'plugins' ) ; foreach ( $ backups as $ name => $ backup ) { $ this -> checkBackup ( $ plugins , $ io , $ name , $ backup ) ; } } | Check backup - configuration . |
22,656 | private function checkBackup ( PluginRegistry $ plugins , SymfonyStyle $ io , $ name , array $ backup ) { $ io -> section ( 'Backup: ' . $ name ) ; if ( ! $ plugins -> has ( $ backup [ 'plugin' ] ) ) { $ io -> warning ( sprintf ( 'Plugin "%s" not found' , $ backup [ 'plugin' ] ) ) ; return false ; } $ optionsResolver = new OptionsResolver ( ) ; $ plugins -> getPlugin ( $ backup [ 'plugin' ] ) -> configureOptionsResolver ( $ optionsResolver ) ; try { $ parameter = $ optionsResolver -> resolve ( $ backup [ 'parameter' ] ) ; } catch ( InvalidArgumentException $ e ) { $ io -> warning ( sprintf ( 'Parameter not valid' . PHP_EOL . PHP_EOL . 'Message: "%s"' , $ e -> getMessage ( ) ) ) ; return false ; } $ io -> write ( 'Process: ' ) ; $ process = 'All' ; if ( 0 < count ( $ backup [ 'process' ] ) ) { $ process = '["' . implode ( '", "' , $ backup [ 'process' ] ) . '""]' ; } $ io -> writeln ( $ process ) ; $ io -> write ( 'Parameter:' ) ; $ messages = array_filter ( explode ( "\r\n" , Yaml :: dump ( $ parameter ) ) ) ; $ io -> block ( $ messages , null , null , ' ' ) ; $ io -> writeln ( 'OK' ) ; return true ; } | Check single backup - configuration . |
22,657 | private function getBackups ( ) { $ backups = $ this -> getContainer ( ) -> getParameter ( 'nanbando.backup' ) ; $ preset = [ ] ; if ( $ name = $ this -> getParameter ( 'nanbando.application.name' ) ) { $ presetStore = $ this -> getContainer ( ) -> get ( 'presets' ) ; $ preset = $ presetStore -> getPreset ( $ name , $ this -> getParameter ( 'nanbando.application.version' ) , $ this -> getParameter ( 'nanbando.application.options' ) ) ; } return array_merge ( $ preset , $ backups ) ; } | Returns backup configuration and merge it with preset if exists . |
22,658 | public function getParameter ( $ name , $ default = null ) { if ( ! $ this -> getContainer ( ) -> hasParameter ( $ name ) ) { return $ default ; } return $ this -> getContainer ( ) -> getParameter ( $ name ) ; } | Returns container parameter or default value . |
22,659 | public function attributes ( ? array $ only = null , ? array $ except = null , ? bool $ schemaOnly = false ) { $ names = array_keys ( static :: getTableSchema ( ) -> columns ) ; if ( ! $ schemaOnly ) { $ class = new \ ReflectionClass ( $ this ) ; foreach ( $ class -> getProperties ( \ ReflectionProperty :: IS_PUBLIC ) as $ property ) { if ( ! $ property -> isStatic ( ) ) { $ names [ ] = $ property -> getName ( ) ; } } } $ names = array_unique ( $ names ) ; if ( $ only ) { $ names = array_intersect ( $ only , $ names ) ; } if ( $ except ) { $ names = array_diff ( $ names , $ except ) ; } return $ names ; } | Returns the list of all attribute names of the model . The default implementation will return all column names of the table associated with this AR class . |
22,660 | public static function getPDO ( $ dsn , $ username , $ password , $ settings = [ 'attributes' => [ ] ] ) { if ( ! isset ( self :: $ PDO ) || ( self :: $ PDO !== null ) ) { self :: $ PDO = new self ( $ dsn , $ username , $ password , $ settings ) ; } return self :: $ PDO ; } | Get Instance of PDO Class as Singleton Pattern . |
22,661 | public function result ( $ row = 0 ) { return isset ( $ this -> results [ $ row ] ) ? $ this -> results [ $ row ] : false ; } | Return PDO Query result by index value . |
22,662 | public function error ( $ msg ) { file_put_contents ( $ this -> config [ 'logDir' ] . self :: LOG_FILE , date ( 'Y-m-d h:m:s' ) . ' :: ' . $ msg . "\n" , FILE_APPEND ) ; if ( $ this -> log ) { $ this -> showQuery ( ) ; $ this -> helper ( ) -> errorBox ( $ msg ) ; } throw new \ PDOException ( $ msg ) ; } | Catch Error in txt file . |
22,663 | public function showQuery ( $ logfile = false ) { if ( ! $ logfile ) { echo "<div style='color:#990099; border:1px solid #777; padding:2px; background-color: #E5E5E5;'>" ; echo " Executed Query -> <span style='color:#008000;'> " ; echo $ this -> helper ( ) -> formatSQL ( $ this -> interpolateQuery ( ) ) ; echo '</span></div>' ; } file_put_contents ( $ this -> config [ 'logDir' ] . self :: LOG_FILE , date ( 'Y-m-d h:m:s' ) . ' :: ' . $ this -> interpolateQuery ( ) . "\n" , FILE_APPEND ) ; return $ this ; } | Show executed query on call . |
22,664 | public function getFieldFromArrayKey ( $ array_key ) { $ key_array = explode ( ' ' , $ array_key ) ; return ( count ( $ key_array ) == '2' ) ? $ key_array [ 0 ] : ( ( count ( $ key_array ) > 2 ) ? $ key_array [ 1 ] : $ key_array [ 0 ] ) ; } | Return real table column from array key . |
22,665 | public function insert ( $ table , $ data = [ ] ) { if ( ! empty ( $ table ) ) { if ( count ( $ data ) > 0 && is_array ( $ data ) ) { $ tmp = [ ] ; foreach ( $ data as $ f => $ v ) { $ tmp [ ] = ":s_$f" ; } $ sNameSpaceParam = implode ( ',' , $ tmp ) ; unset ( $ tmp ) ; $ sFields = implode ( ',' , array_keys ( $ data ) ) ; $ this -> sql = "INSERT INTO `$table` ($sFields) VALUES ($sNameSpaceParam);" ; $ this -> STH = $ this -> prepare ( $ this -> sql ) ; $ this -> data = $ data ; $ this -> _bindPdoNameSpace ( $ data ) ; try { if ( $ this -> STH -> execute ( ) ) { $ this -> lastId = $ this -> lastInsertId ( ) ; $ this -> STH -> closeCursor ( ) ; return $ this ; } else { self :: error ( $ this -> STH -> errorInfo ( ) ) ; } } catch ( \ PDOException $ e ) { self :: error ( $ e -> getMessage ( ) . ': ' . __LINE__ ) ; } } else { self :: error ( 'Data not in valid format..' ) ; } } else { self :: error ( 'Table name not found..' ) ; } } | Execute PDO Insert . |
22,666 | public function insertBatch ( $ table , $ data = [ ] , $ safeModeInsert = true ) { $ this -> start ( ) ; if ( ! empty ( $ table ) ) { if ( count ( $ data ) > 0 && is_array ( $ data ) ) { $ tmp = [ ] ; foreach ( $ data [ 0 ] as $ f => $ v ) { $ tmp [ ] = ":s_$f" ; } $ sNameSpaceParam = implode ( ', ' , $ tmp ) ; unset ( $ tmp ) ; $ sFields = implode ( ', ' , array_keys ( $ data [ 0 ] ) ) ; if ( ! $ safeModeInsert ) { $ this -> sql = "INSERT INTO `$table` ($sFields) VALUES " ; foreach ( $ data as $ key => $ value ) { $ this -> sql .= '(' . "'" . implode ( "', '" , array_values ( $ value ) ) . "'" . '), ' ; } $ this -> sql = rtrim ( $ this -> sql , ', ' ) ; $ this -> STH = $ this -> prepare ( $ this -> sql ) ; try { if ( $ this -> STH -> execute ( ) ) { $ this -> allLastId [ ] = $ this -> lastInsertId ( ) ; } else { self :: error ( $ this -> STH -> errorInfo ( ) ) ; } } catch ( \ PDOException $ e ) { self :: error ( $ e -> getMessage ( ) . ': ' . __LINE__ ) ; $ this -> back ( ) ; } $ this -> end ( ) ; $ this -> STH -> closeCursor ( ) ; return $ this ; } $ this -> sql = "INSERT INTO `$table` ($sFields) VALUES ($sNameSpaceParam);" ; $ this -> STH = $ this -> prepare ( $ this -> sql ) ; $ this -> data = $ data ; $ this -> batch = true ; foreach ( $ data as $ key => $ value ) { $ this -> _bindPdoNameSpace ( $ value ) ; try { if ( $ this -> STH -> execute ( ) ) { $ this -> allLastId [ ] = $ this -> lastInsertId ( ) ; } else { self :: error ( $ this -> STH -> errorInfo ( ) ) ; $ this -> back ( ) ; } } catch ( \ PDOException $ e ) { self :: error ( $ e -> getMessage ( ) . ': ' . __LINE__ ) ; $ this -> back ( ) ; } } $ this -> end ( ) ; $ this -> STH -> closeCursor ( ) ; return $ this ; } else { self :: error ( 'Data not in valid format..' ) ; } } else { self :: error ( 'Table name not found..' ) ; } } | Execute PDO Insert as Batch Data . |
22,667 | public function update ( $ table = '' , $ data = [ ] , $ arrayWhere = [ ] , $ other = '' ) { if ( ! empty ( $ table ) ) { if ( count ( $ data ) > 0 && count ( $ arrayWhere ) > 0 ) { $ tmp = [ ] ; foreach ( $ data as $ k => $ v ) { $ tmp [ ] = "$k = :s_$k" ; } $ sFields = implode ( ', ' , $ tmp ) ; unset ( $ tmp ) ; $ tmp = [ ] ; foreach ( $ arrayWhere as $ k => $ v ) { $ tmp [ ] = "$k = :s_$k" ; } $ this -> data = $ data ; $ this -> arrayWhere = $ arrayWhere ; $ where = implode ( ' AND ' , $ tmp ) ; unset ( $ tmp ) ; $ this -> sql = "UPDATE `$table` SET $sFields WHERE $where $other;" ; $ this -> STH = $ this -> prepare ( $ this -> sql ) ; $ this -> _bindPdoNameSpace ( $ data ) ; $ this -> _bindPdoNameSpace ( $ arrayWhere ) ; try { if ( $ this -> STH -> execute ( ) ) { $ this -> affectedRows = $ this -> STH -> rowCount ( ) ; $ this -> STH -> closeCursor ( ) ; return $ this ; } else { self :: error ( $ this -> STH -> errorInfo ( ) ) ; } } catch ( \ PDOException $ e ) { self :: error ( $ e -> getMessage ( ) . ': ' . __LINE__ ) ; } } else { self :: error ( 'update statement not in valid format..' ) ; } } else { self :: error ( 'Table name not found..' ) ; } } | Execute PDO Update Statement Get No OF Affected Rows updated . |
22,668 | public function count ( $ table = '' , $ where = '' ) { if ( ! empty ( $ table ) ) { if ( empty ( $ where ) ) { $ this -> sql = "SELECT COUNT(*) AS NUMROWS FROM `$table`;" ; } else { $ this -> sql = "SELECT COUNT(*) AS NUMROWS FROM `$table` WHERE $where;" ; } $ this -> STH = $ this -> prepare ( $ this -> sql ) ; try { if ( $ this -> STH -> execute ( ) ) { $ this -> results = $ this -> STH -> fetch ( ) ; $ this -> STH -> closeCursor ( ) ; return $ this -> results [ 'NUMROWS' ] ; } else { self :: error ( $ this -> STH -> errorInfo ( ) ) ; } } catch ( \ PDOException $ e ) { self :: error ( $ e -> getMessage ( ) . ': ' . __LINE__ ) ; } } else { self :: error ( 'Table name not found..' ) ; } } | Get Total Number Of Records in Requested Table . |
22,669 | public function truncate ( $ table = '' ) { if ( ! empty ( $ table ) ) { $ this -> sql = "TRUNCATE TABLE `$table`;" ; $ this -> STH = $ this -> prepare ( $ this -> sql ) ; try { if ( $ this -> STH -> execute ( ) ) { $ this -> STH -> closeCursor ( ) ; return true ; } else { self :: error ( $ this -> STH -> errorInfo ( ) ) ; } } catch ( \ PDOException $ e ) { self :: error ( $ e -> getMessage ( ) . ': ' . __LINE__ ) ; } } else { self :: error ( 'Table name not found..' ) ; } } | Truncate a MySQL table . |
22,670 | public function describe ( $ table = '' ) { $ this -> sql = $ sql = "DESC $table;" ; $ this -> STH = $ this -> prepare ( $ sql ) ; $ this -> STH -> execute ( ) ; $ colList = $ this -> STH -> fetchAll ( ) ; $ field = [ ] ; $ type = [ ] ; foreach ( $ colList as $ key ) { $ field [ ] = $ key [ 'Field' ] ; $ type [ ] = $ key [ 'Type' ] ; } return array_combine ( $ field , $ type ) ; } | Return Table Fields of Requested Table . |
22,671 | public function pdoPrepare ( $ statement , $ options = [ ] ) { $ this -> STH = $ this -> prepare ( $ statement , $ options ) ; return $ this ; } | prepare PDO Query . |
22,672 | protected function sortListeners ( $ eventName ) { $ listeners = isset ( $ this -> listeners [ $ eventName ] ) ? $ this -> listeners [ $ eventName ] : [ ] ; if ( class_exists ( $ eventName ) ) { foreach ( class_implements ( $ eventName ) as $ interface ) { if ( isset ( $ this -> listeners [ $ interface ] ) ) { foreach ( $ this -> listeners [ $ interface ] as $ priority => $ names ) { if ( isset ( $ listeners [ $ priority ] ) ) { $ listeners [ $ priority ] = array_merge ( $ listeners [ $ priority ] , $ names ) ; } else { $ listeners [ $ priority ] = $ names ; } } } } } if ( $ listeners ) { krsort ( $ listeners ) ; $ this -> sorted [ $ eventName ] = call_user_func_array ( 'array_merge' , $ listeners ) ; } else { $ this -> sorted [ $ eventName ] = [ ] ; } } | Sort the listeners for a given event by priority . |
22,673 | protected function isReservedButExpired ( $ query ) { $ expiration = Carbon :: now ( ) -> subSeconds ( $ this -> expire ) -> getTimestamp ( ) ; $ query -> orWhere ( function ( $ query ) use ( $ expiration ) { $ query -> where ( 'reserved_at' , '<=' , $ expiration ) ; } ) ; } | Modify the query to check for jobs that are reserved but have expired . |
22,674 | public function flatter ( $ array ) { $ result = [ ] ; foreach ( $ array as $ item ) { if ( is_array ( $ item ) ) { $ result = array_merge ( $ result , $ this -> flatter ( $ item ) ) ; } else { $ result [ ] = $ item ; } } return $ result ; } | Flatter function . |
22,675 | public function checkValidPagesRecursive ( $ siteMenu = array ( ) ) { $ checkedSiteMenu = array ( ) ; foreach ( $ siteMenu as $ key => $ val ) { if ( $ val [ 'menu' ] != 'NONE' ) { if ( $ val [ 'menu' ] == 'NOLINK' ) { $ val [ 'uri' ] = '#' ; } if ( ! empty ( $ val [ 'pages' ] ) ) { $ pages = $ this -> checkValidPagesRecursive ( $ val [ 'pages' ] ) ; if ( ! empty ( $ pages ) ) { $ val [ 'pages' ] = $ pages ; } } $ checkedSiteMenu [ ] = $ val ; } } return $ checkedSiteMenu ; } | This method checks the show menu option of the page |
22,676 | protected function getSetValues ( $ arrCell , $ intId ) { return array ( 'tstamp' => time ( ) , 'value' => ( string ) $ arrCell [ 'value' ] , 'att_id' => $ this -> get ( 'id' ) , 'row' => ( int ) $ arrCell [ 'row' ] , 'col' => ( int ) $ arrCell [ 'col' ] , 'item_id' => $ intId , ) ; } | Calculate the array of query parameters for the given cell . |
22,677 | protected function getAsync ( array $ endpoints , $ params = [ ] ) { $ promises = array_map ( function ( Endpoint $ endpoint ) use ( $ params ) { $ isCached = $ this -> client -> getCache ( ) && $ this -> client -> getCache ( ) -> getItem ( KeyGenerator :: fromEndpoint ( $ endpoint ) ) -> isHit ( ) ; if ( $ endpoint -> countsTowardsLimit ( ) && ! $ isCached ) { try { $ this -> client -> getMethodRateLimiter ( ) -> hit ( $ endpoint ) ; $ this -> client -> getAppRateLimiter ( ) -> hit ( $ endpoint ) ; } catch ( RateLimitReachedException $ e ) { return new RejectedPromise ( $ e ) ; } } return $ this -> client -> getHttpClient ( ) -> sendAsyncRequest ( $ this -> buildRequest ( $ endpoint , $ params ) ) -> then ( function ( ResponseInterface $ response ) use ( $ endpoint ) { return $ response -> withHeader ( 'X-Endpoint' , $ endpoint -> getName ( ) ) -> withHeader ( 'X-Request' , $ endpoint -> getUrl ( ) ) -> withHeader ( 'X-Region' , $ endpoint -> getRegion ( ) -> getName ( ) ) ; } ) ; } , is_array ( $ endpoints ) ? $ endpoints : [ $ endpoints ] ) ; if ( count ( $ promises ) > 1 ) { $ results = \ GuzzleHttp \ Promise \ settle ( $ promises ) -> wait ( ) ; return BatchResult :: fromSettledPromises ( $ results ) ; } $ result = $ promises [ 0 ] -> wait ( ) ; if ( ! $ result instanceof ResponseInterface ) { throw $ result ; } return Result :: fromPsr7 ( $ result ) ; } | Perform one or more async requests . |
22,678 | private function loadAllEndpoints ( ) { self :: $ endpointClasses = array_map ( function ( $ classPath ) { list ( $ endpointClass ) = array_slice ( explode ( '/' , $ classPath ) , - 1 , 1 ) ; $ fullClassName = join ( '\\' , [ __NAMESPACE__ , 'Endpoints' , str_replace ( '.php' , '' , $ endpointClass ) ] ) ; $ endpoint = new $ fullClassName ( $ this -> region ) ; self :: $ endpointDefinitions [ $ endpoint -> getName ( ) ] = [ 'class' => $ fullClassName , 'instance' => $ endpoint , ] ; return $ fullClassName ; } , glob ( __DIR__ . '/Endpoints/*.php' ) ) ; } | Load all available endpoints as an array of full class names with namespace strings . The endpoints are contained within a folder structure that is only 1 level deep . |
22,679 | private function getSignupEvent ( $ signup , $ opts ) { $ currentStatus = null ; $ previousAttendance = false ; $ previousPartialAttendance = false ; foreach ( $ signup -> statuses as $ status ) { if ( $ status -> timecreated == $ opts [ 'event' ] [ 'timecreated' ] ) { $ currentStatus = $ status ; } else if ( $ status -> timecreated < $ opts [ 'event' ] [ 'timecreated' ] && $ status -> statuscode == $ this -> statuscodes -> partial ) { $ previousPartialAttendance = true ; } else if ( $ status -> timecreated < $ opts [ 'event' ] [ 'timecreated' ] && $ status -> statuscode == $ this -> statuscodes -> attended ) { $ previousAttendance = true ; } } if ( is_null ( $ currentStatus ) ) { return null ; } $ duration = null ; $ completion = null ; if ( $ currentStatus -> statuscode == $ this -> statuscodes -> attended ) { if ( $ previousAttendance == true ) { return null ; } $ duration = $ this -> sessionDuration ; $ completion = true ; } else if ( $ currentStatus -> statuscode == $ this -> statuscodes -> partial ) { if ( $ previousPartialAttendance == true ) { return null ; } $ duration = $ this -> sessionDuration * $ this -> partialAttendanceDurationCredit ; $ completion = false ; } else { return null ; } return [ 'recipe' => 'training_session_attend' , 'attendee_id' => $ signup -> attendee -> id , 'attendee_url' => $ signup -> attendee -> url , 'attendee_name' => $ signup -> attendee -> fullname , 'attempt_duration' => "PT" . ( string ) $ duration . "S" , 'attempt_completion' => $ completion ] ; } | Create an event for a signup or null if no event is required . |
22,680 | public function processFileField ( array $ element , WebformSubmissionInterface $ webform_submission , & $ cleanvalues ) { $ key = $ element [ '#webform_key' ] ; $ original_data = $ webform_submission -> getOriginalData ( ) ; $ value = isset ( $ cleanvalues [ $ key ] ) ? $ cleanvalues [ $ key ] : [ ] ; $ fids = ( is_array ( $ value ) ) ? $ value : [ $ value ] ; $ original_value = isset ( $ original_data [ $ key ] ) ? $ original_data [ $ key ] : [ ] ; $ original_fids = ( is_array ( $ original_value ) ) ? $ original_value : [ $ original_value ] ; $ delete_fids = array_diff ( $ original_fids , $ fids ) ; if ( empty ( $ fids ) ) { return ; } try { $ files = $ this -> entityTypeManager -> getStorage ( 'file' ) -> loadMultiple ( $ fids ) ; } catch ( InvalidPluginDefinitionException $ e ) { } catch ( PluginNotFoundException $ e ) { } $ fileinfo_many = [ ] ; foreach ( $ files as $ file ) { $ fileinfo = [ ] ; if ( isset ( $ cleanvalues [ 'as:image' ] ) ) { $ fileinfo = $ this -> check_file_in_metadata ( $ cleanvalues [ 'as:image' ] , ( int ) $ file -> id ( ) ) ; if ( $ fileinfo ) { $ fileinfo_many [ $ fileinfo [ 'dr:url' ] ] = $ fileinfo ; } } if ( ! $ fileinfo ) { $ uri = $ file -> getFileUri ( ) ; $ md5 = md5_file ( $ uri ) ; $ fileinfo = [ 'type' => 'Image' , 'dr:url' => $ uri , 'url' => $ uri , 'checksum' => $ md5 , 'dr:for' => $ key , 'dr:fid' => ( int ) $ file -> id ( ) , 'name' => $ file -> getFilename ( ) , ] ; $ relativefolder = substr ( $ md5 , 0 , 3 ) ; $ source_uri = $ file -> getFileUri ( ) ; $ realpath_uri = $ this -> fileSystem -> realpath ( $ source_uri ) ; if ( empty ( ! $ realpath_uri ) ) { $ command = escapeshellcmd ( '/usr/local/bin/fido ' . $ realpath_uri . ' -pronom_only -matchprintf ' ) ; $ output = shell_exec ( $ command . '"OK,%(info.puid)" -q' ) ; } $ destination_uri = $ this -> getFileDestinationUri ( $ element , $ file , $ relativefolder , $ webform_submission ) ; $ fileinfo_many [ $ destination_uri ] = $ fileinfo ; } } $ cleanvalues [ 'as:image' ] = $ fileinfo_many ; } | Process temp files and make them permanent |
22,681 | protected function getUriSchemeForManagedFile ( array $ element ) { if ( isset ( $ element [ '#uri_scheme' ] ) ) { return $ element [ '#uri_scheme' ] ; } $ scheme_options = \ Drupal \ webform \ Plugin \ WebformElement \ WebformManagedFileBase :: getVisibleStreamWrappers ( ) ; if ( isset ( $ scheme_options [ 'private' ] ) ) { return 'private' ; } elseif ( isset ( $ scheme_options [ 'public' ] ) ) { return 'public' ; } else { return 'private' ; } } | Gets valid upload stream wrapper schemes . |
22,682 | public function getLayoutPath ( $ sufix = 'layouts' ) { if ( $ this -> _layoutPath === null ) { $ path = parent :: getLayoutPath ( ) ; if ( ! is_dir ( $ path ) && $ parentPath = $ this -> getParentPath ( $ sufix ) ) { $ path = $ parentPath ; } $ this -> _layoutPath = $ path ; } return $ this -> _layoutPath ; } | Returns the directory that contains layout view files for this module . |
22,683 | public function prepare ( $ listener ) { if ( ! $ this -> requirements -> check ( ) ) { return $ listener -> preparationNotCompleted ( ) ; } $ this -> installer -> migrate ( ) ; return $ listener -> preparationCompleted ( ) ; } | Run migration and prepare the database . |
22,684 | public function create ( $ listener ) { $ model = new Fluent ( [ 'site' => [ 'name' => \ config ( 'app.name' , 'Orchestra Platform' ) ] , ] ) ; $ form = $ this -> presenter -> form ( $ model ) ; return $ listener -> createSucceed ( \ compact ( 'form' , 'model' ) ) ; } | Display initial user and site configuration page . |
22,685 | protected function requireInstallerFiles ( bool $ once = true ) : void { $ paths = \ config ( 'orchestra/installer::installers.paths' , [ ] ) ; $ method = ( $ once === true ? 'requireOnce' : 'getRequire' ) ; foreach ( $ paths as $ path ) { $ file = \ rtrim ( $ path , '/' ) . '/installer.php' ; if ( File :: exists ( $ file ) ) { File :: { $ method } ( $ file ) ; } } } | Requires the installer files . |
22,686 | public function dispatch ( Queueable $ job ) { if ( isset ( $ job -> queue , $ job -> delay ) ) { return $ this -> connection -> laterOn ( $ job -> queue , $ job -> delay , $ job ) ; } if ( isset ( $ job -> queue ) ) { return $ this -> connection -> pushOn ( $ job -> queue , $ job ) ; } if ( isset ( $ job -> delay ) ) { return $ this -> connection -> later ( $ job -> delay , $ job ) ; } return $ this -> connection -> push ( $ job ) ; } | Dispatch a job behind a queue . |
22,687 | protected function failJob ( $ job , $ e ) { if ( $ job -> isDeleted ( ) ) { return ; } $ job -> delete ( ) ; $ job -> failed ( $ e ) ; } | Mark the given job as failed and raise the relevant event . |
22,688 | public function shortCode ( $ text ) { $ patterns = [ "/\[(FIGURE)[\s+](.+)\]/" , "/\[(YOUTUBE)[\s+](.+)\]/" , "/\[(CODEPEN)[\s+](.+)\]/" , "/\[(ASCIINEMA)[\s+](.+)\]/" , "/\[(BOOK)[\s+](.+)\]/" , "/(```)([\w]*)\n(.*?)```\n/s" , '/\[(INFO)\]/' , '/\[(\/INFO)\]/' , '/\[(WARNING)\]/' , '/\[(\/WARNING)\]/' , ] ; return preg_replace_callback ( $ patterns , function ( $ matches ) { switch ( $ matches [ 1 ] ) { case "FIGURE" : return self :: shortCodeFigure ( $ matches [ 2 ] ) ; break ; case "YOUTUBE" : return self :: shortCodeYoutube ( $ matches [ 2 ] ) ; break ; case "CODEPEN" : return self :: shortCodeCodepen ( $ matches [ 2 ] ) ; break ; case "ASCIINEMA" : return self :: shortCodeAsciinema ( $ matches [ 2 ] ) ; break ; case "BOOK" : return self :: shortCodeBook ( $ matches [ 2 ] ) ; break ; case "```" : return $ this -> syntaxHighlightJs ( $ matches [ 3 ] , $ matches [ 2 ] ) ; break ; case 'INFO' : return <<<EOD<div class="info"> <span class="icon fa-stack fa-lg"> <i class="fa fa-circle fa-stack-2x"></i> <i class="fa fa-info fa-stack-1x fa-inverse" aria-hidden="true"></i> </span> <div markdown=1>EOD ; break ; case 'WARNING' : return <<<EOD<div class="warning"> <span class="icon fa-stack fa-lg"> <i class="fa fa-circle fa-stack-2x"></i> <i class="fa fa-exclamation-triangle fa-stack-1x fa-inverse" aria-hidden="true"></i> </span> <div markdown=1>EOD ; break ; case '/INFO' : case '/WARNING' : return "</div></div>" ; break ; default : return "{$matches[1]} is unknown shortcode." ; } } , $ text ) ; } | Shortcode to quicker format text as HTML . |
22,689 | public static function shortCodeInit ( $ options ) { preg_match_all ( '/[a-zA-Z0-9]+="[^"]+"|\S+/' , $ options , $ matches ) ; $ res = array ( ) ; foreach ( $ matches [ 0 ] as $ match ) { $ pos = strpos ( $ match , '=' ) ; if ( $ pos === false ) { $ res [ $ match ] = true ; } else { $ key = substr ( $ match , 0 , $ pos ) ; $ val = trim ( substr ( $ match , $ pos + 1 ) , '"' ) ; $ res [ $ key ] = $ val ; } } return $ res ; } | Init shortcode handling by preparing the option list to an array for those using arguments . |
22,690 | protected function processSubmit ( FormInterface $ form , Request $ request ) : void { if ( $ request -> hasFlag ( Request :: RESTORED ) ) { return ; } $ form -> handleRequest ( $ request ) ; if ( ! $ form -> isSubmitted ( ) ) { throw new BadRequestException ( 'The form was not submitted.' ) ; } $ data = $ form -> getData ( ) ; if ( $ form -> isValid ( ) ) { $ this -> onSuccess ( $ data , $ this ) ; } else { $ this -> onError ( $ data , $ this ) ; } $ this -> onSubmit ( $ data , $ this ) ; } | Submits the form . |
22,691 | protected function processValidate ( FormInterface $ form , Request $ request ) : void { $ presenter = $ this -> getPresenter ( ) ; if ( ! $ presenter -> isAjax ( ) ) { throw new BadRequestException ( 'The validate signal is only allowed in ajax mode.' ) ; } $ form -> handleRequest ( $ request ) ; if ( ! $ form -> isSubmitted ( ) ) { throw new BadRequestException ( 'The form was not submitted.' ) ; } $ view = $ this -> getView ( ) ; $ errors = [ ] ; $ this -> walkErrors ( $ form -> getErrors ( true , false ) , $ view , function ( FormView $ view ) use ( & $ errors ) { $ errors [ $ view -> vars [ 'id' ] ] = $ this -> renderer -> searchAndRenderBlock ( $ view , 'errors_content' ) ; } ) ; $ presenter -> sendJson ( ( object ) [ 'errors' => $ errors ] ) ; } | Provides ajax validation . |
22,692 | protected function processRender ( FormInterface $ form , Request $ request ) : void { $ presenter = $ this -> getPresenter ( ) ; if ( ! $ presenter -> isAjax ( ) ) { throw new BadRequestException ( 'The render signal is only allowed in ajax mode.' ) ; } $ fields = $ request -> getPost ( $ this -> lookupPath ( Presenter :: class , true ) . self :: NAME_SEPARATOR . 'fields' ) ; if ( ! $ fields ) { throw new BadRequestException ( 'No fields specified for rendering.' ) ; } $ form -> handleRequest ( $ request ) ; if ( ! $ form -> isSubmitted ( ) ) { throw new BadRequestException ( 'The form was not submitted.' ) ; } $ view = $ this -> getView ( ) ; $ widgets = [ ] ; foreach ( $ fields as $ field ) { if ( ! Strings :: match ( $ field , '~^(?:\[\w++\])++$~' ) ) { throw new BadRequestException ( sprintf ( 'Field identifier "%s" contains unallowed characters.' , $ field ) ) ; } if ( isset ( $ widgets [ $ field ] ) ) { continue ; } try { $ fieldView = $ this -> propertyAccessor -> getValue ( $ view , $ field ) ; } catch ( ExceptionInterface $ e ) { throw new BadRequestException ( sprintf ( 'FormView not found for field identifier "%s".' , $ field ) , 0 , $ e ) ; } $ widgets [ $ field ] = $ this -> renderer -> searchAndRenderBlock ( $ fieldView , 'widget' ) ; } $ presenter -> sendJson ( ( object ) [ 'widgets' => $ widgets ] ) ; } | Renders only specified fields . Useful for dynamic ajax forms . |
22,693 | public function register ( $ context = null ) { if ( ! $ this -> is_needed ( ) ) { return ; } \ shortcode_ui_register_for_shortcode ( $ this -> shortcode_tag , $ this -> config ) ; } | Register the shortcode UI handler function with WordPress . |
22,694 | public function mapToList ( $ map ) { $ list = array ( ) ; foreach ( $ map as $ key => $ value ) { $ list [ ] = new QVariant ( $ key , Types :: TYPE_QBYTE_ARRAY ) ; $ list [ ] = $ value ; } return $ list ; } | converts the given map to a list |
22,695 | public function listToMap ( array $ list ) { $ map = array ( ) ; for ( $ i = 0 , $ n = count ( $ list ) ; $ i < $ n ; $ i += 2 ) { $ map [ $ list [ $ i ] ] = $ list [ $ i + 1 ] ; } return ( object ) $ map ; } | converts the given list to a map |
22,696 | public function make ( array $ input , bool $ multiple = true ) : bool { try { $ this -> validate ( $ input ) ; } catch ( ValidationException $ e ) { Session :: flash ( 'errors' , $ e -> validator -> messages ( ) ) ; return false ; } try { ! $ multiple && $ this -> hasNoExistingUser ( ) ; $ this -> create ( $ this -> createUser ( $ input ) , $ input ) ; Messages :: add ( 'success' , \ trans ( 'orchestra/foundation::install.user.created' ) ) ; return true ; } catch ( Exception $ e ) { Messages :: add ( 'error' , $ e -> getMessage ( ) ) ; } return false ; } | Create adminstrator account . |
22,697 | public function create ( User $ user , array $ input ) : void { $ memory = \ app ( 'orchestra.memory' ) -> make ( ) ; $ actions = [ 'Manage Orchestra' , 'Manage Users' ] ; $ admin = \ config ( 'orchestra/foundation::roles.admin' , 1 ) ; $ roles = Role :: pluck ( 'name' , 'id' ) -> all ( ) ; $ theme = [ 'frontend' => 'default' , 'backend' => 'default' , ] ; $ user -> roles ( ) -> sync ( [ $ admin ] ) ; $ memory -> put ( 'site.name' , $ input [ 'site_name' ] ) ; $ memory -> put ( 'site.theme' , $ theme ) ; $ memory -> put ( 'email' , \ config ( 'mail' ) ) ; $ memory -> put ( 'email.from' , [ 'name' => $ input [ 'site_name' ] , 'address' => $ input [ 'email' ] , ] ) ; $ acl = \ app ( 'orchestra.platform.acl' ) ; $ acl -> attach ( $ memory ) ; $ acl -> actions ( ) -> attach ( $ actions ) ; $ acl -> roles ( ) -> attach ( \ array_values ( $ roles ) ) ; $ acl -> allow ( $ roles [ $ admin ] , $ actions ) ; \ event ( 'orchestra.install: acl' , [ $ acl ] ) ; } | Run application setup . |
22,698 | public function validate ( array $ input ) : bool { $ rules = [ 'email' => [ 'required' , 'email' ] , 'password' => [ 'required' ] , 'fullname' => [ 'required' ] , 'site_name' => [ 'required' ] , ] ; $ validation = \ app ( 'validator' ) -> make ( $ input , $ rules ) ; if ( $ validation -> fails ( ) ) { throw new ValidationException ( $ validation ) ; } return true ; } | Validate request . |
22,699 | public function createUser ( array $ input ) : User { User :: unguard ( ) ; $ user = new User ( [ 'email' => $ input [ 'email' ] , 'password' => $ input [ 'password' ] , 'fullname' => $ input [ 'fullname' ] , 'status' => User :: VERIFIED , ] ) ; \ event ( 'orchestra.install: user' , [ $ user , $ input ] ) ; $ user -> save ( ) ; return $ user ; } | Create user account . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.