idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
35,200
public function setOutputMode ( $ outputMode ) { $ this -> outputMode = ( $ outputMode === self :: OUTPUT_MULTI_LINE ) ? self :: OUTPUT_MULTI_LINE : self :: OUTPUT_SINGLE_LINE ; return $ this ; }
Set the output mode .
35,201
public function isValidConstantType ( ) { if ( $ this -> type === self :: TYPE_AUTO ) { $ type = $ this -> determineType ( $ this -> value ) ; } else { $ type = $ this -> type ; } $ scalarTypes = [ self :: TYPE_BOOLEAN , self :: TYPE_NUMBER , self :: TYPE_INTEGER , self :: TYPE_FLOAT , self :: TYPE_DOUBLE , self :: TYPE_STRING , self :: TYPE_CONSTANT , self :: TYPE_NULL , self :: TYPE_EXPRESSION ] ; return in_array ( $ type , $ scalarTypes ) ; }
Check if the value type is valid for a constant .
35,202
protected function determineType ( $ value ) { if ( $ value instanceof Expression || $ value instanceof ValueGenerator ) { return self :: TYPE_EXPRESSION ; } switch ( gettype ( $ value ) ) { case 'boolean' : return self :: TYPE_BOOLEAN ; case 'integer' : return self :: TYPE_INTEGER ; case 'string' : return self :: TYPE_STRING ; case 'double' : case 'float' : return self :: TYPE_NUMBER ; case 'array' : return self :: TYPE_ARRAY ; case 'NULL' : return self :: TYPE_NULL ; case 'object' : return self :: TYPE_OBJECT ; default : return self :: TYPE_OTHER ; } }
Determine the value type .
35,203
public function escapeStringValue ( $ value , $ quote = true ) { $ output = addcslashes ( ( string ) $ value , "'" ) ; if ( $ quote === true ) { $ output = "'" . $ output . "'" ; } return $ output ; }
Escape string values .
35,204
protected function prepareArrayValue ( array $ value ) { $ rii = new \ RecursiveIteratorIterator ( new \ RecursiveArrayIterator ( $ value ) , \ RecursiveIteratorIterator :: SELF_FIRST ) ; foreach ( $ rii as $ key => $ value ) { if ( ( $ value instanceof ValueGenerator ) === false ) { $ value = new self ( $ value ) ; $ rii -> getSubIterator ( ) -> offsetSet ( $ key , $ value ) ; } $ value -> setIndentationLevel ( $ value -> getIndentationLevel ( ) + $ rii -> getDepth ( ) ) ; } return $ rii -> getSubIterator ( ) -> getArrayCopy ( ) ; }
Prepare the array value .
35,205
protected function generateArrayValue ( array $ value ) { $ value = $ this -> prepareArrayValue ( $ value ) ; $ outputMode = count ( $ value ) > 1 ? $ this -> outputMode : self :: OUTPUT_SINGLE_LINE ; $ code = 'array(' ; if ( $ outputMode === self :: OUTPUT_MULTI_LINE ) { $ code .= $ this -> getLineFeed ( ) . $ this -> getIndentation ( ) . $ this -> getIndentationString ( ) . $ this -> getIndentationString ( ) ; } $ outputParts = array ( ) ; $ noKeyIndex = 0 ; foreach ( $ value as $ n => $ v ) { $ v -> setIndentationLevel ( $ this -> getIndentationLevel ( ) + 1 ) ; $ v -> setOutputMode ( $ this -> outputMode ) ; $ partV = $ v -> generate ( ) ; if ( $ n === $ noKeyIndex ) { $ outputParts [ ] = $ partV ; $ noKeyIndex ++ ; } else { $ outputParts [ ] = ( is_int ( $ n ) === true ? $ n : $ this -> escapeStringValue ( $ n ) ) . ' => ' . $ partV ; } } if ( $ outputMode === self :: OUTPUT_MULTI_LINE ) { $ padding = $ this -> getLineFeed ( ) . $ this -> getIndentation ( ) . $ this -> getIndentationString ( ) . $ this -> getIndentationString ( ) ; } else { $ padding = ' ' ; } $ code .= implode ( ',' . $ padding , $ outputParts ) ; if ( $ outputMode === self :: OUTPUT_MULTI_LINE ) { $ code .= $ this -> getLineFeed ( ) . $ this -> getIndentation ( ) . $ this -> getIndentationString ( ) ; } $ code .= ')' ; return $ code ; }
Generate the code of an array .
35,206
public function isAdminArea ( ) { if ( $ this -> isGeneratedCollection ( ) ) { $ pos = strpos ( $ this -> getCollectionFilename ( ) , '/' . DIRNAME_DASHBOARD ) ; return ( $ pos > - 1 ) ; } return false ; }
Checks if the page is a dashboard page returns true if it is .
35,207
public static function getFromRequest ( Request $ request ) { $ c = $ request -> getCurrentPage ( ) ; if ( is_object ( $ c ) ) { return $ c ; } if ( $ request -> getPath ( ) != '' ) { $ path = $ request -> getPath ( ) ; $ db = Database :: connection ( ) ; $ cID = false ; $ ppIsCanonical = false ; while ( ( ! $ cID ) && $ path ) { $ row = $ db -> fetchAssoc ( 'select cID, ppIsCanonical from PagePaths where cPath = ?' , array ( $ path ) ) ; if ( ! empty ( $ row ) ) { $ cID = $ row [ 'cID' ] ; if ( $ cID ) { $ cPath = $ path ; $ ppIsCanonical = ( bool ) $ row [ 'ppIsCanonical' ] ; break ; } } $ path = substr ( $ path , 0 , strrpos ( $ path , '/' ) ) ; } if ( $ cID && $ cPath ) { $ c = static :: getByID ( $ cID , 'ACTIVE' ) ; $ c -> cPathFetchIsCanonical = $ ppIsCanonical ; } else { $ c = new Page ( ) ; $ c -> loadError ( COLLECTION_NOT_FOUND ) ; } return $ c ; } else { $ cID = $ request -> query -> get ( 'cID' ) ; if ( ! $ cID ) { $ cID = $ request -> request -> get ( 'cID' ) ; } $ cID = Core :: make ( 'helper/security' ) -> sanitizeInt ( $ cID ) ; if ( ! $ cID ) { $ cID = 1 ; } $ c = static :: getByID ( $ cID , 'ACTIVE' ) ; $ c -> cPathFetchIsCanonical = true ; } return $ c ; }
Uses a Request object to determine which page to load . queries by path and then by cID .
35,208
public function addCollectionAlias ( $ c ) { $ db = Database :: connection ( ) ; $ cParentID = $ c -> getCollectionID ( ) ; $ u = new User ( ) ; $ uID = $ u -> getUserID ( ) ; $ handle = $ this -> getCollectionHandle ( ) ; $ cDisplayOrder = $ c -> getNextSubPageDisplayOrder ( ) ; $ _cParentID = $ c -> getCollectionID ( ) ; $ q = 'select PagePaths.cPath from PagePaths where cID = ?' ; $ v = array ( $ _cParentID ) ; if ( $ _cParentID > 1 ) { $ q .= ' and ppIsCanonical = ?' ; $ v [ ] = 1 ; } $ cPath = $ db -> fetchColumn ( $ q , $ v ) ; $ data = array ( 'handle' => $ this -> getCollectionHandle ( ) , 'name' => $ this -> getCollectionName ( ) , ) ; $ cobj = parent :: addCollection ( $ data ) ; $ newCID = $ cobj -> getCollectionID ( ) ; $ v = array ( $ newCID , $ cParentID , $ uID , $ this -> getCollectionID ( ) , $ cDisplayOrder ) ; $ q = "insert into Pages (cID, cParentID, uID, cPointerID, cDisplayOrder) values (?, ?, ?, ?, ?)" ; $ r = $ db -> prepare ( $ q ) ; $ r -> execute ( $ v ) ; PageStatistics :: incrementParents ( $ newCID ) ; $ q2 = 'insert into PagePaths (cID, cPath, ppIsCanonical, ppGeneratedFromURLSlugs) values (?, ?, ?, ?)' ; $ v2 = array ( $ newCID , $ cPath . '/' . $ handle , 1 , 1 ) ; $ db -> executeQuery ( $ q2 , $ v2 ) ; return $ newCID ; }
Make an alias to a page .
35,209
public function updateCollectionAliasExternal ( $ cName , $ cLink , $ newWindow = 0 ) { if ( $ this -> cPointerExternalLink != '' ) { $ db = Database :: connection ( ) ; $ this -> markModified ( ) ; if ( $ newWindow ) { $ newWindow = 1 ; } else { $ newWindow = 0 ; } $ db -> executeQuery ( 'update CollectionVersions set cvName = ? where cID = ?' , array ( $ cName , $ this -> cID ) ) ; $ db -> executeQuery ( 'update Pages set cPointerExternalLink = ?, cPointerExternalLinkNewWindow = ? where cID = ?' , array ( $ cLink , $ newWindow , $ this -> cID ) ) ; } }
Update the name link and to open in a new window for an external link .
35,210
public function addCollectionAliasExternal ( $ cName , $ cLink , $ newWindow = 0 ) { $ db = Database :: connection ( ) ; $ dt = Core :: make ( 'helper/text' ) ; $ ds = Core :: make ( 'helper/security' ) ; $ u = new User ( ) ; $ cParentID = $ this -> getCollectionID ( ) ; $ uID = $ u -> getUserID ( ) ; $ handle = $ this -> getCollectionHandle ( ) ; $ cLink = $ ds -> sanitizeURL ( $ cLink ) ; $ handle = $ dt -> urlify ( $ cLink ) ; $ data = array ( 'handle' => $ handle , 'name' => $ cName , ) ; $ cobj = parent :: addCollection ( $ data ) ; $ newCID = $ cobj -> getCollectionID ( ) ; if ( $ newWindow ) { $ newWindow = 1 ; } else { $ newWindow = 0 ; } $ cInheritPermissionsFromCID = $ this -> getPermissionsCollectionID ( ) ; $ cInheritPermissionsFrom = 'PARENT' ; $ v = array ( $ newCID , $ cParentID , $ uID , $ cInheritPermissionsFrom , $ cInheritPermissionsFromCID , $ cLink , $ newWindow ) ; $ q = 'insert into Pages (cID, cParentID, uID, cInheritPermissionsFrom, cInheritPermissionsFromCID, cPointerExternalLink, cPointerExternalLinkNewWindow) values (?, ?, ?, ?, ?, ?, ?)' ; $ r = $ db -> prepare ( $ q ) ; $ r -> execute ( $ v ) ; PageStatistics :: incrementParents ( $ newCID ) ; static :: getByID ( $ newCID ) -> movePageDisplayOrderToBottom ( ) ; return $ newCID ; }
Add a new external link .
35,211
public function addAdditionalPagePath ( $ cPath , $ commit = true ) { $ db = Database :: connection ( ) ; $ em = $ db -> getEntityManager ( ) ; $ path = new \ Concrete \ Core \ Page \ PagePath ( ) ; $ path -> setPagePath ( '/' . trim ( $ cPath , '/' ) ) ; $ path -> setPageObject ( $ this ) ; $ em -> persist ( $ path ) ; if ( $ commit ) { $ em -> flush ( ) ; } return $ path ; }
Adds a non - canonical page path to the current page .
35,212
public function setCanonicalPagePath ( $ cPath , $ isAutoGenerated = false ) { $ em = Database :: connection ( ) -> getEntityManager ( ) ; $ path = $ this -> getCollectionPathObject ( ) ; if ( is_object ( $ path ) ) { $ path -> setPagePath ( $ cPath ) ; } else { $ path = new \ Concrete \ Core \ Page \ PagePath ( ) ; $ path -> setPagePath ( $ cPath ) ; $ path -> setPageObject ( $ this ) ; } $ path -> setPagePathIsAutoGenerated ( $ isAutoGenerated ) ; $ path -> setPagePathIsCanonical ( true ) ; $ em -> persist ( $ path ) ; $ em -> flush ( ) ; }
Sets the canonical page path for a page .
35,213
public static function getCollectionPathFromID ( $ cID ) { $ db = Database :: connection ( ) ; $ path = $ db -> fetchColumn ( 'select cPath from PagePaths inner join CollectionVersions on (PagePaths.cID = CollectionVersions.cID and CollectionVersions.cvIsApproved = 1) where PagePaths.cID = ? order by PagePaths.ppIsCanonical desc' , array ( $ cID ) ) ; return $ path ; }
Returns the path for a page from its cID .
35,214
public function getCollectionThemeID ( ) { if ( $ this -> vObj -> pThemeID < 1 && $ this -> cID != HOME_CID ) { $ c = static :: getByID ( HOME_CID ) ; return $ c -> getCollectionThemeID ( ) ; } else { return $ this -> vObj -> pThemeID ; } }
Returns theme id for the collection .
35,215
public function getCollectionThemeObject ( ) { if ( ! isset ( $ this -> themeObject ) ) { if ( $ this -> vObj -> pThemeID < 1 ) { $ this -> themeObject = PageTheme :: getSiteTheme ( ) ; } else { $ this -> themeObject = PageTheme :: getByID ( $ this -> vObj -> pThemeID ) ; } } if ( ! $ this -> themeObject ) { $ this -> themeObject = PageTheme :: getSiteTheme ( ) ; } return $ this -> themeObject ; }
Returns Collection s theme object .
35,216
public function getCollectionParentIDs ( ) { $ cIDs = array ( $ this -> cParentID ) ; $ db = Database :: connection ( ) ; $ aliasedParents = $ db -> fetchAll ( 'SELECT cParentID FROM Pages WHERE cPointerID = ?' , array ( $ this -> cID ) ) ; foreach ( $ aliasedParents as $ aliasedParent ) { $ cIDs [ ] = $ aliasedParent [ 'cParentID' ] ; } return $ cIDs ; }
Returns an array of this cParentID and aliased parentIDs .
35,217
public function setPermissionsInheritanceToTemplate ( ) { $ db = Database :: connection ( ) ; if ( $ this -> cID ) { $ db -> executeQuery ( 'update Pages set cOverrideTemplatePermissions = 0 where cID = ?' , array ( $ this -> cID ) ) ; } }
Set the permissions of sub - collections added beneath this permissions to inherit from the template .
35,218
public function setPermissionsInheritanceToOverride ( ) { $ db = Database :: connection ( ) ; if ( $ this -> cID ) { $ db -> executeQuery ( 'update Pages set cOverrideTemplatePermissions = 1 where cID = ?' , array ( $ this -> cID ) ) ; } }
Set the permissions of sub - collections added beneath this permissions to inherit from the parent .
35,219
public function getFirstChild ( $ sortColumn = 'cDisplayOrder asc' , $ excludeSystemPages = false ) { if ( $ excludeSystemPages ) { $ systemPages = ' and cIsSystemPage = 0' ; } else { $ systemPages = '' ; } $ db = Database :: connection ( ) ; $ cID = $ db -> fetchColumn ( 'select Pages.cID from Pages inner join CollectionVersions on Pages.cID = CollectionVersions.cID where cvIsApproved = 1 and cParentID = ? ' . $ systemPages . " order by {$sortColumn}" , array ( $ this -> cID ) ) ; if ( $ cID > 1 ) { return static :: getByID ( $ cID , 'ACTIVE' ) ; } return false ; }
Returns the first child of the current page or null if there is no child .
35,220
protected function computeCanonicalPagePath ( ) { $ parent = static :: getByID ( $ this -> cParentID ) ; $ parentPath = $ parent -> getCollectionPathObject ( ) ; $ path = '' ; if ( $ parentPath instanceof PagePath ) { $ path = $ parentPath -> getPagePath ( ) ; } $ path .= '/' ; $ cID = ( $ this -> getCollectionPointerOriginalID ( ) > 0 ) ? $ this -> getCollectionPointerOriginalID ( ) : $ this -> cID ; $ path .= $ this -> getCollectionHandle ( ) ? $ this -> getCollectionHandle ( ) : $ cID ; $ event = new PagePathEvent ( $ this ) ; $ event -> setPagePath ( $ path ) ; $ event = Events :: dispatch ( 'on_compute_canonical_page_path' , $ event ) ; return $ event -> getPagePath ( ) ; }
For the curret page return the text that will be used for that pages canonical path . This happens before any uniqueness checks get run .
35,221
public static function addHomePage ( ) { $ db = Database :: connection ( ) ; $ cParentID = 0 ; $ handle = HOME_HANDLE ; $ uID = HOME_UID ; $ data = array ( 'name' => HOME_NAME , 'handle' => $ handle , 'uID' => $ uID , 'cID' => HOME_CID , ) ; $ cobj = parent :: createCollection ( $ data ) ; $ cID = $ cobj -> getCollectionID ( ) ; $ v = array ( $ cID , $ cParentID , $ uID , 'OVERRIDE' , 1 , 1 , 0 ) ; $ q = 'insert into Pages (cID, cParentID, uID, cInheritPermissionsFrom, cOverrideTemplatePermissions, cInheritPermissionsFromCID, cDisplayOrder) values (?, ?, ?, ?, ?, ?, ?)' ; $ r = $ db -> prepare ( $ q ) ; $ r -> execute ( $ v ) ; $ pc = static :: getByID ( $ cID , 'RECENT' ) ; return $ pc ; }
Adds the home page to the system . Typically used only by the installation program .
35,222
public function getTotalPageViews ( $ date = null ) { $ db = Database :: connection ( ) ; if ( $ date != null ) { return $ db -> fetchColumn ( 'select count(pstID) from PageStatistics where date = ? AND cID = ?' , array ( $ date , $ this -> getCollectionID ( ) ) ) ; } else { return $ db -> fetchColumn ( 'select count(pstID) from PageStatistics where cID = ?' , array ( $ this -> getCollectionID ( ) ) ) ; } }
Returns the total number of page views for a specific page .
35,223
public function getPageStatistics ( $ limit = 20 ) { $ db = Database :: connection ( ) ; $ limitString = '' ; if ( $ limit != false ) { $ limitString = 'limit ' . $ limit ; } if ( is_object ( $ this ) && $ this instanceof Page ) { return $ db -> fetchAll ( "SELECT * FROM PageStatistics WHERE cID = ? ORDER BY timestamp desc {$limitString}" , array ( $ this -> getCollectionID ( ) ) ) ; } else { return $ db -> fetchAll ( "SELECT * FROM PageStatistics ORDER BY timestamp desc {$limitString}" ) ; } }
Gets a pages statistics .
35,224
public static function encodeFromFile ( $ file , array $ parameters = array ( ) ) { $ json = new JSON ( ) ; $ encoder = function ( $ file ) use ( $ parameters , $ json ) { extract ( $ parameters ) ; include $ file ; return $ json ; } ; return json_encode ( $ encoder -> __invoke ( $ file ) ) ; }
Encode JSON from view file
35,225
public function peek ( ) : string { if ( $ this -> atEnd ( ) ) { return self :: END ; } return $ this -> input [ $ this -> index ] ; }
Returns the next character without removing it from the input .
35,226
public function take ( ) : string { if ( $ this -> atEnd ( ) ) { $ this -> lastTaken = self :: END ; return self :: END ; } $ char = $ this -> input [ $ this -> index ] ; $ this -> index += 1 ; $ this -> lastTaken = $ char ; return $ char ; }
Returns the next character and removes it from the input .
35,227
public function expect ( string $ char ) : void { $ this -> latestExpectations = [ $ char ] ; $ taken = $ this -> take ( ) ; if ( $ taken !== $ char ) { $ this -> lastTaken = null ; throw new UnexpectedChar ( $ this , [ $ char ] ) ; } }
Removes the next character from the input . Fails if it s not the expected one .
35,228
public function takeAllAlphaNumUntil ( string $ ends ) : string { $ ends = self :: split ( $ ends ) ; $ ends [ ] = "alphanumeric" ; $ taken = "" ; while ( ctype_alnum ( $ this -> peek ( ) ) ) { $ char = $ this -> take ( ) ; $ taken .= $ char ; } $ this -> latestExpectations = $ ends ; if ( ! in_array ( $ this -> peek ( ) , $ ends ) ) { throw new UnexpectedChar ( $ this , $ ends ) ; } return $ taken ; }
Removes all alphanumeric characters from the input until one of the end characters is encountered . Returns the removed alphanumeric string .
35,229
public function takeAllUntil ( string $ ends ) : string { $ ends = self :: split ( $ ends ) ; $ ends [ ] = self :: END ; $ taken = "" ; while ( ! in_array ( $ this -> peek ( ) , $ ends ) ) { $ char = $ this -> take ( ) ; $ taken .= $ char ; } return $ taken ; }
Removes all characters from the input until one of the end characters is encountered . Returns the read removed .
35,230
private static function split ( string $ string ) : array { $ chars = [ ] ; for ( $ i = 0 ; $ i < strlen ( $ string ) ; $ i ++ ) { $ chars [ ] = $ string [ $ i ] ; } return $ chars ; }
Splits the string into array of characters . Type - sane version of str_split for PHPStan .
35,231
public function process ( Basket $ basket ) { $ meta = $ this -> meta ( $ basket ) ; $ products = $ this -> products ( $ basket ) ; return new Order ( $ meta , $ products ) ; }
Process a Basket into ... ?
35,232
public function meta ( Basket $ basket ) { $ meta = [ ] ; foreach ( $ this -> metadata as $ item ) { $ meta [ $ item -> name ( ) ] = $ item -> generate ( $ basket ) ; } return $ meta ; }
Process the Meta Data
35,233
public function products ( Basket $ basket ) { $ products = [ ] ; foreach ( $ basket -> products ( ) as $ product ) { $ products [ ] = [ 'sku' => $ product -> sku , 'name' => $ product -> name , 'price' => $ product -> price , 'rate' => $ product -> rate , 'quantity' => $ product -> quantity , 'freebie' => $ product -> freebie , 'taxable' => $ product -> taxable , 'delivery' => $ product -> delivery , 'coupons' => $ product -> coupons , 'tags' => $ product -> tags , 'discount' => $ product -> discount , 'attributes' => $ product -> attributes , 'category' => $ product -> category , 'total_value' => $ this -> reconciler -> value ( $ product ) , 'total_discount' => $ this -> reconciler -> discount ( $ product ) , 'total_delivery' => $ this -> reconciler -> delivery ( $ product ) , 'total_tax' => $ this -> reconciler -> tax ( $ product ) , 'subtotal' => $ this -> reconciler -> subtotal ( $ product ) , 'total' => $ this -> reconciler -> total ( $ product ) ] ; } return $ products ; }
Process the Products
35,234
private function addTransformer ( KeyTransformerInterface $ keyTransformer ) { $ finds = array_filter ( $ this -> transformers , function ( $ transformer ) use ( $ keyTransformer ) { return ( \ get_class ( $ transformer ) === \ get_class ( $ keyTransformer ) ) ; } ) ; if ( \ count ( $ finds ) < 1 ) { $ this -> transformers [ ] = $ keyTransformer ; } }
Add a key transformer .
35,235
static public function addAppHelpers ( array $ helpers ) { self :: $ appQueue = array_merge ( self :: $ appQueue , array_map ( function ( $ c ) { return $ c . 'Helper' ; } , $ helpers ) ) ; }
For application helpers . Class names passed will be appended with Helper . This should only be called by Rails .
35,236
static public function load ( ) { if ( ! self :: $ helpersLoaded ) { if ( ( $ router = Rails :: application ( ) -> dispatcher ( ) -> router ( ) ) && ( $ route = $ router -> route ( ) ) ) { $ controllerHelper = Rails :: services ( ) -> get ( 'inflector' ) -> camelize ( $ route -> controller ( ) ) . 'Helper' ; array_unshift ( self :: $ appQueue , $ controllerHelper ) ; } $ appHelper = 'ApplicationHelper' ; array_unshift ( self :: $ appQueue , $ appHelper ) ; foreach ( array_unique ( self :: $ appQueue ) as $ name ) { self :: loadHelper ( $ name ) ; } foreach ( array_unique ( self :: $ queue ) as $ name ) { self :: loadHelper ( $ name , true ) ; } self :: $ helpers [ self :: BASE_HELPER_NAME ] = new Helper \ Base ( ) ; self :: $ helpersLoaded = true ; } }
Actually include the helpers files .
35,237
protected function getPanelGroup ( ) : ? ContentModel { $ group = ContentModel :: findOneBy ( [ 'tl_content.ptable=?' , 'tl_content.pid=?' , '(tl_content.type = ? OR tl_content.type = ?)' , 'tl_content.sorting < ?' , ] , [ $ this -> get ( 'ptable' ) , $ this -> get ( 'pid' ) , 'bs_panel_group_start' , 'bs_panel_group_end' , $ this -> get ( 'sorting' ) , ] , [ 'order' => 'tl_content.sorting DESC' , ] ) ; if ( $ group && $ group -> type === 'bs_panel_group_start' ) { return $ group ; } return null ; }
Get the panel group starting element .
35,238
private function _getDomainObjectsFromFile ( $ file ) { $ result = array ( ) ; if ( fnmatch ( "*.php" , $ file ) ) { foreach ( $ this -> _getClassFiles ( $ file ) as $ namespace => $ classes ) { foreach ( $ classes as $ class ) { $ fullClass = empty ( $ namespace ) ? "\\$class" : "\\$namespace\\$class" ; $ reflection = new \ ReflectionClass ( $ fullClass ) ; if ( is_a ( $ fullClass , "\Pheasant\DomainObject" , true ) && $ reflection -> isInstantiable ( ) ) { $ result [ ] = $ fullClass ; } } } } return $ result ; }
Finds classes that extend \ Pheasant \ DomainObject
35,239
private function _getClassFiles ( $ file ) { $ classes = array ( ) ; $ namespace = 0 ; $ tokens = token_get_all ( file_get_contents ( $ file ) ) ; $ count = count ( $ tokens ) ; $ dlm = false ; for ( $ i = 2 ; $ i < $ count ; $ i ++ ) { if ( ( isset ( $ tokens [ $ i - 2 ] [ 1 ] ) && ( $ tokens [ $ i - 2 ] [ 1 ] == "phpnamespace" || $ tokens [ $ i - 2 ] [ 1 ] == "namespace" ) ) || ( $ dlm && $ tokens [ $ i - 1 ] [ 0 ] == T_NS_SEPARATOR && $ tokens [ $ i ] [ 0 ] == T_STRING ) ) { if ( ! $ dlm ) $ namespace = 0 ; if ( isset ( $ tokens [ $ i ] [ 1 ] ) ) { $ namespace = $ namespace ? $ namespace . "\\" . $ tokens [ $ i ] [ 1 ] : $ tokens [ $ i ] [ 1 ] ; $ dlm = true ; } } elseif ( $ dlm && ( $ tokens [ $ i ] [ 0 ] != T_NS_SEPARATOR ) && ( $ tokens [ $ i ] [ 0 ] != T_STRING ) ) { $ dlm = false ; } if ( ( $ tokens [ $ i - 2 ] [ 0 ] == T_CLASS || ( isset ( $ tokens [ $ i - 2 ] [ 1 ] ) && $ tokens [ $ i - 2 ] [ 1 ] == "phpclass" ) ) && $ tokens [ $ i - 1 ] [ 0 ] == T_WHITESPACE && $ tokens [ $ i ] [ 0 ] == T_STRING ) { $ class_name = $ tokens [ $ i ] [ 1 ] ; if ( ! isset ( $ classes [ $ namespace ] ) ) $ classes [ $ namespace ] = array ( ) ; $ classes [ $ namespace ] [ ] = $ class_name ; } } return $ classes ; }
Parses PHP and gets Namespaces and Classes
35,240
public function format ( $ value , string $ format = null ) { $ formatted = number_format ( $ value , $ this -> decimals , $ format === 'nomask' ? '' : $ this -> decimal , $ format === 'nomask' ? '' : $ this -> thousand ) ; switch ( $ format ) { case 'name' : $ name = $ this -> name_plural ; if ( ! $ name || ( float ) $ value === 1.0 ) { $ name = $ this -> name ; } return $ formatted . ' ' . $ name ; break ; case 'raw' : case 'nomask' : return $ formatted ; break ; case 'symbol' : default : return $ this -> symbol . ' ' . $ formatted ; break ; } }
Outputs a value formatted to this model
35,241
public function key ( $ key = null ) { if ( $ key === null ) return $ this -> key ; $ this -> key = $ key ; return $ this ; }
Get or set Job key
35,242
public function run ( $ time ) { if ( empty ( $ this -> formats ) or empty ( $ this -> callbacks ) ) return false ; if ( ! is_array ( $ time ) ) $ time = getdate ( $ time ) ; $ should_run = false ; foreach ( $ this -> formats as $ format ) { if ( ! $ format -> test ( $ time ) ) continue ; $ should_run = true ; break ; } if ( ! $ should_run ) return false ; foreach ( $ this -> callbacks as $ callback ) { if ( ! is_callable ( $ callback ) ) continue ; call_user_func ( $ callback ) ; } return true ; }
Determine if this Job is set to be run if so run it
35,243
public function validate ( $ input ) { $ this -> errors = [ ] ; foreach ( $ this -> rawRules as $ rules ) { list ( $ ruleName , $ rule ) = $ rules ; if ( $ rule instanceof Validate ) { $ rule -> validate ( $ input ) ; $ this -> errors = array_merge ( $ this -> errors , $ rule -> getErrors ( ) ) ; continue ; } if ( $ rule instanceof When ) { $ rule -> invert = $ this -> invert ; $ rule -> validate ( $ input ) ; $ this -> errors = array_merge ( $ this -> errors , $ rule -> getErrors ( ) ) ; continue ; } if ( $ rule instanceof Attributes ) { $ config = [ 'one' => $ this -> one , 'invert' => $ this -> invert , 'remainder' => $ this -> remainder ] ; Instance :: configure ( $ rule , $ config ) ; $ rule -> validate ( $ input ) ; $ this -> errors = $ rule -> getErrors ( ) ; break ; } if ( $ this -> skipEmpty && $ rule -> skipEmpty && $ this -> isEmpty ( $ input , $ rule ) ) { continue ; } if ( $ rule -> validate ( $ input ) === ! $ this -> invert ) { continue ; } $ this -> errors [ $ ruleName ] = $ this -> error ( $ ruleName , $ rule ) ; if ( $ this -> one === true ) { break ; } } return empty ( $ this -> errors ) ; }
Checks a value .
35,244
public function getFirstError ( $ attribute = null ) { if ( empty ( $ this -> errors ) ) { return null ; } if ( isset ( $ attribute ) ) { if ( isset ( $ this -> errors [ $ attribute ] ) ) { return current ( $ this -> errors [ $ attribute ] ) ; } return null ; } $ error = current ( $ this -> errors ) ; if ( is_array ( $ error ) ) { return current ( $ error ) ; } return $ error ; }
Returns first error .
35,245
public function getLastError ( $ attribute = null ) { if ( empty ( $ this -> errors ) ) { return null ; } if ( isset ( $ attribute ) ) { if ( isset ( $ this -> errors [ $ attribute ] ) ) { return end ( $ this -> errors [ $ attribute ] ) ; } return null ; } $ error = end ( $ this -> errors ) ; if ( is_array ( $ error ) ) { return end ( $ error ) ; } return $ error ; }
Returns last error .
35,246
protected function isEmpty ( $ value , Rule $ rule ) { if ( is_callable ( $ rule -> isEmpty ) ) { return call_user_func ( $ rule -> isEmpty , $ value ) ; } return $ value === null || $ value === [ ] || $ value === '' ; }
Checks if the given value is empty .
35,247
public function isJson ( $ value ) { if ( ! is_scalar ( $ value ) && ! method_exists ( $ value , '__toString' ) ) { return false ; } json_decode ( $ value ) ; return json_last_error ( ) === JSON_ERROR_NONE ; }
Validate the attribute is a valid JSON string .
35,248
protected function isRequiredUnless ( $ value , $ parameters ) { $ this -> requireParameterCount ( 2 , $ parameters , 'required_unless' ) ; $ data = Arr :: get ( $ this -> data , $ parameters [ 0 ] ) ; $ values = array_slice ( $ parameters , 1 ) ; if ( ! in_array ( $ data , $ values ) ) { return $ this -> isRequired ( $ value ) ; } return true ; }
Validate that an attribute exists when another attribute does not have a given value .
35,249
public function compileAll ( ) { $ this -> emptyCompileDir ( ) ; $ this -> compileOtherFiles ( ) ; $ manifestNames = $ this -> config ( ) -> precompile ; foreach ( $ manifestNames as $ manifest ) { $ ext = pathinfo ( $ manifest , PATHINFO_EXTENSION ) ; $ paths = $ this -> findAllFiles ( $ manifest ) ; foreach ( $ paths as $ path ) { $ this -> compileFile ( new File ( $ ext , $ path ) ) ; } } }
Deletes all compiled files and compiles them again .
35,250
public function emptyCompileDir ( ) { $ this -> console ( "Deleting compiled assets" ) ; $ dir = $ this -> compilePath ( ) . $ this -> prefix ( ) ; if ( is_dir ( $ dir ) ) { Rails \ Toolbox \ FileTools :: emptyDir ( $ dir ) ; } }
Deletes everything inside the compile folder .
35,251
public function getManifestIndex ( ) { $ file = $ this -> manifestIndexFile ( ) ; if ( is_file ( $ file ) ) { $ index = Rails \ Yaml \ Parser :: readFile ( $ file ) ; if ( ! is_array ( $ index ) ) { $ index = [ ] ; } } else { $ index = [ ] ; } return $ index ; }
Gets the contents of the manifest index file .
35,252
public function manifestIndexFile ( ) { $ basePath = $ this -> manifestFilePath ? : $ this -> config ( ) -> compile_path . $ this -> prefix ( ) ; $ indexFile = $ basePath . '/' . $ this -> manifestFileName . '.yml' ; return $ indexFile ; }
Path to the manifest file .
35,253
public function getTransitions ( $ alias , $ id , $ hydrationMode = self :: HYDRATION_MODE_OBJECTS ) { $ current = $ this -> getCurrentTransition ( $ alias , $ id , $ hydrationMode ) ; if ( $ current === null ) { throw new EntityNotFoundException ( $ alias , $ id ) ; } $ currentTransition = $ current -> getTransition ( ) ; $ allTransitions [ 'current' ] = $ current ; if ( $ currentTransition ) { $ allTransitions [ 'previous' ] = array_reverse ( $ this -> getPreviousTransitions ( $ currentTransition -> getSource ( ) , $ currentTransition -> getSourceId ( ) , $ hydrationMode ) ) ; } $ allTransitions [ 'following' ] = $ this -> getFollowingTransitions ( $ alias , $ id , $ hydrationMode ) ; return $ allTransitions ; }
Returns the current all previous and following transitions .
35,254
protected function getNextPreviousTransition ( $ destination , $ destinationId , $ hydrationMode ) { $ transition = $ this -> transitionManager -> findOneByDestination ( $ destination , $ destinationId ) ; if ( $ transition !== null ) { $ transitionResult = $ this -> createTransitionResult ( $ transition -> getDestination ( ) , $ transition -> getDestinationId ( ) , $ hydrationMode ) ; if ( ! $ transitionResult ) { return ; } $ transitionResult -> setId ( $ transition -> getId ( ) ) ; $ transitionResult -> setTransition ( $ transition ) ; return $ transitionResult ; } return null ; }
Returns previous of previous Transition .
35,255
protected function getFollowingTransitions ( $ alias , $ id , $ hydrationMode = self :: HYDRATION_MODE_OBJECTS ) { $ transitionResults = [ ] ; $ transitions = $ this -> transitionManager -> findBySource ( $ alias , $ id ) ; if ( $ transitions && count ( $ transitions ) > 0 ) { foreach ( $ transitions as $ transition ) { $ currentAlias = $ transition -> getDestination ( ) ; $ currentId = $ transition -> getDestinationId ( ) ; $ transitionResult = $ this -> createTransitionResult ( $ currentAlias , $ currentId , $ hydrationMode ) ; if ( ! $ transitionResult ) { continue ; } $ transitionResult -> setId ( $ transition -> getId ( ) ) ; $ transitionResult -> setTransition ( $ transition ) ; $ transitionResults [ ] = $ transitionResult ; $ transitionResults = array_merge ( $ transitionResults , $ this -> getFollowingTransitions ( $ currentAlias , $ currentId , $ hydrationMode ) ) ; } } return $ transitionResults ; }
Returns next following Transition .
35,256
public function updateTotalNetPrice ( ) { if ( ! $ this -> getItems ( ) ) { return ; } $ totalNetPrice = 0 ; foreach ( $ this -> getItems ( ) as $ item ) { if ( ! $ item -> isRecurringPrice ( ) ) { $ totalNetPrice += $ item -> getTotalNetPrice ( ) ; } } $ totalNetPrice += self :: getNetShippingCosts ( ) ; $ this -> setTotalNetPrice ( $ totalNetPrice ) ; }
Updates the total net price .
35,257
public function save ( string $ object , ... $ options ) { if ( ! $ this -> exists ( $ object ) ) { $ this -> registry [ $ object ] = [ ] ; } return ; }
Saves an object to the registry
35,258
public function exists ( string $ object ) : bool { return ( ! empty ( $ this -> registry ) && isset ( $ this -> registry [ $ object ] ) ) ; }
determines if an object exists in the registry
35,259
public function get ( string $ object ) { return ( $ this -> exists ( $ object ) ) ? $ this -> registry [ $ object ] : null ; }
retrieves an object index from the registry
35,260
public function getRegistryNames ( ) : array { $ names = [ ] ; foreach ( $ this -> getRegistry ( ) as $ registryName => $ registryValue ) { $ names [ ] = $ registryName ; } return $ names ; }
returns the names of objects stored in the registry
35,261
public function numberofshippedorderitemsAction ( Request $ request ) { $ orderId = $ request -> get ( 'orderId' ) ; $ sum = $ this -> getManager ( ) -> getSumOfShippedItemsByOrderId ( $ orderId ) ; return $ this -> handleView ( $ this -> view ( $ sum , 200 ) ) ; }
this function returns number of shipped items per item the result is a key value pair of itemId = > number of shipped items
35,262
public function postAction ( Request $ request ) { try { $ shipping = $ this -> getManager ( ) -> save ( $ request -> request -> all ( ) , $ this -> getLocaleManager ( ) -> retrieveLocale ( $ this -> getUser ( ) , $ request -> get ( 'locale' ) ) , $ this -> getUser ( ) -> getId ( ) ) ; $ view = $ this -> view ( $ shipping , 200 ) ; } catch ( ShippingDependencyNotFoundException $ exc ) { $ exception = new EntityNotFoundException ( $ exc -> getEntityName ( ) , $ exc -> getId ( ) ) ; $ view = $ this -> view ( $ exception -> toArray ( ) , 400 ) ; } catch ( MissingShippingAttributeException $ exc ) { $ exception = new MissingArgumentException ( self :: $ shippingEntityName , $ exc -> getAttribute ( ) ) ; $ view = $ this -> view ( $ exception -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; }
Creates and stores a new shipping .
35,263
public function putAction ( Request $ request , $ id ) { try { $ shipping = $ this -> getManager ( ) -> save ( $ request -> request -> all ( ) , $ this -> getLocaleManager ( ) -> retrieveLocale ( $ this -> getUser ( ) , $ request -> get ( 'locale' ) ) , $ this -> getUser ( ) -> getId ( ) , $ id ) ; $ view = $ this -> view ( $ shipping , 200 ) ; } catch ( ShippingNotFoundException $ exc ) { $ exception = new EntityNotFoundException ( $ exc -> getEntityName ( ) , $ exc -> getId ( ) ) ; $ view = $ this -> view ( $ exception -> toArray ( ) , 404 ) ; } catch ( ShippingDependencyNotFoundException $ exc ) { $ exception = new EntityNotFoundException ( $ exc -> getEntityName ( ) , $ exc -> getId ( ) ) ; $ view = $ this -> view ( $ exception -> toArray ( ) , 400 ) ; } catch ( MissingShippingAttributeException $ exc ) { $ exception = new MissingArgumentException ( self :: $ shippingEntityName , $ exc -> getAttribute ( ) ) ; $ view = $ this -> view ( $ exception -> toArray ( ) , 400 ) ; } catch ( ShippingException $ exc ) { $ exception = new RestException ( $ exc -> getMessage ( ) ) ; $ view = $ this -> view ( $ exception -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; }
Change a shipping .
35,264
public function map ( Router $ router ) { $ addon = $ this -> addon ( ) ; $ config = $ addon -> config ( 'addon.routes' ) ; $ attributes = [ 'domain' => array_get ( $ config , 'domain' , null ) , 'prefix' => array_get ( $ config , 'prefix' , '' ) , 'namespace' => array_get ( $ config , 'namespace' , $ addon -> phpNamespace ( ) . '\\Controllers' ) , 'middleware' => array_get ( $ config , 'middleware' , [ ] ) , ] ; $ files = array_map ( function ( $ file ) use ( $ addon ) { return $ addon -> path ( $ file ) ; } , array_get ( $ config , 'files' , [ 'classes/Http/routes.php' ] ) ) ; $ router -> group ( $ attributes , function ( $ router ) use ( $ files ) { foreach ( $ files as $ file ) { require $ file ; } } ) ; }
Define the routes for the addon .
35,265
public function init ( $ consumerKey , $ consumerSecret , $ oauthToken , $ oauthTokenSecret , $ bearerToken ) { $ this -> twitter -> setConsumerKey ( $ consumerKey , $ consumerSecret ) ; if ( ! is_null ( $ bearerToken ) ) { $ this -> setBearerToken ( $ bearerToken ) ; } elseif ( ! is_null ( $ oauthToken ) && ! is_null ( $ oauthTokenSecret ) ) { $ this -> setToken ( $ oauthToken , $ oauthTokenSecret ) ; } elseif ( $ this -> hasSessionToken ( ) ) { $ this -> setSessionToken ( ) ; } }
Initialize the oauth token api .
35,266
public function api ( $ method , $ path , array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false , $ internal = false ) { $ result = $ this -> twitter -> api ( $ method , $ path , $ parameters , $ multipart , $ appOnlyAuth , $ internal ) ; return $ this -> reformatResult ( $ result ) ; }
Twitter Api Call .
35,267
public function reformatResult ( $ result ) { $ collection = new Collection ( $ result ) ; switch ( $ this -> format ) { case 'json' : return $ collection -> toJson ( ) ; break ; case 'object' : return json_decode ( json_encode ( $ collection -> toArray ( ) ) , false ) ; break ; default : return $ collection -> toArray ( ) ; break ; } }
Reformat the result .
35,268
public function patch ( $ path , array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false , $ internal = false ) { return $ this -> api ( 'PATCH' , $ path , $ parameters , $ multipart , $ appOnlyAuth , $ internal ) ; }
Helper method for making a PATCH request .
35,269
public function doAuthFlow ( $ mode , $ url = null , $ errorMessage ) { $ callback = $ url ? : $ this -> getCallbackUrl ( ) ; $ this -> destroy ( ) ; $ this -> twitter -> setToken ( null , null ) ; $ this -> response = $ this -> api ( 'POST' , 'oauth/request_token' , array ( 'oauth_callback' => $ callback ) ) ; if ( $ this -> responseOk ( ) ) { $ token = $ this -> response -> oauth_token ; $ token_secret = $ this -> response -> oauth_token_secret ; $ this -> setToken ( $ token , $ token_secret ) ; $ this -> session -> put ( 'oauth_request_token' , $ token ) ; $ this -> session -> put ( 'oauth_request_token_secret' , $ token_secret ) ; $ this -> session -> put ( 'oauth_request_verify' , true ) ; $ method = 'get' . ucfirst ( $ mode ) . 'Url' ; $ authUrl = $ this -> $ method ( ) ; return $ this -> redirect -> to ( $ authUrl ) ; } $ this -> triggerError ( $ errorMessage ) ; }
Authenticates or authorizes to twitter .
35,270
public function callback ( $ fallback_url = null ) { if ( $ this -> request -> has ( 'denied' ) ) { return $ this -> redirect -> to ( $ fallback_url ? : $ this -> getFallbackUrl ( ) ) ; } elseif ( $ this -> request -> has ( 'oauth_verifier' ) && $ this -> session -> has ( 'oauth_request_verify' ) ) { $ this -> twitter -> setToken ( $ this -> session -> get ( 'oauth_request_token' ) , $ this -> session -> get ( 'oauth_request_token_secret' ) ) ; $ this -> session -> forget ( 'oauth_request_verify' ) ; $ oauthVerifier = $ this -> request -> get ( 'oauth_verifier' ) ; $ this -> response = $ this -> twitter -> api ( 'POST' , 'oauth/access_token' , array ( 'oauth_verifier' => $ oauthVerifier ) ) ; if ( $ this -> responseOk ( ) ) { $ this -> session -> forget ( 'oauth_request_token' ) ; $ this -> session -> forget ( 'oauth_request_token_secret' ) ; $ this -> session -> forget ( 'oauth_request_verify' ) ; $ data = array ( 'oauth_token' , 'oauth_token_secret' , 'user_id' , 'screen_name' ) ; foreach ( $ data as $ key ) { $ this -> session -> put ( "twitter.{$key}" , $ this -> response -> { $ key } ) ; } return $ this -> response ; } $ this -> triggerError ( "Invalid or expired token." ) ; } else { $ this -> triggerError ( "To perform callback, you must authorize the user first." ) ; } }
Perform callback .
35,271
public function check ( ) { $ hasUser = $ this -> session -> has ( 'twitter.user_id' ) && $ this -> session -> has ( 'twitter.screen_name' ) ; return $ this -> hasSessionToken ( ) && $ hasUser ; }
Determine whether have logged user .
35,272
protected function setSessionToken ( ) { $ token = $ this -> session -> get ( 'twitter.oauth_token' ) ; $ tokenSecret = $ this -> session -> get ( 'twitter.oauth_token_secret' ) ; $ this -> setToken ( $ token , $ tokenSecret ) ; }
Set the token from session manager .
35,273
public function getBearerToken ( ) { $ this -> response = $ this -> twitter -> oauth2_token ( ) ; if ( $ this -> responseOk ( ) ) { return $ this -> response -> access_token ; } $ this -> triggerError ( "Unable to get bearer token." , $ this -> response ) ; }
Get bearer token .
35,274
public function getValidator ( PermissionInterface $ permission ) { $ validator = $ this -> validatorPluginManager -> get ( $ permission -> getValidator ( ) ) ; if ( ! $ validator ) { throw new Exception \ ValidatorNotFound ( sprintf ( 'The validator \"%s\" could not be found' , is_object ( $ validator ) ? get_class ( $ validator ) : gettype ( $ validator ) ) ) ; } if ( $ permission -> getValidatorOptions ( ) ) { $ json = $ permission -> getValidatorOptions ( ) ; $ options = json_decode ( $ json , true ) ; if ( ! $ options ) { throw new Exception \ RuntimeException ( sprintf ( 'The options for validator \"%s\" must be in json format' , is_object ( $ validator ) ? get_class ( $ validator ) : gettype ( $ validator ) ) ) ; } foreach ( $ options as $ method => $ value ) { $ validator -> { $ method } ( $ value ) ; } } return $ validator ; }
Get validator from entity
35,275
public static function realpath ( $ path ) { $ path = str_replace ( DIRECTORY_SEPARATOR , '/' , $ path ) ; if ( false === $ parse_url = parse_url ( $ path ) ) { return false ; } if ( ! array_key_exists ( 'host' , $ parse_url ) ) { return realpath ( $ path ) ; } if ( ! array_key_exists ( 'scheme' , $ parse_url ) ) { return false ; } $ parts = [ ] ; $ pathArray = explode ( '/' , str_replace ( DIRECTORY_SEPARATOR , '/' , $ parse_url [ 'path' ] ) ) ; foreach ( $ pathArray as $ part ) { if ( '.' === $ part ) { continue ; } elseif ( '..' === $ part ) { array_pop ( $ parts ) ; } else { $ parts [ ] = $ part ; } } $ path = ( isset ( $ parse_url [ 'scheme' ] ) ? $ parse_url [ 'scheme' ] . '://' : '' ) . ( isset ( $ parse_url [ 'user' ] ) ? $ parse_url [ 'user' ] : '' ) . ( isset ( $ parse_url [ 'pass' ] ) ? ':' . $ parse_url [ 'pass' ] : '' ) . ( isset ( $ parse_url [ 'user' ] ) || isset ( $ parse_url [ 'pass' ] ) ? '@' : '' ) . ( isset ( $ parse_url [ 'host' ] ) ? $ parse_url [ 'host' ] : '' ) . ( isset ( $ parse_url [ 'port' ] ) ? ':' . $ parse_url [ 'port' ] : '' ) . implode ( '/' , $ parts ) ; if ( ! file_exists ( $ path ) ) { return false ; } return $ path ; }
Returns canonicalized absolute pathname
35,276
public static function normalizePath ( $ filepath , $ separator = DIRECTORY_SEPARATOR , $ removeTrailing = true ) { $ scheme = '' ; if ( false !== $ parseUrl = parse_url ( $ filepath ) ) { $ auth = isset ( $ parseUrl [ 'user' ] ) ? $ parseUrl [ 'user' ] : '' ; $ auth .= isset ( $ parseUrl [ 'pass' ] ) ? ':' . $ parseUrl [ 'pass' ] : '' ; $ auth .= ( isset ( $ parseUrl [ 'user' ] ) || isset ( $ parseUrl [ 'pass' ] ) ) ? '@' : '' ; $ scheme .= isset ( $ parseUrl [ 'scheme' ] ) ? $ parseUrl [ 'scheme' ] . ':' : '' ; $ scheme .= isset ( $ parseUrl [ 'host' ] ) ? '//' . $ auth . $ parseUrl [ 'host' ] : '' ; $ scheme .= isset ( $ parseUrl [ 'port' ] ) ? ':' . $ parseUrl [ 'port' ] : '' ; if ( isset ( $ parseUrl [ 'path' ] ) ) { $ filepath = $ parseUrl [ 'path' ] ; } if ( isset ( $ parseUrl [ 'scheme' ] ) && isset ( $ parseUrl [ 'host' ] ) ) { $ separator = '/' ; } } $ patterns = array ( '/\//' , '/\\\\/' , '/\/+/' ) ; $ replacements = array_fill ( 0 , 3 , '/' ) ; if ( true === $ removeTrailing ) { $ patterns [ ] = '/\/$/' ; $ replacements [ ] = '' ; } return str_replace ( '/' , $ separator , $ scheme . preg_replace ( $ patterns , $ replacements , $ filepath ) ) ; }
Normalize a file path according to the system characteristics
35,277
public static function readableFilesize ( $ size , $ precision = 2 ) { $ result = $ size ; $ index = 0 ; while ( $ result > 1024 && $ index < count ( self :: $ prefixes ) ) { $ result = $ result / 1024 ; $ index ++ ; } return sprintf ( '%1.' . $ precision . 'f %sB' , $ result , self :: $ prefixes [ $ index ] ) ; }
Tranformation to human - readable format
35,278
public static function getExtension ( $ filename , $ withDot = true ) { $ filename = basename ( $ filename ) ; if ( false === strrpos ( $ filename , '.' ) ) { return '' ; } return substr ( $ filename , strrpos ( $ filename , '.' ) - strlen ( $ filename ) + ( $ withDot ? 0 : 1 ) ) ; }
Returns the extension file base on its name
35,279
public static function removeExtension ( $ filename ) { if ( false === strrpos ( $ filename , '.' ) ) { return $ filename ; } return substr ( $ filename , 0 , strrpos ( $ filename , '.' ) ) ; }
Removes the extension file from its name
35,280
public static function extractZipArchive ( $ file , $ destinationDir , $ createDir = false ) { if ( ! file_exists ( $ destinationDir ) ) { if ( false === $ createDir ) { throw new ApplicationException ( sprintf ( "Destination directory does not exist: %s ." , $ destinationDir ) ) ; } $ folderCreation = mkdir ( $ destinationDir , 0777 , true ) ; if ( false === $ folderCreation ) { throw new ApplicationException ( sprintf ( "Destination directory cannot be created: %s ." , $ destinationDir ) ) ; } if ( ! is_readable ( $ destinationDir ) ) { throw new ApplicationException ( sprintf ( "Destination directory is not readable: %s ." , $ destinationDir ) ) ; } } elseif ( ! is_dir ( $ destinationDir ) ) { throw new ApplicationException ( sprintf ( "Destination directory cannot be created as a file with that name already exists: %s ." , $ destinationDir ) ) ; } $ archive = new ZipArchive ( ) ; if ( false === $ archive -> open ( $ file ) ) { throw new ApplicationException ( sprintf ( "Could not open archive: %s ." , $ archive ) ) ; } try { $ archive -> extractTo ( $ destinationDir ) ; } catch ( \ Exception $ e ) { throw new ApplicationException ( sprintf ( "Could not extract archive from path: %s ." , $ file ) ) ; } $ archive -> close ( ) ; }
Extracts a zip archive into a specified directory
35,281
public function renderCheckbox ( Checkbox $ checkbox ) { $ content = '<div class="checkbox"><label>' ; $ content .= $ checkbox -> render ( $ this ) ; $ content .= $ checkbox -> getLabel ( ) ; $ content .= '</label></div>' ; return $ content ; }
Renders a basic checkbox
35,282
public function renderSubmit ( Submit $ select ) { $ attributes = $ select -> getAttributes ( ) ; if ( ! isset ( $ attributes [ 'class' ] ) ) { $ attributes [ 'class' ] = '' ; } $ attributes [ 'class' ] .= ' btn btn-default' ; return Html :: tag ( 'button' , $ attributes , $ select -> getValue ( ) ) ; }
Renders a submit with the appropriate classes .
35,283
public function getAccountVerifyCredentials ( array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false ) { return $ this -> api ( 'GET' , 'account/verify_credentials' , $ parameters , $ multipart , $ appOnlyAuth ) ; }
Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful .
35,284
public function getCredentials ( array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false ) { return $ this -> getAccountVerifyCredentials ( $ parameters , $ multipart , $ appOnlyAuth ) ; }
Alias method for getAccountVerifyCredentials .
35,285
public function postAccountSettings ( array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false ) { return $ this -> post ( 'account/settings' , $ parameters , $ multipart , $ appOnlyAuth ) ; }
Updates the authenticating user s settings .
35,286
public function getUsersSearch ( array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false ) { return $ this -> get ( 'users/search' , $ parameters , $ multipart , $ appOnlyAuth ) ; }
Provides a simple relevance - based search interface to public user accounts on Twitter . Try querying by topical interest full name company name location or other criteria . Exact match searches are not supported . Only the first 1 000 matching results are available .
35,287
protected function createModels ( ) { $ path = $ this -> option ( 'path' ) ; $ namespace = $ this -> option ( 'namespace' ) ; $ connectionName = $ this -> option ( 'connection' ) ; $ tableNames = $ this -> getDatabaseTableNames ( $ connectionName ) ; $ models = [ ] ; foreach ( $ tableNames as $ tableName ) { if ( $ this -> skipTable ( $ tableName ) ) { continue ; } $ models [ $ tableName ] = new Model ( $ connectionName , $ tableName ) ; $ models [ $ tableName ] -> setPath ( $ path ) ; $ models [ $ tableName ] -> setNamespace ( $ namespace ) ; $ models [ $ tableName ] -> map ( ) ; } return $ models ; }
Build up meta data
35,288
protected function makeRelations ( array $ models ) { foreach ( $ models as $ model ) { $ localTable = $ model -> getTable ( ) ; $ foreignKeys = $ localTable -> getTableForeignKeys ( ) ; foreach ( $ foreignKeys as $ foreignKey ) { if ( ! isset ( $ models [ $ foreignKey -> getForeignTableName ( ) ] ) ) { continue ; } $ foreignModel = $ models [ $ foreignKey -> getForeignTableName ( ) ] ; $ foreignTable = $ foreignModel -> getTable ( ) ; $ localColumns = $ foreignKey -> getLocalColumns ( ) ; $ foreignColumns = $ foreignKey -> getForeignColumns ( ) ; $ localIndex = $ localTable -> getTableIndexByColumnsName ( $ localColumns ) ; $ foreignIndex = $ foreignTable -> getTableIndexByColumnsName ( $ foreignColumns ) ; $ localTableClass = str_singular ( $ model -> getFullClass ( ) ) ; $ foreignTableClass = str_singular ( $ foreignModel -> getFullClass ( ) ) ; $ localColumn = reset ( $ localColumns ) ; $ foreignColumn = reset ( $ foreignColumns ) ; $ localMethodName = str_replace ( [ '_id' ] , '' , snake_case ( $ localColumn ) ) ; $ foreignMethodName = $ model -> getClass ( ) ; if ( $ localIndex !== false && $ foreignIndex !== false && $ localIndex -> isUnique ( ) && $ foreignIndex -> isUnique ( ) ) { $ localTable -> addHasOneRelation ( $ foreignTableClass , $ localMethodName , $ foreignColumn , $ localColumn ) ; $ foreignTable -> addBelongsToRelation ( $ localTableClass , $ foreignMethodName , $ localColumn , $ foreignColumn ) ; } elseif ( $ foreignIndex !== false && $ foreignIndex -> isUnique ( ) ) { $ localTable -> addBelongsToRelation ( $ foreignTableClass , $ localMethodName , $ localColumn , $ foreignColumn ) ; $ foreignTable -> addHasManyRelation ( $ localTableClass , $ foreignMethodName , $ localColumn , $ foreignColumn ) ; } elseif ( $ localIndex !== false && $ localIndex -> isUnique ( ) ) { $ localTable -> addHasManyRelation ( $ foreignTableClass , $ localMethodName , $ foreignColumn , $ localColumn ) ; $ foreignTable -> addBelongsToRelation ( $ localTableClass , $ foreignMethodName , $ localColumn , $ foreignColumn ) ; } else { $ localTable -> addHasManyRelation ( $ foreignTableClass , $ localMethodName , $ foreignColumn , $ localColumn ) ; $ foreignTable -> addHasManyRelation ( $ localTableClass , $ foreignMethodName , $ localColumn , $ foreignColumn ) ; } } } }
Generate relation to each table
35,289
protected function recursiveAssignValue ( array $ values , $ list ) { foreach ( $ list as $ item ) { if ( $ item instanceof Optgroup ) { $ this -> recursiveAssignValue ( $ values , $ item -> getContents ( ) ) ; } else if ( in_array ( $ item -> getValue ( ) , $ values ) ) { $ this -> assignSelected ( $ item ) ; } } }
Recursive function to be able to handle Optgroups
35,290
protected function assignSelected ( Option $ option ) { $ attributes = $ option -> getAttributes ( ) ; $ attributes [ ] = 'selected' ; $ option -> setAttributes ( $ attributes ) ; }
Sets the given Option as selected
35,291
public function render ( Render $ renderer ) { $ content = '' ; foreach ( $ this -> getContents ( ) as $ option ) { $ content .= "\n" . $ renderer -> render ( $ option ) ; } return Html :: tag ( 'select' , $ this -> getAttributes ( ) , $ content ) ; }
Renders this select and any added options or optgroups
35,292
public function setValue ( $ value ) { $ this -> value = $ value ; if ( ! is_array ( $ value ) && ! $ value instanceof \ ArrayAccess ) { $ valueArray = [ $ value ] ; } else { $ valueArray = $ value ; } foreach ( $ this -> getContents ( ) as $ checkbox ) { $ checkboxValue = $ checkbox -> getValue ( ) ; if ( in_array ( $ checkboxValue , $ valueArray ) ) { $ checkbox -> setChecked ( true ) ; } else { $ checkbox -> setChecked ( false ) ; } } return $ this ; }
Sets the value of the group this will define which elements are selected or checked . If an array is given multiple checkboxes can be enabled .
35,293
public function set ( $ key , $ value ) { if ( ! $ value instanceof Checkbox ) { throw new \ InvalidArgumentException ( 'Only Checkboxs can be added to a CheckboxGroup' ) ; } return parent :: set ( $ key , $ value ) ; }
Extends the set method to ensure that only Checkboxs can be added to a CheckboxGroup
35,294
public function render ( Render $ renderer ) { $ checkboxes = [ ] ; foreach ( $ this -> getContents ( ) as $ checkbox ) { $ checkboxes [ ] = $ renderer -> render ( $ checkbox ) ; } return implode ( '' , $ checkboxes ) ; }
Renders a group of checkboxes to html
35,295
public function process ( ContainerBuilder $ container ) { $ parameterBag = $ container -> getParameterBag ( ) ; $ parameterReplacer = $ container -> get ( ServiceNames :: PARAMETER_REPLACER ) ; $ parameterReplacer -> processParameterBag ( $ parameterBag , $ container ) ; }
Process container .
35,296
public function getSearchTweets ( array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false ) { return $ this -> get ( 'search/tweets' , $ parameters , $ multipart , $ appOnlyAuth ) ; }
Returns a collection of relevant Tweets matching a specified query .
35,297
public function getSavedSearchesList ( array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false ) { return $ this -> get ( 'saved_searches/list' , $ parameters , $ multipart , $ appOnlyAuth ) ; }
Returns the authenticated user s saved search queries .
35,298
public function getSavedSearchesShow ( $ id , array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false ) { return $ this -> get ( "saved_searches/show/{$id}" , $ parameters , $ multipart , $ appOnlyAuth ) ; }
Retrieve the information for the saved search represented by the given id . The authenticating user must be the owner of saved search ID being requested .
35,299
public function getSavedSearchesCreate ( array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false ) { return $ this -> post ( 'saved_searches/create' , $ parameters , $ multipart , $ appOnlyAuth ) ; }
Create a new saved search for the authenticated user . A user may only have 25 saved searches .