idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
26,800 | public function validate ( ) { if ( empty ( $ this -> rules ) ) return true ; if ( ! is_array ( $ this -> rules ) ) throw new \ Exception ( "The rules must be an array of the validator|sanitize rules" , 1 ) ; foreach ( $ this -> rules as $ rule ) { $ rule instanceof \ Closure ? $ rule ( $ this ) : call_user_func ( $ rule , $ this ) ; } return ! $ this -> hasError ( ) ; } | Run the rule of the rules Each rule can push error to the field or change the value of the field |
26,801 | protected function initDefaults ( ) { if ( ! $ this -> hasDefaults ) { return '' ; } $ this -> defaultsLocation = get_calling_class_directory ( $ this ) . DIRECTORY_SEPARATOR . $ this -> defaultsLocation ; return ConfigFactory :: loadConfigFile ( $ this -> defaultsLocation ) ; } | Initialize the defaults . |
26,802 | public function register ( array $ concreteConfig , $ uniqueId ) { $ concreteConfig = $ this -> parseWithDefaultStructure ( $ concreteConfig ) ; if ( ! Validator :: okayToRegister ( $ uniqueId , $ concreteConfig , $ this -> defaultStructure , __CLASS__ ) ) { return false ; } $ concrete = $ this -> getConcrete ( $ concreteConfig , $ uniqueId ) ; if ( true === $ this -> skipQueue ) { return $ this -> registerConcrete ( $ concrete , $ uniqueId ) ; } return $ this -> queued [ $ uniqueId ] = $ concrete ; } | Register a concrete into the container . |
26,803 | protected function registerConcrete ( array $ concrete , $ uniqueId ) { $ this -> uniqueIds [ ] = $ uniqueId ; return $ this -> fulcrum -> registerConcrete ( $ concrete , $ uniqueId ) ; } | Register the concrete into the Container . |
26,804 | public function tokenize ( $ string ) { $ line = 1 ; $ position = 1 ; $ tokens = array ( ) ; while ( strlen ( $ string ) ) { foreach ( $ this -> expressions as $ rule ) { if ( ! preg_match ( $ rule [ 'match' ] , $ string , $ match ) ) { continue ; } $ string = substr ( $ string , strlen ( $ match [ 0 ] ) ) ; $ line += substr_count ( $ match [ 0 ] , "\n" ) ; if ( ( $ pos = strrpos ( $ match [ 0 ] , "\n" ) ) !== false ) { $ position = strrpos ( $ match [ 0 ] , "\n" ) + 1 ; } else { $ position += strlen ( $ match [ 0 ] ) ; } if ( in_array ( $ rule [ 'type' ] , $ this -> ignoreTokens ) ) { continue 2 ; } $ match = $ this -> removeNumericKeys ( $ match ) ; $ tokens [ ] = new Token ( $ rule [ 'type' ] , $ line , $ position , $ match ) ; continue 2 ; } throw new \ RuntimeException ( "Could not parse string: '" . substr ( $ string , 0 , 20 ) . "' in line $line at position $position." ) ; } $ tokens [ ] = new Token ( self :: T_EOF , $ line , $ position , null ) ; return $ tokens ; } | Tokenize the input string |
26,805 | public function create ( array $ data ) { if ( array_key_exists ( 'password' , $ data ) ) { $ data [ 'password' ] = bcrypt ( $ data [ 'password' ] ) ; } return parent :: create ( $ data ) ; } | Encrypt password before creating a new user instance . |
26,806 | public function update ( array $ data , $ id ) { if ( array_key_exists ( 'password' , $ data ) ) { $ data [ 'password' ] = bcrypt ( $ data [ 'password' ] ) ; } return parent :: update ( $ data , $ id ) ; } | Encrypt password before updating a user instance . |
26,807 | private function generateListByIterator ( Iterator $ iterator ) { $ resultado = array ( ) ; foreach ( $ iterator as $ compra ) { $ resultado [ ] = $ this -> preencherCompra ( $ compra ) ; } return $ resultado ; } | Gera um lista completa de compras a partir de um iterator |
26,808 | public function preencherCompra ( Compra $ compra ) { $ compra -> setProduto ( $ this -> getProdutoManager ( ) -> getProduto ( $ compra -> getProdutoId ( ) ) ) ; $ compra -> setAutenticacao ( $ this -> getAutenticacaoManager ( ) -> obterAutenticacaoBasica ( $ compra -> getAutenticacaoId ( ) ) ) ; $ compra -> setStatus ( $ this -> getStatusManager ( ) -> obterStatus ( $ compra -> getStatusId ( ) ) ) ; return $ compra ; } | Preenche as entidades relacionadas na compra |
26,809 | public function getMappedSecondEntitiesByEntityType ( $ secondEntityName ) { $ secondEntities = [ ] ; foreach ( $ this -> data as $ data ) { $ secondEntity = $ this -> createAndReturnNewSecondEntity ( $ data , $ secondEntityName ) ; if ( $ secondEntity ) { $ secondEntities [ ] = $ secondEntity ; } } return $ secondEntities ; } | Get second entities for the passed argument that represents the name of the second entity |
26,810 | private function createAndReturnNewSecondEntity ( $ data , $ secondEntityName ) { $ entity = $ this -> getSecondEntityByName ( $ secondEntityName ) ; if ( is_array ( $ data ) ) { return $ this -> mapAttributesFromFirstEntityToSecondEntityAndReturnEntity ( $ data , $ entity ) ; } return null ; } | Return a new second entity |
26,811 | private function setSecondEntityAttribute ( $ secondEntity , $ attributeName , $ attributeData ) { $ entityAttribute = $ this -> mappingFirstEntityToSecondEntityAttributes [ $ attributeName ] ; $ setterMethod = 'set' . ucfirst ( $ entityAttribute ) ; if ( method_exists ( $ secondEntity , $ setterMethod ) ) { $ secondEntity -> $ setterMethod ( $ attributeData ) ; } } | Set second entity attribute based on the attribute name and attribute data |
26,812 | public function getMappedFirstEntitiesByEntityType ( $ entityName ) { $ entities = [ ] ; foreach ( $ this -> data as $ data ) { $ entity = $ this -> createAndReturnNewFirstEntity ( $ data , $ entityName ) ; if ( $ entity ) { $ entities [ ] = $ entity ; } } return $ entities ; } | Get entities for the passed argument that represents the name of the entity |
26,813 | private static function returnKey ( $ key , $ mappingArray ) { if ( ! is_array ( $ mappingArray ) ) { return $ key ; } foreach ( $ mappingArray as $ mappingKey => $ mappingData ) { if ( is_array ( $ mappingData ) ) { if ( isset ( $ mappingData [ $ key ] ) ) { return $ mappingData [ $ key ] ; } } else { if ( $ mappingKey == $ key ) { return $ mappingData ; } } } return $ key ; } | Search for mapping key |
26,814 | private function setFirstEntityAttribute ( $ entity , $ attributeName , $ attributeData ) { $ entityAttribute = $ this -> mappingSecondEntityToFirstEntityAttributes [ $ attributeName ] ; $ setterMethod = 'set' . ucfirst ( $ entityAttribute ) ; if ( method_exists ( $ entity , $ setterMethod ) ) { $ entity -> $ setterMethod ( $ attributeData ) ; } } | Set entity attribute based on the attribute name and attribute data |
26,815 | public function getMappedSecondAttributes ( ) { $ attributes = [ ] ; if ( is_array ( $ this -> data [ 0 ] ) ) { foreach ( $ this -> data [ 0 ] as $ attribute => $ attributeValue ) { if ( array_key_exists ( $ attribute , $ this -> mappingFirstEntityToSecondEntityAttributes ) ) { $ attributes [ $ this -> mappingFirstEntityToSecondEntityAttributes [ $ attribute ] ] = $ attributeValue ; } } } return $ attributes ; } | Get mapped attributes from the data member mapped to second attributes |
26,816 | public function setBooleanAttrib ( $ name , $ value = true , $ comparisonAttribute = null ) { if ( ! is_bool ( $ value ) && ! is_null ( $ comparisonAttribute ) ) { $ compare = $ this -> getAttrib ( $ comparisonAttribute ) ; if ( is_array ( $ value ) ) { $ value = in_array ( $ compare , $ value , true ) ; } else { $ value = $ value === $ compare ; } } $ this -> setAttrib ( $ name , $ value ) ; } | Sets a boolean attribute by comparing a value with the value of another attribute . |
26,817 | public function str ( ) { $ str = '' ; foreach ( $ this -> attributes as $ name => $ value ) { $ str .= $ this -> getAttribStr ( $ name ) ; } return $ str ; } | Returns the string representation of all attributes . |
26,818 | public function getAttribStr ( $ name ) { $ value = $ this -> attributes [ $ name ] ; if ( $ value === null || $ value === false || $ name === null ) { return '' ; } if ( $ value === true ) { if ( $ this -> element ) { $ class = get_class ( $ this -> element ) ; if ( $ class :: HTML_MODE ) { return ' ' . $ name ; } } $ value = $ name ; } return ' ' . $ name . '="' . $ value . '"' ; } | Returns the string representation of a single attribute . |
26,819 | public function get ( $ name ) { if ( $ name == '' ) { if ( count ( $ this -> instances ) == 1 ) { $ instances = array_values ( $ this -> instances ) ; return array_shift ( $ instances ) ; } throw new InvalidArgumentException ( 'Unspecified Universal Analytics tracker name' ) ; } if ( isset ( $ this -> instances [ $ name ] ) ) return $ this -> instances [ $ name ] ; throw new Exception ( 'Universal Analytics instance for "' . $ name . '" doesn\'t exist' ) ; } | Find a single tracker instance |
26,820 | protected function create ( $ account , $ config = array ( ) ) { if ( ! isset ( $ config [ 'name' ] ) ) { $ config [ 'name' ] = 't' . count ( $ this -> instances ) ; } $ debug = $ this -> debug ; $ autoPageview = $ this -> autoPageview ; $ this -> instances [ $ config [ 'name' ] ] = new UniversalAnalyticsInstance ( $ account , $ config , $ debug , $ autoPageview ) ; return $ this -> instances [ $ config [ 'name' ] ] ; } | Create a new tracker instance or update an existing a new config |
26,821 | public function render ( $ renderedCodeBlock = true , $ renderScriptTag = true ) { $ js = array ( ) ; if ( $ renderScriptTag ) $ js [ ] = '<script>' ; foreach ( $ this -> instances as $ instance ) { $ js [ ] = $ instance -> render ( $ renderedCodeBlock , false ) . PHP_EOL ; $ renderedCodeBlock = false ; } if ( $ renderScriptTag ) $ js [ ] = '</script>' ; return implode ( PHP_EOL , $ js ) ; } | Render the Universal Analytics code |
26,822 | protected function _replace_tags ( $ msg ) { $ label = is_array ( $ this -> field -> label ) ? $ this -> field -> label [ 'label' ] : $ this -> field -> label ; $ value = is_array ( $ this -> value ) ? implode ( ', ' , $ this -> value ) : $ this -> value ; if ( \ Config :: get ( 'validation.quote_labels' , false ) and strpos ( $ label , ' ' ) !== false ) { $ label = '"' . $ label . '"' ; } $ find = array ( ':field' , ':label' , ':value' , ':rule' ) ; $ replace = array ( $ this -> field -> name , $ label , $ value , $ this -> rule ) ; foreach ( $ this -> params as $ key => $ val ) { if ( is_array ( $ val ) ) { $ result = '' ; foreach ( $ val as $ v ) { if ( is_array ( $ v ) ) { $ v = '(array)' ; } elseif ( is_object ( $ v ) ) { $ v = '(object)' ; } elseif ( is_bool ( $ v ) ) { $ v = $ v ? 'true' : 'false' ; } $ result .= empty ( $ result ) ? $ v : ( ', ' . $ v ) ; } $ val = $ result ; } elseif ( is_bool ( $ val ) ) { $ val = $ val ? 'true' : 'false' ; } elseif ( is_object ( $ val ) ) { $ val = method_exists ( $ val , '__toString' ) ? ( string ) $ val : get_class ( $ val ) ; } $ find [ ] = ':param:' . ( $ key + 1 ) ; $ replace [ ] = $ val ; } return str_replace ( $ find , $ replace , $ msg ) ; } | Replace templating tags with values |
26,823 | public function selectById ( $ id ) { $ sql = "SELECT * FROM `$this->tableName` WHERE `$this->pkColName` = %d " ; $ stmt = $ this -> pdo -> prepare ( sprintf ( $ sql , $ id ) ) ; $ res = $ stmt -> execute ( ) ; if ( $ res === false ) { return null ; } $ rows = $ stmt -> fetchAll ( ) ; if ( count ( $ rows ) !== 1 ) { return null ; } return $ this -> prepareEntity ( $ rows [ 0 ] ) ; } | Select entity by its ID . |
26,824 | public function deleteById ( $ id ) { $ sql = "DELETE FROM `$this->tableName` WHERE `$this->pkColName` = :entityId " ; $ stmt = $ this -> pdo -> prepare ( $ sql ) ; $ stmt -> bindParam ( ':entityId' , intval ( $ id ) , \ PDO :: PARAM_INT ) ; $ res = $ stmt -> execute ( ) ; return ( $ res !== false && $ stmt -> rowCount ( ) === 1 ) ; } | Delete record by its identifier . |
26,825 | public function setPartial ( $ partial ) { if ( null === $ partial || is_string ( $ partial ) || is_array ( $ partial ) ) { $ this -> partial = $ partial ; } return $ this ; } | Sets which partial view script to use for rendering tweets |
26,826 | public function getTwitter ( ) { if ( ! $ this -> twitter ) { $ this -> twitter = $ this -> getServiceLocator ( ) -> getServiceLocator ( ) -> get ( Twitter :: class ) ; } return $ this -> twitter ; } | Gets the twitter instance |
26,827 | public static function getData ( $ key = self :: KEY , $ cookieExtra = '' ) { if ( ! empty ( self :: $ data ) ) { return self :: $ data ; } $ key .= $ cookieExtra ; if ( PHP_SESSION_ACTIVE === session_status ( ) && isset ( $ _SESSION [ $ key ] ) ) { self :: $ data = $ _SESSION [ $ key ] ; return self :: $ data ; } if ( isset ( $ _COOKIE ) && isset ( $ _COOKIE [ $ key ] ) ) { self :: $ data = self :: ang ( $ _COOKIE [ $ key ] ) ; if ( isset ( $ _SESSION ) ) { $ _SESSION [ $ key ] = self :: $ data ; } return self :: $ data ; } return null ; } | returns the data |
26,828 | public static function buildJsCode ( $ cookieExtra = '' ) { $ js = self :: buildJs ( ) ; $ js .= self :: buildConvertJs ( self :: KEY , $ cookieExtra , true ) ; return $ js ; } | builds the complete javascript code to output modernizr . js new checkes and to write the detection result into the session |
26,829 | public static function buildJs ( ) { $ js = '' ; foreach ( self :: collectJsFiles ( ) as $ file ) { $ js .= file_get_contents ( __DIR__ . '/../web' . $ file ) ; } return $ js ; } | builds the javascript code to output modernizr . js and new checkes |
26,830 | public static function buildConvertJs ( $ key , $ cookieExtra = '' , $ reload = true ) { $ content = file_get_contents ( __DIR__ . '/../web/convert/start.js.tmp' ) ; ksort ( self :: $ properties ) ; foreach ( array_keys ( self :: $ properties ) as $ i => $ property ) { if ( is_array ( self :: $ properties [ $ property ] ) ) { $ content .= str_replace ( [ '$propertykey' , '$property' ] , [ $ property , $ property ] , file_get_contents ( __DIR__ . '/../web/convert/base-group-start.js.tmp' ) ) ; ksort ( self :: $ properties [ $ property ] ) ; foreach ( array_keys ( self :: $ properties [ $ property ] ) as $ j => $ subproperty ) { $ content .= str_replace ( [ '$property' , '$subpropertykey' , '$subproperty' ] , [ $ property , self :: $ properties [ $ property ] [ $ subproperty ] , $ subproperty ] , file_get_contents ( __DIR__ . '/../web/convert/base-groupbase.js.tmp' ) ) ; if ( $ j < count ( self :: $ properties [ $ property ] ) - 1 ) { $ content .= ',' ; } $ content .= "\n" ; } $ content .= str_replace ( '$property' , $ property , file_get_contents ( __DIR__ . '/../web/convert/base-group-end.js.tmp' ) ) ; } else { $ content .= str_replace ( [ '$propertykey' , '$property' ] , [ self :: $ properties [ $ property ] , $ property ] , file_get_contents ( __DIR__ . '/../web/convert/base-single.js.tmp' ) ) ; } if ( $ i < count ( self :: $ properties ) - 1 ) { $ content .= ',' ; } $ content .= "\n" ; } $ content .= file_get_contents ( __DIR__ . '/../web/convert/end.js.tmp' ) ; return str_replace ( [ '###Modernizr###' , '###EXTRA###' , 'reload = false' ] , [ $ key , $ cookieExtra , ( $ reload ? 'reload = true' : 'reload = false' ) ] , $ content ) ; } | builds the javascript code to write the detection result into a cookie |
26,831 | private static function ang ( $ cookie ) { $ data = new \ stdClass ( ) ; $ features = json_decode ( $ cookie ) ; var_dump ( $ cookie , $ features ) ; exit ; return $ data ; } | extracts the feature data from the cookie |
26,832 | static function override ( $ now ) : void { if ( $ now instanceof \ DateTimeInterface ) { $ now = $ now -> getTimestamp ( ) + ( $ now -> format ( 'u' ) / 1e6 ) ; } elseif ( ! is_int ( $ now ) && ! is_float ( $ now ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Expected int, float or an instance of DateTimeInterface, but got %s' , is_object ( $ now ) ? get_class ( $ now ) : gettype ( $ now ) ) ) ; } self :: $ now = $ now ; } | Override the current time |
26,833 | static function microtime ( ) : float { if ( self :: $ now !== null ) { return ( float ) self :: $ now ; } return microtime ( true ) ; } | Get the current UNIX timestamp with microsecond precision |
26,834 | static function dateTime ( ? \ DateTimeZone $ timezone = null ) : \ DateTime { if ( self :: $ now !== null ) { $ now = \ DateTime :: createFromFormat ( 'U.u' , sprintf ( '%.6F' , self :: $ now ) ) ; $ now -> setTimezone ( $ timezone ?? new \ DateTimeZone ( date_default_timezone_get ( ) ) ) ; return $ now ; } return new \ DateTime ( 'now' , $ timezone ) ; } | Get the current date - time |
26,835 | static function dateTimeImmutable ( ? \ DateTimeZone $ timezone = null ) : \ DateTimeImmutable { if ( self :: $ now !== null ) { $ now = \ DateTimeImmutable :: createFromFormat ( 'U.u' , sprintf ( '%.6F' , self :: $ now ) ) ; $ now = $ now -> setTimezone ( $ timezone ?? new \ DateTimeZone ( date_default_timezone_get ( ) ) ) ; return $ now ; } return new \ DateTimeImmutable ( 'now' , $ timezone ) ; } | Get the current date - time as an immutable instance |
26,836 | public function findDataByTypesAndNames ( string $ locale , array $ namesByTypes , array $ modCombinationIds = [ ] ) : array { $ columns = [ 't.locale AS locale' , 't.type AS type' , 't.name AS name' , 't.value AS value' , 't.description AS description' , 't.isDuplicatedByRecipe AS isDuplicatedByRecipe' , 't.isDuplicatedByMachine AS isDuplicatedByMachine' , 'mc.order AS order' ] ; $ queryBuilder = $ this -> entityManager -> createQueryBuilder ( ) ; $ queryBuilder -> select ( $ columns ) -> from ( Translation :: class , 't' ) -> innerJoin ( 't.modCombination' , 'mc' ) -> andWhere ( 't.locale IN (:locales)' ) -> setParameter ( 'locales' , [ $ locale , 'en' ] ) ; $ conditions = [ ] ; foreach ( $ namesByTypes as $ type => $ names ) { if ( count ( $ names ) > 0 ) { $ index = count ( $ conditions ) ; switch ( $ type ) { case TranslationType :: RECIPE : $ conditions [ ] = '((t.type = :type' . $ index . ' OR t.isDuplicatedByRecipe = 1) ' . 'AND t.name IN (:names' . $ index . '))' ; break ; case TranslationType :: MACHINE : $ conditions [ ] = '((t.type = :type' . $ index . ' OR t.isDuplicatedByMachine = 1) ' . 'AND t.name IN (:names' . $ index . '))' ; break ; default : $ conditions [ ] = '(t.type = :type' . $ index . ' AND t.name IN (:names' . $ index . '))' ; break ; } $ queryBuilder -> setParameter ( 'type' . $ index , $ type ) -> setParameter ( 'names' . $ index , array_values ( $ names ) ) ; } } $ result = [ ] ; if ( count ( $ conditions ) > 0 ) { $ queryBuilder -> andWhere ( '(' . implode ( ' OR ' , $ conditions ) . ')' ) ; if ( count ( $ modCombinationIds ) > 0 ) { $ queryBuilder -> andWhere ( '(t.modCombination IN (:modCombinationIds) OR t.type = :typeMod)' ) -> setParameter ( 'modCombinationIds' , array_values ( $ modCombinationIds ) ) -> setParameter ( 'typeMod' , 'mod' ) ; } $ result = $ this -> mapTranslationDataResult ( $ queryBuilder -> getQuery ( ) -> getResult ( ) ) ; } return $ result ; } | Finds the translation data with the specified types and names . |
26,837 | protected function mapTranslationDataResult ( array $ translationData ) : array { $ result = [ ] ; foreach ( $ translationData as $ data ) { $ result [ ] = TranslationData :: createFromArray ( $ data ) ; } return $ result ; } | Maps the query result to instances of TranslationData . |
26,838 | public function findDataByKeywords ( string $ locale , array $ keywords , array $ modCombinationIds = [ ] ) : array { $ result = [ ] ; if ( count ( $ keywords ) > 0 ) { $ concat = 'LOWER(CONCAT(t.type, t.name, t.value, t.description))' ; $ priorityCase = 'CASE WHEN t.locale = :localePrimary THEN :priorityPrimary ' . 'WHEN t.locale = :localeSecondary THEN :prioritySecondary ELSE :priorityAny END' ; $ columns = [ 't.type AS type' , 't.name AS name' , 'MIN(' . $ priorityCase . ') AS priority' ] ; $ queryBuilder = $ this -> entityManager -> createQueryBuilder ( ) ; $ queryBuilder -> select ( $ columns ) -> from ( Translation :: class , 't' ) -> andWhere ( 't.type IN (:types)' ) -> addGroupBy ( 't.type' ) -> addGroupBy ( 't.name' ) -> setParameter ( 'localePrimary' , $ locale ) -> setParameter ( 'localeSecondary' , 'en' ) -> setParameter ( 'priorityPrimary' , SearchResultPriority :: PRIMARY_LOCALE_MATCH ) -> setParameter ( 'prioritySecondary' , SearchResultPriority :: SECONDARY_LOCALE_MATCH ) -> setParameter ( 'priorityAny' , SearchResultPriority :: ANY_MATCH ) -> setParameter ( 'types' , [ TranslationType :: ITEM , TranslationType :: FLUID , TranslationType :: RECIPE ] ) ; $ index = 0 ; foreach ( $ keywords as $ keyword ) { $ queryBuilder -> andWhere ( $ concat . ' LIKE :keyword' . $ index ) -> setParameter ( 'keyword' . $ index , '%' . addcslashes ( $ keyword , '\\%_' ) . '%' ) ; ++ $ index ; } if ( count ( $ modCombinationIds ) > 0 ) { $ queryBuilder -> innerJoin ( 't.modCombination' , 'mc' ) -> andWhere ( 'mc.id IN (:modCombinationIds)' ) -> setParameter ( 'modCombinationIds' , array_values ( $ modCombinationIds ) ) ; } $ result = $ this -> mapTranslationPriorityDataResult ( $ queryBuilder -> getQuery ( ) -> getResult ( ) ) ; } return $ result ; } | Finds the types and names matching the specified keywords . |
26,839 | protected function mapTranslationPriorityDataResult ( array $ translationPriorityData ) : array { $ result = [ ] ; foreach ( $ translationPriorityData as $ data ) { $ result [ ] = TranslationPriorityData :: createFromArray ( $ data ) ; } return $ result ; } | Maps the query result to instances of TranslationPriorityData . |
26,840 | public static function toTz ( $ pDate , $ pTimezone = NULL ) { if ( $ pTimezone === NULL ) { $ pTimezone = Agl :: app ( ) -> getConfig ( 'main/global/timezone' ) ; } $ time_object = new DateTime ( $ pDate , new DateTimeZone ( self :: DEFAULT_TZ ) ) ; $ time_object -> setTimezone ( new DateTimeZone ( $ pTimezone ) ) ; return $ time_object -> format ( self :: DATE_FORMAT ) ; } | convert a date from the default timezone to the application s timezone . |
26,841 | public static function format ( $ pDate , $ pFormat = 'short' ) { switch ( $ pFormat ) { case 'short' : return strftime ( '%x' , strtotime ( $ pDate ) ) ; break ; case 'long' : return strftime ( '%x %H:%M' , strtotime ( $ pDate ) ) ; break ; case 'full' : return strftime ( '%x %H:%M:%S' , strtotime ( $ pDate ) ) ; break ; } throw new Exception ( "The requested date format is not correct" ) ; } | Format the date based on the locale and the requested format . |
26,842 | public function loadDefaultCodes ( ) { $ this -> addBBCode ( "b" , "<strong>{param}</strong>" ) ; $ this -> addBBCode ( "i" , "<em>{param}</em>" ) ; $ this -> addBBCode ( "u" , "<u>{param}</u>" ) ; $ this -> addBBCode ( "url" , "<a href=\"{param}\">{param}</a>" ) ; $ this -> addBBCode ( "url" , "<a href=\"{option}\">{param}</a>" , true ) ; $ this -> addBBCode ( "img" , "<img src=\"{param}\" alt=\"a user uploaded image\" />" ) ; $ this -> addBBCode ( "img" , "<img src=\"{param}\" alt=\"{option}\" />" , true ) ; $ this -> addBBCode ( "color" , "<span style=\"color: {option}\">{param}</span>" , true ) ; } | Adds a set of default standard bbcode definitions commonly used across the web . |
26,843 | private function getAttributeKeys ( ) : \ Generator { foreach ( $ this -> handlers as $ attributeHandler ) { $ prefix = $ attributeHandler -> getPrefix ( ) ; foreach ( $ this -> idListGenerator ( ) as $ id ) { yield $ id . '.' . $ prefix ; } } } | Obtain all attribute keys . |
26,844 | private function idListGenerator ( ) : \ Generator { if ( null === $ this -> ids ) { $ this -> ids = $ this -> metaModel -> getIdsFromFilter ( null ) ; } yield from $ this -> ids ; } | Obtain all ids in the MetaModel . |
26,845 | public function read ( $ bean , $ property ) { $ model_name = '\Lagan\Model\\' . ucfirst ( $ property [ 'name' ] ) ; $ child = new $ model_name ( ) ; $ add_to_query = '' ; foreach ( $ child -> properties as $ p ) { if ( $ p [ 'type' ] === '\\Lagan\\Property\\Position' ) { $ add_to_query = $ p [ 'name' ] . ' ASC, ' ; } } return \ R :: find ( $ property [ 'name' ] , $ bean -> getMeta ( 'type' ) . '_id = :id ORDER BY ' . $ add_to_query . 'title ASC ' , [ ':id' => $ bean -> id ] ) ; } | The read method is executed each time a property with this type is read . |
26,846 | public function getBody ( $ keyChain ) { if ( $ this -> transformer ) { $ this -> request [ $ keyChain ] = $ this -> transformer -> transformData ( $ this -> request [ $ keyChain ] ) ; } return $ this -> request ; } | return the transformed request body . |
26,847 | protected static function getFilters ( $ set = self :: S_MEDIA ) { $ tags = self :: $ _strict_tags ; $ tags_drop = self :: $ _strict_tags_drop ; $ attributes = self :: $ _strict_attributes ; switch ( $ set ) { case self :: S_MEDIA : $ tags = array_merge_recursive ( $ tags , self :: $ _media_tags ) ; $ tags_drop = array_merge_recursive ( $ tags_drop , self :: $ _media_tags_drop ) ; $ attributes = array_merge_recursive ( $ attributes , self :: $ _media_attributes ) ; case self :: S_LINK : $ tags = array_merge_recursive ( $ tags , self :: $ _link_tags ) ; $ tags_drop = array_merge_recursive ( $ tags_drop , self :: $ _link_tags_drop ) ; $ attributes = array_merge_recursive ( $ attributes , self :: $ _link_attributes ) ; case self :: S_BASIC : $ tags = array_merge_recursive ( $ tags , self :: $ _basic_tags ) ; $ tags_drop = array_merge_recursive ( $ tags_drop , self :: $ _basic_tags_drop ) ; $ attributes = array_merge_recursive ( $ attributes , self :: $ _basic_attributes ) ; break ; case self :: S_LIMITED : $ tags = array_merge_recursive ( static :: $ _limited_tags , static :: $ _media_tags ) ; $ tags_drop = array_merge_recursive ( static :: $ _limited_tags_drop , static :: $ _media_tags_drop ) ; $ attributes = array_merge_recursive ( static :: $ _limited_attributes , static :: $ _media_attributes ) ; break ; default : break ; } return [ 'tags' => $ tags , 'tags_drop' => $ tags_drop , 'attributes' => $ attributes ] ; } | Get the filters . |
26,848 | public static function cleanHTML ( $ html , $ filter_set = self :: S_MEDIA ) { $ filters = self :: getFilters ( $ filter_set ) ; $ html = preg_replace ( '/[\s]+/' , ' ' , $ html ) ; $ html = str_replace ( '> <' , '><' , $ html ) ; $ html = preg_replace ( '/(<br>)+/' , '<br>' , $ html ) ; $ html = str_replace ( [ '<br></' , '><br>' ] , [ '</' , '>' ] , $ html ) ; libxml_clear_errors ( ) ; $ html = mb_convert_encoding ( $ html , 'HTML-ENTITIES' , 'UTF-8' ) ; $ Document = new \ DOMDocument ( ) ; @ $ Document -> loadHTML ( $ html ) ; if ( empty ( $ Document ) ) { $ libXMLError = libxml_get_last_error ( ) ; $ xml_error = '' ; if ( $ libXMLError instanceof \ LibXMLError ) { $ xml_error = ", libXML reports: {$libXMLError->message}" ; } throw new HTMLException ( 'Invalid HTML provided' . $ xml_error ) ; } $ html = self :: _cleanHTML ( $ Document , $ filters ) ; $ html = preg_replace ( '/[\s]+/' , ' ' , $ html ) ; $ html = str_replace ( '> <' , '><' , $ html ) ; $ html = preg_replace ( '/(<br>)+/' , '<br>' , $ html ) ; $ html = str_replace ( [ '<br></' , '><br>' ] , [ '</' , '>' ] , $ html ) ; $ html = Sanitize :: replaceHttpsUrls ( $ html ) ; $ html = trim ( $ html ) ; if ( $ html === '<br>' ) { $ html = '' ; } return $ html ; } | Thoroughly clean HTML based on a set of filters . |
26,849 | private static function _cleanHTML ( DOMNode $ Node , array $ filters ) { $ node_contents = '' ; $ tag_name = '' ; if ( isset ( $ Node -> tagName ) ) { $ tag_name = strtolower ( trim ( $ Node -> tagName ) ) ; } assert ( 'isset($filters[\'tags_drop\']) && is_array($filters[\'tags_drop\'])' ) ; if ( ! isset ( $ filters [ 'tags_drop' ] ) || ! is_array ( $ filters [ 'tags_drop' ] ) ) { $ filters [ 'tags_drop' ] = [ ] ; } if ( $ Node instanceof DOMComment || in_array ( $ tag_name , $ filters [ 'tags_drop' ] ) ) { return '' ; } if ( ! isset ( $ Node -> childNodes ) || $ Node -> childNodes -> length == 0 ) { $ node_contents = html_entity_decode ( $ Node -> nodeValue , ENT_QUOTES , DEFAULT_CHARSET ) ; $ node_contents = preg_replace ( '/\s+/' , ' ' , $ node_contents ) ; $ node_contents = htmlentities ( $ node_contents , ENT_QUOTES , DEFAULT_CHARSET ) ; } else { foreach ( $ Node -> childNodes as $ Child ) { $ node_contents .= self :: _cleanHTML ( $ Child , $ filters ) ; } } assert ( 'isset($filters[\'tags\']) && is_array($filters[\'tags\'])' ) ; if ( ! isset ( $ filters [ 'tags' ] ) || ! is_array ( $ filters [ 'tags' ] ) ) { $ filters [ 'tags' ] = [ ] ; } if ( $ tag_name == '' || ! in_array ( $ tag_name , $ filters [ 'tags' ] ) ) { return $ node_contents ; } else { $ node_attributes = self :: _cleanAttributes ( $ Node , $ filters ) ; if ( $ node_attributes == '' && ( $ tag_name == 'a' || $ tag_name == 'img' ) ) { return $ node_contents ; } switch ( $ tag_name ) { case 'br' : case 'hr' : case 'input' : case 'img' : return "<$tag_name$node_attributes>" ; break ; default : if ( trim ( $ node_contents ) == '' && $ tag_name != 'a' ) return '' ; return "<$tag_name$node_attributes>$node_contents</$tag_name>" ; } } } | Clean the HTML of the provided DOM - node . |
26,850 | public static function convertToPlainText ( $ html , $ strip_urls = false , $ html_format = false ) { $ plain_text = $ html ; $ plain_text = str_replace ( '<li>' , ' * ' , $ plain_text ) ; $ plain_text = str_replace ( [ '</p>' , '</h1>' , '</h2>' , '</h3>' ] , PHP_EOL . PHP_EOL , $ plain_text ) ; $ plain_text = str_replace ( [ '</ul>' , '</ol>' , '<br>' , '</li>' , '</h4>' , '</h5>' ] , PHP_EOL , $ plain_text ) ; $ plain_text = preg_replace ( '/<\/?.*>/iU' , '' , $ plain_text ) ; if ( $ strip_urls ) { $ pattern = '/(?:(?:https?\:\/\/(?:www\.)?)|(?:www\.))\S+\s?/i' ; $ plain_text = preg_replace ( $ pattern , '' , $ plain_text ) ; } $ plain_text = html_entity_decode ( $ plain_text , ENT_QUOTES , DEFAULT_CHARSET ) ; $ plain_text = trim ( $ plain_text ) ; if ( $ html_format ) { $ plain_text = htmlentities ( $ plain_text , ENT_QUOTES , DEFAULT_CHARSET ) ; $ plain_text = str_replace ( PHP_EOL , '<br>' , $ plain_text ) ; $ plain_text = "<p>$plain_text</p>" ; } return $ plain_text ; } | Convert HTML to plain - text . |
26,851 | protected function validateAttributeInternal ( $ model , $ attribute ) { $ value = $ model -> { $ attribute } ; $ result = ( $ this -> type == FormatHelper :: TYPE_LIST ) ? $ this -> validateListValue ( $ model , $ value ) : $ this -> validateValue ( $ value ) ; if ( ! empty ( $ result ) ) { $ this -> addError ( $ model , $ attribute , $ result [ 0 ] , $ result [ 1 ] ) ; return ; } Yii :: info ( 'Type validation success' . PHP_EOL . "Result value for '$attribute': {$this->filteredAttribute}" , __METHOD__ ) ; $ model -> { $ attribute } = $ this -> filteredAttribute ; } | Model validation context |
26,852 | public static function WriteDefinitions ( $ fp , $ Definitions ) { uksort ( $ Definitions , 'strcasecmp' ) ; $ LastC = '' ; foreach ( $ Definitions as $ Key => $ Value ) { if ( isset ( $ Key [ 0 ] ) && strcasecmp ( $ LastC , $ Key [ 0 ] ) != 0 ) { fwrite ( $ fp , "\n" ) ; $ LastC = $ Key [ 0 ] ; } $ Str = '$Definition[' . var_export ( $ Key , TRUE ) . '] = ' . var_export ( $ Value , TRUE ) . ";\n" ; fwrite ( $ fp , $ Str ) ; } } | Write a locale s definitions to a file . |
26,853 | private function _getXPath ( ) { if ( $ this -> _xPath === NULL ) { $ this -> _xPath = new DOMXPath ( $ this -> _domDoc ) ; } return $ this -> _xPath ; } | Create a new DOMXPath . |
26,854 | public function parseXPath ( $ pPath ) { $ path = str_replace ( '@app' , '/' , $ pPath ) ; $ path = preg_replace ( '#^@module\[([a-z0-9/]+)\]|@layout#' , '' , $ path ) ; $ pathArr = explode ( '/' , $ path ) ; foreach ( $ pathArr as $ key => $ node ) { if ( preg_match ( '/^([a-zA-Z0-9\[\]@\'"=_-]+):([a-zA-Z0-9_-]+)$/' , $ node , $ matches ) ) { $ pathArr [ $ key ] = $ matches [ 1 ] . '/attribute::' . $ matches [ 2 ] ; } else if ( preg_match ( '/^([a-zA-Z0-9_-]+):([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]+)$/' , $ node , $ matches ) ) { $ pathArr [ $ key ] = $ matches [ 1 ] . '[@' . $ matches [ 2 ] . '="' . $ matches [ 3 ] . '"]' ; } else if ( preg_match ( '/^([a-zA-Z0-9_-]+)>([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]+)$/' , $ node , $ matches ) ) { $ pathArr [ $ key ] = $ matches [ 1 ] . '[' . $ matches [ 2 ] . '="' . $ matches [ 3 ] . '"]' ; } } return '//' . implode ( '/' , $ pathArr ) ; } | Parse the required config path in order to convert the Agl syntax into a valid XPath query . |
26,855 | public function xPathQuery ( $ pQuery , $ pNode = NULL ) { $ queryResult = $ this -> _getXPath ( ) -> query ( $ pQuery , $ pNode ) ; if ( $ queryResult === false ) { throw new Exception ( "Invalid XPath request" ) ; } return $ queryResult ; } | Execute an XPath query . |
26,856 | private function _getNodeAttributes ( DOMElement $ pNode ) { $ attributes = array ( ) ; if ( $ pNode -> attributes -> length ) { foreach ( $ pNode -> attributes as $ key => $ attr ) { $ attributes [ $ key ] = $ attr -> value ; } } return $ attributes ; } | Get the node attributes as array . |
26,857 | protected function transformUrl ( $ url , $ transformation ) { $ cachedUrl = $ this -> pool -> getItem ( md5 ( $ url ) ) ; if ( $ cachedUrl -> isMiss ( ) ) { $ url = $ this -> provider -> $ transformation ( $ url ) ; $ cachedUrl -> set ( $ url ) ; } else { $ url = $ cachedUrl -> get ( ) ; } return $ url ; } | Shorten or expand a URL checking it in the cache first |
26,858 | public static function cleanModuleList ( $ modules ) { $ app = \ JFactory :: getApplication ( ) ; $ Itemid = \ JFactory :: getApplication ( ) -> input -> getInt ( 'Itemid' ) ; $ negId = $ Itemid ? - ( int ) $ Itemid : false ; $ clean = array ( ) ; $ dupes = array ( ) ; foreach ( $ modules as $ i => $ module ) { $ negHit = ( $ negId === ( int ) $ module -> menuid ) ; if ( isset ( $ dupes [ $ module -> id ] ) ) { if ( $ negHit ) { unset ( $ clean [ $ module -> id ] ) ; } continue ; } $ dupes [ $ module -> id ] = true ; if ( $ negHit ) { continue ; } $ module -> name = substr ( $ module -> module , 4 ) ; $ module -> style = null ; $ module -> position = strtolower ( $ module -> position ) ; $ clean [ $ module -> id ] = $ module ; } unset ( $ dupes ) ; $ app -> triggerEvent ( 'onPrepareModuleList' , array ( & $ clean ) ) ; $ app -> triggerEvent ( 'onAlterModuleList' , array ( & $ clean ) ) ; $ app -> triggerEvent ( 'onPostProcessModuleList' , array ( & $ clean ) ) ; return array_values ( $ clean ) ; } | Clean the module list |
26,859 | private function setLink ( $ type , $ name , $ constraint ) { $ this -> set ( $ type . '/' . $ this -> escape ( $ name ) , $ constraint ) ; return $ this ; } | Set a link on a dependency to a constraint . |
26,860 | public function setLock ( PackageInterface $ package , $ state ) { if ( ( bool ) $ state ) { return $ this -> lockPackage ( $ package ) ; } return $ this -> unlockPackage ( $ package ) ; } | Set the locking state for the passed package . |
26,861 | private function cleanEmptyArraysInPath ( $ path ) { $ subs = $ this -> getEntries ( $ path ) ; if ( ! empty ( $ subs ) ) { foreach ( $ subs as $ subPath ) { $ this -> cleanEmptyArraysInPath ( $ subPath ) ; } } if ( [ ] === $ this -> get ( $ path ) ) { $ this -> remove ( $ path ) ; } } | Cleanup the array section at the given path by removing empty sub arrays . |
26,862 | public function clear ( ) { $ params = [ 'index' => $ this -> _esindex , 'type' => $ this -> _estype , 'body' => [ 'query' => [ 'match_all' => [ ] ] ] ] ; $ query = $ this -> _es -> deleteByQuery ( $ params ) ; $ result = true ; return $ result ; } | Clear tweets in elasticsearch |
26,863 | public function save ( ) { $ result = null ; $ i = 0 ; foreach ( $ iterator = new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $ this -> _dir , RecursiveDirectoryIterator :: SKIP_DOTS ) , RecursiveIteratorIterator :: SELF_FIRST ) as $ item ) { if ( ! $ item -> isDir ( ) ) { $ filename = $ this -> _dir . DIRECTORY_SEPARATOR . $ iterator -> getSubPathName ( ) ; $ _tweet = file_get_contents ( $ filename ) ; $ tweet = json_decode ( $ _tweet , TRUE ) ; $ params = [ 'index' => $ this -> _esindex , 'type' => $ this -> _estype , 'body' => $ tweet ] ; $ result = $ this -> _es -> index ( $ params ) ; $ i ++ ; } } return $ i ; } | Save tweets in elasticsearch |
26,864 | public function tweets ( $ limit = 1000 ) { $ params = [ 'index' => $ this -> _esindex , 'type' => $ this -> _estype , 'size' => $ limit , 'body' => [ 'query' => [ 'match_all' => [ ] ] ] ] ; $ query = $ this -> _es -> search ( $ params ) ; if ( $ query [ 'hits' ] [ 'total' ] >= 1 ) $ result = $ query [ 'hits' ] [ 'hits' ] ; else $ result = [ ] ; return $ result ; } | Return all tweets |
26,865 | public function moveUploadedFile ( File $ file , $ path_pattern = null ) { $ interpolated = $ this -> interpolator -> resolveStorePath ( $ path_pattern ? : $ this -> getConfig ( 'store.path_pattern' , '' ) , $ file ) ; $ target = $ this -> getStoreRootPath ( ) . '/' . ltrim ( $ interpolated , '/' ) ; if ( ! file_exists ( $ target ) ) { $ file -> move ( dirname ( $ target ) , basename ( $ target ) ) ; } return $ interpolated ; } | Move uploaded file to path by pattern |
26,866 | public function makeUrlToUploadedFile ( $ model , $ path_pattern = null , array $ model_map = array ( ) , $ domain = null ) { $ pattern = $ path_pattern ? : $ this -> getConfig ( 'http.path_pattern' , '' ) ; if ( is_null ( $ domain ) ) { $ domain = $ this -> getConfig ( 'http.domain' , '' ) ; } $ path = $ this -> interpolator -> resolvePath ( $ pattern , $ model , $ model_map ) -> getResult ( ) ; $ path = rtrim ( $ domain , '/' ) . '/' . ltrim ( $ path , '/' ) ; return $ path ; } | Make url to uploaded file |
26,867 | public function makePathToUploadedFile ( $ model , $ path_pattern = null , array $ model_map = array ( ) ) { $ pattern = $ path_pattern ? : $ this -> getConfig ( 'store.path_pattern' , '' ) ; $ path = $ this -> interpolator -> resolvePath ( $ pattern , $ model , $ model_map ) -> getResult ( ) ; $ path = $ this -> getStoreRootPath ( ) . '/' . ltrim ( $ path , '/' ) ; return $ path ; } | Full path to uploaded file |
26,868 | public function deleteUploadedFile ( $ model , $ path_pattern = null ) { if ( ! $ this -> canRemoveFiles ( ) ) { return null ; } $ filepath = $ this -> path ( $ model , $ path_pattern ) ; if ( $ filepath && file_exists ( $ filepath ) ) { return unlink ( $ filepath ) ; } return false ; } | Delete uploaded file |
26,869 | public function getUrlRacine ( ) { $ protocol = empty ( $ _SERVER [ "HTTPS" ] ) ? "http" : "https" ; if ( isset ( $ _SERVER [ "SERVER_NAME" ] ) ) { $ dirname = dirname ( $ _SERVER [ "PHP_SELF" ] ) ; if ( basename ( $ dirname ) == "script" ) { $ dirname = dirname ( $ dirname ) ; } } else { $ dirname = "" ; } $ url = $ protocol . "://" . $ this -> getNomServeur ( ) . $ dirname ; if ( $ dirname != "/" ) { $ url .= "/" ; } return $ url ; } | Renvoit la racine de l URL |
26,870 | public function getUrlImage ( $ size = "" , $ name = "" ) { if ( ! empty ( $ size ) ) { $ size .= "/" ; } return $ this -> getUrlRacine ( ) . "images/" . $ size . $ name ; } | Permet d obtenir l URL du dossier d une image |
26,871 | protected function createBuilder ( ResolvedType $ type , array $ options ) { $ builder = new TableBuilder ( $ type , $ this , $ options ) ; $ extensions = $ this -> getExtensionsForType ( $ type ) ; foreach ( $ extensions as $ extension ) { $ extension -> buildTable ( $ builder , $ options ) ; } $ type -> buildTable ( $ builder , $ options ) ; foreach ( $ extensions as $ extension ) { $ extension -> finishTable ( $ builder , $ options ) ; } return $ builder ; } | Creates the table builder for a table type . |
26,872 | private function findExtensions ( & $ extensions , $ name ) { $ extension = $ this -> getExtension ( $ name ) ; foreach ( ( array ) $ extension -> getDependency ( ) as $ dep ) { if ( ! isset ( $ extensions [ $ dep ] ) ) { $ this -> findExtensions ( $ extensions , $ dep ) ; } } $ extensions [ $ name ] = $ extension ; } | Find extnesions recursively |
26,873 | private function sortExtensions ( ) { $ this -> sortedExtensions = array ( ) ; foreach ( $ this -> extensions as $ extension ) { $ this -> addExtensionToSorted ( $ extension ) ; } } | Sort the extensions by dependency |
26,874 | public static function getPercentageColor ( int $ percentage , int $ redLimit = 30 , int $ orangeLimit = 70 ) : string { return $ percentage < $ redLimit ? self :: COLOR_RED : ( $ percentage < $ orangeLimit ? self :: COLOR_ORANGE : self :: COLOR_GREEN ) ; } | Get a color related to a percentage |
26,875 | public function withTransformations ( $ value ) { if ( $ value === null ) return null ; foreach ( $ this -> valueTransformations as $ f ) $ value = $ f ( $ value ) ; return $ value ; } | Returns the given value with all transformations applied |
26,876 | function checkLink ( ) { if ( ! isset ( $ _POST [ 'link' ] ) ) { $ this -> sendError ( ) ; } $ link = strtolower ( str_replace ( [ " " , '"' , "'" , ';' , '.' , ',' ] , [ "-" , "" ] , preg_replace ( "/&([a-z])[a-z]+;/i" , "$1" , htmlentities ( trim ( $ _POST [ 'link' ] ) ) ) ) ) ; $ base = new Model \ Base ; $ status = $ base -> checkLink ( $ link , $ _POST [ 'aID' ] ) === false ? 'ok' : 'error' ; $ this -> send ( [ 'status' => $ status , 'link' => $ link ] ) ; } | Check if link is in use |
26,877 | public function getSegments ( ) { if ( ! isset ( $ this -> segments ) ) $ this -> segments = explode ( '/' , $ this -> path ) ; return $ this -> segments ; } | Get path segments |
26,878 | public function register ( $ name ) { return $ this -> addCommand ( new Command ( $ name , $ this -> input , $ this -> output ) ) ; } | Register a new Console . |
26,879 | public function createCacheKey ( $ keys ) { if ( is_array ( $ keys ) ) { $ key = array_shift ( $ keys ) ; if ( $ keys ) { foreach ( $ keys as $ value ) { if ( is_array ( $ value ) ) { $ key .= '-' . md5 ( json_encode ( $ value ) ) ; } else if ( $ value ) { $ key .= '-' . $ value ; } } } } else { $ key = $ keys ; } return ( string ) $ key ; } | Generate a cache key . If an array is passed drill down and form a key . |
26,880 | public function setCache ( $ key , $ value ) { $ this -> _cache [ $ this -> createCacheKey ( $ key ) ] = $ value ; return $ value ; } | Set a value to the cache with the defined key . This will overwrite any data with the same key . The value being saved will be returned . |
26,881 | public function stream_close ( ) { if ( ! \ is_resource ( $ this -> resource ) ) { return ; } if ( $ this -> resourceType === static :: RESOURCE_TYPE_FILE ) { \ fclose ( $ this -> resource ) ; } else if ( $ this -> ssl ) { \ fclose ( $ this -> resource ) ; $ saveFile = $ this -> getSaveFile ( ) ; \ file_put_contents ( $ saveFile , $ this -> content ) ; } else if ( $ this -> resourceType === static :: RESOURCE_TYPE_SOCKET ) { @ \ socket_shutdown ( $ this -> resource ) ; \ socket_close ( $ this -> resource ) ; $ saveFile = $ this -> getSaveFile ( ) ; \ file_put_contents ( $ saveFile , $ this -> content ) ; } $ this -> resource = NULL ; static :: clearSaveFile ( ) ; } | Close the resource . |
26,882 | static private function isValidFilename ( $ pFilename ) { $ invalidChars = [ ',' , '<' , '>' , '*' , '?' , '|' , '\\' , '/' , "'" , '"' , ':' ] ; $ invalidCharRegExPatter = '@' . implode ( $ invalidChars ) . '@' ; if ( \ preg_match ( $ invalidCharRegExPatter , $ pFilename ) === 1 ) { \ trigger_error ( 'A filename cannot contain the following characters: ' . implode ( '' , $ invalidChars ) ) ; return FALSE ; } return TRUE ; } | Validate a name filename . |
26,883 | private function getSaveFile ( ) { $ filename = static :: getSaveFilename ( ) . static :: persistSuffix ( ) ; if ( empty ( $ filename ) ) { throw new InterceptionException ( InterceptionException :: NO_FILENAME ) ; } $ ext = '.rsd' ; return static :: getSaveDir ( ) . DIRECTORY_SEPARATOR . $ filename . $ ext ; } | Get the full file path by generating one from the URL or the one set by the developer . |
26,884 | private function populateResponseHeaders ( ) { $ done = FALSE ; $ line = NULL ; $ header = '' ; $ buffer = NULL ; if ( $ this -> resourceType === static :: RESOURCE_TYPE_FILE ) { $ done = \ feof ( $ this -> resource ) ; } while ( ! $ done ) { $ buffer = $ this -> readFromResource ( 1 ) ; $ this -> content .= $ buffer ; $ header = \ strstr ( $ this -> content , "\r\n\r\n" , TRUE ) ; if ( $ buffer === '' || $ header !== FALSE ) { break ; } } $ this -> position += \ strlen ( $ this -> content ) ; if ( strlen ( trim ( $ header ) ) > 0 ) { $ this -> wrapperData = explode ( "\r\n" , $ header ) ; } } | Parse the content for the headers . |
26,885 | private function triggerSocketError ( ) { $ errorNo = \ socket_last_error ( $ this -> resource ) ; $ errorStr = \ socket_strerror ( $ errorNo ) ; \ trigger_error ( '\\Kshabazz\\Interception\\StreamWrappers\\Http ' . $ errorStr ) ; } | Trigger socket error . |
26,886 | public function convert ( $ content ) { $ result = strtr ( $ content , $ this -> rules ) ; return $ this -> correct ( $ result ) ; } | Convert content from one encoding to another |
26,887 | protected function correct ( $ content ) { $ corrections = $ this -> corrections ; if ( ! empty ( $ corrections ) ) { foreach ( $ corrections as $ pattern => $ replacement ) { $ reg_count = 0 ; $ content = preg_replace ( '/' . $ pattern . '/us' , $ replacement , $ content , - 1 , $ reg_count ) ; } } return $ content ; } | Correct any ordering or encoding error using regular expression |
26,888 | public function serviceGroup ( $ group ) { $ group = intval ( $ group ) ; if ( empty ( $ group ) ) { return array ( ) ; } $ json = $ this -> service ( 'group' , $ group ) ; return $ json ; } | Call service for Group |
26,889 | public function serviceTree ( $ node = null ) { $ node = ( $ node === null ) ? - 1 : $ node ; $ json = $ this -> service ( 'tree' , $ node ) ; return $ json ; } | Call service for Tree |
26,890 | public function treeData ( $ tree ) { $ receiver = new TreeReceiver ( $ this -> getCacheLink ( ) , $ this -> projectId ) ; return $ receiver -> getArrayData ( $ tree ) ; } | Receive group data |
26,891 | public static function concat ( $ one , $ other ) { Arguments :: define ( Boa :: either ( Boa :: lst ( ) , Boa :: string ( ) ) , Boa :: either ( Boa :: lst ( ) , Boa :: string ( ) ) ) -> check ( $ one , $ other ) ; $ oneType = TypeHound :: fetch ( $ one ) ; $ twoType = TypeHound :: fetch ( $ other ) ; if ( $ oneType !== $ twoType ) { throw new MismatchedArgumentTypesException ( __FUNCTION__ , $ one , $ other ) ; } if ( $ oneType === ScalarTypes :: SCALAR_STRING ) { return $ one . $ other ; } return ArrayMap :: of ( $ one ) -> append ( ArrayMap :: of ( $ other ) ) -> toArray ( ) ; } | Concatenate the two provided values . |
26,892 | public static function each ( callable $ function , $ input ) { if ( $ input instanceof FoldableInterface ) { $ input -> foldl ( function ( $ acc , $ x ) use ( $ function ) { $ function ( $ x ) ; } , null ) ; return ; } elseif ( $ input instanceof LeftFoldableInterface ) { $ input -> foldl ( function ( $ x ) use ( $ function ) { $ function ( $ x ) ; } , null ) ; return ; } static :: map ( $ function , $ input ) ; } | Call the provided function on each element . |
26,893 | public static function within ( $ min , $ max , $ value ) { Arguments :: define ( Boa :: either ( Boa :: integer ( ) , Boa :: float ( ) ) , Boa :: either ( Boa :: integer ( ) , Boa :: float ( ) ) , Boa :: either ( Boa :: integer ( ) , Boa :: float ( ) ) ) -> check ( $ min , $ max , $ value ) ; if ( $ min > $ max ) { throw new LackOfCoffeeException ( 'Max value is less than the min value.' ) ; } return ( $ min <= $ value && $ max >= $ value ) ; } | Check if a value is between two other values . |
26,894 | public static function rope ( $ string , $ encoding = null ) { Arguments :: define ( Boa :: string ( ) , Boa :: maybe ( Boa :: string ( ) ) ) -> check ( $ string , $ encoding ) ; return new Rope ( $ string , $ encoding ) ; } | Create a new instance of a rope . |
26,895 | public static function esc ( $ string ) { Arguments :: define ( Boa :: string ( ) ) -> check ( $ string ) ; return htmlspecialchars ( $ string , ENT_QUOTES , 'UTF-8' ) ; } | Escape the provided input for HTML . |
26,896 | public static function callSetters ( $ object , array $ input , array $ allowed = null ) { $ filtered = ArrayMap :: of ( $ input ) ; if ( $ allowed !== null ) { $ filtered = $ filtered -> only ( $ allowed ) ; } $ filtered -> each ( function ( $ value , $ key ) use ( & $ object ) { $ setterName = 'set' . Str :: studly ( $ key ) ; $ object -> $ setterName ( $ value ) ; } ) ; } | Set properties of an object by only calling setters of array keys that are set in the input array . Useful for parsing API responses into entities . |
26,897 | public static function firstBias ( $ biased , $ one , $ other ) { Arguments :: define ( Boa :: boolean ( ) , Boa :: any ( ) , Boa :: any ( ) ) -> check ( $ biased , $ one , $ other ) ; if ( $ biased ) { return static :: thunk ( $ one ) ; } return static :: thunk ( $ other ) ; } | Return the first value if the condition is true otherwise return the second . |
26,898 | public static function foldr ( callable $ function , $ initial , $ foldable ) { Arguments :: define ( Boa :: func ( ) , Boa :: any ( ) , Boa :: foldable ( ) ) -> check ( $ function , $ initial , $ foldable ) ; return ComplexFactory :: toFoldable ( $ foldable ) -> foldr ( $ function , $ initial ) ; } | Same as foldl but it works from right to left . |
26,899 | public static function map ( callable $ function , $ traversable ) { $ aggregation = [ ] ; foreach ( $ traversable as $ key => $ value ) { $ aggregation [ $ key ] = $ function ( $ value , $ key ) ; } return $ aggregation ; } | Call a function on every item in a list and return the resulting list . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.