idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
20,700
public function generate ( ) : void { $ this -> filesystem -> mkdir ( $ this -> getDirectories ( ) ) ; foreach ( $ this -> getFiles ( ) as $ filePath => $ fileContent ) { $ this -> filesystem -> dumpFile ( $ filePath , $ fileContent ) ; } $ this -> filesystem -> remove ( $ this -> clean ( ) ) ; }
Generate the project .
20,701
public function nextRowset ( ) { if ( false !== ( $ result = $ this -> _statement -> nextRowset ( ) ) ) { $ this -> _index = null ; } return $ result ; }
Advances the reader to the next rowset Not supported by mssql
20,702
public function next ( ) { $ this -> _row = $ this -> fetch ( ) ; if ( ! empty ( $ this -> _row ) ) { $ this -> _index ++ ; } }
Moves the internal pointer to the next row .
20,703
public static function getFullName ( $ obj ) { $ name = null ; if ( is_object ( $ obj ) ) { $ name = get_class ( $ obj ) ; } else if ( is_string ( $ obj ) ) { $ name = trim ( $ obj , '\\' ) ; } else { self :: toss ( "InvalidArgument" , "Argument must be an object or string. Got {0} instead." , $ obj ) ; } return $ name ; }
Returns a fully qualified class name
20,704
public static function isObject ( $ obj ) { if ( is_object ( $ obj ) ) { $ is_object = true ; } else if ( is_array ( $ obj ) ) { $ reduced = array_filter ( $ obj , function ( $ o ) { return is_object ( $ o ) ; } ) ; $ is_object = count ( $ reduced ) == count ( $ obj ) ; } else { $ is_object = false ; } return $ is_object ; }
Returns whether a value is an object or array of objects
20,705
public static function isInstance ( $ obj , $ class ) { if ( is_array ( $ obj ) ) { $ reduced = array_filter ( $ obj , function ( $ o ) use ( $ class ) { return self :: isInstance ( $ o , $ class ) ; } ) ; $ is_instance = count ( $ obj ) == count ( $ reduced ) ; } else { if ( ! is_object ( $ obj ) ) { $ is_instance = false ; } else { $ class = self :: getFullName ( $ class ) ; $ is_instance = is_subclass_of ( $ obj , $ class ) || self :: getFullName ( $ obj ) === $ class ; } } return $ is_instance ; }
Returns whether the object or array of objects is an instance of a class
20,706
public static function equals ( $ obj_a , $ obj_b , $ deep = false ) { $ is_equal = false ; if ( $ obj_a instanceof $ obj_b ) { if ( $ deep ) { $ obj_a = ( ( array ) $ obj_a ) ; $ obj_b = ( ( array ) $ obj_b ) ; } else { $ obj_a = get_object_vars ( $ obj_a ) ; $ obj_b = get_object_vars ( $ obj_b ) ; } $ is_equal = $ obj_a === $ obj_b ; } return $ is_equal ; }
Returns whether two objects are equal to each other
20,707
public static function merge ( $ obj , $ obj2 ) { if ( ! is_object ( $ obj ) || ! is_object ( $ obj2 ) ) { self :: toss ( "InvalidArgument" , "Merged values must be objects. Got type {0}." , gettype ( $ obj ) ) ; } if ( func_num_args ( ) > 2 ) { $ args = func_get_args ( ) ; $ obj = array_shift ( $ args ) ; foreach ( $ args as $ arg ) { self :: merge ( $ obj , $ arg ) ; } } else { foreach ( $ obj2 as $ name => $ value ) { if ( null !== $ value ) { $ obj -> $ name = $ value ; } } } return $ obj ; }
Merges two or more objects
20,708
public function getMethodArgs ( $ argName ) { if ( array_key_exists ( $ argName , $ this -> methodArgs ) ) { return $ this -> methodArgs [ $ argName ] ; } else { return null ; } }
This method gets and returns the value of the arguments requested
20,709
public function trim ( $ array ) { $ this -> inputElement = $ array ; $ this -> outputElement = array_map ( function ( $ item ) { return trim ( $ item ) ; } , $ array ) ; return $ this ; }
This method loops through array elements removing whitespaces from begining and ending of string element values
20,710
public function flatten ( $ array , $ return = array ( ) ) { foreach ( $ array as $ key => $ value ) { if ( is_array ( $ value ) || is_object ( $ value ) ) { $ return = self :: flatten ( $ value , $ return ) ; } else { $ return [ ] = $ value ; } } $ this -> outputElement = $ return ; return $ this ; }
This method converts a multi - dimensional array into a uni - dimensional array
20,711
public function addAutoloader ( $ namespace , $ path = null , $ psr4 = false ) { $ loader = new VirtFsLoader ( $ this ) ; $ loader -> register ( $ namespace , $ path , $ psr4 ) ; $ this -> pushLoader ( $ loader ) ; }
Register an autoloader for the virtual filesystem
20,712
public function pushLoader ( VirtFsLoader $ loader ) { if ( ! in_array ( $ loader , $ this -> loaders ) ) { $ this -> loaders [ ] = $ loader ; } return $ this ; }
Push a VirtFsLoader onto the stack of autoloaders for the virtual filesystem .
20,713
public function registerStreamWrapper ( $ protocol = null ) { if ( $ this -> registered_wrapper ) { throw new \ RuntimeException ( "Unregister the wrapper before registering it again!" ) ; } if ( $ protocol && ! $ this -> protocol ) { $ this -> protocol = $ protocol ; } $ this -> registered_wrapper = true ; self :: $ handlers [ $ this -> protocol ] = $ this ; return stream_wrapper_register ( $ this -> protocol , __CLASS__ , 0 ) ; }
Register a protocol as a stream wrapper .
20,714
public function addDirectory ( $ path , $ mountpoint = '/' , $ writable = false , $ priority = 0 ) { $ mounter = new Mounter \ DirectoryMounter ( $ path , $ mountpoint ) ; $ mounter -> setPriority ( $ priority ) ; $ mounter -> setIsWritable ( $ writable ) ; $ this -> nodes [ ] = $ mounter ; return $ this ; }
Add a directory to the virtual filesystem .
20,715
public function addArchive ( $ path , $ mountpoint = '/' , $ priority = 0 ) { $ mounter = new Mounter \ ArchiveMounter ( $ path , $ mountpoint ) ; $ mounter -> setPriority ( $ priority ) ; $ this -> nodes [ ] = $ mounter ; return $ this ; }
Add an archive to the virtual filesystem
20,716
public function getDirectoryListing ( $ path = '/' ) { $ listing = array ( ) ; foreach ( $ this -> nodes as $ node ) { $ mp = $ node -> getMountPoint ( ) ; if ( ( dirname ( $ mp ) == $ path ) && ( $ path != '/' ) ) { $ listing [ ] = basename ( $ mp ) . "/" ; } if ( strncmp ( $ path , $ mp , strlen ( $ mp ) ) === 0 ) { $ listing = array_merge ( $ listing , $ node -> getDirectoryListing ( $ path ) ) ; } } return $ listing ; }
Get a directory listing from the virtual filesystem .
20,717
public function getPath ( $ file ) { $ file = "/" . ltrim ( $ file , "/" ) ; $ best = null ; foreach ( $ this -> nodes as $ node ) { $ mount = $ node -> getMountPoint ( ) ; if ( strncmp ( $ mount , $ file , strlen ( $ mount ) ) === 0 ) { $ nodefile = substr ( $ file , strlen ( $ mount ) ) ; if ( $ node -> has ( $ nodefile ) ) { return $ node -> getPath ( $ nodefile ) ; } if ( ! $ best ) { $ best = $ node -> getPath ( $ nodefile ) ; } if ( $ node -> getIsWritable ( $ nodefile ) ) { $ best = $ node -> getPath ( $ nodefile ) ; } } } return $ best ; }
Get the canonical path to a file in the virtual filesystem .
20,718
public function render ( Request $ request , Response $ response ) { $ key = $ response -> getResults ( 'captcha' ) ; $ content = $ response -> getContent ( ) ; $ content .= '<script src="https://www.google.com/recaptcha/api.js"></script>' ; $ content .= '<div class="form-group"><div class="g-recaptcha" ' . 'data-sitekey="' . $ key . '"></div></div>' ; $ response -> setContent ( $ content ) ; return $ this ; }
Renders a csrf field
20,719
public function view ( $ name ) { $ this -> _view = View :: make ( $ name ) ; $ vars = get_object_vars ( $ this ) ; foreach ( $ vars as $ key => $ value ) { if ( ! in_array ( $ key , [ '_view' , '_text' , '_type' , '_subject' , '_sender_name' , '_sender_mail' ] ) ) { $ this -> _view -> with ( $ key , $ value ) ; } } $ this -> _type = 'text/html' ; return $ this ; }
Set the view .
20,720
public function from ( $ mail , $ name ) { $ this -> _sender_name = $ name ; $ this -> _sender_mail = $ mail ; return $ this ; }
Set the sender email and name .
20,721
public function attachments ( ) { $ files = func_get_args ( ) ; foreach ( $ files as $ file ) { if ( is_string ( $ file ) ) { $ this -> _attachments [ ] = [ 'file' => $ file ] ; } elseif ( is_array ( $ file ) ) { foreach ( $ file as $ key => $ value ) { $ this -> _attachments [ ] = [ 'name' => $ key , 'file' => $ value ] ; } } } return $ this ; }
add attachments to the mail .
20,722
public function attachment ( $ file , $ name = null ) { if ( ! is_null ( $ name ) ) { $ this -> _attachments [ ] = [ 'name' => $ key , 'file' => $ value ] ; } else { $ this -> _attachments [ ] = [ 'file' => $ value ] ; } return $ this ; }
Add attachment to the mail .
20,723
public function cc ( ) { $ mails = func_get_args ( ) ; foreach ( $ mails as $ mail ) { if ( is_string ( $ mail ) ) { $ this -> _cc [ ] = $ mail ; } elseif ( is_array ( $ mail ) ) { foreach ( $ mail as $ submail ) { $ this -> _cc [ ] = $ submail ; } } } return $ this ; }
Add Carbon Copy to mailable .
20,724
public function cci ( ) { $ mails = func_get_args ( ) ; foreach ( $ mails as $ mail ) { if ( is_string ( $ mail ) ) { $ this -> _cci [ ] = $ mail ; } elseif ( is_array ( $ mail ) ) { foreach ( $ mail as $ submail ) { $ this -> _cci [ ] = $ submail ; } } } return $ this ; }
Add Invisble Carbon Copy to mailable .
20,725
private function _renderTemplate ( $ template = null ) { $ def = $ this -> actionChain -> getCurrentAction ( ) ; if ( ! $ template ) { $ controller = join ( DS , array_map ( 'ucfirst' , explode ( '_' , $ def [ 'controller_name' ] ) ) ) ; $ action = $ def [ 'action' ] ; $ template = sprintf ( '%s/%s.%s' , $ controller , substr ( $ this -> actionChain -> actionNameStrategy ( $ action ) , 0 , - 6 ) , $ this -> renderer -> getSuffix ( ) ) ; } $ def [ 'controller' ] -> beforeRenderer ( ) ; $ result = $ this -> renderer -> render ( $ template ) ; $ this -> response -> setBody ( $ result ) ; if ( $ this -> response -> isHttp ( ) ) { $ this -> response -> setHeader ( 'content-type' , sprintf ( 'text/html; charset=%s' , $ this -> application -> config ( 'encoding.output' ) ) ) ; } }
rendering template .
20,726
private function _getResult ( ) { $ def = $ this -> actionChain -> getCurrentAction ( ) ; $ result = $ def [ 'result' ] ; if ( ! $ result ) { return null ; } elseif ( is_string ( $ result ) ) { return $ result ; } elseif ( is_array ( $ result ) ) { return array_shift ( $ result ) ; } else { throw new Exception ( 'invalid action result.' ) ; } }
Get action result .
20,727
private function _getResultData ( ) { $ def = $ this -> actionChain -> getCurrentAction ( ) ; $ result = $ def [ 'result' ] ; if ( is_string ( $ result ) ) { return $ this -> getAttribute ( $ result ) ; } elseif ( is_array ( $ result ) ) { return array_pop ( $ result ) ; } else { return null ; } }
Get action result data .
20,728
public static function create ( $ string ) { if ( is_array ( $ string ) ) { throw new InvalidArgumentException ( 'Arrays cannot be casted to string!' ) ; } if ( is_object ( $ string ) && ! ( ( $ string instanceof StringConvertibleInterface ) || ( method_exists ( $ string , '__toString' ) ) ) ) { throw new InvalidArgumentException ( 'The given value is an object but cant converted to string!' ) ; } $ value = ( string ) $ string ; return new StringObject ( $ value ) ; }
Creates a new stringObject class from the given value . If the given value is an object and is string convertible the object will be converted to string before consumed .
20,729
public function getButtonAnnotationOptions ( ) { return [ self :: ANNOTATION_NONE => _t ( __CLASS__ . '.NONE' , 'None' ) , self :: ANNOTATION_BUBBLE => _t ( __CLASS__ . '.BUBBLE' , 'Bubble' ) , self :: ANNOTATION_INLINE => _t ( __CLASS__ . '.INLINE' , 'Inline' ) , self :: ANNOTATION_VERTICAL => _t ( __CLASS__ . '.VERTICALBUBBLE' , 'Vertical Bubble' ) ] ; }
Answers an array of options for the button annotation field .
20,730
public static function getChoices ( $ long = false ) { $ offset = $ long ? 1 : 0 ; $ choices = [ ] ; foreach ( static :: getConfig ( ) as $ constant => $ config ) { $ choices [ $ constant ] = $ config [ $ offset ] ; } return $ choices ; }
Returns the constant choices .
20,731
public static function getLabel ( $ constant , $ long = false ) { static :: isValid ( $ constant , true ) ; return static :: getConfig ( ) [ $ constant ] [ $ long ? 1 : 0 ] ; }
Returns the label for the given constant .
20,732
public function makeRequest ( $ path , $ params ) { $ this -> dispatcher -> dispatch ( 'api.createUri' , new GenericEvent ( $ this , array ( 'path' => $ path , 'params' => $ params ) ) ) ; $ this -> response = $ this -> browser -> get ( $ this -> getUri ( ) ) ; $ parsedResponse = json_decode ( $ this -> response -> getContent ( ) , true ) ; if ( array_key_exists ( 'errors' , $ parsedResponse ) ) { throw new NewscoopApiException ( $ parsedResponse ) ; } return $ this ; }
Make request to resource
20,733
protected function mapParty ( array $ source ) { if ( ! isset ( $ source [ '__type' ] ) ) { throw new Exception ( 'Cannot map party without explicit type (server should return "__type" in party account data):' . json_encode ( $ source ) , 1354111717 ) ; } $ partyType = $ source [ '__type' ] ; unset ( $ source [ '__type' ] ) ; if ( isset ( $ this -> typeMapping [ $ partyType ] ) ) { $ partyType = $ this -> typeMapping [ $ partyType ] ; } $ configuration = new TrustedPropertyMappingConfiguration ( ) ; return $ this -> propertyMapper -> convert ( $ source , $ partyType , $ configuration ) ; }
Map the party from the given source data
20,734
public function with ( array $ data ) { foreach ( $ data as $ method ) { if ( method_exists ( $ this , $ method ) ) { $ this -> $ method ( ) ; } elseif ( taxonomy_exists ( $ method ) ) { $ this -> taxonomy ( $ method ) ; } elseif ( function_exists ( 'get_field' ) ) { $ this -> field ( $ method ) ; } } return $ this ; }
Set which data to include in the data object additionally search for an available ACF field if a method can t be found directly .
20,735
public function trim ( array $ namespaces ) { foreach ( $ this -> data as $ post ) { $ this -> removeNamespace ( $ post , $ namespaces ) ; } return $ this ; }
Trim surplus namespaces from array keys .
20,736
public function author ( ) { foreach ( $ this -> data as $ post ) { $ id = $ post -> author ; $ author = get_userdata ( $ id ) ; $ avatar = get_field ( 'author_avatar' , 'user_' . $ id ) ; $ banner = get_field ( 'author_banner' , 'user_' . $ id ) ; $ author = ( object ) [ 'name' => $ author -> display_name , 'permalink' => get_author_posts_url ( $ id ) , 'images' => ( object ) [ 'avatar' => $ avatar ? $ avatar [ 'url' ] : false , 'banner' => $ banner ? $ banner [ 'url' ] : false ] ] ; $ post -> author = $ author ; } return $ this ; }
Include the author display name in the post object .
20,737
public function taxonomy ( $ name ) { foreach ( $ this -> data as $ post ) { $ terms = get_the_terms ( $ post -> ID , $ name ) ; if ( ! empty ( $ terms ) ) { $ term = array_values ( $ terms ) [ 0 ] ; $ post -> $ name = ( object ) [ 'name' => $ term -> name , 'permalink' => get_term_link ( $ term -> slug , $ name ) ] ; } } return $ this ; }
Include the first taxonomy term name in the post object .
20,738
public function images ( ) { foreach ( $ this -> data as $ post ) { $ post -> images = Post :: images ( $ post -> ID ) ; } return $ this ; }
Include the featured image URLs in the post object .
20,739
public function permalink ( ) { foreach ( $ this -> data as $ post ) { $ post -> permalink = get_permalink ( $ post -> ID ) ; } return $ this ; }
Include the permalink in the post object .
20,740
public function field ( $ name ) { foreach ( $ this -> data as $ post ) { $ fieldType = get_field_object ( $ name , $ post -> ID ) [ 'type' ] ; if ( in_array ( $ fieldType , [ 'text' ] ) ) { $ post -> $ name = get_field ( $ name , $ post -> ID ) ; } elseif ( in_array ( $ fieldType , [ 'image' ] ) ) { $ post -> $ name = Data :: arrayToObject ( get_field ( $ name , $ post -> ID ) ) ; } } return $ this -> data ; }
Get the contents of an ACF field .
20,741
public function removeNamespace ( $ post , $ namespaces ) { foreach ( $ post as $ key => $ value ) { $ splitKey = explode ( '_' , $ key ) ; if ( in_array ( $ splitKey [ 0 ] , $ namespaces ) ) { unset ( $ post -> $ key ) ; $ newKey = implode ( array_slice ( $ splitKey , 1 ) , '_' ) ; $ post -> $ newKey = $ value ; } } return $ this ; }
Strip out a namespace from a data set .
20,742
public static function handleFinalException ( \ Exception $ exception ) { if ( PHP_SAPI == 'cli' ) { echo $ exception ; exit ( 1 ) ; } @ header ( 'Status: 500 Internal Error' ) ; @ header ( 'HTTP/1.1 500 Internal Error' ) ; while ( ob_get_level ( ) > 0 ) { ob_end_clean ( ) ; } $ tpl = getcwd ( ) . '/error.php' ; if ( is_readable ( $ tpl ) && is_file ( $ tpl ) ) { include $ tpl ; exit ( 1 ) ; } echo '<html><head><title>Application Error</title></head><body style="background: #000; color: #fff;">' ; if ( is_readable ( getcwd ( ) . '/failure.jpg' ) ) { echo '<img style="float: left;" src="data:image/jpeg;base64,' . base64_encode ( file_get_contents ( getcwd ( ) . '/failure.jpg' ) ) . '" />' ; } echo '<h1 style="color: #f00;">Application Failure</h1>' ; echo sprintf ( '<div style="margin-top: 40px;"><strong>Uncaught Exception (%s)</strong>: %s [code: %d]<br /><pre>%s</pre></div>' , get_class ( $ exception ) , $ exception -> getMessage ( ) , $ exception -> getCode ( ) , $ exception ) ; echo '</body></html>' ; exit ( 1 ) ; }
Handle final exception
20,743
public static function errorToException ( $ errno , $ errstr , $ errfile , $ errline ) { $ exclude = E_STRICT | E_NOTICE | E_USER_NOTICE ; if ( ( ( error_reporting ( ) & $ errno ) != $ errno ) || ( ( $ exclude & $ errno ) == $ errno ) ) { return false ; } $ constants = get_defined_constants ( true ) ; $ name = 'Unknown PHP Error (' . $ errno . ')' ; foreach ( $ constants [ 'Core' ] as $ c => $ value ) { if ( ( substr ( $ c , 0 , 2 ) != 'E_' ) || ( $ value != $ errno ) ) { continue ; } $ name = 'PHP ' . ucwords ( str_replace ( '_' , ' ' , strtolower ( substr ( $ c , 2 ) ) ) ) ; } $ exception = new \ RuntimeException ( sprintf ( '%s: %s in %s on line %d' , $ name , $ errstr , $ errfile , $ errline ) , $ errno ) ; if ( count ( $ exception -> getTrace ( ) ) < 1 ) { return false ; } throw $ exception ; }
Convert php errors to exceptions
20,744
public static function objToSnakeArray ( $ object , $ blackList = [ ] ) { if ( ! is_object ( $ object ) ) { throw new \ InvalidArgumentException ( 'Not an object' ) ; } return array_reduce ( self :: getAllProperties ( $ object , $ blackList ) , function ( array $ result , \ ReflectionProperty $ property ) use ( $ object ) { $ property -> setAccessible ( true ) ; $ field = $ property -> getName ( ) ; $ value = $ property -> getValue ( $ object ) ; $ value = self :: transformValue ( $ value ) ; if ( $ object instanceof WithNullableFields ) { if ( is_null ( $ value ) && ! $ object -> isNullable ( $ field ) ) { return $ result ; } if ( $ object -> isNullable ( $ field ) && ! $ object -> isValueChanged ( $ field ) ) { return $ result ; } } elseif ( is_null ( $ value ) ) { return $ result ; } $ result [ Str :: snake ( $ field ) ] = $ value ; $ property -> setAccessible ( false ) ; return $ result ; } , [ ] ) ; }
Take an object and return an array using all it s properties .
20,745
private static function transformValue ( $ value ) { if ( is_null ( $ value ) ) { return $ value ; } if ( $ value instanceof PrimalValued ) { $ value = $ value -> toPrimitive ( ) ; } elseif ( $ value instanceof Arrayable ) { $ value = $ value -> toArray ( ) ; if ( empty ( $ value ) ) { $ value = null ; } } elseif ( is_array ( $ value ) ) { $ value = array_map ( function ( $ arrValue ) { return self :: transformValue ( $ arrValue ) ; } , $ value ) ; } elseif ( $ value instanceof \ DateTimeZone ) { $ value = $ value -> getName ( ) ; } elseif ( $ value instanceof Carbon ) { $ value = $ value -> toRfc3339String ( ) ; } return $ value ; }
Transform the value .
20,746
public static function getAllProperties ( $ class , $ blacklist = [ ] ) { $ classReflection = new \ ReflectionClass ( $ class ) ; $ properties = $ classReflection -> getProperties ( ) ; if ( $ parentClass = $ classReflection -> getParentClass ( ) ) { $ parentProps = self :: getAllProperties ( $ parentClass -> getName ( ) , $ blacklist ) ; if ( ! empty ( $ parentProps ) ) { $ properties = array_merge ( $ parentProps , $ properties ) ; } } if ( empty ( $ blacklist ) ) { return $ properties ; } return array_filter ( $ properties , function ( \ ReflectionProperty $ property ) use ( $ blacklist ) { return ! $ property -> isStatic ( ) && ! in_array ( $ property -> name , $ blacklist ) ; } ) ; }
Get all the properties not blacklisted .
20,747
public static function populateResponseData ( IResponse $ response , & $ dataObject ) : void { foreach ( array_keys ( $ response -> data ( ) ) as $ key ) { $ method = 'set' ; $ method .= ucfirst ( Str :: camel ( $ key ) ) ; if ( ! method_exists ( $ dataObject , $ method ) ) { continue ; } $ dataObject -> { $ method } ( $ response -> { $ key } ) ; } }
Populate the response data into a dataObject that have the corresponding setters .
20,748
private function registerDefaultPostTypes ( ) { $ this -> registerPostType ( 'post' , [ 'labels' => [ 'name' => 'Posts' , 'singular' => 'Post' , ] , 'hierarchical' => false , 'show_ui' => true , 'icon' => 'fa fa-pencil' , 'menu_position' => 10 , '_built_in' => true , ] ) ; $ this -> registerPostType ( 'page' , [ 'labels' => [ 'name' => 'Pages' , 'singular' => 'Page' , ] , 'hierarchical' => true , 'show_ui' => true , 'icon' => 'fa fa-file' , 'menu_position' => 11 , '_built_in' => true , ] ) ; }
Registering initial post types
20,749
public function registerPostType ( $ post_type , $ args = array ( ) ) { if ( $ this -> postTypeObjectExists ( $ post_type ) ) { return new EtherError ( 'Post type with the same name already exists' ) ; } $ defaults = [ 'labels' => [ 'name' => 'Posts' , 'singular' => 'Post' , ] , 'description' => '' , 'show_ui' => true , 'show_in_admin_menu' => null , 'show_in_nav_menu' => null , 'icon' => null , 'hierarchical' => false , 'taxonomies' => [ ] , 'permissions' => [ 'view_posts' => 'view_posts' , 'create_posts' => 'create_posts' , 'edit_posts' => 'edit_posts' , 'delete_posts' => 'delete_posts' , ] , 'menu_position' => null , '_built_in' => false , ] ; $ args = array_merge ( $ defaults , $ args ) ; if ( null === $ args [ 'show_in_admin_menu' ] ) { $ args [ 'show_in_admin_menu' ] = $ args [ 'show_ui' ] ; } if ( null === $ args [ 'show_in_nav_menu' ] ) { $ args [ 'show_in_nav_menu' ] = $ args [ 'show_ui' ] ; } $ args = ( object ) $ args ; $ args -> name = $ post_type ; if ( empty ( $ post_type ) || strlen ( $ post_type ) > 20 ) { return new EtherError ( 'Post type must be less than 20 characters length' ) ; } foreach ( $ args -> taxonomies as $ taxonomy ) { Taxonomy :: registerTaxonomyForObjectType ( $ taxonomy , $ post_type ) ; } $ this -> postTypes [ $ post_type ] = $ args ; }
Register A Post Type
20,750
public function getPostTypeObject ( $ post_type ) { if ( ! isset ( $ this -> postTypes [ $ post_type ] ) ) { return false ; } return $ this -> postTypes [ $ post_type ] ; }
Returns the registered post type object
20,751
public function create ( $ postArr ) { $ userId = null ; if ( Auth :: check ( ) ) { $ userId = Auth :: user ( ) -> id ; } $ default = [ 'post_author' => $ userId , 'post_content' => '' , 'post_title' => '' , 'post_excerpt' => '' , 'post_status' => 'draft' , 'post_type' => 'post' , 'comment_status' => '' , 'post_parent' => 0 , 'menu_order' => 0 , ] ; $ postArr = array_unique ( array_merge ( $ default , $ postArr ) ) ; $ postArr [ 'guid' ] = sha1 ( time ( ) ) ; if ( empty ( $ postArr [ 'post_title' ] ) ) { return new EtherError ( 'Post title must be provided' ) ; } if ( isset ( $ postArr [ 'post_slug' ] ) && ! empty ( $ postArr [ 'post_slug' ] ) ) { $ postArr [ 'post_slug' ] = $ this -> postRepository -> sluggable ( $ postArr [ 'post_slug' ] , 'post_slug' ) ; } else { $ postArr [ 'post_slug' ] = $ this -> postRepository -> sluggable ( $ postArr [ 'post_title' ] , 'post_slug' ) ; } try { $ post = $ this -> postRepository -> create ( $ postArr ) ; } catch ( \ Exception $ e ) { return new EtherError ( $ e ) ; } return $ post ; }
Inserts a new post and return the post id
20,752
public function find ( $ postId , $ columns = [ '*' ] ) { $ cache_key = ( is_array ( $ columns ) && $ columns [ 0 ] == '*' ) ? 'post_' . $ postId : 'post_' . md5 ( $ postId . http_build_query ( $ columns ) ) ; if ( Cache :: tags ( [ 'posts' , 'post_' . $ postId ] ) -> has ( $ cache_key ) ) { return Cache :: tags ( [ 'posts' , 'post_' . $ postId ] ) -> get ( $ cache_key ) ; } else { try { $ post = $ this -> postRepository -> findOrFail ( $ postId , $ columns ) ; Cache :: tags ( [ 'posts' , 'post_' . $ postId ] ) -> put ( $ cache_key , $ post , \ Option :: get ( 'posts_cache_expires' , 60 ) ) ; return $ post ; } catch ( \ Exception $ e ) { return null ; } } }
Find a post object by id
20,753
protected function fetchTitle ( ) { try { $ this -> fetchOption ( 'title' , true ) ; } catch ( OptionRequiredException $ e ) { if ( null !== $ this -> simpleContentPage ) { $ this -> title = $ this -> simpleContentPage -> getTitle ( ) ; } else { $ this -> title = $ this -> simplePageName ; } } return $ this ; }
Fetch the item s title option .
20,754
public function enableNesting ( $ shortNesting = false ) { $ this -> _disableNesting = false ; $ this -> _shortNesting = $ shortNesting ; return $ this ; }
Automatically load relationships
20,755
public function searchConfiguration ( ) { $ search = new Manager ( $ this ) ; $ search -> like ( 'username' , [ 'before' => true , 'after' => true , 'field' => [ $ this -> aliasField ( 'username' ) ] ] ) ; return $ search ; }
Allows to search users by partial username
20,756
public function findAuth ( $ query , $ options ) { foreach ( $ options [ 'columns' ] as $ column ) { $ query = $ query -> orWhere ( [ $ column => $ options [ 'username' ] ] ) ; } return $ query ; }
Multi - column authenticate
20,757
public function findToken ( $ query , $ options ) { return $ this -> find ( ) -> matching ( 'Tokens' , function ( $ q ) use ( $ options ) { return $ q -> where ( [ 'Tokens.token' => $ options [ 'token' ] ] ) ; } ) ; }
Find user based on token
20,758
protected function setFirewalls ( Application $ app ) { $ app -> extend ( 'security.firewalls' , function ( $ firewalls , $ app ) { $ logout = new RequestMatcher ( '^/oauth/logout' , null , [ 'POST' ] ) ; $ oAuth = new RequestMatcher ( '^/oauth' ) ; $ breedFirewalls = [ 'oauth-logout' => [ 'pattern' => $ logout , 'oauth' => true , ] , 'oauth-public' => [ 'pattern' => $ oAuth , 'anonymous' => true , ] , ] ; return array_merge ( $ breedFirewalls , $ firewalls ) ; } ) ; }
Set OAuth related firewalls
20,759
public function getIdentityRoles ( UserInterface $ user = null ) { if ( $ user === null ) { $ user = $ this -> getDefaultIdentity ( ) ; if ( ! $ user ) { return ( array ) $ this -> getModuleOptions ( ) -> getDefaultGuestRole ( ) ; } } $ resultSet = $ this -> getUserRoleLinkerMapper ( ) -> findByUser ( $ user ) ; if ( count ( $ resultSet ) > 0 ) { $ roles = array ( ) ; foreach ( $ resultSet as $ userRoleLinker ) { $ roles [ ] = $ userRoleLinker -> getRoleId ( ) ; } return $ roles ; } else { return ( array ) $ this -> getModuleOptions ( ) -> getDefaultUserRole ( ) ; } }
Get the list of roles of a user
20,760
protected function saveStatement ( $ query , ClassProfile $ entity , $ asList = true ) { $ config = array_merge ( [ 'map.result' => $ this -> entity , 'map.type' => $ asList ? $ this -> buildListExpression ( $ entity ) : $ this -> buildExpression ( $ entity ) ] , $ this -> config ) ; $ this -> statement = new SQLStatement ( $ query , $ config ) ; }
Stores a new Statement instance with the given configuration
20,761
public function register ( ServerRequestInterface $ request , ResponseInterface $ response ) { $ this -> request = $ request ; $ this -> response = $ response ; return $ this ; }
Registers the current HTTP request and response
20,762
public function set ( $ key , $ value = null ) { if ( is_string ( $ key ) ) { return $ this -> registerVar ( $ key , $ value ) ; } foreach ( $ key as $ name => $ value ) { $ this -> registerVar ( $ name , $ value ) ; } return $ this ; }
Sets a value to be used by render
20,763
public function disableRendering ( $ disable = true ) { $ this -> request = $ this -> request -> withAttribute ( 'render' , ! $ disable ) ; return $ this ; }
Enables or disables rendering
20,764
public function getRouteAttributes ( $ name = null , $ default = null ) { $ route = $ this -> request -> getAttribute ( 'route' , false ) ; $ attributes = $ route ? $ route -> attributes : [ ] ; if ( null == $ name ) { return $ attributes ; } return array_key_exists ( $ name , $ attributes ) ? $ attributes [ $ name ] : $ default ; }
Get the routed request attributes
20,765
public function getEventsManager ( ) { if ( ! is_object ( parent :: getEventsManager ( ) ) ) { $ em = $ this -> getUserOption ( 'eventsManager' ) ; if ( ! is_object ( $ em ) ) { $ em = new EventsManager ( ) ; } $ em -> enablePriorities ( true ) ; $ this -> setEventsManager ( $ em ) ; } return parent :: getEventsManager ( ) ; }
Returns the internal event manager
20,766
public function getNextWebfileForTimestamp ( $ time ) { $ webfiles = $ this -> getWebfilesAsStream ( ) -> getWebfiles ( ) ; ksort ( $ webfiles ) ; foreach ( $ webfiles as $ key => $ value ) { if ( $ key > $ time ) { return $ value ; } } return null ; }
According to the given timestamp the next matching webfile will be searched and returned .
20,767
public function render ( ) { $ result = $ this -> arguments [ 'result' ] ; $ this -> conf = $ this -> arguments [ 'conf' ] ; $ domImplementation = new \ DOMImplementation ( ) ; $ this -> doc = $ domImplementation -> createDocument ( ) ; $ li = $ this -> doc -> createElement ( 'li' ) ; $ this -> doc -> appendChild ( $ li ) ; $ li -> setAttribute ( 'class' , 'pz2-detailsVisible' ) ; $ iconElement = $ this -> doc -> createElement ( 'span' ) ; $ li -> appendChild ( $ iconElement ) ; $ mediaClass = 'other' ; if ( count ( $ result [ 'md-medium' ] ) == 1 ) { $ mediaClass = $ result [ 'md-medium' ] [ 0 ] [ 'values' ] [ 0 ] ; } elseif ( count ( $ result [ 'md-medium' ] ) > 1 ) { $ mediaClass = 'multiple' ; } $ iconElement -> setAttribute ( 'class' , 'pz2-mediaIcon ' . $ mediaClass ) ; $ iconElement -> setAttribute ( 'title' , LocalizationUtility :: translate ( 'media-type-' . $ mediaClass , 'Pazpar2' ) ) ; $ this -> appendInfoToContainer ( $ this -> titleInfo ( $ result ) , $ li ) ; $ authors = $ this -> authorInfo ( $ result ) ; $ this -> appendInfoToContainer ( $ authors , $ li ) ; $ journal = $ this -> journalInfo ( $ result ) ; $ this -> appendInfoToContainer ( $ journal , $ li ) ; if ( ! $ journal ) { $ spaceBefore = ' ' ; if ( $ authors ) { $ spaceBefore = ', ' ; } $ this -> appendMarkupForFieldToContainer ( 'date' , $ result , $ li , $ spaceBefore , '.' ) ; } if ( $ this -> conf [ 'provideCOinSExport' ] == 1 ) { $ this -> appendCOinSSpansToContainer ( $ result , $ li ) ; } $ this -> appendInfoToContainer ( $ this -> renderDetails ( $ result ) , $ li ) ; return $ this -> doc -> saveHTML ( ) ; }
Main function called by Fluid .
20,768
protected function appendInfoToContainer ( $ info , $ container ) { if ( $ info && $ container ) { if ( is_array ( $ info ) == false ) { $ container -> appendChild ( $ info ) ; } else { foreach ( $ info as $ infoItem ) { $ container -> appendChild ( $ infoItem ) ; } } } }
Convenince method to append an item to another one even if undefineds and arrays are involved .
20,769
protected function appendMarkupForFieldToContainer ( $ fieldName , $ result , $ container , $ prepend = '' , $ append = '' ) { $ span = null ; $ fieldContent = $ result [ 'md-' . $ fieldName ] [ 0 ] [ 'values' ] [ 0 ] ; if ( $ fieldContent && $ container ) { $ span = $ this -> doc -> createElement ( 'span' ) ; $ span -> setAttribute ( 'class' , 'pz2-' . $ fieldName ) ; $ span -> appendChild ( $ this -> doc -> createTextNode ( $ fieldContent ) ) ; if ( $ prepend != '' ) { $ container -> appendChild ( $ this -> doc -> createTextNode ( $ prepend ) ) ; } $ container -> appendChild ( $ span ) ; if ( $ append != '' ) { $ container -> appendChild ( $ this -> doc -> createTextNode ( $ append ) ) ; } } return $ span ; }
Creates span DOM element and content for a field name ; Appends it to the given container .
20,770
protected function titleInfo ( $ result ) { $ titleCompleteElement = $ this -> doc -> createElement ( 'span' ) ; $ titleCompleteElement -> setAttribute ( 'class' , 'pz2-title-complete' ) ; $ titleMainElement = $ this -> doc -> createElement ( 'span' ) ; $ titleCompleteElement -> appendChild ( $ titleMainElement ) ; $ titleMainElement -> setAttribute ( 'class' , 'pz2-title-main' ) ; $ this -> appendMarkupForFieldToContainer ( 'title' , $ result , $ titleMainElement ) ; $ this -> appendMarkupForFieldToContainer ( 'multivolume-title' , $ result , $ titleMainElement , ' ' ) ; $ this -> appendMarkupForFieldToContainer ( 'title-remainder' , $ result , $ titleCompleteElement , ' ' ) ; $ this -> appendMarkupForFieldToContainer ( 'title-number-section' , $ result , $ titleCompleteElement , ' ' ) ; $ titleCompleteElement -> appendChild ( $ this -> doc -> createTextNode ( '. ' ) ) ; return $ titleCompleteElement ; }
Returns DOM SPAN element with markup for the current hit s title .
20,771
protected function authorInfo ( $ result ) { $ outputElement = null ; if ( $ result [ 'md-title-responsibility' ] [ 0 ] [ 'values' ] ) { $ outputText = implode ( '; ' , $ result [ 'md-title-responsibility' ] [ 0 ] [ 'values' ] ) ; if ( ! $ outputText && $ result [ 'md-author' ] ) { $ authors = [ ] ; foreach ( $ result [ 'md-author' ] as $ index => $ author ) { if ( $ index < self :: MAX_AUTHORS ) { $ authorName = $ author [ 'values' ] [ 0 ] ; $ authors [ ] = $ authorName ; } else { $ authors [ ] = LocalizationUtility :: translate ( 'et al.' , 'Pazpar2' ) ; break ; } } $ outputText = implode ( '; ' , $ authors ) ; } } if ( isset ( $ outputText ) ) { $ outputElement = $ this -> doc -> createElement ( 'span' ) ; $ outputElement -> setAttribute ( 'class' , 'pz2-item-responsibility' ) ; $ outputElement -> appendChild ( $ this -> doc -> createTextNode ( $ outputText ) ) ; } return $ outputElement ; }
Returns DOM SPAN element with markup for the current hit s author information . The pre - formatted title - responsibility field is preferred and a list of author names is used as a fallback .
20,772
protected function markupInfoItems ( $ infoItems ) { $ result = null ; if ( count ( $ infoItems ) == 1 ) { $ result = $ infoItems [ 0 ] ; } else { $ result = $ this -> doc -> createElement ( 'ul' ) ; foreach ( $ infoItems as $ item ) { $ li = $ this -> doc -> createElement ( 'li' ) ; $ result -> appendChild ( $ li ) ; $ li -> appendChild ( $ item ) ; } } return $ result ; }
Returns marked up version of the DOM items passed putting them into a list if necessary .
20,773
protected function locationDetails ( $ result ) { $ locationDetails = [ ] ; foreach ( $ result [ 'location' ] as $ locationAll ) { $ location = $ locationAll [ 'ch' ] ; $ detailsData = $ this -> doc -> createElement ( 'dd' ) ; if ( $ location [ 'md-medium' ] [ 0 ] [ 'values' ] [ 0 ] != 'article' ) { $ this -> appendInfoToContainer ( $ this -> detailInfoItem ( 'edition' , $ location ) , $ detailsData ) ; $ this -> appendInfoToContainer ( $ this -> detailInfoItem ( 'publication-name' , $ location ) , $ detailsData ) ; $ this -> appendInfoToContainer ( $ this -> detailInfoItem ( 'publication-place' , $ location ) , $ detailsData ) ; $ this -> appendInfoToContainer ( $ this -> detailInfoItem ( 'date' , $ location ) , $ detailsData ) ; $ this -> appendInfoToContainer ( $ this -> detailInfoItem ( 'physical-extent' , $ location ) , $ detailsData ) ; } $ this -> appendInfoToContainer ( $ this -> detailInfoItem ( 'isbn' , $ location ) , $ detailsData ) ; $ this -> appendInfoToContainer ( $ this -> electronicURLs ( $ location , $ result ) , $ detailsData ) ; $ this -> appendInfoToContainer ( $ this -> parentLink ( $ locationAll , $ result ) , $ detailsData ) ; $ this -> appendInfoToContainer ( $ this -> catalogueLink ( $ locationAll ) , $ detailsData ) ; if ( $ detailsData -> hasChildNodes ( ) ) { $ detailsHeading = $ this -> doc -> createElement ( 'dt' ) ; $ locationDetails [ ] = $ detailsHeading ; $ detailsHeading -> appendChild ( $ this -> doc -> createTextNode ( LocalizationUtility :: translate ( 'Ausgabe' , 'Pazpar2' ) . ':' ) ) ; $ locationDetails [ ] = $ detailsData ; } } return $ locationDetails ; }
Returns markup for each location of the item found from the current data .
20,774
protected function cleanURLList ( $ location , $ result ) { $ URLs = $ location [ 'md-electronic-url' ] ; if ( $ URLs ) { $ indexesToRemove = [ ] ; foreach ( $ URLs as $ URLIndex => & $ URLInfo ) { $ URLInfo [ 'attrs' ] [ 'originalPosition' ] = $ URLIndex ; $ URL = $ URLInfo [ 'values' ] [ 0 ] ; for ( $ remainingURLIndex = $ URLIndex + 1 ; $ remainingURLIndex < count ( $ URLs ) ; $ remainingURLIndex ++ ) { $ remainingURLInfo = $ URLs [ $ remainingURLIndex ] ; $ remainingURL = $ remainingURLInfo [ 'values' ] [ 0 ] ; if ( $ URL == $ remainingURL ) { $ URLIndexToRemove = $ URLIndex + $ remainingURLIndex ; if ( ! $ URLInfo [ 'attrs' ] && $ remainingURLInfo [ 'attrs' ] ) { $ URLIndexToRemove = $ URLIndex ; } $ indexesToRemove [ $ URLIndexToRemove ] = true ; } } $ DOIs = $ result [ 'md-doi' ] ; if ( $ DOIs ) { foreach ( $ DOIs as $ DOI ) { if ( strpos ( $ DOI [ 'values' ] [ 0 ] , $ URL ) !== false ) { $ indexesToRemove [ $ URLIndexToRemove ] = true ; break ; } } } } foreach ( array_keys ( $ indexesToRemove ) as $ index ) { $ URLs [ $ index ] = false ; } $ URLs = array_filter ( $ URLs ) ; usort ( $ URLs , [ $ this , 'URLSort' ] ) ; } return $ URLs ; }
Returns a cleaned and sorted list of the URLs in the md - electronic - url fields .
20,775
protected function electronicURLs ( $ location , $ result ) { $ electronicURLs = $ this -> cleanURLList ( $ location , $ result ) ; $ URLsContainer = null ; if ( $ electronicURLs && count ( $ electronicURLs ) != 0 ) { $ URLsContainer = $ this -> doc -> createElement ( 'span' ) ; foreach ( $ electronicURLs as $ URLInfo ) { $ linkTexts = [ ] ; $ linkURL = $ URLInfo [ 'values' ] [ 0 ] ; if ( $ URLInfo [ 'attrs' ] [ 'name' ] ) { $ linkTexts [ ] = $ URLInfo [ 'attrs' ] [ 'name' ] ; if ( $ URLInfo [ 'attrs' ] [ 'note' ] ) { $ linkTexts [ ] = $ URLInfo [ 'attrs' ] [ 'note' ] ; } } elseif ( $ URLInfo [ 'attrs' ] [ 'note' ] ) { $ linkTexts [ ] = $ URLInfo [ 'attrs' ] [ 'note' ] ; } elseif ( $ URLInfo [ 'attrs' ] [ 'fulltextfile' ] ) { $ linkTexts [ ] = 'Document' ; } else { $ linkTexts [ ] = 'Link' ; } $ localisedLinkTexts = [ ] ; foreach ( $ linkTexts as $ linkText ) { $ localisedLinkText = LocalizationUtility :: translate ( 'link-description-' . $ linkText , 'Pazpar2' ) ; if ( ! $ localisedLinkText ) { $ localisedLinkText = $ linkText ; } $ localisedLinkTexts [ ] = $ localisedLinkText ; } $ linkText = '[' . implode ( ', ' , $ localisedLinkTexts ) . ']' ; if ( $ URLsContainer -> hasChildNodes ( ) ) { $ URLsContainer -> appendChild ( $ this -> doc -> createTextNode ( ', ' ) ) ; } $ link = $ this -> doc -> createElement ( 'a' ) ; $ URLsContainer -> appendChild ( $ link ) ; $ link -> setAttribute ( 'class' , 'pz2-electronic-url' ) ; $ link -> setAttribute ( 'href' , $ linkURL ) ; $ this -> turnIntoNewWindowLink ( $ link ) ; $ link -> appendChild ( $ this -> doc -> createTextNode ( $ linkText ) ) ; } $ URLsContainer -> appendChild ( $ this -> doc -> createTextNode ( '; ' ) ) ; } return $ URLsContainer ; }
Create markup for URLs in current location data .
20,776
protected function catalogueLink ( $ locationAll ) { $ linkElement = null ; $ URL = $ locationAll [ 'ch' ] [ 'md-catalogue-url' ] [ 0 ] [ 'values' ] [ 0 ] ; $ targetName = $ locationAll [ 'attrs' ] [ 'name' ] ; if ( $ URL && $ targetName ) { $ linkElement = $ this -> doc -> createElement ( 'a' ) ; $ linkElement -> setAttribute ( 'href' , $ URL ) ; $ linkTitle = LocalizationUtility :: translate ( 'Im Katalog ansehen' , 'Pazpar2' ) ; $ linkElement -> setAttribute ( 'title' , $ linkTitle ) ; $ this -> turnIntoNewWindowLink ( $ linkElement ) ; $ linkElement -> setAttribute ( 'class' , 'pz2-detail-catalogueLink' ) ; $ linkText = LocalizationUtility :: translate ( 'catalogue-name-' . $ targetName , 'Pazpar2' ) ; if ( $ linkText === null ) { $ linkText = $ targetName ; } $ linkElement -> appendChild ( $ this -> doc -> createTextNode ( $ linkText ) ) ; } return $ linkElement ; }
Returns a link for the current record that points to the catalogue page for that item .
20,777
protected function exportLinks ( $ result ) { $ extraLinkList = $ this -> doc -> createElement ( 'ul' ) ; $ labelFormat = LocalizationUtility :: translate ( 'download-label-format-simple' , 'Pazpar2' ) ; if ( count ( $ result [ 'location' ] ) > 1 ) { $ labelFormat = LocalizationUtility :: translate ( 'download-label-format-all' , 'Pazpar2' ) ; } if ( $ this -> conf [ 'showKVKLink' ] == 1 ) { $ this -> appendInfoToContainer ( $ this -> KVKItem ( $ result ) , $ extraLinkList ) ; } $ this -> appendExportItemsTo ( $ result [ 'location' ] , $ labelFormat , $ extraLinkList ) ; $ exportLinks = null ; if ( $ extraLinkList -> hasChildNodes ( ) ) { $ exportLinks = $ this -> doc -> createElement ( 'div' ) ; $ exportLinks -> setAttribute ( 'class' , 'pz2-extraLinks' ) ; $ exportLinksLabel = $ this -> doc -> createElement ( 'span' ) ; $ exportLinks -> appendChild ( $ exportLinksLabel ) ; $ exportLinksLabel -> setAttribute ( 'class' , 'pz2-extraLinksLabel' ) ; $ exportLinksLabel -> appendChild ( $ this -> doc -> createTextNode ( LocalizationUtility :: translate ( 'mehr Links' , 'Pazpar2' ) ) ) ; $ exportLinks -> appendChild ( $ extraLinkList ) ; } return $ exportLinks ; }
Returns markup for links to each active export format .
20,778
protected function appendExportItemsTo ( $ locations , $ labelFormat , $ container ) { foreach ( $ this -> conf [ 'exportFormats' ] as $ name => $ active ) { if ( $ active ) { $ container -> appendChild ( $ this -> exportItem ( $ locations , $ name , $ labelFormat ) ) ; } } }
Appends list items with an export form for each exportFormat to the container .
20,779
protected function exportItem ( $ locations , $ exportFormat , $ labelFormat ) { $ form = $ this -> dataConversionForm ( $ locations , $ exportFormat , $ labelFormat ) ; $ item = null ; if ( $ form ) { $ item = $ this -> doc -> createElement ( 'li' ) ; $ item -> appendChild ( $ form ) ; } return $ item ; }
Returns a list item containing the form for export data conversion . The parameters are passed to dataConversionForm .
20,780
protected function dataConversionForm ( $ locations , $ exportFormat , $ labelFormat ) { $ recordXML = $ this -> XMLForLocations ( $ locations ) ; $ XMLString = $ recordXML -> saveXML ( ) ; $ form = null ; if ( $ XMLString ) { $ form = $ this -> doc -> createElement ( 'form' ) ; $ form -> setAttribute ( 'method' , 'POST' ) ; $ scriptPath = 'typo3conf/ext/pazpar2/Resources/Public/pz2-client/converter/convert-pazpar2-record.php' ; $ scriptGetParameters = [ 'format' => $ exportFormat ] ; if ( $ GLOBALS [ 'TSFE' ] -> lang ) { $ scriptGetParameters [ 'language' ] = $ GLOBALS [ 'TSFE' ] -> lang ; } if ( $ this -> conf [ 'siteName' ] ) { $ scriptGetParameters [ 'filename' ] = $ this -> conf [ 'siteName' ] ; } $ form -> setAttribute ( 'action' , $ scriptPath . '?' . http_build_query ( $ scriptGetParameters ) ) ; $ qInput = $ this -> doc -> createElement ( 'input' ) ; $ qInput -> setAttribute ( 'name' , 'q' ) ; $ qInput -> setAttribute ( 'type' , 'hidden' ) ; $ qInput -> setAttribute ( 'value' , $ XMLString ) ; $ form -> appendChild ( $ qInput ) ; $ submitButton = $ this -> doc -> createElement ( 'input' ) ; $ form -> appendChild ( $ submitButton ) ; $ submitButton -> setAttribute ( 'type' , 'submit' ) ; $ buttonText = LocalizationUtility :: translate ( 'download-label-' . $ exportFormat , 'Pazpar2' ) ; $ submitButton -> setAttribute ( 'value' , $ buttonText ) ; if ( $ labelFormat ) { $ labelText = str_replace ( '*' , $ buttonText , $ labelFormat ) ; $ submitButton -> setAttribute ( 'title' , $ labelText ) ; } } return $ form ; }
Returns form Element containing the record information to initiate data conversion .
20,781
protected function XMLForLocations ( $ locations ) { $ XML = new \ DOMDocument ( ) ; $ locationsElement = $ XML -> createElement ( 'locations' ) ; $ XML -> appendChild ( $ locationsElement ) ; foreach ( $ locations as $ location ) { $ locationElement = $ XML -> createElement ( 'location' ) ; $ locationsElement -> appendChild ( $ locationElement ) ; if ( array_key_exists ( 'attrs' , $ location ) ) { foreach ( $ location [ 'attrs' ] as $ attributeName => $ attributeContent ) { $ locationElement -> setAttribute ( $ attributeName , $ attributeContent ) ; } } if ( array_key_exists ( 'ch' , $ location ) ) { foreach ( $ location [ 'ch' ] as $ fieldName => $ fields ) { foreach ( $ fields as $ field ) { $ childElement = $ XML -> createElement ( $ fieldName ) ; $ locationElement -> appendChild ( $ childElement ) ; $ childElement -> appendChild ( $ XML -> createTextNode ( $ field [ 'values' ] [ 0 ] ) ) ; if ( array_key_exists ( 'attr' , $ field ) ) { foreach ( $ field [ 'attr' ] as $ attributeName => $ attributeContent ) { $ childElement -> setAttribute ( $ attributeName , $ attributeContent ) ; } } } } } } return $ XML ; }
Returns XML representing the passed locations .
20,782
private function transformKey ( $ key ) { $ regEx = '/(?#! splitCamelCase Rev:20140412) # Split camelCase "words". Two global alternatives. Either g1of2: (?<=[a-z]) # Position is after a lowercase, (?=[A-Z]) # and before an uppercase letter. | (?<=[A-Z]) # Or g2of2; Position is after uppercase, (?=[A-Z][a-z]) # and before upper-then-lower case. /x' ; $ words = preg_split ( $ regEx , $ key ) ; $ envName = implode ( '_' , $ words ) ; $ envName = str_replace ( [ '.' , '_' , '-' ] , '_' , $ envName ) ; $ envName = strtoupper ( $ envName ) ; return $ envName ; }
Transforms the provided key to a environment variable name
20,783
protected function isFileEmpty ( $ value , $ file = null ) { $ source = null ; $ filename = null ; if ( is_string ( $ value ) && is_array ( $ file ) ) { $ filename = $ file [ 'name' ] ; $ source = $ file [ 'tmp_name' ] ; } elseif ( is_array ( $ value ) ) { if ( isset ( $ value [ 'tmp_name' ] ) ) { $ source = $ value [ 'tmp_name' ] ; } if ( isset ( $ value [ 'name' ] ) ) { $ filename = $ value [ 'name' ] ; } } else { $ source = $ value ; $ filename = basename ( $ source ) ; } return empty ( $ source ) || empty ( $ filename ) ; }
Indicates whether the file is defined .
20,784
public function replace ( UnitOfWork $ replacement ) { parent :: replace ( $ replacement ) ; $ this -> connection -> execute ( sprintf ( "DELETE FROM %s WHERE unique_id = ?" , $ this -> tableName ) , array ( $ replacement -> getUniqueId ( ) , ) ) ; unset ( $ this -> presentUidsOnConstruction [ $ replacement -> getUniqueId ( ) ] ) ; }
Next to replacing the unit internally the entry has to be also removed in the database
20,785
private function buildMigrations ( ) { $ unitDataArray = $ this -> loadUnitDataIteratorFromDatabase ( ) ; foreach ( $ unitDataArray as $ unitData ) { $ unitOfWork = UnitOfWorkFactory :: BuildFromFlatArray ( $ unitData ) ; $ this -> presentUidsOnConstruction [ $ unitOfWork -> getUniqueId ( ) ] = true ; $ this -> add ( $ unitOfWork ) ; } }
Builds the migrations from the database
20,786
private function loadUnitDataIteratorFromDatabase ( ) { $ result = $ this -> connection -> query ( sprintf ( "SELECT * FROM %s ORDER BY unique_id ASC" , $ this -> tableName ) ) ; return new \ ArrayIterator ( $ result ) ; }
Loads the UnitsOfWork from the database as Iterator
20,787
public static function Sp00 ( $ date1 , $ date2 ) { $ t ; $ sp ; $ t = ( ( $ date1 - DJ00 ) + $ date2 ) / DJC ; $ sp = - 47e-6 * $ t * DAS2R ; return $ sp ; }
- - - - - - - - i a u S p 0 0 - - - - - - - -
20,788
public static function match ( $ keyword , $ text = '' , & $ matches = false ) { return ( bool ) preg_match ( sprintf ( self :: $ re , self :: regex ( $ keyword ) ) , $ text , $ matches , PREG_OFFSET_CAPTURE ) ; }
Match romanian regex
20,789
public static function cuttext ( $ value , $ length = 200 , $ ellipsis = '...' ) { if ( ! is_array ( $ value ) ) { $ string = $ value ; $ match_to = $ value { 0 } ; } else list ( $ string , $ match_to ) = $ value ; self :: match ( $ match_to , $ string , $ matches ) ; $ match_start = isset ( $ matches [ 0 ] ) && isset ( $ matches [ 0 ] [ 1 ] ) ? mb_substr ( $ string , mb_strlen ( substr ( $ string , 0 , $ matches [ 0 ] [ 1 ] ) ) ) : false ; $ match_compute = $ match_start ? ( mb_strlen ( $ string ) - mb_strlen ( $ match_start ) ) : 0 ; if ( mb_strlen ( $ string ) > $ length ) { if ( $ match_compute < ( $ length - mb_strlen ( $ match_to ) ) ) { $ pre_string = mb_substr ( $ string , 0 , $ length ) ; $ pos_end = mb_strrpos ( $ pre_string , ' ' ) ; if ( $ pos_end === false ) $ string = trim ( $ pre_string ) . $ ellipsis ; else $ string = trim ( mb_substr ( $ pre_string , 0 , $ pos_end ) ) . $ ellipsis ; } else if ( $ match_compute > ( mb_strlen ( $ string ) - ( $ length - mb_strlen ( $ match_to ) ) ) ) { $ pre_string = mb_substr ( $ string , ( mb_strlen ( $ string ) - ( $ length - mb_strlen ( $ match_to ) ) ) ) ; $ pos_start = mb_strpos ( $ pre_string , ' ' ) ; if ( $ pos_start === false ) $ string = $ ellipsis . trim ( $ pre_string ) ; else $ string = $ ellipsis . trim ( mb_substr ( $ pre_string , $ pos_start ) ) ; } else { $ pre_string = mb_substr ( $ string , ( $ match_compute - round ( ( $ length / 3 ) ) ) , $ length ) ; $ pos_start = mb_strpos ( $ pre_string , ' ' ) ; if ( $ pos_start === false ) $ pre_string = $ ellipsis . trim ( $ pre_string ) ; else $ pre_string = $ ellipsis . trim ( mb_substr ( $ pre_string , $ pos_start ) ) ; $ pos_end = mb_strrpos ( $ pre_string , ' ' ) ; if ( $ pos_end === false ) $ pre_string = trim ( $ pre_string ) . $ ellipsis ; else $ pre_string = trim ( mb_substr ( $ pre_string , 0 , $ pos_end ) ) . $ ellipsis ; $ string = $ pre_string ; } } return trim ( $ string ) ; }
Cut text left middle right
20,790
public function bind ( $ ip = '0.0.0.0' , $ port = 8080 , $ ssl = false ) { $ this -> addNode ( new HttpListenerNode ( $ this , $ ip , $ port , $ ssl , $ this -> logger ) ) ; }
Creates listener using default HttpListenerNode class
20,791
private function upgradeClient ( ClientUpgradeException $ upgrade ) { $ oldClient = $ upgrade -> getOldClient ( ) ; if ( ! isset ( $ oldClient -> socket , $ this -> nodes [ ( int ) $ oldClient -> socket ] ) ) { $ this -> logger -> emergency ( "Client $oldClient not found during upgrade" ) ; throw new ServerException ( 'Tried to upgrade non existing client!' ) ; } $ this -> nodes [ ( int ) $ oldClient -> socket ] = $ upgrade -> getNewClient ( ) ; }
Upgrades client protocol . It s done by replacing whole client class in nodes table .
20,792
public function getClientId ( ) { if ( ! isset ( $ this -> _poolClientId ) ) { while ( ! isset ( $ id ) || ! $ this -> isPoolClientIdUnique ( $ id ) ) { $ id = static :: generatePoolClientId ( ) ; } $ this -> _poolClientId = $ id ; } return $ this -> _poolClientId ; }
Get client unique ID
20,793
protected function changeState ( $ state ) { $ currState = $ this -> _poolClientState ; if ( isset ( $ currState ) && $ currState !== PoolClientInterface :: CLIENT_POOL_STATE_LOCKED ) { $ this -> _poolClientStatePrev = $ currState ; } $ this -> _poolClientState = $ state ; $ this -> emit ( PoolClientInterface :: CLIENT_POOL_EVENT_CHANGE_STATE , [ $ state ] ) ; }
Change client state helper
20,794
protected function changeQueueCount ( $ queueCounter ) { if ( $ queueCounter < 0 ) { $ queueCounter = 0 ; } $ this -> _poolClientQueueCounter = $ queueCounter ; if ( $ this -> _poolClientQueueCounter === 0 && $ this -> _poolClientState === PoolClientInterface :: CLIENT_POOL_STATE_BUSY ) { $ this -> changeState ( PoolClientInterface :: CLIENT_POOL_STATE_READY ) ; } elseif ( $ this -> _poolClientQueueCounter > 0 && $ this -> _poolClientState === PoolClientInterface :: CLIENT_POOL_STATE_READY ) { $ this -> changeState ( PoolClientInterface :: CLIENT_POOL_STATE_BUSY ) ; } $ this -> emit ( PoolClientInterface :: CLIENT_POOL_EVENT_CHANGE_QUEUE , [ $ queueCounter ] ) ; }
Change client queue counter helper
20,795
private static function generatePoolClientId ( ) { $ now = ceil ( microtime ( true ) * 10000 ) ; if ( class_exists ( 'Reaction' , false ) ) { $ rand = \ Reaction :: $ app -> security -> generateRandomString ( 8 ) ; } else { $ rand = static :: randomStr ( ) ; } return static :: getClientIdPrefix ( ) . $ now . $ rand ; }
Generate random client ID
20,796
public function setRouteParameters ( $ routeParameters ) { if ( ! is_string ( $ routeParameters ) ) { $ this -> routeParameters = json_encode ( $ routeParameters ) ; } else { $ this -> routeParameters = $ routeParameters ; } return $ this ; }
Set routeParameters .
20,797
public function setFilterParameters ( $ filterParameters ) { if ( ! is_string ( $ filterParameters ) ) { $ this -> filterParameters = json_encode ( $ filterParameters ) ; } else { $ this -> filterParameters = $ filterParameters ; } return $ this ; }
Set filterParameters .
20,798
public function getDt ( ) { if ( is_null ( $ this -> dt ) ) { $ this -> dt = new Carbon ( ) ; $ this -> dt -> setTimezone ( $ this -> getTz ( ) ) ; } return $ this -> dt ; }
Returns an instance of our DateTime object
20,799
public function convertTimestamp ( $ date , $ format ) { if ( ! is_numeric ( $ date ) ) { $ date = strtotime ( $ date ) ; } return $ this -> getDt ( ) -> createFromTimestamp ( $ date , $ this -> getTz ( ) ) -> format ( $ format ) ; }
Converts a timestamp from one format to another