idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
28,100 | public static function strReplaceFile ( string $ find , string $ replace , string $ file_path ) { file_put_contents ( $ file_path , str_replace ( $ find , $ replace , file_get_contents ( $ file_path ) ) ) ; } | Replace a string from a file . |
28,101 | public static function massStrReplaceFile ( string $ find , string $ replace , string $ path ) { $ dir = opendir ( $ path ) ; while ( false !== ( $ file = readdir ( $ dir ) ) ) { if ( ( $ file != '.' ) && ( $ file != '..' ) ) { if ( is_dir ( $ path . '/' . $ file ) ) { static :: massStrReplaceFile ( $ find , $ replace , $ path . '/' . $ file ) ; } else { static :: strReplaceFile ( $ find , $ replace , $ path . '/' . $ file ) ; } } } closedir ( $ dir ) ; } | Replace a string from each file in a given directory . |
28,102 | public static function create ( array $ config ) { if ( \ Tripod \ Config :: getConfig ( ) !== $ config ) { \ Tripod \ Config :: setConfig ( $ config ) ; } if ( isset ( $ config [ 'class' ] ) && class_exists ( $ config [ 'class' ] ) ) { $ tripodConfig = call_user_func ( array ( $ config [ 'class' ] , 'deserialize' ) , $ config ) ; } else { $ tripodConfig = \ Tripod \ Mongo \ Config :: deserialize ( $ config ) ; } return $ tripodConfig ; } | Factory method to get a Tripod \ ITripodConfig instance from either a config array or a serialized ITripodConfigSerializer instance |
28,103 | public function generateAndIndexSearchDocuments ( $ resourceUri , $ context , $ podName , $ specType = [ ] ) { $ mongoCollection = $ this -> config -> getCollectionForCBD ( $ this -> storeName , $ podName ) ; $ searchDocGenerator = $ this -> getSearchDocumentGenerator ( $ mongoCollection , $ context ) ; $ searchProvider = $ this -> getSearchProvider ( ) ; $ searchProvider -> deleteDocument ( $ resourceUri , $ context , $ specType ) ; $ documentsToIndex = [ ] ; $ query = array ( "_id" => array ( 'r' => $ this -> labeller -> uri_to_alias ( $ resourceUri ) , 'c' => $ this -> getContextAlias ( $ context ) ) ) ; $ resourceAndType = $ mongoCollection -> find ( $ query , [ 'projection' => [ "_id" => 1 , "rdf:type" => 1 ] , 'maxTimeMS' => $ this -> config -> getMongoCursorTimeout ( ) ] ) ; foreach ( $ resourceAndType as $ rt ) { if ( array_key_exists ( "rdf:type" , $ rt ) ) { $ rdfTypes = [ ] ; if ( array_key_exists ( 'u' , $ rt [ "rdf:type" ] ) ) { $ rdfTypes [ ] = $ rt [ "rdf:type" ] [ 'u' ] ; } else { foreach ( $ rt [ "rdf:type" ] as $ type ) { $ rdfTypes [ ] = $ type [ 'u' ] ; } } $ docs = $ searchDocGenerator -> generateSearchDocumentsBasedOnRdfTypes ( $ rdfTypes , $ resourceUri , $ context ) ; foreach ( $ docs as $ d ) { $ documentsToIndex [ ] = $ d ; } } } foreach ( $ documentsToIndex as $ document ) { if ( ! empty ( $ document ) ) { $ searchProvider -> indexDocument ( $ document ) ; } } } | Removes all existing documents for the supplied resource and regenerate the search documents |
28,104 | public function toArray ( ) { return array ( "resourceId" => $ this -> resourceId , "operation" => $ this -> operation , "specTypes" => $ this -> specTypes , "storeName" => $ this -> storeName , "podName" => $ this -> podName ) ; } | Serialises the data as an array |
28,105 | public function update ( ) { $ tripod = $ this -> getTripod ( ) ; if ( isset ( $ this -> stat ) ) { $ tripod -> setStat ( $ this -> stat ) ; } $ tripod -> getComposite ( $ this -> operation ) -> update ( $ this ) ; } | Perform the update on the composite defined by the operation |
28,106 | function uri_to_alias ( $ uri ) { try { $ retVal = $ this -> uri_to_qname ( $ uri ) ; } catch ( \ Tripod \ Exceptions \ LabellerException $ e ) { } return ( empty ( $ retVal ) ) ? $ uri : $ retVal ; } | If labeller can generate a qname for this uri it will return it . Otherwise just returns the original uri |
28,107 | function qname_to_alias ( $ qname ) { try { $ retVal = $ this -> qname_to_uri ( $ qname ) ; } catch ( \ Tripod \ Exceptions \ LabellerException $ e ) { } return ( empty ( $ retVal ) ) ? $ qname : $ retVal ; } | If labeller can generate a uri for this qname it will return it . Otherwise just returns the original qname |
28,108 | protected function setSmtpApi ( & $ data , Swift_Mime_SimpleMessage $ message ) { foreach ( $ message -> getChildren ( ) as $ attachment ) { if ( ! $ attachment instanceof Swift_Image || ! in_array ( self :: SMTP_API_NAME , [ $ attachment -> getFilename ( ) , $ attachment -> getContentType ( ) ] ) ) { continue ; } $ data [ 'x-smtpapi' ] = json_encode ( $ attachment -> getBody ( ) ) ; } } | Set Sendgrid SMTP API |
28,109 | public function downloadDrupal7 ( ) { ProcessBuilder :: create ( ) -> setPrefix ( $ this -> drushBin ) -> add ( 'pm-download' ) -> add ( 'drupal-7.38' ) -> add ( '--destination=' . $ this -> workingDir ) -> add ( '--drupal-project-rename' ) -> add ( '--yes' ) -> setTimeout ( 600 ) -> getProcess ( ) -> mustRun ( ) ; } | Downloads Drupal 7 . |
28,110 | public function runServer ( ) { $ router = $ this -> drupalDir . '/.ht.router.php' ; if ( ! file_exists ( $ router ) ) { $ this -> createFile ( $ router , file_get_contents ( __DIR__ . '/.ht.router.php' ) ) ; } $ uri = parse_url ( $ this -> baseUrl ) ; $ this -> serverProcess = ProcessBuilder :: create ( ) -> setPrefix ( 'exec' ) -> add ( $ this -> phpBin ) -> add ( '-S' ) -> add ( sprintf ( '%s:%s' , $ uri [ 'host' ] , $ uri [ 'port' ] ) ) -> add ( $ router ) -> setWorkingDirectory ( $ this -> drupalDir ) -> getProcess ( ) ; $ this -> serverProcess -> start ( ) ; sleep ( 1 ) ; if ( ! $ this -> serverProcess -> isRunning ( ) ) { throw new RuntimeException ( 'PHP built-in server process terminated immediately' ) ; } register_shutdown_function ( [ $ this , 'stopServer' ] ) ; } | Run server . |
28,111 | public function index ( ) { if ( ! $ this -> canCreateForums ( ) ) { return redirect ( ) -> route ( 'laravel-forum.index' ) ; } $ data = $ this -> buildData ( ) ; $ data [ 'counts' ] = [ 'forum' => ( new Forum ) -> getCount ( ) , 'category' => ( new ForumCategory ) -> getCount ( ) , 'post' => ( new ForumPost ) -> getCount ( ) , 'reply' => ( new ForumReply ) -> getCount ( ) , ] ; return view ( 'laravel-forum::admin/index' , $ data ) ; } | Admin index . |
28,112 | protected function queueApplyJob ( array $ subjects , $ queueName , array $ jobOptions ) { $ this -> getApplyOperation ( ) -> createJob ( $ subjects , $ queueName , $ jobOptions ) ; } | Queues a batch of ImpactedSubjects in a single ApplyOperation job |
28,113 | public function cleanupOutputDirectory ( ) { $ directoryIterator = new \ RecursiveDirectoryIterator ( $ this -> outputDirectory , \ RecursiveDirectoryIterator :: SKIP_DOTS ) ; $ filterCallback = function ( \ SplFileInfo $ current ) { $ skipItem = false === strpos ( $ current -> getFilename ( ) , '.gitkeep' ) ? true : false ; return $ skipItem ; } ; $ filteredDirectoryIterator = new \ RecursiveCallbackFilterIterator ( $ directoryIterator , $ filterCallback ) ; $ items = new \ RecursiveIteratorIterator ( $ filteredDirectoryIterator , \ RecursiveIteratorIterator :: CHILD_FIRST ) ; $ this -> fileSystem -> remove ( $ items ) ; } | Delete the generated contents of the output directory |
28,114 | protected function generateClassFiles ( array $ classMap ) { $ backwardsCompatibilityMap = $ this -> getBackwardsCompatibilityMap ( ) ; $ unifiedNamespaceArray = $ this -> getUnifiedNamespaceArray ( $ classMap ) ; $ this -> validateUnifiedNamespaceArray ( $ unifiedNamespaceArray ) ; foreach ( $ unifiedNamespaceArray as $ unifiedSubNamespace => $ editionClassDescriptions ) { $ this -> buildSubNamespace ( $ unifiedSubNamespace , $ editionClassDescriptions , $ backwardsCompatibilityMap ) ; } } | Generate class files for a given class map |
28,115 | protected function getUnifiedNamespaceArray ( array $ classMap ) { $ unifiedNameSpace = [ ] ; foreach ( $ classMap as $ fullyQualifiedUnifiedClass => $ editionClassDescription ) { $ parts = explode ( '\\' , $ fullyQualifiedUnifiedClass ) ; $ shortUnifiedClassName = array_pop ( $ parts ) ; $ this -> validateShortUnifiedClassName ( $ shortUnifiedClassName , $ fullyQualifiedUnifiedClass ) ; $ unifiedSubNamespace = implode ( '\\' , $ parts ) ; $ this -> validateUnifiedNamespace ( $ unifiedSubNamespace , $ fullyQualifiedUnifiedClass ) ; $ this -> validateEditionClassDescription ( $ editionClassDescription ) ; $ unifiedNameSpace [ $ unifiedSubNamespace ] [ ] = [ 'isAbstract' => $ editionClassDescription [ 'isAbstract' ] , 'isInterface' => $ editionClassDescription [ 'isInterface' ] , 'isDeprecated' => $ editionClassDescription [ 'isDeprecated' ] , 'shortUnifiedClassName' => $ shortUnifiedClassName , 'editionClassName' => $ editionClassDescription [ 'editionClassName' ] , ] ; } return $ unifiedNameSpace ; } | Return a map of sub - namespaces and their corresponding classes including metadata |
28,116 | protected function buildSubNamespace ( $ unifiedSubNamespace , array $ editionClassDescriptions , array $ backwardsCompatibilityMap ) { $ unifiedSubNamespacePath = $ this -> createUnifiedNamespaceSubDirectory ( $ unifiedSubNamespace ) ; foreach ( $ editionClassDescriptions as $ editionClassDescription ) { $ filePath = $ unifiedSubNamespacePath . '/' . $ editionClassDescription [ 'shortUnifiedClassName' ] . '.php' ; $ fullyQualifiedUnifiedClass = '\\' . trim ( $ unifiedSubNamespace . '\\' . $ editionClassDescription [ 'shortUnifiedClassName' ] , '\\' ) ; $ backwardsCompatibleClass = null ; $ backwardsCompatibilityMapIndex = trim ( $ fullyQualifiedUnifiedClass , '\\' ) ; if ( array_key_exists ( $ backwardsCompatibilityMapIndex , $ backwardsCompatibilityMap ) ) { $ backwardsCompatibleClass = $ backwardsCompatibilityMap [ $ backwardsCompatibilityMapIndex ] ; } $ content = $ this -> renderContent ( $ unifiedSubNamespace , $ editionClassDescription , $ fullyQualifiedUnifiedClass , $ backwardsCompatibleClass ) ; $ this -> writeFile ( $ filePath , $ content ) ; } } | Delegate rendering of the contents and writing the class files for a given sub - namespace |
28,117 | protected function renderContent ( $ unifiedSubNamespace , $ editionClassDescription , $ fullyQualifiedUnifiedClass , $ backwardsCompatibleClass ) { $ smarty = $ this -> getSmarty ( ) ; $ smarty -> assign ( 'shopEdition' , $ this -> shopEdition ) ; $ smarty -> assign ( 'class' , $ editionClassDescription ) ; $ smarty -> assign ( 'namespace' , $ unifiedSubNamespace ) ; $ smarty -> assign ( 'fullyQualifiedUnifiedClass' , $ fullyQualifiedUnifiedClass ) ; $ smarty -> assign ( 'backwardsCompatibleClass' , $ backwardsCompatibleClass ) ; return $ smarty -> fetch ( 'class_file_template.tpl' ) ; } | Delegate rendering and return the content of a given class file in the unified namespace |
28,118 | protected function writeFile ( $ filePath , $ content ) { $ this -> validateOutputDirectoryPermissions ( ) ; $ currentDirectory = dirname ( $ filePath ) ; if ( ! is_writable ( $ currentDirectory ) ) { throw new \ OxidEsales \ UnifiedNameSpaceGenerator \ Exceptions \ PermissionException ( 'Could not create file ' . $ filePath . ' ' . 'The directory ' . $ currentDirectory . ' is not writable for user "' . get_current_user ( ) . '". ' . 'Please fix the permissions on this directory and run this script again.' , static :: ERROR_CODE_FILE_CREATION_ERROR ) ; } $ fileHandle = fopen ( $ filePath , 'wb' ) ; if ( ! $ fileHandle ) { throw new \ OxidEsales \ UnifiedNameSpaceGenerator \ Exceptions \ FileSystemCompatibilityException ( 'Could not open file file handle for ' . $ filePath . ' ' . 'There might be a problem with your file system. Try to solve this problem and run this script again.' , static :: ERROR_CODE_FILE_CREATION_ERROR ) ; } $ result = fwrite ( $ fileHandle , $ content ) ; if ( false === $ result ) { fclose ( $ fileHandle ) ; throw new \ Exception ( 'Could not create file ' . $ filePath , static :: ERROR_CODE_FILE_CREATION_ERROR ) ; } if ( 0 === $ result ) { fclose ( $ fileHandle ) ; throw new \ Exception ( 'Created empty file ' . $ filePath , static :: ERROR_CODE_FILE_CREATION_ERROR ) ; } fclose ( $ fileHandle ) ; } | Write a given content to a given file path |
28,119 | protected function validateEditionClassDescription ( array $ editionClassDescription ) { $ expectedKeys = [ 'isAbstract' , 'isInterface' , 'editionClassName' , 'isDeprecated' ] ; $ message = 'Edition class description has a wrong layout. ' . 'It must be an non empty array with the following keys ' . implode ( ',' , $ expectedKeys ) . ' ' ; $ code = static :: ERROR_CODE_INVALID_UNIFIED_NAMESPACE_CLASS_MAP_ENTRY ; if ( empty ( $ editionClassDescription ) || ! is_array ( $ editionClassDescription ) ) { throw new \ Exception ( $ message , $ code ) ; } $ actualKeys = array_keys ( $ editionClassDescription ) ; sort ( $ expectedKeys ) ; sort ( $ actualKeys ) ; if ( $ expectedKeys != $ actualKeys ) { $ message .= ' Actual edition class description is ' . var_export ( $ editionClassDescription , true ) ; throw new \ Exception ( $ message , $ code ) ; } } | Validate the layout of the edition class description as defined in the current UnifiedNameSpaceClassMap . php The this script has to be kept in sync with the layout of that file . |
28,120 | protected function validateShopEdition ( $ shopEdition ) { $ expectedShopEditions = [ static :: COMMUNITY_EDITION , static :: PROFESSIONAL_EDITION , static :: ENTERPRISE_EDITION ] ; if ( ! in_array ( $ this -> shopEdition , $ expectedShopEditions ) ) { throw new \ InvalidArgumentException ( 'Parameter $shopEdition has an unexpected value: "' . $ shopEdition . '". ' . 'Expected values are: "' . implode ( ',' , $ expectedShopEditions ) . '". ' , static :: ERROR_CODE_INVALID_SHOP_EDITION ) ; } } | Validate a given shop edition |
28,121 | protected function createUnifiedNamespaceSubDirectory ( $ unifiedSubNamespace ) { $ this -> validateOutputDirectoryPermissions ( ) ; $ unifiedSubNamespacePath = $ this -> outputDirectory . str_replace ( '\\' , DIRECTORY_SEPARATOR , $ unifiedSubNamespace ) ; $ this -> fileSystem -> mkdir ( $ unifiedSubNamespacePath , 0755 ) ; return $ unifiedSubNamespacePath ; } | Create the subdirectory where the files of a given namespace will be written to and return is path |
28,122 | protected function getSmarty ( ) { $ smarty = new \ Smarty ( ) ; $ smarty -> template_dir = realpath ( __DIR__ . DIRECTORY_SEPARATOR . 'smarty' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR ) ; $ smarty -> compile_dir = realpath ( static :: SMARTY_COMPILE_DIR ) ; if ( ! is_dir ( $ smarty -> compile_dir ) || ! is_writable ( $ smarty -> compile_dir ) ) { throw new \ Exception ( 'Smarty compile directory ' . static :: SMARTY_COMPILE_DIR . ' is not writable for user "' . get_current_user ( ) . '". ' . 'Please fix the permissions on this directory' , static :: ERROR_CODE_SMARTY_COMPILE_DIR_PERMISSIONS ) ; } $ smarty -> left_delimiter = '{{' ; $ smarty -> right_delimiter = '}}' ; return $ smarty ; } | Return a configured instance of smarty |
28,123 | public static function set ( string $ key , $ value ) { file_put_contents ( self :: determineDabaseFilePathFor ( $ key ) , Json :: encode ( $ value ) ) ; return $ value ; } | Sets a value for the given key . |
28,124 | public static function get ( string $ key ) { $ encodedValue = @ file_get_contents ( self :: determineDabaseFilePathFor ( $ key ) ) ; if ( $ encodedValue === false ) { return null ; } return Json :: decode ( $ encodedValue ) ; } | Returns the value that was previously set for the given key or null if no value is known . |
28,125 | public static function incr ( string $ key ) { $ currentValue = self :: get ( $ key ) ; return self :: set ( $ key , ( int ) $ currentValue + 1 ) ; } | Increments the value of the value that was previously set for the given key . If no value is known it will assume it to be 0 . It casts non - integer values to an integer if necessary . |
28,126 | public static function extractFile ( Entry $ entry ) { if ( null === self :: $ compression ) { self :: $ compression = array ( 'bzip2' => function_exists ( 'bzdecompress' ) , 'gzip' => function_exists ( 'gzinflate' ) , ) ; } $ reader = $ entry -> getArchive ( ) -> getReader ( ) ; $ reader -> seek ( $ entry -> getOffset ( ) ) ; $ contents = $ reader -> read ( $ entry -> getCompressedSize ( ) ) ; if ( $ entry -> isCompressed ( Entry :: BZ2 ) ) { if ( ! self :: $ compression [ 'bzip2' ] ) { throw FileException :: createUsingFormat ( 'The "bz2" extension is required to decompress "%s".' , $ entry -> getName ( ) ) ; } $ contents = bzdecompress ( $ contents ) ; } elseif ( $ entry -> isCompressed ( Entry :: GZ ) ) { if ( ! self :: $ compression [ 'gzip' ] ) { throw FileException :: createUsingFormat ( 'The "zlib" extension is required to decompress "%s".' , $ entry -> getName ( ) ) ; } $ contents = gzinflate ( $ contents ) ; } return $ contents ; } | Returns the contents of a file from an archive . |
28,127 | public function setAuthorizerAccessToken ( $ token , $ expires = 7200 ) { return $ this -> cache -> save ( $ this -> getAuthorizerAccessTokenKey ( ) , $ token , $ expires ) ; } | Saves the authorizer access token in cache . |
28,128 | public static function createFromAssetsLoader ( AssetsLoader $ loader ) { $ _class = get_called_class ( ) ; return new $ _class ( $ loader -> getRootDirectory ( ) , $ loader -> getAssetsDirectory ( ) , $ loader -> getVendorDirectory ( ) , $ loader -> getAssetsVendorDirectory ( ) ) ; } | Create a new instance from an AssetsManager \ Loader instance |
28,129 | public function loadFromArray ( array $ entries ) { foreach ( $ entries as $ var => $ val ) { switch ( $ var ) { case 'name' : $ this -> setName ( $ val ) ; break ; case 'version' : $ this -> setVersion ( $ val ) ; break ; case 'relative_path' : $ this -> setRelativePath ( $ val ) ; break ; case 'assets_path' : case 'path' : $ this -> setAssetsPath ( $ val ) ; break ; case 'assets_presets' : $ this -> setAssetsPresets ( $ val ) ; break ; } } return $ this ; } | Load a new package from the ASSETS_DB_FILENAME entry |
28,130 | public static function languageNames ( $ codes = null ) { $ list = [ ] ; $ codes = $ codes ? : static :: codes ( ) ; foreach ( $ codes as $ code ) { $ list [ $ code ] = static :: languageName ( $ code ) ; } return $ list ; } | Returns list of language names in the each language |
28,131 | public static function localeNames ( $ codes , $ in_code = null ) { $ list = [ ] ; $ codes = $ codes ? : static :: codes ( ) ; foreach ( $ codes as $ code ) { $ list [ $ code ] = static :: localeName ( $ code , $ in_code ) ; } return $ list ; } | Returns list of locale language names in a locale |
28,132 | public static function countryLanguageCodes ( $ countryCode ) { $ localeCodes = Locale :: countryLocaleCodes ( $ countryCode ) ; $ list = [ ] ; foreach ( $ localeCodes as $ localeCode ) { $ list [ ] = Locale :: languageCode ( $ localeCode ) ; } return $ list ; } | Returns list of country ISO 639 - 1 language codes |
28,133 | public function perform ( ) { $ this -> debugLog ( 'Ensuring indexes for tenant=' . $ this -> args [ self :: STORENAME_KEY ] . ', reindex=' . $ this -> args [ self :: REINDEX_KEY ] . ', background=' . $ this -> args [ self :: BACKGROUND_KEY ] ) ; $ this -> getIndexUtils ( ) -> ensureIndexes ( $ this -> args [ self :: REINDEX_KEY ] , $ this -> args [ self :: STORENAME_KEY ] , $ this -> args [ self :: BACKGROUND_KEY ] ) ; } | Runs the EnsureIndexes Job |
28,134 | public function createJob ( $ storeName , $ reindex , $ background , $ queueName = null ) { $ configInstance = $ this -> getConfigInstance ( ) ; if ( ! $ queueName ) { $ queueName = $ configInstance :: getEnsureIndexesQueueName ( ) ; } elseif ( strpos ( $ queueName , $ configInstance :: getEnsureIndexesQueueName ( ) ) === false ) { $ queueName = $ configInstance :: getEnsureIndexesQueueName ( ) . '::' . $ queueName ; } $ data = [ self :: STORENAME_KEY => $ storeName , self :: REINDEX_KEY => $ reindex , self :: BACKGROUND_KEY => $ background ] ; $ this -> submitJob ( $ queueName , get_class ( $ this ) , array_merge ( $ data , $ this -> generateConfigJobArgs ( ) ) ) ; } | This method is use to schedule an EnsureIndexes job . |
28,135 | public static function countryContinentCode ( $ countryCode ) { foreach ( static :: CODES as $ code => $ countryCodes ) { if ( in_array ( $ countryCode , $ countryCodes ) ) { return $ code ; } } return null ; } | Returns continent code by ISO 3166 - 1 alpha - 2 country code . |
28,136 | public static function fromName ( string $ name ) : self { $ oid = self :: attrNameToOID ( $ name ) ; return new self ( $ oid ) ; } | Initialize from attribute name . |
28,137 | public function typeName ( ) : string { if ( array_key_exists ( $ this -> _oid , self :: MAP_OID_TO_NAME ) ) { return self :: MAP_OID_TO_NAME [ $ this -> _oid ] [ 0 ] ; } return $ this -> _oid ; } | Get name of the attribute . |
28,138 | private static function _oidReverseMap ( ) : array { static $ map ; if ( ! isset ( $ map ) ) { $ map = array ( ) ; foreach ( self :: MAP_OID_TO_NAME as $ oid => $ names ) { foreach ( $ names as $ name ) { $ map [ strtolower ( $ name ) ] = $ oid ; } } } return $ map ; } | Get name to OID lookup map . |
28,139 | public static function attrNameToOID ( string $ name ) : string { if ( preg_match ( '/^[0-9]+(?:\.[0-9]+)*$/' , $ name ) ) { return $ name ; } $ map = self :: _oidReverseMap ( ) ; $ k = strtolower ( $ name ) ; if ( ! isset ( $ map [ $ k ] ) ) { throw new \ OutOfBoundsException ( "No OID for $name." ) ; } return $ map [ $ k ] ; } | Convert attribute name to OID . |
28,140 | public static function asn1StringForType ( string $ oid , string $ str ) : StringType { if ( ! array_key_exists ( $ oid , self :: MAP_ATTR_TO_STR_TYPE ) ) { return new UTF8String ( $ str ) ; } switch ( self :: MAP_ATTR_TO_STR_TYPE [ $ oid ] ) { case Element :: TYPE_PRINTABLE_STRING : return new PrintableString ( $ str ) ; default : throw new \ LogicException ( ) ; } } | Get ASN . 1 string for given attribute type . |
28,141 | public function updateSnapshot ( ) { $ zoneSettings = $ this -> get ( 'zoneCheck' , [ 'zones' => $ this -> zone ] ) ; $ zid = ( int ) array_get ( $ zoneSettings , 'response.zones' ) [ $ this -> zone ] ; $ this -> action ( 'zoneGrab' , [ 'zid' => $ zid ] , false ) ; return $ this ; } | Updated the site snapshot on the challenge page . |
28,142 | public function ips ( $ hours = 24 , $ class = null ) { $ zoneIps = $ this -> get ( 'zoneIps' , $ this -> data ( compact ( 'hours' , 'class' ) ) , $ hours . $ class ) ; $ ips = array_get ( $ zoneIps , 'response.ips' ) ; $ all = new Collection ( ) ; foreach ( $ ips as $ ip ) { $ name = $ ip [ 'ip' ] ; $ zoneIp = new ZoneIP ( $ this -> client , $ name , $ this , [ 'zoneIp' => $ ip ] ) ; $ all -> put ( $ name , $ zoneIp ) ; } return $ all ; } | Get all ips as a collection of models . |
28,143 | public function ip ( $ address , $ hours = 24 , $ class = null ) { $ zoneIps = $ this -> get ( 'zoneIps' , $ this -> data ( compact ( 'hours' , 'class' ) ) , $ hours . $ class ) ; $ ips = array_get ( $ zoneIps , 'response.ips' ) ; foreach ( $ ips as $ ip ) { if ( $ ip [ 'ip' ] == $ address ) { return new ZoneIP ( $ this -> client , $ address , $ this , [ 'zoneIp' => $ ip ] ) ; } } } | Get an ip as a model . |
28,144 | public function records ( ) { $ recs = $ this -> get ( 'recLoadAll' ) ; $ records = array_get ( $ recs , 'response.recs.objs' ) ; $ all = new Collection ( ) ; foreach ( $ records as $ record ) { $ id = ( int ) $ record [ 'rec_id' ] ; $ model = new Record ( $ this -> client , $ id , $ this , [ 'recLoad' => $ record ] ) ; $ all -> put ( $ id , $ model ) ; } return $ all ; } | Get all dns records as a collection of models . |
28,145 | public function record ( $ id ) { $ recs = $ this -> get ( 'recLoadAll' ) ; $ records = array_get ( $ recs , 'response.recs.objs' ) ; foreach ( $ records as $ record ) { if ( ( int ) $ record [ 'rec_id' ] === ( int ) $ id ) { return new Record ( $ this -> client , ( int ) $ id , $ this , [ 'recLoad' => $ record ] ) ; } } } | Get a dns record as a model . |
28,146 | protected function stat ( $ time , $ name ) { $ stats = $ this -> get ( 'stats' , [ 'interval' => $ time ] , ( string ) $ time ) ; return array_get ( $ stats , 'response.result.objs.0.' . $ name ) ; } | Lookup a statistic . |
28,147 | public function play_turn ( $ turn ) { $ directions = [ 'forward' , 'left' , 'right' , 'backward' ] ; foreach ( $ directions as $ direction ) { if ( $ turn -> feel ( $ direction ) -> is_player ( ) ) { $ turn -> attack ( $ direction ) ; return ; } } } | Play your turn . |
28,148 | public function setToken ( $ token , $ expires = 7200 ) { $ this -> getCache ( ) -> save ( $ this -> getCacheKey ( ) , $ token , $ expires - 1500 ) ; return $ this ; } | Set custom token . |
28,149 | public function is_out_of_bounds ( $ x , $ y ) { return ( $ x < 0 || $ y < 0 || $ x > ( $ this -> width - 1 ) || $ y > ( $ this -> height - 1 ) ) ; } | Is it out of bounds? |
28,150 | public function unique_units ( ) { $ unique_units = [ ] ; foreach ( $ this -> units as $ u ) { $ unique_units [ ( string ) $ u ] = $ u ; } return $ unique_units ; } | Get the unique units . |
28,151 | public function setArguments ( Arguments $ args ) { if ( $ this -> isUpdating ( ) ) { throw BuilderException :: isUpdating ( ) ; } $ this -> arguments = $ args ; } | Sets the method arguments to be used for an observer update . |
28,152 | public function doAddMockData ( $ data , $ form ) { $ this -> owner -> record -> fill ( array ( 'only_empty' => true , 'include_relations' => false , 'download_images' => false ) ) ; Controller :: curr ( ) -> getResponse ( ) -> addHeader ( "X-Pjax" , "Content" ) ; $ link = Controller :: join_links ( $ this -> owner -> gridField -> Link ( ) , "item" , $ this -> owner -> record -> ID ) ; return Controller :: curr ( ) -> redirect ( $ link ) ; } | A form action that handles populating the record with mock data |
28,153 | public function retrieve ( string $ id ) { $ data = $ this -> retrieveAll ( ) ; if ( ! array_key_exists ( $ id , $ data ) ) { throw new \ RuntimeException ( sprintf ( 'Unable to load object of type "%s" with ID "%s"' , $ this -> className , $ id ) ) ; } $ object = $ data [ $ id ] ; Assertion :: isInstanceOf ( $ object , $ this -> className ) ; return $ object ; } | Provide an id and you will retrieve the unserialized version of a previously persisted object . |
28,154 | private function loadAllObjects ( ) : array { if ( ! file_exists ( $ this -> databaseFilePath ) ) { return [ ] ; } $ objects = Serializer :: deserialize ( "{$this->className}[]" , file_get_contents ( $ this -> databaseFilePath ) ) ; Assertion :: allIsInstanceOf ( $ objects , $ this -> className ) ; return $ objects ; } | Load all previously persisted objects from disk . |
28,155 | private function saveAllObjects ( array $ allData ) : void { $ fileSaved = @ file_put_contents ( $ this -> databaseFilePath , Serializer :: serialize ( $ allData ) ) ; if ( $ fileSaved === false ) { throw new \ RuntimeException ( sprintf ( 'Failed to save file "%s"' , $ this -> databaseFilePath ) ) ; } } | Save all objects in the given array to disk . |
28,156 | public function cancelTransaction ( $ transaction_id , \ Exception $ error = null ) { $ params = array ( 'status' => 'cancelling' ) ; if ( $ error != null ) { $ params [ 'error' ] = array ( 'reason' => $ error -> getMessage ( ) , 'trace' => $ error -> getTraceAsString ( ) ) ; } $ this -> updateTransaction ( array ( "_id" => $ transaction_id ) , array ( '$set' => $ params ) , array ( "w" => 1 , 'upsert' => true ) ) ; } | Updates the status of a transaction to cancelling . If you passed in an Exception the exception is logged in the transaction log . |
28,157 | public function failTransaction ( $ transaction_id , \ Exception $ error = null ) { $ params = array ( 'status' => 'failed' , 'failedTime' => \ Tripod \ Mongo \ DateUtil :: getMongoDate ( ) ) ; if ( $ error != null ) { $ params [ 'error' ] = array ( 'reason' => $ error -> getMessage ( ) , 'trace' => $ error -> getTraceAsString ( ) ) ; } $ this -> updateTransaction ( array ( "_id" => $ transaction_id ) , array ( '$set' => $ params ) , array ( 'w' => 1 , 'upsert' => true ) ) ; } | Updates the status of a transaction to failed and adds a fail time . If you passed in an Exception the exception is logged in the transaction log |
28,158 | public function completeTransaction ( $ transaction_id , Array $ newCBDs ) { $ this -> updateTransaction ( array ( "_id" => $ transaction_id ) , array ( '$set' => array ( 'status' => 'completed' , 'endTime' => \ Tripod \ Mongo \ DateUtil :: getMongoDate ( ) , 'newCBDs' => $ newCBDs ) ) , array ( 'w' => 1 ) ) ; } | Update the status of a transaction to completed and adds an end time |
28,159 | protected function updateTransaction ( $ query , $ update , $ options ) { return $ this -> transaction_collection -> updateOne ( $ query , $ update , $ options ) ; } | Proxy method to help with test mocking |
28,160 | public function preSetData ( FormEvent $ event ) { $ entity = $ event -> getData ( ) ; if ( $ entity instanceof ImageInterface && null !== $ entity -> getId ( ) ) { try { $ this -> imageManager -> copyImagesToTemporaryDirectory ( $ entity ) ; } catch ( \ Gaufrette \ Exception \ FileNotFound $ e ) { $ event -> setData ( null ) ; } } } | Copy image to temporary directory |
28,161 | public static function fromString ( string $ str ) : self { $ rdns = array ( ) ; foreach ( DNParser :: parseString ( $ str ) as $ nameComponent ) { $ attribs = array ( ) ; foreach ( $ nameComponent as list ( $ name , $ val ) ) { $ type = AttributeType :: fromName ( $ name ) ; if ( $ val instanceof Element ) { $ el = $ val ; } else { $ el = AttributeType :: asn1StringForType ( $ type -> oid ( ) , $ val ) ; } $ value = AttributeValue :: fromASN1ByOID ( $ type -> oid ( ) , $ el -> asUnspecified ( ) ) ; $ attribs [ ] = new AttributeTypeAndValue ( $ type , $ value ) ; } $ rdns [ ] = new RDN ( ... $ attribs ) ; } return new self ( ... $ rdns ) ; } | Initialize from distinguished name string . |
28,162 | public function toString ( ) : string { $ parts = array_map ( function ( RDN $ rdn ) { return $ rdn -> toString ( ) ; } , array_reverse ( $ this -> _rdns ) ) ; return implode ( "," , $ parts ) ; } | Get distinguised name string conforming to RFC 2253 . |
28,163 | public function equals ( Name $ other ) : bool { if ( count ( $ this ) != count ( $ other ) ) { return false ; } for ( $ i = count ( $ this ) - 1 ; $ i >= 0 ; -- $ i ) { $ rdn1 = $ this -> _rdns [ $ i ] ; $ rdn2 = $ other -> _rdns [ $ i ] ; if ( ! $ rdn1 -> equals ( $ rdn2 ) ) { return false ; } } return true ; } | Whether name is semantically equal to other . Comparison conforms to RFC 4518 string preparation algorithm . |
28,164 | public function firstValueOf ( string $ name ) : AttributeValue { $ oid = AttributeType :: attrNameToOID ( $ name ) ; foreach ( $ this -> _rdns as $ rdn ) { $ tvs = $ rdn -> allOf ( $ oid ) ; if ( count ( $ tvs ) > 1 ) { throw new \ RangeException ( "RDN with multiple $name attributes." ) ; } if ( 1 == count ( $ tvs ) ) { return $ tvs [ 0 ] -> value ( ) ; } } throw new \ RangeException ( "Attribute $name not found." ) ; } | Get the first AttributeValue of given type . |
28,165 | public function countOfType ( string $ name ) : int { $ oid = AttributeType :: attrNameToOID ( $ name ) ; return array_sum ( array_map ( function ( RDN $ rdn ) use ( $ oid ) { return count ( $ rdn -> allOf ( $ oid ) ) ; } , $ this -> _rdns ) ) ; } | Get the number of attributes of given type . |
28,166 | public function qname_to_uri ( $ qname ) { if ( preg_match ( "~^(.+):(.+)$~" , $ qname , $ m ) ) { if ( isset ( $ this -> _ns [ $ m [ 1 ] ] ) ) { return $ this -> _ns [ $ m [ 1 ] ] . $ m [ 2 ] ; } } return null ; } | Convert a QName to a URI using registered namespace prefixes |
28,167 | public function uri_to_qname ( $ uri ) { if ( preg_match ( '~^(.*[\/\#])([a-z0-9\-\_\:]+)$~i' , $ uri , $ m ) ) { $ ns = $ m [ 1 ] ; $ localname = $ m [ 2 ] ; $ prefix = $ this -> get_prefix ( $ ns ) ; if ( $ prefix != null && $ prefix !== FALSE ) { return $ prefix . ':' . $ localname ; } } return null ; } | Convert a URI to a QName using registered namespace prefixes |
28,168 | public function equals ( AttributeTypeAndValue $ other ) : bool { if ( $ this -> oid ( ) !== $ other -> oid ( ) ) { return false ; } $ matcher = $ this -> _value -> equalityMatchingRule ( ) ; $ result = $ matcher -> compare ( $ this -> _value -> stringValue ( ) , $ other -> _value -> stringValue ( ) ) ; if ( $ result ) { return true ; } return false ; } | Check whether attribute is semantically equal to other . |
28,169 | public function postSetData ( FormEvent $ event ) { $ collection = $ event -> getData ( ) ; $ form = $ event -> getForm ( ) ; if ( $ collection instanceof PersistentCollection ) { foreach ( $ collection as $ key => $ file ) { if ( $ file instanceof MultiFileInterface ) { try { $ this -> fileManager -> copyFileToTemporaryDirectory ( $ file ) ; } catch ( \ Gaufrette \ Exception \ FileNotFound $ e ) { $ form -> remove ( $ key ) ; $ collection -> removeElement ( $ file ) ; } } } } } | Copy file from permenent to temporary directory |
28,170 | public function postSubmit ( FormEvent $ event ) { $ collection = $ event -> getData ( ) ; if ( $ collection instanceof PersistentCollection ) { foreach ( $ collection -> getDeleteDiff ( ) as $ entity ) { if ( $ entity instanceof MultiFileInterface ) { $ this -> om -> remove ( $ entity ) ; } } } } | Remove deleted files |
28,171 | public function setRootDirectory ( $ path ) { if ( @ file_exists ( $ path ) && is_dir ( $ path ) ) { $ this -> _root_dir = $ path ; } else { throw new InvalidArgumentException ( sprintf ( 'Root package directory "%s" not found !' , $ path ) ) ; } return $ this ; } | Set the project root directory absolute path |
28,172 | public function getFullPath ( $ path , $ type = null , $ out = false ) { if ( @ file_exists ( $ path ) ) { return realpath ( $ path ) ; } $ base = DirectoryHelper :: slashDirname ( $ this -> getRootDirectory ( ) ) ; if ( in_array ( $ type , array ( 'asset' , 'assets' ) ) ) { $ base .= DirectoryHelper :: slashDirname ( $ this -> getAssetsDirectory ( ) ) ; } elseif ( $ type === 'vendor' ) { $ base .= DirectoryHelper :: slashDirname ( $ this -> getVendorDirectory ( ) ) ; } elseif ( $ type === 'assets_vendor' ) { $ base .= DirectoryHelper :: slashDirname ( $ this -> getAssetsDirectory ( ) ) . DirectoryHelper :: slashDirname ( $ this -> getAssetsVendorDirectory ( ) ) ; } $ f = $ base . $ path ; if ( @ file_exists ( $ f ) ) { return $ f ; } if ( $ out ) { return null ; } if ( ! in_array ( $ type , array ( 'asset' , 'assets' ) ) ) { $ f = $ this -> getFullPath ( $ path , 'asset' , true ) ; if ( @ file_exists ( $ f ) ) { return $ f ; } } if ( $ type !== 'vendor' ) { $ f = $ this -> getFullPath ( $ path , 'vendor' , true ) ; if ( @ file_exists ( $ f ) ) { return $ f ; } } } | Get the absolute path in the package |
28,173 | public static function flag ( string $ country , string $ size = 'medium' ) : string { $ sizes = [ 'small' => 100 , 'medium' => 250 , 'big' => 1000 , ] ; $ code = $ country ; if ( strlen ( $ country ) > 2 ) { $ code = static :: countryAlpha2 ( $ country ) ; } $ code = strtolower ( $ code ) ; if ( $ code === 'unknown' ) { $ flag = __DIR__ . "/../Assets/country-flags/Unknown.png" ; } else { $ flag = __DIR__ . "/../Assets/country-flags/png{$sizes[$size]}px/{$code}.png" ; } $ cache_key = "support__flag:{$code}_{$size}" ; if ( ! Cache :: has ( $ cache_key ) ) { $ image = Image :: make ( $ flag ) -> resize ( $ sizes [ $ size ] , bcmul ( $ sizes [ $ size ] , 0.6 , 2 ) ) -> encode ( 'data-url' ) ; Cache :: put ( $ cache_key , $ image ) ; return $ image ; } return Cache :: get ( $ cache_key ) ; } | Returns the country image . |
28,174 | public static function countryAlpha2 ( string $ country ) : string { $ alpha2 = static :: simpleCountries ( ) -> filter ( function ( $ c ) use ( $ country ) { return $ c === $ country ; } ) -> keys ( ) -> first ( ) ; return $ alpha2 ? $ alpha2 : 'Unknown' ; } | Returns the country alpha2 ISO code . |
28,175 | public static function country ( string $ country , string $ accessor , string $ only_accessor = null ) : Collection { $ country = strtolower ( $ country ) ; $ accessor = strtolower ( $ accessor ) ; $ file = __DIR__ . "/../Assets/topojson/countries/{$country}/{$country}-{$accessor}.json" ; if ( ! file_exists ( $ file ) ) { return Collection :: make ( [ ] ) ; } $ json = json_decode ( file_get_contents ( $ file ) , true ) [ 'objects' ] ; $ key = array_keys ( $ json ) [ 0 ] ; return Collection :: make ( $ json [ $ key ] [ 'geometries' ] ) -> map ( function ( $ country ) use ( $ only_accessor ) { if ( $ only_accessor ) { return $ country [ 'properties' ] [ $ only_accessor ] ; } return $ country [ 'properties' ] ; } ) ; } | Return the country information based on the accessor . |
28,176 | public static function countries ( string $ continent = null , bool $ only_names = false ) : Collection { if ( ! $ continent ) { return static :: getWorldContries ( $ only_names ) ; } $ file = __DIR__ . "/../Assets/topojson/continents/{$continent}.json" ; if ( ! file_exists ( $ file ) ) { return Collection :: make ( [ ] ) ; } $ countries = Collection :: make ( json_decode ( file_get_contents ( $ file ) , true ) [ 'objects' ] [ 'continent_' . ucfirst ( $ country ) . '_subunits' ] [ 'geometries' ] ) -> map ( function ( $ country ) { return $ country [ 'properties' ] ; } ) ; if ( $ only_names ) { $ countries = $ countries -> map ( function ( $ country ) { return $ country [ 'geounit' ] ; } ) ; } return $ countries ; } | Return the countries of the given continent . |
28,177 | protected static function getWorldContries ( $ only_names = false ) : Collection { $ file = __DIR__ . "/../Assets/topojson/world-countries.json" ; return Collection :: make ( json_decode ( file_get_contents ( $ file ) , true ) [ 'objects' ] [ 'countries1' ] [ 'geometries' ] ) -> map ( function ( $ country ) use ( $ only_names ) { if ( $ only_names ) { return $ country [ 'properties' ] [ 'name' ] ; } return $ country [ 'properties' ] ; } ) ; } | Return the all world countries . |
28,178 | public static function continents ( ) : Collection { $ file = __DIR__ . "/../Assets/topojson/world-continents.json" ; return Collection :: make ( json_decode ( file_get_contents ( $ file ) , true ) [ 'objects' ] [ 'continent' ] [ 'geometries' ] ) -> map ( function ( $ continent ) { return $ continent [ 'properties' ] [ 'continent' ] ; } ) ; } | Return the world continents . |
28,179 | public static function findOffset ( Reader $ reader ) { $ reader -> seek ( 0 ) ; $ offset = 0 ; while ( ! $ reader -> isEndOfFile ( ) ) { if ( strtolower ( $ reader -> read ( 1 ) ) === self :: $ sequence [ $ offset ] ) { $ offset ++ ; } else { $ offset = 0 ; } if ( ! isset ( self :: $ sequence [ $ offset + 1 ] ) ) { break ; } } $ reader -> seek ( 1 , SEEK_CUR ) ; if ( $ offset === ( count ( self :: $ sequence ) - 1 ) ) { $ position = $ reader -> getPosition ( ) ; if ( "\r\n" === $ reader -> read ( 2 ) ) { return $ position + 2 ; } return $ position ; } return null ; } | Finds the data offset of an archive . |
28,180 | public function getApiVersion ( ) { $ this -> reader -> seek ( $ this -> offset + 8 ) ; $ version = unpack ( 'H*' , $ this -> reader -> read ( 2 ) ) ; $ version = hexdec ( $ version [ 1 ] ) ; $ version = sprintf ( '%u.%u.%u' , $ version >> 12 , ( $ version >> 8 ) & 0xF , ( $ version >> 4 ) & 0xF ) ; return $ version ; } | Returns the version of the archive file format . |
28,181 | public function getEntries ( ) { $ count = $ this -> getEntryCount ( ) ; $ size = $ this -> getManifestSize ( ) + 4 ; $ this -> reader -> seek ( $ this -> offset + 18 + $ this -> getAliasSize ( ) + 4 + $ this -> getMetadataSize ( ) ) ; return $ this -> readFileList ( $ count , $ size ) ; } | Returns the list of entries in manifest for this archive . |
28,182 | public function getGlobalFlags ( ) { $ this -> reader -> seek ( $ this -> offset + 10 ) ; return $ this -> readLong ( ) & self :: MASK ; } | Returns the global bitmapped flags for this archive . |
28,183 | public function getMetadataSize ( ) { $ this -> reader -> seek ( $ this -> offset + 18 + $ this -> getAliasSize ( ) ) ; return $ this -> readLong ( ) ; } | Returns the size of metadata in this archive in bytes . |
28,184 | private function readLong ( ) { $ long = unpack ( 'V' , $ this -> reader -> read ( 4 ) ) ; $ long = ( int ) $ long [ 1 ] ; return $ long ; } | Reads and unpacks an unsigned long . |
28,185 | public function fromArray ( array $ values ) { foreach ( $ values as $ property => $ value ) { $ this -> __set ( $ property , $ value ) ; } return $ this ; } | Metoda wypelniajaca obiekt na podstawie tablicy |
28,186 | public function generateDownloadUrl ( FileInterface $ file ) { return $ this -> container -> get ( 'router' ) -> generate ( 'thrace_media_file_download' , array ( 'filepath' => $ file -> getFilePath ( ) , 'filename' => $ file -> getOriginalName ( ) ) , true ) ; } | Return download url |
28,187 | public function make ( array $ config ) { $ client = $ this -> createClient ( $ config ) ; $ zone = new ZoneRepository ( $ client ) ; $ ip = new IpRepository ( $ client ) ; return new CloudFlareAPI ( $ zone , $ ip ) ; } | Make a new api instance . |
28,188 | public static function getBetween ( string $ var1 , string $ var2 , string $ pool ) : string { $ temp1 = strpos ( $ pool , $ var1 ) + strlen ( $ var1 ) ; $ result = substr ( $ pool , $ temp1 , strlen ( $ pool ) ) ; $ dd = strpos ( $ result , $ var2 ) ; if ( $ dd == 0 ) { $ dd = strlen ( $ result ) ; } return substr ( $ result , 0 , $ dd ) ; } | Get a string between two substrings . |
28,189 | public static function randomString ( int $ length = 10 , string $ letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ) : string { return substr ( str_shuffle ( str_repeat ( $ x = $ letters , ceil ( $ length / strlen ( $ x ) ) ) ) , 1 , $ length ) ; } | Return a random string . |
28,190 | public static function getInstance ( $ root_dir = null , $ assets_dir = null , $ document_root = null , $ conflict_flag = self :: PRESETS_CONFLICT ) { if ( empty ( self :: $ __instance ) ) { $ cls = get_called_class ( ) ; self :: $ __isStaticInstance = true ; self :: $ __instance = new $ cls ( $ root_dir , $ assets_dir , $ document_root , $ conflict_flag ) ; } return self :: $ __instance ; } | Loader static instance constructor |
28,191 | public function init ( $ root_dir = null , $ assets_dir = null , $ document_root = null ) { try { $ this -> setRootDirectory ( ! is_null ( $ root_dir ) ? $ root_dir : __DIR__ . '/../../../../../' ) ; $ composer = $ this -> getRootDirectory ( ) . '/' . Config :: getInternal ( 'composer-db' ) ; $ vendor_dir = Config :: get ( 'vendor-dir' ) ; if ( file_exists ( $ composer ) ) { $ json_package = json_decode ( file_get_contents ( $ composer ) , true ) ; if ( isset ( $ json_package [ 'config' ] ) && isset ( $ json_package [ 'config' ] [ 'vendor-dir' ] ) ) { $ vendor_dir = $ json_package [ 'config' ] [ 'vendor-dir' ] ; } } else { throw new \ Exception ( sprintf ( 'Composer json "%s" not found!' , $ composer ) ) ; } $ this -> setVendorDirectory ( $ vendor_dir ) ; $ extra = isset ( $ json_package [ 'extra' ] ) ? $ json_package [ 'extra' ] : array ( ) ; if ( isset ( $ extra [ 'assets-config-class' ] ) ) { Config :: load ( $ extra [ 'assets-config-class' ] ) ; } if ( ! empty ( $ extra ) ) { Config :: overload ( $ extra ) ; } $ assets_db_filename = isset ( $ extra [ 'assets-db-filename' ] ) ? $ extra [ 'assets-db-filename' ] : Config :: get ( 'assets-db-filename' ) ; $ db_file = $ this -> getRootDirectory ( ) . '/' . $ this -> getVendorDirectory ( ) . '/' . $ assets_db_filename ; if ( file_exists ( $ db_file ) ) { $ json_assets = json_decode ( file_get_contents ( $ db_file ) , true ) ; $ this -> setAssetsDirectory ( ! is_null ( $ assets_dir ) ? $ assets_dir : ( isset ( $ json_assets [ 'assets_dir' ] ) ? $ json_assets [ 'assets_dir' ] : Config :: get ( 'assets-dir' ) ) ) -> setAssetsVendorDirectory ( isset ( $ json_assets [ 'assets_vendor_dir' ] ) ? $ json_assets [ 'assets_vendor_dir' ] : Config :: get ( 'assets-vendor-dir' ) ) -> setDocumentRoot ( ! is_null ( $ document_root ) ? $ document_root : ( isset ( $ json_assets [ 'document_root' ] ) ? $ json_assets [ 'document_root' ] : Config :: get ( 'document-root' ) ) ) -> setAssetsDb ( ! empty ( $ json_assets [ 'packages' ] ) ? $ json_assets [ 'packages' ] : array ( ) ) ; } else { throw new \ Exception ( sprintf ( 'Assets json DB "%s" not found!' , $ db_file ) ) ; } $ this -> validatePresets ( ) ; } catch ( \ Exception $ e ) { throw $ e ; } } | Initializing a new loader populating all paths & packages |
28,192 | public function setDocumentRoot ( $ path ) { if ( file_exists ( $ path ) ) { $ this -> document_root = realpath ( $ path ) ; } elseif ( file_exists ( DirectoryHelper :: slashDirname ( $ this -> getRootDirectory ( ) ) . $ path ) ) { $ this -> document_root = DirectoryHelper :: slashDirname ( $ this -> getRootDirectory ( ) ) . $ path ; } else { throw new \ InvalidArgumentException ( sprintf ( 'Document root path "%s" doesn\'t exist!' , $ path ) ) ; } return $ this ; } | Set the document root directory |
28,193 | public function setAssetsDb ( array $ db ) { foreach ( $ db as $ package_name => $ package ) { if ( empty ( $ package [ 'path' ] ) && isset ( $ package [ 'relative_path' ] ) ) { $ db [ $ package_name ] [ 'path' ] = DirectoryHelper :: slashDirname ( DirectoryHelper :: slashDirname ( $ this -> getRootDirectory ( ) ) . DirectoryHelper :: slashDirname ( $ this -> getAssetsDirectory ( ) ) . DirectoryHelper :: slashDirname ( $ this -> getAssetsVendorDirectory ( ) ) . $ package [ 'relative_path' ] ) ; } } $ this -> assets_db = $ db ; return $ this ; } | Set the package s assets database |
28,194 | public function getPackageAssetsWebPath ( $ package_name ) { $ package = $ this -> getPackage ( $ package_name ) ; return $ this -> buildWebPath ( $ package -> getAssetsPath ( ) ) ; } | Get the web path for assets of a specific package |
28,195 | public function hasPackage ( $ package_name ) { if ( ! isset ( $ this -> packages_instances [ $ package_name ] ) ) { try { $ this -> packages_instances [ $ package_name ] = $ this -> _buildNewPackage ( $ package_name ) ; } catch ( \ Exception $ e ) { } } return isset ( $ this -> packages_instances [ $ package_name ] ) ; } | Test if a package exists |
28,196 | public function getPackage ( $ package_name ) { if ( ! isset ( $ this -> packages_instances [ $ package_name ] ) ) { try { $ this -> packages_instances [ $ package_name ] = $ this -> _buildNewPackage ( $ package_name ) ; } catch ( \ Exception $ e ) { throw $ e ; } } return $ this -> packages_instances [ $ package_name ] ; } | Get a package instance |
28,197 | protected function _buildNewPackage ( $ package_name ) { $ package = isset ( $ this -> assets_db [ $ package_name ] ) ? $ this -> assets_db [ $ package_name ] : null ; if ( ! empty ( $ package ) ) { $ cls_name = Config :: get ( 'assets-package-class' ) ; if ( @ class_exists ( $ cls_name ) ) { $ interfaces = class_implements ( $ cls_name ) ; $ config_interface = Config :: getInternal ( 'assets-package-interface' ) ; if ( in_array ( $ config_interface , $ interfaces ) ) { $ package_object = $ cls_name :: createFromAssetsLoader ( $ this ) ; $ package_object -> loadFromArray ( $ package ) ; return $ package_object ; } else { throw new \ DomainException ( sprintf ( 'Package class "%s" must implement interface "%s"!' , $ cls_name , $ config_interface ) ) ; } } else { throw new \ DomainException ( sprintf ( 'Package class "%s" not found!' , $ cls_name ) ) ; } } else { throw new \ InvalidArgumentException ( sprintf ( 'Unknown package "%s"!' , $ package_name ) ) ; } return null ; } | Build a new package instance |
28,198 | public function validatePresets ( ) { $ this -> presets_data = array ( ) ; if ( ! empty ( $ this -> assets_db ) ) { foreach ( $ this -> assets_db as $ package_name => $ package_data ) { if ( ! empty ( $ package_data [ 'assets_presets' ] ) ) { foreach ( $ package_data [ 'assets_presets' ] as $ preset_name => $ preset_data ) { if ( array_key_exists ( $ preset_name , $ this -> presets_data ) && ( $ this -> conflict_flag & self :: PRESETS_CONFLICT ) ) { throw new \ Exception ( sprintf ( 'Presets conflict: duplicate entry named "%s"!' , $ preset_name ) ) ; } else { $ this -> presets_data [ $ preset_name ] = array ( 'data' => $ preset_data , 'package' => $ package_name ) ; } } } } } } | Load and validate all packages presets in one table |
28,199 | public function getPreset ( $ preset_name ) { if ( isset ( $ this -> presets_data [ $ preset_name ] ) ) { if ( ! isset ( $ this -> presets_data [ $ preset_name ] [ 'instance' ] ) ) { try { $ this -> presets_data [ $ preset_name ] [ 'instance' ] = $ this -> _buildNewPreset ( $ preset_name ) ; } catch ( \ Exception $ e ) { throw $ e ; } } return $ this -> presets_data [ $ preset_name ] [ 'instance' ] ; } else { throw new \ InvalidArgumentException ( sprintf ( 'Preset "%s" not found!' , $ preset_name ) ) ; } } | Get a preset instance |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.