idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
2,300 | protected function findModelByRouteKey ( $ key ) { return $ this -> model -> where ( $ this -> model -> getRouteKeyName ( ) , $ key ) -> first ( ) ; } | Find Eloquent model by route key . |
2,301 | protected function getAllRouteNames ( $ resourceName = null ) { $ resourceName = $ resourceName ?? $ this -> resourceName ; return [ 'index' => $ this -> prefix . $ this -> resourceName . '.index' , 'create' => $ this -> prefix . $ this -> resourceName . '.create' , 'store' => $ this -> prefix . $ this -> resourceName . '.store' , 'show' => $ this -> prefix . $ this -> resourceName . '.show' , 'edit' => $ this -> prefix . $ this -> resourceName . '.edit' , 'update' => $ this -> prefix . $ this -> resourceName . '.update' , 'destroy' => $ this -> prefix . $ this -> resourceName . '.destroy' , ] ; } | Get all route names for the specified resource . |
2,302 | public function composeWithModel ( View $ view ) { $ key = $ this -> getModelRouteKey ( ) ; $ model = $ this -> findModelByRouteKey ( $ key ) ; $ view -> with ( 'model' , $ model ) ; } | Compose with model . |
2,303 | public function composeWithAllRouteNames ( View $ view ) { $ routes = $ this -> getAllRouteNames ( ) ; foreach ( $ routes as $ action => $ routeName ) { $ view -> with ( "{$action}Route" , $ routeName ) ; } } | Compose with all route names for the specified resource . |
2,304 | public function composeWithRequiredFields ( View $ view ) { $ requiredFields = array_keys ( $ this -> getRequiredFields ( ) ) ; $ view -> with ( 'requiredFields' , $ requiredFields ) ; } | Compose with validation required fields . |
2,305 | private function _checkModelProperty ( ) { if ( ! $ this -> model ) { if ( Lang :: has ( 'resource-composer.propertynotset' ) ) { $ message = trans ( 'resource-composer.propertynotset' , [ 'property' => '$model' ] ) ; } else { $ message = '$model property must be set.' ; } throw new ResourceComposerException ( $ message ) ; } } | Throw an exception if model property is not set . |
2,306 | public function getElement ( $ name , $ offset = null , & $ pieceOfPath = null ) { if ( StringUtils :: beginsWith ( "this." , $ name ) ) { $ name = substr ( $ name , 5 ) ; } if ( null !== $ offset ) { if ( $ offset < 0 ) { throw new BadParameterException ( "\$offset can't be negative. " . $ offset . " given" ) ; } $ lastPath = "" ; while ( $ offset > 0 ) { $ lastDot = strrpos ( $ name , "." ) ; $ lastPath = substr ( $ name , $ lastDot + 1 ) . "." . $ lastPath ; $ name = substr ( $ name , 0 , $ lastDot ) ; $ offset -- ; } if ( "" === $ name ) { throw new \ Face \ Exception \ RootFaceReachedException ( "Offset was too deep and reached root face" ) ; } $ lastPath = rtrim ( $ lastPath , "." ) ; $ pieceOfPath [ 0 ] = $ name ; $ pieceOfPath [ 1 ] = $ lastPath ; } if ( false !== strpos ( $ name , "." ) ) { $ firstChildFace = $ this -> getElement ( strstr ( $ name , "." , true ) ) -> getFace ( ) ; return $ firstChildFace -> getElement ( trim ( strstr ( $ name , "." ) , "." ) ) ; } if ( ! isset ( $ this -> elements [ $ name ] ) ) { throw new FaceElementDoesntExistsException ( $ name , $ this ) ; } return $ this -> elements [ $ name ] ; } | get the element in this element with the given name |
2,307 | public function make ( $ transformer ) { if ( is_string ( $ transformer ) ) { return $ this -> makeTransformerClass ( $ transformer ) ; } else if ( is_callable ( $ transformer ) ) { return $ this -> makeCallableTransformer ( $ transformer ) ; } else if ( is_object ( $ transformer ) && method_exists ( $ transformer , 'transform' ) ) { return $ transformer ; } throw new ResolveTransformerException ( "Cannot resolve transformer" ) ; } | Build a transformer object . |
2,308 | public function getDefaultDataByteLength ( ) { $ default = - 1 ; $ length = $ default ; switch ( $ this -> storage_type ) { case StorageType :: NOBYTES : $ length = 0 ; break ; case StorageType :: BYTE : $ length = 1 ; break ; case StorageType :: WORD : $ length = 2 ; break ; case StorageType :: DWORD : $ length = 4 ; break ; case StorageType :: QWORD : $ length = 8 ; break ; } return $ length ; } | Certain storage container types do not require a data length because it is predefined . |
2,309 | final public function getAllowedDataFromRequest ( array $ requestParams , $ httpMethod ) { if ( in_array ( $ httpMethod , [ 'PATCH' , 'PUT' ] ) ) { $ properties = $ this -> getModifiableProperties ( ) ; } elseif ( $ httpMethod === 'POST' ) { $ properties = $ this -> getWritableProperties ( ) ; } else { return [ ] ; } $ data = [ ] ; if ( false === empty ( $ properties ) ) { foreach ( $ properties as $ property ) { $ lcProperty = lcfirst ( $ property ) ; if ( array_key_exists ( $ lcProperty , $ requestParams ) ) { $ data [ $ property ] = $ requestParams [ $ lcProperty ] ; } } } return $ data ; } | Hydrates an ActiveRecord with filtered Request params |
2,310 | final public function getExposedProperties ( ) { if ( null === $ this -> exposedProperties ) { $ this -> exposedProperties = array_diff ( $ this -> getVisibleFields ( ) , $ this -> getHiddenFieldsAndRelations ( ) ) ; } return $ this -> exposedProperties ; } | None all or partial list of properties |
2,311 | final public function getExposedRelations ( ) { if ( null === $ this -> exposedRelations ) { $ this -> exposedRelations = array_diff ( $ this -> getRelationsNames ( ) , $ this -> getHiddenFieldsAndRelations ( ) ) ; } return $ this -> exposedRelations ; } | None all or partial list of relations |
2,312 | final public function getRelations ( ) { if ( $ this -> relationsBuilt === false ) { $ tableMap = $ this -> getTableMap ( ) ; $ this -> buildRelations ( $ tableMap ) ; $ this -> relationsBuilt = true ; } return $ this -> relations ; } | Returns names of relations |
2,313 | public function init ( ) { if ( count ( $ this -> buckets ) ) { foreach ( $ this -> buckets as $ alias => $ bucket ) { $ this -> _buckets [ $ alias ] = new BucketFileSystem ( $ bucket [ 'basePath' ] , $ bucket [ 'baseUrl' ] , isset ( $ bucket [ 'filePermission' ] ) ? $ bucket [ 'filePermission' ] : 0777 ) ; } } } | Initialization storage system |
2,314 | static public function ConvertIPv4CIDRToMask ( $ cidr ) { $ subnetMask = str_pad ( "" , $ cidr , "1" ) ; $ subnetMask = str_pad ( $ subnetMask , 32 , "0" ) ; $ subnetMask = array_map ( function ( $ x ) { return bindec ( $ x ) ; } , str_split ( $ subnetMask , 8 ) ) ; return implode ( "." , $ subnetMask ) ; } | Converts IPv4 CIDR to subnet mask format |
2,315 | static public function ConvertIPv4CIDRToDecimal ( $ ipAndCidr ) { list ( $ ip , $ subnetMask ) = explode ( "/" , $ ipAndCidr ) ; $ ip = static :: ConvertIPv4ToDecimal ( $ ip ) ; $ subnetMask = static :: ConvertIPv4CIDRToMask ( $ subnetMask ) ; $ subnetMask = static :: ConvertIPv4ToDecimal ( $ subnetMask ) ; return compact ( 'ip' , 'subnetMask' ) ; } | Converts IPv4 and CIDR to decimal notation |
2,316 | static public function IsIPv4SubnetWithinSupernet ( $ ipAndCidrSub , $ ipAndCidrSuper ) { $ ipAndCidrSubMin = static :: ConvertIPv4ToDecimal ( static :: GetIPv4NetworkAddress ( $ ipAndCidrSub ) ) ; $ ipAndCidrSubMax = static :: ConvertIPv4ToDecimal ( static :: GetIPv4BroadcastAddress ( $ ipAndCidrSub ) ) ; $ ipAndCidrSuperMin = static :: ConvertIPv4ToDecimal ( static :: GetIPv4NetworkAddress ( $ ipAndCidrSuper ) ) ; $ ipAndCidrSuperMax = static :: ConvertIPv4ToDecimal ( static :: GetIPv4BroadcastAddress ( $ ipAndCidrSuper ) ) ; if ( $ ipAndCidrSuperMin <= $ ipAndCidrSubMin && $ ipAndCidrSuperMax >= $ ipAndCidrSubMax ) { return true ; } return false ; } | Checks if a given range is within a range |
2,317 | static public function GetIPv4NumberOfHostAddresses ( $ ipAndCidr ) { $ ipAndCidrNetwork = static :: ConvertIPv4ToDecimal ( static :: GetIPv4NetworkAddress ( $ ipAndCidr ) ) ; $ ipAndCidrBroadcast = static :: ConvertIPv4ToDecimal ( static :: GetIPv4BroadcastAddress ( $ ipAndCidr ) ) ; return $ ipAndCidrBroadcast - $ ipAndCidrNetwork - 1 ; } | Get the number of host addresses in a given subnet |
2,318 | static public function IsIPv6SubnetWithinSupernet ( $ ipAndCidrSub , $ ipAndCidrSuper ) { $ ipAndCidrSubMin = static :: ConvertIPv6ToBinary ( static :: GetIPv6NetworkAddress ( $ ipAndCidrSub ) ) ; $ ipAndCidrSubMax = static :: ConvertIPv6ToBinary ( static :: GetIPv6BroadcastAddress ( $ ipAndCidrSub ) ) ; $ ipAndCidrSuperMin = static :: ConvertIPv6ToBinary ( static :: GetIPv6NetworkAddress ( $ ipAndCidrSuper ) ) ; $ ipAndCidrSuperMax = static :: ConvertIPv6ToBinary ( static :: GetIPv6BroadcastAddress ( $ ipAndCidrSuper ) ) ; if ( $ ipAndCidrSuperMin <= $ ipAndCidrSubMin && $ ipAndCidrSuperMax >= $ ipAndCidrSubMax ) { return true ; } return false ; } | Checks if an IPv6 subnet is within an IPv6 supernet |
2,319 | static public function NormalizeIPv6Address ( $ ipv6 ) { if ( strpos ( $ ipv6 , "::" ) === false && substr_count ( $ ipv6 , ":" ) !== 7 ) { throw new \ Exception ( "Invalid IPv6 address" ) ; } if ( strpos ( $ ipv6 , "::" ) !== false ) { $ padding = ":" ; $ paddingRequired = 9 - substr_count ( $ ipv6 , ":" ) ; while ( substr_count ( $ padding , ":" ) < $ paddingRequired ) { $ padding .= "0000:" ; } $ ipv6 = str_replace ( "::" , $ padding , $ ipv6 ) ; } $ ipv6 = explode ( ":" , $ ipv6 ) ; foreach ( $ ipv6 as & $ field ) { while ( strlen ( $ field ) < 4 ) { $ field = "0{$field}" ; } } return implode ( ":" , $ ipv6 ) ; } | Converts an IPv6 address and formats to leading 0s format |
2,320 | public function getRenderedTitle ( ) { $ rendered = $ this -> getRenderedContent ( ) ; if ( $ rendered instanceof Content || $ rendered instanceof MetaContent ) { return $ rendered -> title ; } return null ; } | Get rendered title |
2,321 | public function setRootTitle ( $ title ) { $ content = $ this -> getDependentContent ( ) ; if ( $ content ) { $ content -> title = $ title ; } return $ this ; } | Set root title |
2,322 | protected function getConstructParameters ( ReflectionClass $ reflectionClass , array $ data ) : array { $ constructor = $ reflectionClass -> getConstructor ( ) ; if ( $ constructor instanceof ReflectionMethod ) { foreach ( $ constructor -> getParameters ( ) as $ parameter ) { $ name = $ parameter -> getName ( ) ; $ class = $ parameter -> getClass ( ) ; if ( $ class instanceof ReflectionClass ) { $ value = $ class -> newInstanceArgs ( $ this -> getConstructParameters ( $ class , $ data [ $ name ] ?? [ ] ) ) ; } elseif ( array_key_exists ( $ name , $ data ) === true ) { $ value = $ data [ $ name ] ; } elseif ( $ parameter -> isDefaultValueAvailable ( ) === true ) { $ value = $ parameter -> getDefaultValue ( ) ; } elseif ( $ parameter -> allowsNull ( ) === true ) { $ value = null ; } else { throw new MissingConstructParameter ( $ parameter ) ; } $ parameters [ $ name ] = $ value ; } } return $ parameters ?? [ ] ; } | Get construct parameters . |
2,323 | protected function getObjectValues ( object $ object ) : array { $ class = new ReflectionClass ( get_class ( $ object ) ) ; $ constructor = $ class -> getConstructor ( ) ; if ( $ constructor instanceof ReflectionMethod ) { foreach ( $ constructor -> getParameters ( ) as $ parameter ) { $ name = $ parameter -> getName ( ) ; $ property = $ class -> getProperty ( $ name ) ; $ property -> setAccessible ( true ) ; $ value = $ property -> getValue ( $ object ) ; if ( is_object ( $ value ) === true ) { $ value = $ this -> getObjectValues ( $ value ) ; } $ data [ $ name ] = $ value ; } } return $ data ?? [ ] ; } | Get object values . |
2,324 | private function addCsrf ( ) { if ( ! $ this -> getName ( ) ) { throw new \ LogicException ( "Can't set CSRF token with form name" ) ; } $ csrfName = 'CSRF_' . $ this -> getName ( ) ; $ csrfToken = md5 ( ( string ) mt_rand ( ) ) ; self :: session ( ) -> set ( $ csrfName , $ csrfToken ) ; $ this -> addFirst ( new Hidden ( '_csrf' , $ csrfToken ) ) ; } | add Csrf input hidden . |
2,325 | protected function readContent ( $ path ) { $ str = file_get_contents ( $ path ) ; if ( is_string ( $ str ) ) { return $ str ; } else { throw new LogicException ( Message :: get ( Message :: ENV_READ_FAIL , $ path ) , Message :: ENV_READ_FAIL ) ; } } | Read from a file returns the content string |
2,326 | public static function getFormItemByAttributeName ( $ attributeName , $ attributeValue , $ localizedName = "" ) { $ attributeType = substr ( $ attributeName , 2 , 1 ) ; if ( $ attributeType == "s" ) { $ formItem = static :: getFormItemByAttributeType ( "shorttext" , $ attributeName , $ attributeValue , $ localizedName ) ; } else if ( $ attributeType == "l" ) { $ formItem = static :: getFormItemByAttributeType ( "longtext" , $ attributeName , $ attributeValue , $ localizedName ) ; } else if ( $ attributeType == "h" ) { $ formItem = static :: getFormItemByAttributeType ( "htmllongtext" , $ attributeName , $ attributeValue , $ localizedName ) ; } else if ( $ attributeType == "t" ) { $ formItem = static :: getFormItemByAttributeType ( "time" , $ attributeName , $ attributeValue , $ localizedName ) ; } else if ( $ attributeType == "d" ) { $ formItem = static :: getFormItemByAttributeType ( "date" , $ attributeName , $ attributeValue , $ localizedName ) ; } else if ( $ attributeType == "w" ) { $ formItem = static :: getFormItemByAttributeType ( "weekday" , $ attributeName , $ attributeValue , $ localizedName ) ; } else { $ formItem = static :: getFormItemByAttributeType ( "shorttext" , $ attributeName , $ attributeValue , $ localizedName ) ; } return $ formItem ; } | Creates a MFormItem by a given attributeName . |
2,327 | public static function getDefault ( ) { if ( ( self :: $ compatibilityMode === true ) or ( func_num_args ( ) > 0 ) ) { if ( ! self :: $ _breakChain ) { self :: $ _breakChain = true ; trigger_error ( 'You are running Zend_Locale in compatibility mode... please migrate your scripts' , E_USER_NOTICE ) ; $ params = func_get_args ( ) ; $ param = null ; if ( isset ( $ params [ 0 ] ) ) { $ param = $ params [ 0 ] ; } return self :: getOrder ( $ param ) ; } self :: $ _breakChain = false ; } return self :: $ _default ; } | Return the default locale |
2,328 | public static function getEnvironment ( ) { if ( self :: $ _environment !== null ) { return self :: $ _environment ; } $ language = setlocale ( LC_ALL , 0 ) ; $ languages = explode ( ';' , $ language ) ; $ languagearray = array ( ) ; foreach ( $ languages as $ locale ) { if ( strpos ( $ locale , '=' ) !== false ) { $ language = substr ( $ locale , strpos ( $ locale , '=' ) ) ; $ language = substr ( $ language , 1 ) ; } if ( $ language !== 'C' ) { if ( strpos ( $ language , '.' ) !== false ) { $ language = substr ( $ language , 0 , strpos ( $ language , '.' ) ) ; } else if ( strpos ( $ language , '@' ) !== false ) { $ language = substr ( $ language , 0 , strpos ( $ language , '@' ) ) ; } $ language = str_ireplace ( array_keys ( Zend_Locale_Data_Translation :: $ languageTranslation ) , array_values ( Zend_Locale_Data_Translation :: $ languageTranslation ) , ( string ) $ language ) ; $ language = str_ireplace ( array_keys ( Zend_Locale_Data_Translation :: $ regionTranslation ) , array_values ( Zend_Locale_Data_Translation :: $ regionTranslation ) , $ language ) ; if ( isset ( self :: $ _localeData [ $ language ] ) === true ) { $ languagearray [ $ language ] = 1 ; if ( strpos ( $ language , '_' ) !== false ) { $ languagearray [ substr ( $ language , 0 , strpos ( $ language , '_' ) ) ] = 1 ; } } } } self :: $ _environment = $ languagearray ; return $ languagearray ; } | Expects the Systems standard locale |
2,329 | public static function getBrowser ( ) { if ( self :: $ _browser !== null ) { return self :: $ _browser ; } $ httplanguages = getenv ( 'HTTP_ACCEPT_LANGUAGE' ) ; if ( empty ( $ httplanguages ) && array_key_exists ( 'HTTP_ACCEPT_LANGUAGE' , $ _SERVER ) ) { $ httplanguages = $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ; } $ languages = array ( ) ; if ( empty ( $ httplanguages ) ) { return $ languages ; } $ accepted = preg_split ( '/,\s*/' , $ httplanguages ) ; foreach ( $ accepted as $ accept ) { $ match = null ; $ result = preg_match ( '/^([a-z]{1,8}(?:[-_][a-z]{1,8})*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i' , $ accept , $ match ) ; if ( $ result < 1 ) { continue ; } if ( isset ( $ match [ 2 ] ) === true ) { $ quality = ( float ) $ match [ 2 ] ; } else { $ quality = 1.0 ; } $ countrys = explode ( '-' , $ match [ 1 ] ) ; $ region = array_shift ( $ countrys ) ; $ country2 = explode ( '_' , $ region ) ; $ region = array_shift ( $ country2 ) ; foreach ( $ countrys as $ country ) { $ languages [ $ region . '_' . strtoupper ( $ country ) ] = $ quality ; } foreach ( $ country2 as $ country ) { $ languages [ $ region . '_' . strtoupper ( $ country ) ] = $ quality ; } if ( ( isset ( $ languages [ $ region ] ) === false ) || ( $ languages [ $ region ] < $ quality ) ) { $ languages [ $ region ] = $ quality ; } } self :: $ _browser = $ languages ; return $ languages ; } | Return an array of all accepted languages of the client Expects RFC compilant Header !! |
2,330 | public function setLocale ( $ locale = null ) { $ locale = self :: _prepareLocale ( $ locale ) ; if ( isset ( self :: $ _localeData [ ( string ) $ locale ] ) === false ) { $ region = substr ( ( string ) $ locale , 0 , 3 ) ; if ( isset ( $ region [ 2 ] ) === true ) { if ( ( $ region [ 2 ] === '_' ) or ( $ region [ 2 ] === '-' ) ) { $ region = substr ( $ region , 0 , 2 ) ; } } if ( isset ( self :: $ _localeData [ ( string ) $ region ] ) === true ) { $ this -> _locale = $ region ; } else { $ this -> _locale = 'root' ; } } else { $ this -> _locale = $ locale ; } } | Sets a new locale |
2,331 | public function getRegion ( ) { $ locale = explode ( '_' , $ this -> _locale ) ; if ( isset ( $ locale [ 1 ] ) === true ) { return $ locale [ 1 ] ; } return false ; } | Returns the region part of the locale if available |
2,332 | public static function getHttpCharset ( ) { $ httpcharsets = getenv ( 'HTTP_ACCEPT_CHARSET' ) ; $ charsets = array ( ) ; if ( $ httpcharsets === false ) { return $ charsets ; } $ accepted = preg_split ( '/,\s*/' , $ httpcharsets ) ; foreach ( $ accepted as $ accept ) { if ( empty ( $ accept ) === true ) { continue ; } if ( strpos ( $ accept , ';' ) !== false ) { $ quality = ( float ) substr ( $ accept , ( strpos ( $ accept , '=' ) + 1 ) ) ; $ pos = substr ( $ accept , 0 , strpos ( $ accept , ';' ) ) ; $ charsets [ $ pos ] = $ quality ; } else { $ quality = 1.0 ; $ charsets [ $ accept ] = $ quality ; } } return $ charsets ; } | Return the accepted charset of the client |
2,333 | public static function getTranslationList ( $ path = null , $ locale = null , $ value = null ) { $ locale = self :: findLocale ( $ locale ) ; $ result = Zend_Locale_Data :: getList ( $ locale , $ path , $ value ) ; if ( empty ( $ result ) === true ) { return false ; } return $ result ; } | Returns localized informations as array supported are several types of informations . For detailed information about the types look into the documentation |
2,334 | public static function getTranslation ( $ value = null , $ path = null , $ locale = null ) { $ locale = self :: findLocale ( $ locale ) ; $ result = Zend_Locale_Data :: getContent ( $ locale , $ path , $ value ) ; if ( empty ( $ result ) === true && '0' !== $ result ) { return false ; } return $ result ; } | Returns a localized information string supported are several types of informations . For detailed information about the types look into the documentation |
2,335 | public static function getLanguageTranslation ( $ value , $ locale = null ) { trigger_error ( "The method getLanguageTranslation is deprecated. Use getTranslation($value, 'language', $locale) instead" , E_USER_NOTICE ) ; return self :: getTranslation ( $ value , 'language' , $ locale ) ; } | Returns the localized language name |
2,336 | public static function getScriptTranslation ( $ value , $ locale = null ) { trigger_error ( "The method getScriptTranslation is deprecated. Use getTranslation($value, 'script', $locale) instead" , E_USER_NOTICE ) ; return self :: getTranslation ( $ value , 'script' , $ locale ) ; } | Returns the localized script name |
2,337 | public static function getCountryTranslation ( $ value , $ locale = null ) { trigger_error ( "The method getCountryTranslation is deprecated. Use getTranslation($value, 'country', $locale) instead" , E_USER_NOTICE ) ; return self :: getTranslation ( $ value , 'country' , $ locale ) ; } | Returns the localized country name |
2,338 | public static function getTerritoryTranslation ( $ value , $ locale = null ) { trigger_error ( "The method getTerritoryTranslation is deprecated. Use getTranslation($value, 'territory', $locale) instead" , E_USER_NOTICE ) ; return self :: getTranslation ( $ value , 'territory' , $ locale ) ; } | Returns the localized territory name All territories contains other countries . |
2,339 | public static function getQuestion ( $ locale = null ) { $ locale = self :: findLocale ( $ locale ) ; $ quest = Zend_Locale_Data :: getList ( $ locale , 'question' ) ; $ yes = explode ( ':' , $ quest [ 'yes' ] ) ; $ no = explode ( ':' , $ quest [ 'no' ] ) ; $ quest [ 'yes' ] = $ yes [ 0 ] ; $ quest [ 'yesarray' ] = $ yes ; $ quest [ 'no' ] = $ no [ 0 ] ; $ quest [ 'noarray' ] = $ no ; $ quest [ 'yesexpr' ] = self :: _prepareQuestionString ( $ yes ) ; $ quest [ 'noexpr' ] = self :: _prepareQuestionString ( $ no ) ; return $ quest ; } | Returns an array with translated yes strings |
2,340 | private static function _prepareQuestionString ( $ input ) { $ regex = '' ; if ( is_array ( $ input ) === true ) { $ regex = '^' ; $ start = true ; foreach ( $ input as $ row ) { if ( $ start === false ) { $ regex .= '|' ; } $ start = false ; $ regex .= '(' ; $ one = null ; if ( strlen ( $ row ) > 2 ) { $ one = true ; } foreach ( str_split ( $ row , 1 ) as $ char ) { $ regex .= '[' . $ char ; $ regex .= strtoupper ( $ char ) . ']' ; if ( $ one === true ) { $ one = false ; $ regex .= '(' ; } } if ( $ one === false ) { $ regex .= ')' ; } $ regex .= '?)' ; } } return $ regex ; } | Internal function for preparing the returned question regex string |
2,341 | public static function findLocale ( $ locale = null ) { if ( $ locale === null ) { if ( Zend_Registry :: isRegistered ( 'Zend_Locale' ) ) { $ locale = Zend_Registry :: get ( 'Zend_Locale' ) ; } } if ( $ locale === null ) { $ locale = new Zend_Locale ( ) ; } if ( ! Zend_Locale :: isLocale ( $ locale , true , false ) ) { if ( ! Zend_Locale :: isLocale ( $ locale , false , false ) ) { $ locale = Zend_Locale :: getLocaleToTerritory ( $ locale ) ; if ( empty ( $ locale ) ) { throw new Zend_Locale_Exception ( "The locale '$locale' is no known locale" ) ; } } else { $ locale = new Zend_Locale ( $ locale ) ; } } $ locale = self :: _prepareLocale ( $ locale ) ; return $ locale ; } | Finds the proper locale based on the input Checks if it exists degrades it when necessary Detects registry locale and when all fails tries to detect a automatic locale Returns the found locale as string |
2,342 | public static function getLocaleToTerritory ( $ territory ) { $ territory = strtoupper ( $ territory ) ; if ( array_key_exists ( $ territory , self :: $ _territoryData ) ) { return self :: $ _territoryData [ $ territory ] ; } return null ; } | Returns the expected locale for a given territory |
2,343 | private static function _prepareLocale ( $ locale , $ strict = false ) { if ( $ locale instanceof Zend_Locale ) { $ locale = $ locale -> toString ( ) ; } if ( is_array ( $ locale ) ) { return '' ; } if ( empty ( self :: $ _auto ) === true ) { self :: $ _browser = self :: getBrowser ( ) ; self :: $ _environment = self :: getEnvironment ( ) ; self :: $ _breakChain = true ; self :: $ _auto = self :: getBrowser ( ) + self :: getEnvironment ( ) + self :: getDefault ( ) ; } if ( ! $ strict ) { if ( $ locale === 'browser' ) { $ locale = self :: $ _browser ; } if ( $ locale === 'environment' ) { $ locale = self :: $ _environment ; } if ( $ locale === 'default' ) { $ locale = self :: $ _default ; } if ( ( $ locale === 'auto' ) or ( $ locale === null ) ) { $ locale = self :: $ _auto ; } if ( is_array ( $ locale ) === true ) { $ locale = key ( $ locale ) ; } } if ( $ locale === null ) { throw new Zend_Locale_Exception ( 'Autodetection of Locale has been failed!' ) ; } if ( strpos ( $ locale , '-' ) !== false ) { $ locale = strtr ( $ locale , '-' , '_' ) ; } $ parts = explode ( '_' , $ locale ) ; if ( ! isset ( self :: $ _localeData [ $ parts [ 0 ] ] ) ) { if ( ( count ( $ parts ) == 1 ) && array_key_exists ( $ parts [ 0 ] , self :: $ _territoryData ) ) { return self :: $ _territoryData [ $ parts [ 0 ] ] ; } return '' ; } foreach ( $ parts as $ key => $ value ) { if ( ( strlen ( $ value ) < 2 ) || ( strlen ( $ value ) > 3 ) ) { unset ( $ parts [ $ key ] ) ; } } $ locale = implode ( '_' , $ parts ) ; return ( string ) $ locale ; } | Internal function returns a single locale on detection |
2,344 | public static function getOrder ( $ order = null ) { switch ( $ order ) { case self :: ENVIRONMENT : self :: $ _breakChain = true ; $ languages = self :: getEnvironment ( ) + self :: getBrowser ( ) + self :: getDefault ( ) ; break ; case self :: ZFDEFAULT : self :: $ _breakChain = true ; $ languages = self :: getDefault ( ) + self :: getEnvironment ( ) + self :: getBrowser ( ) ; break ; default : self :: $ _breakChain = true ; $ languages = self :: getBrowser ( ) + self :: getEnvironment ( ) + self :: getDefault ( ) ; break ; } return $ languages ; } | Search the locale automatically and return all used locales ordered by quality |
2,345 | protected function takeChildFromDOM ( $ child ) { if ( $ child -> nodeType == XML_TEXT_NODE ) { $ this -> _text = $ child -> nodeValue ; } else { $ extensionElement = new Zend_Gdata_App_Extension_Element ( ) ; $ extensionElement -> transferFromDOM ( $ child ) ; $ this -> _extensionElements [ ] = $ extensionElement ; } } | Given a child DOMNode tries to determine how to map the data into object instance members . If no mapping is defined Extension_Element objects are created and stored in an array . |
2,346 | public function transferFromDOM ( $ node ) { foreach ( $ node -> childNodes as $ child ) { $ this -> takeChildFromDOM ( $ child ) ; } foreach ( $ node -> attributes as $ attribute ) { $ this -> takeAttributeFromDOM ( $ attribute ) ; } } | Transfers each child and attribute into member variables . This is called when XML is received over the wire and the data model needs to be built to represent this XML . |
2,347 | public function registerNamespace ( $ prefix , $ namespaceUri , $ majorVersion = 1 , $ minorVersion = 0 ) { $ this -> _namespaces [ $ prefix ] [ $ majorVersion ] [ $ minorVersion ] = $ namespaceUri ; } | Add a namespace and prefix to the registered list |
2,348 | protected function initComponents ( $ componentNames ) { $ components = array ( ) ; foreach ( $ componentNames as $ name ) { $ className = sprintf ( "EventRegistration\Calculator\%sComponent" , $ name ) ; array_push ( $ components , \ Injector :: inst ( ) -> create ( $ className , $ this -> registration ) ) ; } return $ components ; } | Creates instances of components from component name strings |
2,349 | protected function addBinding ( $ key , $ value , $ override = false ) : void { if ( isset ( $ this -> routeBindings [ $ key ] ) && ! $ override ) { throw new \ InvalidArgumentException ( "You can't override the key: $key" ) ; } if ( $ value instanceof PrimalValued ) { $ value = $ value -> toPrimitive ( ) ; } if ( is_object ( $ value ) || is_array ( $ value ) ) { throw new \ InvalidArgumentException ( "You can't use an object or an array as binding" ) ; } $ this -> routeBindings [ $ key ] = $ value ; } | Set a new binding . |
2,350 | public function getInitialValue ( ) { if ( $ this -> hasDefaultValue ) { return $ this -> defaultValue ; } return $ this -> isNullable ? null : $ this -> dataType -> getInitialValue ( ) ; } | Returns the initial value of the column . |
2,351 | public function getFilterCallback ( ) { if ( $ this -> filterCallback !== null ) { $ callback = $ this -> filterCallback ; } else { $ field = $ this -> field ; $ callback = function ( $ value ) use ( $ field ) { return [ $ field => $ value ] ; } ; } return $ callback ; } | Get callback that takes the value being validated and returns an array of wheres to be used with the mapper . |
2,352 | public final function getFactory ( ) { $ calledClass = get_called_class ( ) ; if ( empty ( self :: $ factories [ $ calledClass ] ) ) { self :: $ factories [ $ calledClass ] = $ this -> getDefaultFactory ( ) ; } return self :: $ factories [ $ calledClass ] ; } | Get the factory that supplies entities to the collection browser . |
2,353 | protected function getViewResponse ( Entity $ entity ) { $ response = $ this -> getHtmlResponse ( ) ; $ response -> setTemplateId ( $ this -> getViewTemplateId ( ) ) ; $ response -> setData ( $ this -> getItemName ( ) , $ entity -> getFieldsData ( ) ) ; $ response -> appendToTitle ( sprintf ( _ ( '%s %s' ) , ucfirst ( $ this -> getItemName ( ) ) , $ entity -> getId ( ) ) ) ; return $ response ; } | Generate a response that displays an entity s data . |
2,354 | public function getSidebarData ( ) { if ( $ this -> _entityName === 'Veonik\Bundle\BlogBundle\Entity\Category' ) { $ join = 'JOIN posts_categories pt ON pt.category_id = t.id ' ; } else { $ join = 'JOIN posts_tags pt ON pt.tag_id = t.id ' ; } $ stmt = $ this -> _em -> getConnection ( ) -> executeQuery ( "SELECT t.id FROM tags t {$join} JOIN posts p ON pt.post_id = p.id WHERE p.active = TRUE AND t.active = TRUE GROUP BY t.id ORDER BY COUNT(p.id) DESC LIMIT 10" ) ; $ results = $ stmt -> fetchAll ( \ PDO :: FETCH_COLUMN ) ; return $ this -> createQueryBuilder ( 't' ) -> join ( 'VeonikBlogBundle:AbstractPost' , 'p' ) -> where ( 't.id IN (:ids)' ) -> setParameter ( 'ids' , $ results ) -> getQuery ( ) -> useResultCache ( true , 3600 , 'sidebar_tags' . $ this -> _entityName ) -> getResult ( ) ; } | Gets sidebar data |
2,355 | public static function inTheInput ( array $ data , MapsProperty $ mapping , string $ key ) : UnmappableInput { return new self ( sprintf ( 'Missing the key `%s` for property `%s` in the input data: %s; ' . 'Mapper: %s' , $ key , $ mapping -> name ( ) , json_encode ( $ data ) , get_class ( $ mapping ) ) ) ; } | Notifies the client code about a missing input key . |
2,356 | public function getOAUTHInstance ( ) { if ( ! is_object ( $ this -> oauth ) ) { $ this -> oauth = new PHPMailerOAuthGoogle ( $ this -> oauthUserEmail , $ this -> oauthClientSecret , $ this -> oauthClientId , $ this -> oauthRefreshToken ) ; } return $ this -> oauth ; } | Get a PHPMailerOAuthGoogle instance to use . |
2,357 | public static function validateData ( $ engine , $ keyword , $ pageUrl , $ pageNumber , $ age , $ entries ) { if ( ! self :: validateEngine ( $ engine ) ) throw new \ Franzip \ SerpPageSerializer \ Exceptions \ InvalidArgumentException ( 'Invalid SerializableSerpPage $engine: please supply a valid non-empty string.' ) ; if ( ! self :: validateKeyword ( $ keyword ) ) throw new \ Franzip \ SerpPageSerializer \ Exceptions \ InvalidArgumentException ( 'Invalid SerializableSerpPage $keyword: please supply a valid non-empty string.' ) ; if ( ! self :: validatePageUrl ( $ pageUrl ) ) throw new \ Franzip \ SerpPageSerializer \ Exceptions \ InvalidArgumentException ( 'Invalid SerializableSerpPage $pageUrl: supplied URL appears to be invalid.' ) ; if ( ! self :: validatePageNumber ( $ pageNumber ) ) throw new \ Franzip \ SerpPageSerializer \ Exceptions \ InvalidArgumentException ( 'Invalid SerializableSerpPage $pageNumber: please supply a positive integer.' ) ; if ( ! self :: validateAge ( $ age ) ) throw new \ Franzip \ SerpPageSerializer \ Exceptions \ InvalidArgumentException ( 'Invalid SerializableSerpPage $age: $age must be a DateTime object.' ) ; if ( ! self :: validateEntries ( $ entries ) ) throw new \ Franzip \ SerpPageSerializer \ Exceptions \ InvalidArgumentException ( 'Invalid SerializableSerpPage $entries: $entries must be an array with the following structure. array(0 => array(\'url\' => \'someurl\', \'snippet\' => \'somesnippet\', \'title\' => \'sometitle\'), 1 => array(\'url\' => \'someurl\', \'snippet\' => \'somesnippet\', \'title\' => \'sometitle\'), ...' ) ; } | Validate SerializableSerpPage constructor data . |
2,358 | public function supportParameter ( $ name ) { if ( in_array ( $ name , QueryModifiers ) ) { throw new \ DomainException ( "parameter $name not allowed" ) ; } $ this -> supportedParameters [ $ name ] = $ name ; asort ( $ this -> supportedParameters ) ; } | Enable support of a query parameter . |
2,359 | public function create ( $ class ) { $ reflectionClass = new ReflectionClass ( $ class ) ; $ reflectionMethod = $ reflectionClass -> getConstructor ( ) ; if ( ! $ reflectionMethod ) { return new $ class ; } $ params = & $ this -> fetchDepsFromSignature ( $ reflectionMethod ) ; return $ reflectionClass -> newInstanceArgs ( $ params ) ; } | Create an object of the given class |
2,360 | public function inject ( $ callable , $ overloadedDeps = array ( ) ) { $ reflection = new ReflectionFunction ( $ callable ) ; $ params = & $ this -> fetchDepsFromSignature ( $ reflection , $ overloadedDeps ) ; return call_user_func_array ( $ callable , $ params ) ; } | Executes the given callable |
2,361 | public function replace ( $ name , $ value ) { if ( ! isset ( $ this -> unresolvedDeps [ $ name ] ) ) { throw new Exception ( "Dependency does not exist: $name!" ) ; } if ( isset ( $ this -> resolvedDeps [ $ name ] ) ) { throw new Exception ( "Could replace resolved Dependency: $name!" ) ; } $ this -> unresolvedDeps [ $ name ] = & $ value ; } | Replace an existing dependency |
2,362 | protected function parseRelationshipParams ( array $ params ) : array { if ( empty ( $ params ) ) { return [ ] ; } $ parsed = [ ] ; foreach ( $ params as $ key => $ value ) { if ( is_int ( $ key ) ) { $ parsed [ $ key ] = '' ; continue ; } if ( $ key !== 'paginate' || ( $ key === 'paginate' && ! Arr :: isAssoc ( $ value ) ) ) { $ key = $ key === 'paginate' ? 'limit' : $ key ; $ parsed [ $ key ] = implode ( '|' , $ value ) ; } else { $ limit = $ this -> findInArray ( $ value , 'limit' , 0 , 10 ) ; $ offset = $ this -> findInArray ( $ value , 'offset' , 1 , 0 ) ; $ parsed [ 'limit' ] = $ limit . '|' . $ offset ; } } return $ parsed ; } | Processes the parameters passed for the relationship . |
2,363 | private function findInArray ( array $ target , string $ key , int $ defaultIndex = 0 , $ defaultValue = null ) { if ( empty ( $ target ) ) { return $ defaultValue ; } if ( ! empty ( $ target [ $ key ] ) ) { return $ target [ $ key ] ; } elseif ( ! empty ( $ target [ $ defaultIndex ] ) ) { return $ target [ $ defaultIndex ] ; } return $ defaultValue ; } | Searches the array for a value based on a key a default index else it returns the default value . |
2,364 | private function _createRoute ( $ controller_name , $ action_name ) { $ route = new Router \ Route ( ) ; $ route -> setControllerName ( $ controller_name ) ; $ route -> setActionName ( $ action_name ) ; return $ route ; } | Private helper function to create a route |
2,365 | private function _getRoute ( $ controller_name , $ action_name ) { $ _route = $ this -> _createRoute ( $ controller_name , $ action_name ) ; foreach ( $ this -> _routes as $ route ) { if ( $ route -> getControllerName ( ) == $ _route -> getControllerName ( ) && $ route -> getActionName ( ) == $ _route -> getActionName ( ) ) { return $ route ; } } } | Private helper function to retrieve a route |
2,366 | public function allow ( $ role , $ controller_name , $ action_name ) { $ route = $ this -> _getRoute ( $ controller_name , $ action_name ) ; $ this -> _allow_list [ $ role ] [ ] = $ route ; } | Attach a route with a role in the allow list |
2,367 | public function deny ( $ role , $ resource , $ action ) { $ route = $ this -> _getRoute ( $ controller_name , $ action_name ) ; $ this -> _deny_list [ $ role ] [ ] = $ route ; } | Attach a route with a role in the deny list |
2,368 | public function isAllowed ( $ role , $ controller_name , $ action_name ) { $ _route = $ this -> _createRoute ( $ controller_name , $ action_name ) ; if ( $ this -> _default_action == "ALLOW" ) { $ list = $ this -> _deny_list ; } else if ( $ this -> _default_action == "DENY" ) { $ list = $ this -> _allow_list ; } foreach ( $ list [ $ role ] as $ route ) { if ( $ route -> getControllerName ( ) == $ _route -> getControllerName ( ) && $ route -> getActionName ( ) == $ _route -> getActionName ( ) ) { return self :: ALLOW ; } } return self :: DENY ; } | Check is role has the route attached |
2,369 | public static function parse ( $ typeName ) { $ normalize = array ( "int" => self :: INTEGER_NAME , "bool" => self :: BOOLEAN_NAME , "double" => self :: FLOAT_NAME , "real" => self :: FLOAT_NAME , "long" => self :: INTEGER_NAME ) ; if ( isset ( $ normalize [ $ typeName ] ) ) $ typeName = $ normalize [ $ typeName ] ; if ( self :: $ cachedTypes === null ) { self :: $ cachedTypes = array ( self :: INTEGER_NAME => new PrimitiveType ( self :: INTEGER_NAME ) , self :: FLOAT_NAME => new PrimitiveType ( self :: FLOAT_NAME ) , self :: STRING_NAME => new PrimitiveType ( self :: STRING_NAME ) , self :: BOOLEAN_NAME => new PrimitiveType ( self :: BOOLEAN_NAME ) , self :: MIXED_NAME => new PrimitiveType ( self :: MIXED_NAME ) , self :: RESOURCE_NAME => new PrimitiveType ( self :: RESOURCE_NAME ) , self :: OBJECT_NAME => new PrimitiveType ( self :: OBJECT_NAME ) , self :: NULL_NAME => new PrimitiveType ( self :: NULL_NAME ) , self :: CALLABLE_NAME => new PrimitiveType ( self :: CALLABLE_NAME ) ) ; } if ( isset ( self :: $ cachedTypes [ $ typeName ] ) ) return self :: $ cachedTypes [ $ typeName ] ; return null ; } | Parses a primitive type name . Returns null if the provided type name is not a name of a primitive type . |
2,370 | public function setComposerManifest ( ComposerManifestParser $ composer ) { $ this -> composer_manifest = $ composer ; $ this -> setDependencies ( $ this -> composer_manifest -> getExtraEntry ( 'assets-presets' ) ) ; return $ this ; } | setters & getters |
2,371 | public function buildQuery ( ) { $ model = $ this -> model ; $ query = $ model :: query ( ) ; if ( is_array ( $ this -> join ) ) { foreach ( $ this -> join as $ condition ) { list ( $ joinModel , $ column , $ foreignKey ) = $ condition ; $ query -> join ( $ joinModel , $ column , $ foreignKey ) ; } } $ filter = $ this -> parseFilterInput ( $ this -> filter ) ; $ query -> where ( $ filter ) ; if ( ! empty ( $ this -> search ) && is_string ( $ this -> search ) && property_exists ( $ model , 'searchableProperties' ) ) { $ w = [ ] ; $ search = addslashes ( $ this -> search ) ; foreach ( $ model :: $ searchableProperties as $ name ) { $ w [ ] = "`$name` LIKE '%$search%'" ; } if ( count ( $ w ) > 0 ) { $ query -> where ( '(' . implode ( ' OR ' , $ w ) . ')' ) ; } } foreach ( $ this -> expand as $ k ) { $ property = $ model :: getProperty ( $ k ) ; if ( $ property && isset ( $ property [ 'relation' ] ) ) { if ( isset ( $ property [ 'id_property' ] ) ) { $ query -> with ( $ property [ 'id_property' ] ) ; } else { $ query -> with ( $ k ) ; } } } if ( isset ( $ this -> sort ) ) { $ query -> sort ( $ this -> sort ) ; } $ start = ( $ this -> page - 1 ) * $ this -> perPage ; $ query -> start ( $ start ) -> limit ( $ this -> perPage ) ; return $ query ; } | Builds the model query . |
2,372 | public function paginate ( $ page , $ perPage , $ total ) { $ this -> response -> setHeader ( 'X-Total-Count' , $ total ) ; $ pageCount = max ( 1 , ceil ( $ total / $ perPage ) ) ; $ base = $ this -> getEndpoint ( ) ; $ requestQuery = $ this -> request -> query ( ) ; if ( isset ( $ requestQuery [ 'per_page' ] ) ) { unset ( $ requestQuery [ 'per_page' ] ) ; } if ( $ perPage != self :: DEFAULT_PER_PAGE ) { $ requestQuery [ 'per_page' ] = $ perPage ; } $ links = [ 'self' => $ this -> link ( $ base , array_replace ( $ requestQuery , [ 'page' => $ page ] ) ) , 'first' => $ this -> link ( $ base , array_replace ( $ requestQuery , [ 'page' => 1 ] ) ) , ] ; if ( $ page > 1 ) { $ links [ 'previous' ] = $ this -> link ( $ base , array_replace ( $ requestQuery , [ 'page' => $ page - 1 ] ) ) ; } if ( $ page < $ pageCount ) { $ links [ 'next' ] = $ this -> link ( $ base , array_replace ( $ requestQuery , [ 'page' => $ page + 1 ] ) ) ; } $ links [ 'last' ] = $ this -> link ( $ base , array_replace ( $ requestQuery , [ 'page' => $ pageCount ] ) ) ; $ linkStr = implode ( ', ' , array_map ( function ( $ link , $ rel ) { return "<$link>; rel=\"$rel\"" ; } , $ links , array_keys ( $ links ) ) ) ; $ this -> response -> setHeader ( 'Link' , $ linkStr ) ; } | Paginates the results from this route . |
2,373 | protected function parseFilterInput ( array $ input ) { if ( count ( $ input ) === 0 ) { return [ ] ; } $ allowed = [ ] ; $ model = $ this -> model ; if ( property_exists ( $ model , 'filterableProperties' ) ) { $ allowed = $ model :: $ filterableProperties ; } $ filter = [ ] ; foreach ( $ input as $ key => $ value ) { if ( is_numeric ( $ key ) || ! preg_match ( '/^[A-Za-z0-9_]*$/' , $ key ) ) { throw new InvalidRequest ( "Invalid filter parameter: $key" ) ; } if ( ! in_array ( $ key , $ allowed ) ) { throw new InvalidRequest ( "Invalid filter parameter: $key" ) ; } $ filter [ $ key ] = $ value ; } return $ filter ; } | Builds the filter from an input array of parameters . |
2,374 | public function fetch ( $ what = null , $ live = false ) { if ( ! in_array ( $ what , [ 'style' , 'script' ] ) ) throw new Exception ( "{$what} not supported" ) ; $ this -> compress = ! Configure :: read ( 'debug' ) || $ live == true ; $ function = '_' . $ what ; echo $ this -> $ function ( ) ; } | Fetch either combined css or js |
2,375 | public function inline ( $ what = null , $ data = null , $ return = false ) { if ( ! in_array ( $ what , [ 'style' , 'script' ] ) ) throw new Exception ( "{$what} not supported" ) ; $ function = '_inline' . ucfirst ( $ what ) ; $ data = $ this -> $ function ( $ data ) ; if ( $ return ) return $ data ; echo $ data ; } | Fetch inline minified css or js |
2,376 | private function path ( $ file , array $ options = [ ] ) { $ base = $ this -> Url -> assetUrl ( $ file , $ options ) ; $ fullpath = preg_replace ( '/^' . preg_quote ( $ this -> request -> getAttribute ( 'webroot' ) , '/' ) . '/' , '' , urldecode ( $ base ) ) ; $ webrootPath = Configure :: read ( 'App.wwwRoot' ) . str_replace ( '/' , DS , $ fullpath ) ; if ( file_exists ( $ webrootPath ) ) return $ webrootPath ; $ pluginFile = $ this -> _getPluginFile ( $ fullpath ) ; if ( $ pluginFile !== null && file_exists ( $ pluginFile ) ) return $ pluginFile ; return false ; } | Get full webroot path for an asset |
2,377 | private function filename ( $ what = null ) { if ( ! $ this -> $ what [ 'intern' ] ) return false ; $ last = 0 ; foreach ( $ this -> $ what [ 'intern' ] as $ res ) if ( file_exists ( $ res ) ) $ last = max ( $ last , filemtime ( $ res ) ) ; return "cache-{$last}-" . md5 ( serialize ( $ this -> $ what [ 'intern' ] ) ) . ".{$what}" ; } | Attempt to create the filename for the selected resources |
2,378 | private function process ( $ what = null ) { $ output = null ; foreach ( $ this -> $ what [ 'intern' ] as $ idx => $ file ) { $ contents = file_get_contents ( $ file ) ; if ( $ what == 'css' ) $ contents = $ this -> dilemma ( $ contents , $ this -> $ what [ 'extern' ] [ $ idx ] ) ; if ( strpos ( $ file , ".min.{$what}" ) === false ) { $ contents = Algorithms :: $ what ( $ contents , $ this -> _config [ 'config' ] [ $ what ] ) ; if ( $ what == 'js' ) $ contents .= ";" ; } $ output .= "\n" . $ contents . "\n" ; } $ output = preg_replace ( '#(\r\n?|\n){2,}#' , "\n" , $ output ) ; return trim ( $ output ) ; } | Take individual files and process them based on an algorithm |
2,379 | private function dilemma ( $ input = null , $ from = false ) { list ( $ plugin , $ from ) = $ this -> _View -> pluginSplit ( $ from , false ) ; $ from = Configure :: read ( 'App.cssBaseUrl' ) . $ from ; if ( isset ( $ plugin ) ) $ from = Inflector :: underscore ( $ plugin ) . '/' . $ from ; $ converter = new Converter ( "/{$from}-fake-file.css" , "{$this->_config['paths']['css']}/cache-fake-file.css" ) ; return $ this -> morph ( $ input , function ( $ url ) use ( $ converter ) { return $ converter -> convert ( $ url ) ; } ) ; } | Dilemma? This function uses morph to fix and convert paths found in css |
2,380 | private function morph ( $ input , callable $ callback , $ ignore = '/^(data:|https?:|\\/)/' ) { $ relativeRegexes = [ '/url\(\s*(?P<quotes>["\'])?(?P<path>.+?)(?(quotes)(?P=quotes))\s*\)/ix' , '/@import\s+(?P<quotes>["\'])(?P<path>.+?)(?P=quotes)/ix' , ] ; $ matches = [ ] ; foreach ( $ relativeRegexes as $ relativeRegex ) if ( preg_match_all ( $ relativeRegex , $ input , $ regexMatches , PREG_SET_ORDER ) ) $ matches = array_merge ( $ matches , $ regexMatches ) ; $ search = [ ] ; $ replace = [ ] ; foreach ( $ matches as $ match ) { $ type = ( strpos ( $ match [ 0 ] , '@import' ) === 0 ? 'import' : 'url' ) ; $ url = $ match [ 'path' ] ; if ( preg_match ( $ ignore , $ url ) === 0 ) { $ params = strrchr ( $ url , '?' ) ; $ url = $ params ? substr ( $ url , 0 , - strlen ( $ params ) ) : $ url ; $ url = $ callback ( $ url ) ; $ url .= $ params ; } $ url = trim ( $ url ) ; if ( preg_match ( '/[\s\)\'"#\x{7f}-\x{9f}]/u' , $ url ) ) $ url = $ match [ 'quotes' ] . $ url . $ match [ 'quotes' ] ; $ search [ ] = $ match [ 0 ] ; if ( $ type === 'url' ) $ replace [ ] = 'url(' . $ url . ')' ; elseif ( $ type === 'import' ) $ replace [ ] = '@import "' . $ url . '"' ; } return str_replace ( $ search , $ replace , $ input ) ; } | Morph The function that detects urls and morphs paths accordingly |
2,381 | private function _inlineStyle ( $ data = null ) { if ( is_null ( $ data ) ) return false ; $ data = $ this -> morph ( $ data , function ( $ url ) { return $ this -> Url -> build ( $ url ) ; } , '/^(data:|https?:)/' ) ; $ data = Algorithms :: css ( $ data , $ this -> _config [ 'config' ] [ 'css' ] ) ; $ hash = md5 ( $ data ) ; if ( in_array ( $ hash , $ this -> inline [ 'css' ] ) ) return false ; else $ this -> inline [ 'css' ] [ ] = $ hash ; return "<style>{$data}</style>" ; } | Return the compressed inline css data |
2,382 | private function _inlineScript ( $ data = null ) { if ( is_null ( $ data ) ) return false ; $ data = Algorithms :: js ( $ data , $ this -> _config [ 'config' ] [ 'js' ] ) ; $ hash = md5 ( $ data ) ; if ( in_array ( $ hash , $ this -> inline [ 'js' ] ) ) return false ; else $ this -> inline [ 'js' ] [ ] = $ hash ; return "<script>{$data}</script>" ; } | Return the compressed inline js data |
2,383 | protected function _createNewContent ( $ options = array ( ) ) { extract ( $ options ) ; $ contentTable = TableRegistry :: get ( 'CmsContent' ) ; $ content = $ contentTable -> newEntity ( ) ; $ content -> parent = isset ( $ parent ) ? intval ( $ parent ) : 0 ; $ content -> name = $ this -> _randomString ( ) ; $ content -> content_title = isset ( $ content_title ) ? h ( $ content_title ) : '' ; $ content -> content_description = isset ( $ content_description ) ? h ( $ content_description ) : '' ; $ content -> content_excerpt = isset ( $ content_excerpt ) ? h ( $ content_excerpt ) : '' ; $ content -> content_status = isset ( $ content_status ) ? trim ( $ content_status ) : 'draft' ; $ content -> content_type = isset ( $ content_type ) ? trim ( $ content_type ) : 'page' ; $ content -> content_path = isset ( $ content_path ) ? trim ( $ content_path ) : '' ; $ content -> menu_order = isset ( $ menu_order ) ? trim ( $ menu_order ) : 0 ; $ content -> publish_start = isset ( $ publish_start ) ? trim ( $ publish_start ) : date ( 'Y-m-d H:i:s' ) ; $ content -> publish_end = isset ( $ publish_end ) ? trim ( $ publish_end ) : '0000-00-00 00:00:00' ; $ content -> author_id = isset ( $ author_id ) ? intval ( $ author_id ) : 1 ; $ content -> created = date ( 'Y-m-d H:i:s' ) ; $ content -> created_user = isset ( $ created_user ) ? intval ( $ created_user ) : 1 ; $ content -> modified = date ( 'Y-m-d H:i:s' ) ; $ content -> modified_user = isset ( $ modified_user ) ? intval ( $ modified_user ) : 1 ; if ( $ contentTable -> save ( $ content ) ) : $ content -> name = ( ! isset ( $ name ) ) ? $ content -> id : $ this -> _permittedContentName ( $ content -> id , $ name ) ; if ( $ contentTable -> save ( $ content ) ) return $ content -> id ; endif ; return FALSE ; } | Create new Content |
2,384 | public function saveMenuOrder ( ) { $ ITER = 1 ; $ contentTable = TableRegistry :: get ( 'CmsContent' ) ; if ( $ this -> request -> is ( 'post' ) ) : $ items = explode ( ',' , $ this -> request -> data [ 'order' ] ) ; foreach ( $ items as $ id ) : $ content = $ contentTable -> get ( $ id ) ; $ content -> menu_order = $ ITER ++ ; $ contentTable -> save ( $ content ) ; endforeach ; endif ; exit ( 'ok' ) ; } | This function is invoked in AJAX to save the ordering of the elements related |
2,385 | public function saveContent ( $ id = null ) { $ id = ( isset ( $ this -> request -> data [ 'id' ] ) ) ? $ this -> request -> data [ 'id' ] : $ id ; $ this -> CmsContent = TableRegistry :: get ( 'CmsContent' ) ; $ cmsContent = $ this -> CmsContent -> get ( $ id ) ; if ( $ this -> request -> is ( [ 'patch' , 'post' , 'put' ] ) ) { $ this -> CmsContent -> patchEntity ( $ cmsContent , $ this -> request -> data ) ; $ CONTENT_PATH = $ this -> _uploadFile ( $ this -> request -> data [ 'content_file' ] ) ; if ( $ CONTENT_PATH ) { $ cmsContent -> content_path = $ CONTENT_PATH ; } else { if ( $ this -> request -> data [ 'content_file_remove_ck' ] == 1 ) { $ this -> _removeFile ( $ cmsContent -> content_path ) ; $ cmsContent -> content_path = '' ; } } if ( $ this -> CmsContent -> save ( $ cmsContent ) ) { $ this -> Flash -> success ( 'The cms content has been saved.' ) ; exit ( 'ok' ) ; } else { $ this -> Flash -> error ( 'The cms content could not be saved. Please, try again.' ) ; exit ( 'ko' ) ; } } } | This function is invoked in AJAX for saving data related to an object |
2,386 | public function saveMeta ( $ id = null ) { $ id = ( isset ( $ this -> request -> data [ 'id' ] ) ) ? $ this -> request -> data [ 'id' ] : $ id ; $ this -> CmsContentMeta = TableRegistry :: get ( 'CmsContentMeta' ) ; $ meta = $ this -> CmsContentMeta -> get ( $ id ) ; if ( $ this -> request -> is ( [ 'patch' , 'post' , 'put' ] ) ) { $ this -> CmsContentMeta -> patchEntity ( $ meta , $ this -> request -> data ) ; if ( $ this -> CmsContentMeta -> save ( $ meta ) ) { $ this -> Flash -> success ( 'The meta has been saved.' ) ; exit ( 'ok' ) ; } else { $ this -> Flash -> error ( 'The meta could not be saved. Please, try again.' ) ; exit ( 'ko' ) ; } } } | This function is invoked in AJAX for saving data related to an meta |
2,387 | public function initRouterDi ( ) { $ config = $ this -> getConfig ( ) ; if ( ! isset ( $ config [ 'router' ] ) ) { throw new Exception \ RuntimeException ( 'Cannot init DI for router. Cannot find router configuration' ) ; } $ config = $ config [ 'router' ] -> toArray ( ) ; $ router = new Router ( $ this -> diFactory ) ; foreach ( $ config as $ name => $ routeInfo ) { $ router -> addRoute ( $ name , $ routeInfo ) ; } $ this -> diFactory -> set ( 'router' , $ router , true ) ; return $ this ; } | Base on router config init Di for router |
2,388 | public function initInvokableServices ( ) { $ config = $ this -> getConfig ( ) ; if ( ! isset ( $ config [ 'service_manager' ] ) ) { return $ this ; } $ smConfig = $ config [ 'service_manager' ] ; if ( ! isset ( $ smConfig [ 'invokables' ] ) ) { return $ this ; } $ invokables = $ smConfig [ 'invokables' ] -> toArray ( ) ; $ shared = isset ( $ smConfig [ 'shared' ] ) ? $ smConfig [ 'shared' ] -> toArray ( ) : [ ] ; foreach ( $ invokables as $ serviceName => $ serviceClassName ) { if ( ! is_string ( $ serviceClassName ) ) { $ msg = sprintf ( 'Config for invokable service "%s" must be string data type' , $ serviceName ) ; throw new Exception \ UnexpectedValueException ( $ msg ) ; } $ isShare = isset ( $ shared [ $ serviceName ] ) ? ( bool ) $ shared [ $ serviceName ] : true ; $ this -> diFactory -> set ( $ serviceName , $ serviceClassName , $ isShare ) ; } return $ this ; } | Base on config service manager invokables create DI service |
2,389 | public function initFactoriedServices ( ) { $ config = $ this -> getConfig ( ) ; if ( ! isset ( $ config [ 'service_manager' ] ) ) { return $ this ; } $ smConfig = $ config [ 'service_manager' ] ; if ( ! isset ( $ smConfig [ 'factories' ] ) ) { return $ this ; } $ factories = $ smConfig [ 'factories' ] -> toArray ( ) ; $ shared = isset ( $ smConfig [ 'shared' ] ) ? $ smConfig [ 'shared' ] -> toArray ( ) : [ ] ; foreach ( $ factories as $ serviceName => $ serviceConfig ) { $ isShare = isset ( $ shared [ $ serviceName ] ) ? ( bool ) $ shared [ $ serviceName ] : true ; $ this -> setServiceFactories ( $ serviceName , $ serviceConfig , $ isShare ) ; } return $ this ; } | Base on config service manager factories create DI services |
2,390 | public function createErrorHandler ( ) { $ config = $ this -> getConfig ( ) ; if ( ! isset ( $ config [ 'error_handler' ] ) ) { throw new Exception \ RuntimeException ( 'Not found error handler config' ) ; } $ errorHandlerConfig = $ config [ 'error_handler' ] -> toArray ( ) ; $ adapter = ! isset ( $ errorHandlerConfig [ 'adapter' ] ) ? HandlerDefault :: class : $ errorHandlerConfig [ 'adapter' ] ; $ this -> setServiceFactories ( 'errorHandler' , $ adapter , false ) ; } | Create DI error handler |
2,391 | public function Base_BeforeCheckComments_Handler ( $ Sender ) { $ ActionMessage = & $ Sender -> EventArguments [ 'ActionMessage' ] ; $ Discussion = $ Sender -> EventArguments [ 'Discussion' ] ; if ( Gdn :: Session ( ) -> CheckPermission ( 'Vanilla.Discussions.Edit' , TRUE , 'Category' , $ Discussion -> PermissionCategoryID ) ) $ ActionMessage .= ' ' . Anchor ( T ( 'Split' ) , 'vanilla/moderation/splitcomments/' . $ Discussion -> DiscussionID . '/' , 'Split Popup' ) ; } | Add split action link . |
2,392 | public function Base_BeforeCheckDiscussions_Handler ( $ Sender ) { $ ActionMessage = & $ Sender -> EventArguments [ 'ActionMessage' ] ; if ( Gdn :: Session ( ) -> CheckPermission ( 'Vanilla.Discussions.Edit' , TRUE , 'Category' , 'any' ) ) $ ActionMessage .= ' ' . Anchor ( T ( 'Merge' ) , 'vanilla/moderation/mergediscussions/' , 'Merge Popup' ) ; } | Add merge action link . |
2,393 | public function updateDatabaseAction ( ) { $ request = $ this -> getRequest ( ) ; if ( ! $ request instanceof ConsoleRequest ) { throw new \ Zend \ Console \ Exception \ RuntimeException ( 'You can only access this function through a console' ) ; } if ( ( bool ) $ request -> getParam ( 'help' , false ) || $ request -> getParam ( 'h' , false ) ) { $ mode = 'help' ; } else { $ mode = $ request -> getParam ( 'clean-install' , false ) ? 'clean-install' : false ; if ( ! $ mode ) { $ mode = $ request -> getParam ( 'update' , false ) ? 'update' : false ; } if ( ! $ mode ) { $ mode = 'help' ; } } $ verbose = ( bool ) $ request -> getParam ( 'verbose' , false ) || $ request -> getParam ( 'v' , false ) ; $ result = '' ; if ( $ verbose ) { print_r ( 'Processing mode: ' ) ; print_r ( $ mode . "\n" ) ; } switch ( $ mode ) { case 'clean-install' : $ email = $ request -> getParam ( 'email' , null ) ; if ( ! $ email ) { throw new \ Zend \ Console \ Exception \ RuntimeException ( 'No e-mail parameter was received.' ) ; } $ result = $ this -> getService ( ) -> installDatabase ( $ email , $ verbose ) ; break ; case 'update' : $ result = $ this -> getService ( ) -> updateDatabase ( $ verbose ) ; break ; case 'help' : $ result = $ this -> getHelpOutput ( ) ; break ; } return $ result ; } | Will check and update the entire database structure . |
2,394 | protected function getHelpOutput ( ) { $ result = "\n" ; $ result .= "Copyright 2014 by Jasper van Herpt <jasper.v.herpt@gmail.com>\n" ; $ result .= "\n" ; $ result .= "Database actions:" ; $ result .= "\n" ; $ result .= "Usage:\t\tacl database [clean-install|update] [--email=] [--help|-h] [--verbose|-v]\n" ; $ result .= "Examples:\tacl database clean-install --email=john.doe@example.com --verbose\n" ; $ result .= "\t\tacl database update --verbose\n" ; $ result .= "\t\tacl database --help\n" ; $ result .= "\n" ; $ result .= "clean-install: Installs the database schema to the configurated database connection\n" ; $ result .= "\t--e-mail\t(required):\tAny e-mail address\n" ; $ result .= "\t--verbose|-v\t(optional):\tOutput progress\n" ; $ result .= "\n" ; $ result .= "update: Update the class data to the existing database schema.\n" ; $ result .= "\t--verbose|-v\t(optional):\tOutput progress\n" ; $ result .= "\n" ; $ result .= "\n" ; $ result .= "Creating a new user" ; $ result .= "\n" ; $ result .= "Usage:\t\tacl new-user --username=|-u --email=|-e --password=|-p [--help|-h] [--verbose|-v]\n" ; $ result .= "Example:\tacl new-user --email=john.doe@example.com --password=something --verbose\n" ; $ result .= "This action will create a new admin user" ; $ result .= "\t--e-mail\t(required):\tAny e-mail address\n" ; $ result .= "\t--password\t(required):\tA valid password, minimum 8 characters\n" ; return $ result ; } | Get the help output for console usage of the JaztecAcl acl database console command . |
2,395 | public function add ( $ alert , $ class = 'danger' , $ dismissible = true ) { $ alertDefault = array ( 'alert' => '' , 'class' => $ class , 'dismissible' => $ dismissible , ) ; if ( ! \ is_array ( $ alert ) ) { $ alert = array ( 'alert' => $ alert , ) ; } else { foreach ( array ( 'alert' , 'class' , 'dismissible' ) as $ i => $ key ) { if ( isset ( $ alert [ $ i ] ) ) { $ alert [ $ key ] = $ alert [ $ i ] ; unset ( $ alert [ $ i ] ) ; } } } $ alert = \ array_merge ( $ alertDefault , $ alert ) ; if ( \ strlen ( $ alert [ 'alert' ] ) ) { $ this -> alerts [ ] = $ alert ; } } | Add an alert |
2,396 | public function buildAlerts ( ) { $ str = '' ; foreach ( $ this -> alerts as $ alert ) { $ str = $ this -> build ( $ alert ) ; } return $ str ; } | Default Alert Builder |
2,397 | private function build ( $ alert = array ( ) ) { $ str = '' ; $ alert = \ array_merge ( array ( 'alert' => '' , 'dismissible' => true , 'class' => 'danger' , 'framework' => 'bootstrap' , ) , $ alert ) ; $ alert [ 'class' ] = 'alert-' . $ alert [ 'class' ] ; if ( $ alert [ 'framework' ] == 'bootstrap' ) { if ( $ alert [ 'dismissible' ] ) { $ str .= '<div class="alert alert-dismissible ' . $ alert [ 'class' ] . '" role="alert">' . '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' . $ alert [ 'alert' ] . '</div>' ; } else { $ str .= '<div class="alert ' . $ alert [ 'class' ] . '" role="alert">' . $ alert [ 'alert' ] . '</div>' ; } } else { $ str .= '<div class="alert ' . $ alert [ 'class' ] . '">' . $ alert [ 'alert' ] . '</div>' ; } return $ str ; } | Build an alert |
2,398 | public function log ( ) { $ this -> empty = true ; $ log = array ( ) ; $ pattern = "/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\].*/" ; $ log_levels = $ this -> getLevels ( ) ; $ log_file = $ this -> path . '/' . $ this -> fileName ; if ( ! empty ( $ log_file ) && File :: exists ( $ log_file ) ) { $ this -> empty = false ; $ file = File :: get ( $ log_file ) ; preg_match_all ( $ pattern , $ file , $ headings ) ; $ log_data = preg_split ( $ pattern , $ file ) ; if ( $ log_data [ 0 ] < 1 ) { $ trash = array_shift ( $ log_data ) ; unset ( $ trash ) ; } foreach ( $ headings as $ h ) { for ( $ i = 0 , $ j = count ( $ h ) ; $ i < $ j ; $ i ++ ) { foreach ( $ log_levels as $ ll ) { if ( $ this -> level == $ ll or $ this -> level == 'all' ) { if ( strpos ( strtolower ( $ h [ $ i ] ) , strtolower ( 'production.' . $ ll ) ) ) { $ log [ ] = array ( 'level' => $ ll , 'header' => $ h [ $ i ] , 'stack' => $ log_data [ $ i ] ) ; } } } } } } unset ( $ headings ) ; unset ( $ log_data ) ; if ( strtolower ( Config :: get ( 'logviewer::log_order' ) ) == "desc" ) { $ log = array_reverse ( $ log ) ; } return $ log ; } | Open and parse the log . |
2,399 | public function getImageInfo ( array $ liprop = null , $ lilimit = null , $ listart = null , $ liend = null , $ liurlwidth = null , $ liurlheight = null , $ limetadataversion = null , $ liurlparam = null , $ licontinue = null ) { $ path = '?action=query&prop=imageinfo' ; if ( isset ( $ liprop ) ) { $ path .= '&liprop=' . $ this -> buildParameter ( $ liprop ) ; } if ( isset ( $ lilimit ) ) { $ path .= '&lilimit=' . $ lilimit ; } if ( isset ( $ listart ) ) { $ path .= '&listart=' . $ listart ; } if ( isset ( $ liend ) ) { $ path .= '&liend=' . $ liend ; } if ( isset ( $ liurlwidth ) ) { $ path .= '&liurlwidth=' . $ liurlwidth ; } if ( isset ( $ liurlheight ) ) { $ path .= '&liurlheight=' . $ liurlheight ; } if ( isset ( $ limetadataversion ) ) { $ path .= '&limetadataversion=' . $ limetadataversion ; } if ( isset ( $ liurlparam ) ) { $ path .= '&liurlparam=' . $ liurlparam ; } if ( $ licontinue ) { $ path .= '&alcontinue=' ; } $ response = $ this -> client -> get ( $ this -> fetchUrl ( $ path ) ) ; return $ this -> validateResponse ( $ response ) ; } | Method to get all image information and upload history . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.