idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
19,200
private function traverseObject ( $ obj , $ keys ) { if ( empty ( $ keys ) ) { return $ obj ; } $ key = current ( $ keys ) ; if ( is_array ( $ obj ) && isset ( $ obj [ $ key ] ) ) { return $ this -> traverseObject ( $ obj [ $ key ] , array_slice ( $ keys , 1 ) ) ; } else if ( is_object ( $ obj ) && isset ( $ obj -> { $ key } ) ) { return $ this -> traverseObject ( $ obj -> { $ key } , array_slice ( $ keys , 1 ) ) ; } else { return null ; } }
Recursive traversing object based on properties from array
19,201
public function beforeHandleTask ( $ argv ) { return function ( Event $ event , Console $ console , Dispatcher $ dispatcher ) use ( $ argv ) { $ parsedOptions = OptionParser :: parse ( $ argv ) ; $ dispatcher -> setParams ( array ( 'activeTask' => isset ( $ parsedOptions [ 0 ] ) ? $ parsedOptions [ 0 ] : false , 'activeAction' => isset ( $ parsedOptions [ 1 ] ) ? $ parsedOptions [ 1 ] : false , 'args' => count ( $ parsedOptions ) > 2 ? array_slice ( $ parsedOptions , 2 ) : [ ] ) ) ; } ; }
Event fired before task is handling
19,202
private function findPattern ( $ matches ) { switch ( $ matches [ 1 ] ) { case ':num' : $ replacement = '([0-9]' ; break ; case ':alpha' : $ replacement = '([a-zA-Z]' ; break ; case ':any' : $ replacement = '([^\/]' ; break ; } if ( isset ( $ matches [ 3 ] ) && is_numeric ( $ matches [ 3 ] ) ) { if ( isset ( $ matches [ 4 ] ) && $ matches [ 4 ] == '?' ) { $ replacement .= '{0,' . $ matches [ 3 ] . '})' ; } else { $ replacement .= '{' . $ matches [ 3 ] . '})' ; } } else { if ( isset ( $ matches [ 4 ] ) && $ matches [ 4 ] == '?' ) { $ replacement .= '*)' ; } else { $ replacement .= '+)' ; } } return $ replacement ; }
Finds url pattern
19,203
public function toMappedArray ( ) { $ values = $ this -> toArray ( ) ; $ mappedValues = [ ] ; foreach ( $ values as $ key => $ value ) { $ mappedValues [ $ key ] = $ this -> readMapped ( $ key ) ; } return $ mappedValues ; }
Returns array of attributes with mapped values
19,204
public function readMapped ( $ name ) { if ( ! $ this -> hasMapping ( $ name ) && isset ( $ this -> mappings [ $ name ] ) ) { $ this -> addMapping ( $ name , $ this -> mappings [ $ name ] ) ; } $ value = $ this -> readAttribute ( $ name ) ; $ value = $ this -> resolveMapping ( $ name , $ value ) ; return $ value ; }
Returns mapped value of attribute
19,205
public static function value ( array $ data , $ key , $ default = null ) { $ value = static :: valueIfSet ( $ data , $ key , $ default ) ; if ( $ value ) { return $ value ; } else { return $ default ; } }
Get an element from an array or the default if it is not set or it s value is falsy .
19,206
private function exist ( User $ aUser ) { $ count = $ this -> execute ( 'SELECT COUNT(*) FROM user WHERE id = :id' , [ ':id' => $ aUser -> id ( ) -> id ( ) ] ) -> fetchColumn ( ) ; return ( int ) $ count === 1 ; }
Checks if the user given exists in the database .
19,207
private function insert ( User $ aUser ) { $ sql = 'INSERT INTO user ( id, confirmation_token_token, confirmation_token_created_on, created_on, email, invitation_token_token, invitation_token_created_on, last_login, password, salt, remember_password_token_token, remember_password_token_created_on, roles, updated_on ) VALUES ( :id, :confirmationTokenToken, :confirmationTokenCreatedOn, :createdOn, :email, :invitationTokenToken, :invitationTokenCreatedOn, :lastLogin, :password, :salt, :rememberPasswordTokenToken, :rememberPasswordTokenCreatedOn, :roles, :updatedOn )' ; $ this -> execute ( $ sql , [ 'id' => $ aUser -> id ( ) -> id ( ) , 'confirmationTokenToken' => $ aUser -> confirmationToken ( ) ? $ aUser -> confirmationToken ( ) -> token ( ) : null , 'confirmationTokenCreatedOn' => $ aUser -> confirmationToken ( ) ? $ aUser -> confirmationToken ( ) -> createdOn ( ) : null , 'createdOn' => $ aUser -> createdOn ( ) -> format ( self :: DATE_FORMAT ) , 'email' => $ aUser -> email ( ) -> email ( ) , 'invitationTokenToken' => $ aUser -> invitationToken ( ) ? $ aUser -> invitationToken ( ) -> token ( ) : null , 'invitationTokenCreatedOn' => $ aUser -> invitationToken ( ) ? $ aUser -> invitationToken ( ) -> createdOn ( ) : null , 'lastLogin' => $ aUser -> lastLogin ( ) ? $ aUser -> lastLogin ( ) -> format ( self :: DATE_FORMAT ) : null , 'password' => $ aUser -> password ( ) -> encodedPassword ( ) , 'salt' => $ aUser -> password ( ) -> salt ( ) , 'rememberPasswordTokenToken' => $ aUser -> rememberPasswordToken ( ) ? $ aUser -> rememberPasswordToken ( ) -> token ( ) : null , 'rememberPasswordTokenCreatedOn' => $ aUser -> rememberPasswordToken ( ) ? $ aUser -> rememberPasswordToken ( ) -> createdOn ( ) : null , 'roles' => $ this -> rolesToString ( $ aUser -> roles ( ) ) , 'updatedOn' => $ aUser -> updatedOn ( ) -> format ( self :: DATE_FORMAT ) , ] ) ; }
Prepares the insert SQL with the user given .
19,208
private function execute ( $ aSql , array $ parameters ) { $ statement = $ this -> pdo -> prepare ( $ aSql ) ; $ statement -> execute ( $ parameters ) ; return $ statement ; }
Wrapper that encapsulates the same logic about execute the query in PDO .
19,209
private function buildUser ( $ row ) { $ createdOn = new \ DateTimeImmutable ( $ row [ 'created_on' ] ) ; $ updatedOn = new \ DateTimeImmutable ( $ row [ 'updated_on' ] ) ; $ lastLogin = null === $ row [ 'last_login' ] ? null : new \ DateTimeImmutable ( $ row [ 'last_login' ] ) ; $ confirmationToken = null ; if ( null !== $ row [ 'confirmation_token_token' ] ) { $ confirmationToken = new UserToken ( $ row [ 'confirmation_token_token' ] ) ; $ this -> set ( $ confirmationToken , 'createdOn' , new \ DateTimeImmutable ( $ row [ 'confirmation_token_created_on' ] ) ) ; } $ invitationToken = null ; if ( null !== $ row [ 'invitation_token_token' ] ) { $ invitationToken = new UserToken ( $ row [ 'invitation_token_token' ] ) ; $ this -> set ( $ invitationToken , 'createdOn' , new \ DateTimeImmutable ( $ row [ 'invitation_token_created_on' ] ) ) ; } $ rememberPasswordToken = null ; if ( null !== $ row [ 'remember_password_token_token' ] ) { $ rememberPasswordToken = new UserToken ( $ row [ 'remember_password_token_token' ] ) ; $ this -> set ( $ rememberPasswordToken , 'createdOn' , new \ DateTimeImmutable ( $ row [ 'remember_password_token_created_on' ] ) ) ; } $ user = User :: signUp ( new UserId ( $ row [ 'id' ] ) , new UserEmail ( $ row [ 'email' ] ) , UserPassword :: fromEncoded ( $ row [ 'password' ] , $ row [ 'salt' ] ) , $ this -> rolesToArray ( $ row [ 'roles' ] ) ) ; $ user = $ this -> set ( $ user , 'createdOn' , $ createdOn ) ; $ user = $ this -> set ( $ user , 'updatedOn' , $ updatedOn ) ; $ user = $ this -> set ( $ user , 'lastLogin' , $ lastLogin ) ; $ user = $ this -> set ( $ user , 'confirmationToken' , $ confirmationToken ) ; $ user = $ this -> set ( $ user , 'invitationToken' , $ invitationToken ) ; $ user = $ this -> set ( $ user , 'rememberPasswordToken' , $ rememberPasswordToken ) ; return $ user ; }
Builds the user with the given sql row attributes .
19,210
public function setFields ( array $ models ) { try { $ this -> validator -> verify ( $ models , [ 'isArray' , 'isNotEmpty' , 'isExists' ] , 'where' ) ; } catch ( ExceptionFactory $ e ) { echo $ e -> getMessage ( ) ; } return $ this ; }
Prepare models and fields to participate in search
19,211
public function setThreshold ( $ threshold ) { if ( is_array ( $ threshold ) === true ) { $ threshold = array_map ( 'intval' , array_splice ( $ threshold , 0 , 2 ) ) ; } else { $ threshold = intval ( $ threshold ) ; } $ this -> validator -> verify ( $ threshold , [ ] , 'threshold' ) ; return $ this ; }
Setup offset limit threshold
19,212
public function setQuery ( $ query = null ) { try { $ this -> validator -> verify ( $ query , [ 'isNotNull' , 'isAcceptLength' ] ) ; if ( false === $ this -> exact ) { $ this -> query = [ 'query' => '%' . $ query . '%' ] ; } else { $ this -> query = [ 'query' => $ query ] ; } } catch ( ExceptionFactory $ e ) { echo $ e -> getMessage ( ) ; } return $ this ; }
Prepare query value
19,213
final public function run ( $ hydratorset = null , $ callback = null ) { try { $ result = ( new Builder ( $ this ) ) -> loop ( $ hydratorset , $ callback ) ; return $ result ; } catch ( ExceptionFactory $ e ) { echo $ e -> getMessage ( ) ; } }
Search procedure started
19,214
public function soapServerAction ( ) { try { $ apiModel = $ this -> _getModelName ( $ this -> obj ) ; $ wsdlParams = [ 'module' => 'cms' , 'controller' => 'api' , 'action' => 'wsdl' , 'obj' => $ this -> obj , ] ; if ( \ Mmi \ App \ FrontController :: getInstance ( ) -> getEnvironment ( ) -> authUser ) { $ apiModel .= 'Private' ; $ auth = new \ Mmi \ Security \ Auth ; $ auth -> setModelName ( $ apiModel ) ; $ auth -> httpAuth ( 'Private API' , 'Access denied!' ) ; $ wsdlParams [ 'type' ] = 'private' ; } $ url = $ this -> view -> url ( $ wsdlParams , true , true , $ this -> _isSsl ( ) ) ; $ this -> getResponse ( ) -> setTypeXml ( ) ; $ soap = new SoapServer ( $ url ) ; $ soap -> setClass ( $ apiModel ) ; $ soap -> handle ( ) ; return '' ; } catch ( \ Exception $ e ) { return $ this -> _internalError ( $ e ) ; } }
Akcja serwera SOAP
19,215
protected static function _checkAndCopyFile ( \ Mmi \ Http \ RequestFile $ file , $ allowedTypes = [ ] ) { if ( $ file -> type == 'image/x-ms-bmp' || $ file -> type == 'image/tiff' ) { $ file -> type = 'application/octet-stream' ; } if ( ! empty ( $ allowedTypes ) && ! in_array ( $ file -> type , $ allowedTypes ) ) { return null ; } $ pointPosition = strrpos ( $ file -> name , '.' ) ; $ name = md5 ( microtime ( true ) . $ file -> tmpName ) . ( ( $ pointPosition !== false ) ? substr ( $ file -> name , $ pointPosition ) : '' ) ; $ dir = BASE_PATH . '/var/data/' . $ name [ 0 ] . '/' . $ name [ 1 ] . '/' . $ name [ 2 ] . '/' . $ name [ 3 ] ; if ( ! file_exists ( $ dir ) ) { mkdir ( $ dir , 0777 , true ) ; } chmod ( $ file -> tmpName , 0664 ) ; copy ( $ file -> tmpName , $ dir . '/' . $ name ) ; return $ name ; }
Sprawdza parametry i kopiuje plik do odpowiedniego katalogu na dysku
19,216
public static function move ( $ srcObject , $ srcId , $ destObject , $ destId ) { $ i = 0 ; foreach ( CmsFileQuery :: byObject ( $ srcObject , $ srcId ) -> find ( ) as $ file ) { $ file -> object = $ destObject ; $ file -> objectId = $ destId ; $ file -> save ( ) ; $ i ++ ; } return $ i ; }
Przenosi plik z jednego obiektu na inny
19,217
public static function copy ( $ srcObject , $ srcId , $ destObject , $ destId ) { $ i = 0 ; foreach ( CmsFileQuery :: byObject ( $ srcObject , $ srcId ) -> find ( ) as $ file ) { try { $ copy = new \ Mmi \ Http \ RequestFile ( [ 'name' => $ file -> original , 'tmp_name' => $ file -> getRealPath ( ) , 'size' => $ file -> size ] ) ; } catch ( \ Mmi \ App \ KernelException $ e ) { \ Mmi \ App \ FrontController :: getInstance ( ) -> getLogger ( ) -> warning ( 'Unable to copy file, file not found: ' . $ file -> getRealPath ( ) ) ; continue ; } $ newFile = clone $ file ; $ newFile -> id = null ; self :: _copyFile ( $ copy , $ destObject , $ destId , $ newFile ) ; $ i ++ ; } return $ i ; }
Kopiuje plik z jednego obiektu na inny
19,218
protected static function _updateRecordFromRequestFile ( \ Mmi \ Http \ RequestFile $ file , \ Cms \ Orm \ CmsFileRecord $ record ) { $ record -> mimeType = $ file -> type ; $ class = explode ( '/' , $ file -> type ) ; $ record -> class = $ class [ 0 ] ; $ record -> original = $ file -> name ; $ record -> size = $ file -> size ; if ( ! $ record -> dateAdd ) { $ record -> dateAdd = date ( 'Y-m-d H:i:s' ) ; } if ( ! $ record -> dateModify ) { $ record -> dateModify = date ( 'Y-m-d H:i:s' ) ; } $ record -> cmsAuthId = \ App \ Registry :: $ auth ? \ App \ Registry :: $ auth -> getId ( ) : null ; if ( $ record -> active === null ) { $ record -> active = 1 ; } return $ record ; }
Aktualizuje rekord na podstawie pliku z requestu
19,219
public function setContainer ( ContainerInterface $ container = NULL ) { parent :: setContainer ( $ container ) ; if ( ! $ this -> container -> getParameter ( 'fom_user.selfregister' ) ) throw new AccessDeniedHttpException ( ) ; }
Check if self registration is allowed .
19,220
public function extract ( $ path , $ regex = null ) { $ directory = new RecursiveDirectoryIterator ( $ path , FilesystemIterator :: SKIP_DOTS ) ; $ iterator = new RecursiveIteratorIterator ( $ directory ) ; if ( $ regex ) { $ iterator = new RegexIterator ( $ iterator , $ regex ) ; } $ this -> iterator -> attachIterator ( $ iterator ) ; return $ this ; }
Add a new source folder .
19,221
private function scan ( Translations $ translations ) { foreach ( $ this -> iterator as $ each ) { foreach ( $ each as $ file ) { if ( $ file === null || ! $ file -> isFile ( ) ) { continue ; } $ target = $ file -> getPathname ( ) ; if ( ( $ fn = $ this -> getFunctionName ( 'addFrom' , $ target , 'File' ) ) ) { $ translations -> $ fn ( $ target ) ; } } } }
Execute the scan .
19,222
private function getFunctionName ( $ prefix , $ file , $ suffix , $ key = 0 ) { if ( preg_match ( self :: getRegex ( ) , strtolower ( $ file ) , $ matches ) ) { $ format = self :: $ suffixes [ $ matches [ 1 ] ] ; if ( is_array ( $ format ) ) { $ format = $ format [ $ key ] ; } return sprintf ( '%s%s%s' , $ prefix , $ format , $ suffix ) ; } }
Get the format based in the extension .
19,223
private static function getRegex ( ) { if ( self :: $ regex === null ) { self :: $ regex = '/(' . str_replace ( '.' , '\\.' , implode ( '|' , array_keys ( self :: $ suffixes ) ) ) . ')$/' ; } return self :: $ regex ; }
Returns the regular expression to detect the file format .
19,224
public function setPassword ( User $ user , $ password ) { $ encoder = $ this -> container -> get ( 'security.encoder_factory' ) -> getEncoder ( $ user ) ; $ salt = $ this -> createSalt ( ) ; $ encryptedPassword = $ encoder -> encodePassword ( $ password , $ salt ) ; $ user -> setPassword ( $ encryptedPassword ) -> setSalt ( $ salt ) ; }
Set salt encrypt password and set it on the user object
19,225
private function createSalt ( $ max = 15 ) { $ characterList = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" ; $ i = 0 ; $ salt = "" ; do { $ salt .= $ characterList { mt_rand ( 0 , strlen ( $ characterList ) - 1 ) } ; $ i ++ ; } while ( $ i < $ max ) ; return $ salt ; }
Generate a salt for storing the encrypted password
19,226
public function giveOwnRights ( $ user ) { $ aclProvider = $ this -> container -> get ( 'security.acl.provider' ) ; $ maskBuilder = new MaskBuilder ( ) ; $ usid = UserSecurityIdentity :: fromAccount ( $ user ) ; $ uoid = ObjectIdentity :: fromDomainObject ( $ user ) ; foreach ( $ this -> container -> getParameter ( "fom_user.user_own_permissions" ) as $ permission ) { $ maskBuilder -> add ( $ permission ) ; } $ umask = $ maskBuilder -> get ( ) ; try { $ acl = $ aclProvider -> findAcl ( $ uoid ) ; } catch ( \ Exception $ e ) { $ acl = $ aclProvider -> createAcl ( $ uoid ) ; } $ acl -> insertObjectAce ( $ usid , $ umask ) ; $ aclProvider -> updateAcl ( $ acl ) ; }
Gives a user the right to edit himself .
19,227
public function modelCommand ( $ input , $ modelName , $ optimized = false ) { if ( strpos ( $ modelName , '\\' ) === false ) { $ modelName = 'App\\Models\\' . ucfirst ( $ modelName ) ; } $ fieldTypes = $ this -> _inferFieldTypes ( [ $ input ] ) ; $ model = $ this -> _renderModel ( $ fieldTypes , $ modelName , 'mongodb' , $ optimized ) ; $ file = '@tmp/mongodb_model/' . substr ( $ modelName , strrpos ( $ modelName , '\\' ) + 1 ) . '.php' ; $ this -> filesystem -> filePut ( $ file , $ model ) ; $ this -> console -> writeLn ( [ 'write model to :file' , 'file' => $ file ] ) ; }
generate model file from base64 encoded string
19,228
public function modelsCommand ( $ services = [ ] , $ namespace = 'App\Models' , $ optimized = false , $ sample = 1000 , $ db = [ ] ) { if ( strpos ( $ namespace , '\\' ) === false ) { $ namespace = 'App\\' . ucfirst ( $ namespace ) . '\\Models' ; } foreach ( $ this -> _getServices ( $ services ) as $ service ) { $ mongodb = $ this -> _di -> getShared ( $ service ) ; $ defaultDb = $ mongodb -> getDefaultDb ( ) ; foreach ( $ defaultDb ? [ $ defaultDb ] : $ mongodb -> listDatabases ( ) as $ cdb ) { if ( in_array ( $ cdb , [ 'admin' , 'local' ] , true ) || ( $ db && ! in_array ( $ cdb , $ db , true ) ) ) { continue ; } foreach ( $ mongodb -> listCollections ( $ cdb ) as $ collection ) { if ( strpos ( $ collection , '.' ) ) { continue ; } if ( ! $ docs = $ mongodb -> aggregate ( "$cdb.$collection" , [ [ '$sample' => [ 'size' => $ sample ] ] ] ) ) { continue ; } $ plainClass = Text :: camelize ( $ collection ) ; $ fileName = "@tmp/mongodb_models/$plainClass.php" ; $ this -> console -> progress ( [ '`:collection` processing...' , 'collection' => $ collection ] , '' ) ; $ fieldTypes = $ this -> _inferFieldTypes ( $ docs ) ; $ modelClass = $ namespace . '\\' . $ plainClass ; $ model = $ this -> _renderModel ( $ fieldTypes , $ modelClass , $ service , $ defaultDb ? $ collection : "$cdb.$collection" , $ optimized ) ; $ this -> filesystem -> filePut ( $ fileName , $ model ) ; $ this -> console -> progress ( [ ' `:namespace` collection saved to `:file`' , 'namespace' => "$cdb.$collection" , 'file' => $ fileName ] ) ; $ pending_fields = [ ] ; foreach ( $ fieldTypes as $ field => $ type ) { if ( $ type === '' || strpos ( $ type , '|' ) !== false ) { $ pending_fields [ ] = $ field ; } } if ( $ pending_fields ) { $ this -> console -> warn ( [ '`:collection` has pending fields: :fields' , 'collection' => $ collection , 'fields' => implode ( ', ' , $ pending_fields ) ] ) ; } } } } }
generate models file from data files or online data
19,229
public function csvCommand ( $ services = [ ] , $ collection_pattern = '' , $ bom = false ) { foreach ( $ this -> _getServices ( $ services ) as $ service ) { $ mongodb = $ this -> _di -> getShared ( $ service ) ; $ defaultDb = $ mongodb -> getDefaultDb ( ) ; foreach ( $ defaultDb ? [ $ defaultDb ] : $ mongodb -> listDatabases ( ) as $ db ) { if ( in_array ( $ db , [ 'admin' , 'local' ] , true ) ) { continue ; } foreach ( $ mongodb -> listCollections ( $ db ) as $ collection ) { if ( $ collection_pattern && ! fnmatch ( $ collection_pattern , $ collection ) ) { continue ; } $ fileName = "@tmp/mongodb_csv/$db/$collection.csv" ; $ this -> console -> progress ( [ '`:collection` processing...' , 'collection' => $ collection ] , '' ) ; $ this -> filesystem -> dirCreate ( dirname ( $ fileName ) ) ; $ file = fopen ( $ this -> alias -> resolve ( $ fileName ) , 'wb' ) ; if ( $ bom ) { fprintf ( $ file , "\xEF\xBB\xBF" ) ; } $ docs = $ mongodb -> fetchAll ( "$db.$collection" ) ; if ( $ docs ) { $ columns = [ ] ; foreach ( $ docs [ 0 ] as $ k => $ v ) { if ( $ k === '_id' && is_object ( $ v ) ) { continue ; } $ columns [ ] = $ k ; } fputcsv ( $ file , $ columns ) ; } $ linesCount = 0 ; $ startTime = microtime ( true ) ; if ( count ( $ docs ) !== 0 ) { foreach ( $ docs as $ doc ) { $ line = [ ] ; foreach ( $ doc as $ k => $ v ) { if ( $ k === '_id' && is_object ( $ v ) ) { continue ; } $ line [ ] = $ v ; } $ linesCount ++ ; fputcsv ( $ file , $ line ) ; } } fclose ( $ file ) ; $ this -> console -> progress ( [ 'write to `:file` success: :count [:time]' , 'file' => $ fileName , 'count' => $ linesCount , 'time' => round ( microtime ( true ) - $ startTime , 4 ) ] ) ; } } } }
export mongodb data to csv files
19,230
public function listCommand ( $ services = [ ] , $ collection_pattern = '' , $ field = '' , $ db = [ ] ) { foreach ( $ this -> _getServices ( $ services ) as $ service ) { $ mongodb = $ this -> _di -> getShared ( $ service ) ; $ defaultDb = $ mongodb -> getDefaultDb ( ) ; foreach ( $ defaultDb ? [ $ defaultDb ] : $ mongodb -> listDatabases ( ) as $ cdb ) { if ( $ db && ! in_array ( $ cdb , $ db , true ) ) { continue ; } $ this -> console -> writeLn ( [ '---`:db` db of `:service` service---' , 'db' => $ cdb , 'service' => $ service ] , Console :: BC_CYAN ) ; foreach ( $ mongodb -> listCollections ( $ cdb ) as $ row => $ collection ) { if ( $ collection_pattern && ! fnmatch ( $ collection_pattern , $ collection ) ) { continue ; } if ( $ field ) { if ( ! $ docs = $ mongodb -> fetchAll ( "$cdb.$collection" , [ $ field => [ '$exists' => 1 ] ] , [ 'limit' => 1 ] ) ) { continue ; } } else { $ docs = $ mongodb -> fetchAll ( "$cdb.$collection" , [ ] , [ 'limit' => 1 ] ) ; } $ columns = $ docs ? array_keys ( $ docs [ 0 ] ) : [ ] ; $ this -> console -> writeLn ( [ ' :row :namespace(:columns)' , 'row' => sprintf ( '%2d ' , $ row + 1 ) , 'namespace' => $ this -> console -> colorize ( "$cdb.$collection" , Console :: FC_GREEN ) , 'columns' => implode ( ', ' , $ columns ) ] ) ; } } } }
list databases and collections
19,231
public function addDefinition ( $ type , $ value , $ field ) { $ definition = new \ stdClass ( ) ; $ definition -> type = $ type ; $ definition -> value = $ value ; $ definition -> field = $ field ; $ this -> _filter [ ] = $ definition ; }
Adds a new filter definition
19,232
public function rise ( array $ params , $ line , $ filename ) { $ this -> invoke = [ 'MODEL_DOES_NOT_EXISTS' => function ( $ params , $ filename , $ line ) { $ this -> message = "Model `" . $ params [ 1 ] . "` not exists. File: " . $ filename . " Line: " . $ line ; } ] ; $ this -> invoke [ current ( $ params ) ] ( $ params , $ filename , $ line ) ; return $ this ; }
Rise error message for Model Exceptions
19,233
public function postDeleteRole ( ) { $ response = ( object ) array ( 'method' => 'deleterole' , 'success' => false , 'status' => 200 , 'error_code' => 0 , 'error_message' => '' ) ; $ data = json_decode ( file_get_contents ( "php://input" ) ) ; if ( empty ( $ data ) ) { $ data = ( object ) $ _POST ; } $ requiredParams = array ( 'id' ) ; try { AuthorizerHelper :: can ( RoleValidator :: ROLE_CAN_DELETE ) ; $ data = ( array ) $ data ; foreach ( $ requiredParams as $ param ) { if ( empty ( $ data [ $ param ] ) ) { throw new \ Exception ( ucfirst ( $ param ) . ' is required.' ) ; } } $ roleModel = new \ erdiko \ users \ models \ Role ( ) ; $ roleId = $ roleModel -> delete ( $ data [ 'id' ] ) ; $ responseRoleId = array ( 'id' => $ roleId ) ; $ response -> success = true ; $ response -> role = $ responseRoleId ; unset ( $ response -> error_code ) ; unset ( $ response -> error_message ) ; } catch ( \ Exception $ e ) { $ response -> success = false ; $ response -> error_code = $ e -> getCode ( ) ; $ response -> error_message = $ e -> getMessage ( ) ; } $ this -> setContent ( $ response ) ; }
delete a given role
19,234
public function output ( $ remove = true ) { $ context = $ this -> _context ; foreach ( $ context -> messages as $ message ) { echo $ message ; } if ( $ remove ) { $ context -> messages = [ ] ; } }
Prints the messages in the session flasher
19,235
public function editAction ( ) { $ form = new \ CmsAdmin \ Form \ Text ( new \ Cms \ Orm \ CmsTextRecord ( $ this -> id ) ) ; $ this -> view -> textForm = $ form ; if ( ! $ form -> isMine ( ) ) { return ; } if ( $ form -> isSaved ( ) ) { $ this -> getMessenger ( ) -> addMessage ( 'messenger.text.text.saved' , true ) ; $ this -> getResponse ( ) -> redirect ( 'cmsAdmin' , 'text' ) ; } $ this -> getMessenger ( ) -> addMessage ( 'messenger.text.text.error' , false ) ; }
Akcja edycji tekstu
19,236
public function getThumbnailUrl ( Tube $ video ) { if ( 0 === strlen ( $ this -> thumbnailSize ) ) { return false ; } return sprintf ( 'http://img.youtube.com/vi/%s/%s.jpg' , $ video -> id , $ this -> thumbnailSize ) ; }
Get the thumbnail from a given URL .
19,237
public function getPropertyValue ( $ user , $ property = self :: LOGIN_PROPERTY , $ strict = false ) { if ( $ this -> checkProperty ( $ property , $ strict ) ) { $ oid = spl_object_hash ( $ user ) ; if ( null !== $ cacheHit = $ this -> resolveCache ( $ oid , $ property ) ) { return $ cacheHit ; } if ( is_string ( $ this -> properties [ $ property ] ) ) { $ this -> properties [ $ property ] = new ReflectionProperty ( $ user , $ this -> properties [ $ property ] ) ; } $ this -> properties [ $ property ] -> setAccessible ( true ) ; return $ this -> lazyValueCache [ $ oid ] [ $ property ] = $ this -> properties [ $ property ] -> getValue ( $ user ) ; } }
Gets the value of the given property .
19,238
public function getPropertyName ( $ property = self :: LOGIN_PROPERTY , $ strict = false ) { if ( $ this -> checkProperty ( $ property , $ strict ) ) { if ( is_string ( $ this -> properties [ $ property ] ) ) { return $ this -> properties [ $ property ] ; } if ( isset ( $ this -> lazyPropertyNameCache [ $ property ] ) ) { return $ this -> lazyPropertyNameCache [ $ property ] ; } return $ this -> lazyPropertyNameCache [ $ property ] = $ this -> properties [ $ property ] -> getName ( ) ; } }
Gets the name of a specific property by its metadata constant .
19,239
public function modifyProperty ( $ user , $ newValue , $ property = self :: LOGIN_PROPERTY ) { $ this -> checkProperty ( $ property , true ) ; $ propertyObject = $ this -> properties [ $ property ] ; if ( is_string ( $ propertyObject ) ) { $ this -> properties [ $ property ] = $ propertyObject = new ReflectionProperty ( $ user , $ propertyObject ) ; } $ propertyObject -> setAccessible ( true ) ; $ propertyObject -> setValue ( $ user , $ newValue ) ; $ oid = spl_object_hash ( $ user ) ; if ( ! array_key_exists ( $ oid , $ this -> lazyValueCache ) ) { $ this -> lazyValueCache [ $ oid ] = array ( ) ; } $ this -> lazyValueCache [ $ oid ] [ $ property ] = $ newValue ; }
Modifies a property and clears the cache .
19,240
private function checkProperty ( $ property = self :: LOGIN_PROPERTY , $ strict = false ) { if ( ! isset ( $ this -> properties [ $ property ] ) ) { if ( $ strict ) { throw new \ LogicException ( sprintf ( 'Cannot get property "%s"!' , $ property ) ) ; } return false ; } return true ; }
Validates a property .
19,241
private function resolveCache ( $ oid , $ property ) { if ( isset ( $ this -> lazyValueCache [ $ oid ] ) ) { if ( isset ( $ this -> lazyValueCache [ $ oid ] [ $ property ] ) ) { return $ this -> lazyValueCache [ $ oid ] [ $ property ] ; } return ; } $ this -> lazyValueCache [ $ oid ] = array ( ) ; }
Resolves the lazy value cache .
19,242
protected function registerMakeCommand ( ) { $ this -> app -> singleton ( 'command.repository.make' , function ( $ app ) { $ prefix = $ app [ 'config' ] [ 'repository.prefix' ] ; $ suffix = $ app [ 'config' ] [ 'repository.suffix' ] ; $ contract = $ app [ 'config' ] [ 'repository.contract' ] ; $ namespace = $ app [ 'config' ] [ 'repository.namespace' ] ; $ creator = $ app [ 'repository.creator' ] ; $ files = $ app [ 'files' ] ; return new RepositoryMakeCommand ( $ creator , $ prefix , $ suffix , $ contract , $ namespace , $ files ) ; } ) ; $ this -> commands ( 'command.repository.make' ) ; }
Register the make repository command .
19,243
public function setCookie ( $ name , $ value , $ expire = 0 , $ path = null , $ domain = null , $ secure = false , $ httpOnly = true ) { $ context = $ this -> _context ; if ( $ expire > 0 ) { $ current = time ( ) ; if ( $ expire < $ current ) { $ expire += $ current ; } } $ context -> cookies [ $ name ] = [ 'name' => $ name , 'value' => $ value , 'expire' => $ expire , 'path' => $ path , 'domain' => $ domain , 'secure' => $ secure , 'httpOnly' => $ httpOnly ] ; $ globals = $ this -> request -> getGlobals ( ) ; $ globals -> _COOKIE [ $ name ] = $ value ; return $ this ; }
Sets a cookie to be sent at the end of the request
19,244
public function setStatus ( $ code , $ text = null ) { $ context = $ this -> _context ; $ context -> status_code = ( int ) $ code ; $ context -> status_text = $ text ? : $ this -> getStatusText ( $ code ) ; return $ this ; }
Sets the HTTP response code
19,245
public function setHeader ( $ name , $ value ) { $ context = $ this -> _context ; $ context -> headers [ $ name ] = $ value ; return $ this ; }
Overwrites a header in the response
19,246
public function redirect ( $ location , $ temporarily = true ) { if ( $ temporarily ) { $ this -> setStatus ( 302 , 'Temporarily Moved' ) ; } else { $ this -> setStatus ( 301 , 'Permanently Moved' ) ; } $ this -> setHeader ( 'Location' , $ this -> url -> get ( $ location ) ) ; throw new AbortException ( ) ; return $ this ; }
Redirect by HTTP to another action or URL
19,247
public function setContent ( $ content ) { $ context = $ this -> _context ; $ context -> content = ( string ) $ content ; return $ this ; }
Sets HTTP response body
19,248
public function setJsonContent ( $ content ) { $ context = $ this -> _context ; $ this -> setHeader ( 'Content-Type' , 'application/json; charset=utf-8' ) ; if ( is_array ( $ content ) ) { if ( ! isset ( $ content [ 'code' ] ) ) { $ content = [ 'code' => 0 , 'message' => '' , 'data' => $ content ] ; } } elseif ( $ content instanceof \ JsonSerializable ) { $ content = [ 'code' => 0 , 'message' => '' , 'data' => $ content ] ; } elseif ( is_string ( $ content ) ) { null ; } elseif ( is_int ( $ content ) ) { $ content = [ 'code' => $ content , 'message' => '' ] ; } elseif ( $ content === null ) { $ content = [ 'code' => 0 , 'message' => '' , 'data' => null ] ; } elseif ( $ content instanceof ValidatorException ) { $ content = [ 'code' => - 2 , 'message' => $ content -> getMessage ( ) ] ; } elseif ( $ content instanceof \ Exception ) { if ( $ content instanceof \ ManaPHP \ Exception ) { $ this -> setStatus ( $ content -> getStatusCode ( ) ) ; $ content = $ content -> getJson ( ) ; } else { $ this -> setStatus ( 500 ) ; $ content = [ 'code' => 500 , 'message' => 'Server Internal Error' ] ; } } $ context -> content = $ this -> _jsonEncode ( $ content ) ; return $ this ; }
Sets HTTP response body . The parameter is automatically converted to JSON
19,249
protected function _checkForFile ( $ directory , $ file ) { if ( strlen ( $ file ) < 33 || strlen ( $ file ) > 37 ) { echo $ file . "\n" ; return ; } if ( null === $ fr = ( new \ Cms \ Orm \ CmsFileQuery ) -> whereName ( ) -> equals ( $ file ) -> findFirst ( ) ) { $ this -> _size += filesize ( $ directory . '/' . $ file ) ; $ this -> _count ++ ; unlink ( $ directory . '/' . $ file ) ; return $ this -> _reportLine ( $ directory . '/' . $ file ) ; } $ this -> _found ++ ; }
Sprawdza istnienie pliku
19,250
public function webCommand ( $ id = '' , $ ip = '' ) { $ options = [ ] ; if ( $ id ) { $ options [ 'id' ] = $ id ; } if ( $ ip ) { $ options [ 'ip' ] = $ ip ; } $ this -> fiddlerPlugin -> subscribeWeb ( $ options ) ; }
fiddler web app
19,251
public function cliCommand ( $ id = '' ) { $ options = [ ] ; if ( $ id ) { $ options [ 'id' ] = $ id ; } $ this -> fiddlerPlugin -> subscribeCli ( $ options ) ; }
fiddler cli app
19,252
function register_node_class ( $ s , $ class ) { if ( ! class_exists ( $ class ) ) { $ s = $ this -> token_name ( $ s ) ; throw new Exception ( "If you want to register class `$class' for symbol `$s' you should include it first" ) ; } $ this -> node_classes [ $ s ] = $ class ; }
Register a custom ParseNode class for a given symbol
19,253
function create_node ( $ s ) { if ( isset ( $ this -> node_classes [ $ s ] ) ) { $ class = $ this -> node_classes [ $ s ] ; } else { $ class = $ this -> default_node_class ; } return new $ class ( $ s ) ; }
Create a Parse Node according to registered symbol
19,254
function token_name ( $ t ) { $ t = self :: token_to_symbol ( $ t ) ; if ( ! is_int ( $ t ) ) { return $ t ; } return $ this -> Lex -> name ( $ t ) ; }
Get name of scalar symbol for debugging
19,255
protected function current_token ( ) { if ( ! isset ( $ this -> tok ) ) { $ this -> tok = current ( $ this -> input ) ; $ this -> t = self :: token_to_symbol ( $ this -> tok ) ; } return $ this -> tok ; }
Get current token from input stream .
19,256
protected function next_token ( ) { $ this -> tok = next ( $ this -> input ) ; $ this -> t = self :: token_to_symbol ( $ this -> tok ) ; return $ this -> tok ; }
Advance input stream to next token
19,257
protected function prev_token ( ) { $ this -> tok = prev ( $ this -> input ) ; $ this -> t = self :: token_to_symbol ( $ this -> tok ) ; return $ this -> tok ; }
Rollback input stream to previous token
19,258
public function syncCommand ( $ url = 'http://www.baidu.com' ) { $ timestamp = $ this -> _getRemoteTimestamp ( $ url ) ; if ( $ timestamp === false ) { return $ this -> console -> error ( [ 'fetch remote timestamp failed: `:url`' , 'url' => $ url ] ) ; } else { $ this -> _updateDate ( $ timestamp ) ; $ this -> console -> write ( date ( 'Y-m-d H:i:s' ) ) ; return 0 ; } }
sync system time with http server time clock
19,259
public function remoteCommand ( $ url = 'http://www.baidu.com' ) { $ timestamp = $ this -> _getRemoteTimestamp ( $ url ) ; if ( $ timestamp === false ) { return $ this -> console -> error ( [ 'fetch remote timestamp failed: `:url`' , 'url' => $ url ] ) ; } else { $ this -> console -> writeLn ( date ( 'Y-m-d H:i:s' , $ timestamp ) ) ; return 0 ; } }
show remote time
19,260
public function diffCommand ( $ url = 'http://www.baidu.com' ) { $ remote_ts = $ this -> _getRemoteTimestamp ( $ url ) ; $ local_ts = time ( ) ; if ( $ remote_ts === false ) { return $ this -> console -> error ( [ 'fetch remote timestamp failed: `:url`' , 'url' => $ url ] ) ; } else { $ this -> console -> writeLn ( ' local: ' . date ( 'Y-m-d H:i:s' , $ local_ts ) ) ; $ this -> console -> writeLn ( 'remote: ' . date ( 'Y-m-d H:i:s' , $ remote_ts ) ) ; $ this -> console -> writeLn ( ' diff: ' . ( $ local_ts - $ remote_ts ) ) ; return 0 ; } }
show local and remote diff
19,261
private function _getRequestFile ( ) { $ data = [ 'name' => $ this -> _fileName , 'size' => $ this -> _fileSize , 'tmp_name' => $ this -> _filePath ] ; return new \ Mmi \ Http \ RequestFile ( $ data ) ; }
Zwraca obiekt pliku request
19,262
protected function askQuestion ( $ question , $ choices , $ default ) { do { echo $ question . ' ' . $ choices . ': ' ; $ handle = fopen ( "php://stdin" , "r" ) ; $ line = fgets ( $ handle ) ; $ response = trim ( $ line ) ; if ( empty ( $ response ) ) $ response = $ default ; } while ( ! in_array ( $ response , explode ( '/' , $ choices ) ) ) ; return $ response ; }
Prompts the user for a response
19,263
public function requestApiKeyAction ( Request $ request ) { $ dispatcher = $ this -> get ( 'event_dispatcher' ) ; $ credentials = [ ] ; if ( $ request -> request -> has ( 'login' ) ) { $ credentials [ $ this -> getPropertyName ( ClassMetadata :: LOGIN_PROPERTY ) ] = $ request -> request -> get ( 'login' ) ; } if ( $ request -> request -> has ( 'password' ) ) { $ credentials [ $ this -> getPropertyName ( ClassMetadata :: PASSWORD_PROPERTY ) ] = $ request -> request -> get ( 'password' ) ; } [ $ user , $ exception ] = $ this -> processAuthentication ( $ credentials ) ; $ result = $ dispatcher -> dispatch ( Ma27ApiKeyAuthenticationEvents :: ASSEMBLE_RESPONSE , new OnAssembleResponseEvent ( $ user , $ exception ) ) ; if ( ! $ response = $ result -> getResponse ( ) ) { throw new HttpException ( Response :: HTTP_INTERNAL_SERVER_ERROR , 'Cannot assemble the response!' , $ exception ) ; } return $ response ; }
Requests an api key .
19,264
public function removeSessionAction ( Request $ request ) { $ om = $ this -> get ( $ this -> container -> getParameter ( 'ma27_api_key_authentication.object_manager' ) ) ; if ( ! $ header = ( string ) $ request -> headers -> get ( $ this -> container -> getParameter ( 'ma27_api_key_authentication.key_header' ) ) ) { return new JsonResponse ( [ 'message' => 'Missing api key header!' ] , 400 ) ; } $ user = $ om -> getRepository ( $ this -> container -> getParameter ( 'ma27_api_key_authentication.model_name' ) ) -> findOneBy ( [ $ this -> getPropertyName ( ClassMetadata :: API_KEY_PROPERTY ) => $ header , ] ) ; $ this -> get ( 'ma27_api_key_authentication.auth_handler' ) -> removeSession ( $ user ) ; return new JsonResponse ( [ ] , 204 ) ; }
Removes an api key .
19,265
private function processAuthentication ( array $ credentials ) { $ authenticationHandler = $ this -> get ( 'ma27_api_key_authentication.auth_handler' ) ; $ dispatcher = $ this -> get ( 'event_dispatcher' ) ; try { $ user = $ authenticationHandler -> authenticate ( $ credentials ) ; } catch ( CredentialException $ ex ) { $ userOrNull = $ user ?? null ; $ dispatcher -> dispatch ( Ma27ApiKeyAuthenticationEvents :: CREDENTIAL_EXCEPTION_THROWN , new OnCredentialExceptionThrownEvent ( $ ex , $ userOrNull ) ) ; return [ $ userOrNull , $ ex ] ; } return [ $ user , null ] ; }
Internal utility to handle the authentication process based on the credentials .
19,266
private function hydrateDataObject ( $ data ) { $ dataObject = new MetadataDataObjectOracle ( new MetaDataColumnCollection ( ) , new MetaDataRelationCollection ( ) ) ; $ tableName = $ data [ 'TABLE_NAME' ] ; $ owner = $ data [ 'OWNER' ] ; $ dataObject -> setName ( $ owner . '/' . $ tableName ) ; $ columnDataObject = new MetaDataColumn ( ) ; $ statement = $ this -> pdo -> prepare ( sprintf ( "SELECT COLUMN_NAME as name, NULLABLE as nullable, DATA_TYPE as type, DATA_LENGTH as length FROM SYS.ALL_TAB_COLUMNS WHERE TABLE_NAME = '%s' and OWNER= '%s'" , $ tableName , $ owner ) ) ; $ statement -> execute ( array ( ) ) ; $ allFields = $ statement -> fetchAll ( PDO :: FETCH_ASSOC ) ; $ identifiers = $ this -> getIdentifiers ( $ owner , $ tableName ) ; foreach ( $ allFields as $ metadata ) { $ column = clone $ columnDataObject ; $ type = $ metadata [ 'type' ] ; if ( isset ( $ this -> typeConversion [ $ type ] ) === true ) { $ type = $ this -> typeConversion [ $ type ] ; } $ column -> setName ( $ metadata [ 'name' ] ) -> setType ( $ type ) -> setLength ( isset ( $ metadata [ 'length' ] ) === true ? $ metadata [ 'length' ] : null ) ; if ( in_array ( $ metadata [ 'name' ] , $ identifiers ) === true ) { $ column -> setPrimaryKey ( true ) ; } $ dataObject -> appendColumn ( $ column ) ; } return $ dataObject ; }
Convert PDOmapping to CrudGenerator mapping
19,267
private function pdoMetadataToGeneratorMetadata ( array $ metadataCollection ) { $ metaDataCollection = new MetaDataCollection ( ) ; foreach ( $ metadataCollection as $ tableName ) { $ metaDataCollection -> append ( $ this -> hydrateDataObject ( $ tableName ) ) ; } return $ metaDataCollection ; }
Convert MySQL mapping to CrudGenerator mapping
19,268
private function hydrateDataObject ( $ tableName , array $ parentName = array ( ) ) { $ dataObject = new MetadataDataObjectMySQL ( new MetaDataColumnCollection ( ) , new MetaDataRelationCollection ( ) ) ; $ dataObject -> setName ( $ tableName ) ; $ statement = $ this -> pdo -> prepare ( "SELECT columnTable.column_name, columnTable.table_name, columnTable.data_type, columnTable.column_key, columnTable.is_nullable, k.referenced_table_name, k.referenced_column_name FROM information_schema.columns as columnTable left outer join information_schema.key_column_usage k on k.table_schema=columnTable.table_schema and k.table_name=columnTable.table_name and k.column_name=columnTable.column_name WHERE columnTable.table_name = :tableName AND columnTable.table_schema = :databaseName" ) ; $ statement -> execute ( array ( ':tableName' => $ tableName , ':databaseName' => $ this -> pdoConfig -> getResponse ( 'configDatabaseName' ) , ) ) ; $ allFields = $ statement -> fetchAll ( PDO :: FETCH_ASSOC ) ; $ columnsAssociation = array ( ) ; foreach ( $ allFields as $ index => $ metadata ) { if ( $ metadata [ 'referenced_table_name' ] !== null && $ metadata [ 'referenced_column_name' ] !== null ) { $ columnsAssociation [ $ index ] = $ metadata ; unset ( $ allFields [ $ index ] ) ; continue ; } } return $ this -> hydrateRelation ( $ this -> hydrateFields ( $ dataObject , $ allFields ) , $ columnsAssociation , $ parentName ) ; }
Convert MySQL mapping to CodeGenerator mapping
19,269
public static function authenticate ( $ identity , $ credential ) { if ( null === $ record = self :: _findUserByIdentity ( $ identity ) ) { return ; } if ( ! self :: _localAuthenticate ( $ record , $ credential ) && ! self :: _ldapAuthenticate ( $ record , $ credential ) ) { self :: _updateUserFailedLogin ( $ record ) ; return self :: _authFailed ( $ identity , 'Invalid password.' ) ; } return self :: _authSuccess ( $ record ) ; }
Autoryzacja do CMS
19,270
public static function idAuthenticate ( $ id ) { if ( null === $ record = self :: _findUserByIdentity ( $ id ) ) { return ; } return self :: _authSuccess ( $ record ) ; }
Autoryzacja po ID
19,271
protected static function _authSuccess ( CmsAuthRecord $ record ) { $ record -> lastIp = \ Mmi \ App \ FrontController :: getInstance ( ) -> getEnvironment ( ) -> remoteAddress ; $ record -> lastLog = date ( 'Y-m-d H:i:s' ) ; $ record -> save ( ) ; \ Mmi \ App \ FrontController :: getInstance ( ) -> getLogger ( ) -> info ( 'Logged in: ' . $ record -> username ) ; $ authRecord = new \ Mmi \ Security \ AuthRecord ; $ authRecord -> id = $ record -> id ; $ authRecord -> name = $ record -> name ; $ authRecord -> username = $ record -> username ; $ authRecord -> email = $ record -> email ; $ authRecord -> lang = $ record -> lang ; $ authRecord -> roles = count ( $ record -> getRoles ( ) ) ? $ record -> getRoles ( ) : [ 'guest' ] ; return $ authRecord ; }
Po poprawnej autoryzacji zapis danych i loga zwraca rekord autoryzacji
19,272
public function importFileMeta ( array $ files ) { foreach ( $ files as $ importData ) { if ( ! isset ( $ importData [ 'name' ] ) || ! isset ( $ importData [ 'id' ] ) ) { return ; } if ( null === $ file = ( new \ Cms \ Orm \ CmsFileQuery ) -> findPk ( $ importData [ 'id' ] ) ) { $ file = new \ Cms \ Orm \ CmsFileRecord ; } if ( $ file -> name && $ file -> name != $ importData [ 'name' ] ) { continue ; } $ file -> setFromArray ( $ importData ) ; if ( ! $ file -> save ( ) ) { return ; } } return $ file ; }
Importuje meta pliku
19,273
public function decode ( $ json ) { $ decoded = json_decode ( $ json , true ) ; if ( null !== $ decoded ) { return $ decoded ; } if ( JSON_ERROR_NONE === json_last_error ( ) ) { return $ json ; } return self :: $ json_errors [ json_last_error ( ) ] ; }
Decodes json response
19,274
public function renderCell ( \ Mmi \ Orm \ RecordRo $ record ) { $ view = FrontController :: getInstance ( ) -> getView ( ) ; $ view -> record = $ record ; return $ view -> renderDirectly ( $ this -> getTemplateCode ( ) ) ; }
Renderuje customowe Columny
19,275
public function extract ( callable $ callback = null ) { if ( $ callback === null ) { $ result = $ this -> result -> serialize ( ) ; } else { $ result = $ callback ( $ this -> result -> serialize ( ) ) ; } return $ result ; }
Extract result data to serialize string
19,276
function set_conf ( $ confname ) { $ this -> confname = $ confname ; $ this -> confdir = PLUG_HOST_DIR . '/' . $ confname ; if ( ! PLUGTool :: check_dir ( $ this -> confdir ) ) { throw new PLUGException ( 'bad conf' ) ; } $ confpath = $ this -> confdir . '/PLUG.conf.php' ; $ this -> conf_vars = array ( ) ; $ this -> conf_consts = array ( ) ; $ this -> load_conf ( $ confpath ) ; }
Set target configuration .
19,277
function load_conf ( $ confpath ) { if ( ! PLUGTool :: check_file ( $ confpath ) ) { throw new PLUGException ( 'bad conf' ) ; } $ e = PLUG :: exec_bin ( 'parseconf' , array ( $ confpath ) , $ s ) ; if ( $ e ) { trigger_error ( 'Failed to parse ' . basename ( $ confpath ) , E_USER_NOTICE ) ; return false ; } $ a = unserialize ( $ s ) ; if ( ! is_array ( $ a ) ) { trigger_error ( "parseconf returned bad serialize string, $s" , E_USER_WARNING ) ; return false ; } $ this -> conf_vars = array_merge ( $ this -> conf_vars , $ a [ 0 ] ) ; $ this -> conf_consts = array_merge ( $ this -> conf_consts , $ a [ 1 ] ) ; return true ; }
Parse a given config file and merge values into registry . Currenly only constants in configs are supported by this compiler .
19,278
function register_include ( $ path ) { if ( ! isset ( $ this -> incs [ $ path ] ) ) { $ this -> incs [ $ path ] = 1 ; return false ; } else { $ this -> incs [ $ path ] ++ ; return true ; } }
Register a file path for inclusion
19,279
function next_dependency ( ) { foreach ( $ this -> dependencies as $ path => $ done ) { if ( ! $ done ) { $ this -> dependencies [ $ path ] = 1 ; return $ path ; } } return null ; }
get next dependant file and flag as done
19,280
private function open_php ( & $ src ) { if ( ! $ this -> inphp ) { $ this -> inphp = true ; $ makenice = $ this -> opt ( COMPILER_OPTION_NICE_TAGS ) ; if ( $ makenice && substr ( $ src , - 2 ) === '?>' ) { $ src = substr_replace ( $ src , '' , - 2 ) ; } else { $ ws = $ this -> opt ( COMPILER_OPTION_WHITESPACE ) ? "\n" : ' ' ; $ src .= '<?php' . $ ws ; } } return $ src ; }
Open php tag if required .
19,281
private function close_php ( & $ src ) { if ( $ this -> inphp ) { $ this -> inphp = false ; $ makenice = $ this -> opt ( COMPILER_OPTION_NICE_TAGS ) ; if ( $ makenice && substr ( $ src , - 5 ) === '<?php' ) { $ src = substr_replace ( $ src , '' , - 5 ) ; } else { $ src .= ' ?>' ; } } return $ src ; }
Close php tag if required .
19,282
function session_lifespan ( $ ttl = null , $ hibernate = null ) { $ current = $ this -> sess_ttl ; if ( $ ttl !== null ) { $ this -> sess_ttl = $ ttl ; } if ( $ hibernate !== null ) { $ this -> sess_hibernate = $ hibernate ; } return $ current ; }
Define how many times object can be deserialized from session before it is dead
19,283
static function raise_error ( $ code , $ message , $ type , array $ trace = null ) { if ( error_reporting ( ) === 0 ) { return ; } self :: clear_error_handlers ( ) ; if ( is_null ( $ trace ) ) { $ trace = debug_backtrace ( ) ; array_shift ( $ trace ) ; } $ callee = current ( $ trace ) ; $ Err = new PLUGError ( $ code , $ type , $ message , $ callee [ 'file' ] , $ callee [ 'line' ] , $ trace ) ; $ Err -> raise ( ) ; self :: set_error_handlers ( ) ; return $ Err ; }
Force the raising of an error
19,284
static function raise_exception ( Exception $ Ex , $ type ) { if ( error_reporting ( ) === 0 ) { return ; } PLUG :: clear_error_handlers ( ) ; $ code = $ Ex -> getCode ( ) or $ code = PLUG_EXCEPTION_STD ; $ Err = new PLUGError ( $ code , $ type , $ Ex -> getMessage ( ) , $ Ex -> getFile ( ) , $ Ex -> getLine ( ) , $ Ex -> getTrace ( ) ) ; $ Err -> raise ( ) ; PLUG :: set_error_handlers ( ) ; return $ Err ; }
Raise an error from an Exception
19,285
static function dump_errors ( $ emask = PLUG_ERROR_REPORTING ) { $ errs = PLUGError :: get_errors ( $ emask ) ; foreach ( $ errs as $ Err ) { $ s = $ Err -> __toString ( ) . "\n" ; if ( PLUG_CLI ) { PLUGCli :: stderr ( $ s ) ; } else { echo $ s ; } } }
Dump all raised errors to output
19,286
static function set_error_display ( $ handler ) { if ( ! is_callable ( $ handler ) ) { trigger_error ( 'Error display handler is not callable (' . var_export ( $ handler , 1 ) . ')' , E_USER_WARNING ) ; return false ; } PLUGError :: $ displayfunc = $ handler ; return true ; }
Register error display function .
19,287
static function set_error_logger ( $ handler ) { if ( ! is_callable ( $ handler ) ) { trigger_error ( 'Error logging handler is not callable (' . var_export ( $ handler , 1 ) . ')' , E_USER_WARNING ) ; return false ; } PLUGError :: $ logfunc = $ handler ; return true ; }
Register error logging function .
19,288
static function set_error_terminator ( $ handler ) { if ( ! is_callable ( $ handler ) ) { trigger_error ( 'Fatal error handler is not callable (' . var_export ( $ handler , 1 ) . ')' , E_USER_WARNING ) ; return false ; } PLUGError :: $ deathfunc = $ handler ; return true ; }
Register script termination function
19,289
public function onFirewallLogin ( OnFirewallAuthenticationEvent $ event ) { $ this -> doModify ( $ event ) ; $ this -> om -> persist ( $ event -> getUser ( ) ) ; $ this -> om -> flush ( ) ; }
Modifies the last action property on firewall authentication .
19,290
private function doModify ( AbstractUserEvent $ event ) { $ this -> classMetadata -> modifyProperty ( $ event -> getUser ( ) , new \ DateTime ( sprintf ( '@%s' , $ this -> requestStack -> getMasterRequest ( ) -> server -> get ( 'REQUEST_TIME' ) ) ) , ClassMetadata :: LAST_ACTION_PROPERTY ) ; }
Modifies the last action property of a user object .
19,291
public static function setupAcl ( ) { $ acl = new \ Mmi \ Security \ Acl ; $ aclData = ( new CmsAclQuery ) -> join ( 'cms_role' ) -> on ( 'cms_role_id' ) -> find ( ) ; foreach ( $ aclData as $ aclRule ) { $ resource = '' ; if ( $ aclRule -> module ) { $ resource .= $ aclRule -> module . ':' ; } if ( $ aclRule -> controller ) { $ resource .= $ aclRule -> controller . ':' ; } if ( $ aclRule -> action ) { $ resource .= $ aclRule -> action . ':' ; } $ access = $ aclRule -> access ; if ( $ access == 'allow' || $ access == 'deny' ) { $ acl -> $ access ( $ aclRule -> getJoined ( 'cms_role' ) -> name , trim ( $ resource , ':' ) ) ; } } return $ acl ; }
Ustawianie ACL a
19,292
public function create ( $ userId = null , $ eventLog = null , $ eventData = null ) { if ( is_null ( $ userId ) ) throw new \ Exception ( 'User ID is required.' ) ; if ( is_null ( $ eventLog ) ) throw new \ Exception ( 'Event Log is required.' ) ; if ( ! is_numeric ( $ userId ) ) throw new \ Exception ( "Invalid User ID." ) ; $ id = $ this -> save ( $ this -> generateEntity ( intval ( $ userId ) , $ eventLog , $ eventData ) ) ; return $ id ; }
Create user log entry
19,293
protected function configureRoute ( Route $ route , \ ReflectionClass $ class , \ ReflectionMethod $ method , $ annot ) { parent :: configureRoute ( $ route , $ class , $ method , $ annot ) ; if ( is_a ( $ annot , 'FOM\ManagerBundle\Configuration\Route' ) ) { $ route -> setPath ( $ this -> prefix . $ route -> getPath ( ) ) ; } }
For all route annotations using FOM \ ManagerBundle \ Configuration \ Route this adds the configured prefix .
19,294
public function checkIntegrationState ( ) { $ this -> response = parent :: checkIntegrationState ( $ this -> entity ) ; if ( Exception \ IntegrationState :: check ( $ this -> response ) ) { throw new Exception \ IntegrationState ( $ this -> response ) ; } return $ this -> response ; }
Checks the current entity integration state
19,295
public function subscribeToWebhook ( Structure \ RequestWebhook $ requestWebhook ) { $ this -> response = parent :: subscribeToWebhook ( $ this -> entity , $ requestWebhook ) ; if ( Exception \ IntegrationState :: check ( $ this -> response -> integrationState ) ) { throw new Exception \ IntegrationState ( $ this -> response -> integrationState ) ; } if ( $ this -> response -> integrationState -> state == 0 ) { throw new Exception \ IntegrationResponse ( $ this -> response -> integrationState -> message , $ this -> response -> integrationState -> code ) ; } return $ this -> response ; }
Subscribe to a webhook to receive callbacks from events ocurred at PayPay .
19,296
public function createPaymentReference ( Structure \ RequestReferenceDetails $ paymentData ) { $ this -> response = parent :: createPaymentReference ( $ this -> entity , $ paymentData ) ; if ( Exception \ IntegrationState :: check ( $ this -> response -> integrationState ) ) { throw new Exception \ IntegrationState ( $ this -> response -> integrationState ) ; } if ( $ this -> response -> state == 0 ) { throw new Exception \ IntegrationResponse ( $ this -> response -> err_msg , $ this -> response -> err_code ) ; } return $ this -> response ; }
Creates a new payment reference via PayPay .
19,297
public function validatePaymentReference ( Structure \ RequestReferenceDetails $ paymentData ) { $ this -> response = parent :: validatePaymentReference ( $ this -> entity , $ paymentData ) ; if ( Exception \ IntegrationState :: check ( $ this -> response -> integrationState ) ) { throw new Exception \ IntegrationState ( $ this -> response -> integrationState ) ; } if ( ! empty ( $ this -> response -> err_code ) ) { throw new Exception \ IntegrationResponse ( $ this -> response -> err_msg , $ this -> response -> err_code ) ; } return $ this -> response ; }
Validates a new payment reference via PayPay .
19,298
public function doWebPayment ( $ requestWebPayment ) { $ this -> response = parent :: doWebPayment ( $ this -> entity , $ requestWebPayment ) ; if ( Exception \ IntegrationState :: check ( $ this -> response -> requestState ) ) { throw new Exception \ IntegrationState ( $ this -> response -> requestState ) ; } if ( $ this -> response -> requestState -> state == 0 ) { throw new Exception \ IntegrationResponse ( $ this -> response -> requestState -> message , $ this -> response -> requestState -> code ) ; } return $ this -> response ; }
Calls PayPay Webservice to request a payment via PayPay redirect .
19,299
public function checkWebPayment ( $ token , $ transactionId ) { $ requestPayment = new Structure \ RequestPaymentDetails ( $ token , $ transactionId ) ; $ this -> response = parent :: checkWebPayment ( $ this -> entity , $ requestPayment ) ; if ( Exception \ IntegrationState :: check ( $ this -> response -> requestState ) ) { throw new Exception \ IntegrationState ( $ this -> response -> requestState ) ; } if ( $ this -> response -> requestState -> state == 0 ) { throw new Exception \ IntegrationResponse ( $ this -> response -> requestState -> message , $ this -> response -> requestState -> code ) ; } return $ this -> response ; }
Calls PayPay Webservice to check the payment state .