idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
11,700
|
public function syncDictionary ( ) { $ this -> kernel = $ this -> get ( 'kernel' ) ; $ this -> locales = $ this -> getLocales ( ) ; $ this -> propertyAccessor = PropertyAccess :: createPropertyAccessor ( ) ; $ this -> filesystem = new Filesystem ( ) ; foreach ( $ this -> locales as $ locale ) { $ this -> updateFilesystemTranslationsForLocale ( $ locale ) ; } $ this -> synchronizeDatabaseTranslations ( ) ; }
|
Synchronizes database and filesystem translations
|
11,701
|
protected function get_field ( \ WP_Post $ post ) { $ html = parent :: get_field ( $ post ) ; return $ html . sprintf ( '<p class="inline-error"><i class="dashicons dashicons-location-alt"></i> %s</p>' , $ this -> __ ( 'Can\'t find map point. Try another string' ) ) ; }
|
Add error message .
|
11,702
|
public static function setHTML ( $ id , $ html ) { $ js = '$("' . $ id . '").html(' . json_encode ( $ html ) . ');' ; return self :: execHeader ( $ js ) ; }
|
Uses jsexec_header to set the innerHTML of an element by id
|
11,703
|
public static function execScript ( $ script_path , $ context = null ) { header ( 'Content-type: text/javascript' ) ; if ( ! is_null ( $ context ) ) { if ( is_object ( $ context ) ) { $ context = get_object_vars ( $ context ) ; } if ( is_array ( $ context ) ) { extract ( $ context ) ; } } require ( $ script_path ) ; }
|
Executes a script at a certain path
|
11,704
|
private function processMetadataDrivers ( ) { $ builder = $ this -> getContainerBuilder ( ) ; $ annotationReader = $ builder -> addDefinition ( $ this -> prefix ( 'metadata.annotationReader' ) ) -> setClass ( AnnotationReader :: class ) ; $ cachedReader = $ builder -> addDefinition ( $ this -> prefix ( 'metadata.cachedReader' ) ) -> setClass ( CachedReader :: class ) -> setFactory ( CachedReader :: class , [ '@' . $ this -> prefix ( 'metadata.annotationReader' ) , '@' . $ this -> prefix ( 'cache.annotations' ) , $ this -> debugMode ] ) ; $ driverChain = $ builder -> addDefinition ( $ this -> prefix ( 'metadata.driver' ) ) -> setClass ( MappingDriverChain :: class ) ; foreach ( $ this -> config [ 'metadata' ] as $ namespace => $ directory ) { $ driver = $ builder -> addDefinition ( $ this -> prefix ( 'driver.' . $ this -> createServiceName ( $ namespace ) ) ) -> setClass ( MappingDriver :: class ) -> setFactory ( AnnotationDriver :: class , [ '@' . $ this -> prefix ( 'metadata.cachedReader' ) , $ directory ] ) ; $ driverChain -> addSetup ( '$service->addDriver(?, ?)' , [ '@' . $ this -> prefix ( 'driver.' . $ this -> createServiceName ( $ namespace ) ) , $ namespace ] ) ; } }
|
Registers metadata drivers .
|
11,705
|
private function createServiceName ( string $ namespace ) { $ parts = explode ( '\\' , $ namespace ) ; foreach ( $ parts as $ k => $ part ) { $ parts [ $ k ] = lcfirst ( $ part ) ; } return trim ( implode ( '.' , $ parts ) , '.' ) ; }
|
Converts PHP namespace to service name .
|
11,706
|
private function processConnection ( ) { $ builder = $ this -> getContainerBuilder ( ) ; $ connection = $ builder -> addDefinition ( $ this -> prefix ( 'connection' ) ) -> setClass ( Connection :: class ) -> setFactory ( DriverManager :: class . '::getConnection' , [ $ this -> config [ 'connection' ] ] ) ; }
|
Registers DBAL connection .
|
11,707
|
private function processEvents ( ) { $ builder = $ this -> getContainerBuilder ( ) ; $ eventManager = $ builder -> addDefinition ( $ this -> prefix ( 'eventManager' ) ) -> setClass ( EventManager :: class ) ; $ entityListenerResolver = $ builder -> addDefinition ( $ this -> prefix ( 'entityListenerResolver' ) ) -> setClass ( ContainerEntityListenerResolver :: class ) ; $ rc = new \ ReflectionClass ( Events :: class ) ; $ events = $ rc -> getConstants ( ) ; foreach ( $ this -> config [ 'listeners' ] as $ event => $ listeners ) { if ( ! isset ( $ events [ $ event ] ) ) { throw new InvalidStateException ( "Event '$event' is not valid doctrine event. See class " . Events :: class . ' for list of available events.' ) ; } foreach ( ( array ) $ listeners as $ listener ) { $ builder -> getDefinition ( $ this -> prefix ( 'eventManager' ) ) -> addSetup ( '$service->addEventListener([' . Events :: class . '::?], ?)' , [ $ event , $ listener ] ) ; } } }
|
Registers Event Manager .
|
11,708
|
private function processEntityManager ( ) { $ builder = $ this -> getContainerBuilder ( ) ; $ configuration = $ builder -> addDefinition ( $ this -> prefix ( 'configuration' ) ) -> setClass ( Configuration :: class ) -> addSetup ( '$service->setMetadataDriverImpl($this->getService(?))' , [ $ this -> prefix ( 'metadata.driver' ) ] ) -> addSetup ( '$service->setMetadataCacheImpl(?)' , [ '@' . $ this -> prefix ( 'cache.metadata' ) ] ) -> addSetup ( '$service->setQueryCacheImpl(?)' , [ '@' . $ this -> prefix ( 'cache.query' ) ] ) -> addSetup ( '$service->setResultCacheImpl(?)' , [ '@' . $ this -> prefix ( 'cache.result' ) ] ) -> addSetup ( '$service->setHydrationCacheImpl(?)' , [ '@' . $ this -> prefix ( 'cache.hydration' ) ] ) -> addSetup ( '$service->setProxyDir(?)' , [ $ this -> config [ 'proxyDir' ] ] ) -> addSetup ( '$service->setProxyNamespace(?)' , [ $ this -> config [ 'proxyNamespace' ] ] ) -> addSetup ( '$service->setNamingStrategy(?)' , [ new \ Nette \ DI \ Statement ( 'Doctrine\ORM\Mapping\UnderscoreNamingStrategy' ) ] ) -> addSetup ( '$service->setQuoteStrategy(?)' , [ new \ Nette \ DI \ Statement ( 'Doctrine\ORM\Mapping\DefaultQuoteStrategy' ) ] ) -> addSetup ( '$service->setAutoGenerateProxyClasses(?)' , [ 1 ] ) -> addSetup ( '$service->setEntityListenerResolver(?)' , [ '@' . $ this -> prefix ( 'entityListenerResolver' ) ] ) ; $ entityManager = $ builder -> addDefinition ( $ this -> prefix ( 'entityManager' ) ) -> setClass ( EntityManager :: class ) -> setFactory ( EntityManager :: class . '::create' , [ '@' . $ this -> prefix ( 'connection' ) , '@' . $ this -> prefix ( 'configuration' ) , '@' . $ this -> prefix ( 'eventManager' ) ] ) ; }
|
Registers Entity Manager .
|
11,709
|
private function processCachingServices ( ) { $ this -> createCache ( 'annotations' ) ; $ this -> createCache ( 'metadata' ) ; $ this -> createCache ( 'query' ) ; $ this -> createCache ( 'result' ) ; $ this -> createCache ( 'hydration' ) ; }
|
Registers caching services .
|
11,710
|
private function createCache ( string $ name ) { $ builder = $ this -> getContainerBuilder ( ) ; $ cache = $ builder -> addDefinition ( $ this -> prefix ( 'cache.' . $ name ) ) -> setClass ( Cache :: class ) -> setArguments ( [ '@Nette\Caching\IStorage' , $ this -> debugMode ] ) -> addSetup ( '$service->setNamespace(?)' , [ $ this -> prefix ( 'cache.' . $ name ) ] ) ; return $ cache ; }
|
Creates a caching service .
|
11,711
|
private function processConsole ( ) { $ builder = $ this -> getContainerBuilder ( ) ; $ console = $ builder -> addDefinition ( $ this -> prefix ( 'console' ) ) -> setClass ( Application :: class ) -> setArguments ( [ 'Doctrine Command Line Interface' , \ Doctrine \ ORM \ Version :: VERSION ] ) -> addSetup ( '?->setCatchExceptions(TRUE)' , [ '@self' ] ) -> addSetup ( '$helperSet = ' . ConsoleRunner :: class . '::createHelperSet(?)' , [ '@' . $ this -> prefix ( 'entityManager' ) ] ) -> addSetup ( '$helperSet->set(new \Andromeda\Doctrine\Console\Helpers\ContainerHelper(?), ?)' , [ '@Nette\DI\Container' , 'container' ] ) -> addSetup ( '?->setHelperSet($helperSet)' , [ '@self' ] ) -> addSetup ( ConsoleRunner :: class . '::addCommands(?)' , [ '@self' ] ) ; $ commands = array_merge ( [ Commands \ SchemaCreateCommand :: class , Commands \ SchemaUpdateCommand :: class , Commands \ SchemaDropCommand :: class ] , $ this -> config [ 'commands' ] ) ; foreach ( $ commands as $ command ) { $ console -> addSetup ( '?->add(?)' , [ '@self' , new Nette \ DI \ Statement ( $ command ) ] ) ; } }
|
Registers Doctrine Console .
|
11,712
|
private function processTracy ( ) { $ builder = $ this -> getContainerBuilder ( ) ; $ tracyPanel = $ builder -> addDefinition ( $ this -> prefix ( 'tracyPanel' ) ) -> setClass ( Panel :: class ) ; $ builder -> getDefinition ( $ this -> prefix ( 'entityManager' ) ) -> addSetup ( '?->setEntityManager(?)' , [ '@' . $ this -> prefix ( 'tracyPanel' ) , '@self' ] ) ; }
|
Registers debug panel .
|
11,713
|
public function preview ( $ id ) { $ item = app ( StackRepository :: class ) -> fetchOne ( ( int ) $ id ) -> firstOrFail ( ) ; if ( in_array ( $ item -> notification -> type -> name , [ 'email' , 'sms' ] ) ) { $ classname = $ item -> notification -> type -> name === 'email' ? EmailNotification :: class : SmsNotification :: class ; $ notification = app ( $ classname ) ; $ notification -> setModel ( $ item ) ; return view ( 'antares/notifications::admin.logs.preview' , [ 'content' => $ notification -> render ( ) ] ) ; } $ decorator = app ( SidebarItemDecorator :: class ) ; $ decorated = $ decorator -> item ( $ item , config ( 'antares/notifications::templates.notification' ) ) ; return new JsonResponse ( [ 'content' => $ decorated ] , 200 ) ; }
|
Preview notification log
|
11,714
|
public function delete ( LogsListener $ listener , $ id = null ) : RedirectResponse { $ stack = ! empty ( $ ids = input ( 'attr' ) ) ? $ this -> stack -> newQuery ( ) -> whereIn ( 'id' , $ ids ) : $ this -> stack -> newQuery ( ) -> findOrFail ( $ id ) ; if ( $ stack -> delete ( ) ) { return $ listener -> deleteSuccess ( ) ; } return $ listener -> deleteFailed ( ) ; }
|
Deletes notification log
|
11,715
|
protected function checkDumpDir ( ) { if ( ! is_dir ( $ this -> dump_dir ) ) { mkdir ( $ this -> dump_dir , 0700 , true ) ; } foreach ( \ range ( $ this -> max_version , 1 ) as $ version ) { $ dir = $ this -> dump_dir . $ version ; if ( is_dir ( $ dir ) ) { if ( $ version == $ this -> max_version ) { $ this -> recursiveDelete ( $ dir , 1 ) ; $ this -> log ( 'Deleting backup ' . $ this -> max_version ) ; } else { $ new_version = $ version + 1 ; rename ( $ dir , $ this -> dump_dir . $ new_version ) ; $ this -> log ( 'Moving backup ' . $ version . ' to version ' . $ new_version ) ; } } } if ( ! is_dir ( $ this -> dump_dir . '1' ) ) { mkdir ( $ this -> dump_dir . '1' , 0700 , true ) ; } }
|
check to make sure dump directory exists and if not create it
|
11,716
|
protected function dumpDatabases ( ) { foreach ( $ this -> db -> query ( "SHOW DATABASES" ) as $ list ) { $ database = $ list -> Database ; if ( ! in_array ( $ database , $ this -> ignore ) || preg_match ( "~_no_backup$~" , $ database ) ) { $ start = microtime ( true ) ; $ dir = $ this -> dump_dir . '1/' ; $ filename = $ dir . $ database ; $ this -> log ( "Dumping Database: " . $ database ) ; $ command = "mysqldump -u " . $ this -> db_user . " -h " . $ this -> db_host . " -p" . $ this -> db_pass . " " . $ database . ">" . $ filename . ".sql" ; exec ( $ command ) ; $ command = "tar -zcvf " . $ filename . ".gz " . $ filename . ".sql" ; exec ( $ command ) ; $ ms = round ( ( microtime ( true ) - $ start ) * 1000 , 2 ) ; clearstatcache ( ) ; $ size = round ( ( filesize ( $ filename . '.gz' ) / 1024 ) , 2 ) . 'kb' ; $ this -> log ( $ list -> Database . " was backed up in " . $ ms . ' ms and is ' . $ size . ' bytes' ) ; unlink ( $ filename . '.sql' ) ; } } }
|
Dump the database files and gzip add version number
|
11,717
|
protected function log ( $ message ) { if ( $ this -> debug == true ) { file_put_contents ( "php://stdout" , $ message . "\n" ) ; } file_put_contents ( $ this -> dump_dir . 'dump.log' , $ message . "\n" , \ FILE_APPEND ) ; }
|
Send messages to stdout
|
11,718
|
protected function recursiveDelete ( $ dir , $ del = 0 ) { if ( substr ( $ dir , 0 , 1 ) == '/' ) { throw new \ Exception ( "You cannot delete root directories" ) ; } $ iterator = new \ RecursiveDirectoryIterator ( $ dir ) ; foreach ( new \ RecursiveIteratorIterator ( $ iterator , \ RecursiveIteratorIterator :: CHILD_FIRST ) as $ file ) { $ name = $ file -> getFilename ( ) ; if ( $ file -> isDir ( ) && $ name != '.' && $ name != '..' ) { rmdir ( $ file -> getPathname ( ) ) ; } elseif ( $ file -> isFile ( ) ) { unlink ( $ file -> getPathname ( ) ) ; } } if ( $ del == 1 ) { rmdir ( $ dir ) ; } }
|
Recursively deletes the files in a diretory
|
11,719
|
public function addNotifier ( Notifier $ notifier , bool $ setLogger = true ) { if ( $ notifier instanceof self ) { throw new LogicException ( 'Cannot add self' ) ; } if ( $ setLogger ) { $ notifier -> setLogger ( $ this -> getLogger ( ) ) ; } $ this -> notifiers [ ] = $ notifier ; }
|
Add a notifier to the Notification center .
|
11,720
|
function devoid ( $ key ) { $ val = $ this -> ref ( $ key , FALSE ) ; return empty ( $ val ) && ( ! Cache :: instance ( ) -> exists ( $ this -> hash ( $ key ) . '.var' , $ val ) || ! $ val ) ; }
|
Return TRUE if hive key is empty and not cached
|
11,721
|
function get ( $ key , $ args = NULL ) { if ( is_string ( $ val = $ this -> ref ( $ key , FALSE ) ) && ! is_null ( $ args ) ) return call_user_func_array ( array ( $ this , 'format' ) , array_merge ( array ( $ val ) , is_array ( $ args ) ? $ args : array ( $ args ) ) ) ; if ( is_null ( $ val ) ) { if ( Cache :: instance ( ) -> exists ( $ this -> hash ( $ key ) . '.var' , $ data ) ) return $ data ; } return $ val ; }
|
Retrieve contents of hive key
|
11,722
|
function pre ( $ data , $ exit = false ) { echo '<pre>' ; print_r ( $ data ) ; echo '</pre>' ; ! $ exit || exit ( str_repeat ( '<br>' , 2 ) . ' ' . $ exit ) ; echo '<hr>' ; }
|
Output the data
|
11,723
|
function constants ( $ class , $ prefix = '' ) { $ ref = new ReflectionClass ( $ class ) ; $ out = array ( ) ; foreach ( preg_grep ( '/^' . $ prefix . '/' , array_keys ( $ ref -> getconstants ( ) ) ) as $ val ) { $ out [ $ key = substr ( $ val , strlen ( $ prefix ) ) ] = constant ( ( is_object ( $ class ) ? get_class ( $ class ) : $ class ) . '::' . $ prefix . $ key ) ; } unset ( $ ref ) ; return $ out ; }
|
Convert class constants to array
|
11,724
|
function recursive ( $ arg , $ func , $ stack = NULL ) { if ( $ stack ) { foreach ( $ stack as $ node ) if ( $ arg === $ node ) return $ arg ; } else $ stack = array ( ) ; switch ( gettype ( $ arg ) ) { case 'object' : if ( method_exists ( 'ReflectionClass' , 'iscloneable' ) ) { $ ref = new ReflectionClass ( $ arg ) ; if ( $ ref -> iscloneable ( ) ) { $ arg = clone ( $ arg ) ; $ cast = is_a ( $ arg , 'IteratorAggregate' ) ? iterator_to_array ( $ arg ) : get_object_vars ( $ arg ) ; foreach ( $ cast as $ key => $ val ) $ arg -> $ key = $ this -> recursive ( $ val , $ func , array_merge ( $ stack , array ( $ arg ) ) ) ; } } return $ arg ; case 'array' : $ copy = array ( ) ; foreach ( $ arg as $ key => $ val ) $ copy [ $ key ] = $ this -> recursive ( $ val , $ func , array_merge ( $ stack , array ( $ arg ) ) ) ; return $ copy ; } return $ func ( $ arg ) ; }
|
Invoke callback recursively for all data types
|
11,725
|
function map ( $ url , $ class , $ ttl = 0 , $ kbps = 0 ) { if ( is_array ( $ url ) ) { foreach ( $ url as $ item ) $ this -> map ( $ item , $ class , $ ttl , $ kbps ) ; return ; } foreach ( explode ( '|' , self :: VERBS ) as $ method ) $ this -> route ( $ method . ' ' . $ url , is_string ( $ class ) ? $ class . '->' . $ this -> hive [ 'PREMAP' ] . strtolower ( $ method ) : array ( $ class , $ this -> hive [ 'PREMAP' ] . strtolower ( $ method ) ) , $ ttl , $ kbps ) ; }
|
Provide ReST interface by mapping HTTP verb to class method
|
11,726
|
function highlight ( $ text ) { $ out = '' ; $ pre = FALSE ; $ text = trim ( $ text ) ; if ( ! preg_match ( '/^<\?php/' , $ text ) ) { $ text = '<?php ' . $ text ; $ pre = TRUE ; } foreach ( token_get_all ( $ text ) as $ token ) if ( $ pre ) $ pre = FALSE ; else $ out .= '<span' . ( is_array ( $ token ) ? ( ' class="' . substr ( strtolower ( token_name ( $ token [ 0 ] ) ) , 2 ) . '">' . $ this -> encode ( $ token [ 1 ] ) . '' ) : ( '>' . $ this -> encode ( $ token ) ) ) . '</span>' ; return $ out ? ( '<code>' . $ out . '</code>' ) : $ text ; }
|
Apply syntax highlighting
|
11,727
|
public function getApiRequestUrl ( Event $ event ) { $ params = $ event -> getCustomParams ( ) ; $ query = trim ( implode ( " " , $ params ) ) ; $ querystringParams = [ 'v' => '1.0' , 'q' => $ query ] ; return sprintf ( "%s?%s" , $ this -> apiUrl , http_build_query ( $ querystringParams ) ) ; }
|
Get the url for the API request
|
11,728
|
public function getHtmlHelper ( ) { $ this -> HtmlHelper -> Form -> getDataService ( ) -> template = $ this -> template ; $ this -> HtmlHelper -> getRouterService ( ) -> template = $ this -> template ; $ this -> HtmlHelper -> getAssetsService ( ) -> template = $ this -> template ; return $ this -> HtmlHelper ; }
|
return the instance of the html helper
|
11,729
|
public function display ( ) { $ path = func_get_args ( ) ; $ count = count ( $ path ) ; if ( ! $ count ) { return $ this -> redirect ( '/' ) ; } $ page = $ subpage = $ title_for_layout = null ; if ( ! empty ( $ path [ 0 ] ) ) { $ page = $ path [ 0 ] ; } if ( ! empty ( $ path [ 1 ] ) ) { $ subpage = $ path [ 1 ] ; } if ( ! empty ( $ path [ $ count - 1 ] ) ) { $ title_for_layout = Inflector :: humanize ( $ path [ $ count - 1 ] ) ; } $ this -> set ( compact ( 'page' , 'subpage' , 'title_for_layout' ) ) ; try { $ this -> render ( implode ( '/' , $ path ) ) ; } catch ( MissingViewException $ e ) { if ( Configure :: read ( 'debug' ) ) { throw $ e ; } throw new NotFoundException ( ) ; } }
|
Displays a view
|
11,730
|
public function run ( ) { $ this -> loader -> parse ( ) ; $ files = $ this -> filesystem -> getFiles ( ) ; while ( $ files -> valid ( ) ) { $ file = $ files -> current ( ) ; if ( $ file -> isLink ( ) ) { $ files -> next ( ) ; continue ; } $ filename = $ this -> getRelativeFilename ( $ file ) ; if ( $ this -> isExcluded ( $ filename ) ) { $ files -> next ( ) ; continue ; } $ fileShouldBeExecutable = $ this -> shouldBeExecutable ( $ filename ) ; if ( ! $ fileShouldBeExecutable && $ file -> isExecutable ( ) ) { $ this -> messageBag -> addMessage ( $ file -> getPathname ( ) , 'minx' ) ; $ files -> next ( ) ; continue ; } if ( $ fileShouldBeExecutable && ! $ file -> isExecutable ( ) ) { $ this -> messageBag -> addMessage ( $ file -> getPathname ( ) , 'plusx' ) ; $ files -> next ( ) ; continue ; } $ files -> next ( ) ; } }
|
Run the permission check and return any errors
|
11,731
|
protected function isExcluded ( $ filename ) { foreach ( $ this -> config -> getExcludedFiles ( ) as $ excludedFile ) { if ( $ filename === $ excludedFile ) { return true ; } } foreach ( $ this -> config -> getExcludedDirs ( ) as $ excludedDir ) { if ( strpos ( $ filename , $ excludedDir ) === 0 ) { return true ; } } return false ; }
|
Check whether the given file should be excluded .
|
11,732
|
protected function shouldBeExecutable ( $ filename ) { foreach ( $ this -> config -> getExecutableFiles ( ) as $ exFile ) { if ( $ filename === $ exFile ) { return true ; } } return false ; }
|
Check whether the given file should be executable .
|
11,733
|
protected function getRelativeFilename ( SplFileInfo $ file ) { $ filename = $ file -> getPathname ( ) ; $ regex = sprintf ( '#^(%s)/(.+)#' , $ this -> directory ) ; $ matches = array ( ) ; preg_match ( $ regex , $ filename , $ matches ) ; return $ matches [ 2 ] ; }
|
Get the relative name of the given file .
|
11,734
|
public function walk ( ) { if ( $ this -> dom instanceof \ DOMDocument ) { $ this -> rules -> document ( $ this -> dom ) ; } elseif ( $ this -> dom instanceof \ DOMDocumentFragment ) { if ( $ this -> dom -> hasChildNodes ( ) ) { $ this -> children ( $ this -> dom -> childNodes ) ; } } elseif ( $ this -> dom instanceof \ DOMNodeList ) { $ this -> children ( $ this -> dom ) ; } else { $ this -> node ( $ this -> dom ) ; } return $ this -> out ; }
|
Tell the traverser to walk the DOM .
|
11,735
|
public function node ( \ DOMNode $ node ) { switch ( $ node -> nodeType ) { case XML_ELEMENT_NODE : $ this -> rules -> element ( $ node ) ; break ; case XML_TEXT_NODE : $ this -> rules -> text ( $ node ) ; break ; case XML_CDATA_SECTION_NODE : $ this -> rules -> cdata ( $ node ) ; break ; case XML_PI_NODE : $ this -> rules -> processorInstruction ( $ node ) ; break ; case XML_COMMENT_NODE : $ this -> rules -> comment ( $ node ) ; break ; default : print '<!-- Skipped ; break ; } }
|
Process a node in the DOM .
|
11,736
|
public function isLocalElement ( $ element ) { $ uri = $ element -> namespaceURI ; if ( empty ( $ uri ) ) { return false ; } return isset ( static :: $ local_ns [ $ uri ] ) ; }
|
Is an element local?
|
11,737
|
private function setupRules ( $ rules ) { $ rules = Utils \ HelperRequiredIf :: prepare ( $ this , $ rules ) ; $ rules = Utils \ HelperSameWith :: prepare ( $ this , $ rules ) ; return $ rules ; }
|
set up rules ; - add required rule based on requiredIf rule . - add sameAs rule based on sameWith rule .
|
11,738
|
private function existsParamTagWithArgument ( $ parameters , ArgumentDescriptor $ argument ) { foreach ( $ parameters as $ parameter ) { if ( $ argument -> getName ( ) == $ parameter -> getVariableName ( ) ) { return true ; } } return false ; }
|
Returns whether the list of param tags features the given argument .
|
11,739
|
protected function getProgressBar ( InputInterface $ input ) { $ progress = parent :: getProgressBar ( $ input ) ; if ( ! $ progress ) { return null ; } $ this -> getService ( 'event_dispatcher' ) -> addListener ( 'parser.file.pre' , function ( PreFileEvent $ event ) use ( $ progress ) { $ progress -> advance ( ) ; } ) ; return $ progress ; }
|
Adds the parser . file . pre event to the advance the progressbar .
|
11,740
|
protected function compileUpdateJoinWheres ( Builder $ query ) { $ joinWheres = [ ] ; foreach ( $ query -> joins as $ join ) { foreach ( $ join -> wheres as $ where ) { $ method = "where{$where['type']}" ; $ joinWheres [ ] = $ where [ 'boolean' ] . ' ' . $ this -> { $ method } ( $ query , $ where ) ; } } return implode ( ' ' , $ joinWheres ) ; }
|
Compile the join clause where clauses for an update .
|
11,741
|
public function onRequestSent ( Event $ event ) { $ request = $ event [ 'request' ] ; $ response = $ event [ 'response' ] ; $ exception = $ event [ 'exception' ] ; $ params = $ request -> getParams ( ) ; $ retries = ( int ) $ params -> get ( self :: RETRY_PARAM ) ; $ delay = $ this -> strategy -> getBackoffPeriod ( $ retries , $ request , $ response , $ exception ) ; if ( $ delay !== false ) { $ params -> set ( self :: RETRY_PARAM , ++ $ retries ) -> set ( self :: DELAY_PARAM , microtime ( true ) + $ delay ) ; $ request -> setState ( RequestInterface :: STATE_TRANSFER ) ; $ this -> dispatch ( self :: RETRY_EVENT , array ( 'request' => $ request , 'response' => $ response , 'handle' => $ exception ? $ exception -> getCurlHandle ( ) : null , 'retries' => $ retries , 'delay' => $ delay ) ) ; } }
|
Called when a request has been sent and isn t finished processing
|
11,742
|
private function createPackages ( array $ packages ) { $ matcherPackages = [ ] ; foreach ( $ packages as $ package ) { $ reflection = new ReflectionClass ( $ package ) ; if ( $ reflection -> implementsInterface ( self :: PACKAGE_REGISTRAR ) === false ) { throw NotAvailableException :: createForPackage ( self :: PACKAGE_REGISTRAR ) ; } $ matcherPackages [ ] = $ reflection -> newInstance ( ) ; } return $ matcherPackages ; }
|
Create a few new package registrars
|
11,743
|
private function createReporter ( $ reporter ) { $ reflection = new ReflectionClass ( $ reporter ) ; if ( $ reflection -> implementsInterface ( self :: REPORTER ) === false ) { throw NotAvailableException :: createForReporter ( self :: REPORTER ) ; } return $ reflection -> newInstance ( ) ; }
|
Create a new result reporter
|
11,744
|
protected function getObject ( $ path ) { $ location = $ this -> applyPathPrefix ( $ path ) ; return $ this -> container -> getObject ( $ location ) ; }
|
Get an object .
|
11,745
|
protected function getRootPath ( PackageInterface $ package ) { $ rootPath = $ this -> vendorDir . '/raulfraile/ladybug-themes/Ladybug/' ; if ( $ this -> composer -> getPackage ( ) -> getName ( ) === 'raulfraile/ladybug' ) { $ rootPath = 'data/' . ( $ package -> getType ( ) === self :: PACKAGE_TYPE_THEME ? 'themes' : 'plugins' ) . '/Ladybug/' ; } $ rootPath .= ( $ package -> getType ( ) === self :: PACKAGE_TYPE_THEME ) ? 'Theme' : 'Plugin' ; return $ rootPath ; }
|
Returns the root installation path for templates .
|
11,746
|
public function consume ( AbstractConsumer $ consumer , $ auto_ack = false ) { if ( ! $ consumer -> active ( ) ) { return ; } $ outside_error = null ; try { $ consumer -> begin ( $ this ) ; $ this -> queue -> consume ( function ( AMQPEnvelope $ envelope ) use ( $ consumer ) { $ delivery = $ this -> builder -> build ( $ envelope ) ; $ this -> feed ( $ delivery , $ consumer ) ; return $ consumer -> active ( ) ; } , $ auto_ack ? AMQP_AUTOACK : AMQP_NOPARAM ) ; } catch ( Exception $ e ) { $ outside_error = $ e ; } try { $ this -> queue -> cancel ( ) ; } catch ( Exception $ e ) { } $ consumer -> end ( $ this , $ outside_error ) ; if ( $ outside_error ) { throw $ outside_error ; } }
|
Attach consumer to process payload from queue
|
11,747
|
protected function get_options ( ) { $ terms = get_terms ( $ this -> name ) ; if ( ! $ terms || is_wp_error ( $ terms ) ) { return [ ] ; } else { $ result = [ ] ; foreach ( $ terms as $ term ) { $ result [ $ term -> term_id ] = $ term -> name ; } return $ result ; } }
|
Get terms as option
|
11,748
|
protected function buttons ( $ fluent , Fieldset $ fieldset ) { $ fieldset -> control ( 'button' , 'cancel' ) -> field ( function ( ) { return app ( 'html' ) -> link ( handles ( "antares::notifications/" ) , trans ( 'Cancel' ) , [ 'class' => 'btn btn--md btn--default mdl-button mdl-js-button' ] ) ; } ) ; $ acl = app ( 'antares.acl' ) -> make ( 'antares/notifications' ) ; if ( $ acl -> can ( 'notifications-preview' ) ) { $ fieldset -> control ( 'button' , 'preview' ) -> attributes ( [ 'type' => 'button' , 'value' => trans ( 'Preview' ) , 'class' => 'btn btn-default notification-template-preview' , 'url' => handles ( 'antares::notifications/preview/' . $ fluent -> id ) , 'data-title' => trans ( 'antares/notifications::messages.generating_notification_preview' ) ] ) -> value ( trans ( 'Preview' ) ) ; } if ( $ acl -> can ( 'notifications-test' ) && in_array ( $ this -> fluent -> type , [ 'email' , 'sms' ] ) ) { $ fieldset -> control ( 'button' , 'sendtest' ) -> attributes ( [ 'type' => 'button' , 'class' => 'btn btn-default send-test-notification' , 'rel' => handles ( 'antares::notifications/sendtest' , [ 'csrf' => true ] ) ] ) -> value ( trans ( 'Send test' ) ) ; } $ fieldset -> control ( 'button' , 'button' ) -> attributes ( [ 'type' => 'submit' , 'class' => 'btn btn-primary' ] ) -> value ( $ fluent -> id ? trans ( 'antares/foundation::label.save_changes' ) : trans ( 'Save' ) ) ; }
|
buttons in form
|
11,749
|
public function onCreate ( ) { $ this -> grid -> attributes ( [ 'url' => handles ( 'antares::notifications/store' ) , 'method' => 'POST' , ] ) ; $ layout = ( $ this -> fluent -> type == 'sms' ) ? 'antares/notifications::admin.index.form_sms' : 'antares/notifications::admin.index.form' ; $ this -> grid -> layout ( $ layout , $ this -> layoutAttributes ) ; return $ this ; }
|
on create scenario
|
11,750
|
protected function getNotificationContentData ( $ fluent , $ langId , $ key = 'title' ) { foreach ( $ fluent -> contents as $ content ) { if ( $ langId !== $ content [ 'lang_id' ] ) { continue ; } return array_get ( $ content , $ key ) ; } return '' ; }
|
Gets notification data
|
11,751
|
public function delete ( ) { if ( $ this -> isNewRecord ( ) ) { throw new DeleteModelException ( "New models can't be deleted." ) ; } $ this -> beforeDelete ( ) ; $ this -> raiseEvent ( "BeforeDelete" ) ; $ this -> Deleted = true ; $ this -> save ( ) ; $ this -> afterDelete ( ) ; $ this -> raiseEvent ( "AfterDelete" ) ; }
|
Replaces the standard delete by flagging the entry deleted instead .
|
11,752
|
protected function _init ( $ definition = null ) { if ( ! is_null ( $ definition ) ) { $ this -> _packageXml = simplexml_load_string ( $ definition ) ; } else { $ packageXmlStub = <<<END<?xml version="1.0"?><package> <name /> <version /> <stability /> <license /> <channel /> <extends /> <summary /> <description /> <notes /> <authors /> <date /> <time /> <contents /> <compatible /> <dependencies /></package>END ; $ this -> _packageXml = simplexml_load_string ( $ packageXmlStub ) ; } return $ this ; }
|
Initializes an empty package object
|
11,753
|
protected function _loadFile ( $ filename = '' ) { if ( is_null ( $ this -> _reader ) ) { $ this -> _reader = new Mage_Connect_Package_Reader ( $ filename ) ; } $ content = $ this -> _reader -> load ( ) ; $ this -> _packageXml = simplexml_load_string ( $ content ) ; return $ this ; }
|
Loads a package from specified file
|
11,754
|
public function save ( $ path ) { $ this -> validate ( ) ; $ path = rtrim ( $ path , "\\/" ) . DS ; $ this -> _savePackage ( $ path ) ; return $ this ; }
|
Creates a package and saves it
|
11,755
|
protected function _savePackage ( $ path ) { $ fileName = $ this -> getReleaseFilename ( ) ; if ( is_null ( $ this -> _writer ) ) { $ this -> _writer = new Mage_Connect_Package_Writer ( $ this -> getContents ( ) , $ path . $ fileName ) ; } $ this -> _writer -> composePackage ( ) -> addPackageXml ( $ this -> getPackageXml ( ) ) -> archivePackage ( ) ; return $ this ; }
|
Creates a package archive and saves it to specified path
|
11,756
|
protected function _getNode ( $ tag , $ parent , $ name = '' ) { $ found = false ; foreach ( $ parent -> xpath ( $ tag ) as $ _node ) { if ( $ _node [ 'name' ] == $ name ) { $ node = $ _node ; $ found = true ; break ; } } if ( ! $ found ) { $ node = $ parent -> addChild ( $ tag ) ; if ( $ name ) { $ node -> addAttribute ( 'name' , $ name ) ; } } return $ node ; }
|
Retrieve SimpleXMLElement node by xpath . If it absent create new . For comparing nodes method uses attribute name in each nodes . If attribute name is same for both nodes nodes are same .
|
11,757
|
public function setDependencyPhpVersion ( $ minVersion , $ maxVersion ) { $ parent = $ this -> _packageXml -> dependencies ; $ parent = $ this -> _getNode ( 'required' , $ parent ) ; $ parent = $ this -> _getNode ( 'php' , $ parent ) ; $ parent -> addChild ( 'min' , $ minVersion ) ; $ parent -> addChild ( 'max' , $ maxVersion ) ; return $ this ; }
|
Set dependency from php version .
|
11,758
|
public function checkPhpVersion ( ) { $ min = $ this -> getDependencyPhpVersionMin ( ) ; $ max = $ this -> getDependencyPhpVersionMax ( ) ; $ minOk = $ min ? version_compare ( PHP_VERSION , $ min , ">=" ) : true ; $ maxOk = $ max ? version_compare ( PHP_VERSION , $ max , "<=" ) : true ; if ( ! $ minOk || ! $ maxOk ) { $ err = "requires PHP version " ; if ( $ min && $ max ) { $ err .= " >= $min and <= $max " ; } elseif ( $ min ) { $ err .= " >= $min " ; } elseif ( $ max ) { $ err .= " <= $max " ; } $ err .= " current is: " . PHP_VERSION ; return $ err ; } return true ; }
|
Check PHP version restriction
|
11,759
|
public function checkPhpDependencies ( ) { $ errors = array ( ) ; foreach ( $ this -> getDependencyPhpExtensions ( ) as $ dep ) { if ( ! extension_loaded ( $ dep [ 'name' ] ) ) { $ errors [ ] = $ dep ; } } if ( count ( $ errors ) ) { return $ errors ; } return true ; }
|
Check PHP extensions availability
|
11,760
|
public function setDependencyPhpExtensions ( $ extensions ) { foreach ( $ extensions as $ _extension ) { $ this -> addDependencyExtension ( $ _extension [ 'name' ] , $ _extension [ 'min_version' ] , $ _extension [ 'max_version' ] ) ; } return $ this ; }
|
Set dependency from php extensions .
|
11,761
|
public function setDependencyPackages ( $ packages , $ clear = false ) { if ( $ clear ) { unset ( $ this -> _packageXml -> dependencies -> required -> package ) ; } foreach ( $ packages as $ _package ) { $ filesArrayCondition = isset ( $ _package [ 'files' ] ) && is_array ( $ _package [ 'files' ] ) ; $ filesArray = $ filesArrayCondition ? $ _package [ 'files' ] : array ( ) ; $ this -> addDependencyPackage ( $ _package [ 'name' ] , $ _package [ 'channel' ] , $ _package [ 'min_version' ] , $ _package [ 'max_version' ] , $ filesArray ) ; } return $ this ; }
|
Set dependency from another packages .
|
11,762
|
public function addDependencyPackage ( $ name , $ channel , $ minVersion , $ maxVersion , $ files = array ( ) ) { $ parent = $ this -> _packageXml -> dependencies ; $ parent = $ this -> _getNode ( 'required' , $ parent ) ; $ parent = $ parent -> addChild ( 'package' ) ; $ parent -> addChild ( 'name' , $ name ) ; $ parent -> addChild ( 'channel' , $ channel ) ; $ parent -> addChild ( 'min' , $ minVersion ) ; $ parent -> addChild ( 'max' , $ maxVersion ) ; if ( count ( $ files ) ) { $ parent = $ parent -> addChild ( 'files' ) ; foreach ( $ files as $ row ) { if ( ! empty ( $ row [ 'target' ] ) && ! empty ( $ row [ 'path' ] ) ) { $ node = $ parent -> addChild ( "file" ) ; $ node [ "target" ] = $ row [ 'target' ] ; $ node [ "path" ] = $ row [ 'path' ] ; } } } return $ this ; }
|
Add package to dependency packages .
|
11,763
|
public function addDependencyExtension ( $ name , $ minVersion , $ maxVersion ) { $ parent = $ this -> _packageXml -> dependencies ; $ parent = $ this -> _getNode ( 'required' , $ parent ) ; $ parent = $ parent -> addChild ( 'extension' ) ; $ parent -> addChild ( 'name' , $ name ) ; $ parent -> addChild ( 'min' , $ minVersion ) ; $ parent -> addChild ( 'max' , $ maxVersion ) ; return $ this ; }
|
Add package to dependency extension .
|
11,764
|
public function getAuthors ( ) { if ( is_array ( $ this -> _authors ) ) return $ this -> _authors ; $ this -> _authors = array ( ) ; if ( ! isset ( $ this -> _packageXml -> authors -> author ) ) { return array ( ) ; } foreach ( $ this -> _packageXml -> authors -> author as $ _author ) { $ this -> _authors [ ] = array ( 'name' => ( string ) $ _author -> name , 'user' => ( string ) $ _author -> user , 'email' => ( string ) $ _author -> email ) ; } return $ this -> _authors ; }
|
Get list of authors in associative array .
|
11,765
|
public function getContents ( ) { if ( is_array ( $ this -> _contents ) ) return $ this -> _contents ; $ this -> _contents = array ( ) ; if ( ! isset ( $ this -> _packageXml -> contents -> target ) ) { return $ this -> _contents ; } foreach ( $ this -> _packageXml -> contents -> target as $ target ) { $ targetUri = $ this -> getTarget ( ) -> getTargetUri ( $ target [ 'name' ] ) ; $ this -> _getList ( $ target , $ targetUri ) ; } return $ this -> _contents ; }
|
Create list of all files from package . xml
|
11,766
|
public function getHashContents ( ) { if ( is_array ( $ this -> _hashContents ) ) return $ this -> _hashContents ; $ this -> _hashContents = array ( ) ; if ( ! isset ( $ this -> _packageXml -> contents -> target ) ) { return $ this -> _hashContents ; } foreach ( $ this -> _packageXml -> contents -> target as $ target ) { $ targetUri = $ this -> getTarget ( ) -> getTargetUri ( $ target [ 'name' ] ) ; $ this -> _getHashList ( $ target , $ targetUri ) ; } return $ this -> _hashContents ; }
|
Create list of all files from package . xml with hash
|
11,767
|
public function getCompatible ( ) { if ( is_array ( $ this -> _compatible ) ) return $ this -> _compatible ; $ this -> _compatible = array ( ) ; if ( ! isset ( $ this -> _packageXml -> compatible -> package ) ) { return array ( ) ; } foreach ( $ this -> _packageXml -> compatible -> package as $ _package ) { $ this -> _compatible [ ] = array ( 'name' => ( string ) $ _package -> name , 'channel' => ( string ) $ _package -> channel , 'min' => ( string ) $ _package -> min , 'max' => ( string ) $ _package -> max ) ; } return $ this -> _compatible ; }
|
Get compatible packages .
|
11,768
|
public function getDependencyPhpExtensions ( ) { if ( is_array ( $ this -> _dependencyPhpExtensions ) ) return $ this -> _dependencyPhpExtensions ; $ this -> _dependencyPhpExtensions = array ( ) ; if ( ! isset ( $ this -> _packageXml -> dependencies -> required -> extension ) ) { return $ this -> _dependencyPhpExtensions ; } foreach ( $ this -> _packageXml -> dependencies -> required -> extension as $ _package ) { $ this -> _dependencyPhpExtensions [ ] = array ( 'name' => ( string ) $ _package -> name , 'min' => ( string ) $ _package -> min , 'max' => ( string ) $ _package -> max , ) ; } return $ this -> _dependencyPhpExtensions ; }
|
Get list of php extensions .
|
11,769
|
public function getDependencyPackages ( ) { $ this -> _dependencyPackages = array ( ) ; if ( ! isset ( $ this -> _packageXml -> dependencies -> required -> package ) ) { return $ this -> _dependencyPackages ; } foreach ( $ this -> _packageXml -> dependencies -> required -> package as $ _package ) { $ add = array ( 'name' => ( string ) $ _package -> name , 'channel' => ( string ) $ _package -> channel , 'min' => ( string ) $ _package -> min , 'max' => ( string ) $ _package -> max , ) ; if ( isset ( $ _package -> files ) ) { $ add [ 'files' ] = array ( ) ; foreach ( $ _package -> files as $ node ) { if ( isset ( $ node -> file ) ) { $ add [ 'files' ] [ ] = array ( 'target' => ( string ) $ node -> file [ 'target' ] , 'path' => ( string ) $ node -> file [ 'path' ] ) ; } } } $ this -> _dependencyPackages [ ] = $ add ; } return $ this -> _dependencyPackages ; }
|
Get list of dependency packages .
|
11,770
|
public function convertChannelFromV1x ( $ channel ) { $ channelMap = array ( 'connect.magentocommerce.com/community' => 'community' , 'connect.magentocommerce.com/core' => 'community' ) ; if ( ! empty ( $ channel ) && isset ( $ channelMap [ $ channel ] ) ) { $ channel = $ channelMap [ $ channel ] ; } return $ channel ; }
|
Convert package channel in order for it to be compatible with current version of Magento Connect Manager
|
11,771
|
private function getUniqueKey ( ) : string { do { try { $ isDuplicate = null ; $ key = random_bytes ( $ this -> getOpt ( self :: OPT_SESSION_KEY_LENGTH ) ) ; $ this -> emit ( 'duplicate-check' , [ $ key , & $ isDuplicate ] ) ; } catch ( \ Exception $ e ) { throw new SessionException ( $ e -> getMessage ( ) , SessionException :: ERR_RANDOM_BYTES ) ; } } while ( isset ( $ this -> SESSION [ $ key ] ) || $ isDuplicate === true ) ; return $ key ; }
|
Generate unique key
|
11,772
|
public static function parseHeaders ( string $ rawHeaders ) : array { if ( empty ( trim ( $ rawHeaders ) ) ) { throw new InvalidArgumentException ( '$rawHeaders cannot be whitespace' ) ; } $ headers = [ ] ; $ rawHeaders = preg_replace ( "/\r\n[\t ]+/" , ' ' , trim ( $ rawHeaders ) ) ; $ fields = explode ( "\r\n" , $ rawHeaders ) ; foreach ( $ fields as $ field ) { $ match = null ; if ( preg_match ( '/([^:]+): (.+)/m' , $ field , $ match ) ) { $ key = $ match [ 1 ] ; $ key = strtolower ( trim ( $ key ) ) ; $ key = ucwords ( preg_replace ( '/[\s-]/' , ' ' , $ key ) ) ; $ key = strtr ( $ key , ' ' , '-' ) ; $ value = trim ( $ match [ 2 ] ) ; if ( ! array_key_exists ( $ key , $ headers ) ) { $ headers [ $ key ] = $ value ; continue ; } if ( ! is_array ( $ headers [ $ key ] ) ) { $ headers [ $ key ] = [ $ headers [ $ key ] ] ; } $ headers [ $ key ] [ ] = $ value ; continue ; } if ( preg_match ( '#([A-Za-z]+) +([^ ]+) +HTTP/([\d.]+)#' , $ field , $ match ) ) { $ headers = self :: addRequestDataToHeaders ( $ match , $ headers ) ; continue ; } if ( preg_match ( '#HTTP/([\d.]+) +(\d{3}) +(.*)#' , $ field , $ match ) ) { $ headers = self :: addResponseDataToHeaders ( $ match , $ headers ) ; continue ; } throw new Exception ( "Unsupported header format: {$field}" ) ; } return $ headers ; }
|
Parses HTTP headers into an associative array .
|
11,773
|
public static function buildQueryString ( array $ parameters ) : string { $ queryStrings = [ ] ; foreach ( $ parameters as $ parameterName => $ parameterValue ) { $ parameterName = rawurlencode ( $ parameterName ) ; if ( is_array ( $ parameterValue ) ) { foreach ( $ parameterValue as $ eachValue ) { $ eachValue = rawurlencode ( $ eachValue ) ; $ queryStrings [ ] = "{$parameterName}={$eachValue}" ; } } elseif ( $ parameterValue === false ) { $ queryStrings [ ] = "{$parameterName}=false" ; } elseif ( $ parameterValue === true ) { $ queryStrings [ ] = "{$parameterName}=true" ; } else { $ parameterValue = rawurlencode ( $ parameterValue ) ; $ queryStrings [ ] = "{$parameterName}={$parameterValue}" ; } } return implode ( '&' , $ queryStrings ) ; }
|
Generate URL - encoded query string
|
11,774
|
protected function routes ( ) { if ( $ this -> app -> routesAreCached ( ) ) { return ; } Route :: middleware ( [ 'nova' , Authorize :: class ] ) -> prefix ( 'nova-vendor/nova-spotify-auth-tool' ) -> group ( __DIR__ . '/../routes/web.php' ) ; Route :: middleware ( [ 'nova' , Authorize :: class ] ) -> prefix ( 'nova-vendor/nova-spotify-auth-tool' ) -> group ( __DIR__ . '/../routes/api.php' ) ; }
|
Register the tool s routes .
|
11,775
|
public function add_meta_boxes ( $ post_type , $ post ) { if ( $ this -> is_valid_post_type ( $ post_type ) && $ this -> has_cap ( ) ) { if ( empty ( $ this -> name ) || empty ( $ this -> label ) ) { $ message = sprintf ( $ this -> __ ( '<code>%s</code> has invalid name or label.' ) , get_called_class ( ) ) ; add_action ( 'admin_notices' , function ( ) use ( $ message ) { printf ( '<div class="error"><p>%s</p></div>' , $ message ) ; } ) ; } else { add_meta_box ( $ this -> name , $ this -> label , [ $ this , 'render' ] , $ post_type , $ this -> context , $ this -> priority ) ; } } }
|
Register meta box
|
11,776
|
public static function autoload ( $ className ) { Eresus_Kernel :: log ( __METHOD__ , LOG_DEBUG , '(%s)' , $ className ) ; ezcBase :: setPackageDir ( ) ; if ( array_key_exists ( $ className , ezcBase :: $ autoloadArray ) ) { if ( ezcBase :: $ autoloadArray [ $ className ] == false ) { return false ; } ezcBase :: loadFile ( ezcBase :: $ autoloadArray [ $ className ] ) ; return true ; } if ( array_key_exists ( $ className , ezcBase :: $ externalAutoloadArray ) ) { if ( ezcBase :: $ externalAutoloadArray [ $ className ] == false ) { return false ; } ezcBase :: loadExternalFile ( ezcBase :: $ externalAutoloadArray [ $ className ] ) ; return true ; } $ fileNames = array ( ) ; if ( preg_match ( "/^([a-z0-9]*)([A-Z][a-z0-9]*)?([A-Z][a-z0-9]*)?/" , $ className , $ matches ) !== false ) { $ autoloadFile = "" ; switch ( sizeof ( $ matches ) ) { case 4 : $ autoloadFile = strtolower ( "{$matches[2]}_{$matches[3]}_autoload.php" ) ; $ fileNames [ ] = $ autoloadFile ; if ( ezcBase :: requireFile ( $ autoloadFile , $ className , $ matches [ 1 ] ) ) { return true ; } case 3 : $ autoloadFile = strtolower ( "{$matches[2]}_autoload.php" ) ; $ fileNames [ ] = $ autoloadFile ; if ( ezcBase :: requireFile ( $ autoloadFile , $ className , $ matches [ 1 ] ) ) { return true ; } case 2 : $ autoloadFile = 'autoload.php' ; $ fileNames [ ] = $ autoloadFile ; if ( ezcBase :: requireFile ( $ autoloadFile , $ className , $ matches [ 1 ] ) ) { return true ; } break ; } ezcBase :: $ autoloadArray [ $ className ] = false ; } $ path = ezcBase :: $ packageDir . 'autoload/' ; $ realPath = realpath ( $ path ) ; if ( $ realPath == '' ) { trigger_error ( "Couldn't find autoload directory '$path'" , E_USER_ERROR ) ; } $ dirs = self :: getRepositoryDirectories ( ) ; if ( ezcBase :: $ options && ezcBase :: $ options -> debug ) { throw new ezcBaseAutoloadException ( $ className , $ fileNames , $ dirs ) ; } return false ; }
|
Tries to autoload the given className . If the className could be found this method returns true otherwise false .
|
11,777
|
protected static function setPackageDir ( ) { if ( ezcBase :: $ packageDir !== null ) { return ; } $ baseDir = dirname ( __FILE__ ) ; switch ( ezcBase :: $ libraryMode ) { case "custom" : ezcBase :: $ packageDir = self :: $ currentWorkingDirectory . '/' ; break ; case "devel" : case "tarball" : ezcBase :: $ packageDir = $ baseDir . "/../../" ; break ; case "pear" ; ezcBase :: $ packageDir = $ baseDir . "/../" ; break ; } }
|
Figures out the base path of the eZ Components installation .
|
11,778
|
protected static function requireFile ( $ fileName , $ className , $ prefix ) { $ autoloadDir = ezcBase :: $ packageDir . "autoload/" ; if ( $ prefix === 'ezc' && file_exists ( "$autoloadDir$fileName" ) ) { $ array = require ( "$autoloadDir$fileName" ) ; if ( is_array ( $ array ) && array_key_exists ( $ className , $ array ) ) { ezcBase :: $ autoloadArray = array_merge ( ezcBase :: $ autoloadArray , $ array ) ; if ( ezcBase :: $ options !== null && ezcBase :: $ options -> preload && ! preg_match ( '/Exception$/' , $ className ) ) { foreach ( $ array as $ loadClassName => $ file ) { if ( $ loadClassName !== 'ezcBase' && ! class_exists ( $ loadClassName , false ) && ! interface_exists ( $ loadClassName , false ) && ! preg_match ( '/Exception$/' , $ loadClassName ) ) { ezcBase :: loadFile ( ezcBase :: $ autoloadArray [ $ loadClassName ] ) ; } } } else { ezcBase :: loadFile ( ezcBase :: $ autoloadArray [ $ className ] ) ; } return true ; } } foreach ( ezcBase :: $ repositoryDirs as $ repositoryPrefix => $ extraDir ) { if ( gettype ( $ repositoryPrefix ) === 'string' && $ repositoryPrefix !== $ prefix ) { continue ; } if ( file_exists ( $ extraDir [ 'autoloadDirPath' ] . '/' . $ fileName ) ) { $ array = array ( ) ; $ originalArray = require ( $ extraDir [ 'autoloadDirPath' ] . '/' . $ fileName ) ; foreach ( $ originalArray as $ class => $ classPath ) { $ array [ $ class ] = $ extraDir [ 'basePath' ] . '/' . $ classPath ; } if ( is_array ( $ array ) && array_key_exists ( $ className , $ array ) ) { ezcBase :: $ externalAutoloadArray = array_merge ( ezcBase :: $ externalAutoloadArray , $ array ) ; ezcBase :: loadExternalFile ( ezcBase :: $ externalAutoloadArray [ $ className ] ) ; return true ; } } } return false ; }
|
Tries to load the autoload array and if loaded correctly includes the class .
|
11,779
|
public static function checkDependency ( $ component , $ type , $ value ) { switch ( $ type ) { case self :: DEP_PHP_EXTENSION : if ( extension_loaded ( $ value ) ) { return ; } else { die ( "\nThe {$component} component depends on the default PHP extension '{$value}', which is not loaded.\n" ) ; } break ; case self :: DEP_PHP_VERSION : $ phpVersion = phpversion ( ) ; if ( version_compare ( $ phpVersion , $ value , '>=' ) ) { return ; } else { die ( "\nThe {$component} component depends on the PHP version '{$value}', but the current version is '{$phpVersion}'.\n" ) ; } break ; } }
|
Checks for dependencies on PHP versions or extensions
|
11,780
|
public static function getRepositoryDirectories ( ) { $ autoloadDirs = array ( ) ; ezcBase :: setPackageDir ( ) ; $ repositoryDir = self :: $ currentWorkingDirectory ? self :: $ currentWorkingDirectory : ( realpath ( dirname ( __FILE__ ) . '/../../' ) ) ; $ autoloadDirs [ 'ezc' ] = new ezcBaseRepositoryDirectory ( ezcBaseRepositoryDirectory :: TYPE_INTERNAL , $ repositoryDir , $ repositoryDir . "/autoload" ) ; foreach ( ezcBase :: $ repositoryDirs as $ extraDirKey => $ extraDirArray ) { $ repositoryDirectory = new ezcBaseRepositoryDirectory ( ezcBaseRepositoryDirectory :: TYPE_EXTERNAL , realpath ( $ extraDirArray [ 'basePath' ] ) , realpath ( $ extraDirArray [ 'autoloadDirPath' ] ) ) ; $ autoloadDirs [ $ extraDirKey ] = $ repositoryDirectory ; } return $ autoloadDirs ; }
|
Return the list of directories that contain class repositories .
|
11,781
|
public static function addClassRepository ( $ basePath , $ autoloadDirPath = null , $ prefix = null ) { if ( ! is_dir ( $ basePath ) ) { throw new ezcBaseFileNotFoundException ( $ basePath , 'base directory' ) ; } if ( is_null ( $ autoloadDirPath ) ) { $ autoloadDirPath = $ basePath . '/autoload' ; } if ( ! is_dir ( $ autoloadDirPath ) ) { throw new ezcBaseFileNotFoundException ( $ autoloadDirPath , 'autoload directory' ) ; } if ( $ prefix === null ) { $ array = array ( 'basePath' => $ basePath , 'autoloadDirPath' => $ autoloadDirPath ) ; ezcBase :: $ repositoryDirs [ ] = $ array ; } else { if ( array_key_exists ( $ prefix , ezcBase :: $ repositoryDirs ) ) { throw new ezcBaseDoubleClassRepositoryPrefixException ( $ prefix , $ basePath , $ autoloadDirPath ) ; } ezcBase :: $ repositoryDirs [ $ prefix ] = array ( 'basePath' => $ basePath , 'autoloadDirPath' => $ autoloadDirPath ) ; } }
|
Adds an additional class repository .
|
11,782
|
public static function getInstallationPath ( ) { self :: setPackageDir ( ) ; $ path = realpath ( self :: $ packageDir ) ; if ( substr ( $ path , - 1 ) !== DIRECTORY_SEPARATOR ) { $ path .= DIRECTORY_SEPARATOR ; } return $ path ; }
|
Returns the base path of the eZ Components installation
|
11,783
|
public static function setRunMode ( $ runMode ) { if ( ! in_array ( $ runMode , array ( ezcBase :: MODE_PRODUCTION , ezcBase :: MODE_DEVELOPMENT ) ) ) { throw new ezcBaseValueException ( 'runMode' , $ runMode , 'ezcBase::MODE_PRODUCTION or ezcBase::MODE_DEVELOPMENT' ) ; } self :: $ runMode = $ runMode ; }
|
Sets the development mode to the one specified .
|
11,784
|
public static function parse ( $ value , $ exceptionOnInvalidType = false , $ objectSupport = false ) { self :: $ exceptionOnInvalidType = $ exceptionOnInvalidType ; self :: $ objectSupport = $ objectSupport ; $ value = trim ( $ value ) ; if ( 0 == strlen ( $ value ) ) { return '' ; } if ( function_exists ( 'mb_internal_encoding' ) && ( ( int ) ini_get ( 'mbstring.func_overload' ) ) & 2 ) { $ mbEncoding = mb_internal_encoding ( ) ; mb_internal_encoding ( 'ASCII' ) ; } $ i = 0 ; switch ( $ value [ 0 ] ) { case '[' : $ result = self :: parseSequence ( $ value , $ i ) ; ++ $ i ; break ; case '{' : $ result = self :: parseMapping ( $ value , $ i ) ; ++ $ i ; break ; default : $ result = self :: parseScalar ( $ value , null , array ( '"' , "'" ) , $ i ) ; } if ( preg_replace ( '/\s+#.*$/A' , '' , substr ( $ value , $ i ) ) ) { throw new ParseException ( sprintf ( 'Unexpected characters near "%s".' , substr ( $ value , $ i ) ) ) ; } if ( isset ( $ mbEncoding ) ) { mb_internal_encoding ( $ mbEncoding ) ; } return $ result ; }
|
Converts a YAML string to a PHP array .
|
11,785
|
public static function parseScalar ( $ scalar , $ delimiters = null , $ stringDelimiters = array ( '"' , "'" ) , & $ i = 0 , $ evaluate = true ) { if ( in_array ( $ scalar [ $ i ] , $ stringDelimiters ) ) { $ output = self :: parseQuotedScalar ( $ scalar , $ i ) ; if ( null !== $ delimiters ) { $ tmp = ltrim ( substr ( $ scalar , $ i ) , ' ' ) ; if ( ! in_array ( $ tmp [ 0 ] , $ delimiters ) ) { throw new ParseException ( sprintf ( 'Unexpected characters (%s).' , substr ( $ scalar , $ i ) ) ) ; } } } else { if ( ! $ delimiters ) { $ output = substr ( $ scalar , $ i ) ; $ i += strlen ( $ output ) ; if ( false !== $ strpos = strpos ( $ output , ' #' ) ) { $ output = rtrim ( substr ( $ output , 0 , $ strpos ) ) ; } } elseif ( preg_match ( '/^(.+?)(' . implode ( '|' , $ delimiters ) . ')/' , substr ( $ scalar , $ i ) , $ match ) ) { $ output = $ match [ 1 ] ; $ i += strlen ( $ output ) ; } else { throw new ParseException ( sprintf ( 'Malformed inline YAML string (%s).' , $ scalar ) ) ; } $ output = $ evaluate ? self :: evaluateScalar ( $ output ) : $ output ; } return $ output ; }
|
Parses a scalar to a YAML string .
|
11,786
|
public function forgotCheckAction ( Request $ request ) { $ error = null ; $ last_email = null ; $ userService = $ this -> get ( "flowcode.user" ) ; $ user = $ userService -> loadUserByUsername ( $ request -> get ( "_username" ) ) ; if ( $ user ) { $ userService -> resetPasssword ( $ user ) ; } else { $ error = array ( "messageKey" => "security.login.unknown_user" , "messageData" => array ( ) , ) ; } return array ( "error" => $ error , "last_email" => $ last_email , ) ; }
|
Forget check .
|
11,787
|
public function view ( $ user , Event $ event ) { if ( $ event -> creator -> id == $ user -> id ) { return true ; } return User :: findOrFail ( $ user -> id ) -> hasPermission ( 'laralum::events.view' ) ; }
|
Determine if the current user can view events .
|
11,788
|
public function publicDelete ( $ user , Event $ event ) { if ( $ event -> creator -> id == $ user -> id ) { return User :: findOrFail ( $ user -> id ) -> hasPermission ( 'laralum::events.delete-public' ) ; } return false ; }
|
Determine if the current user can delete events on public views .
|
11,789
|
public function routeError ( \ Exception $ e ) { if ( $ e instanceof NotFoundHttpException ) { $ responseContent = $ this -> twig ( ) -> render ( 'Default\404.twig' ) ; $ response = new Response ( $ responseContent , 404 ) ; } else { $ responseContent = $ this -> twig ( ) -> render ( 'Default\500.twig' , array ( 'error' => $ e -> getMessage ( ) ) ) ; $ response = new Response ( $ responseContent , 500 ) ; } return $ response ; }
|
404 and 500 error page for non debug mode
|
11,790
|
public function setMessage ( $ type , $ content ) { $ message = new \ stdClass ; $ message -> mt = $ type ; $ message -> content = $ content ; $ messages = $ this -> session ( ) -> get ( 'messages' , array ( ) ) ; $ messages [ ] = $ message ; $ this -> session ( ) -> set ( 'messages' , $ messages ) ; }
|
Sets a user message to present after reload or redirect .
|
11,791
|
public function hasErrorMessages ( ) { $ messages = $ this -> getMessages ( ) ; foreach ( $ messages as $ message ) { if ( $ message -> mt == 'error' ) { return true ; } } return false ; }
|
Checks into the message bag if there is some error message . Type == error
|
11,792
|
public function attachFiles ( $ id , $ table , $ files ) { foreach ( $ files as $ file ) { if ( ! empty ( $ file ) ) { $ this -> attachFile ( $ id , $ table , $ file ) ; } } }
|
It will attach the array of files to the entity .
|
11,793
|
public function attachFile ( $ id , $ table , \ Symfony \ Component \ HttpFoundation \ File \ UploadedFile $ file ) { $ newFileName = md5 ( microtime ( ) . '.' . strtolower ( $ file -> getClientOriginalExtension ( ) ) ) ; $ relativePath = $ table . '/' . date ( 'Y/m/d' ) ; $ relativeFilePath = $ relativePath . '/' . $ newFileName ; $ dstPath = APP_UPLOADS_DIR . '/' . $ relativePath ; $ file -> move ( $ dstPath , $ newFileName ) ; $ pic = new \ Towel \ Model \ Pic ( ) ; $ pic -> object_id = $ id ; $ pic -> object_type = $ table ; $ pic -> pic = $ relativeFilePath ; $ pic -> created = time ( ) ; $ pic -> save ( ) ; }
|
It will attach the file .
|
11,794
|
public function setResponseCookie ( $ response , $ name , $ value = null , $ expiration = 0 ) { $ expiration = 1 ; if ( $ expiration == 0 ) { $ expiration = 30 ; } if ( is_numeric ( $ expiration ) ) { $ expiration = $ expiration ; } $ response = FigResponseCookies :: set ( $ response , SetCookie :: create ( $ name ) -> withExpires ( Carbon :: parse ( ) -> timestamp + 60 * 60 * 24 * $ expiration ) -> withValue ( $ value ) ) ; return $ response ; }
|
Set New Response Cookie
|
11,795
|
public function modifyResponseCookie ( $ response , $ name , $ value = null , $ expiration = 0 ) { $ expiration = 1 ; if ( $ expiration == 0 ) { $ expiration = 30 ; } if ( is_numeric ( $ expiration ) ) { $ expiration = $ expiration ; } $ modify = function ( SetCookie $ setCookie ) { $ value = $ setCookie -> getValue ( ) ; return $ setCookie -> withValue ( $ value ) -> withExpires ( $ expiration ) ; } ; $ response = FigResponseCookies :: modify ( $ response , $ name , $ modify ) ; return $ response ; }
|
Modify Response Cookie
|
11,796
|
public function setRequestCookie ( $ request , $ name , $ value = null ) { if ( empty ( $ name ) ) { return false ; } $ request = FigRequestCookies :: set ( $ request , Cookie :: create ( $ name , $ value ) ) ; return $ request ; }
|
Set New Request Cookie
|
11,797
|
public function modifyRequestCookie ( $ request , $ name , $ value = null ) { $ modify = function ( Cookie $ cookie ) { $ value = $ cookie -> getValue ( ) ; return $ cookie -> withValue ( $ value ) ; } ; $ request = FigRequestCookies :: modify ( $ request , $ name , $ modify ) ; return $ request ; }
|
Modify Request Cookie
|
11,798
|
public function move ( $ destination , $ newName = '' ) { $ source = $ this -> file [ 'tmp_name' ] ; if ( $ destination != '' && substr ( $ destination , - 1 ) != '/' ) { $ destination .= '/' ; } if ( ! empty ( $ newName ) ) { $ target = $ destination . $ newName ; } else { $ target = $ destination . $ this -> file [ 'name' ] ; } if ( ! @ move_uploaded_file ( $ source , $ target ) ) { $ error = error_get_last ( ) ; throw new FileException ( sprintf ( 'Could not move the file "%s" to "%s" (%s)' , $ this -> getPathname ( ) , $ target , strip_tags ( $ error [ 'message' ] ) ) ) ; } @ chmod ( $ target , 0666 & ~ umask ( ) ) ; return $ target ; }
|
Move file from temporary to actual location
|
11,799
|
protected function translateToUrlEncodedPath ( $ generatedPathAsUtf8 ) { $ iso88591Path = explode ( '/' , $ generatedPathAsUtf8 ) ; foreach ( $ iso88591Path as & $ part ) { if ( substr ( $ part , - 1 ) == ':' ) { continue ; } $ subparts = explode ( '#' , $ part ) ; if ( extension_loaded ( 'iconv' ) ) { $ subparts [ 0 ] = iconv ( 'UTF-8' , 'ASCII//TRANSLIT' , $ subparts [ 0 ] ) ; } $ subparts [ 0 ] = urlencode ( $ subparts [ 0 ] ) ; $ part = implode ( '#' , $ subparts ) ; } return implode ( '/' , $ iso88591Path ) ; }
|
Translates the provided path with UTF - 8 characters into a web - and windows - safe variant .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.