idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
2,700
|
public function addGroup ( Communicator $ communicator , ProcessedGroup $ group ) : ProcessedMembership { $ response = $ communicator -> post ( 'api/memberships' , new Membership ( $ group -> getID ( ) , $ this -> contactID ) ) ; $ returnValue = RecipientFactory :: createProcessedMembershipFromJSON ( $ response ) ; if ( $ this -> memberShipsFetched ) { $ this -> memberships [ ] = $ returnValue ; } return $ returnValue ; }
|
Adds the contact to the given group and returns the membership .
|
2,701
|
public static function classToName ( $ class , $ type ) { if ( ! class_exists ( $ class ) ) { throw new InvalidArgumentException ( "Class '" . $ class . "' not found!" ) ; } $ class = self :: _trimNamespace ( $ class ) ; if ( ! isset ( self :: $ masks [ $ type ] ) ) { throw new InvalidArgumentException ( "Invalid mask type " . $ type . "!" ) ; } $ mask = self :: _trimNamespace ( self :: $ masks [ $ type ] ) ; if ( $ mask === "*" ) { return $ class ; } preg_match ( "/" . str_replace ( "*" , "(.*)" , $ mask ) . "/" , $ class , $ match ) ; return $ match [ 1 ] ; }
|
Converts class to name
|
2,702
|
public static function nameToClass ( $ name , $ type ) { if ( ! isset ( self :: $ masks [ $ type ] ) ) { throw new InvalidArgumentException ( "Invalid mask type " . $ type . "!" ) ; } return str_replace ( "*" , $ name , self :: $ masks [ $ type ] ) ; }
|
Converts name to class
|
2,703
|
protected function addScript ( $ name , $ from = AssetsInterface :: ASSETS_JS , array $ dependencies = [ 'jquery' ] , $ version = '1.0.0' , $ inFooter = true , $ ajaxUrl = null ) { wp_enqueue_script ( $ name , $ this -> path ( $ from , $ name ) , $ dependencies , $ version , $ inFooter ) ; if ( null !== $ ajaxUrl ) { $ this -> registerAjaxUrls ( $ name , $ ajaxUrl ) ; } return $ this ; }
|
Method that wraps the WordPress internal wp_enqueue_script simplifying the process adding some common default values .
|
2,704
|
protected function addStylesheet ( $ name , $ from = AssetsInterface :: CSS , array $ dependencies = [ ] , $ version = '1.0.0' , $ media = 'all' ) { wp_enqueue_style ( $ name , $ this -> path ( $ from , $ name , 'css' ) , $ dependencies , $ version , $ media ) ; return $ this ; }
|
Method that wraps the WordPress internal wp_enqueue_style simplifying the process adding some common default values .
|
2,705
|
protected function registerAjaxUrls ( $ name , $ ajaxUrl ) { if ( false === is_array ( $ ajaxUrl ) ) { $ ajaxUrl = [ $ ajaxUrl ] ; } foreach ( $ ajaxUrl as $ url ) { wp_localize_script ( $ name , $ url , [ 'ajaxUrl' => admin_url ( 'admin-ajax.php' ) , ] ) ; } }
|
Registers the ajax urls inside given JS filename .
|
2,706
|
protected function pdepend ( $ path ) { $ jsonGenerator = new JsonGenerator ( ) ; $ jsonGenerator -> setLogFile ( $ path . DIRECTORY_SEPARATOR . $ this -> json ) ; $ application = new Application ( ) ; $ config = $ application -> getConfiguration ( ) ; $ config -> cache -> driver = 'file' ; $ config -> cache -> location = $ path . DIRECTORY_SEPARATOR . $ this -> pdepend ; $ engine = $ application -> getEngine ( ) ; $ engine -> addReportGenerator ( $ jsonGenerator ) ; $ engine -> addDirectory ( $ this -> config [ 'path' ] ) ; $ converter = new PathConverter ( $ this -> config [ 'path' ] , getcwd ( ) ) ; $ exclude = array_map ( array ( $ converter , 'convert' ) , $ this -> config [ 'exclude_folders' ] ) ; $ filter = new ExcludePathFilter ( $ exclude ) ; $ engine -> addFileFilter ( $ filter ) ; try { $ engine -> analyze ( ) ; } catch ( \ Exception $ e ) { throw new Exception ( 'Unable to generate pdepend metrics.' ) ; } }
|
Runs pdepend to generate the metrics .
|
2,707
|
public function createComponentZip ( ) { $ comZip = new \ ZipArchive ( JPATH_BASE . "/dist" , \ ZipArchive :: CREATE ) ; $ tmp_path = '/dist/tmp/cbuild' ; if ( file_exists ( JPATH_BASE . $ tmp_path ) ) { $ this -> _deleteDir ( JPATH_BASE . $ tmp_path ) ; } $ this -> _mkdir ( JPATH_BASE . $ tmp_path ) ; $ this -> _copyDir ( $ this -> current . '/administrator' , JPATH_BASE . $ tmp_path . '/administrator' ) ; $ this -> _remove ( JPATH_BASE . $ tmp_path . '/administrator/manifests' ) ; $ this -> _copyDir ( $ this -> current . '/language' , JPATH_BASE . $ tmp_path . '/language' ) ; $ this -> _copyDir ( $ this -> current . '/components' , JPATH_BASE . $ tmp_path . '/components' ) ; if ( file_exists ( $ this -> current . '/media' ) ) { $ this -> _copyDir ( $ this -> current . '/media' , JPATH_BASE . $ tmp_path . '/media' ) ; } $ comZip -> open ( JPATH_BASE . '/dist/zips/com_' . $ this -> getExtensionName ( ) . '.zip' , \ ZipArchive :: CREATE ) ; $ this -> addFiles ( $ comZip , JPATH_BASE . $ tmp_path ) ; $ comZip -> addFile ( $ this -> current . "/" . $ this -> getExtensionName ( ) . ".xml" , $ this -> getExtensionName ( ) . ".xml" ) ; $ comZip -> addFile ( $ this -> current . "/administrator/components/com_" . $ this -> getExtensionName ( ) . "/script.php" , "script.php" ) ; $ comZip -> close ( ) ; }
|
Create a installable zip file for a component
|
2,708
|
public function createLibraryZips ( ) { $ path = $ this -> current . "/libraries" ; $ hdl = opendir ( $ path ) ; while ( $ lib = readdir ( $ hdl ) ) { $ p = $ path . "/" . $ lib ; if ( substr ( $ lib , 0 , 1 ) == '.' ) { continue ; } if ( substr ( $ lib , 0 , 3 ) != "lib" ) { $ lib = 'lib_' . $ lib ; } if ( ! is_file ( $ p ) ) { $ this -> say ( "Packaging Library " . $ lib ) ; $ zip = new \ ZipArchive ( JPATH_BASE . "/dist" , \ ZipArchive :: CREATE ) ; $ zip -> open ( JPATH_BASE . '/dist/zips/' . $ lib . '.zip' , \ ZipArchive :: CREATE ) ; $ this -> say ( "Library " . $ p ) ; $ this -> addFiles ( $ zip , $ p ) ; $ zip -> close ( ) ; } } closedir ( $ hdl ) ; }
|
Create zips for libraries
|
2,709
|
public function createModuleZips ( ) { $ path = $ this -> current . "/modules" ; $ hdl = opendir ( $ path ) ; while ( $ entry = readdir ( $ hdl ) ) { $ p = $ path . "/" . $ entry ; if ( substr ( $ entry , 0 , 1 ) == '.' ) { continue ; } if ( ! is_file ( $ p ) ) { $ this -> say ( "Packaging Module " . $ entry ) ; $ zip = new \ ZipArchive ( JPATH_BASE . "/dist" , \ ZipArchive :: CREATE ) ; $ zip -> open ( JPATH_BASE . '/dist/zips/' . $ entry . '.zip' , \ ZipArchive :: CREATE ) ; $ this -> say ( "Module " . $ p ) ; $ this -> addFiles ( $ zip , $ p ) ; $ zip -> close ( ) ; } } closedir ( $ hdl ) ; }
|
Create zips for modules
|
2,710
|
public function createPluginZips ( ) { $ path = $ this -> current . "/plugins" ; $ hdl = opendir ( $ path ) ; while ( $ entry = readdir ( $ hdl ) ) { $ p = $ path . "/" . $ entry ; if ( substr ( $ entry , 0 , 1 ) == '.' ) { continue ; } if ( ! is_file ( $ p ) ) { $ type = $ entry ; $ hdl2 = opendir ( $ p ) ; while ( $ plugin = readdir ( $ hdl2 ) ) { if ( substr ( $ plugin , 0 , 1 ) == '.' ) { continue ; } $ p2 = $ path . "/" . $ type . "/" . $ plugin ; if ( ! is_file ( $ p2 ) ) { $ plg = "plg_" . $ type . "_" . $ plugin ; $ this -> say ( "Packaging Plugin " . $ plg ) ; $ zip = new \ ZipArchive ( JPATH_BASE . "/dist" , \ ZipArchive :: CREATE ) ; $ zip -> open ( JPATH_BASE . '/dist/zips/' . $ plg . '.zip' , \ ZipArchive :: CREATE ) ; $ this -> addFiles ( $ zip , $ p2 ) ; $ zip -> close ( ) ; } } closedir ( $ hdl2 ) ; } } closedir ( $ hdl ) ; }
|
Create zips for plugins
|
2,711
|
public function translate ( $ key , $ package = 'default' , $ locale = '' , $ default = null ) { $ defaultLocale = Locale :: getDefault ( ) ; $ locale = $ locale ? : Locale :: get ( ) ; $ locale = $ locale ? : $ defaultLocale ; $ translation = null ; $ fallbackList = LocaleHelper :: getLocaleFallbackList ( $ locale , $ defaultLocale ) ; foreach ( $ fallbackList as $ locale ) { $ translation = ( $ translation ? : $ this -> processor -> get ( $ key , $ locale , $ package , null ) ) ; if ( ! is_null ( $ translation ) ) { break ; } } if ( is_null ( $ default ) && $ translation === $ default ) { throw new Exception ( 'The translation for [' . $ package . ']->[' . $ key . '] is not found in any locale [' . implode ( ', ' , $ fallbackList ) . '].' ) ; } return $ translation ? : $ default ; }
|
Get a translation value . If there is no value for the given locale it tries to fallback to default locale . If the default value is null and no translation is found it throws Exception .
|
2,712
|
protected function getValue ( $ field ) { $ value = null ; $ readField = 'get' . $ field ; foreach ( $ this -> readProfiles as $ profile ) { $ value = $ profile -> $ readField ( ) ; if ( $ value !== null ) { $ this -> setValue ( $ field , $ value ) ; break ; } } return $ value ; }
|
Searches all profiles for the given value
|
2,713
|
private function purgeRecurse ( $ dir ) { $ base = $ dir . '/' ; $ time = time ( ) ; if ( substr ( $ dir , 0 , strlen ( $ this -> dir ) ) !== $ this -> dir ) { assert ( 0 ) ; return ; } foreach ( scandir ( $ dir ) as $ f ) { $ fn = $ base . $ f ; if ( $ f [ 0 ] === '.' ) { continue ; } if ( is_dir ( $ fn ) ) { $ this -> purgeRecurse ( $ fn ) ; } else { $ update = filemtime ( $ fn ) ; if ( $ time - $ update > $ this -> timeout ) { unlink ( $ fn ) ; } } } }
|
Purges the contents of a directory recursively
|
2,714
|
protected function generateClassName ( $ tableName , $ short = false ) { $ ns = null ; if ( list ( $ prefix , $ ns ) = $ this -> tablePrefixMatches ( $ tableName ) ) { $ tableName = substr ( $ tableName , strlen ( $ prefix ) ) ; } $ className = parent :: generateClassName ( $ tableName ) ; if ( null !== $ ns && $ short === false ) { $ className = '\\' . trim ( $ this -> ns . '\\' . $ ns , '\\' ) . '\\' . $ className ; } return $ className ; }
|
Generates a class name with namespace prefix from the specified table name .
|
2,715
|
public static function fromPairs ( $ array ) { if ( ! is_array ( $ array ) && ! ( $ array instanceof \ Traversable ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Dictionary::fromPairs() argument must be array or Traversable, ' . 'but is "%s".' , gettype ( $ array ) ) ) ; } $ result = new Dictionary ( ) ; foreach ( $ array as $ pair ) { if ( ! is_array ( $ pair ) || ! isset ( $ pair [ 0 ] ) || ! isset ( $ pair [ 1 ] ) ) { throw new \ InvalidArgumentException ( 'Each element of array or Traversable passed to Dictionary::FromPairs()' . ' must be two-elements array.' ) ; } $ result [ $ pair [ 0 ] ] = $ pair [ 1 ] ; } return $ result ; }
|
Create new Dictionary from array of key - value pairs .
|
2,716
|
public static function fromArray ( $ array ) { if ( ! is_array ( $ array ) && ! ( $ array instanceof \ Traversable ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Dictionary::fromArray() argument must be array or Traversable, ' . 'but is "%s".' , gettype ( $ array ) ) ) ; } $ result = new Dictionary ( ) ; foreach ( $ array as $ key => $ value ) { $ result [ $ key ] = $ value ; } return $ result ; }
|
Create new Dictionary from standard PHP array .
|
2,717
|
public function toPairs ( ) { $ result = [ ] ; foreach ( $ this as $ key => $ value ) { $ result [ ] = [ $ key , $ value ] ; } return $ result ; }
|
Get array of all key - value pairs in dictionary .
|
2,718
|
public function sortBy ( $ callback = null , $ direction = 'ASC' ) { if ( ! is_callable ( $ callback ) ) { if ( is_null ( $ callback ) or is_string ( $ callback ) && 'values' === strtolower ( $ callback ) ) { $ callback = function ( $ value , $ key ) { return $ value ; } ; } else if ( is_string ( $ callback ) && 'keys' === strtolower ( $ callback ) ) { $ callback = function ( $ value , $ key ) { return $ key ; } ; } else { throw new \ InvalidArgumentException ( sprintf ( 'Dictionary::sort() argument must be "keys", "values" or callable, ' . 'but is "%s".' , gettype ( $ callback ) ) ) ; } } if ( $ direction !== SORT_ASC && $ direction !== SORT_DESC ) { if ( is_string ( $ direction ) ) { switch ( strtolower ( $ direction ) ) { case 'asc' : $ direction = SORT_ASC ; break ; case 'desc' : $ direction = SORT_DESC ; break ; default : throw new \ InvalidArgumentException ( sprintf ( 'Direction must be "asc" or "desc", but is "%s".' , $ direction ) ) ; } } else { throw new \ InvalidArgumentException ( sprintf ( 'Direction must be string "asc" or "desc", but is "%s".' , gettype ( $ direction ) ) ) ; } } $ order = [ ] ; foreach ( $ this as $ key => $ value ) { $ order [ ] = $ callback ( $ value , $ key ) ; } array_multisort ( $ order , $ direction , SORT_REGULAR , $ this -> data , $ this -> keys ) ; return $ this ; }
|
Sort Dictionary by values returned by callback .
|
2,719
|
private function handle ( $ handler , $ parameters ) { if ( $ handler instanceof \ Closure ) { $ this -> app -> execute ( $ handler , $ parameters ) ; } else { list ( $ controller , $ action ) = explode ( '@' , $ handler ) ; $ class = $ this -> app -> construct ( $ controller ) ; $ this -> app -> execute ( [ $ class , $ action ] , $ parameters ) ; } }
|
Handler for route found support Closure and Controller methods .
|
2,720
|
public static function createFromConfig ( array $ config ) { $ fields = [ ] ; foreach ( $ config as $ name => $ field ) { $ fields [ $ name ] = Fields :: create ( $ name , $ field ) ; } return new static ( $ fields ) ; }
|
Method to create form fieldset object and fields from config
|
2,721
|
public function setCurrent ( $ i ) { $ this -> current = ( int ) $ i ; if ( ! isset ( $ this -> fields [ $ this -> current ] ) ) { $ this -> fields [ $ this -> current ] = [ ] ; } return $ this ; }
|
Method to get current group index
|
2,722
|
public function insertFieldAfter ( $ name , Element \ AbstractElement $ field ) { foreach ( $ this -> fields as $ i => $ group ) { $ fields = [ ] ; foreach ( $ group as $ key => $ value ) { if ( $ key == $ name ) { $ fields [ $ key ] = $ value ; $ fields [ $ field -> getName ( ) ] = $ field ; } else { $ fields [ $ key ] = $ value ; } } $ this -> fields [ $ i ] = $ fields ; } return $ this ; }
|
Method to insert a field after another one
|
2,723
|
public function count ( ) { $ count = 0 ; foreach ( $ this -> fields as $ group ) { $ count += count ( $ group ) ; } return $ count ; }
|
Method to get the count of elements in the form fieldset
|
2,724
|
public function hasField ( $ name ) { $ result = false ; foreach ( $ this -> fields as $ key => $ fields ) { if ( isset ( $ fields [ $ name ] ) ) { $ result = true ; break ; } } return $ result ; }
|
Method to determine if the fieldset has a field
|
2,725
|
public function getFields ( $ i ) { return ( isset ( $ this -> fields [ $ i ] ) ) ? $ this -> fields [ $ i ] : null ; }
|
Method to get field element objects in a group
|
2,726
|
public function getAllFields ( ) { $ fields = [ ] ; foreach ( $ this -> fields as $ group ) { foreach ( $ group as $ field ) { $ fields [ $ field -> getName ( ) ] = $ field ; } } return $ fields ; }
|
Method to get all field elements
|
2,727
|
public function prepareForView ( ) { $ fields = [ ] ; foreach ( $ this -> fields as $ groups ) { foreach ( $ groups as $ field ) { if ( null !== $ field -> getLabel ( ) ) { $ labelFor = $ field -> getName ( ) . ( ( $ field -> getNodeName ( ) == 'fieldset' ) ? '1' : '' ) ; $ label = new Child ( 'label' , $ field -> getLabel ( ) ) ; $ label -> setAttribute ( 'for' , $ labelFor ) ; if ( null !== $ field -> getLabelAttributes ( ) ) { $ label -> setAttributes ( $ field -> getLabelAttributes ( ) ) ; } if ( $ field -> isRequired ( ) ) { if ( $ label -> hasAttribute ( 'class' ) ) { $ label -> setAttribute ( 'class' , $ label -> getAttribute ( 'class' ) . ' required' ) ; } else { $ label -> setAttribute ( 'class' , 'required' ) ; } } $ fields [ $ field -> getName ( ) . '_label' ] = $ label -> render ( ) ; } if ( null !== $ field -> getHint ( ) ) { $ hint = new Child ( 'span' , $ field -> getHint ( ) ) ; if ( null !== $ field -> getHintAttributes ( ) ) { $ hint -> setAttributes ( $ field -> getHintAttributes ( ) ) ; } $ fields [ $ field -> getName ( ) . '_hint' ] = $ hint -> render ( ) ; } if ( $ field -> hasErrors ( ) ) { $ fields [ $ field -> getName ( ) . '_errors' ] = $ field -> getErrors ( ) ; } $ fields [ $ field -> getName ( ) ] = $ field -> render ( ) ; } } return $ fields ; }
|
Prepare fieldset elements for rendering with a view
|
2,728
|
public function getUserModel ( ) { $ model = Config :: get ( 'auth.model' ) ; if ( class_exists ( $ model ) ) { return $ model ; } $ ns = $ this -> getAppNamespace ( ) ; if ( $ ns ) { $ model = $ ns . 'User' ; if ( class_exists ( $ model ) ) { return $ model ; } $ model = $ ns . 'Models\User' ; if ( class_exists ( $ model ) ) { return $ model ; } } return false ; }
|
Gets the user model if found .
|
2,729
|
public function createGuest ( ) { $ model = $ this -> getUserModel ( ) ; if ( $ model ) { $ guest = new $ model ( ) ; $ guest -> name = 'Guest' ; $ guest -> email = 'guest@example.com' ; } else { $ guest = ( object ) [ 'name' => 'Guest' , 'email' => 'guest@example.com' ] ; } return $ guest ; }
|
Return an instance of a guest user uses user model if exists .
|
2,730
|
public static function getVersion ( $ path , $ strict = false ) { $ version = 'unknown' ; $ temp_path = getcwd ( ) ; chdir ( $ path ) ; do { $ descriptorspec = array ( 0 => array ( 'pipe' , 'r' ) , 1 => array ( 'pipe' , 'w' ) , 2 => array ( 'pipe' , 'w' ) , ) ; $ process = proc_open ( 'git describe' , $ descriptorspec , $ pipes ) ; $ return_value = null ; if ( is_resource ( $ process ) ) { $ raw_version = stream_get_contents ( $ pipes [ 1 ] ) ; $ errors = stream_get_contents ( $ pipes [ 2 ] ) ; $ return_value = proc_close ( $ process ) ; } if ( $ return_value !== 0 ) { break ; } if ( 1 === preg_match ( '/^v?(\d+\.\d+.\d+)(?:\-(\d+)\-[\w\d]+)?$/' , $ raw_version , $ matches ) ) { if ( isset ( $ matches [ 2 ] ) ) { if ( $ strict ) { break ; } else { $ version = $ matches [ 1 ] . '+' . $ matches [ 2 ] ; } } else { $ version = $ matches [ 1 ] ; } } else { break ; } } while ( false ) ; chdir ( $ temp_path ) ; return $ version ; }
|
Determine the git version based on git describe and semver conventions .
|
2,731
|
public function afterFind ( ) { if ( $ this -> autoFetchProperties === true ) { $ owner = $ this -> owner ; $ owner -> ensurePropertyGroupIds ( ) ; $ models = [ & $ owner ] ; PropertiesHelper :: fillProperties ( $ models ) ; } return true ; }
|
Performs auto fetching properties if it is turned on
|
2,732
|
public function beforeDelete ( ) { $ owner = $ this -> owner ; $ event = new HasPropertiesEvent ( ) ; $ event -> model = $ owner ; HasPropertiesEvent :: trigger ( self :: class , self :: EVENT_BEFORE_DELETE , $ event ) ; $ array = [ & $ owner ] ; PropertiesHelper :: deleteAllProperties ( $ array ) ; unset ( $ array ) ; return true ; }
|
Deletes related properties from database
|
2,733
|
public function hasPropertyKey ( $ key ) { $ owner = $ this -> owner ; $ owner -> ensurePropertiesAttributes ( ) ; return in_array ( $ key , $ owner -> propertiesAttributes ) ; }
|
Returns if property is binded to model
|
2,734
|
public function afterInsert ( ) { $ owner = $ this -> owner ; $ groups = $ owner -> propertyGroupIds ; $ owner -> propertyGroupIds = null ; $ event = new HasPropertiesEvent ( ) ; $ event -> model = $ owner ; HasPropertiesEvent :: trigger ( self :: class , self :: EVENT_AFTER_SAVE , $ event ) ; if ( count ( $ groups ) > 0 ) { foreach ( $ groups as $ group_id ) { $ group = PropertyGroup :: findOne ( [ 'id' => $ group_id ] ) ; if ( $ group ) { $ owner -> addPropertyGroup ( $ group ) ; } } } $ handlers = PropertyStorageHelper :: getHandlersForModel ( $ owner ) ; $ models = [ & $ owner ] ; foreach ( $ handlers as $ handler ) { $ handler -> modelsInserted ( $ models ) ; } $ this -> afterSave ( ) ; }
|
Performs after insert stuff
|
2,735
|
public function indexAction ( ) { $ optionsProvider = $ this -> getOptionsProvider ( ) ; if ( $ this -> getRequest ( ) -> isPost ( ) ) { $ event = $ this -> request -> getPost ( 'suboperation' ) ; if ( ! empty ( $ event ) ) { $ events = $ this -> getEventManager ( ) ; $ params = $ this -> request -> getPost ( ) ; $ result = $ events -> trigger ( $ event , $ this , $ params ) ; if ( $ result -> last ( ) instanceof Response ) { return $ result -> last ( ) ; } } } $ lists = $ this -> getContentListProvider ( ) ; $ view = new ViewModel ( [ 'optionsProvider' => $ optionsProvider , 'contentListsProvider' => $ lists ] ) ; $ flashMessenger = $ this -> flashMessenger ( ) ; if ( $ flashMessenger -> hasMessages ( ) ) { $ view -> messages = $ flashMessenger -> getMessages ( ) ; } return $ view ; }
|
Show content list .
|
2,736
|
public function searchAction ( ) { $ optionsProvider = $ this -> getOptionsProvider ( ) ; $ pane = $ this -> params ( ) -> fromRoute ( 'pane' ) ; if ( ! $ pane || ! $ optionsProvider -> hasIdentifier ( $ pane ) ) { $ pane = 'first' ; } $ options = $ optionsProvider -> getOptions ( $ pane , 'search' ) ; $ search = $ optionsProvider -> getSearchProxy ( $ pane ) ; $ form = $ this -> getSearchForm ( ) ; $ form -> setAttribute ( 'action' , $ this -> url ( ) -> fromRoute ( 'sc-admin/content-search' , [ 'pane' => $ pane ] ) ) ; $ form -> bind ( $ search ) ; if ( $ this -> getRequest ( ) -> isPost ( ) ) { $ post = $ this -> params ( ) -> fromPost ( ) ; if ( array_key_exists ( 'clean' , $ post ) ) { $ search -> clean ( ) ; } else { $ form -> setData ( $ post ) ; } if ( $ form -> isValid ( ) ) { $ options -> setSearchOptions ( $ form -> getData ( ContentSearchForm :: VALUES_AS_ARRAY ) ) ; $ optionsProvider -> save ( $ options -> getName ( ) ) ; } } $ list = $ this -> getContentListProvider ( ) -> getList ( $ pane ) ; return new ViewModel ( [ 'options' => $ options , 'list' => $ list , 'pane' => $ pane , 'form' => $ form , ] ) ; }
|
Show search options .
|
2,737
|
public static function nearestColor ( $ refLabs , $ lab , $ algorithm , $ returnArrayKey = false , $ cacheKey = "" ) { $ subKey = $ lab [ 0 ] . $ lab [ 1 ] . $ lab [ 2 ] ; $ result = array ( ) ; if ( empty ( $ cacheKey ) || ! isset ( static :: $ nearestColors [ $ cacheKey ] ) || ! isset ( static :: $ nearestColors [ $ cacheKey ] [ $ subKey ] ) ) { $ nearestColor = [ 0 , 10000 ] ; foreach ( $ refLabs as $ key => $ refLab ) { $ distance = static :: { $ algorithm } ( $ refLab , $ lab ) ; if ( $ distance < $ nearestColor [ 1 ] ) { $ nearestColor = [ $ key , $ distance ] ; } } $ result = array ( $ nearestColor [ 0 ] , $ refLabs [ $ nearestColor [ 0 ] ] ) ; if ( ! empty ( $ cacheKey ) ) { if ( ! isset ( static :: $ nearestColors [ $ cacheKey ] ) ) { static :: $ nearestColors [ $ cacheKey ] = array ( ) ; } static :: $ nearestColors [ $ cacheKey ] [ $ subKey ] = $ result ; } } if ( empty ( $ result ) ) { $ result = static :: $ nearestColors [ $ cacheKey ] [ $ subKey ] ; } if ( $ returnArrayKey ) { return $ result [ 0 ] ; } return $ result [ 1 ] ; }
|
Searches a list of colors for the one with the shortest distance to a given color
|
2,738
|
public function fetch ( $ key ) { $ key = $ this -> get_key ( $ key ) ; return wp_cache_get ( $ key , $ this -> group ) ; }
|
Fetch cache data .
|
2,739
|
public function save ( $ key , $ value , $ expire = 0 ) { $ key = $ this -> get_key ( $ key ) ; wp_cache_set ( $ key , $ value , $ this -> group , $ expire ) ; }
|
Save cache data .
|
2,740
|
public function getFormatter ( ) { $ fmt = $ this -> settings -> format ; $ formatter = null ; if ( ! is_string ( $ fmt ) && is_subclass_of ( $ fmt , 'Luminous\\Formatters\\Formatter' ) ) { $ formatter = clone $ fmt ; } elseif ( $ fmt === 'html' ) { $ formatter = new HtmlFormatter ( ) ; } elseif ( $ fmt === 'html-inline' ) { $ formatter = new InlineHtmlFormatter ( ) ; } elseif ( $ fmt === 'html-full' ) { $ formatter = new FullPageHtmlFormatter ( ) ; } elseif ( $ fmt === 'latex' ) { $ formatter = new LatexFormatter ( ) ; } elseif ( $ fmt === 'ansi' ) { $ formatter = new AnsiFormatter ( ) ; } elseif ( $ fmt === null || $ fmt === 'none' ) { $ formatter = new IdentityFormatter ( ) ; } if ( $ formatter === null ) { throw new Exception ( 'Unknown formatter: ' . $ this -> settings -> format ) ; return null ; } $ this -> setFormatterOptions ( $ formatter ) ; return $ formatter ; }
|
Returns an instance of the current formatter
|
2,741
|
public function highlight ( $ scanner , $ source , $ settings = null ) { $ oldSettings = null ; if ( $ settings !== null ) { if ( ! is_array ( $ settings ) ) { throw new Exception ( 'Luminous internal error: Settings is not an array' ) ; } $ oldSettings = clone $ this -> settings ; foreach ( $ settings as $ k => $ v ) { $ this -> settings -> set ( $ k , $ v ) ; } } $ shouldResetLanguage = false ; $ this -> cache = null ; if ( ! is_string ( $ source ) ) { throw new InvalidArgumentException ( 'Non-string supplied for $source' ) ; } if ( ! ( $ scanner instanceof Scanner ) ) { if ( ! is_string ( $ scanner ) ) { throw new InvalidArgumentException ( 'Non-string or LuminousScanner instance supplied for $scanner' ) ; } $ code = $ scanner ; $ scanner = $ this -> scanners -> GetScanner ( $ code ) ; if ( $ scanner === null ) { throw new Exception ( "No known scanner for '$code' and no default set" ) ; } $ shouldResetLanguage = true ; $ this -> language = $ this -> scanners -> GetDescription ( $ code ) ; } $ cacheHit = true ; $ out = null ; if ( $ this -> settings -> cache ) { $ cacheId = $ this -> cacheId ( $ scanner , $ source ) ; if ( $ this -> settings -> sqlFunction !== null ) { $ this -> cache = new SqlCache ( $ cacheId ) ; $ this -> cache -> setSqlFunction ( $ this -> settings -> sqlFunction ) ; } else { $ this -> cache = new FileSystemCache ( $ cacheId ) ; } $ this -> cache -> setPurgeTime ( $ this -> settings -> cacheAge ) ; $ out = $ this -> cache -> read ( ) ; } if ( $ out === null ) { $ cacheHit = false ; $ outRaw = $ scanner -> highlight ( $ source ) ; $ formatter = $ this -> getFormatter ( ) ; $ out = $ formatter -> format ( $ outRaw ) ; } if ( $ this -> settings -> cache && ! $ cacheHit ) { $ this -> cache -> write ( $ out ) ; } if ( $ shouldResetLanguage ) { $ this -> language = null ; } if ( $ oldSettings !== null ) { $ this -> settings = $ oldSettings ; } return $ out ; }
|
The real highlighting function
|
2,742
|
public function persistence ( $ provider , array $ params = array ( ) ) { $ this -> persistence = array_merge ( array ( Config :: PROVIDER => $ provider ) , array ( Config :: PARAMS => $ params ) ) ; return $ this ; }
|
Set persistence provider
|
2,743
|
public function cache ( $ provider , array $ params = array ( ) ) { $ this -> cache = array_merge ( array ( config :: PROVIDER => $ provider ) , array ( Config :: PARAMS => $ params ) ) ; return $ this ; }
|
Set Cache provider
|
2,744
|
public function logDir ( $ dir ) { $ this -> logDir = $ dir ; $ this -> buildFileLogger ( $ this -> logDir ) ; return $ this ; }
|
Set logging directory
|
2,745
|
protected static function getResolvedClassInstance ( ) { $ classNamespace = static :: getStaticClassAccessor ( ) ; $ resolvedClassInstance = self :: getClass ( $ classNamespace ) ; if ( ! $ resolvedClassInstance ) { return self :: resolveClassNameSpace ( $ classNamespace ) ; } return $ resolvedClassInstance ; }
|
Check if the class namespace already have a cached resolved instance if not then the class namespace must be resolve .
|
2,746
|
protected static function resolveClassNameSpace ( $ classNamespace ) { if ( ! \ is_string ( $ classNamespace ) ) { throw ClassNamespaceResolverException :: isNotString ( ) ; } if ( ! \ class_exists ( $ classNamespace ) ) { throw ClassNamespaceResolverException :: isNotExist ( ) ; } $ classNamespace = self :: classNamespaceDecorator ( $ classNamespace ) ; $ classInstance = new $ classNamespace ( ) ; self :: setClass ( $ classNamespace , $ classInstance ) ; return $ classInstance ; }
|
Resolver for service class namespace . Set the resolved service class instance to the class property .
|
2,747
|
private function _initType ( $ definition ) { if ( isset ( self :: $ typeAliases [ $ definition ] ) ) { $ definition = self :: $ typeAliases [ $ definition ] ; } if ( self :: isScalarType ( $ definition ) || in_array ( $ definition , [ self :: TYPE_ARRAY , self :: TYPE_DATE , self :: TYPE_DATETIME ] , true ) ) { $ this -> type = $ definition ; } elseif ( class_exists ( Convention :: nameToClass ( $ definition , Convention :: ENTITY_MASK ) ) ) { $ this -> type = self :: TYPE_ENTITY ; $ this -> typeOption = $ definition ; } elseif ( substr ( $ definition , - 2 ) === "[]" ) { $ this -> type = self :: TYPE_COLLECTION ; $ this -> typeOption = rtrim ( $ definition , "[]" ) ; } else { throw new Exception \ PropertyException ( "Unsupported type '" . $ definition . "'!" ) ; } }
|
Initialize property type
|
2,748
|
public function convertValue ( $ value ) { if ( $ value === null || ( $ value === "" && $ this -> type !== self :: TYPE_STRING ) ) { return ; } if ( self :: isScalarType ( $ this -> type ) || $ this -> type === self :: TYPE_ARRAY ) { if ( $ this -> type === self :: TYPE_BOOLEAN && strtolower ( $ value ) === "false" ) { return false ; } if ( is_scalar ( $ value ) || $ this -> type === self :: TYPE_ARRAY ) { if ( settype ( $ value , $ this -> type ) ) { return $ value ; } } } elseif ( $ this -> type === self :: TYPE_DATETIME || $ this -> type === self :: TYPE_DATE ) { if ( $ value instanceof \ DateTime ) { return $ value ; } elseif ( is_array ( $ value ) && isset ( $ value [ "date" ] ) ) { $ date = $ value [ "date" ] ; } elseif ( is_object ( $ value ) && isset ( $ value -> date ) ) { $ date = $ value -> date ; } else { $ date = $ value ; } if ( isset ( $ date ) ) { try { return new \ DateTime ( $ date ) ; } catch ( \ Exception $ e ) { } } } elseif ( $ this -> type === self :: TYPE_COLLECTION && Validator :: isTraversable ( $ value ) ) { return new Entity \ Collection ( $ this -> typeOption , $ value ) ; } elseif ( $ this -> type === self :: TYPE_ENTITY && Validator :: isTraversable ( $ value ) ) { return Entity \ Reflection :: load ( $ this -> typeOption ) -> createEntity ( $ value ) ; } throw new Exception \ InvalidArgumentException ( "Can not convert value on property '" . $ this -> name . "' automatically!" , $ value ) ; }
|
Try to convert value on required type automatically
|
2,749
|
protected function renderNamespace ( $ ns , $ directives ) { $ ret = '' ; $ ret .= $ this -> start ( 'tbody' , array ( 'class' => 'namespace' ) ) ; $ ret .= $ this -> start ( 'tr' ) ; $ ret .= $ this -> element ( 'th' , $ ns , array ( 'colspan' => 2 ) ) ; $ ret .= $ this -> end ( 'tr' ) ; $ ret .= $ this -> end ( 'tbody' ) ; $ ret .= $ this -> start ( 'tbody' ) ; foreach ( $ directives as $ directive => $ value ) { $ ret .= $ this -> start ( 'tr' ) ; $ ret .= $ this -> start ( 'th' ) ; if ( $ this -> docURL ) { $ url = str_replace ( '%s' , urlencode ( "$ns.$directive" ) , $ this -> docURL ) ; $ ret .= $ this -> start ( 'a' , array ( 'href' => $ url ) ) ; } $ attr = array ( 'for' => "{$this->name}:$ns.$directive" ) ; if ( ! $ this -> compress || ( strlen ( $ directive ) < $ this -> compress ) ) { $ directive_disp = $ directive ; } else { $ directive_disp = substr ( $ directive , 0 , $ this -> compress - 2 ) . '...' ; $ attr [ 'title' ] = $ directive ; } $ ret .= $ this -> element ( 'label' , $ directive_disp , $ attr ) ; if ( $ this -> docURL ) $ ret .= $ this -> end ( 'a' ) ; $ ret .= $ this -> end ( 'th' ) ; $ ret .= $ this -> start ( 'td' ) ; $ def = $ this -> config -> def -> info [ "$ns.$directive" ] ; if ( is_int ( $ def ) ) { $ allow_null = $ def < 0 ; $ type = abs ( $ def ) ; } else { $ type = $ def -> type ; $ allow_null = isset ( $ def -> allow_null ) ; } if ( ! isset ( $ this -> fields [ $ type ] ) ) $ type = 0 ; $ type_obj = $ this -> fields [ $ type ] ; if ( $ allow_null ) { $ type_obj = new HTMLPurifier_Printer_ConfigForm_NullDecorator ( $ type_obj ) ; } $ ret .= $ type_obj -> render ( $ ns , $ directive , $ value , $ this -> name , array ( $ this -> genConfig , $ this -> config ) ) ; $ ret .= $ this -> end ( 'td' ) ; $ ret .= $ this -> end ( 'tr' ) ; } $ ret .= $ this -> end ( 'tbody' ) ; return $ ret ; }
|
Renders a single namespace
|
2,750
|
public function parseJson ( $ json ) { $ this -> mentionName = $ json [ 'mention_name' ] ; $ this -> id = $ json [ 'id' ] ; $ this -> name = $ json [ 'name' ] ; if ( isset ( $ json [ 'links' ] ) ) { $ this -> links = $ json [ 'links' ] ; } if ( isset ( $ json [ 'xmpp_jid' ] ) ) { $ this -> xmppJid = $ json [ 'xmpp_jid' ] ; $ this -> deleted = $ json [ 'is_deleted' ] ; $ this -> lastActive = $ json [ 'last_active' ] ; $ this -> title = $ json [ 'title' ] ; $ this -> created = new \ Datetime ( $ json [ 'created' ] ) ; $ this -> groupAdmin = $ json [ 'is_group_admin' ] ; $ this -> timezone = $ json [ 'timezone' ] ; $ this -> guest = $ json [ 'is_guest' ] ; $ this -> email = $ json [ 'email' ] ; $ this -> photoUrl = $ json [ 'photo_url' ] ; } }
|
Parses response given by the API and maps the fields to User object
|
2,751
|
public function call ( $ method , $ url , array $ post = array ( ) , array $ headers = array ( ) ) { $ options = array ( CURLOPT_URL => $ url , CURLOPT_RETURNTRANSFER => true , CURLOPT_HTTPHEADER => $ headers , ) ; switch ( $ method ) { case HttpMethod :: GET : $ options [ CURLOPT_POST ] = false ; break ; case HttpMethod :: POST : $ options [ CURLOPT_POST ] = true ; $ options [ CURLOPT_POSTFIELDS ] = json_encode ( $ post ) ; break ; case HttpMethod :: PUT : $ options [ CURLOPT_CUSTOMREQUEST ] = 'PUT' ; $ options [ CURLOPT_POSTFIELDS ] = json_encode ( $ post ) ; break ; case HttpMethod :: DELETE : $ options [ CURLOPT_CUSTOMREQUEST ] = 'DELETE' ; $ options [ CURLOPT_POSTFIELDS ] = json_encode ( $ post ) ; break ; default : throw new InvalidArgumentException ( sprintf ( 'Invalid method: %s' , $ method ) ) ; } $ this -> curl -> init ( ) ; $ this -> curl -> setOptArray ( $ options ) ; $ rawResponse = $ this -> curl -> exec ( 1 , true ) ; $ contentType = $ this -> curl -> getInfo ( CURLINFO_CONTENT_TYPE ) ; if ( strpos ( $ contentType , self :: CONTENT_TYPE_JSON ) === false ) { return $ rawResponse ; } $ response = json_decode ( $ rawResponse ) ; if ( ! isset ( $ response -> response ) ) { throw new RuntimeException ( sprintf ( 'Unexpected response: %s' , $ rawResponse ) ) ; } $ response = $ response -> response ; if ( 'OK' == @ $ response -> status ) { return $ response ; } elseif ( 'NOAUTH' == @ $ response -> error_id || 'Authentication failed - not logged in' == @ $ response -> error ) { throw new TokenExpiredException ( $ response ) ; } throw new ServerException ( $ response ) ; }
|
Do raw HTTP call
|
2,752
|
public function update ( Entity $ entity , $ primaryValue ) { if ( ! $ entity -> getValidator ( ) -> validate ( ) ) { throw new Exception \ ValidatorException ( $ entity -> getValidator ( ) ) ; } try { if ( ! $ this -> query ( ) -> updateOne ( $ primaryValue , $ entity -> getData ( ) ) -> run ( $ this -> connection ) ) { throw new Exception \ RepositoryException ( "Entity was not successfully updated!" ) ; } } catch ( Exception \ QueryException $ e ) { throw new Exception \ RepositoryException ( $ e -> getMessage ( ) ) ; } $ this -> _saveAssociated ( $ primaryValue , $ entity ) ; }
|
Update single record
|
2,753
|
public function destroy ( Entity $ entity ) { $ requiredClass = Convention :: nameToClass ( $ this -> getEntityName ( ) , Convention :: ENTITY_MASK ) ; if ( ! $ entity instanceof $ requiredClass ) { throw new Exception \ RepositoryException ( "Entity must be instance of " . $ requiredClass . "!" ) ; } $ reflection = $ entity :: getReflection ( ) ; if ( ! $ reflection -> hasPrimary ( ) ) { throw new Exception \ RepositoryException ( "Can not delete entity without primary property!" ) ; } $ primaryName = $ reflection -> getPrimaryProperty ( ) -> getName ( ) ; try { return $ this -> query ( ) -> deleteOne ( $ entity -> { $ primaryName } ) -> run ( $ this -> connection ) ; } catch ( Exception \ QueryException $ e ) { throw new Exception \ RepositoryException ( $ e -> getMessage ( ) ) ; } }
|
Delete single record
|
2,754
|
public function find ( array $ filter = [ ] , array $ orderBy = [ ] , $ limit = 0 , $ offset = 0 , array $ associate = [ ] ) { try { $ query = $ this -> query ( ) -> select ( ) -> associate ( $ associate ) -> setFilter ( $ filter ) ; foreach ( $ orderBy as $ orderByRule ) { $ query -> orderBy ( $ orderByRule [ 0 ] , $ orderByRule [ 1 ] ) ; } return $ query -> limit ( $ limit ) -> offset ( $ offset ) -> run ( $ this -> connection ) ; } catch ( Exception \ QueryException $ e ) { throw new Exception \ RepositoryException ( $ e -> getMessage ( ) ) ; } }
|
Find all records
|
2,755
|
public function findPrimaries ( array $ primaryValues , array $ associate = [ ] ) { $ reflection = Entity \ Reflection :: load ( $ this -> getEntityName ( ) ) ; if ( ! $ reflection -> hasPrimary ( ) ) { throw new Exception \ RepositoryException ( "Method can not be used because entity " . $ this -> getEntityName ( ) . " has no primary property defined!" ) ; } if ( empty ( $ primaryValues ) ) { throw new Exception \ RepositoryException ( "Values can not be empty!" ) ; } try { return $ this -> query ( ) -> select ( ) -> setFilter ( [ $ reflection -> getPrimaryProperty ( ) -> getName ( ) => [ Filter :: EQUAL => $ primaryValues ] ] ) -> associate ( $ associate ) -> run ( $ this -> connection ) ; } catch ( Exception \ QueryException $ e ) { throw new Exception \ RepositoryException ( $ e -> getMessage ( ) ) ; } }
|
Find records by set of primary values
|
2,756
|
public static function collectionContains ( $ needle , $ haystack ) { foreach ( $ haystack as $ value ) { if ( $ value === $ needle ) { return true ; } } return false ; }
|
Indicates wether given collection contains the wanted item or not .
|
2,757
|
protected function _initRequest ( $ socket , $ response ) { $ stream = $ this -> _classes [ 'stream' ] ; $ curlOptions = $ socket -> options ( ) ; $ curlOptions [ CURLOPT_INFILESIZE ] = $ socket -> outgoing ( ) -> length ( ) ; if ( isset ( $ curlOptions [ CURLOPT_FILE ] ) ) { $ response -> body ( fopen ( $ curlOptions [ CURLOPT_FILE ] , 'w+' ) ) ; } $ socket -> incoming ( $ response -> stream ( ) ) ; if ( ! $ handle = curl_init ( ) ) { throw new ClientException ( 'Unable to create a new cURL handle' ) ; } curl_setopt_array ( $ handle , $ curlOptions ) ; return $ handle ; }
|
Initialize a socket to be ready to send data .
|
2,758
|
public function push ( $ request , $ response , $ options = [ ] ) { $ socket = $ request instanceof $ this -> _classes [ 'socket' ] ? $ request : $ this ( $ request , $ options ) ; $ this -> _queue [ $ socket -> id ( ) ] = [ 'socket' => $ socket , 'response' => $ response ] ; }
|
Push a request in the queue .
|
2,759
|
public function flush ( $ max = 10 , $ options = [ ] ) { $ defaults = [ 'selectTimeout' => 1.0 ] ; $ options += $ defaults ; do { $ this -> select ( $ options [ 'selectTimeout' ] ) ; $ this -> process ( $ max ) ; } while ( $ this -> _running > 0 ) ; $ results = $ this -> _results ; $ this -> _results = [ ] ; return $ results ; }
|
Runs until all outstanding requests have been completed .
|
2,760
|
protected function _fillup ( $ max ) { $ nb = $ max - $ this -> _running ; $ list = array_splice ( $ this -> _queue , 0 , $ nb ) ; foreach ( $ list as $ item ) { $ handle = $ this -> _initRequest ( $ item [ 'socket' ] , $ item [ 'response' ] ) ; $ this -> _handles [ ( integer ) $ handle ] = $ item ; curl_multi_add_handle ( $ this -> _curl , $ handle ) ; } }
|
Fill the multi handle up to the maximum allowed connections .
|
2,761
|
public static function rangeThisWeek ( ) { $ ts = strtotime ( date ( 'Y-m-d' ) ) + 86400 ; do { $ ts -= 86400 ; $ startDate = date ( 'N' , $ ts ) ; } while ( $ startDate != '1' ) ; return [ $ ts , $ ts + ( 86400 * 6 ) ] ; }
|
Returns a date range for the current week .
|
2,762
|
public static function rangeThisMonth ( ) { $ currentMonth = date ( 'Y-m-01' , time ( ) ) ; $ currentMonthTs = self :: toTs ( $ currentMonth ) ; return [ $ currentMonthTs , $ currentMonthTs + ( 86400 * ( date ( 't' ) - 1 ) ) ] ; }
|
Returns a date range for the current month .
|
2,763
|
public static function rangeLastMonth ( ) { $ lastMonth = date ( 'm' ) - 1 ; if ( $ lastMonth <= 0 ) { $ lastMonth = 12 ; } $ lastMonth = date ( 'Y' ) . '-' . $ lastMonth . '-01' ; return [ self :: toTs ( $ lastMonth ) , self :: toTs ( $ lastMonth ) + ( 86400 * ( date ( 't' , strtotime ( $ lastMonth ) ) - 1 ) ) ] ; }
|
Returns a date range for the previous month .
|
2,764
|
public static function getAnnotationReader ( ) { if ( self :: $ annotationReader === null ) { self :: $ annotationReader = new CachedReader ( new AnnotationReader ( ) , new ArrayCache ( ) ) ; } return self :: $ annotationReader ; }
|
Get the annotation reader that is used . Initializes it if it doesn t already exists .
|
2,765
|
public static function getConstraintsValidator ( ) { if ( self :: $ constraintsValidator === null ) { self :: $ constraintsValidator = Validation :: createValidatorBuilder ( ) -> enableAnnotationMapping ( self :: getAnnotationReader ( ) ) -> getValidator ( ) ; } return self :: $ constraintsValidator ; }
|
Get the constraints validator that is used . Initializes it if it doesn t already exists .
|
2,766
|
private static function setCache ( Cache & $ cacheToChange = null , Cache $ cache = null , $ namespace = null ) { if ( $ namespace === null ) { $ namespace = self :: $ cacheDefaultNamespace ; } if ( ! is_string ( $ namespace ) ) { throw new \ InvalidArgumentException ( "The namespace must be a string." ) ; } $ cacheToChange = $ cache ; if ( $ cache !== null ) { $ cacheToChange -> setNamespace ( $ namespace ) ; } }
|
Set a cache driver .
|
2,767
|
public static function setCacheDriver ( Cache $ cache = null , $ namespace = null ) { self :: setCache ( self :: $ cacheDriver , $ cache , $ namespace ) ; }
|
Set the cache driver that will be used .
|
2,768
|
public static function beNice ( $ strength = self :: ALL_LOWER_CASE , $ lenght = 8 , $ append_numbers = 2 ) { $ password = '' ; $ vocals = self :: EVEN_CHARS ; $ consonants = self :: ODD_CHARS ; if ( $ strength > 0 ) { $ vocals .= strtoupper ( $ vocals ) ; } if ( $ strength > 1 ) { $ consonants .= strtoupper ( $ consonants ) ; } for ( $ i = 0 ; $ i < $ lenght ; $ i ++ ) { if ( ( $ i % 2 ) > 0 ) { $ password .= $ vocals [ ( rand ( ) % strlen ( $ vocals ) ) ] ; } else { $ password .= $ consonants [ ( rand ( ) % strlen ( $ consonants ) ) ] ; } } $ password [ 0 ] = strtoupper ( $ password [ 0 ] ) ; if ( $ append_numbers > 0 ) { $ number = 0 ; while ( strlen ( $ number ) < $ append_numbers ) { $ number = ( rand ( ) % ( pow ( 10 , $ append_numbers ) - 1 ) ) ; } $ password .= $ number ; } return $ password ; }
|
Generate a random human readable password .
|
2,769
|
public static function checkAccess ( $ permissionName , $ user = false , $ params = [ ] ) { if ( is_array ( $ permissionName ) ) { $ permissionName = self :: createPermissionName ( $ permissionName ) ; } if ( ! $ user ) { $ user = Yii :: $ app -> user ; } if ( ! $ user -> isGuest && ! isset ( self :: $ userRoles [ $ user -> id ] ) ) { self :: $ userRoles [ $ user -> id ] = Yii :: $ app -> authManager -> getRolesByUser ( $ user -> id ) ; } if ( isset ( self :: $ userRoles [ $ user -> id ] [ self :: ROLE_ROOT ] ) ) { return true ; } if ( ! self :: $ defaultRoles ) { self :: setDefaultRoles ( $ user -> id ) ; } if ( in_array ( $ permissionName , self :: $ defaultRoles ) ) { return true ; } return $ user -> can ( $ permissionName , $ params ) ; }
|
Check whether the user has access to permission .
|
2,770
|
public function move ( $ oldParent , $ newParent ) { return $ oldParent -> removeChild ( $ this ) ? $ newParent -> addChild ( $ this ) : false ; }
|
Detaches this model from its old parent and attaches to the new one .
|
2,771
|
public function addChild ( AuthItem $ item ) { if ( $ item -> isNewRecord && ! $ item -> save ( ) ) { return false ; } return Yii :: $ app -> authManager -> addChild ( $ this , $ item ) ; }
|
Attaches child related to this model by AuthItemChild .
|
2,772
|
public function eq ( $ str , $ flags = 0 ) { $ ret = false ; if ( list ( $ str ) = $ this -> match ( preg_quote ( $ str , "/" ) , $ matches , $ flags ) ) { $ ret = array ( $ str ) ; } return $ ret ; }
|
Is the next token equal to a given string?
|
2,773
|
public function in ( $ items , $ flags = 0 ) { $ ret = false ; usort ( $ items , function ( $ item1 , $ item2 ) { return strlen ( $ item1 ) < strlen ( $ item2 ) ; } ) ; foreach ( $ items as $ item ) { if ( $ this -> eq ( $ item , $ flags ) ) { $ ret = array ( $ item ) ; break ; } } return $ ret ; }
|
Is the next token the in a given list?
|
2,774
|
public function number ( $ flags = 0 ) { $ ret = false ; if ( $ number = $ this -> match ( TextTokenizer :: NUMBER , $ matches , $ flags ) ) { $ ret = $ number ; } return $ ret ; }
|
Is the next token a number?
|
2,775
|
public function str ( $ flags = 0 ) { $ ret = false ; if ( $ this -> match ( TextTokenizer :: STRING , $ matches , $ flags ) ) { $ delimiter = $ matches [ 2 ] ; $ str = $ matches [ 3 ] ; $ str = str_replace ( "\\$delimiter" , "$delimiter" , $ str ) ; $ ret = array ( $ str ) ; } return $ ret ; }
|
Is the next token a string?
|
2,776
|
public function id ( ) { $ ret = false ; if ( list ( $ id ) = $ this -> match ( TextTokenizer :: IDENTIFIER ) ) { $ ret = array ( $ id ) ; } return $ ret ; }
|
Is the next token an identifier?
|
2,777
|
public function match ( $ regexp , & $ matches = array ( ) , $ flags = 0 ) { if ( strlen ( $ regexp ) == 0 ) { return false ; } $ ret = false ; $ explicitRegexp = strlen ( $ regexp ) > 0 && $ regexp [ 0 ] == "/" ; $ substr = substr ( $ this -> string , $ this -> offset ) ; if ( ! $ explicitRegexp ) { $ caseSensitive = TextTokenizer :: CASE_SENSITIVE & ( $ this -> _flags | $ flags ) ; $ searchAnywhere = TextTokenizer :: SEARCH_ANYWHERE & ( $ this -> _flags | $ flags ) ; $ modifiers = "us" . ( $ caseSensitive ? "" : "i" ) ; $ regexp = $ searchAnywhere ? "/($regexp)/$modifiers" : "/^\s*($regexp)/$modifiers" ; } if ( preg_match ( $ regexp , $ substr , $ matches , PREG_OFFSET_CAPTURE ) ) { $ offsetCapture = TextTokenizer :: OFFSET_CAPTURE & ( $ this -> _flags | $ flags ) ; $ str = $ matches [ 0 ] [ 0 ] ; $ offset = $ matches [ 0 ] [ 1 ] + strlen ( $ str ) ; if ( $ offsetCapture ) { foreach ( $ matches as $ i => $ match ) { $ matches [ $ i ] [ 1 ] += $ this -> offset ; } } else { foreach ( $ matches as $ i => $ match ) { $ matches [ $ i ] = $ matches [ $ i ] [ 0 ] ; } } if ( ! ctype_alnum ( $ substr [ $ offset - 1 ] ) || $ offset == strlen ( $ substr ) || ! ctype_alnum ( $ substr [ $ offset ] ) ) { $ this -> offset += $ offset ; $ ret = array ( ltrim ( $ str ) ) ; } } return $ ret ; }
|
Matches the string against a regex .
|
2,778
|
public function isZero ( ) { return ( gmp_sign ( $ this -> value [ 'real' ] -> numerator ( ) -> gmp ( ) ) == 0 && gmp_sign ( $ this -> value [ 'imaginary' ] -> numerator ( ) -> gmp ( ) ) == 0 ) ; }
|
Is this number equal to zero?
|
2,779
|
public function forceAuthentication ( ) { if ( self :: isAuthenticated ( ) ) { return true ; } elseif ( $ this -> getTicket ( ) ) { return $ this -> validateCas ( ) ; } session_write_close ( ) ; $ this -> redirectToCas ( ) ; return true ; }
|
If not authenticated redirect to CAS . If authenticated return true .
|
2,780
|
public function checkAuthentication ( ) { if ( self :: isAuthenticated ( ) ) { return true ; } elseif ( self :: isGatewayed ( ) ) { return $ this -> validateCas ( ) ; } self :: setGatewayed ( true ) ; session_write_close ( ) ; $ this -> redirectToCas ( true ) ; return true ; }
|
If not gatewayed redirect to CAS with gateway = true .
|
2,781
|
protected function redirectToCas ( $ gateway = false ) { $ query [ 'service' ] = self :: getDefaultService ( ) ; if ( $ gateway ) { $ query [ 'gateway' ] = 'true' ; } self :: http_redirect ( $ this -> server [ 'login_url' ] . '?' . http_build_query ( $ query ) ) ; return true ; }
|
Redirect to CAS server for login
|
2,782
|
protected static function getDefaultService ( ) { $ service = ( isset ( $ _SERVER [ 'HTTPS' ] ) ? 'https' : 'http' ) . '://' . $ _SERVER [ 'SERVER_NAME' ] . $ _SERVER [ 'REQUEST_URI' ] ; $ parts = parse_url ( $ service ) ; if ( isset ( $ parts [ 'query' ] ) ) { parse_str ( $ parts [ 'query' ] , $ query ) ; } else { $ query = array ( ) ; } unset ( $ query [ 'ticket' ] ) ; $ parts [ 'query' ] = http_build_query ( $ query ) ; return self :: build_url ( $ parts ) ; }
|
Get the service name of this request
|
2,783
|
private function checkPages ( ) { if ( is_null ( $ this -> pageLimit ) ) { return false ; } if ( ++ $ this -> pageCounter > $ this -> pageLimit ) { return true ; } return false ; }
|
Uses internal counter to check page limit
|
2,784
|
private function checkTime ( ) { if ( is_null ( $ this -> timeLimit ) ) { return false ; } if ( ( $ this -> startTime + $ this -> timeLimit ) <= time ( ) ) { return true ; } return false ; }
|
Checks time between first and current request
|
2,785
|
public function add ( $ key , $ default , $ type , $ allow_null ) { $ obj = new stdclass ( ) ; $ obj -> type = is_int ( $ type ) ? $ type : HTMLPurifier_VarParser :: $ types [ $ type ] ; if ( $ allow_null ) $ obj -> allow_null = true ; $ this -> info [ $ key ] = $ obj ; $ this -> defaults [ $ key ] = $ default ; $ this -> defaultPlist -> set ( $ key , $ default ) ; }
|
Defines a directive for configuration
|
2,786
|
public function run ( InputInterface $ input , OutputInterface $ output ) : int { return $ this -> console -> run ( $ input , $ output ) ; }
|
Runs Console Application .
|
2,787
|
private function initConsole ( string $ name , string $ version ) { $ this -> console = $ this -> container -> get ( SymfonyConsoleApplication :: class ) ; $ this -> console -> setName ( $ name ) ; $ this -> console -> setVersion ( $ version ) ; $ this -> console -> setCatchExceptions ( false ) ; $ this -> console -> setAutoExit ( false ) ; $ commands = $ this -> container -> get ( CommandCollectionContract :: class ) ; foreach ( $ commands as $ command ) { $ this -> console -> add ( $ this -> resolveCommand ( $ command ) ) ; } }
|
Initiates Symfony Console Application .
|
2,788
|
public function getAllDevices ( ) { $ devices = array ( ) ; $ devicesId = $ this -> getAllDevicesID ( ) ; foreach ( $ devicesId as $ deviceId ) { $ device = $ this -> getDevice ( $ deviceId ) ; $ devices [ ] = $ device ; } return $ devices ; }
|
Returns all devices in the repository
|
2,789
|
public static function getNearestStation ( $ stations , $ coordinatesRequest ) { $ calculator = new Vincenty ( ) ; $ nearestStation = null ; $ nextDist = INF ; foreach ( $ stations as $ activeStation ) { if ( is_object ( $ activeStation ) && $ activeStation instanceof DWDStation ) { $ coordinatesStation = new Coordinate ( $ activeStation -> getLatitude ( ) , $ activeStation -> getLongitude ( ) ) ; $ diff = $ calculator -> getDistance ( $ coordinatesRequest , $ coordinatesStation ) ; if ( $ diff < $ nextDist ) { $ nearestStation = $ activeStation ; $ nextDist = $ diff ; } } else throw new DWDLibException ( "Stations parameter does contain an object that is no instance of DWDStation" ) ; } return $ nearestStation ; }
|
Return the nearest stations from a stations array .
|
2,790
|
public static function getNearestStations ( $ stations , Coordinate $ coordinatesRequest , int $ radiusKM = 200 ) { DWDUtil :: log ( self :: class , "Getting nearest stations from a list of " . count ( $ stations ) . ", around coordinates: " . $ coordinatesRequest -> format ( new DecimalDegrees ( ) ) ) ; $ calculator = new Vincenty ( ) ; $ nearestStations = array ( ) ; foreach ( $ stations as $ activeStation ) { if ( is_object ( $ activeStation ) && $ activeStation instanceof DWDStation ) { $ coordinatesStation = new Coordinate ( $ activeStation -> getLatitude ( ) , $ activeStation -> getLongitude ( ) ) ; $ diff = $ calculator -> getDistance ( $ coordinatesRequest , $ coordinatesStation ) ; if ( $ diff <= $ radiusKM * DWDStationsController :: kmToMeters ) { $ nearestStations [ intval ( $ diff ) ] = $ activeStation ; } ksort ( $ nearestStations ) ; } } DWDUtil :: log ( self :: class , "Got nearest stations :" . count ( $ nearestStations ) ) ; if ( count ( $ nearestStations ) < 1 ) { throw new DWDLibException ( "No Stations near the given Coordinates are available inside of a 200km radius around coordinates: " . $ coordinatesRequest -> format ( new DecimalDegrees ( ) ) ) ; } return $ nearestStations ; }
|
Get all stations in an x km radius .
|
2,791
|
public static function getStationFile ( $ stationFtpPath , $ outputPath ) { $ ftpConfig = DWDConfiguration :: getFTPConfiguration ( ) ; $ ftp_connection = ftp_connect ( $ ftpConfig -> url ) ; $ login_result = ftp_login ( $ ftp_connection , $ ftpConfig -> userName , $ ftpConfig -> userPassword ) ; if ( $ login_result && ftp_size ( $ ftp_connection , $ stationFtpPath ) > - 1 ) { $ result = ftp_get ( $ ftp_connection , $ outputPath , $ stationFtpPath , FTP_BINARY ) ; ftp_close ( $ ftp_connection ) ; if ( ! isset ( $ result ) ) { throw new DWDLibException ( "Could not retrieve data from ftp location: " . $ stationFtpPath ) ; } } }
|
Tries to download the station file from the given path .
|
2,792
|
public static function parseStations ( $ filePath ) { if ( DIRECTORY_SEPARATOR == '\\' ) $ filePath = str_replace ( '/' , '\\' , $ filePath ) ; ini_set ( 'display_errors' , 1 ) ; error_reporting ( E_ALL ) ; $ stationConf = DWDConfiguration :: getStationConfiguration ( ) ; $ stations = array ( ) ; if ( file_exists ( $ filePath ) ) { $ handle = fopen ( $ filePath , "r" ) ; if ( $ handle ) { self :: skipDescriptionLines ( $ stationConf -> skipLines , $ handle ) ; while ( ( $ line = fgets ( $ handle ) ) !== false ) { $ line = mb_convert_encoding ( $ line , "UTF-8" , "iso-8859-1" ) ; $ output = preg_replace ( '!\s+!' , ' ' , $ line ) ; $ output = trim ( $ output , ' ' ) ; $ split = explode ( " " , $ output , 7 ) ; $ name = explode ( " " , $ split [ count ( $ split ) - 1 ] ) ; $ county = $ name [ count ( $ name ) - 1 ] ; $ nameSlice = array_slice ( $ name , 0 , count ( $ name ) - 1 ) ; $ name = implode ( " " , $ nameSlice ) ; $ from = Carbon :: createFromFormat ( $ stationConf -> dateFormat , $ split [ 1 ] , 'UTC' ) ; $ until = Carbon :: createFromFormat ( $ stationConf -> dateFormat , $ split [ 2 ] , 'UTC' ) ; $ station = new DWDStation ( $ split [ 0 ] , $ from , $ until , $ split [ 3 ] , $ split [ 4 ] , $ split [ 5 ] , $ name , $ county , $ stationConf -> activeRequirementDays ) ; $ stations [ ] = $ station ; } fclose ( $ handle ) ; } else { throw new DWDLibException ( "Error opening the file: " . $ filePath ) ; } } else throw new DWDLibException ( "File does not exist - path: " . $ filePath ) ; return $ stations ; }
|
Parse the station files into station objects .
|
2,793
|
public static function createByName ( $ name ) { $ constants = self :: getConstantsByName ( ) ; if ( ! array_key_exists ( $ name , $ constants ) ) { throw EnumException :: invalidName ( get_called_class ( ) , $ name ) ; } return new static ( $ constants [ $ name ] ) ; }
|
Creates a new type instance using the name of a value
|
2,794
|
public static function createByValue ( $ value ) { $ constants = self :: getConstantsByValue ( ) ; if ( ! array_key_exists ( $ value , $ constants ) ) { throw EnumException :: invalidValue ( get_called_class ( ) , $ value ) ; } return new static ( $ value ) ; }
|
Creates a new type instance using the value
|
2,795
|
public function parseHourlyDataOld ( String $ content , DWDStation $ nearestStation , Coordinate $ coordinate , Carbon $ startDate = null , Carbon $ endDate = null ) : array { $ time = microtime ( true ) ; $ lines = explode ( 'eor' , $ content ) ; $ data = array ( ) ; DWDUtil :: log ( "PARSER" , "DATE=[" . $ endDate -> toIso8601String ( ) . "," . $ startDate -> toIso8601String ( ) . "]" ) ; for ( $ i = sizeof ( $ lines ) - 1 ; $ i > 0 ; $ i -- ) { $ lines [ $ i ] = str_replace ( ' ' , '' , $ lines [ $ i ] ) ; $ cols = explode ( ';' , $ lines [ $ i ] ) ; if ( sizeof ( $ cols ) < 3 ) continue ; $ date = Carbon :: createFromFormat ( $ this -> getTimeFormat ( ) , $ cols [ 1 ] , 'utc' ) ; if ( $ date ) { switch ( func_num_args ( ) ) { case 4 : { if ( $ date >= $ startDate ) { $ temp = $ this -> createParameter ( $ cols , $ date , $ nearestStation , $ coordinate ) ; $ data [ ] = $ temp ; } else break 2 ; break ; } case 5 : { if ( $ date <= $ endDate && $ date >= $ startDate ) { $ temp = $ this -> createParameter ( $ cols , $ date , $ nearestStation , $ coordinate ) ; $ data [ ] = $ temp ; } else if ( $ date <= $ startDate ) { break 2 ; } break ; } default : { $ temp = $ this -> createParameter ( $ cols , $ date , $ nearestStation , $ coordinate ) ; $ data [ ] = $ temp ; } } } else throw new ParseError ( self :: class . " - Error while parsing date: col=" . $ cols [ 1 ] . " | date=" . $ date ) ; } DWDUtil :: log ( "PARSER" , "RetCount=" . count ( $ data ) ) ; DWDUtil :: log ( "TIMER" , "Duration=" . ( microtime ( true ) - $ time ) ) ; return $ data ; }
|
Parse the textual representation of DWD Data can be filtered by specifying before and after . This means if you specify after - you will get timestamps after the specified team If you also specify before you can pinpoint values .
|
2,796
|
public function getStationFTPPath ( string $ ftpPath ) { $ fileName = DWDUtil :: getFileNameFromPath ( $ ftpPath ) ; $ filePath = DWDConfiguration :: getConfiguration ( ) -> baseDirectory . DWDConfiguration :: getConfiguration ( ) -> dwdHourly -> localBaseFolder . '/' . $ fileName ; return $ filePath ; }
|
Return the path to the file that contains the stations .
|
2,797
|
public function boot ( $ request = null ) { $ this -> getApp ( ) -> boot ( $ request , $ this -> bootstrapRegistry -> getItems ( ) ) ; Controller :: setRouter ( $ this -> getRouter ( ) ) ; include_once $ this -> routesConfiguration -> getRoutesPath ( $ this -> getApp ( ) -> getBasePath ( ) ) ; }
|
Init the panda application and start all the interfaces that are needed for runtime .
|
2,798
|
public function handle ( SymfonyRequest $ request ) { $ this -> boot ( $ request ) ; return $ this -> getRouter ( ) -> dispatch ( $ request ) ; }
|
Handle the incoming request and return a response .
|
2,799
|
public function setDimension ( $ dimensionName , $ dimensionValue = null ) { $ this -> pipeline [ '$match' ] [ 'name' ] = $ dimensionName ; if ( ! empty ( $ dimensionValue ) ) { $ this -> pipeline [ '$match' ] [ 'value' ] = $ dimensionValue ; } return $ this ; }
|
Filter the dimension records .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.